blob: 2ae33108673ef9e19cb2bb122adcc6abd6c3d8fe [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 Jakkam1bf1bd62021-09-12 16:35:55 +05308916 dut->num_dscp_status = 0;
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308917 snprintf(buf, sizeof(buf),
8918 "ip -6 route replace fe80::/64 dev %s table local",
8919 intf);
8920 if (system(buf) != 0)
8921 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s",
8922 buf);
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05308923
8924 stop_dscp_policy_mon_thread(dut);
8925 clear_all_dscp_policies(dut);
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308926 }
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308927
Jouni Malinen8179fee2019-03-28 03:19:47 +02008928 dut->akm_values = 0;
Shivani Baranwal7aa48602021-09-29 10:53:38 +05308929
8930#ifdef NL80211_SUPPORT
8931 if (get_driver_type(dut) == DRIVER_WCN)
8932 sta_config_params(dut, intf, STA_SET_FT_DS, 0);
8933#endif /* NL80211_SUPPORT */
8934
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03008935 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02008936
Sunil Dutt076081f2018-02-05 19:45:50 +05308937#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008938 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05308939 dut->config_rsnie == 1) {
8940 dut->config_rsnie = 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308941 sta_config_params(dut, intf, STA_SET_RSNIE, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05308942 }
8943#endif /* NL80211_SUPPORT */
8944
Sunil Duttfebf8a82018-02-09 18:50:13 +05308945 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
8946 dut->dev_role = DEVROLE_STA_CFON;
8947 return sta_cfon_reset_default(dut, conn, cmd);
8948 }
8949
Jouni Malinen439352d2018-09-13 03:42:23 +03008950 wpa_command(intf, "SET setband AUTO");
8951
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05308952 ret = wpa_command_resp(intf, "GET_CAPABILITY ocv", resp, sizeof(resp));
8953 dut->ocvc = ret == 0 && strncmp(resp, "supported", 9) == 0;
8954
8955 ret = wpa_command_resp(intf, "GET_CAPABILITY beacon_prot", resp,
8956 sizeof(resp));
8957 dut->beacon_prot = ret == 0 && strncmp(resp, "supported", 9) == 0;
8958
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308959 if (sta_set_client_privacy(dut, conn, intf,
8960 dut->program == PROGRAM_WPA3 &&
8961 dut->device_type == STA_dut &&
8962 dut->client_privacy_default)) {
8963 sigma_dut_print(dut, DUT_MSG_ERROR,
8964 "Failed to set client privacy functionality");
8965 /* sta_reset_default command is not really supposed to fail,
8966 * so allow this to continue. */
8967 }
8968
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05308969 dut->saquery_oci_freq = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308970
Sunil Duttfebf8a82018-02-09 18:50:13 +05308971 if (dut->program != PROGRAM_VHT)
8972 return cmd_sta_p2p_reset(dut, conn, cmd);
8973
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08008974 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008975}
8976
8977
Jouni Malinenf7222712019-06-13 01:50:21 +03008978static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
8979 struct sigma_conn *conn,
8980 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008981{
8982 const char *program = get_param(cmd, "Program");
8983
8984 if (program == NULL)
8985 return -1;
8986#ifdef ANDROID_NAN
8987 if (strcasecmp(program, "NAN") == 0)
8988 return nan_cmd_sta_get_events(dut, conn, cmd);
8989#endif /* ANDROID_NAN */
8990 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8991 return 0;
8992}
8993
8994
Jouni Malinen82905202018-04-29 17:20:10 +03008995static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
8996 struct sigma_cmd *cmd)
8997{
8998 const char *url = get_param(cmd, "url");
8999 const char *method = get_param(cmd, "method");
9000 pid_t pid;
9001 int status;
9002
9003 if (!url || !method)
9004 return -1;
9005
9006 /* TODO: Add support for method,post */
9007 if (strcasecmp(method, "get") != 0) {
9008 send_resp(dut, conn, SIGMA_ERROR,
9009 "ErrorCode,Unsupported method");
9010 return 0;
9011 }
9012
9013 pid = fork();
9014 if (pid < 0) {
9015 perror("fork");
9016 return -1;
9017 }
9018
9019 if (pid == 0) {
9020 char * argv[5] = { "wget", "-O", "/dev/null",
9021 (char *) url, NULL };
9022
9023 execv("/usr/bin/wget", argv);
9024 perror("execv");
9025 exit(0);
9026 return -1;
9027 }
9028
9029 if (waitpid(pid, &status, 0) < 0) {
9030 perror("waitpid");
9031 return -1;
9032 }
9033
9034 if (WIFEXITED(status)) {
9035 const char *errmsg;
9036
9037 if (WEXITSTATUS(status) == 0)
9038 return 1;
9039 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
9040 WEXITSTATUS(status));
9041 switch (WEXITSTATUS(status)) {
9042 case 4:
9043 errmsg = "errmsg,Network failure";
9044 break;
9045 case 8:
9046 errmsg = "errmsg,Server issued an error response";
9047 break;
9048 default:
9049 errmsg = "errmsg,Unknown failure from wget";
9050 break;
9051 }
9052 send_resp(dut, conn, SIGMA_ERROR, errmsg);
9053 return 0;
9054 }
9055
9056 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
9057 return 0;
9058}
9059
9060
Jouni Malinenf7222712019-06-13 01:50:21 +03009061static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
9062 struct sigma_conn *conn,
9063 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009064{
9065 const char *program = get_param(cmd, "Prog");
9066
Jouni Malinen82905202018-04-29 17:20:10 +03009067 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009068 return -1;
9069#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03009070 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009071 return nan_cmd_sta_exec_action(dut, conn, cmd);
9072#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03009073
9074 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07009075 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03009076
9077 if (get_param(cmd, "url"))
9078 return sta_exec_action_url(dut, conn, cmd);
9079
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009080 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
9081 return 0;
9082}
9083
9084
Jouni Malinenf7222712019-06-13 01:50:21 +03009085static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
9086 struct sigma_conn *conn,
9087 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009088{
9089 const char *intf = get_param(cmd, "Interface");
9090 const char *val, *mcs32, *rate;
9091
9092 val = get_param(cmd, "GREENFIELD");
9093 if (val) {
9094 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
9095 /* Enable GD */
9096 send_resp(dut, conn, SIGMA_ERROR,
9097 "ErrorCode,GF not supported");
9098 return 0;
9099 }
9100 }
9101
9102 val = get_param(cmd, "SGI20");
9103 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009104 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009105 case DRIVER_ATHEROS:
9106 ath_sta_set_sgi(dut, intf, val);
9107 break;
9108 default:
9109 send_resp(dut, conn, SIGMA_ERROR,
9110 "ErrorCode,SGI20 not supported");
9111 return 0;
9112 }
9113 }
9114
9115 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
9116 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
9117 if (mcs32 && rate) {
9118 /* TODO */
9119 send_resp(dut, conn, SIGMA_ERROR,
9120 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
9121 return 0;
9122 } else if (mcs32 && !rate) {
9123 /* TODO */
9124 send_resp(dut, conn, SIGMA_ERROR,
9125 "ErrorCode,MCS32 not supported");
9126 return 0;
9127 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009128 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009129 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07009130 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009131 ath_sta_set_11nrates(dut, intf, rate);
9132 break;
9133 default:
9134 send_resp(dut, conn, SIGMA_ERROR,
9135 "ErrorCode,MCS32_FIXEDRATE not supported");
9136 return 0;
9137 }
9138 }
9139
9140 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9141}
9142
9143
Arif Hussain7b47d2d2018-05-09 10:44:02 -07009144static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
9145 int mcs_config)
9146{
9147#ifdef NL80211_SUPPORT
9148 int ret;
9149
9150 switch (mcs_config) {
9151 case HE_80_MCS0_7:
9152 case HE_80_MCS0_9:
9153 case HE_80_MCS0_11:
9154 ret = sta_set_he_mcs(dut, intf, mcs_config);
9155 if (ret) {
9156 sigma_dut_print(dut, DUT_MSG_ERROR,
9157 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
9158 mcs_config, ret);
9159 }
9160 break;
9161 default:
9162 sigma_dut_print(dut, DUT_MSG_ERROR,
9163 "cmd_set_max_he_mcs: Invalid mcs %d",
9164 mcs_config);
9165 break;
9166 }
9167#else /* NL80211_SUPPORT */
9168 sigma_dut_print(dut, DUT_MSG_ERROR,
9169 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
9170#endif /* NL80211_SUPPORT */
9171}
9172
9173
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009174struct wait_event {
9175 struct sigma_dut *dut;
9176 int cmd;
9177 unsigned int twt_op;
9178};
9179
9180#ifdef NL80211_SUPPORT
9181
9182static int twt_event_handler(struct nl_msg *msg, void *arg)
9183{
9184 struct wait_event *wait = arg;
9185 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9186 struct nlattr *tb[NL80211_ATTR_MAX + 1];
9187 uint32_t subcmd;
9188 uint8_t *data = NULL;
9189 size_t len = 0;
9190 struct nlattr *twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_MAX + 1];
9191 struct nlattr *twt_status[QCA_WLAN_VENDOR_ATTR_TWT_SETUP_MAX + 1];
9192 int cmd_id;
9193 unsigned char val;
9194
9195 if (!wait)
9196 return NL_SKIP;
9197
9198 if (gnlh->cmd != NL80211_CMD_VENDOR) {
9199 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9200 "%s: NL cmd is not vendor %d", __func__,
9201 gnlh->cmd);
9202 return NL_SKIP;
9203 }
9204
9205 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
9206 genlmsg_attrlen(gnlh, 0), NULL);
9207
9208 if (!tb[NL80211_ATTR_VENDOR_ID] || !tb[NL80211_ATTR_VENDOR_SUBCMD]) {
9209 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9210 "%s: vendor ID not found", __func__);
9211 return NL_SKIP;
9212 }
9213 subcmd = nla_get_u32(tb[NL80211_ATTR_VENDOR_SUBCMD]);
9214
9215 if (subcmd != QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) {
9216 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9217 "%s: Not a TWT_cmd %d", __func__, subcmd);
9218 return NL_SKIP;
9219 }
9220 if (tb[NL80211_ATTR_VENDOR_DATA]) {
9221 data = nla_data(tb[NL80211_ATTR_VENDOR_DATA]);
9222 len = nla_len(tb[NL80211_ATTR_VENDOR_DATA]);
9223 } else {
9224 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9225 "%s: vendor data not present", __func__);
9226 return NL_SKIP;
9227 }
9228 if (!data || !len) {
9229 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9230 "Invalid vendor data or len");
9231 return NL_SKIP;
9232 }
9233 sigma_dut_print(wait->dut, DUT_MSG_DEBUG,
9234 "event data len %ld", len);
9235 hex_dump(wait->dut, data, len);
9236 if (nla_parse(twt_rsp, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_MAX,
9237 (struct nlattr *) data, len, NULL)) {
9238 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9239 "vendor data parse error");
9240 return NL_SKIP;
9241 }
9242
9243 val = nla_get_u8(twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION]);
9244 if (val != wait->twt_op) {
9245 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9246 "Invalid TWT operation, expected %d, rcvd %d",
9247 wait->twt_op, val);
9248 return NL_SKIP;
9249 }
9250 if (nla_parse_nested(twt_status, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_MAX,
9251 twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS],
9252 NULL)) {
9253 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9254 "nla_parse failed for TWT event");
9255 return NL_SKIP;
9256 }
9257
9258 cmd_id = QCA_WLAN_VENDOR_ATTR_TWT_SETUP_STATUS;
9259 if (!twt_status[cmd_id]) {
9260 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9261 "%s TWT resp status missing", __func__);
9262 wait->cmd = -1;
9263 } else {
9264 val = nla_get_u8(twt_status[cmd_id]);
9265 if (val != QCA_WLAN_VENDOR_TWT_STATUS_OK) {
9266 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9267 "%s TWT resp status %d", __func__, val);
9268 wait->cmd = -1;
9269 } else {
9270 wait->cmd = 1;
9271 }
9272 }
9273
9274 return NL_SKIP;
9275}
9276
9277
9278static int wait_on_nl_socket(struct nl_sock *sock, struct sigma_dut *dut,
9279 unsigned int timeout)
9280{
9281 fd_set read_fd_set;
9282 int retval;
9283 int sock_fd;
9284 struct timeval time_out;
9285
9286 time_out.tv_sec = timeout;
9287 time_out.tv_usec = 0;
9288
9289 FD_ZERO(&read_fd_set);
9290
9291 if (!sock)
9292 return -1;
9293
9294 sock_fd = nl_socket_get_fd(sock);
9295 FD_SET(sock_fd, &read_fd_set);
9296
9297 retval = select(sock_fd + 1, &read_fd_set, NULL, NULL, &time_out);
9298
9299 if (retval == 0)
9300 sigma_dut_print(dut, DUT_MSG_ERROR,
9301 "%s: TWT event response timedout", __func__);
9302
9303 if (retval < 0)
9304 sigma_dut_print(dut, DUT_MSG_ERROR, "%s:no NL msgs, ret=%d",
9305 __func__, retval);
9306
9307 return retval;
9308}
9309
9310
9311#define TWT_ASYNC_EVENT_WAIT_TIME_SEC 6
9312
9313static int twt_async_event_wait(struct sigma_dut *dut, unsigned int twt_op)
9314{
9315 struct nl_cb *cb;
9316 int err_code = 0, select_retval = 0;
9317 struct wait_event wait_info;
9318
9319 cb = nl_socket_get_cb(dut->nl_ctx->event_sock);
9320 if (!cb) {
9321 sigma_dut_print(dut, DUT_MSG_ERROR,
9322 "event callback not found");
9323 return ERROR_SEND_STATUS;
9324 }
9325
9326 wait_info.cmd = 0;
9327 wait_info.dut = dut;
9328 wait_info.twt_op = twt_op;
9329
9330 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, twt_event_handler, &wait_info);
9331
9332 while (!wait_info.cmd) {
9333 select_retval = wait_on_nl_socket(
9334 dut->nl_ctx->event_sock, dut,
9335 TWT_ASYNC_EVENT_WAIT_TIME_SEC);
9336
9337 if (select_retval > 0) {
9338 err_code = nl_recvmsgs(dut->nl_ctx->event_sock, cb);
9339 if (err_code < 0) {
9340 sigma_dut_print(dut, DUT_MSG_ERROR,
9341 "%s: nl rcv failed, err_code %d",
9342 __func__, err_code);
9343 break;
9344 }
9345 } else {
9346 sigma_dut_print(dut, DUT_MSG_ERROR,
9347 "%s: wait on socket failed %d",
9348 __func__, select_retval);
9349 err_code = 1;
9350 break;
9351 }
9352
9353 }
9354 nl_cb_put(cb);
9355
9356 if (wait_info.cmd < 0)
9357 err_code = 1;
9358
9359 sigma_dut_print(dut, DUT_MSG_DEBUG,
9360 "%s: rcvd cmd %d, err_code %d, s_ret %d",
9361 __func__, wait_info.cmd, err_code, select_retval);
9362
9363 return err_code;
9364}
9365
9366#endif /* NL80211_SUPPORT */
9367
9368
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009369static int sta_twt_send_suspend(struct sigma_dut *dut, struct sigma_conn *conn,
9370 struct sigma_cmd *cmd)
9371{
9372#ifdef NL80211_SUPPORT
9373 struct nlattr *attr, *attr1;
9374 struct nl_msg *msg;
9375 int ifindex, ret;
9376 const char *intf = get_param(cmd, "Interface");
9377
9378 ifindex = if_nametoindex(intf);
9379 if (ifindex == 0) {
9380 sigma_dut_print(dut, DUT_MSG_ERROR,
9381 "%s: Index for interface %s failed",
9382 __func__, intf);
9383 return ERROR_SEND_STATUS;
9384 }
9385
9386 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9387 NL80211_CMD_VENDOR)) ||
9388 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9389 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9390 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9391 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
9392 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9393 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9394 QCA_WLAN_TWT_SUSPEND) ||
9395 !(attr1 = nla_nest_start(msg,
Kiran Kumar Lokere7ede00c2021-08-09 00:59:52 -07009396 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS))) {
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009397 sigma_dut_print(dut, DUT_MSG_ERROR,
9398 "%s: err in adding vendor_cmd and vendor_data",
9399 __func__);
9400 nlmsg_free(msg);
9401 return ERROR_SEND_STATUS;
9402 }
9403 nla_nest_end(msg, attr1);
9404 nla_nest_end(msg, attr);
9405
9406 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9407 if (ret) {
9408 sigma_dut_print(dut, DUT_MSG_ERROR,
9409 "%s: err in send_and_recv_msgs, ret=%d",
9410 __func__, ret);
9411 }
9412
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009413 if (!dut->sta_async_twt_supp)
9414 return ret;
9415
9416 return twt_async_event_wait(dut, QCA_WLAN_TWT_SUSPEND);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009417#else /* NL80211_SUPPORT */
9418 sigma_dut_print(dut, DUT_MSG_ERROR,
9419 "TWT suspend cannot be done without NL80211_SUPPORT defined");
9420 return ERROR_SEND_STATUS;
9421#endif /* NL80211_SUPPORT */
9422}
9423
9424
9425static int sta_twt_send_nudge(struct sigma_dut *dut, struct sigma_conn *conn,
9426 struct sigma_cmd *cmd,
9427 unsigned int suspend_duration)
9428{
9429#ifdef NL80211_SUPPORT
9430 struct nlattr *attr, *attr1;
9431 struct nl_msg *msg;
9432 int ifindex, ret;
9433 const char *intf = get_param(cmd, "Interface");
9434 int next_twt_size = 1;
9435
9436 ifindex = if_nametoindex(intf);
9437 if (ifindex == 0) {
9438 sigma_dut_print(dut, DUT_MSG_ERROR,
9439 "%s: Index for interface %s failed",
9440 __func__, intf);
9441 return ERROR_SEND_STATUS;
9442 }
9443
9444 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9445 NL80211_CMD_VENDOR)) ||
9446 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9447 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9448 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9449 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
9450 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9451 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9452 QCA_WLAN_TWT_NUDGE) ||
9453 !(attr1 = nla_nest_start(msg,
9454 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
9455 (suspend_duration &&
9456 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_WAKE_TIME,
9457 suspend_duration)) ||
9458 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_NEXT_TWT_SIZE,
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009459 next_twt_size) ||
9460 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_FLOW_ID, 0)) {
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009461 sigma_dut_print(dut, DUT_MSG_ERROR,
9462 "%s: err in adding vendor_cmd and vendor_data",
9463 __func__);
9464 nlmsg_free(msg);
9465 return ERROR_SEND_STATUS;
9466 }
9467 nla_nest_end(msg, attr1);
9468 nla_nest_end(msg, attr);
9469
9470 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9471 if (ret) {
9472 sigma_dut_print(dut, DUT_MSG_ERROR,
9473 "%s: err in send_and_recv_msgs, ret=%d",
9474 __func__, ret);
9475 }
9476
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009477 if (!dut->sta_async_twt_supp)
9478 return ret;
9479
9480 return twt_async_event_wait(dut, QCA_WLAN_TWT_NUDGE);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009481#else /* NL80211_SUPPORT */
9482 sigma_dut_print(dut, DUT_MSG_ERROR,
9483 "TWT suspend cannot be done without NL80211_SUPPORT defined");
9484 return ERROR_SEND_STATUS;
9485#endif /* NL80211_SUPPORT */
9486}
9487
9488
9489static int sta_twt_suspend_or_nudge(struct sigma_dut *dut,
9490 struct sigma_conn *conn,
9491 struct sigma_cmd *cmd)
9492{
9493 const char *val;
9494
9495 val = get_param(cmd, "TWT_SuspendDuration");
9496 if (val) {
9497 unsigned int suspend_duration;
9498
9499 suspend_duration = atoi(val);
9500 suspend_duration = suspend_duration * 1000 * 1000;
9501 return sta_twt_send_nudge(dut, conn, cmd, suspend_duration);
9502 }
9503
9504 return sta_twt_send_suspend(dut, conn, cmd);
9505}
9506
9507
9508static int sta_twt_resume(struct sigma_dut *dut, struct sigma_conn *conn,
9509 struct sigma_cmd *cmd)
9510{
9511#ifdef NL80211_SUPPORT
9512 struct nlattr *attr, *attr1;
9513 struct nl_msg *msg;
9514 int ifindex, ret;
9515 const char *intf = get_param(cmd, "Interface");
9516 int next2_twt_size = 1;
9517 unsigned int resume_duration = 0;
9518 const char *val;
9519
9520 ifindex = if_nametoindex(intf);
9521 if (ifindex == 0) {
9522 sigma_dut_print(dut, DUT_MSG_ERROR,
9523 "%s: Index for interface %s failed",
9524 __func__, intf);
9525 return ERROR_SEND_STATUS;
9526 }
9527
9528 val = get_param(cmd, "TWT_ResumeDuration");
9529 if (val) {
9530 resume_duration = atoi(val);
9531 resume_duration = resume_duration * 1000 * 1000;
9532 }
9533
9534 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9535 NL80211_CMD_VENDOR)) ||
9536 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9537 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9538 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9539 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
9540 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9541 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9542 QCA_WLAN_TWT_RESUME) ||
9543 !(attr1 = nla_nest_start(msg,
9544 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
9545 (resume_duration &&
9546 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_RESUME_NEXT2_TWT,
9547 resume_duration)) ||
9548 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_RESUME_NEXT_TWT_SIZE,
9549 next2_twt_size)) {
9550 sigma_dut_print(dut, DUT_MSG_ERROR,
9551 "%s: err in adding vendor_cmd and vendor_data",
9552 __func__);
9553 nlmsg_free(msg);
9554 return ERROR_SEND_STATUS;
9555 }
9556 nla_nest_end(msg, attr1);
9557 nla_nest_end(msg, attr);
9558
9559 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9560 if (ret) {
9561 sigma_dut_print(dut, DUT_MSG_ERROR,
9562 "%s: err in send_and_recv_msgs, ret=%d",
9563 __func__, ret);
9564 }
9565
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009566 if (!dut->sta_async_twt_supp)
9567 return ret;
9568
9569 return twt_async_event_wait(dut, QCA_WLAN_TWT_RESUME);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009570#else /* NL80211_SUPPORT */
9571 sigma_dut_print(dut, DUT_MSG_ERROR,
9572 "TWT resume cannot be done without NL80211_SUPPORT defined");
9573 return ERROR_SEND_STATUS;
9574#endif /* NL80211_SUPPORT */
9575}
9576
9577
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009578#define TWT_REQUEST_CMD 0
9579#define TWT_SUGGEST_CMD 1
9580#define TWT_DEMAND_CMD 2
9581
Arif Hussain480d5f42019-03-12 14:40:42 -07009582static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
9583 struct sigma_cmd *cmd)
9584{
9585#ifdef NL80211_SUPPORT
9586 struct nlattr *params;
9587 struct nlattr *attr;
Arif Hussain480d5f42019-03-12 14:40:42 -07009588 struct nl_msg *msg;
9589 int ifindex, ret;
9590 const char *val;
9591 const char *intf = get_param(cmd, "Interface");
9592 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
9593 wake_interval_mantissa = 512;
9594 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009595 protection = 0, cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009596 int bcast_twt = 0;
9597 int bcast_twt_id = 0, bcast_twt_recommdn = 0, bcast_twt_persis = 0;
Arif Hussain480d5f42019-03-12 14:40:42 -07009598
9599 ifindex = if_nametoindex(intf);
9600 if (ifindex == 0) {
9601 sigma_dut_print(dut, DUT_MSG_ERROR,
9602 "%s: Index for interface %s failed",
9603 __func__, intf);
9604 return -1;
9605 }
9606
9607 val = get_param(cmd, "FlowType");
9608 if (val) {
9609 flow_type = atoi(val);
9610 if (flow_type != 0 && flow_type != 1) {
9611 sigma_dut_print(dut, DUT_MSG_ERROR,
9612 "TWT: Invalid FlowType %d", flow_type);
9613 return -1;
9614 }
9615 }
9616
9617 val = get_param(cmd, "TWT_Trigger");
9618 if (val) {
9619 twt_trigger = atoi(val);
9620 if (twt_trigger != 0 && twt_trigger != 1) {
9621 sigma_dut_print(dut, DUT_MSG_ERROR,
9622 "TWT: Invalid TWT_Trigger %d",
9623 twt_trigger);
9624 return -1;
9625 }
9626 }
9627
9628 val = get_param(cmd, "Protection");
9629 if (val) {
9630 protection = atoi(val);
9631 if (protection != 0 && protection != 1) {
9632 sigma_dut_print(dut, DUT_MSG_ERROR,
9633 "TWT: Invalid Protection %d",
9634 protection);
9635 return -1;
9636 }
9637 }
9638
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009639 val = get_param(cmd, "SetupCommand");
9640 if (val) {
9641 cmd_type = atoi(val);
9642 if (cmd_type == TWT_REQUEST_CMD)
9643 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_REQUEST;
9644 else if (cmd_type == TWT_SUGGEST_CMD)
9645 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
9646 else if (cmd_type == TWT_DEMAND_CMD)
9647 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_DEMAND;
9648 else
9649 sigma_dut_print(dut, DUT_MSG_ERROR,
9650 "Default suggest is used for cmd %d",
9651 cmd_type);
9652 }
9653
Arif Hussain480d5f42019-03-12 14:40:42 -07009654 val = get_param(cmd, "TargetWakeTime");
9655 if (val)
9656 target_wake_time = atoi(val);
9657
9658 val = get_param(cmd, "WakeIntervalMantissa");
9659 if (val)
9660 wake_interval_mantissa = atoi(val);
9661
9662 val = get_param(cmd, "WakeIntervalExp");
9663 if (val)
9664 wake_interval_exp = atoi(val);
9665
9666 val = get_param(cmd, "NominalMinWakeDur");
9667 if (val)
9668 nominal_min_wake_dur = atoi(val);
9669
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009670 val = get_param(cmd, "BTWT_ID");
9671 if (val) {
9672 bcast_twt_id = atoi(val);
9673 bcast_twt = 1;
9674 }
9675
9676 val = get_param(cmd, "BTWT_Persistence");
9677 if (val) {
9678 bcast_twt_persis = atoi(val);
9679 bcast_twt = 1;
9680 }
9681
9682 val = get_param(cmd, "BTWT_Recommendation");
9683 if (val) {
9684 bcast_twt_recommdn = atoi(val);
9685 bcast_twt = 1;
9686 }
9687
9688 if (bcast_twt)
9689 sigma_dut_print(dut, DUT_MSG_DEBUG,
9690 "BCAST_TWT: ID %d, RECOMM %d, PERSIS %d",
9691 bcast_twt_id, bcast_twt_recommdn,
9692 bcast_twt_persis);
9693
Arif Hussain480d5f42019-03-12 14:40:42 -07009694 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9695 NL80211_CMD_VENDOR)) ||
9696 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9697 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9698 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009699 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009700 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009701 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9702 QCA_WLAN_TWT_SET) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009703 !(params = nla_nest_start(
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009704 msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009705 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
9706 wake_interval_exp) ||
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009707 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, cmd_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07009708 (twt_trigger &&
9709 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009710 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
9711 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07009712 (protection &&
9713 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009714 (bcast_twt &&
9715 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST)) ||
9716 (bcast_twt &&
9717 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_ID,
9718 bcast_twt_id)) ||
9719 (bcast_twt &&
9720 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_PERSISTENCE,
9721 bcast_twt_persis)) ||
9722 (bcast_twt &&
9723 nla_put_u8(msg,
9724 QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_RECOMMENDATION,
9725 bcast_twt_recommdn)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009726 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
9727 target_wake_time) ||
9728 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
9729 nominal_min_wake_dur) ||
9730 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
9731 wake_interval_mantissa)) {
9732 sigma_dut_print(dut, DUT_MSG_ERROR,
9733 "%s: err in adding vendor_cmd and vendor_data",
9734 __func__);
9735 nlmsg_free(msg);
9736 return -1;
9737 }
Arif Hussain480d5f42019-03-12 14:40:42 -07009738 nla_nest_end(msg, params);
9739 nla_nest_end(msg, attr);
9740
9741 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9742 if (ret) {
9743 sigma_dut_print(dut, DUT_MSG_ERROR,
9744 "%s: err in send_and_recv_msgs, ret=%d",
9745 __func__, ret);
9746 }
9747
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009748 if (!dut->sta_async_twt_supp)
9749 return ret;
9750
9751 return twt_async_event_wait(dut, QCA_WLAN_TWT_SET);
Arif Hussain480d5f42019-03-12 14:40:42 -07009752#else /* NL80211_SUPPORT */
9753 sigma_dut_print(dut, DUT_MSG_ERROR,
9754 "TWT request cannot be done without NL80211_SUPPORT defined");
9755 return -1;
9756#endif /* NL80211_SUPPORT */
9757}
9758
9759
9760static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
9761 struct sigma_cmd *cmd)
9762{
9763 #ifdef NL80211_SUPPORT
9764 struct nlattr *params;
9765 struct nlattr *attr;
Arif Hussain480d5f42019-03-12 14:40:42 -07009766 int ifindex, ret;
9767 struct nl_msg *msg;
9768 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009769 int bcast_twt = 0;
9770 int bcast_twt_id = 0;
9771 const char *val;
Arif Hussain480d5f42019-03-12 14:40:42 -07009772
9773 ifindex = if_nametoindex(intf);
9774 if (ifindex == 0) {
9775 sigma_dut_print(dut, DUT_MSG_ERROR,
9776 "%s: Index for interface %s failed",
9777 __func__, intf);
9778 return -1;
9779 }
9780
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009781 val = get_param(cmd, "BTWT_ID");
9782 if (val) {
9783 bcast_twt_id = atoi(val);
9784 bcast_twt = 1;
9785 }
9786
Arif Hussain480d5f42019-03-12 14:40:42 -07009787 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9788 NL80211_CMD_VENDOR)) ||
9789 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9790 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9791 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009792 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009793 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009794 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9795 QCA_WLAN_TWT_TERMINATE) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009796 !(params = nla_nest_start(
9797 msg,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009798 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009799 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0) ||
9800 (bcast_twt &&
9801 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST)) ||
9802 (bcast_twt &&
9803 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_ID,
9804 bcast_twt_id))) {
Arif Hussain480d5f42019-03-12 14:40:42 -07009805 sigma_dut_print(dut, DUT_MSG_ERROR,
9806 "%s: err in adding vendor_cmd and vendor_data",
9807 __func__);
9808 nlmsg_free(msg);
9809 return -1;
9810 }
Arif Hussain480d5f42019-03-12 14:40:42 -07009811 nla_nest_end(msg, params);
9812 nla_nest_end(msg, attr);
9813
9814 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9815 if (ret) {
9816 sigma_dut_print(dut, DUT_MSG_ERROR,
9817 "%s: err in send_and_recv_msgs, ret=%d",
9818 __func__, ret);
9819 }
9820
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009821 if (!dut->sta_async_twt_supp)
9822 return ret;
9823
9824 return twt_async_event_wait(dut, QCA_WLAN_TWT_TERMINATE);
Arif Hussain480d5f42019-03-12 14:40:42 -07009825#else /* NL80211_SUPPORT */
9826 sigma_dut_print(dut, DUT_MSG_ERROR,
9827 "TWT teardown cannot be done without NL80211_SUPPORT defined");
9828 return -1;
9829#endif /* NL80211_SUPPORT */
9830}
9831
9832
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08009833static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
9834 struct sigma_cmd *cmd)
9835{
9836#ifdef NL80211_SUPPORT
9837 struct nlattr *params;
9838 struct nlattr *attr;
9839 struct nlattr *attr1;
9840 struct nl_msg *msg;
9841 int ifindex, ret;
9842 const char *val;
9843 const char *intf = get_param(cmd, "Interface");
9844 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
9845 ulmu_data_dis = 0;
9846
9847 ifindex = if_nametoindex(intf);
9848 if (ifindex == 0) {
9849 sigma_dut_print(dut, DUT_MSG_ERROR,
9850 "%s: Index for interface %s failed",
9851 __func__, intf);
9852 return -1;
9853 }
9854 val = get_param(cmd, "OMCtrl_RxNSS");
9855 if (val)
9856 rx_nss = atoi(val);
9857
9858 val = get_param(cmd, "OMCtrl_ChnlWidth");
9859 if (val)
9860 ch_bw = atoi(val);
9861
9862 val = get_param(cmd, "OMCtrl_ULMUDisable");
9863 if (val)
9864 ulmu_dis = atoi(val);
9865
9866 val = get_param(cmd, "OMCtrl_TxNSTS");
9867 if (val)
9868 tx_nsts = atoi(val);
9869
9870 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
9871 if (val)
9872 ulmu_data_dis = atoi(val);
9873
9874 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9875 NL80211_CMD_VENDOR)) ||
9876 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9877 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9878 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9879 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9880 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9881 !(params = nla_nest_start(
9882 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
9883 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9884 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
9885 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
9886 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
9887 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
9888 ulmu_data_dis) ||
9889 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
9890 ulmu_dis)) {
9891 sigma_dut_print(dut, DUT_MSG_ERROR,
9892 "%s: err in adding vendor_cmd and vendor_data",
9893 __func__);
9894 nlmsg_free(msg);
9895 return -1;
9896 }
9897 nla_nest_end(msg, attr1);
9898 nla_nest_end(msg, params);
9899 nla_nest_end(msg, attr);
9900
9901 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9902 if (ret) {
9903 sigma_dut_print(dut, DUT_MSG_ERROR,
9904 "%s: err in send_and_recv_msgs, ret=%d",
9905 __func__, ret);
9906 }
9907
9908 return ret;
9909#else /* NL80211_SUPPORT */
9910 sigma_dut_print(dut, DUT_MSG_ERROR,
9911 "OMI TX cannot be processed without NL80211_SUPPORT defined");
9912 return -1;
9913#endif /* NL80211_SUPPORT */
9914}
9915
9916
Jouni Malinen224e3902021-06-09 16:41:27 +03009917static enum sigma_cmd_result
9918cmd_sta_set_wireless_vht(struct sigma_dut *dut, struct sigma_conn *conn,
9919 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009920{
9921 const char *intf = get_param(cmd, "Interface");
9922 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07009923 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009924 int tkip = -1;
9925 int wep = -1;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309926 int iwpriv_status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009927
Arif Hussaina37e9552018-06-20 17:05:59 -07009928 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009929 val = get_param(cmd, "SGI80");
9930 if (val) {
9931 int sgi80;
9932
9933 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009934 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009935 }
9936
9937 val = get_param(cmd, "TxBF");
9938 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009939 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009940 case DRIVER_WCN:
9941 if (sta_set_tx_beamformee(dut, intf, 1)) {
9942 send_resp(dut, conn, SIGMA_ERROR,
9943 "ErrorCode,Failed to set TX beamformee enable");
Jouni Malinen224e3902021-06-09 16:41:27 +03009944 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009945 }
9946 break;
9947 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009948 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009949 send_resp(dut, conn, SIGMA_ERROR,
9950 "ErrorCode,Setting vhtsubfee failed");
Jouni Malinen224e3902021-06-09 16:41:27 +03009951 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009952 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009953 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009954 send_resp(dut, conn, SIGMA_ERROR,
9955 "ErrorCode,Setting vhtsubfer failed");
Jouni Malinen224e3902021-06-09 16:41:27 +03009956 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009957 }
9958 break;
9959 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009960 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009961 "Unsupported driver type");
9962 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009963 }
9964 }
9965
9966 val = get_param(cmd, "MU_TxBF");
9967 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009968 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009969 case DRIVER_ATHEROS:
9970 ath_sta_set_txsp_stream(dut, intf, "1SS");
9971 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009972 run_iwpriv(dut, intf, "vhtmubfee 1");
9973 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05309974 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009975 case DRIVER_WCN:
9976 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
9977 send_resp(dut, conn, SIGMA_ERROR,
9978 "ErrorCode,Failed to set RX/TXSP_STREAM");
Jouni Malinen224e3902021-06-09 16:41:27 +03009979 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009980 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05309981 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009982 default:
9983 sigma_dut_print(dut, DUT_MSG_ERROR,
9984 "Setting SP_STREAM not supported");
9985 break;
9986 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009987 }
9988
9989 val = get_param(cmd, "LDPC");
9990 if (val) {
9991 int ldpc;
9992
9993 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309994 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", ldpc);
9995 if (iwpriv_status)
9996 sta_config_params(dut, intf, STA_SET_LDPC, ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009997 }
9998
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08009999 val = get_param(cmd, "BCC");
10000 if (val) {
10001 int bcc;
10002
10003 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
10004 /* use LDPC iwpriv itself to set bcc coding, bcc coding
10005 * is mutually exclusive to bcc */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +053010006 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", !bcc);
10007 if (iwpriv_status)
10008 sta_config_params(dut, intf, STA_SET_LDPC, !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -080010009 }
10010
Arif Hussain7b47d2d2018-05-09 10:44:02 -070010011 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
10012 if (val && dut->sta_nss == 1)
10013 cmd_set_max_he_mcs(dut, intf, atoi(val));
10014
10015 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
10016 if (val && dut->sta_nss == 2)
10017 cmd_set_max_he_mcs(dut, intf, atoi(val));
10018
Arif Hussainac6c5112018-05-25 17:34:00 -070010019 val = get_param(cmd, "MCS_FixedRate");
10020 if (val) {
10021#ifdef NL80211_SUPPORT
10022 int mcs, ratecode = 0;
10023 enum he_mcs_config mcs_config;
10024 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +030010025 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -070010026
10027 ratecode = (0x07 & dut->sta_nss) << 5;
10028 mcs = atoi(val);
10029 /* Add the MCS to the ratecode */
10030 if (mcs >= 0 && mcs <= 11) {
10031 ratecode += mcs;
10032 if (dut->device_type == STA_testbed &&
10033 mcs > 7 && mcs <= 11) {
10034 if (mcs <= 9)
10035 mcs_config = HE_80_MCS0_9;
10036 else
10037 mcs_config = HE_80_MCS0_11;
10038 ret = sta_set_he_mcs(dut, intf, mcs_config);
10039 if (ret) {
10040 sigma_dut_print(dut, DUT_MSG_ERROR,
10041 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
10042 mcs, mcs_config, ret);
10043 }
10044 }
10045 snprintf(buf, sizeof(buf),
10046 "iwpriv %s set_11ax_rate 0x%03x",
10047 intf, ratecode);
10048 if (system(buf) != 0) {
10049 sigma_dut_print(dut, DUT_MSG_ERROR,
10050 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
10051 ratecode);
10052 }
10053 } else {
10054 sigma_dut_print(dut, DUT_MSG_ERROR,
10055 "MCS_FixedRate: HE MCS %d not supported",
10056 mcs);
10057 }
10058#else /* NL80211_SUPPORT */
10059 sigma_dut_print(dut, DUT_MSG_ERROR,
10060 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
10061#endif /* NL80211_SUPPORT */
10062 }
10063
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010064 val = get_param(cmd, "opt_md_notif_ie");
10065 if (val) {
10066 char *result = NULL;
10067 char delim[] = ";";
10068 char token[30];
10069 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010070 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010071
Peng Xub8fc5cc2017-05-10 17:27:28 -070010072 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010073 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010074
10075 /* Extract the NSS information */
10076 if (result) {
10077 value = atoi(result);
10078 switch (value) {
10079 case 1:
10080 config_val = 1;
10081 break;
10082 case 2:
10083 config_val = 3;
10084 break;
10085 case 3:
10086 config_val = 7;
10087 break;
10088 case 4:
10089 config_val = 15;
10090 break;
10091 default:
10092 config_val = 3;
10093 break;
10094 }
10095
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010096 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
10097 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010098
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010099 }
10100
10101 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010102 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010103 if (result) {
10104 value = atoi(result);
10105 switch (value) {
10106 case 20:
10107 config_val = 0;
10108 break;
10109 case 40:
10110 config_val = 1;
10111 break;
10112 case 80:
10113 config_val = 2;
10114 break;
10115 case 160:
10116 config_val = 3;
10117 break;
10118 default:
10119 config_val = 2;
10120 break;
10121 }
10122
10123 dut->chwidth = config_val;
10124
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010125 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010126 }
10127
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010128 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010129 }
10130
10131 val = get_param(cmd, "nss_mcs_cap");
10132 if (val) {
10133 int nss, mcs;
10134 char token[20];
10135 char *result = NULL;
10136 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010137 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010138
Peng Xub8fc5cc2017-05-10 17:27:28 -070010139 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010140 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010141 if (!result) {
10142 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010143 "NSS not specified");
10144 send_resp(dut, conn, SIGMA_ERROR,
10145 "errorCode,NSS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +030010146 return STATUS_SENT_ERROR;
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010147 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010148 nss = atoi(result);
10149
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010150 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -070010151 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010152
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010153 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010154 if (result == NULL) {
10155 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010156 "MCS not specified");
10157 send_resp(dut, conn, SIGMA_ERROR,
10158 "errorCode,MCS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +030010159 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010160 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010161 result = strtok_r(result, "-", &saveptr);
10162 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010163 if (!result) {
10164 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010165 "MCS not specified");
10166 send_resp(dut, conn, SIGMA_ERROR,
10167 "errorCode,MCS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +030010168 return STATUS_SENT_ERROR;
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010169 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010170 mcs = atoi(result);
10171
Arif Hussaina37e9552018-06-20 17:05:59 -070010172 if (program && strcasecmp(program, "HE") == 0) {
10173#ifdef NL80211_SUPPORT
10174 enum he_mcs_config mcs_config;
10175 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010176
Arif Hussaina37e9552018-06-20 17:05:59 -070010177 if (mcs >= 0 && mcs <= 7) {
10178 mcs_config = HE_80_MCS0_7;
10179 } else if (mcs > 7 && mcs <= 9) {
10180 mcs_config = HE_80_MCS0_9;
10181 } else if (mcs > 9 && mcs <= 11) {
10182 mcs_config = HE_80_MCS0_11;
10183 } else {
10184 sigma_dut_print(dut, DUT_MSG_ERROR,
10185 "nss_mcs_cap: HE: Invalid mcs: %d",
10186 mcs);
10187 send_resp(dut, conn, SIGMA_ERROR,
10188 "errorCode,Invalid MCS");
Jouni Malinen224e3902021-06-09 16:41:27 +030010189 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010190 }
Arif Hussaina37e9552018-06-20 17:05:59 -070010191
10192 ret = sta_set_he_mcs(dut, intf, mcs_config);
10193 if (ret) {
10194 sigma_dut_print(dut, DUT_MSG_ERROR,
10195 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
10196 mcs_config, ret);
10197 send_resp(dut, conn, SIGMA_ERROR,
10198 "errorCode,Failed to set MCS");
Jouni Malinen224e3902021-06-09 16:41:27 +030010199 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010200 }
Arif Hussaina37e9552018-06-20 17:05:59 -070010201#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010202 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010203 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
10204#endif /* NL80211_SUPPORT */
10205 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010206 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -070010207
10208 switch (nss) {
10209 case 1:
10210 switch (mcs) {
10211 case 7:
10212 vht_mcsmap = 0xfffc;
10213 break;
10214 case 8:
10215 vht_mcsmap = 0xfffd;
10216 break;
10217 case 9:
10218 vht_mcsmap = 0xfffe;
10219 break;
10220 default:
10221 vht_mcsmap = 0xfffe;
10222 break;
10223 }
10224 break;
10225 case 2:
10226 switch (mcs) {
10227 case 7:
10228 vht_mcsmap = 0xfff0;
10229 break;
10230 case 8:
10231 vht_mcsmap = 0xfff5;
10232 break;
10233 case 9:
10234 vht_mcsmap = 0xfffa;
10235 break;
10236 default:
10237 vht_mcsmap = 0xfffa;
10238 break;
10239 }
10240 break;
10241 case 3:
10242 switch (mcs) {
10243 case 7:
10244 vht_mcsmap = 0xffc0;
10245 break;
10246 case 8:
10247 vht_mcsmap = 0xffd5;
10248 break;
10249 case 9:
10250 vht_mcsmap = 0xffea;
10251 break;
10252 default:
10253 vht_mcsmap = 0xffea;
10254 break;
10255 }
10256 break;
10257 default:
10258 vht_mcsmap = 0xffea;
10259 break;
10260 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010261 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010262 }
10263 }
10264
10265 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
10266
10267 val = get_param(cmd, "Vht_tkip");
10268 if (val)
10269 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
10270
10271 val = get_param(cmd, "Vht_wep");
10272 if (val)
10273 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
10274
10275 if (tkip != -1 || wep != -1) {
10276 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010277 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010278 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010279 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010280 } else {
Jouni Malinen224e3902021-06-09 16:41:27 +030010281 send_resp(dut, conn, SIGMA_ERROR,
10282 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
10283 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010284 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010285 }
10286
Kiran Kumar Lokere09dbcef2021-08-09 00:01:41 -070010287 val = get_param(cmd, "TWTSchedSTASupport");
10288 if (val) {
10289 int set_val;
10290
10291 switch (get_driver_type(dut)) {
10292 case DRIVER_WCN:
10293 if (strcasecmp(val, "Enable") == 0) {
10294 set_val = 1;
10295 } else if (strcasecmp(val, "Disable") == 0) {
10296 set_val = 0;
10297 } else {
10298 send_resp(dut, conn, SIGMA_ERROR,
10299 "ErrorCode,Invalid TWTSchedSTASupport");
10300 return STATUS_SENT_ERROR;
10301 }
10302
10303 if (sta_set_bcast_twt_support(dut, intf, set_val)) {
10304 send_resp(dut, conn, SIGMA_ERROR,
10305 "ErrorCode,Failed to set TWTSchedSTASupport");
10306 return STATUS_SENT_ERROR;
10307 }
10308 break;
10309 default:
10310 sigma_dut_print(dut, DUT_MSG_ERROR,
10311 "Setting TWTSchedSTASupport not supported");
10312 break;
10313 }
10314 }
10315
10316 val = get_param(cmd, "MBSSID_RxCtrl");
10317 if (val) {
10318 int set_val;
10319
10320 switch (get_driver_type(dut)) {
10321 case DRIVER_WCN:
10322 if (strcasecmp(val, "Enable") == 0) {
10323 set_val = 1;
10324 } else if (strcasecmp(val, "Disable") == 0) {
10325 set_val = 0;
10326 } else {
10327 send_resp(dut, conn, SIGMA_ERROR,
10328 "ErrorCode,Invalid MBSSID_RxCtrl");
10329 return STATUS_SENT_ERROR;
10330 }
10331
10332 if (sta_set_rx_ctrl_multi_bss(dut, intf, set_val)) {
10333 send_resp(dut, conn, SIGMA_ERROR,
10334 "ErrorCode,Failed to set MBSSID_RxCtrl");
10335 return STATUS_SENT_ERROR;
10336 }
10337 break;
10338 default:
10339 sigma_dut_print(dut, DUT_MSG_ERROR,
10340 "Setting MBSSID_RxCtrl not supported");
10341 break;
10342 }
10343 }
10344
Arif Hussain55f00da2018-07-03 08:28:26 -070010345 val = get_param(cmd, "txBandwidth");
10346 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010347 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -070010348 case DRIVER_WCN:
10349 if (wcn_sta_set_width(dut, intf, val) < 0) {
10350 send_resp(dut, conn, SIGMA_ERROR,
10351 "ErrorCode,Failed to set txBandwidth");
Jouni Malinen224e3902021-06-09 16:41:27 +030010352 return STATUS_SENT_ERROR;
Arif Hussain55f00da2018-07-03 08:28:26 -070010353 }
10354 break;
10355 case DRIVER_ATHEROS:
10356 if (ath_set_width(dut, conn, intf, val) < 0) {
10357 send_resp(dut, conn, SIGMA_ERROR,
10358 "ErrorCode,Failed to set txBandwidth");
Jouni Malinen224e3902021-06-09 16:41:27 +030010359 return STATUS_SENT_ERROR;
Arif Hussain55f00da2018-07-03 08:28:26 -070010360 }
10361 break;
10362 default:
10363 sigma_dut_print(dut, DUT_MSG_ERROR,
10364 "Setting txBandwidth not supported");
10365 break;
10366 }
10367 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010368
Arif Hussain9765f7d2018-07-03 08:28:26 -070010369 val = get_param(cmd, "BeamformeeSTS");
10370 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -070010371 if (sta_set_tx_beamformee(dut, intf, 1)) {
10372 send_resp(dut, conn, SIGMA_ERROR,
10373 "ErrorCode,Failed to set TX beamformee enable");
Jouni Malinen224e3902021-06-09 16:41:27 +030010374 return STATUS_SENT_ERROR;
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -070010375 }
10376
Arif Hussain9765f7d2018-07-03 08:28:26 -070010377 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
10378 send_resp(dut, conn, SIGMA_ERROR,
10379 "ErrorCode,Failed to set BeamformeeSTS");
Jouni Malinen224e3902021-06-09 16:41:27 +030010380 return STATUS_SENT_ERROR;
Arif Hussain9765f7d2018-07-03 08:28:26 -070010381 }
10382 }
10383
Arif Hussain68d23f52018-07-11 13:39:08 -070010384 val = get_param(cmd, "Trig_MAC_Padding_Dur");
10385 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -070010386#ifdef NL80211_SUPPORT
10387 enum qca_wlan_he_mac_padding_dur set_val;
10388
10389 switch (atoi(val)) {
10390 case 16:
10391 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
10392 break;
10393 case 8:
10394 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
10395 break;
10396 default:
10397 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
10398 break;
10399 }
10400 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -070010401 send_resp(dut, conn, SIGMA_ERROR,
10402 "ErrorCode,Failed to set MAC padding duration");
Jouni Malinen224e3902021-06-09 16:41:27 +030010403 return STATUS_SENT_ERROR;
Arif Hussain68d23f52018-07-11 13:39:08 -070010404 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -070010405#else /* NL80211_SUPPORT */
10406 sigma_dut_print(dut, DUT_MSG_ERROR,
10407 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
10408#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -070010409 }
10410
Arif Hussain480d5f42019-03-12 14:40:42 -070010411 val = get_param(cmd, "TWT_ReqSupport");
10412 if (val) {
10413 int set_val;
10414
10415 if (strcasecmp(val, "Enable") == 0) {
10416 set_val = 1;
10417 } else if (strcasecmp(val, "Disable") == 0) {
10418 set_val = 0;
10419 } else {
10420 send_resp(dut, conn, SIGMA_ERROR,
10421 "ErrorCode,Invalid TWT_ReqSupport");
Jouni Malinen224e3902021-06-09 16:41:27 +030010422 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070010423 }
10424
10425 if (sta_set_twt_req_support(dut, intf, set_val)) {
10426 sigma_dut_print(dut, DUT_MSG_ERROR,
10427 "Failed to set TWT req support %d",
10428 set_val);
10429 send_resp(dut, conn, SIGMA_ERROR,
10430 "ErrorCode,Failed to set TWT_ReqSupport");
Jouni Malinen224e3902021-06-09 16:41:27 +030010431 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070010432 }
10433 }
10434
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -070010435 val = get_param(cmd, "PreamblePunctRx");
10436 if (val && get_driver_type(dut) == DRIVER_WCN) {
10437 int set_val;
10438
10439 if (strcasecmp(val, "Enable") == 0) {
10440 set_val = 1;
10441 } else if (strcasecmp(val, "Disable") == 0) {
10442 set_val = 0;
10443 } else {
10444 send_resp(dut, conn, SIGMA_ERROR,
10445 "ErrorCode,Invalid PreamblePunctRx");
10446 return STATUS_SENT_ERROR;
10447 }
10448
10449 if (sta_set_punctured_preamble_rx(dut, intf, set_val)) {
10450 sigma_dut_print(dut, DUT_MSG_ERROR,
10451 "Failed to set PreamblePunctRx support %d",
10452 set_val);
10453 send_resp(dut, conn, SIGMA_ERROR,
10454 "ErrorCode,Failed to set PreamblePunctRx");
10455 return STATUS_SENT_ERROR;
10456 }
10457 }
10458
Srinivas Girigowda0525e292020-11-12 13:28:21 -080010459 val = get_param(cmd, "FullBW_ULMUMIMO");
10460 if (val) {
10461 int set_val;
10462
10463 if (strcasecmp(val, "Enable") == 0) {
10464 set_val = 1;
10465 } else if (strcasecmp(val, "Disable") == 0) {
10466 set_val = 0;
10467 } else {
10468 send_resp(dut, conn, SIGMA_ERROR,
10469 "ErrorCode,Invalid FullBW_ULMUMIMO");
10470 return STATUS_SENT_ERROR;
10471 }
10472
10473 if (sta_set_fullbw_ulmumimo(dut, intf, set_val)) {
10474 sigma_dut_print(dut, DUT_MSG_ERROR,
10475 "Failed to set FullBW_ULMUMIMO %d",
10476 set_val);
10477 send_resp(dut, conn, SIGMA_ERROR,
10478 "ErrorCode,Failed to set FullBW_ULMUMIMO");
10479 return STATUS_SENT_ERROR;
10480 }
10481 }
10482
Srinivas Girigowda6707f032020-10-26 15:24:46 -070010483 val = get_param(cmd, "TWTInfoFrameTx");
10484 if (val) {
10485 if (strcasecmp(val, "Enable") == 0) {
10486 /* No-op */
10487 } else if (strcasecmp(val, "Disable") == 0) {
10488 /* No-op */
10489 } else {
10490 send_resp(dut, conn, SIGMA_ERROR,
10491 "ErrorCode,Invalid TWTInfoFrameTx");
10492 return STATUS_SENT_ERROR;
10493 }
10494 }
10495
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -070010496 val = get_param(cmd, "MU_EDCA");
10497 if (val && (strcasecmp(val, "Override") == 0)) {
10498 if (sta_set_mu_edca_override(dut, intf, 1)) {
10499 send_resp(dut, conn, SIGMA_ERROR,
10500 "ErrorCode,Failed to set MU EDCA override");
Jouni Malinen224e3902021-06-09 16:41:27 +030010501 return STATUS_SENT_ERROR;
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -070010502 }
10503 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010504
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -070010505 val = get_param(cmd, "PPDUTxType");
10506 if (val && strcasecmp(val, "ER-SU") == 0) {
10507 if (sta_set_er_su_ppdu_type_tx(dut, intf, 1)) {
10508 send_resp(dut, conn, SIGMA_ERROR,
10509 "ErrorCode,Failed to set ER-SU PPDU type Tx");
10510 return STATUS_SENT_ERROR;
10511 }
10512 }
10513
10514 val = get_param(cmd, "RUAllocTone");
10515 if (val && strcasecmp(val, "242") == 0) {
10516 if (sta_set_ru_242_tone_tx(dut, intf, 1)) {
10517 send_resp(dut, conn, SIGMA_ERROR,
10518 "ErrorCode,Failed to set RU 242 tone Tx");
10519 return STATUS_SENT_ERROR;
10520 }
10521 }
10522
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -070010523 val = get_param(cmd, "OMControl");
10524 if (val) {
10525 int set_val = 1;
10526
10527 if (strcasecmp(val, "Enable") == 0)
10528 set_val = 1;
10529 else if (strcasecmp(val, "Disable") == 0)
10530 set_val = 0;
10531
10532 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
10533 send_resp(dut, conn, SIGMA_ERROR,
10534 "ErrorCode,Failed to set OM ctrl supp");
Jouni Malinen224e3902021-06-09 16:41:27 +030010535 return STATUS_SENT_ERROR;
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -070010536 }
10537 }
10538
Kiran Kumar Lokere4f2d4b02021-04-01 00:07:39 -070010539 val = get_param(cmd, "BSSMaxIdlePeriod");
10540 if (val && sta_set_bss_max_idle_period(dut, intf, atoi(val))) {
10541 send_resp(dut, conn, SIGMA_ERROR,
10542 "ErrorCode,Failed to set BSS max idle period");
10543 return STATUS_SENT_ERROR;
10544 }
10545
Kiran Kumar Lokere07ad92b2021-08-09 00:27:14 -070010546 val = get_param(cmd, "BSS_max_idle");
10547 if (val) {
10548 int set_val = 0;
10549
10550 if (strcasecmp(val, "Enable") == 0)
10551 set_val = 1;
10552 else if (strcasecmp(val, "Disable") == 0)
10553 set_val = 0;
10554 if (sta_set_bss_max_idle_support(dut, intf, set_val)) {
10555 send_resp(dut, conn, SIGMA_ERROR,
10556 "ErrorCode,Failed to set BSS max idle support");
10557 return STATUS_SENT_ERROR;
10558 }
10559 }
10560
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010561 val = get_param(cmd, "ADDBAResp_BufSize");
10562 if (val) {
10563 int buf_size;
10564
10565 if (strcasecmp(val, "gt64") == 0)
10566 buf_size = 256;
10567 else
10568 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010569 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010570 sta_set_addba_buf_size(dut, intf, buf_size)) {
10571 send_resp(dut, conn, SIGMA_ERROR,
10572 "ErrorCode,set addbaresp_buff_size failed");
Jouni Malinen224e3902021-06-09 16:41:27 +030010573 return STATUS_SENT_ERROR;
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010574 }
10575 }
10576
10577 val = get_param(cmd, "ADDBAReq_BufSize");
10578 if (val) {
10579 int buf_size;
10580
10581 if (strcasecmp(val, "gt64") == 0)
10582 buf_size = 256;
10583 else
10584 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010585 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010586 sta_set_addba_buf_size(dut, intf, buf_size)) {
10587 send_resp(dut, conn, SIGMA_ERROR,
10588 "ErrorCode,set addbareq_buff_size failed");
Jouni Malinen224e3902021-06-09 16:41:27 +030010589 return STATUS_SENT_ERROR;
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010590 }
10591 }
10592
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010593 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
10594}
10595
10596
10597static int sta_set_wireless_60g(struct sigma_dut *dut,
10598 struct sigma_conn *conn,
10599 struct sigma_cmd *cmd)
10600{
10601 const char *dev_role = get_param(cmd, "DevRole");
10602
10603 if (!dev_role) {
10604 send_resp(dut, conn, SIGMA_INVALID,
10605 "ErrorCode,DevRole not specified");
10606 return 0;
10607 }
10608
10609 if (strcasecmp(dev_role, "PCP") == 0)
10610 return sta_set_60g_pcp(dut, conn, cmd);
10611 if (strcasecmp(dev_role, "STA") == 0)
10612 return sta_set_60g_sta(dut, conn, cmd);
10613 send_resp(dut, conn, SIGMA_INVALID,
10614 "ErrorCode,DevRole not supported");
10615 return 0;
10616}
10617
10618
Ankita Bajaj0d5825b2017-10-25 16:20:17 +053010619static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
10620 struct sigma_cmd *cmd)
10621{
10622 int status;
10623 const char *intf = get_param(cmd, "Interface");
10624 const char *val = get_param(cmd, "DevRole");
10625
10626 if (val && strcasecmp(val, "STA-CFON") == 0) {
10627 status = sta_cfon_set_wireless(dut, conn, cmd);
10628 if (status)
10629 return status;
10630 }
10631 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
10632}
10633
10634
Jouni Malinen67433fc2020-06-26 22:50:33 +030010635static enum sigma_cmd_result
10636sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
10637 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +053010638{
10639 const char *intf = get_param(cmd, "Interface");
10640 const char *val;
10641
10642 val = get_param(cmd, "ocvc");
10643 if (val)
10644 dut->ocvc = atoi(val);
10645
Jouni Malinen67433fc2020-06-26 22:50:33 +030010646 val = get_param(cmd, "ClientPrivacy");
Veerendranath Jakkam47867202020-12-21 01:53:52 +053010647 if (val && dut->client_privacy != atoi(val) &&
10648 sta_set_client_privacy(dut, conn, intf, atoi(val))) {
10649 send_resp(dut, conn, SIGMA_ERROR,
10650 "errorCode,Failed to configure random MAC address use");
10651 return STATUS_SENT_ERROR;
Jouni Malinen67433fc2020-06-26 22:50:33 +030010652 }
10653
Vamsi Krishnac1633d22020-05-06 18:31:21 +053010654 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
10655}
10656
10657
Jouni Malinenf7222712019-06-13 01:50:21 +030010658static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
10659 struct sigma_conn *conn,
10660 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010661{
10662 const char *val;
10663
10664 val = get_param(cmd, "Program");
10665 if (val) {
10666 if (strcasecmp(val, "11n") == 0)
10667 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -080010668 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010669 return cmd_sta_set_wireless_vht(dut, conn, cmd);
10670 if (strcasecmp(val, "60ghz") == 0)
10671 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +053010672 if (strcasecmp(val, "OCE") == 0)
10673 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +020010674 /* sta_set_wireless in WPS program is only used for 60G */
10675 if (is_60g_sigma_dut(dut))
10676 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +053010677 if (strcasecmp(val, "WPA3") == 0)
10678 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010679 send_resp(dut, conn, SIGMA_ERROR,
10680 "ErrorCode,Program value not supported");
10681 } else {
10682 send_resp(dut, conn, SIGMA_ERROR,
10683 "ErrorCode,Program argument not available");
10684 }
10685
10686 return 0;
10687}
10688
10689
10690static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
10691 int tid)
10692{
10693 char buf[100];
10694 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
10695
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +053010696 if (tid < 0 ||
10697 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
10698 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
10699 return;
10700 }
10701
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010702 /*
10703 * Two ways to ensure that addba request with a
10704 * non zero TID could be sent out. EV 117296
10705 */
10706 snprintf(buf, sizeof(buf),
10707 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
10708 tid);
10709 if (system(buf) != 0) {
10710 sigma_dut_print(dut, DUT_MSG_ERROR,
10711 "Ping did not send out");
10712 }
10713
10714 snprintf(buf, sizeof(buf),
10715 "iwconfig %s | grep Access | awk '{print $6}' > %s",
10716 intf, VI_QOS_TMP_FILE);
10717 if (system(buf) != 0)
10718 return;
10719
10720 snprintf(buf, sizeof(buf),
10721 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
10722 intf, VI_QOS_TMP_FILE);
10723 if (system(buf) != 0)
10724 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
10725
10726 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
10727 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
10728 if (system(buf) != 0) {
10729 sigma_dut_print(dut, DUT_MSG_ERROR,
10730 "VI_QOS_TEMP_FILE generation error failed");
10731 }
10732 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
10733 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
10734 if (system(buf) != 0) {
10735 sigma_dut_print(dut, DUT_MSG_ERROR,
10736 "VI_QOS_FILE generation failed");
10737 }
10738
10739 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
10740 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
10741 if (system(buf) != 0) {
10742 sigma_dut_print(dut, DUT_MSG_ERROR,
10743 "VI_QOS_FILE generation failed");
10744 }
10745
10746 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
10747 if (system(buf) != 0) {
10748 }
10749}
10750
10751
10752static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
10753 struct sigma_cmd *cmd)
10754{
10755 const char *intf = get_param(cmd, "Interface");
10756 const char *val;
10757 int tid = 0;
10758 char buf[100];
10759
10760 val = get_param(cmd, "TID");
10761 if (val) {
10762 tid = atoi(val);
10763 if (tid)
10764 ath_sta_inject_frame(dut, intf, tid);
10765 }
10766
10767 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010768 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010769
10770 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
10771 if (system(buf) != 0) {
10772 sigma_dut_print(dut, DUT_MSG_ERROR,
10773 "wifitool senddelba failed");
10774 }
10775
10776 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
10777 if (system(buf) != 0) {
10778 sigma_dut_print(dut, DUT_MSG_ERROR,
10779 "wifitool sendaddba failed");
10780 }
10781
10782 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
10783
10784 return 1;
10785}
10786
10787
Lior David9981b512017-01-20 13:16:40 +020010788#ifdef __linux__
10789
10790static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
10791 int agg_size)
10792{
10793 char dir[128], buf[128];
10794 FILE *f;
10795 regex_t re;
10796 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +030010797 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +020010798
10799 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
10800 sigma_dut_print(dut, DUT_MSG_ERROR,
10801 "failed to get wil6210 debugfs dir");
10802 return -1;
10803 }
10804
Jouni Malinen3aa72862019-05-29 23:14:51 +030010805 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
10806 if (res < 0 || res >= sizeof(buf))
10807 return -1;
Lior David9981b512017-01-20 13:16:40 +020010808 f = fopen(buf, "r");
10809 if (!f) {
10810 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010811 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +030010812 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
10813 if (res < 0 || res >= sizeof(buf))
10814 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010815 f = fopen(buf, "r");
10816 if (!f) {
10817 sigma_dut_print(dut, DUT_MSG_ERROR,
10818 "failed to open: %s", buf);
10819 return -1;
10820 }
Lior David9981b512017-01-20 13:16:40 +020010821 }
10822
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010823 /* can be either VRING tx... or RING... */
10824 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +020010825 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
10826 goto out;
10827 }
10828
10829 /* find TX VRING for the mac address */
10830 found = 0;
10831 while (fgets(buf, sizeof(buf), f)) {
10832 if (strcasestr(buf, dest_mac)) {
10833 found = 1;
10834 break;
10835 }
10836 }
10837
10838 if (!found) {
10839 sigma_dut_print(dut, DUT_MSG_ERROR,
10840 "no TX VRING for %s", dest_mac);
10841 goto out;
10842 }
10843
10844 /* extract VRING ID, "VRING tx_<id> = {" */
10845 if (!fgets(buf, sizeof(buf), f)) {
10846 sigma_dut_print(dut, DUT_MSG_ERROR,
10847 "no VRING start line for %s", dest_mac);
10848 goto out;
10849 }
10850
10851 rc = regexec(&re, buf, 2, m, 0);
10852 regfree(&re);
10853 if (rc || m[1].rm_so < 0) {
10854 sigma_dut_print(dut, DUT_MSG_ERROR,
10855 "no VRING TX ID for %s", dest_mac);
10856 goto out;
10857 }
10858 buf[m[1].rm_eo] = 0;
10859 vring_id = atoi(&buf[m[1].rm_so]);
10860
10861 /* send the addba command */
10862 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +030010863 res = snprintf(buf, sizeof(buf), "%s/back", dir);
10864 if (res < 0 || res >= sizeof(buf))
10865 return -1;
Lior David9981b512017-01-20 13:16:40 +020010866 f = fopen(buf, "w");
10867 if (!f) {
10868 sigma_dut_print(dut, DUT_MSG_ERROR,
10869 "failed to open: %s", buf);
10870 return -1;
10871 }
10872
10873 fprintf(f, "add %d %d\n", vring_id, agg_size);
10874
10875 ret = 0;
10876
10877out:
10878 fclose(f);
10879
10880 return ret;
10881}
10882
10883
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020010884int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10885 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010886{
10887 const char *val;
10888 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010889
10890 val = get_param(cmd, "TID");
10891 if (val) {
10892 tid = atoi(val);
10893 if (tid != 0) {
10894 sigma_dut_print(dut, DUT_MSG_ERROR,
10895 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
10896 tid);
10897 }
10898 }
10899
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020010900 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010901 if (!val) {
10902 sigma_dut_print(dut, DUT_MSG_ERROR,
10903 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020010904 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010905 }
10906
Lior David9981b512017-01-20 13:16:40 +020010907 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010908 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010909
10910 return 1;
10911}
10912
Lior David9981b512017-01-20 13:16:40 +020010913#endif /* __linux__ */
10914
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010915
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010916static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
10917 struct sigma_cmd *cmd)
10918{
10919#ifdef NL80211_SUPPORT
10920 const char *intf = get_param(cmd, "Interface");
10921 const char *val;
10922 int tid = -1;
10923 int bufsize = 64;
10924 struct nl_msg *msg;
10925 int ret = 0;
10926 struct nlattr *params;
10927 int ifindex;
10928
10929 val = get_param(cmd, "TID");
10930 if (val)
10931 tid = atoi(val);
10932
10933 if (tid == -1) {
10934 send_resp(dut, conn, SIGMA_ERROR,
10935 "ErrorCode,sta_send_addba tid invalid");
10936 return 0;
10937 }
10938
10939 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
10940
10941 ifindex = if_nametoindex(intf);
10942 if (ifindex == 0) {
10943 sigma_dut_print(dut, DUT_MSG_ERROR,
10944 "%s: Index for interface %s failed",
10945 __func__, intf);
10946 send_resp(dut, conn, SIGMA_ERROR,
10947 "ErrorCode,sta_send_addba interface invalid");
10948 return 0;
10949 }
10950
10951 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10952 NL80211_CMD_VENDOR)) ||
10953 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
10954 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10955 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10956 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
10957 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10958 nla_put_u8(msg,
10959 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
10960 QCA_WLAN_ADD_BA) ||
10961 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
10962 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -070010963 nla_put_u16(msg,
10964 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
10965 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010966 sigma_dut_print(dut, DUT_MSG_ERROR,
10967 "%s: err in adding vendor_cmd and vendor_data",
10968 __func__);
10969 nlmsg_free(msg);
10970 send_resp(dut, conn, SIGMA_ERROR,
10971 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
10972 return 0;
10973 }
10974 nla_nest_end(msg, params);
10975
10976 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
10977 if (ret) {
10978 sigma_dut_print(dut, DUT_MSG_ERROR,
10979 "%s: err in send_and_recv_msgs, ret=%d",
10980 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +053010981 if (ret == -EOPNOTSUPP)
10982 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010983 send_resp(dut, conn, SIGMA_ERROR,
10984 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
10985 return 0;
10986 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010987#else /* NL80211_SUPPORT */
10988 sigma_dut_print(dut, DUT_MSG_ERROR,
10989 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010990#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +053010991
10992 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010993}
10994
10995
Jouni Malinenf7222712019-06-13 01:50:21 +030010996static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
10997 struct sigma_conn *conn,
10998 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010999{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011000 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011001 case DRIVER_ATHEROS:
11002 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080011003 case DRIVER_WCN:
11004 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +020011005#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011006 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020011007 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +020011008#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011009 default:
11010 /*
11011 * There is no driver specific implementation for other drivers.
11012 * Ignore the command and report COMPLETE since the following
11013 * throughput test operation will end up sending ADDBA anyway.
11014 */
11015 return 1;
11016 }
11017}
11018
11019
11020int inject_eth_frame(int s, const void *data, size_t len,
11021 unsigned short ethtype, char *dst, char *src)
11022{
11023 struct iovec iov[4] = {
11024 {
11025 .iov_base = dst,
11026 .iov_len = ETH_ALEN,
11027 },
11028 {
11029 .iov_base = src,
11030 .iov_len = ETH_ALEN,
11031 },
11032 {
11033 .iov_base = &ethtype,
11034 .iov_len = sizeof(unsigned short),
11035 },
11036 {
11037 .iov_base = (void *) data,
11038 .iov_len = len,
11039 }
11040 };
11041 struct msghdr msg = {
11042 .msg_name = NULL,
11043 .msg_namelen = 0,
11044 .msg_iov = iov,
11045 .msg_iovlen = 4,
11046 .msg_control = NULL,
11047 .msg_controllen = 0,
11048 .msg_flags = 0,
11049 };
11050
11051 return sendmsg(s, &msg, 0);
11052}
11053
11054#if defined(__linux__) || defined(__QNXNTO__)
11055
11056int inject_frame(int s, const void *data, size_t len, int encrypt)
11057{
11058#define IEEE80211_RADIOTAP_F_WEP 0x04
11059#define IEEE80211_RADIOTAP_F_FRAG 0x08
11060 unsigned char rtap_hdr[] = {
11061 0x00, 0x00, /* radiotap version */
11062 0x0e, 0x00, /* radiotap length */
11063 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
11064 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
11065 0x00, /* padding */
11066 0x00, 0x00, /* RX and TX flags to indicate that */
11067 0x00, 0x00, /* this is the injected frame directly */
11068 };
11069 struct iovec iov[2] = {
11070 {
11071 .iov_base = &rtap_hdr,
11072 .iov_len = sizeof(rtap_hdr),
11073 },
11074 {
11075 .iov_base = (void *) data,
11076 .iov_len = len,
11077 }
11078 };
11079 struct msghdr msg = {
11080 .msg_name = NULL,
11081 .msg_namelen = 0,
11082 .msg_iov = iov,
11083 .msg_iovlen = 2,
11084 .msg_control = NULL,
11085 .msg_controllen = 0,
11086 .msg_flags = 0,
11087 };
11088
11089 if (encrypt)
11090 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
11091
11092 return sendmsg(s, &msg, 0);
11093}
11094
11095
11096int open_monitor(const char *ifname)
11097{
11098#ifdef __QNXNTO__
11099 struct sockaddr_dl ll;
11100 int s;
11101
11102 memset(&ll, 0, sizeof(ll));
11103 ll.sdl_family = AF_LINK;
11104 ll.sdl_index = if_nametoindex(ifname);
11105 if (ll.sdl_index == 0) {
11106 perror("if_nametoindex");
11107 return -1;
11108 }
11109 s = socket(PF_INET, SOCK_RAW, 0);
11110#else /* __QNXNTO__ */
11111 struct sockaddr_ll ll;
11112 int s;
11113
11114 memset(&ll, 0, sizeof(ll));
11115 ll.sll_family = AF_PACKET;
11116 ll.sll_ifindex = if_nametoindex(ifname);
11117 if (ll.sll_ifindex == 0) {
11118 perror("if_nametoindex");
11119 return -1;
11120 }
11121 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
11122#endif /* __QNXNTO__ */
11123 if (s < 0) {
11124 perror("socket[PF_PACKET,SOCK_RAW]");
11125 return -1;
11126 }
11127
11128 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
11129 perror("monitor socket bind");
11130 close(s);
11131 return -1;
11132 }
11133
11134 return s;
11135}
11136
11137
11138static int hex2num(char c)
11139{
11140 if (c >= '0' && c <= '9')
11141 return c - '0';
11142 if (c >= 'a' && c <= 'f')
11143 return c - 'a' + 10;
11144 if (c >= 'A' && c <= 'F')
11145 return c - 'A' + 10;
11146 return -1;
11147}
11148
11149
11150int hwaddr_aton(const char *txt, unsigned char *addr)
11151{
11152 int i;
11153
11154 for (i = 0; i < 6; i++) {
11155 int a, b;
11156
11157 a = hex2num(*txt++);
11158 if (a < 0)
11159 return -1;
11160 b = hex2num(*txt++);
11161 if (b < 0)
11162 return -1;
11163 *addr++ = (a << 4) | b;
11164 if (i < 5 && *txt++ != ':')
11165 return -1;
11166 }
11167
11168 return 0;
11169}
11170
11171#endif /* defined(__linux__) || defined(__QNXNTO__) */
11172
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011173
11174#ifdef NL80211_SUPPORT
11175static int nl80211_send_frame_cmd(struct sigma_dut *dut, const char *intf,
11176 const u8 *data, size_t data_len, int freq)
11177{
11178 struct nl_msg *msg;
11179 int ret = 0;
11180 int ifindex;
11181
11182 ifindex = if_nametoindex(intf);
11183 if (ifindex == 0) {
11184 sigma_dut_print(dut, DUT_MSG_ERROR,
11185 "%s: Index for interface %s failed",
11186 __func__, intf);
11187 return -1;
11188 }
11189
11190 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
11191 NL80211_CMD_FRAME)) ||
11192 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11193 nla_put(msg, NL80211_ATTR_FRAME, data_len, data)) {
11194 sigma_dut_print(dut, DUT_MSG_ERROR,
11195 "%s: Error in adding NL80211_CMD_FRAME",
11196 __func__);
11197 nlmsg_free(msg);
11198 return -1;
11199 }
11200
11201 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
11202 if (ret) {
11203 sigma_dut_print(dut, DUT_MSG_ERROR,
11204 "nl80211: Frame command failed: ret=%d (%s) req=%u",
11205 ret, strerror(-ret), freq);
11206 return -1;
11207 }
11208
11209 return 0;
11210}
11211#endif /* NL80211_SUPPORT */
11212
11213
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011214enum send_frame_type {
11215 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
11216};
11217enum send_frame_protection {
11218 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
11219};
11220
11221
11222static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011223 const char *intf, enum send_frame_type frame,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011224 enum send_frame_protection protected,
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011225 const char *dest, int use_monitor)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011226{
11227#ifdef __linux__
11228 unsigned char buf[1000], *pos;
11229 int s, res;
11230 char bssid[20], addr[20];
11231 char result[32], ssid[100];
11232 size_t ssid_len;
11233
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011234 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011235 sizeof(result)) < 0 ||
11236 strncmp(result, "COMPLETED", 9) != 0) {
11237 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
11238 return 0;
11239 }
11240
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011241 if (get_wpa_status(get_station_ifname(dut), "bssid",
11242 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011243 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
11244 "current BSSID");
11245 return 0;
11246 }
11247
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011248 if (get_wpa_status(get_station_ifname(dut), "address",
11249 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011250 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
11251 "own MAC address");
11252 return 0;
11253 }
11254
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011255 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011256 < 0) {
11257 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
11258 "current SSID");
11259 return 0;
11260 }
11261 ssid_len = strlen(ssid);
11262
11263 pos = buf;
11264
11265 /* Frame Control */
11266 switch (frame) {
11267 case DISASSOC:
11268 *pos++ = 0xa0;
11269 break;
11270 case DEAUTH:
11271 *pos++ = 0xc0;
11272 break;
11273 case SAQUERY:
11274 *pos++ = 0xd0;
11275 break;
11276 case AUTH:
11277 *pos++ = 0xb0;
11278 break;
11279 case ASSOCREQ:
11280 *pos++ = 0x00;
11281 break;
11282 case REASSOCREQ:
11283 *pos++ = 0x20;
11284 break;
11285 case DLS_REQ:
11286 *pos++ = 0xd0;
11287 break;
11288 }
11289
11290 if (protected == INCORRECT_KEY)
11291 *pos++ = 0x40; /* Set Protected field to 1 */
11292 else
11293 *pos++ = 0x00;
11294
11295 /* Duration */
11296 *pos++ = 0x00;
11297 *pos++ = 0x00;
11298
11299 /* addr1 = DA (current AP) */
11300 hwaddr_aton(bssid, pos);
11301 pos += 6;
11302 /* addr2 = SA (own address) */
11303 hwaddr_aton(addr, pos);
11304 pos += 6;
11305 /* addr3 = BSSID (current AP) */
11306 hwaddr_aton(bssid, pos);
11307 pos += 6;
11308
11309 /* Seq# (to be filled by driver/mac80211) */
11310 *pos++ = 0x00;
11311 *pos++ = 0x00;
11312
11313 if (protected == INCORRECT_KEY) {
11314 /* CCMP parameters */
11315 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
11316 pos += 8;
11317 }
11318
11319 if (protected == INCORRECT_KEY) {
11320 switch (frame) {
11321 case DEAUTH:
11322 /* Reason code (encrypted) */
11323 memcpy(pos, "\xa7\x39", 2);
11324 pos += 2;
11325 break;
11326 case DISASSOC:
11327 /* Reason code (encrypted) */
11328 memcpy(pos, "\xa7\x39", 2);
11329 pos += 2;
11330 break;
11331 case SAQUERY:
11332 /* Category|Action|TransID (encrypted) */
11333 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
11334 pos += 4;
11335 break;
11336 default:
11337 return -1;
11338 }
11339
11340 /* CCMP MIC */
11341 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
11342 pos += 8;
11343 } else {
11344 switch (frame) {
11345 case DEAUTH:
11346 /* reason code = 8 */
11347 *pos++ = 0x08;
11348 *pos++ = 0x00;
11349 break;
11350 case DISASSOC:
11351 /* reason code = 8 */
11352 *pos++ = 0x08;
11353 *pos++ = 0x00;
11354 break;
11355 case SAQUERY:
11356 /* Category - SA Query */
11357 *pos++ = 0x08;
11358 /* SA query Action - Request */
11359 *pos++ = 0x00;
11360 /* Transaction ID */
11361 *pos++ = 0x12;
11362 *pos++ = 0x34;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011363 if (dut->saquery_oci_freq) {
11364 /* OCI IE - Extended ID */
11365 *pos++ = 0xFF;
11366 *pos++ = 0x04;
11367 *pos++ = 0x36;
11368 /* Operating Class */
11369 *pos++ = 0x74;
11370 /* Primary Channel */
11371 *pos++ = freq_to_channel(dut->saquery_oci_freq);
11372 /* Frequency Segment 1 Channel Number */
11373 *pos++ = 0x00;
11374 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011375 break;
11376 case AUTH:
11377 /* Auth Alg (Open) */
11378 *pos++ = 0x00;
11379 *pos++ = 0x00;
11380 /* Seq# */
11381 *pos++ = 0x01;
11382 *pos++ = 0x00;
11383 /* Status code */
11384 *pos++ = 0x00;
11385 *pos++ = 0x00;
11386 break;
11387 case ASSOCREQ:
11388 /* Capability Information */
11389 *pos++ = 0x31;
11390 *pos++ = 0x04;
11391 /* Listen Interval */
11392 *pos++ = 0x0a;
11393 *pos++ = 0x00;
11394 /* SSID */
11395 *pos++ = 0x00;
11396 *pos++ = ssid_len;
11397 memcpy(pos, ssid, ssid_len);
11398 pos += ssid_len;
11399 /* Supported Rates */
11400 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
11401 10);
11402 pos += 10;
11403 /* Extended Supported Rates */
11404 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
11405 pos += 6;
11406 /* RSN */
11407 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
11408 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
11409 "\x00\x00\x00\x00\x0f\xac\x06", 28);
11410 pos += 28;
11411 break;
11412 case REASSOCREQ:
11413 /* Capability Information */
11414 *pos++ = 0x31;
11415 *pos++ = 0x04;
11416 /* Listen Interval */
11417 *pos++ = 0x0a;
11418 *pos++ = 0x00;
11419 /* Current AP */
11420 hwaddr_aton(bssid, pos);
11421 pos += 6;
11422 /* SSID */
11423 *pos++ = 0x00;
11424 *pos++ = ssid_len;
11425 memcpy(pos, ssid, ssid_len);
11426 pos += ssid_len;
11427 /* Supported Rates */
11428 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
11429 10);
11430 pos += 10;
11431 /* Extended Supported Rates */
11432 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
11433 pos += 6;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011434 /* RSNE - Group and Pairwise ciphers */
11435 memcpy(pos,
11436 "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04",
11437 14);
11438 pos += 14;
11439 /* RSNE - AKM Suite count */
11440 *pos++ = 0x01;
11441 *pos++ = 0x00;
11442 /* RSNE - AKM Suites */
11443 if (dut->program == PROGRAM_WPA3)
11444 memcpy(pos, "\x00\x0f\xac\x08", 4);
11445 else
11446 memcpy(pos, "\x00\x0f\xac\x02", 4);
11447 pos += 4;
11448 /* RSNE - Capabilities */
11449 *pos++ = 0xc0;
11450 if (dut->ocvc)
11451 *pos++ = 0x40;
11452 else
11453 *pos++ = 0x00;
11454 /* RSNE - PMKID list and Group Management Ciphers */
11455 memcpy(pos, "\x00\x00\x00\x0f\xac\x06", 6);
11456 pos += 6;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011457 break;
11458 case DLS_REQ:
11459 /* Category - DLS */
11460 *pos++ = 0x02;
11461 /* DLS Action - Request */
11462 *pos++ = 0x00;
11463 /* Destination MACAddress */
11464 if (dest)
11465 hwaddr_aton(dest, pos);
11466 else
11467 memset(pos, 0, 6);
11468 pos += 6;
11469 /* Source MACAddress */
11470 hwaddr_aton(addr, pos);
11471 pos += 6;
11472 /* Capability Information */
11473 *pos++ = 0x10; /* Privacy */
11474 *pos++ = 0x06; /* QoS */
11475 /* DLS Timeout Value */
11476 *pos++ = 0x00;
11477 *pos++ = 0x01;
11478 /* Supported rates */
11479 *pos++ = 0x01;
11480 *pos++ = 0x08;
11481 *pos++ = 0x0c; /* 6 Mbps */
11482 *pos++ = 0x12; /* 9 Mbps */
11483 *pos++ = 0x18; /* 12 Mbps */
11484 *pos++ = 0x24; /* 18 Mbps */
11485 *pos++ = 0x30; /* 24 Mbps */
11486 *pos++ = 0x48; /* 36 Mbps */
11487 *pos++ = 0x60; /* 48 Mbps */
11488 *pos++ = 0x6c; /* 54 Mbps */
11489 /* TODO: Extended Supported Rates */
11490 /* TODO: HT Capabilities */
11491 break;
11492 }
11493 }
11494
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011495 if (use_monitor) {
11496 s = open_monitor("sigmadut");
11497 if (s < 0) {
11498 send_resp(dut, conn, SIGMA_ERROR,
11499 "errorCode,Failed to open monitor socket");
11500 return 0;
11501 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011502
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011503 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
11504 if (res < 0) {
11505 send_resp(dut, conn, SIGMA_ERROR,
11506 "errorCode,Failed to inject frame");
11507 close(s);
11508 return 0;
11509 }
11510 if (res < pos - buf) {
11511 send_resp(dut, conn, SIGMA_ERROR,
11512 "errorCode,Only partial frame sent");
11513 close(s);
11514 return 0;
11515 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011516
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011517 close(s);
11518 } else {
11519#ifdef NL80211_SUPPORT
11520 int freq;
11521 char freq_str[10];
11522
11523 if (get_wpa_status(get_station_ifname(dut), "freq",
11524 freq_str, sizeof(freq_str)) < 0) {
11525 send_resp(dut, conn, SIGMA_ERROR,
11526 "errorCode,Could not get current operating frequency");
11527 return 0;
11528 }
11529 freq = atoi(freq_str);
11530
11531 if (nl80211_send_frame_cmd(dut, intf, buf, pos - buf, freq)) {
11532 send_resp(dut, conn, SIGMA_ERROR,
11533 "errorCode,Failed to inject frame");
11534 return 0;
11535 }
11536#else /* NL80211_SUPPORT */
11537 send_resp(dut, conn, SIGMA_ERROR,
11538 "errorCode,Failed to inject frame (no NL80211_SUPPORT)");
11539 return 0;
11540#endif /* NL80211_SUPPORT */
11541 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011542
11543 return 1;
11544#else /* __linux__ */
11545 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
11546 "yet supported");
11547 return 0;
11548#endif /* __linux__ */
11549}
11550
11551
11552static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
11553 struct sigma_conn *conn,
11554 struct sigma_cmd *cmd)
11555{
11556 const char *intf = get_param(cmd, "Interface");
11557 const char *sta, *val;
11558 unsigned char addr[ETH_ALEN];
11559 char buf[100];
11560
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011561 if (!intf)
11562 return -1;
11563
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011564 sta = get_param(cmd, "peer");
11565 if (sta == NULL)
11566 sta = get_param(cmd, "station");
11567 if (sta == NULL) {
11568 send_resp(dut, conn, SIGMA_ERROR,
11569 "ErrorCode,Missing peer address");
11570 return 0;
11571 }
11572 if (hwaddr_aton(sta, addr) < 0) {
11573 send_resp(dut, conn, SIGMA_ERROR,
11574 "ErrorCode,Invalid peer address");
11575 return 0;
11576 }
11577
11578 val = get_param(cmd, "type");
11579 if (val == NULL)
11580 return -1;
11581
11582 if (strcasecmp(val, "DISCOVERY") == 0) {
11583 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
11584 if (wpa_command(intf, buf) < 0) {
11585 send_resp(dut, conn, SIGMA_ERROR,
11586 "ErrorCode,Failed to send TDLS discovery");
11587 return 0;
11588 }
11589 return 1;
11590 }
11591
11592 if (strcasecmp(val, "SETUP") == 0) {
11593 int status = 0, timeout = 0;
11594
11595 val = get_param(cmd, "Status");
11596 if (val)
11597 status = atoi(val);
11598
11599 val = get_param(cmd, "Timeout");
11600 if (val)
11601 timeout = atoi(val);
11602
11603 if (status != 0 && status != 37) {
11604 send_resp(dut, conn, SIGMA_ERROR,
11605 "ErrorCode,Unsupported status value");
11606 return 0;
11607 }
11608
11609 if (timeout != 0 && timeout != 301) {
11610 send_resp(dut, conn, SIGMA_ERROR,
11611 "ErrorCode,Unsupported timeout value");
11612 return 0;
11613 }
11614
11615 if (status && timeout) {
11616 send_resp(dut, conn, SIGMA_ERROR,
11617 "ErrorCode,Unsupported timeout+status "
11618 "combination");
11619 return 0;
11620 }
11621
11622 if (status == 37 &&
11623 wpa_command(intf, "SET tdls_testing 0x200")) {
11624 send_resp(dut, conn, SIGMA_ERROR,
11625 "ErrorCode,Failed to enable "
11626 "decline setup response test mode");
11627 return 0;
11628 }
11629
11630 if (timeout == 301) {
11631 int res;
11632 if (dut->no_tpk_expiration)
11633 res = wpa_command(intf,
11634 "SET tdls_testing 0x108");
11635 else
11636 res = wpa_command(intf,
11637 "SET tdls_testing 0x8");
11638 if (res) {
11639 send_resp(dut, conn, SIGMA_ERROR,
11640 "ErrorCode,Failed to set short TPK "
11641 "lifetime");
11642 return 0;
11643 }
11644 }
11645
11646 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
11647 if (wpa_command(intf, buf) < 0) {
11648 send_resp(dut, conn, SIGMA_ERROR,
11649 "ErrorCode,Failed to send TDLS setup");
11650 return 0;
11651 }
11652 return 1;
11653 }
11654
11655 if (strcasecmp(val, "TEARDOWN") == 0) {
11656 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
11657 if (wpa_command(intf, buf) < 0) {
11658 send_resp(dut, conn, SIGMA_ERROR,
11659 "ErrorCode,Failed to send TDLS teardown");
11660 return 0;
11661 }
11662 return 1;
11663 }
11664
11665 send_resp(dut, conn, SIGMA_ERROR,
11666 "ErrorCode,Unsupported TDLS frame");
11667 return 0;
11668}
11669
11670
11671static int sta_ap_known(const char *ifname, const char *bssid)
11672{
11673 char buf[4096];
11674
Jouni Malinendd32f192018-09-15 02:55:19 +030011675 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011676 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
11677 return 0;
11678 if (strncmp(buf, "id=", 3) != 0)
11679 return 0;
11680 return 1;
11681}
11682
11683
11684static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
11685 const char *bssid)
11686{
11687 int res;
11688 struct wpa_ctrl *ctrl;
11689 char buf[256];
11690
11691 if (sta_ap_known(ifname, bssid))
11692 return 0;
11693 sigma_dut_print(dut, DUT_MSG_DEBUG,
11694 "AP not in BSS table - start scan");
11695
11696 ctrl = open_wpa_mon(ifname);
11697 if (ctrl == NULL) {
11698 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11699 "wpa_supplicant monitor connection");
11700 return -1;
11701 }
11702
11703 if (wpa_command(ifname, "SCAN") < 0) {
11704 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
11705 wpa_ctrl_detach(ctrl);
11706 wpa_ctrl_close(ctrl);
11707 return -1;
11708 }
11709
11710 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
11711 buf, sizeof(buf));
11712
11713 wpa_ctrl_detach(ctrl);
11714 wpa_ctrl_close(ctrl);
11715
11716 if (res < 0) {
11717 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
11718 return -1;
11719 }
11720
11721 if (sta_ap_known(ifname, bssid))
11722 return 0;
11723 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
11724 return -1;
11725}
11726
11727
11728static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
11729 struct sigma_conn *conn,
11730 struct sigma_cmd *cmd,
11731 const char *intf)
11732{
11733 char buf[200];
11734
11735 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
11736 if (system(buf) != 0) {
11737 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
11738 "ndsend");
11739 return 0;
11740 }
11741
11742 return 1;
11743}
11744
11745
11746static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
11747 struct sigma_conn *conn,
11748 struct sigma_cmd *cmd,
11749 const char *intf)
11750{
11751 char buf[200];
11752 const char *ip = get_param(cmd, "SenderIP");
11753
Peng Xu26b356d2017-10-04 17:58:16 -070011754 if (!ip)
11755 return 0;
11756
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011757 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
11758 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11759 if (system(buf) == 0) {
11760 sigma_dut_print(dut, DUT_MSG_INFO,
11761 "Neighbor Solicitation got a response "
11762 "for %s@%s", ip, intf);
11763 }
11764
11765 return 1;
11766}
11767
11768
11769static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
11770 struct sigma_conn *conn,
11771 struct sigma_cmd *cmd,
11772 const char *ifname)
11773{
11774 char buf[200];
11775 const char *ip = get_param(cmd, "SenderIP");
11776
11777 if (ip == NULL) {
11778 send_resp(dut, conn, SIGMA_ERROR,
11779 "ErrorCode,Missing SenderIP parameter");
11780 return 0;
11781 }
11782 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
11783 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11784 if (system(buf) != 0) {
11785 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
11786 "for %s@%s", ip, ifname);
11787 }
11788
11789 return 1;
11790}
11791
11792
11793static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
11794 struct sigma_conn *conn,
11795 struct sigma_cmd *cmd,
11796 const char *ifname)
11797{
11798 char buf[200];
11799 char ip[16];
11800 int s;
Peng Xub3756882017-10-04 14:39:09 -070011801 struct ifreq ifr;
11802 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011803
11804 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070011805 if (s < 0) {
11806 perror("socket");
11807 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011808 }
11809
Peng Xub3756882017-10-04 14:39:09 -070011810 memset(&ifr, 0, sizeof(ifr));
11811 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
11812 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
11813 sigma_dut_print(dut, DUT_MSG_INFO,
11814 "Failed to get %s IP address: %s",
11815 ifname, strerror(errno));
11816 close(s);
11817 return -1;
11818 }
11819 close(s);
11820
11821 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
11822 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
11823
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011824 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
11825 ip);
11826 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11827 if (system(buf) != 0) {
11828 }
11829
11830 return 1;
11831}
11832
11833
11834static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
11835 struct sigma_conn *conn,
11836 struct sigma_cmd *cmd,
11837 const char *ifname)
11838{
11839 char buf[200], addr[20];
11840 char dst[ETH_ALEN], src[ETH_ALEN];
11841 short ethtype = htons(ETH_P_ARP);
11842 char *pos;
11843 int s, res;
11844 const char *val;
11845 struct sockaddr_in taddr;
11846
11847 val = get_param(cmd, "dest");
11848 if (val)
11849 hwaddr_aton(val, (unsigned char *) dst);
11850
11851 val = get_param(cmd, "DestIP");
11852 if (val)
11853 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070011854 else
11855 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011856
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011857 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011858 sizeof(addr)) < 0)
11859 return -2;
11860 hwaddr_aton(addr, (unsigned char *) src);
11861
11862 pos = buf;
11863 *pos++ = 0x00;
11864 *pos++ = 0x01;
11865 *pos++ = 0x08;
11866 *pos++ = 0x00;
11867 *pos++ = 0x06;
11868 *pos++ = 0x04;
11869 *pos++ = 0x00;
11870 *pos++ = 0x02;
11871 memcpy(pos, src, ETH_ALEN);
11872 pos += ETH_ALEN;
11873 memcpy(pos, &taddr.sin_addr, 4);
11874 pos += 4;
11875 memcpy(pos, dst, ETH_ALEN);
11876 pos += ETH_ALEN;
11877 memcpy(pos, &taddr.sin_addr, 4);
11878 pos += 4;
11879
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011880 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011881 if (s < 0) {
11882 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
11883 "monitor socket");
11884 return 0;
11885 }
11886
11887 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
11888 if (res < 0) {
11889 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
11890 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053011891 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011892 return 0;
11893 }
11894
11895 close(s);
11896
11897 return 1;
11898}
11899
11900
11901static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
11902 struct sigma_conn *conn,
11903 struct sigma_cmd *cmd,
11904 const char *intf, const char *dest)
11905{
11906 char buf[100];
11907
11908 if (if_nametoindex("sigmadut") == 0) {
11909 snprintf(buf, sizeof(buf),
11910 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011911 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011912 if (system(buf) != 0 ||
11913 if_nametoindex("sigmadut") == 0) {
11914 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11915 "monitor interface with '%s'", buf);
11916 return -2;
11917 }
11918 }
11919
11920 if (system("ifconfig sigmadut up") != 0) {
11921 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11922 "monitor interface up");
11923 return -2;
11924 }
11925
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011926 return sta_inject_frame(dut, conn, intf, DLS_REQ, UNPROTECTED, dest, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011927}
11928
11929
11930static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
11931 struct sigma_conn *conn,
11932 struct sigma_cmd *cmd)
11933{
11934 const char *intf = get_param(cmd, "Interface");
11935 const char *dest = get_param(cmd, "Dest");
11936 const char *type = get_param(cmd, "FrameName");
11937 const char *val;
11938 char buf[200], *pos, *end;
11939 int count, count2;
11940
11941 if (type == NULL)
11942 type = get_param(cmd, "Type");
11943
11944 if (intf == NULL || dest == NULL || type == NULL)
11945 return -1;
11946
11947 if (strcasecmp(type, "NeighAdv") == 0)
11948 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
11949
11950 if (strcasecmp(type, "NeighSolicitReq") == 0)
11951 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
11952
11953 if (strcasecmp(type, "ARPProbe") == 0)
11954 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
11955
11956 if (strcasecmp(type, "ARPAnnounce") == 0)
11957 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
11958
11959 if (strcasecmp(type, "ARPReply") == 0)
11960 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
11961
11962 if (strcasecmp(type, "DLS-request") == 0 ||
11963 strcasecmp(type, "DLSrequest") == 0)
11964 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
11965 dest);
11966
11967 if (strcasecmp(type, "ANQPQuery") != 0 &&
11968 strcasecmp(type, "Query") != 0) {
11969 send_resp(dut, conn, SIGMA_ERROR,
11970 "ErrorCode,Unsupported HS 2.0 send frame type");
11971 return 0;
11972 }
11973
11974 if (sta_scan_ap(dut, intf, dest) < 0) {
11975 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
11976 "the requested AP");
11977 return 0;
11978 }
11979
11980 pos = buf;
11981 end = buf + sizeof(buf);
11982 count = 0;
11983 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
11984
11985 val = get_param(cmd, "ANQP_CAP_LIST");
11986 if (val && atoi(val)) {
11987 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
11988 count++;
11989 }
11990
11991 val = get_param(cmd, "VENUE_NAME");
11992 if (val && atoi(val)) {
11993 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
11994 count++;
11995 }
11996
11997 val = get_param(cmd, "NETWORK_AUTH_TYPE");
11998 if (val && atoi(val)) {
11999 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
12000 count++;
12001 }
12002
12003 val = get_param(cmd, "ROAMING_CONS");
12004 if (val && atoi(val)) {
12005 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
12006 count++;
12007 }
12008
12009 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
12010 if (val && atoi(val)) {
12011 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
12012 count++;
12013 }
12014
12015 val = get_param(cmd, "NAI_REALM_LIST");
12016 if (val && atoi(val)) {
12017 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
12018 count++;
12019 }
12020
12021 val = get_param(cmd, "3GPP_INFO");
12022 if (val && atoi(val)) {
12023 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
12024 count++;
12025 }
12026
12027 val = get_param(cmd, "DOMAIN_LIST");
12028 if (val && atoi(val)) {
12029 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
12030 count++;
12031 }
12032
Jouni Malinen34cf9532018-04-29 19:26:33 +030012033 val = get_param(cmd, "Venue_URL");
12034 if (val && atoi(val)) {
12035 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
12036 count++;
12037 }
12038
Jouni Malinend3bca5d2018-04-29 17:25:23 +030012039 val = get_param(cmd, "Advice_Of_Charge");
12040 if (val && atoi(val)) {
12041 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
12042 count++;
12043 }
12044
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012045 if (count && wpa_command(intf, buf)) {
12046 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
12047 return 0;
12048 }
12049
12050 pos = buf;
12051 end = buf + sizeof(buf);
12052 count2 = 0;
12053 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
12054
12055 val = get_param(cmd, "HS_CAP_LIST");
12056 if (val && atoi(val)) {
12057 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
12058 count2++;
12059 }
12060
12061 val = get_param(cmd, "OPER_NAME");
12062 if (val && atoi(val)) {
12063 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
12064 count2++;
12065 }
12066
12067 val = get_param(cmd, "WAN_METRICS");
12068 if (!val)
12069 val = get_param(cmd, "WAN_MAT");
12070 if (!val)
12071 val = get_param(cmd, "WAN_MET");
12072 if (val && atoi(val)) {
12073 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
12074 count2++;
12075 }
12076
12077 val = get_param(cmd, "CONNECTION_CAPABILITY");
12078 if (val && atoi(val)) {
12079 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
12080 count2++;
12081 }
12082
12083 val = get_param(cmd, "OP_CLASS");
12084 if (val && atoi(val)) {
12085 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
12086 count2++;
12087 }
12088
12089 val = get_param(cmd, "OSU_PROVIDER_LIST");
12090 if (val && atoi(val)) {
12091 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
12092 count2++;
12093 }
12094
Jouni Malinenf67afec2018-04-29 19:24:58 +030012095 val = get_param(cmd, "OPER_ICON_METADATA");
12096 if (!val)
12097 val = get_param(cmd, "OPERATOR_ICON_METADATA");
12098 if (val && atoi(val)) {
12099 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
12100 count2++;
12101 }
12102
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012103 if (count && count2) {
12104 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
12105 "second query");
12106 sleep(1);
12107 }
12108
12109 if (count2 && wpa_command(intf, buf)) {
12110 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
12111 "failed");
12112 return 0;
12113 }
12114
12115 val = get_param(cmd, "NAI_HOME_REALM_LIST");
12116 if (val) {
12117 if (count || count2) {
12118 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
12119 "sending out second query");
12120 sleep(1);
12121 }
12122
12123 if (strcmp(val, "1") == 0)
12124 val = "mail.example.com";
12125 snprintf(buf, end - pos,
12126 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
12127 dest, val);
12128 if (wpa_command(intf, buf)) {
12129 send_resp(dut, conn, SIGMA_ERROR,
12130 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
12131 "failed");
12132 return 0;
12133 }
12134 }
12135
12136 val = get_param(cmd, "ICON_REQUEST");
12137 if (val) {
12138 if (count || count2) {
12139 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
12140 "sending out second query");
12141 sleep(1);
12142 }
12143
12144 snprintf(buf, end - pos,
12145 "HS20_ICON_REQUEST %s %s", dest, val);
12146 if (wpa_command(intf, buf)) {
12147 send_resp(dut, conn, SIGMA_ERROR,
12148 "ErrorCode,HS20_ICON_REQUEST failed");
12149 return 0;
12150 }
12151 }
12152
12153 return 1;
12154}
12155
12156
12157static int ath_sta_send_frame_vht(struct sigma_dut *dut,
12158 struct sigma_conn *conn,
12159 struct sigma_cmd *cmd)
12160{
12161 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012162 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012163 int chwidth, nss;
12164
12165 val = get_param(cmd, "framename");
12166 if (!val)
12167 return -1;
12168 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
12169
12170 /* Command sequence to generate Op mode notification */
12171 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012172 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012173
12174 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012175 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012176
12177 /* Extract Channel width */
12178 val = get_param(cmd, "Channel_width");
12179 if (val) {
12180 switch (atoi(val)) {
12181 case 20:
12182 chwidth = 0;
12183 break;
12184 case 40:
12185 chwidth = 1;
12186 break;
12187 case 80:
12188 chwidth = 2;
12189 break;
12190 case 160:
12191 chwidth = 3;
12192 break;
12193 default:
12194 chwidth = 2;
12195 break;
12196 }
12197
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012198 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012199 }
12200
12201 /* Extract NSS */
12202 val = get_param(cmd, "NSS");
12203 if (val) {
12204 switch (atoi(val)) {
12205 case 1:
12206 nss = 1;
12207 break;
12208 case 2:
12209 nss = 3;
12210 break;
12211 case 3:
12212 nss = 7;
12213 break;
12214 default:
12215 /* We do not support NSS > 3 */
12216 nss = 3;
12217 break;
12218 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012219 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012220 }
12221
12222 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012223 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012224 }
12225
12226 return 1;
12227}
12228
12229
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012230static int wcn_sta_set_pmf_config(struct sigma_dut *dut, const char *intf,
12231 enum send_frame_protection protected)
12232{
12233#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053012234 return wcn_wifi_test_config_set_u8(
12235 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PMF_PROTECTION,
12236 protected);
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012237#else /* NL80211_SUPPORT */
12238 sigma_dut_print(dut, DUT_MSG_ERROR,
12239 "PMF config cannot be set without NL80211_SUPPORT defined");
12240 return -1;
12241#endif /* NL80211_SUPPORT */
12242}
12243
12244
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012245static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
12246 struct sigma_conn *conn,
12247 struct sigma_cmd *cmd)
12248{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012249 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012250 case DRIVER_ATHEROS:
12251 return ath_sta_send_frame_vht(dut, conn, cmd);
12252 default:
12253 send_resp(dut, conn, SIGMA_ERROR,
12254 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
12255 return 0;
12256 }
12257}
12258
12259
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012260static int wcn_sta_send_disassoc(struct sigma_dut *dut, const char *intf)
12261{
12262#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053012263 return wcn_wifi_test_config_set_flag(
12264 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISASSOC_TX);
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012265#else /* NL80211_SUPPORT */
12266 sigma_dut_print(dut, DUT_MSG_ERROR,
12267 "Disassoc Tx cannot be done without NL80211_SUPPORT defined");
12268 return -1;
12269#endif /* NL80211_SUPPORT */
12270}
12271
12272
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012273static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
12274 struct sigma_cmd *cmd)
12275{
12276 const char *val;
12277 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012278 enum send_frame_protection protected;
12279 const char *pmf;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012280
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030012281 if (!intf)
12282 return -1;
12283
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012284 val = get_param(cmd, "framename");
12285 if (!val)
12286 return -1;
12287 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
12288
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012289 pmf = get_param(cmd, "PMFProtected");
12290 if (!pmf)
12291 pmf = get_param(cmd, "Protected");
12292 if (pmf) {
12293 if (strcasecmp(pmf, "Correct-key") == 0 ||
12294 strcasecmp(pmf, "CorrectKey") == 0) {
12295 protected = CORRECT_KEY;
12296 } else if (strcasecmp(pmf, "IncorrectKey") == 0) {
12297 protected = INCORRECT_KEY;
12298 } else if (strcasecmp(pmf, "Unprotected") == 0) {
12299 protected = UNPROTECTED;
12300 } else {
12301 send_resp(dut, conn, SIGMA_ERROR,
12302 "errorCode,Unsupported PMFProtected");
12303 return STATUS_SENT_ERROR;
12304 }
12305 sigma_dut_print(dut, DUT_MSG_DEBUG, "Config PMF protection %d",
12306 protected);
12307 wcn_sta_set_pmf_config(dut, intf, protected);
12308 }
12309
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012310 /* Command sequence to generate Op mode notification */
12311 if (val && strcasecmp(val, "action") == 0) {
12312 val = get_param(cmd, "PPDUTxType");
12313 if (val && strcasecmp(val, "TB") == 0) {
12314 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
12315 sigma_dut_print(dut, DUT_MSG_ERROR,
12316 "failed to send TB PPDU Tx cfg");
12317 send_resp(dut, conn, SIGMA_ERROR,
12318 "ErrorCode,set TB PPDU Tx cfg failed");
12319 return 0;
12320 }
12321 return 1;
12322 }
12323
12324 sigma_dut_print(dut, DUT_MSG_ERROR,
12325 "Action Tx type is not defined");
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012326
12327 return SUCCESS_SEND_STATUS;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012328 }
12329
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012330 if (strcasecmp(val, "disassoc") == 0)
12331 wcn_sta_send_disassoc(dut, intf);
12332
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012333 return 1;
12334}
12335
12336
12337static int cmd_sta_send_frame_he(struct sigma_dut *dut,
12338 struct sigma_conn *conn,
12339 struct sigma_cmd *cmd)
12340{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012341 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012342 case DRIVER_WCN:
12343 return wcn_sta_send_frame_he(dut, conn, cmd);
12344 default:
12345 send_resp(dut, conn, SIGMA_ERROR,
12346 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
12347 return 0;
12348 }
12349}
12350
12351
Lior David0fe101e2017-03-09 16:09:50 +020012352#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012353
12354static int
12355wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
12356 const char *frame_name, const char *dest_mac)
12357{
12358 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
12359 const char *ssid = get_param(cmd, "ssid");
12360 const char *countstr = get_param(cmd, "count");
12361 const char *channelstr = get_param(cmd, "channel");
12362 const char *group_id = get_param(cmd, "groupid");
12363 const char *client_id = get_param(cmd, "clientmac");
12364 int count, channel, freq, i;
12365 const char *fname;
12366 char frame[1024], src_mac[20], group_id_attr[25],
12367 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
12368 const char *group_ssid;
12369 const int group_ssid_prefix_len = 9;
12370 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
12371 size_t framelen = sizeof(frame);
12372 struct template_frame_tag tags[2];
12373 size_t tags_total = ARRAY_SIZE(tags);
12374 int tag_index, len, dst_len;
12375
12376 if (!countstr || !channelstr) {
12377 sigma_dut_print(dut, DUT_MSG_ERROR,
12378 "Missing argument: count, channel");
12379 return -1;
12380 }
12381 if (isprobereq && !ssid) {
12382 sigma_dut_print(dut, DUT_MSG_ERROR,
12383 "Missing argument: ssid");
12384 return -1;
12385 }
12386 if (!isprobereq && (!group_id || !client_id)) {
12387 sigma_dut_print(dut, DUT_MSG_ERROR,
12388 "Missing argument: group_id, client_id");
12389 return -1;
12390 }
12391
12392 count = atoi(countstr);
12393 channel = atoi(channelstr);
12394 freq = channel_to_freq(dut, channel);
12395
12396 if (!freq) {
12397 sigma_dut_print(dut, DUT_MSG_ERROR,
12398 "invalid channel: %s", channelstr);
12399 return -1;
12400 }
12401
12402 if (isprobereq) {
12403 if (strcasecmp(ssid, "wildcard") == 0) {
12404 fname = "probe_req_wildcard.txt";
12405 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
12406 fname = "probe_req_P2P_Wildcard.txt";
12407 } else {
12408 sigma_dut_print(dut, DUT_MSG_ERROR,
12409 "invalid probe request type");
12410 return -1;
12411 }
12412 } else {
12413 fname = "P2P_device_discovery_req.txt";
12414 }
12415
12416 if (parse_template_frame_file(dut, fname, frame, &framelen,
12417 tags, &tags_total)) {
12418 sigma_dut_print(dut, DUT_MSG_ERROR,
12419 "invalid frame template: %s", fname);
12420 return -1;
12421 }
12422
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012423 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012424 src_mac, sizeof(src_mac)) < 0 ||
12425 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
12426 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
12427 return -1;
12428 /* Use wildcard BSSID, since we are in PBSS */
12429 memset(&hdr->addr3, 0xFF, ETH_ALEN);
12430
12431 if (!isprobereq) {
12432 tag_index = find_template_frame_tag(tags, tags_total, 1);
12433 if (tag_index < 0) {
12434 sigma_dut_print(dut, DUT_MSG_ERROR,
12435 "can't find device id attribute");
12436 return -1;
12437 }
12438 if (parse_mac_address(dut, client_id,
12439 (unsigned char *) client_mac)) {
12440 sigma_dut_print(dut, DUT_MSG_ERROR,
12441 "invalid client_id: %s", client_id);
12442 return -1;
12443 }
12444 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
12445 framelen - tags[tag_index].offset,
12446 IEEE80211_P2P_ATTR_DEVICE_ID,
12447 client_mac, ETH_ALEN)) {
12448 sigma_dut_print(dut, DUT_MSG_ERROR,
12449 "fail to replace device id attribute");
12450 return -1;
12451 }
12452
12453 /*
12454 * group_id arg contains device MAC address followed by
12455 * space and SSID (DIRECT-somessid).
12456 * group id attribute contains device address (6 bytes)
12457 * followed by SSID prefix DIRECT-XX (9 bytes)
12458 */
12459 if (strlen(group_id) < sizeof(device_macstr)) {
12460 sigma_dut_print(dut, DUT_MSG_ERROR,
12461 "group_id arg too short");
12462 return -1;
12463 }
12464 memcpy(device_macstr, group_id, sizeof(device_macstr));
12465 device_macstr[sizeof(device_macstr) - 1] = '\0';
12466 if (parse_mac_address(dut, device_macstr,
12467 (unsigned char *) group_id_attr)) {
12468 sigma_dut_print(dut, DUT_MSG_ERROR,
12469 "fail to parse device address from group_id");
12470 return -1;
12471 }
12472 group_ssid = strchr(group_id, ' ');
12473 if (!group_ssid) {
12474 sigma_dut_print(dut, DUT_MSG_ERROR,
12475 "invalid group_id arg, no ssid");
12476 return -1;
12477 }
12478 group_ssid++;
12479 len = strlen(group_ssid);
12480 if (len < group_ssid_prefix_len) {
12481 sigma_dut_print(dut, DUT_MSG_ERROR,
12482 "group_id SSID too short");
12483 return -1;
12484 }
12485 dst_len = sizeof(group_id_attr) - ETH_ALEN;
12486 if (len > dst_len) {
12487 sigma_dut_print(dut, DUT_MSG_ERROR,
12488 "group_id SSID (%s) too long",
12489 group_ssid);
12490 return -1;
12491 }
12492
12493 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
12494 tag_index = find_template_frame_tag(tags, tags_total, 2);
12495 if (tag_index < 0) {
12496 sigma_dut_print(dut, DUT_MSG_ERROR,
12497 "can't find group id attribute");
12498 return -1;
12499 }
12500 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
12501 framelen - tags[tag_index].offset,
12502 IEEE80211_P2P_ATTR_GROUP_ID,
12503 group_id_attr,
12504 sizeof(group_id_attr))) {
12505 sigma_dut_print(dut, DUT_MSG_ERROR,
12506 "fail to replace group id attribute");
12507 return -1;
12508 }
12509 }
12510
12511 for (i = 0; i < count; i++) {
12512 if (wil6210_transmit_frame(dut, freq,
12513 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
12514 frame, framelen)) {
12515 sigma_dut_print(dut, DUT_MSG_ERROR,
12516 "fail to transmit probe request frame");
12517 return -1;
12518 }
12519 }
12520
12521 return 0;
12522}
12523
12524
Lior David0fe101e2017-03-09 16:09:50 +020012525int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
12526 struct sigma_cmd *cmd)
12527{
12528 const char *frame_name = get_param(cmd, "framename");
12529 const char *mac = get_param(cmd, "dest_mac");
12530
12531 if (!frame_name || !mac) {
12532 sigma_dut_print(dut, DUT_MSG_ERROR,
12533 "framename and dest_mac must be provided");
12534 return -1;
12535 }
12536
12537 if (strcasecmp(frame_name, "brp") == 0) {
12538 const char *l_rx = get_param(cmd, "L-RX");
12539 int l_rx_i;
12540
12541 if (!l_rx) {
12542 sigma_dut_print(dut, DUT_MSG_ERROR,
12543 "L-RX must be provided");
12544 return -1;
12545 }
12546 l_rx_i = atoi(l_rx);
12547
12548 sigma_dut_print(dut, DUT_MSG_INFO,
12549 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
12550 mac, l_rx);
12551 if (l_rx_i != 16) {
12552 sigma_dut_print(dut, DUT_MSG_ERROR,
12553 "unsupported L-RX: %s", l_rx);
12554 return -1;
12555 }
12556
12557 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
12558 return -1;
12559 } else if (strcasecmp(frame_name, "ssw") == 0) {
12560 sigma_dut_print(dut, DUT_MSG_INFO,
12561 "dev_send_frame: SLS, dest_mac %s", mac);
12562 if (wil6210_send_sls(dut, mac))
12563 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012564 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
12565 (strcasecmp(frame_name, "devdiscreq") == 0)) {
12566 sigma_dut_print(dut, DUT_MSG_INFO,
12567 "dev_send_frame: %s, dest_mac %s", frame_name,
12568 mac);
12569 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
12570 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020012571 } else {
12572 sigma_dut_print(dut, DUT_MSG_ERROR,
12573 "unsupported frame type: %s", frame_name);
12574 return -1;
12575 }
12576
12577 return 1;
12578}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012579
Lior David0fe101e2017-03-09 16:09:50 +020012580#endif /* __linux__ */
12581
12582
12583static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
12584 struct sigma_conn *conn,
12585 struct sigma_cmd *cmd)
12586{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012587 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020012588#ifdef __linux__
12589 case DRIVER_WIL6210:
12590 return wil6210_send_frame_60g(dut, conn, cmd);
12591#endif /* __linux__ */
12592 default:
12593 send_resp(dut, conn, SIGMA_ERROR,
12594 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
12595 return 0;
12596 }
12597}
12598
12599
Ashwini Patildb59b3c2017-04-13 15:19:23 +053012600static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
12601 const char *intf, struct sigma_cmd *cmd)
12602{
12603 const char *val, *addr;
12604 char buf[100];
12605
12606 addr = get_param(cmd, "DestMac");
12607 if (!addr) {
12608 send_resp(dut, conn, SIGMA_INVALID,
12609 "ErrorCode,AP MAC address is missing");
12610 return 0;
12611 }
12612
12613 val = get_param(cmd, "ANQPQuery_ID");
12614 if (!val) {
12615 send_resp(dut, conn, SIGMA_INVALID,
12616 "ErrorCode,Missing ANQPQuery_ID");
12617 return 0;
12618 }
12619
12620 if (strcasecmp(val, "NeighborReportReq") == 0) {
12621 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
12622 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
12623 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
12624 } else {
12625 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
12626 val);
12627 send_resp(dut, conn, SIGMA_INVALID,
12628 "ErrorCode,Invalid ANQPQuery_ID");
12629 return 0;
12630 }
12631
Ashwini Patild174f2c2017-04-13 16:49:46 +053012632 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
12633 * (Address3 = Wildcard BSSID when sent to not-associated AP;
12634 * if associated, AP BSSID).
12635 */
12636 if (wpa_command(intf, "SET gas_address3 1") < 0) {
12637 send_resp(dut, conn, SIGMA_ERROR,
12638 "ErrorCode,Failed to set gas_address3");
12639 return 0;
12640 }
12641
Ashwini Patildb59b3c2017-04-13 15:19:23 +053012642 if (wpa_command(intf, buf) < 0) {
12643 send_resp(dut, conn, SIGMA_ERROR,
12644 "ErrorCode,Failed to send ANQP query");
12645 return 0;
12646 }
12647
12648 return 1;
12649}
12650
12651
12652static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
12653 struct sigma_conn *conn,
12654 const char *intf,
12655 struct sigma_cmd *cmd)
12656{
12657 const char *val = get_param(cmd, "FrameName");
12658
12659 if (val && strcasecmp(val, "ANQPQuery") == 0)
12660 return mbo_send_anqp_query(dut, conn, intf, cmd);
12661
12662 return 2;
12663}
12664
12665
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053012666static enum sigma_cmd_result cmd_sta_send_frame_wpa3(struct sigma_dut *dut,
12667 struct sigma_conn *conn,
12668 const char *intf,
12669 struct sigma_cmd *cmd)
12670{
12671 const char *val = get_param(cmd, "framename");
12672
12673 if (!val)
12674 return INVALID_SEND_STATUS;
12675
12676 if (strcasecmp(val, "SAQueryReq") == 0) {
12677 val = get_param(cmd, "OCIChannel");
12678
12679 if (!val) {
12680 send_resp(dut, conn, SIGMA_ERROR,
12681 "errorCode,OCIChannel not present");
12682 return STATUS_SENT_ERROR;
12683 }
12684
12685 dut->saquery_oci_freq = channel_to_freq(dut, atoi(val));
12686 if (!dut->saquery_oci_freq) {
12687 send_resp(dut, conn, SIGMA_ERROR,
12688 "errorCode,Invalid OCIChannel number");
12689 return STATUS_SENT_ERROR;
12690 }
12691
12692 return sta_inject_frame(dut, conn, intf, SAQUERY, CORRECT_KEY,
12693 NULL, 0);
12694 }
12695
12696 if (strcasecmp(val, "reassocreq") == 0)
12697 return sta_inject_frame(dut, conn, intf, REASSOCREQ,
12698 CORRECT_KEY, NULL, 0);
12699
Veerendranath9f81dfb2020-08-10 01:21:29 -070012700 if (strcasecmp(val, "ANQPQuery") == 0) {
12701 char buf[50];
12702 const char *dest = get_param(cmd, "DestMac");
12703 const char *chan = get_param(cmd, "channel");
Veerendranath Jakkam78862fc2020-11-19 21:23:27 +053012704 const char *freq_str = get_param(cmd, "ChnlFreq");
Veerendranath9f81dfb2020-08-10 01:21:29 -070012705 int len, freq;
12706
Veerendranath Jakkam78862fc2020-11-19 21:23:27 +053012707 if (freq_str)
12708 freq = atoi(freq_str);
12709 else
12710 freq = chan ? channel_to_freq(dut, atoi(chan)) : 0;
12711
Veerendranath9f81dfb2020-08-10 01:21:29 -070012712 if (!dest || !freq)
12713 return INVALID_SEND_STATUS;
12714
12715 len = snprintf(buf, sizeof(buf), "ANQP_GET %s freq=%d 257",
12716 dest, freq);
12717 if (len < 0 || len >= sizeof(buf)) {
12718 sigma_dut_print(dut, DUT_MSG_ERROR,
12719 "Failed to allocate buf");
12720 return ERROR_SEND_STATUS;
12721 }
12722
12723 if (wpa_command(intf, buf) != 0) {
12724 send_resp(dut, conn, SIGMA_ERROR,
12725 "ErrorCode,Failed to send ANQP Query frame");
12726 return STATUS_SENT_ERROR;
12727 }
12728
12729 sigma_dut_print(dut, DUT_MSG_DEBUG,
12730 "ANQP Query sent: %s", buf);
12731
12732 return SUCCESS_SEND_STATUS;
12733 }
12734
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053012735 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported framename");
12736 return STATUS_SENT_ERROR;
12737}
12738
12739
Vinita S. Malooca85fd22021-01-15 02:54:34 +053012740static int
12741get_type4_frame_classifier(struct sigma_dut *dut, struct sigma_cmd *cmd,
12742 char *pos, int rem_len, int num_of_scs_desc,
12743 int num_of_tclas_elem)
12744{
12745 const char *val;
12746 int ipv6;
12747 int len, total_len = 0;
12748
12749 val = get_param_fmt(cmd, "TCLASElem_Version_%d_%d", num_of_scs_desc,
12750 num_of_tclas_elem);
12751 if (!val) {
12752 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: ip_version empty",
12753 __func__);
12754 return -1;
12755 }
12756
12757 if (strcmp(val, "6") == 0) {
12758 ipv6 = 1;
12759 } else if (strcmp(val, "4") == 0) {
12760 ipv6 = 0;
12761 } else {
12762 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: ip_version invalid",
12763 __func__);
12764 return -1;
12765 }
12766
12767 len = snprintf(pos, rem_len, " ip_version=%s", ipv6 ? "ipv6" : "ipv4");
12768 if (len < 0 || len >= rem_len)
12769 return -1;
12770
12771 pos += len;
12772 rem_len -= len;
12773 total_len += len;
12774
12775 val = get_param_fmt(cmd, "TCLASElem_SourceIPAddr_%d_%d",
12776 num_of_scs_desc, num_of_tclas_elem);
12777 if (val) {
12778 len = snprintf(pos, rem_len, " src_ip=%s", val);
12779 if (len < 0 || len >= rem_len)
12780 return -1;
12781
12782 pos += len;
12783 rem_len -= len;
12784 total_len += len;
12785 }
12786
12787 val = get_param_fmt(cmd, "TCLASElem_DestinationIPAddr_%d_%d",
12788 num_of_scs_desc, num_of_tclas_elem);
12789 if (val) {
12790 len = snprintf(pos, rem_len, " dst_ip=%s", val);
12791 if (len < 0 || len >= rem_len)
12792 return -1;
12793
12794 pos += len;
12795 rem_len -= len;
12796 total_len += len;
12797 }
12798
12799 val = get_param_fmt(cmd, "TCLASElem_SourcePort_%d_%d", num_of_scs_desc,
12800 num_of_tclas_elem);
12801 if (val) {
12802 len = snprintf(pos, rem_len, " src_port=%s", val);
12803 if (len < 0 || len >= rem_len)
12804 return -1;
12805
12806 pos += len;
12807 rem_len -= len;
12808 total_len += len;
12809 }
12810
12811 val = get_param_fmt(cmd, "TCLASElem_DestinationPort_%d_%d",
12812 num_of_scs_desc, num_of_tclas_elem);
12813 if (val) {
12814 len = snprintf(pos, rem_len, " dst_port=%s", val);
12815 if (len < 0 || len >= rem_len)
12816 return -1;
12817
12818 pos += len;
12819 rem_len -= len;
12820 total_len += len;
12821 }
12822
12823 val = get_param_fmt(cmd, "TCLASElem_DSCP_%d_%d", num_of_scs_desc,
12824 num_of_tclas_elem);
12825 if (val) {
12826 len = snprintf(pos, rem_len, " dscp=%s", val);
12827 if (len < 0 || len >= rem_len)
12828 return -1;
12829
12830 pos += len;
12831 rem_len -= len;
12832 total_len += len;
12833 }
12834
12835 val = get_param_fmt(cmd, "TCLASElem_ProtocolNxtHeader_%d_%d",
12836 num_of_scs_desc, num_of_tclas_elem);
12837 if (val) {
12838 char *prot;
12839
12840 switch (atoi(val)) {
12841 case 17:
12842 prot = "udp";
12843 break;
12844 case 6:
12845 prot = "tcp";
12846 break;
12847 case 50:
12848 prot = "esp";
12849 break;
12850 default:
12851 sigma_dut_print(dut, DUT_MSG_ERROR,
12852 "Invalid protocol %d", atoi(val));
12853 return -1;
12854 }
12855
12856 if (ipv6)
12857 len = snprintf(pos, rem_len, " next_header=%s", prot);
12858 else
12859 len = snprintf(pos, rem_len, " protocol=%s", prot);
12860 if (len < 0 || len >= rem_len)
12861 return -1;
12862
12863 pos += len;
12864 rem_len -= len;
12865 total_len += len;
12866 }
12867
12868 return total_len;
12869}
12870
12871
12872static int
12873get_type10_frame_classifier(struct sigma_dut *dut, struct sigma_cmd *cmd,
12874 char *pos, int rem_len, int num_of_scs_desc,
12875 int num_of_tclas_elem)
12876{
12877 const char *val;
12878 int len, total_len = 0;
12879
12880 val = get_param_fmt(cmd, "TCLASElem_ProtoInstance_%d_%d",
12881 num_of_scs_desc, num_of_tclas_elem);
12882 if (val) {
12883 len = snprintf(pos, rem_len, " prot_instance=%s",
12884 val);
12885 if (len < 0 || len >= rem_len)
12886 return -1;
12887
12888 pos += len;
12889 rem_len -= len;
12890 total_len += len;
12891 }
12892
12893 val = get_param_fmt(cmd, "TCLASElem_ProtoNumNextHeader_%d_%d",
12894 num_of_scs_desc, num_of_tclas_elem);
12895 if (val) {
12896 char *prot;
12897
12898 switch (atoi(val)) {
12899 case 17:
12900 prot = "udp";
12901 break;
12902 case 6:
12903 prot = "tcp";
12904 break;
12905 case 50:
12906 prot = "esp";
12907 break;
12908 default:
12909 sigma_dut_print(dut, DUT_MSG_ERROR,
12910 "Invalid protocol %d",
12911 atoi(val));
12912 return -1;
12913 }
12914
12915 len = snprintf(pos, rem_len, " prot_number=%s", prot);
12916 if (len < 0 || len >= rem_len)
12917 return -1;
12918
12919 pos += len;
12920 rem_len -= len;
12921 total_len += len;
12922 }
12923
12924 val = get_param_fmt(cmd, "TCLASElem_FilterValue_%d_%d",
12925 num_of_scs_desc, num_of_tclas_elem);
12926 if (val) {
12927 len = snprintf(pos, rem_len, " filter_value=%s", (val + 2));
12928 if (len < 0 || len >= rem_len)
12929 return -1;
12930
12931 pos += len;
12932 rem_len -= len;
12933 total_len += len;
12934 }
12935
12936 val = get_param_fmt(cmd, "TCLASElem_FilterMask_%d_%d", num_of_scs_desc,
12937 num_of_tclas_elem);
12938 if (val && strlen(val) >= 2) {
12939 len = snprintf(pos, rem_len, " filter_mask=%s", val + 2);
12940 if (len < 0 || len >= rem_len)
12941 return -1;
12942
12943 pos += len;
12944 rem_len -= len;
12945 total_len += len;
12946 }
12947
12948 return total_len;
12949}
12950
12951
12952static enum sigma_cmd_result
12953cmd_sta_send_frame_scs(struct sigma_dut *dut, struct sigma_conn *conn,
12954 const char *intf, struct sigma_cmd *cmd)
12955{
12956 char buf[4096], *pos;
12957 const char *val, *scs_id, *classifier_type;
12958 int len, rem_len, total_bytes;
12959 int num_of_scs_desc = 0, num_of_tclas_elem = 0;
12960
12961 scs_id = get_param(cmd, "SCSDescrElem_SCSID_1");
12962 if (!scs_id) {
12963 sigma_dut_print(dut, DUT_MSG_ERROR, "SCS ID empty");
12964 return INVALID_SEND_STATUS;
12965 }
12966
12967 rem_len = sizeof(buf);
12968 pos = buf;
12969
12970 len = snprintf(buf, sizeof(buf), "SCS");
12971 if (len < 0 || len > rem_len)
12972 goto fail;
12973
12974 pos += len;
12975 rem_len -= len;
12976
12977 while (scs_id) {
12978 num_of_scs_desc++;
12979
12980 val = get_param_fmt(cmd, "SCSDescrElem_RequestType_%d",
12981 num_of_scs_desc);
12982 if (!val)
12983 return INVALID_SEND_STATUS;
12984
12985 if (strcasecmp(val, "Add") == 0) {
12986 len = snprintf(pos, rem_len, " scs_id=%s add",
12987 scs_id);
12988 } else if (strcasecmp(val, "Change") == 0) {
12989 len = snprintf(pos, rem_len, " scs_id=%s change",
12990 scs_id);
12991 } else if (strcasecmp(val, "Remove") == 0) {
12992 len = snprintf(pos, rem_len, " scs_id=%s remove",
12993 scs_id);
12994 if (len < 0 || len >= rem_len)
12995 goto fail;
12996
12997 pos += len;
12998 rem_len -= len;
12999 goto scs_desc_end;
13000 } else {
13001 sigma_dut_print(dut, DUT_MSG_ERROR,
13002 "%s: request type - %s is invalid",
13003 __func__, val);
13004 return INVALID_SEND_STATUS;
13005 }
13006
13007 if (len < 0 || len >= rem_len)
13008 goto fail;
13009
13010 pos += len;
13011 rem_len -= len;
13012
13013 val = get_param_fmt(cmd, "IntraAccessCatElem_UP_%d",
13014 num_of_scs_desc);
13015 if (!val) {
13016 sigma_dut_print(dut, DUT_MSG_ERROR,
13017 "IntraAccess Priority empty");
13018 return INVALID_SEND_STATUS;
13019 }
13020
13021 len = snprintf(pos, rem_len, " scs_up=%s", val);
13022 if (len < 0 || len >= rem_len)
13023 goto fail;
13024
13025 pos += len;
13026 rem_len -= len;
13027
13028 classifier_type = get_param_fmt(cmd,
13029 "TCLASElem_ClassifierType_%d_1",
13030 num_of_scs_desc);
13031 if (!classifier_type) {
13032 sigma_dut_print(dut, DUT_MSG_ERROR,
13033 "classifier type missing");
13034 return INVALID_SEND_STATUS;
13035 }
13036
13037 while (classifier_type) {
13038 num_of_tclas_elem++;
13039
13040 len = snprintf(pos, rem_len, " classifier_type=%s",
13041 classifier_type);
13042 if (len < 0 || len >= rem_len)
13043 goto fail;
13044
13045 pos += len;
13046 rem_len -= len;
13047
13048 if (strcmp(classifier_type, "10") == 0) {
13049 total_bytes = get_type10_frame_classifier(
13050 dut, cmd, pos, rem_len,
13051 num_of_scs_desc,
13052 num_of_tclas_elem);
13053 } else if (strcmp(classifier_type, "4") == 0) {
13054 total_bytes = get_type4_frame_classifier(
13055 dut, cmd, pos, rem_len,
13056 num_of_scs_desc,
13057 num_of_tclas_elem);
13058 } else {
13059 sigma_dut_print(dut, DUT_MSG_ERROR,
13060 "classifier_type invalid");
13061 goto fail;
13062 }
13063
13064 if (total_bytes < 0)
13065 goto fail;
13066
13067 pos += total_bytes;
13068 rem_len -= total_bytes;
13069
13070 classifier_type = get_param_fmt(
13071 cmd, "TCLASElem_ClassifierType_%d_%d",
13072 num_of_scs_desc, num_of_tclas_elem + 1);
13073 }
13074
13075 if (num_of_tclas_elem > 1) {
13076 val = get_param_fmt(cmd,
13077 "TCLASProcessingElem_Processing_%d",
13078 num_of_scs_desc);
13079 if (!val) {
13080 sigma_dut_print(dut, DUT_MSG_ERROR,
13081 "Tclas_processing element %d empty",
13082 num_of_scs_desc);
13083 goto fail;
13084 }
13085
13086 len = snprintf(pos, rem_len,
13087 " tclas_processing=%s", val);
13088 if (len < 0 || len >= rem_len)
13089 goto fail;
13090
13091 pos += len;
13092 rem_len -= len;
13093 }
13094scs_desc_end:
13095 num_of_tclas_elem = 0;
13096 scs_id = get_param_fmt(cmd, "SCSDescrElem_SCSID_%d",
13097 num_of_scs_desc + 1);
13098 }
13099
13100 if (wpa_command(intf, buf) != 0) {
13101 send_resp(dut, conn, SIGMA_ERROR,
13102 "ErrorCode,Failed to send SCS frame request");
13103 return STATUS_SENT_ERROR;
13104 }
13105
13106 sigma_dut_print(dut, DUT_MSG_DEBUG,
13107 "SCS frame request sent: %s", buf);
13108
13109 return SUCCESS_SEND_STATUS;
13110fail:
13111 sigma_dut_print(dut, DUT_MSG_ERROR,
13112 "Failed to create SCS frame request");
13113 return ERROR_SEND_STATUS;
13114}
13115
13116
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013117static enum sigma_cmd_result
13118cmd_sta_send_frame_mscs(struct sigma_dut *dut, struct sigma_conn *conn,
13119 const char *intf, struct sigma_cmd *cmd)
13120{
13121 char buf[128], *pos;
13122 const char *val, *classifier_type = "04", *type;
13123 int len, rem_len;
13124 u8 up_bitmap;
13125
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013126 type = get_param(cmd, "Request_Type");
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013127 if (!type) {
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013128 sigma_dut_print(dut, DUT_MSG_ERROR,
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013129 "%s: type not valid", __func__);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013130 return INVALID_SEND_STATUS;
13131 }
13132
13133 rem_len = sizeof(buf);
13134 pos = buf;
13135 if (strcasecmp(type, "add") == 0) {
13136 len = snprintf(pos, rem_len, "MSCS add");
13137 } else if (strcasecmp(type, "update") == 0) {
13138 len = snprintf(pos, rem_len, "MSCS change");
13139 } else if (strcasecmp(type, "remove") == 0) {
13140 if (wpa_command(intf, "MSCS remove") != 0) {
13141 send_resp(dut, conn, SIGMA_ERROR,
13142 "ErrorCode,Failed to send MSCS frame req");
13143 return STATUS_SENT_ERROR;
13144 }
13145 return SUCCESS_SEND_STATUS;
13146 } else {
13147 sigma_dut_print(dut, DUT_MSG_ERROR,
13148 "%s: request type invalid", __func__);
13149 return INVALID_SEND_STATUS;
13150 }
13151
13152 if (len < 0 || len >= rem_len)
13153 goto fail;
13154
13155 pos += len;
13156 rem_len -= len;
13157
13158 val = get_param(cmd, "User_Priority_Bitmap");
13159 if (!val) {
13160 sigma_dut_print(dut, DUT_MSG_ERROR,
13161 "%s: user priority bitmap empty", __func__);
13162 return INVALID_SEND_STATUS;
13163 }
13164
13165 switch (atoi(val)) {
13166 case 0:
13167 up_bitmap = 0x00;
13168 break;
13169 case 1:
13170 up_bitmap = 0xF0;
13171 break;
13172 case 2:
13173 up_bitmap = 0xF6;
13174 break;
13175 default:
13176 sigma_dut_print(dut, DUT_MSG_ERROR,
13177 "%s: Unknown User_Priority_Bitmap value %d",
13178 __func__, atoi(val));
13179 return INVALID_SEND_STATUS;
13180 }
13181
13182 len = snprintf(pos, rem_len, " up_bitmap=%02x", up_bitmap);
13183 if (len < 0 || len >= rem_len)
13184 goto fail;
13185
13186 pos += len;
13187 rem_len -= len;
13188
13189 val = get_param(cmd, "User_Priority_Limit");
13190 if (!val) {
13191 sigma_dut_print(dut, DUT_MSG_ERROR,
13192 "%s: invalid user priority limit", __func__);
13193 return INVALID_SEND_STATUS;
13194 }
13195
13196 len = snprintf(pos, rem_len, " up_limit=%s", val);
13197 if (len < 0 || len >= rem_len)
13198 goto fail;
13199
13200 pos += len;
13201 rem_len -= len;
13202
13203 val = get_param(cmd, "Stream_Timeout");
13204 if (!val)
13205 val = get_param(cmd, "Stream_Timtout");
13206 if (!val) {
13207 sigma_dut_print(dut, DUT_MSG_ERROR,
13208 "%s: invalid stream timeout", __func__);
13209 return INVALID_SEND_STATUS;
13210 }
13211
13212 len = snprintf(pos, rem_len, " stream_timeout=%s", val);
13213 if (len < 0 || len >= rem_len)
13214 goto fail;
13215
13216 pos += len;
13217 rem_len -= len;
13218
13219 val = get_param(cmd, "TCLAS_Mask");
13220 if (!val) {
13221 sigma_dut_print(dut, DUT_MSG_ERROR,
13222 "%s: invalid tclas mask", __func__);
13223 return INVALID_SEND_STATUS;
13224 }
13225
13226 len = snprintf(pos, rem_len, " frame_classifier=%s%lx%032x",
13227 classifier_type, strtol(val, NULL, 2), 0);
13228 if (len < 0 || len >= rem_len)
13229 goto fail;
13230
13231 if (wpa_command(intf, buf) != 0) {
13232 send_resp(dut, conn, SIGMA_ERROR,
13233 "ErrorCode,Failed to send MSCS frame req");
13234 return STATUS_SENT_ERROR;
13235 }
13236
13237 sigma_dut_print(dut, DUT_MSG_DEBUG,
13238 "MSCS frame request sent: %s", buf);
13239
13240 return SUCCESS_SEND_STATUS;
13241fail:
13242 sigma_dut_print(dut, DUT_MSG_ERROR,
13243 "Failed to create MSCS frame req");
13244 return ERROR_SEND_STATUS;
13245}
13246
13247
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013248static enum sigma_cmd_result
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053013249cmd_sta_send_frame_dscp_query(struct sigma_dut *dut, struct sigma_conn *conn,
13250 const char *intf, struct sigma_cmd *cmd)
13251{
13252 char buf[150], *pos;
13253 const char *val;
13254 int len, rem_len;
13255
13256 rem_len = sizeof(buf);
13257 pos = buf;
13258
13259 len = snprintf(pos, rem_len, "DSCP_QUERY");
13260 if (len < 0 || len >= rem_len)
13261 goto fail;
13262
13263 pos += len;
13264 rem_len -= len;
13265
13266 val = get_param(cmd, "Wildcard");
13267 if (val && strcasecmp(val, "Yes") == 0) {
13268 len = snprintf(pos, rem_len, " wildcard");
13269 if (len < 0 || len >= rem_len)
13270 goto fail;
13271 } else if (strlen(dut->qm_domain_name)) {
13272 len = snprintf(pos, rem_len, " domain_name=%s",
13273 dut->qm_domain_name);
13274 if (len < 0 || len >= rem_len)
13275 goto fail;
13276 } else {
13277 sigma_dut_print(dut, DUT_MSG_ERROR,
13278 "Invalid DSCP Query configuration");
13279 return INVALID_SEND_STATUS;
13280 }
13281
13282 if (wpa_command(intf, buf) != 0) {
13283 send_resp(dut, conn, SIGMA_ERROR,
13284 "ErrorCode,Failed to send DSCP policy query frame");
13285 return STATUS_SENT_ERROR;
13286 }
13287
13288 sigma_dut_print(dut, DUT_MSG_DEBUG,
13289 "DSCP policy query frame sent: %s", buf);
13290 return SUCCESS_SEND_STATUS;
13291fail:
13292 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to send DSCP query");
13293 return ERROR_SEND_STATUS;
13294}
13295
13296
13297static enum sigma_cmd_result
Veerendranath Jakkam1bf1bd62021-09-12 16:35:55 +053013298cmd_sta_send_frame_dscp_response(struct sigma_dut *dut, struct sigma_conn *conn,
13299 const char *intf, struct sigma_cmd *cmd)
13300{
13301 char buf[256], *pos, *item, *list, *saveptr;
13302 const char *val;
13303 int len, rem_len;
13304
13305 pos = buf;
13306 rem_len = sizeof(buf);
13307
13308 len = snprintf(pos, rem_len, "DSCP_RESP");
13309 if (snprintf_error(rem_len, len)) {
13310 sigma_dut_print(dut, DUT_MSG_ERROR,
13311 "Failed to create DSCP Policy Response command");
13312 return ERROR_SEND_STATUS;
13313 }
13314
13315 pos += len;
13316 rem_len -= len;
13317
13318 val = get_param(cmd, "PolicyID_List");
13319 if (!val) {
13320 sigma_dut_print(dut, DUT_MSG_ERROR,
13321 "DSCP policy ID list missing");
13322 return INVALID_SEND_STATUS;
13323 }
13324
13325 list = strdup(val);
13326 if (!list)
13327 return ERROR_SEND_STATUS;
13328
13329 item = strtok_r(list, "_", &saveptr);
13330 while (item) {
13331 unsigned int i;
13332 int policy_id = atoi(item);
13333
13334 for (i = 0; i < dut->num_dscp_status; i++)
13335 if (dut->dscp_status[i].id == policy_id)
13336 break;
13337
13338 if (i == dut->num_dscp_status) {
13339 free(list);
13340 send_resp(dut, conn, SIGMA_ERROR,
13341 "ErrorCode,DSCP policy id not found in status list");
13342 return STATUS_SENT_ERROR;
13343 }
13344
13345 len = snprintf(pos, rem_len, " policy_id=%d status=%d",
13346 policy_id, dut->dscp_status[i].status);
13347 if (snprintf_error(rem_len, len)) {
13348 free(list);
13349 sigma_dut_print(dut, DUT_MSG_ERROR,
13350 "Failed to write DSCP policy list");
13351 return ERROR_SEND_STATUS;
13352 }
13353
13354 pos += len;
13355 rem_len -= len;
13356
13357 if (dut->dscp_status[i].status)
13358 remove_dscp_policy(dut, policy_id);
13359
13360 item = strtok_r(NULL, "_", &saveptr);
13361 }
13362
13363 free(list);
13364
13365 if (wpa_command(intf, buf) != 0) {
13366 send_resp(dut, conn, SIGMA_ERROR,
13367 "ErrorCode,Failed to send DSCP Policy Response frame");
13368 return STATUS_SENT_ERROR;
13369 }
13370
13371 sigma_dut_print(dut, DUT_MSG_DEBUG,
13372 "DSCP Policy Response frame sent: %s", buf);
13373 return SUCCESS_SEND_STATUS;
13374}
13375
13376
13377static enum sigma_cmd_result
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013378cmd_sta_send_frame_qm(struct sigma_dut *dut, struct sigma_conn *conn,
13379 const char *intf, struct sigma_cmd *cmd)
13380{
13381 const char *val;
13382
13383 val = get_param(cmd, "FrameName");
13384 if (val) {
13385 if (strcasecmp(val, "MSCSReq") == 0)
13386 return cmd_sta_send_frame_mscs(dut, conn, intf, cmd);
13387 if (strcasecmp(val, "SCSReq") == 0)
13388 return cmd_sta_send_frame_scs(dut, conn, intf, cmd);
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053013389 if (strcasecmp(val, "DSCPPolicyQuery") == 0)
13390 return cmd_sta_send_frame_dscp_query(dut, conn, intf,
13391 cmd);
Veerendranath Jakkam1bf1bd62021-09-12 16:35:55 +053013392 if (strcasecmp(val, "DSCPPolicyResponse") == 0)
13393 return cmd_sta_send_frame_dscp_response(dut, conn, intf,
13394 cmd);
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013395
13396 sigma_dut_print(dut, DUT_MSG_ERROR,
13397 "%s: frame name - %s is invalid",
13398 __func__, val);
13399 }
13400
13401 return INVALID_SEND_STATUS;
13402}
13403
13404
Jouni Malinenf7222712019-06-13 01:50:21 +030013405enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
13406 struct sigma_conn *conn,
13407 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013408{
13409 const char *intf = get_param(cmd, "Interface");
13410 const char *val;
13411 enum send_frame_type frame;
13412 enum send_frame_protection protected;
13413 char buf[100];
13414 unsigned char addr[ETH_ALEN];
13415 int res;
13416
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030013417 if (!intf)
13418 return -1;
13419
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013420 val = get_param(cmd, "program");
13421 if (val == NULL)
13422 val = get_param(cmd, "frame");
13423 if (val && strcasecmp(val, "TDLS") == 0)
13424 return cmd_sta_send_frame_tdls(dut, conn, cmd);
13425 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030013426 strcasecmp(val, "HS2-R2") == 0 ||
13427 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013428 return cmd_sta_send_frame_hs2(dut, conn, cmd);
13429 if (val && strcasecmp(val, "VHT") == 0)
13430 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070013431 if (val && strcasecmp(val, "HE") == 0)
13432 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070013433 if (val && strcasecmp(val, "LOC") == 0)
13434 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020013435 if (val && strcasecmp(val, "60GHz") == 0)
13436 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053013437 if (val && strcasecmp(val, "MBO") == 0) {
13438 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
13439 if (res != 2)
13440 return res;
13441 }
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053013442 if (val && strcasecmp(val, "WPA3") == 0)
13443 return cmd_sta_send_frame_wpa3(dut, conn, intf, cmd);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013444 if (val && strcasecmp(val, "QM") == 0)
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013445 return cmd_sta_send_frame_qm(dut, conn, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013446
13447 val = get_param(cmd, "TD_DISC");
13448 if (val) {
13449 if (hwaddr_aton(val, addr) < 0)
13450 return -1;
13451 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
13452 if (wpa_command(intf, buf) < 0) {
13453 send_resp(dut, conn, SIGMA_ERROR,
13454 "ErrorCode,Failed to send TDLS discovery");
13455 return 0;
13456 }
13457 return 1;
13458 }
13459
13460 val = get_param(cmd, "TD_Setup");
13461 if (val) {
13462 if (hwaddr_aton(val, addr) < 0)
13463 return -1;
13464 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
13465 if (wpa_command(intf, buf) < 0) {
13466 send_resp(dut, conn, SIGMA_ERROR,
13467 "ErrorCode,Failed to start TDLS setup");
13468 return 0;
13469 }
13470 return 1;
13471 }
13472
13473 val = get_param(cmd, "TD_TearDown");
13474 if (val) {
13475 if (hwaddr_aton(val, addr) < 0)
13476 return -1;
13477 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
13478 if (wpa_command(intf, buf) < 0) {
13479 send_resp(dut, conn, SIGMA_ERROR,
13480 "ErrorCode,Failed to tear down TDLS link");
13481 return 0;
13482 }
13483 return 1;
13484 }
13485
13486 val = get_param(cmd, "TD_ChannelSwitch");
13487 if (val) {
13488 /* TODO */
13489 send_resp(dut, conn, SIGMA_ERROR,
13490 "ErrorCode,TD_ChannelSwitch not yet supported");
13491 return 0;
13492 }
13493
13494 val = get_param(cmd, "TD_NF");
13495 if (val) {
13496 /* TODO */
13497 send_resp(dut, conn, SIGMA_ERROR,
13498 "ErrorCode,TD_NF not yet supported");
13499 return 0;
13500 }
13501
13502 val = get_param(cmd, "PMFFrameType");
13503 if (val == NULL)
13504 val = get_param(cmd, "FrameName");
13505 if (val == NULL)
13506 val = get_param(cmd, "Type");
13507 if (val == NULL)
13508 return -1;
13509 if (strcasecmp(val, "disassoc") == 0)
13510 frame = DISASSOC;
13511 else if (strcasecmp(val, "deauth") == 0)
13512 frame = DEAUTH;
13513 else if (strcasecmp(val, "saquery") == 0)
13514 frame = SAQUERY;
13515 else if (strcasecmp(val, "auth") == 0)
13516 frame = AUTH;
13517 else if (strcasecmp(val, "assocreq") == 0)
13518 frame = ASSOCREQ;
13519 else if (strcasecmp(val, "reassocreq") == 0)
13520 frame = REASSOCREQ;
13521 else if (strcasecmp(val, "neigreq") == 0) {
13522 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
13523
13524 val = get_param(cmd, "ssid");
13525 if (val == NULL)
13526 return -1;
13527
13528 res = send_neighbor_request(dut, intf, val);
13529 if (res) {
13530 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
13531 "Failed to send neighbor report request");
13532 return 0;
13533 }
13534
13535 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053013536 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
13537 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013538 sigma_dut_print(dut, DUT_MSG_DEBUG,
13539 "Got Transition Management Query");
13540
Ashwini Patil5acd7382017-04-13 15:55:04 +053013541 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013542 if (res) {
13543 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
13544 "Failed to send Transition Management Query");
13545 return 0;
13546 }
13547
13548 return 1;
13549 } else {
13550 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13551 "PMFFrameType");
13552 return 0;
13553 }
13554
13555 val = get_param(cmd, "PMFProtected");
13556 if (val == NULL)
13557 val = get_param(cmd, "Protected");
13558 if (val == NULL)
13559 return -1;
13560 if (strcasecmp(val, "Correct-key") == 0 ||
13561 strcasecmp(val, "CorrectKey") == 0)
13562 protected = CORRECT_KEY;
13563 else if (strcasecmp(val, "IncorrectKey") == 0)
13564 protected = INCORRECT_KEY;
13565 else if (strcasecmp(val, "Unprotected") == 0)
13566 protected = UNPROTECTED;
13567 else {
13568 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13569 "PMFProtected");
13570 return 0;
13571 }
13572
13573 if (protected != UNPROTECTED &&
13574 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
13575 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
13576 "PMFProtected for auth/assocreq/reassocreq");
13577 return 0;
13578 }
13579
13580 if (if_nametoindex("sigmadut") == 0) {
13581 snprintf(buf, sizeof(buf),
13582 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013583 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013584 if (system(buf) != 0 ||
13585 if_nametoindex("sigmadut") == 0) {
13586 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
13587 "monitor interface with '%s'", buf);
13588 return -2;
13589 }
13590 }
13591
13592 if (system("ifconfig sigmadut up") != 0) {
13593 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
13594 "monitor interface up");
13595 return -2;
13596 }
13597
Veerendranath Jakkam49774122020-07-05 09:52:18 +053013598 return sta_inject_frame(dut, conn, intf, frame, protected, NULL, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013599}
13600
13601
13602static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
13603 struct sigma_conn *conn,
13604 struct sigma_cmd *cmd,
13605 const char *ifname)
13606{
13607 char buf[200];
13608 const char *val;
13609
13610 val = get_param(cmd, "ClearARP");
13611 if (val && atoi(val) == 1) {
13612 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
13613 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13614 if (system(buf) != 0) {
13615 send_resp(dut, conn, SIGMA_ERROR,
13616 "errorCode,Failed to clear ARP cache");
13617 return 0;
13618 }
13619 }
13620
13621 return 1;
13622}
13623
13624
13625int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
13626 struct sigma_cmd *cmd)
13627{
13628 const char *intf = get_param(cmd, "Interface");
13629 const char *val;
13630
13631 if (intf == NULL)
13632 return -1;
13633
13634 val = get_param(cmd, "program");
13635 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030013636 strcasecmp(val, "HS2-R2") == 0 ||
13637 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013638 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
13639
13640 return -1;
13641}
13642
13643
Jouni Malinenf7222712019-06-13 01:50:21 +030013644static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
13645 struct sigma_conn *conn,
13646 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013647{
13648 const char *intf = get_param(cmd, "Interface");
13649 const char *mac = get_param(cmd, "MAC");
13650
13651 if (intf == NULL || mac == NULL)
13652 return -1;
13653
13654 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
13655 "interface %s to %s", intf, mac);
13656
13657 if (dut->set_macaddr) {
13658 char buf[128];
13659 int res;
13660 if (strcasecmp(mac, "default") == 0) {
13661 res = snprintf(buf, sizeof(buf), "%s",
13662 dut->set_macaddr);
13663 dut->tmp_mac_addr = 0;
13664 } else {
13665 res = snprintf(buf, sizeof(buf), "%s %s",
13666 dut->set_macaddr, mac);
13667 dut->tmp_mac_addr = 1;
13668 }
13669 if (res < 0 || res >= (int) sizeof(buf))
13670 return -1;
13671 if (system(buf) != 0) {
13672 send_resp(dut, conn, SIGMA_ERROR,
13673 "errorCode,Failed to set MAC "
13674 "address");
13675 return 0;
13676 }
13677 return 1;
13678 }
13679
13680 if (strcasecmp(mac, "default") == 0)
13681 return 1;
13682
13683 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13684 "command");
13685 return 0;
13686}
13687
13688
13689static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
13690 struct sigma_conn *conn, const char *intf,
13691 int val)
13692{
13693 char buf[200];
13694 int res;
13695
13696 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
13697 intf, val);
13698 if (res < 0 || res >= (int) sizeof(buf))
13699 return -1;
13700 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13701 if (system(buf) != 0) {
13702 send_resp(dut, conn, SIGMA_ERROR,
13703 "errorCode,Failed to configure offchannel mode");
13704 return 0;
13705 }
13706
13707 return 1;
13708}
13709
13710
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013711static int off_chan_val(enum sec_ch_offset off)
13712{
13713 switch (off) {
13714 case SEC_CH_NO:
13715 return 0;
13716 case SEC_CH_40ABOVE:
13717 return 40;
13718 case SEC_CH_40BELOW:
13719 return -40;
13720 }
13721
13722 return 0;
13723}
13724
13725
13726static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
13727 const char *intf, int off_ch_num,
13728 enum sec_ch_offset sec)
13729{
13730 char buf[200];
13731 int res;
13732
13733 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
13734 intf, off_ch_num);
13735 if (res < 0 || res >= (int) sizeof(buf))
13736 return -1;
13737 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13738 if (system(buf) != 0) {
13739 send_resp(dut, conn, SIGMA_ERROR,
13740 "errorCode,Failed to set offchan");
13741 return 0;
13742 }
13743
13744 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
13745 intf, off_chan_val(sec));
13746 if (res < 0 || res >= (int) sizeof(buf))
13747 return -1;
13748 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13749 if (system(buf) != 0) {
13750 send_resp(dut, conn, SIGMA_ERROR,
13751 "errorCode,Failed to set sec chan offset");
13752 return 0;
13753 }
13754
13755 return 1;
13756}
13757
13758
13759static int tdls_set_offchannel_offset(struct sigma_dut *dut,
13760 struct sigma_conn *conn,
13761 const char *intf, int off_ch_num,
13762 enum sec_ch_offset sec)
13763{
13764 char buf[200];
13765 int res;
13766
13767 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
13768 off_ch_num);
13769 if (res < 0 || res >= (int) sizeof(buf))
13770 return -1;
13771 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13772
13773 if (wpa_command(intf, buf) < 0) {
13774 send_resp(dut, conn, SIGMA_ERROR,
13775 "ErrorCode,Failed to set offchan");
13776 return 0;
13777 }
13778 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
13779 off_chan_val(sec));
13780 if (res < 0 || res >= (int) sizeof(buf))
13781 return -1;
13782
13783 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13784
13785 if (wpa_command(intf, buf) < 0) {
13786 send_resp(dut, conn, SIGMA_ERROR,
13787 "ErrorCode,Failed to set sec chan offset");
13788 return 0;
13789 }
13790
13791 return 1;
13792}
13793
13794
13795static int tdls_set_offchannel_mode(struct sigma_dut *dut,
13796 struct sigma_conn *conn,
13797 const char *intf, int val)
13798{
13799 char buf[200];
13800 int res;
13801
13802 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
13803 val);
13804 if (res < 0 || res >= (int) sizeof(buf))
13805 return -1;
13806 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13807
13808 if (wpa_command(intf, buf) < 0) {
13809 send_resp(dut, conn, SIGMA_ERROR,
13810 "ErrorCode,Failed to configure offchannel mode");
13811 return 0;
13812 }
13813
13814 return 1;
13815}
13816
13817
13818static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
13819 struct sigma_conn *conn,
13820 struct sigma_cmd *cmd)
13821{
13822 const char *val;
13823 enum {
13824 CHSM_NOT_SET,
13825 CHSM_ENABLE,
13826 CHSM_DISABLE,
13827 CHSM_REJREQ,
13828 CHSM_UNSOLRESP
13829 } chsm = CHSM_NOT_SET;
13830 int off_ch_num = -1;
13831 enum sec_ch_offset sec_ch = SEC_CH_NO;
13832 int res;
13833
13834 val = get_param(cmd, "Uapsd");
13835 if (val) {
13836 char buf[100];
13837 if (strcasecmp(val, "Enable") == 0)
13838 snprintf(buf, sizeof(buf), "SET ps 99");
13839 else if (strcasecmp(val, "Disable") == 0)
13840 snprintf(buf, sizeof(buf), "SET ps 98");
13841 else {
13842 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
13843 "Unsupported uapsd parameter value");
13844 return 0;
13845 }
13846 if (wpa_command(intf, buf)) {
13847 send_resp(dut, conn, SIGMA_ERROR,
13848 "ErrorCode,Failed to change U-APSD "
13849 "powersave mode");
13850 return 0;
13851 }
13852 }
13853
13854 val = get_param(cmd, "TPKTIMER");
13855 if (val && strcasecmp(val, "DISABLE") == 0) {
13856 if (wpa_command(intf, "SET tdls_testing 0x100")) {
13857 send_resp(dut, conn, SIGMA_ERROR,
13858 "ErrorCode,Failed to enable no TPK "
13859 "expiration test mode");
13860 return 0;
13861 }
13862 dut->no_tpk_expiration = 1;
13863 }
13864
13865 val = get_param(cmd, "ChSwitchMode");
13866 if (val) {
13867 if (strcasecmp(val, "Enable") == 0 ||
13868 strcasecmp(val, "Initiate") == 0)
13869 chsm = CHSM_ENABLE;
13870 else if (strcasecmp(val, "Disable") == 0 ||
13871 strcasecmp(val, "passive") == 0)
13872 chsm = CHSM_DISABLE;
13873 else if (strcasecmp(val, "RejReq") == 0)
13874 chsm = CHSM_REJREQ;
13875 else if (strcasecmp(val, "UnSolResp") == 0)
13876 chsm = CHSM_UNSOLRESP;
13877 else {
13878 send_resp(dut, conn, SIGMA_ERROR,
13879 "ErrorCode,Unknown ChSwitchMode value");
13880 return 0;
13881 }
13882 }
13883
13884 val = get_param(cmd, "OffChNum");
13885 if (val) {
13886 off_ch_num = atoi(val);
13887 if (off_ch_num == 0) {
13888 send_resp(dut, conn, SIGMA_ERROR,
13889 "ErrorCode,Invalid OffChNum");
13890 return 0;
13891 }
13892 }
13893
13894 val = get_param(cmd, "SecChOffset");
13895 if (val) {
13896 if (strcmp(val, "20") == 0)
13897 sec_ch = SEC_CH_NO;
13898 else if (strcasecmp(val, "40above") == 0)
13899 sec_ch = SEC_CH_40ABOVE;
13900 else if (strcasecmp(val, "40below") == 0)
13901 sec_ch = SEC_CH_40BELOW;
13902 else {
13903 send_resp(dut, conn, SIGMA_ERROR,
13904 "ErrorCode,Unknown SecChOffset value");
13905 return 0;
13906 }
13907 }
13908
13909 if (chsm == CHSM_NOT_SET) {
13910 /* no offchannel changes requested */
13911 return 1;
13912 }
13913
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013914 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
13915 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013916 send_resp(dut, conn, SIGMA_ERROR,
13917 "ErrorCode,Unknown interface");
13918 return 0;
13919 }
13920
13921 switch (chsm) {
13922 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030013923 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013924 break;
13925 case CHSM_ENABLE:
13926 if (off_ch_num < 0) {
13927 send_resp(dut, conn, SIGMA_ERROR,
13928 "ErrorCode,Missing OffChNum argument");
13929 return 0;
13930 }
13931 if (wifi_chip_type == DRIVER_WCN) {
13932 res = tdls_set_offchannel_offset(dut, conn, intf,
13933 off_ch_num, sec_ch);
13934 } else {
13935 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
13936 sec_ch);
13937 }
13938 if (res != 1)
13939 return res;
13940 if (wifi_chip_type == DRIVER_WCN)
13941 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
13942 else
13943 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
13944 break;
13945 case CHSM_DISABLE:
13946 if (wifi_chip_type == DRIVER_WCN)
13947 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
13948 else
13949 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
13950 break;
13951 case CHSM_REJREQ:
13952 if (wifi_chip_type == DRIVER_WCN)
13953 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
13954 else
13955 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
13956 break;
13957 case CHSM_UNSOLRESP:
13958 if (off_ch_num < 0) {
13959 send_resp(dut, conn, SIGMA_ERROR,
13960 "ErrorCode,Missing OffChNum argument");
13961 return 0;
13962 }
13963 if (wifi_chip_type == DRIVER_WCN) {
13964 res = tdls_set_offchannel_offset(dut, conn, intf,
13965 off_ch_num, sec_ch);
13966 } else {
13967 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
13968 sec_ch);
13969 }
13970 if (res != 1)
13971 return res;
13972 if (wifi_chip_type == DRIVER_WCN)
13973 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
13974 else
13975 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
13976 break;
13977 }
13978
13979 return res;
13980}
13981
13982
13983static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
13984 struct sigma_conn *conn,
13985 struct sigma_cmd *cmd)
13986{
13987 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053013988 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013989
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070013990 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080013991
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013992 val = get_param(cmd, "nss_mcs_opt");
13993 if (val) {
13994 /* String (nss_operating_mode; mcs_operating_mode) */
13995 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053013996 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013997
13998 token = strdup(val);
13999 if (!token)
14000 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053014001 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053014002 if (!result) {
14003 sigma_dut_print(dut, DUT_MSG_ERROR,
14004 "VHT NSS not specified");
14005 goto failed;
14006 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014007 if (strcasecmp(result, "def") != 0) {
14008 nss = atoi(result);
14009 if (nss == 4)
14010 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070014011 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014012 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070014013
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014014 }
14015
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053014016 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053014017 if (!result) {
14018 sigma_dut_print(dut, DUT_MSG_ERROR,
14019 "VHT MCS not specified");
14020 goto failed;
14021 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014022 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070014023 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014024 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014025 } else {
14026 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070014027 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014028 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014029 }
14030 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070014031 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014032 }
14033
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053014034 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014035 return 1;
14036failed:
14037 free(token);
14038 return 0;
14039}
14040
14041
14042static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
14043 struct sigma_conn *conn,
14044 struct sigma_cmd *cmd)
14045{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014046 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014047 case DRIVER_ATHEROS:
14048 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
14049 default:
14050 send_resp(dut, conn, SIGMA_ERROR,
14051 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
14052 return 0;
14053 }
14054}
14055
14056
Jouni Malinen1702fe32021-06-08 19:08:01 +030014057static enum sigma_cmd_result
14058wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
14059 struct sigma_conn *conn, struct sigma_cmd *cmd)
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014060{
14061 const char *val;
14062 char *token = NULL, *result;
14063 char buf[60];
14064
14065 val = get_param(cmd, "nss_mcs_opt");
14066 if (val) {
14067 /* String (nss_operating_mode; mcs_operating_mode) */
14068 int nss, mcs, ratecode;
14069 char *saveptr;
14070
14071 token = strdup(val);
14072 if (!token)
Jouni Malinen1702fe32021-06-08 19:08:01 +030014073 return ERROR_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014074
14075 result = strtok_r(token, ";", &saveptr);
14076 if (!result) {
14077 sigma_dut_print(dut, DUT_MSG_ERROR,
14078 "HE NSS not specified");
14079 goto failed;
14080 }
14081 nss = 1;
14082 if (strcasecmp(result, "def") != 0)
14083 nss = atoi(result);
14084
14085 result = strtok_r(NULL, ";", &saveptr);
14086 if (!result) {
14087 sigma_dut_print(dut, DUT_MSG_ERROR,
14088 "HE MCS not specified");
14089 goto failed;
14090 }
14091 mcs = 7;
14092 if (strcasecmp(result, "def") != 0)
14093 mcs = atoi(result);
14094
Arif Hussain557bf412018-05-25 17:29:36 -070014095 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014096 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070014097 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014098 } else if (nss > 2) {
14099 sigma_dut_print(dut, DUT_MSG_ERROR,
14100 "HE NSS %d not supported", nss);
14101 goto failed;
14102 }
14103
Arif Hussain557bf412018-05-25 17:29:36 -070014104 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
14105 if (system(buf) != 0) {
14106 sigma_dut_print(dut, DUT_MSG_ERROR,
14107 "nss_mcs_opt: iwpriv %s nss %d failed",
14108 intf, nss);
14109 goto failed;
14110 }
Arif Hussainac6c5112018-05-25 17:34:00 -070014111 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070014112
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014113 /* Add the MCS to the ratecode */
14114 if (mcs >= 0 && mcs <= 11) {
14115 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070014116#ifdef NL80211_SUPPORT
14117 if (dut->device_type == STA_testbed) {
14118 enum he_mcs_config mcs_config;
14119 int ret;
14120
14121 if (mcs <= 7)
14122 mcs_config = HE_80_MCS0_7;
14123 else if (mcs <= 9)
14124 mcs_config = HE_80_MCS0_9;
14125 else
14126 mcs_config = HE_80_MCS0_11;
14127 ret = sta_set_he_mcs(dut, intf, mcs_config);
14128 if (ret) {
14129 sigma_dut_print(dut, DUT_MSG_ERROR,
14130 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
14131 mcs, mcs_config, ret);
14132 goto failed;
14133 }
14134 }
14135#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014136 } else {
14137 sigma_dut_print(dut, DUT_MSG_ERROR,
14138 "HE MCS %d not supported", mcs);
14139 goto failed;
14140 }
14141 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
14142 intf, ratecode);
14143 if (system(buf) != 0) {
14144 sigma_dut_print(dut, DUT_MSG_ERROR,
14145 "iwpriv setting of 11ax rates failed");
14146 goto failed;
14147 }
14148 free(token);
14149 }
14150
14151 val = get_param(cmd, "GI");
14152 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014153 int fix_rate_sgi;
14154
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014155 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070014156 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014157 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014158 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070014159 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
14160 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014161 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014162 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070014163 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
14164 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014165 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014166 } else {
14167 send_resp(dut, conn, SIGMA_ERROR,
14168 "errorCode,GI value not supported");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014169 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014170 }
14171 if (system(buf) != 0) {
14172 send_resp(dut, conn, SIGMA_ERROR,
14173 "errorCode,Failed to set shortgi");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014174 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014175 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014176 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
14177 intf, fix_rate_sgi);
14178 if (system(buf) != 0) {
14179 send_resp(dut, conn, SIGMA_ERROR,
14180 "errorCode,Failed to set fix rate shortgi");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014181 return STATUS_SENT_ERROR;
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014182 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014183 }
14184
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014185 val = get_param(cmd, "LTF");
14186 if (val) {
14187#ifdef NL80211_SUPPORT
14188 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080014189 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014190 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080014191 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014192 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080014193 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014194 } else {
14195 send_resp(dut, conn, SIGMA_ERROR,
14196 "errorCode, LTF value not supported");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014197 return STATUS_SENT_ERROR;
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014198 }
14199#else /* NL80211_SUPPORT */
14200 sigma_dut_print(dut, DUT_MSG_ERROR,
14201 "LTF cannot be set without NL80211_SUPPORT defined");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014202 return ERROR_SEND_STATUS;
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014203#endif /* NL80211_SUPPORT */
14204 }
14205
Kiran Kumar Lokere1809da12021-06-24 00:45:38 -070014206 val = get_param(cmd, "KeepAlive");
14207 if (val) {
14208 int set_val = QCA_WLAN_KEEP_ALIVE_DEFAULT;
14209
14210 if (strcasecmp(val, "Data") == 0)
14211 set_val = QCA_WLAN_KEEP_ALIVE_DATA;
14212 else if (strcasecmp(val, "Mgmt") == 0)
14213 set_val = QCA_WLAN_KEEP_ALIVE_MGMT;
14214
14215 if (sta_set_keep_alive_data_cfg(dut, intf, set_val)) {
14216 send_resp(dut, conn, SIGMA_ERROR,
14217 "ErrorCode,Failed to set keep alive type config");
14218 return STATUS_SENT_ERROR;
14219 }
14220 }
14221
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070014222 val = get_param(cmd, "TxSUPPDU");
14223 if (val) {
14224 int set_val = 1;
14225
14226 if (strcasecmp(val, "Enable") == 0)
14227 set_val = 1;
14228 else if (strcasecmp(val, "Disable") == 0)
14229 set_val = 0;
14230
14231 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
14232 send_resp(dut, conn, SIGMA_ERROR,
14233 "ErrorCode,Failed to set Tx SU PPDU config");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014234 return STATUS_SENT_ERROR;
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070014235 }
14236 }
14237
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -070014238 val = get_param(cmd, "Mgmt_Data_TX_Resp_Frame");
14239 if (val) {
14240 int set_val = 0;
14241
14242 if (strcasecmp(val, "Enable") == 0)
14243 set_val = 0;
14244 else if (strcasecmp(val, "Disable") == 0)
14245 set_val = 1;
14246
14247 if (sta_set_mgmt_data_tx_disable_cfg(dut, intf, set_val)) {
14248 send_resp(dut, conn, SIGMA_ERROR,
14249 "ErrorCode,Failed to set mgmt/data Tx disable config");
14250 return STATUS_SENT_ERROR;
14251 }
14252 }
14253
Arif Hussain480d5f42019-03-12 14:40:42 -070014254 val = get_param(cmd, "TWT_Setup");
14255 if (val) {
14256 if (strcasecmp(val, "Request") == 0) {
14257 if (sta_twt_request(dut, conn, cmd)) {
14258 send_resp(dut, conn, SIGMA_ERROR,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070014259 "ErrorCode,TWT setup failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014260 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070014261 }
14262 } else if (strcasecmp(val, "Teardown") == 0) {
14263 if (sta_twt_teardown(dut, conn, cmd)) {
14264 send_resp(dut, conn, SIGMA_ERROR,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070014265 "ErrorCode,TWT teardown failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014266 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070014267 }
14268 }
14269 }
14270
Srinivas Girigowda6707f032020-10-26 15:24:46 -070014271 val = get_param(cmd, "TWT_Operation");
14272 if (val) {
14273 if (strcasecmp(val, "Suspend") == 0) {
14274 if (sta_twt_suspend_or_nudge(dut, conn, cmd)) {
14275 send_resp(dut, conn, SIGMA_ERROR,
14276 "ErrorCode,TWT suspend failed");
14277 return STATUS_SENT_ERROR;
14278 }
14279 } else if (strcasecmp(val, "Resume") == 0) {
14280 if (sta_twt_resume(dut, conn, cmd)) {
14281 send_resp(dut, conn, SIGMA_ERROR,
14282 "ErrorCode,TWT resume failed");
14283 return STATUS_SENT_ERROR;
14284 }
14285 }
14286 }
14287
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080014288 val = get_param(cmd, "transmitOMI");
14289 if (val && sta_transmit_omi(dut, conn, cmd)) {
14290 send_resp(dut, conn, SIGMA_ERROR,
14291 "ErrorCode,sta_transmit_omi failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014292 return STATUS_SENT_ERROR;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070014293 }
14294
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014295 val = get_param(cmd, "Powersave");
14296 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014297 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014298
14299 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014300 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014301 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014302 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014303 } else {
14304 sigma_dut_print(dut, DUT_MSG_ERROR,
14305 "Unsupported Powersave value '%s'",
14306 val);
Jouni Malinen1702fe32021-06-08 19:08:01 +030014307 return INVALID_SEND_STATUS;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014308 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014309 if (set_power_save_wcn(dut, intf, ps) < 0)
Jouni Malinen1702fe32021-06-08 19:08:01 +030014310 return ERROR_SEND_STATUS;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014311 }
14312
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080014313 val = get_param(cmd, "MU_EDCA");
14314 if (val) {
14315 if (strcasecmp(val, "Override") == 0) {
14316 if (sta_set_mu_edca_override(dut, intf, 1)) {
14317 send_resp(dut, conn, SIGMA_ERROR,
14318 "errorCode,MU EDCA override set failed");
14319 return STATUS_SENT;
14320 }
14321 } else if (strcasecmp(val, "Disable") == 0) {
14322 if (sta_set_mu_edca_override(dut, intf, 0)) {
14323 send_resp(dut, conn, SIGMA_ERROR,
14324 "errorCode,MU EDCA override disable failed");
14325 return STATUS_SENT;
14326 }
14327 }
14328 }
14329
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -070014330 val = get_param(cmd, "RUAllocTone");
14331 if (val && strcasecmp(val, "242") == 0) {
14332 if (sta_set_ru_242_tone_tx(dut, intf, 1)) {
14333 send_resp(dut, conn, SIGMA_ERROR,
14334 "ErrorCode,Failed to set RU 242 tone Tx");
14335 return STATUS_SENT_ERROR;
14336 }
14337 }
14338
14339 val = get_param(cmd, "PPDUTxType");
14340 if (val && strcasecmp(val, "ER-SU") == 0) {
14341 if (sta_set_er_su_ppdu_type_tx(dut, intf, 1)) {
14342 send_resp(dut, conn, SIGMA_ERROR,
14343 "ErrorCode,Failed to set ER-SU PPDU type Tx");
14344 return STATUS_SENT_ERROR;
14345 }
14346 }
14347
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -070014348 val = get_param(cmd, "Ch_Pref");
14349 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
14350 return STATUS_SENT;
14351
14352 val = get_param(cmd, "Cellular_Data_Cap");
14353 if (val && mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
14354 return STATUS_SENT;
14355
Jouni Malinen1702fe32021-06-08 19:08:01 +030014356 return SUCCESS_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014357
14358failed:
14359 free(token);
Jouni Malinen1702fe32021-06-08 19:08:01 +030014360 return ERROR_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014361}
14362
14363
Jouni Malinen1702fe32021-06-08 19:08:01 +030014364static enum sigma_cmd_result
14365cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
14366 struct sigma_conn *conn, struct sigma_cmd *cmd)
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014367{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014368 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014369 case DRIVER_WCN:
14370 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
14371 default:
14372 send_resp(dut, conn, SIGMA_ERROR,
14373 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014374 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014375 }
14376}
14377
14378
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014379static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
14380 struct sigma_conn *conn,
14381 struct sigma_cmd *cmd)
14382{
14383 const char *val;
14384
14385 val = get_param(cmd, "powersave");
14386 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014387 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014388
14389 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014390 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014391 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014392 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014393 } else {
14394 sigma_dut_print(dut, DUT_MSG_ERROR,
14395 "Unsupported power save config");
14396 return -1;
14397 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014398 if (set_power_save_wcn(dut, intf, ps) < 0)
14399 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014400 return 1;
14401 }
14402
14403 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
14404
14405 return 0;
14406}
14407
14408
Ashwini Patil5acd7382017-04-13 15:55:04 +053014409static int btm_query_candidate_list(struct sigma_dut *dut,
14410 struct sigma_conn *conn,
14411 struct sigma_cmd *cmd)
14412{
14413 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
14414 int len, ret;
14415 char buf[10];
14416
14417 /*
14418 * Neighbor Report elements format:
14419 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
14420 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
14421 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
14422 */
14423
14424 bssid = get_param(cmd, "Nebor_BSSID");
14425 if (!bssid) {
14426 send_resp(dut, conn, SIGMA_INVALID,
14427 "errorCode,Nebor_BSSID is missing");
14428 return 0;
14429 }
14430
14431 info = get_param(cmd, "Nebor_Bssid_Info");
14432 if (!info) {
14433 sigma_dut_print(dut, DUT_MSG_INFO,
14434 "Using default value for Nebor_Bssid_Info: %s",
14435 DEFAULT_NEIGHBOR_BSSID_INFO);
14436 info = DEFAULT_NEIGHBOR_BSSID_INFO;
14437 }
14438
14439 op_class = get_param(cmd, "Nebor_Op_Class");
14440 if (!op_class) {
14441 send_resp(dut, conn, SIGMA_INVALID,
14442 "errorCode,Nebor_Op_Class is missing");
14443 return 0;
14444 }
14445
14446 ch = get_param(cmd, "Nebor_Op_Ch");
14447 if (!ch) {
14448 send_resp(dut, conn, SIGMA_INVALID,
14449 "errorCode,Nebor_Op_Ch is missing");
14450 return 0;
14451 }
14452
14453 phy_type = get_param(cmd, "Nebor_Phy_Type");
14454 if (!phy_type) {
14455 sigma_dut_print(dut, DUT_MSG_INFO,
14456 "Using default value for Nebor_Phy_Type: %s",
14457 DEFAULT_NEIGHBOR_PHY_TYPE);
14458 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
14459 }
14460
14461 /* Parse optional subelements */
14462 buf[0] = '\0';
14463 pref = get_param(cmd, "Nebor_Pref");
14464 if (pref) {
14465 /* hexdump for preferrence subelement */
14466 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
14467 if (ret < 0 || ret >= (int) sizeof(buf)) {
14468 sigma_dut_print(dut, DUT_MSG_ERROR,
14469 "snprintf failed for optional subelement ret: %d",
14470 ret);
14471 send_resp(dut, conn, SIGMA_ERROR,
14472 "errorCode,snprintf failed for subelement");
14473 return 0;
14474 }
14475 }
14476
14477 if (!dut->btm_query_cand_list) {
14478 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
14479 if (!dut->btm_query_cand_list) {
14480 send_resp(dut, conn, SIGMA_ERROR,
14481 "errorCode,Failed to allocate memory for btm_query_cand_list");
14482 return 0;
14483 }
14484 }
14485
14486 len = strlen(dut->btm_query_cand_list);
14487 ret = snprintf(dut->btm_query_cand_list + len,
14488 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
14489 bssid, info, op_class, ch, phy_type, buf);
14490 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
14491 sigma_dut_print(dut, DUT_MSG_ERROR,
14492 "snprintf failed for neighbor report list ret: %d",
14493 ret);
14494 send_resp(dut, conn, SIGMA_ERROR,
14495 "errorCode,snprintf failed for neighbor report");
14496 free(dut->btm_query_cand_list);
14497 dut->btm_query_cand_list = NULL;
14498 return 0;
14499 }
14500
14501 return 1;
14502}
14503
14504
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014505int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
14506 struct sigma_ese_alloc *allocs, int *allocs_size)
14507{
14508 int max_count = *allocs_size;
14509 int count = 0, i;
14510 const char *val;
14511
14512 do {
14513 val = get_param_indexed(cmd, "AllocID", count);
14514 if (val)
14515 count++;
14516 } while (val);
14517
14518 if (count == 0 || count > max_count) {
14519 sigma_dut_print(dut, DUT_MSG_ERROR,
14520 "Invalid number of allocations(%d)", count);
14521 return -1;
14522 }
14523
14524 for (i = 0; i < count; i++) {
14525 val = get_param_indexed(cmd, "PercentBI", i);
14526 if (!val) {
14527 sigma_dut_print(dut, DUT_MSG_ERROR,
14528 "Missing PercentBI parameter at index %d",
14529 i);
14530 return -1;
14531 }
14532 allocs[i].percent_bi = atoi(val);
14533
14534 val = get_param_indexed(cmd, "SrcAID", i);
14535 if (val)
14536 allocs[i].src_aid = strtol(val, NULL, 0);
14537 else
14538 allocs[i].src_aid = ESE_BCAST_AID;
14539
14540 val = get_param_indexed(cmd, "DestAID", i);
14541 if (val)
14542 allocs[i].dst_aid = strtol(val, NULL, 0);
14543 else
14544 allocs[i].dst_aid = ESE_BCAST_AID;
14545
14546 allocs[i].type = ESE_CBAP;
14547 sigma_dut_print(dut, DUT_MSG_INFO,
14548 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
14549 i, allocs[i].percent_bi, allocs[i].src_aid,
14550 allocs[i].dst_aid);
14551 }
14552
14553 *allocs_size = count;
14554 return 0;
14555}
14556
14557
14558static int sta_set_60g_ese(struct sigma_dut *dut, int count,
14559 struct sigma_ese_alloc *allocs)
14560{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014561 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014562#ifdef __linux__
14563 case DRIVER_WIL6210:
14564 if (wil6210_set_ese(dut, count, allocs))
14565 return -1;
14566 return 1;
14567#endif /* __linux__ */
14568 default:
14569 sigma_dut_print(dut, DUT_MSG_ERROR,
14570 "Unsupported sta_set_60g_ese with the current driver");
14571 return -1;
14572 }
14573}
14574
14575
14576static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
14577 struct sigma_conn *conn,
14578 struct sigma_cmd *cmd)
14579{
14580 const char *val;
14581
14582 val = get_param(cmd, "ExtSchIE");
14583 if (val && !strcasecmp(val, "Enable")) {
14584 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
14585 int count = MAX_ESE_ALLOCS;
14586
14587 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
14588 return -1;
14589 return sta_set_60g_ese(dut, count, allocs);
14590 }
14591
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020014592 val = get_param(cmd, "MCS_FixedRate");
14593 if (val) {
14594 int sta_mcs = atoi(val);
14595
14596 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
14597 sta_mcs);
14598 wil6210_set_force_mcs(dut, 1, sta_mcs);
14599
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014600 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020014601 }
14602
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014603 send_resp(dut, conn, SIGMA_ERROR,
14604 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014605 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014606}
14607
14608
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053014609static int wcn_sta_override_oci(struct sigma_dut *dut, const char *intf,
14610 const char *oci_frametype, uint32_t oci_freq)
14611{
14612#ifdef NL80211_SUPPORT
14613 struct nl_msg *msg;
14614 int ret = 0;
14615 struct nlattr *params;
14616 struct nlattr *attr;
14617 int ifindex;
14618 u8 frame_type;
14619
14620 ifindex = if_nametoindex(intf);
14621 if (ifindex == 0) {
14622 sigma_dut_print(dut, DUT_MSG_ERROR,
14623 "%s: Index for interface %s failed",
14624 __func__, intf);
14625 return -1;
14626 }
14627
14628 if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
14629 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_REQ;
14630 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
14631 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_RESP;
14632 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
14633 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_FT_REASSOC_REQ;
14634 } else {
14635 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: Unknown frametype %s",
14636 __func__, oci_frametype);
14637 return -1;
14638 }
14639
14640
14641 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
14642 NL80211_CMD_VENDOR)) ||
14643 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
14644 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
14645 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
14646 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
14647 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
14648 !(params = nla_nest_start(
14649 msg,
14650 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OCI_OVERRIDE)) ||
14651 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FRAME_TYPE,
14652 frame_type) ||
14653 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FREQUENCY,
14654 oci_freq)) {
14655 sigma_dut_print(dut, DUT_MSG_ERROR,
14656 "%s: err in adding vendor_cmd and vendor_data",
14657 __func__);
14658 nlmsg_free(msg);
14659 return -1;
14660 }
14661 nla_nest_end(msg, params);
14662 nla_nest_end(msg, attr);
14663
14664 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
14665 if (ret) {
14666 sigma_dut_print(dut, DUT_MSG_ERROR,
14667 "%s: err in send_and_recv_msgs, ret=%d",
14668 __func__, ret);
14669 }
14670 return ret;
14671#else /* NL80211_SUPPORT */
14672 sigma_dut_print(dut, DUT_MSG_ERROR,
14673 "OCI override not possible without NL80211_SUPPORT defined");
14674 return -1;
14675#endif /* NL80211_SUPPORT */
14676}
14677
14678
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053014679static int wcn_sta_ignore_csa(struct sigma_dut *dut, const char *intf,
14680 uint8_t ignore_csa)
14681{
14682#ifdef NL80211_SUPPORT
14683 return wcn_wifi_test_config_set_u8(
14684 dut, intf,
14685 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_CSA, ignore_csa);
14686#else /* NL80211_SUPPORT */
14687 sigma_dut_print(dut, DUT_MSG_ERROR,
14688 "IgnoreCSA can't be set without NL80211_SUPPORT defined");
14689 return -1;
14690#endif /* NL80211_SUPPORT */
14691}
14692
14693
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053014694static int wcn_sta_set_rsnxe_used(struct sigma_dut *dut, const char *intf,
14695 uint8_t rsnxe_used)
14696{
14697#ifdef NL80211_SUPPORT
14698 return wcn_wifi_test_config_set_u8(
14699 dut, intf,
14700 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FT_REASSOCREQ_RSNXE_USED,
14701 rsnxe_used);
14702#else /* NL80211_SUPPORT */
14703 sigma_dut_print(dut, DUT_MSG_ERROR,
14704 "RSNXE_Used can't be set without NL80211_SUPPORT defined");
14705 return -1;
14706#endif /* NL80211_SUPPORT */
14707}
14708
14709
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053014710static int wcn_sta_ignore_sa_query_timeout(struct sigma_dut *dut,
14711 const char *intf,
14712 uint8_t ignore_sa_query_timeout)
14713{
14714#ifdef NL80211_SUPPORT
14715 return wcn_wifi_test_config_set_u8(
14716 dut, intf,
14717 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_SA_QUERY_TIMEOUT,
14718 ignore_sa_query_timeout);
14719#else /* NL80211_SUPPORT */
14720 sigma_dut_print(dut, DUT_MSG_ERROR,
14721 "Ignore SA Query timeout can't be set without NL80211_SUPPORT defined");
14722 return -1;
14723#endif /* NL80211_SUPPORT */
14724}
14725
14726
Jouni Malinen6250cb02020-04-15 13:54:45 +030014727static enum sigma_cmd_result
14728cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
14729 struct sigma_conn *conn,
14730 struct sigma_cmd *cmd)
14731{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014732 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030014733
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053014734 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030014735 if (val && atoi(val) == 1) {
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053014736 if (wifi_chip_type == DRIVER_WCN) {
14737 if (wcn_sta_set_rsnxe_used(dut, intf, 1)) {
14738 send_resp(dut, conn, SIGMA_ERROR,
14739 "errorCode,Failed to set ft_rsnxe_used");
14740 return STATUS_SENT_ERROR;
14741 }
14742 return SUCCESS_SEND_STATUS;
14743 } else if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
Jouni Malinen6250cb02020-04-15 13:54:45 +030014744 send_resp(dut, conn, SIGMA_ERROR,
14745 "errorCode,Failed to set ft_rsnxe_used");
14746 return STATUS_SENT_ERROR;
14747 }
14748 return SUCCESS_SEND_STATUS;
14749 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014750
14751 oci_chan = get_param(cmd, "OCIChannel");
14752 oci_frametype = get_param(cmd, "OCIFrameType");
14753 if (oci_chan && oci_frametype) {
14754 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
14755 char buf[100];
14756
14757 if (!oci_freq) {
14758 send_resp(dut, conn, SIGMA_ERROR,
14759 "errorCode,Invalid OCIChannel number");
14760 return STATUS_SENT_ERROR;
14761 }
14762
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053014763 if (wifi_chip_type == DRIVER_WCN &&
14764 (strcasecmp(oci_frametype, "SAQueryReq") == 0 ||
14765 strcasecmp(oci_frametype, "SAQueryResp") == 0 ||
14766 strcasecmp(oci_frametype, "Reassocreq") == 0)) {
14767 if (wcn_sta_override_oci(dut, intf, oci_frametype,
14768 oci_freq)) {
14769 send_resp(dut, conn, SIGMA_ERROR,
14770 "errorCode,Failed to override OCI");
14771 return STATUS_SENT_ERROR;
14772 }
14773 return SUCCESS_SEND_STATUS;
14774 }
14775
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014776 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
14777 snprintf(buf, sizeof(buf),
14778 "SET oci_freq_override_eapol %d", oci_freq);
14779 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
14780 snprintf(buf, sizeof(buf),
14781 "SET oci_freq_override_saquery_req %d",
14782 oci_freq);
14783 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
14784 snprintf(buf, sizeof(buf),
14785 "SET oci_freq_override_saquery_resp %d",
14786 oci_freq);
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053014787 } else if (strcasecmp(oci_frametype, "GrpKeyM2") == 0) {
14788 snprintf(buf, sizeof(buf),
14789 "SET oci_freq_override_eapol_g2 %d",
14790 oci_freq);
14791 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
14792 snprintf(buf, sizeof(buf),
14793 "SET oci_freq_override_ft_assoc %d",
14794 oci_freq);
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014795 } else {
14796 send_resp(dut, conn, SIGMA_ERROR,
14797 "errorCode,Unsupported OCIFrameType");
14798 return STATUS_SENT_ERROR;
14799 }
14800 if (wpa_command(intf, buf) < 0) {
14801 send_resp(dut, conn, SIGMA_ERROR,
14802 "errorCode,Failed to set oci_freq_override");
14803 return STATUS_SENT_ERROR;
14804 }
14805 return SUCCESS_SEND_STATUS;
14806 }
14807
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053014808 val = get_param(cmd, "IgnoreCSA");
14809 if (val && atoi(val) == 1) {
14810 if (wifi_chip_type == DRIVER_WCN) {
14811 if (wcn_sta_ignore_csa(dut, intf, 1)) {
14812 send_resp(dut, conn, SIGMA_ERROR,
14813 "errorCode,Failed to set ignore CSA");
14814 return STATUS_SENT_ERROR;
14815 }
14816 return SUCCESS_SEND_STATUS;
14817 }
14818 }
14819
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053014820 val = get_param(cmd, "Deauth_Per_SAQueryResp");
14821 if (val && atoi(val) == 0) {
14822 if (wifi_chip_type == DRIVER_WCN) {
14823 if (wcn_sta_ignore_sa_query_timeout(dut, intf, 1)) {
14824 send_resp(dut, conn, SIGMA_ERROR,
14825 "errorCode,Failed to set ignore SA Query timeout");
14826 return STATUS_SENT_ERROR;
14827 }
14828 return SUCCESS_SEND_STATUS;
14829 }
14830 }
14831
Jouni Malinen6250cb02020-04-15 13:54:45 +030014832 send_resp(dut, conn, SIGMA_ERROR,
14833 "errorCode,Unsupported WPA3 rfeature");
14834 return STATUS_SENT_ERROR;
14835}
14836
14837
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053014838static enum sigma_cmd_result
14839cmd_sta_set_rfeature_qm(const char *intf, struct sigma_dut *dut,
14840 struct sigma_conn *conn, struct sigma_cmd *cmd)
14841{
14842 const char *val;
14843
14844 val = get_param(cmd, "DomainName_Domain");
14845 if (val) {
14846 if (strlen(val) >= sizeof(dut->qm_domain_name))
14847 return ERROR_SEND_STATUS;
14848
14849 strlcpy(dut->qm_domain_name, val, sizeof(dut->qm_domain_name));
14850 return SUCCESS_SEND_STATUS;
14851 }
14852
Veerendranath Jakkam1bf1bd62021-09-12 16:35:55 +053014853 val = get_param(cmd, "DSCPPolicy_PolicyID");
14854 if (val) {
14855 unsigned int i;
14856 int policy_id = atoi(val);
14857
14858 val = get_param(cmd, "DSCPPolicy_RequestType");
14859
14860 if (!policy_id || !val)
14861 return INVALID_SEND_STATUS;
14862
14863 if (dut->num_dscp_status >= ARRAY_SIZE(dut->dscp_status)) {
14864 send_resp(dut, conn, SIGMA_ERROR,
14865 "errorCode,DSCP status list full");
14866 return STATUS_SENT_ERROR;
14867 }
14868
14869 for (i = 0; i < dut->num_dscp_status; i++)
14870 if (dut->dscp_status[i].id == policy_id)
14871 break;
14872
14873 /* New policy configured */
14874 if (i == dut->num_dscp_status) {
14875 dut->dscp_status[i].id = policy_id;
14876 dut->num_dscp_status++;
14877 }
14878
14879 dut->dscp_status[i].status = strcasecmp(val, "Remove") ?
14880 DSCP_POLICY_SUCCESS : DSCP_POLICY_REJECT;
14881
14882 return SUCCESS_SEND_STATUS;
14883 }
14884
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053014885 send_resp(dut, conn, SIGMA_ERROR,
14886 "errorCode,Unsupported QM rfeature");
14887 return STATUS_SENT_ERROR;
14888}
14889
14890
Jouni Malinenf7222712019-06-13 01:50:21 +030014891static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
14892 struct sigma_conn *conn,
14893 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014894{
14895 const char *intf = get_param(cmd, "Interface");
14896 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053014897 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014898
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053014899 if (!prog)
14900 prog = get_param(cmd, "Program");
14901
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014902 if (intf == NULL || prog == NULL)
14903 return -1;
14904
Ashwini Patil5acd7382017-04-13 15:55:04 +053014905 /* BSS Transition candidate list for BTM query */
14906 val = get_param(cmd, "Nebor_BSSID");
14907 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
14908 return 0;
14909
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014910 if (strcasecmp(prog, "TDLS") == 0)
14911 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
14912
14913 if (strcasecmp(prog, "VHT") == 0)
14914 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
14915
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014916 if (strcasecmp(prog, "HE") == 0)
14917 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
14918
Ashwini Patil68d02cd2017-01-10 15:39:16 +053014919 if (strcasecmp(prog, "MBO") == 0) {
14920 val = get_param(cmd, "Cellular_Data_Cap");
14921 if (val &&
14922 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
14923 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053014924
14925 val = get_param(cmd, "Ch_Pref");
14926 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
14927 return 0;
14928
Ashwini Patil68d02cd2017-01-10 15:39:16 +053014929 return 1;
14930 }
14931
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014932 if (strcasecmp(prog, "60GHz") == 0)
14933 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
14934
Jouni Malinen6250cb02020-04-15 13:54:45 +030014935 if (strcasecmp(prog, "WPA3") == 0)
14936 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053014937 if (strcasecmp(prog, "QM") == 0)
14938 return cmd_sta_set_rfeature_qm(intf, dut, conn, cmd);
Jouni Malinen6250cb02020-04-15 13:54:45 +030014939
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014940 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
14941 return 0;
14942}
14943
14944
Jouni Malinenf7222712019-06-13 01:50:21 +030014945static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
14946 struct sigma_conn *conn,
14947 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014948{
14949 const char *intf = get_param(cmd, "Interface");
14950 const char *mode = get_param(cmd, "Mode");
14951 int res;
14952
14953 if (intf == NULL || mode == NULL)
14954 return -1;
14955
14956 if (strcasecmp(mode, "On") == 0)
14957 res = wpa_command(intf, "SET radio_disabled 0");
14958 else if (strcasecmp(mode, "Off") == 0)
14959 res = wpa_command(intf, "SET radio_disabled 1");
14960 else
14961 return -1;
14962
14963 if (res) {
14964 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
14965 "radio mode");
14966 return 0;
14967 }
14968
14969 return 1;
14970}
14971
14972
Jouni Malinenf7222712019-06-13 01:50:21 +030014973static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
14974 struct sigma_conn *conn,
14975 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014976{
14977 const char *intf = get_param(cmd, "Interface");
14978 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014979 const char *prog = get_param(cmd, "program");
14980 const char *powersave = get_param(cmd, "powersave");
14981 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014982
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014983 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014984 return -1;
14985
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014986 if (prog && strcasecmp(prog, "60GHz") == 0) {
14987 /*
14988 * The CAPI mode parameter does not exist in 60G
14989 * unscheduled PS.
14990 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080014991 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014992 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014993 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020014994 strcasecmp(prog, "HE") == 0) {
14995 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014996 } else {
14997 if (mode == NULL)
14998 return -1;
14999
15000 if (strcasecmp(mode, "On") == 0)
15001 res = set_ps(intf, dut, 1);
15002 else if (strcasecmp(mode, "Off") == 0)
15003 res = set_ps(intf, dut, 0);
15004 else
15005 return -1;
15006 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015007
15008 if (res) {
15009 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
15010 "power save mode");
15011 return 0;
15012 }
15013
15014 return 1;
15015}
15016
15017
Jouni Malinenf7222712019-06-13 01:50:21 +030015018static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
15019 struct sigma_conn *conn,
15020 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015021{
15022 const char *intf = get_param(cmd, "Interface");
15023 const char *val, *bssid;
15024 int res;
15025 char *buf;
15026 size_t buf_len;
15027
15028 val = get_param(cmd, "BSSID_FILTER");
15029 if (val == NULL)
15030 return -1;
15031
15032 bssid = get_param(cmd, "BSSID_List");
15033 if (atoi(val) == 0 || bssid == NULL) {
15034 /* Disable BSSID filter */
15035 if (wpa_command(intf, "SET bssid_filter ")) {
15036 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
15037 "to disable BSSID filter");
15038 return 0;
15039 }
15040
15041 return 1;
15042 }
15043
15044 buf_len = 100 + strlen(bssid);
15045 buf = malloc(buf_len);
15046 if (buf == NULL)
15047 return -1;
15048
15049 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
15050 res = wpa_command(intf, buf);
15051 free(buf);
15052 if (res) {
15053 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
15054 "BSSID filter");
15055 return 0;
15056 }
15057
15058 return 1;
15059}
15060
15061
Jouni Malinenf7222712019-06-13 01:50:21 +030015062static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
15063 struct sigma_conn *conn,
15064 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015065{
15066 const char *intf = get_param(cmd, "Interface");
15067 const char *val;
15068
15069 /* TODO: ARP */
15070
15071 val = get_param(cmd, "HS2_CACHE_PROFILE");
15072 if (val && strcasecmp(val, "All") == 0)
15073 hs2_clear_credentials(intf);
15074
15075 return 1;
15076}
15077
15078
Jouni Malinenf7222712019-06-13 01:50:21 +030015079static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
15080 struct sigma_conn *conn,
15081 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015082{
15083 const char *intf = get_param(cmd, "Interface");
15084 const char *key_type = get_param(cmd, "KeyType");
15085 char buf[100], resp[200];
15086
15087 if (key_type == NULL)
15088 return -1;
15089
15090 if (strcasecmp(key_type, "GTK") == 0) {
15091 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
15092 strncmp(buf, "FAIL", 4) == 0) {
15093 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15094 "not fetch current GTK");
15095 return 0;
15096 }
15097 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
15098 send_resp(dut, conn, SIGMA_COMPLETE, resp);
15099 return 0;
15100 } else {
15101 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
15102 "KeyType");
15103 return 0;
15104 }
15105
15106 return 1;
15107}
15108
15109
15110static int hs2_set_policy(struct sigma_dut *dut)
15111{
15112#ifdef ANDROID
15113 system("ip rule del prio 23000");
15114 if (system("ip rule add from all lookup main prio 23000") != 0) {
15115 sigma_dut_print(dut, DUT_MSG_ERROR,
15116 "Failed to run:ip rule add from all lookup main prio");
15117 return -1;
15118 }
15119 if (system("ip route flush cache") != 0) {
15120 sigma_dut_print(dut, DUT_MSG_ERROR,
15121 "Failed to run ip route flush cache");
15122 return -1;
15123 }
15124 return 1;
15125#else /* ANDROID */
15126 return 0;
15127#endif /* ANDROID */
15128}
15129
15130
Jouni Malinenf7222712019-06-13 01:50:21 +030015131static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
15132 struct sigma_conn *conn,
15133 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015134{
15135 const char *intf = get_param(cmd, "Interface");
15136 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030015137 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015138 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030015139 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015140 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
15141 int tries = 0;
15142 int ignore_blacklist = 0;
15143 const char *events[] = {
15144 "CTRL-EVENT-CONNECTED",
15145 "INTERWORKING-BLACKLISTED",
15146 "INTERWORKING-NO-MATCH",
15147 NULL
15148 };
15149
15150 start_sta_mode(dut);
15151
Jouni Malinen439352d2018-09-13 03:42:23 +030015152 if (band) {
15153 if (strcmp(band, "2.4") == 0) {
15154 wpa_command(intf, "SET setband 2G");
15155 } else if (strcmp(band, "5") == 0) {
15156 wpa_command(intf, "SET setband 5G");
15157 } else {
15158 send_resp(dut, conn, SIGMA_ERROR,
15159 "errorCode,Unsupported band");
15160 return 0;
15161 }
15162 }
15163
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015164 blacklisted[0] = '\0';
15165 if (val && atoi(val))
15166 ignore_blacklist = 1;
15167
15168try_again:
15169 ctrl = open_wpa_mon(intf);
15170 if (ctrl == NULL) {
15171 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
15172 "wpa_supplicant monitor connection");
15173 return -2;
15174 }
15175
15176 tries++;
15177 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
15178 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
15179 "Interworking connection");
15180 wpa_ctrl_detach(ctrl);
15181 wpa_ctrl_close(ctrl);
15182 return 0;
15183 }
15184
15185 buf[0] = '\0';
15186 while (1) {
15187 char *pos;
15188 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
15189 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
15190 if (!pos)
15191 break;
15192 pos += 25;
15193 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
15194 pos);
15195 if (!blacklisted[0])
15196 memcpy(blacklisted, pos, strlen(pos) + 1);
15197 }
15198
15199 if (ignore_blacklist && blacklisted[0]) {
15200 char *end;
15201 end = strchr(blacklisted, ' ');
15202 if (end)
15203 *end = '\0';
15204 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
15205 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030015206 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
15207 blacklisted);
15208 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015209 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
15210 wpa_ctrl_detach(ctrl);
15211 wpa_ctrl_close(ctrl);
15212 return 0;
15213 }
15214 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
15215 buf, sizeof(buf));
15216 }
15217
15218 wpa_ctrl_detach(ctrl);
15219 wpa_ctrl_close(ctrl);
15220
15221 if (res < 0) {
15222 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
15223 "connect");
15224 return 0;
15225 }
15226
15227 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
15228 strstr(buf, "INTERWORKING-BLACKLISTED")) {
15229 if (tries < 2) {
15230 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
15231 goto try_again;
15232 }
15233 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
15234 "matching credentials found");
15235 return 0;
15236 }
15237
15238 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
15239 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
15240 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
15241 "get current BSSID/SSID");
15242 return 0;
15243 }
15244
15245 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
15246 send_resp(dut, conn, SIGMA_COMPLETE, resp);
15247 hs2_set_policy(dut);
15248 return 0;
15249}
15250
15251
Jouni Malinenf7222712019-06-13 01:50:21 +030015252static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
15253 struct sigma_conn *conn,
15254 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030015255{
15256 const char *intf = get_param(cmd, "Interface");
15257 const char *display = get_param(cmd, "Display");
15258 struct wpa_ctrl *ctrl;
15259 char buf[300], params[400], *pos;
15260 char bssid[20];
15261 int info_avail = 0;
15262 unsigned int old_timeout;
15263 int res;
15264
15265 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
15266 send_resp(dut, conn, SIGMA_ERROR,
15267 "ErrorCode,Could not get current BSSID");
15268 return 0;
15269 }
15270 ctrl = open_wpa_mon(intf);
15271 if (!ctrl) {
15272 sigma_dut_print(dut, DUT_MSG_ERROR,
15273 "Failed to open wpa_supplicant monitor connection");
15274 return -2;
15275 }
15276
15277 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
15278 wpa_command(intf, buf);
15279
15280 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
15281 if (res < 0) {
15282 send_resp(dut, conn, SIGMA_ERROR,
15283 "ErrorCode,Could not complete GAS query");
15284 goto fail;
15285 }
15286
15287 old_timeout = dut->default_timeout;
15288 dut->default_timeout = 2;
15289 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
15290 dut->default_timeout = old_timeout;
15291 if (res < 0)
15292 goto done;
15293 pos = strchr(buf, ' ');
15294 if (!pos)
15295 goto done;
15296 pos++;
15297 pos = strchr(pos, ' ');
15298 if (!pos)
15299 goto done;
15300 pos++;
15301 info_avail = 1;
15302 snprintf(params, sizeof(params), "browser %s", pos);
15303
15304 if (display && strcasecmp(display, "Yes") == 0) {
15305 pid_t pid;
15306
15307 pid = fork();
15308 if (pid < 0) {
15309 perror("fork");
15310 return -1;
15311 }
15312
15313 if (pid == 0) {
15314 run_hs20_osu(dut, params);
15315 exit(0);
15316 }
15317 }
15318
15319done:
15320 snprintf(buf, sizeof(buf), "Info_available,%s",
15321 info_avail ? "Yes" : "No");
15322 send_resp(dut, conn, SIGMA_COMPLETE, buf);
15323fail:
15324 wpa_ctrl_detach(ctrl);
15325 wpa_ctrl_close(ctrl);
15326 return 0;
15327}
15328
15329
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015330static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
15331 struct sigma_conn *conn,
15332 const char *ifname,
15333 struct sigma_cmd *cmd)
15334{
15335 const char *val;
15336 int id;
15337
15338 id = add_cred(ifname);
15339 if (id < 0)
15340 return -2;
15341 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
15342
15343 val = get_param(cmd, "prefer");
15344 if (val && atoi(val) > 0)
15345 set_cred(ifname, id, "priority", "1");
15346
15347 val = get_param(cmd, "REALM");
15348 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
15349 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15350 "realm");
15351 return 0;
15352 }
15353
15354 val = get_param(cmd, "HOME_FQDN");
15355 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
15356 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15357 "home_fqdn");
15358 return 0;
15359 }
15360
15361 val = get_param(cmd, "Username");
15362 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
15363 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15364 "username");
15365 return 0;
15366 }
15367
15368 val = get_param(cmd, "Password");
15369 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
15370 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15371 "password");
15372 return 0;
15373 }
15374
15375 val = get_param(cmd, "ROOT_CA");
15376 if (val) {
15377 char fname[200];
15378 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
15379#ifdef __linux__
15380 if (!file_exists(fname)) {
15381 char msg[300];
15382 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
15383 "file (%s) not found", fname);
15384 send_resp(dut, conn, SIGMA_ERROR, msg);
15385 return 0;
15386 }
15387#endif /* __linux__ */
15388 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
15389 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15390 "not set root CA");
15391 return 0;
15392 }
15393 }
15394
15395 return 1;
15396}
15397
15398
15399static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
15400{
15401 FILE *in, *out;
15402 char buf[500];
15403 int found = 0;
15404
15405 in = fopen("devdetail.xml", "r");
15406 if (in == NULL)
15407 return -1;
15408 out = fopen("devdetail.xml.tmp", "w");
15409 if (out == NULL) {
15410 fclose(in);
15411 return -1;
15412 }
15413
15414 while (fgets(buf, sizeof(buf), in)) {
15415 char *pos = strstr(buf, "<IMSI>");
15416 if (pos) {
15417 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
15418 imsi);
15419 pos += 6;
15420 *pos = '\0';
15421 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
15422 found++;
15423 } else {
15424 fprintf(out, "%s", buf);
15425 }
15426 }
15427
15428 fclose(out);
15429 fclose(in);
15430 if (found)
15431 rename("devdetail.xml.tmp", "devdetail.xml");
15432 else
15433 unlink("devdetail.xml.tmp");
15434
15435 return 0;
15436}
15437
15438
15439static int sta_add_credential_sim(struct sigma_dut *dut,
15440 struct sigma_conn *conn,
15441 const char *ifname, struct sigma_cmd *cmd)
15442{
15443 const char *val, *imsi = NULL;
15444 int id;
15445 char buf[200];
15446 int res;
15447 const char *pos;
15448 size_t mnc_len;
15449 char plmn_mcc[4];
15450 char plmn_mnc[4];
15451
15452 id = add_cred(ifname);
15453 if (id < 0)
15454 return -2;
15455 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
15456
15457 val = get_param(cmd, "prefer");
15458 if (val && atoi(val) > 0)
15459 set_cred(ifname, id, "priority", "1");
15460
15461 val = get_param(cmd, "PLMN_MCC");
15462 if (val == NULL) {
15463 send_resp(dut, conn, SIGMA_ERROR,
15464 "errorCode,Missing PLMN_MCC");
15465 return 0;
15466 }
15467 if (strlen(val) != 3) {
15468 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
15469 return 0;
15470 }
15471 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
15472
15473 val = get_param(cmd, "PLMN_MNC");
15474 if (val == NULL) {
15475 send_resp(dut, conn, SIGMA_ERROR,
15476 "errorCode,Missing PLMN_MNC");
15477 return 0;
15478 }
15479 if (strlen(val) != 2 && strlen(val) != 3) {
15480 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
15481 return 0;
15482 }
15483 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
15484
15485 val = get_param(cmd, "IMSI");
15486 if (val == NULL) {
15487 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
15488 "IMSI");
15489 return 0;
15490 }
15491
15492 imsi = pos = val;
15493
15494 if (strncmp(plmn_mcc, pos, 3) != 0) {
15495 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
15496 return 0;
15497 }
15498 pos += 3;
15499
15500 mnc_len = strlen(plmn_mnc);
15501 if (mnc_len < 2) {
15502 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
15503 return 0;
15504 }
15505
15506 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
15507 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
15508 return 0;
15509 }
15510 pos += mnc_len;
15511
15512 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
15513 if (res < 0 || res >= (int) sizeof(buf))
15514 return -1;
15515 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
15516 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15517 "not set IMSI");
15518 return 0;
15519 }
15520
15521 val = get_param(cmd, "Password");
15522 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
15523 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15524 "not set password");
15525 return 0;
15526 }
15527
Jouni Malinenba630452018-06-22 11:49:59 +030015528 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015529 /*
15530 * Set provisioning_sp for the test cases where SIM/USIM
15531 * provisioning is used.
15532 */
15533 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
15534 "wi-fi.org") < 0) {
15535 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15536 "not set provisioning_sp");
15537 return 0;
15538 }
15539
15540 update_devdetail_imsi(dut, imsi);
15541 }
15542
15543 return 1;
15544}
15545
15546
15547static int sta_add_credential_cert(struct sigma_dut *dut,
15548 struct sigma_conn *conn,
15549 const char *ifname,
15550 struct sigma_cmd *cmd)
15551{
15552 const char *val;
15553 int id;
15554
15555 id = add_cred(ifname);
15556 if (id < 0)
15557 return -2;
15558 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
15559
15560 val = get_param(cmd, "prefer");
15561 if (val && atoi(val) > 0)
15562 set_cred(ifname, id, "priority", "1");
15563
15564 val = get_param(cmd, "REALM");
15565 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
15566 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15567 "realm");
15568 return 0;
15569 }
15570
15571 val = get_param(cmd, "HOME_FQDN");
15572 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
15573 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15574 "home_fqdn");
15575 return 0;
15576 }
15577
15578 val = get_param(cmd, "Username");
15579 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
15580 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15581 "username");
15582 return 0;
15583 }
15584
15585 val = get_param(cmd, "clientCertificate");
15586 if (val) {
15587 char fname[200];
15588 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
15589#ifdef __linux__
15590 if (!file_exists(fname)) {
15591 char msg[300];
15592 snprintf(msg, sizeof(msg),
15593 "ErrorCode,clientCertificate "
15594 "file (%s) not found", fname);
15595 send_resp(dut, conn, SIGMA_ERROR, msg);
15596 return 0;
15597 }
15598#endif /* __linux__ */
15599 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
15600 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15601 "not set client_cert");
15602 return 0;
15603 }
15604 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
15605 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15606 "not set private_key");
15607 return 0;
15608 }
15609 }
15610
15611 val = get_param(cmd, "ROOT_CA");
15612 if (val) {
15613 char fname[200];
15614 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
15615#ifdef __linux__
15616 if (!file_exists(fname)) {
15617 char msg[300];
15618 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
15619 "file (%s) not found", fname);
15620 send_resp(dut, conn, SIGMA_ERROR, msg);
15621 return 0;
15622 }
15623#endif /* __linux__ */
15624 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
15625 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15626 "not set root CA");
15627 return 0;
15628 }
15629 }
15630
15631 return 1;
15632}
15633
15634
Jouni Malinenf7222712019-06-13 01:50:21 +030015635static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
15636 struct sigma_conn *conn,
15637 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015638{
15639 const char *intf = get_param(cmd, "Interface");
15640 const char *type;
15641
15642 start_sta_mode(dut);
15643
15644 type = get_param(cmd, "Type");
15645 if (!type)
15646 return -1;
15647
15648 if (strcasecmp(type, "uname_pwd") == 0)
15649 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
15650
15651 if (strcasecmp(type, "sim") == 0)
15652 return sta_add_credential_sim(dut, conn, intf, cmd);
15653
15654 if (strcasecmp(type, "cert") == 0)
15655 return sta_add_credential_cert(dut, conn, intf, cmd);
15656
15657 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
15658 "type");
15659 return 0;
15660}
15661
15662
Jouni Malinenf7222712019-06-13 01:50:21 +030015663static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
15664 struct sigma_conn *conn,
15665 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015666{
15667 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015668 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Veerendranathdc581b52020-08-10 03:29:08 -070015669 char buf[4096], scan_res[20];
vamsi krishna89ad8c62017-09-19 12:51:18 +053015670 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080015671 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015672 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015673 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030015674 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015675
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020015676 start_sta_mode(dut);
15677
Arif Hussain66a4af02019-02-07 15:04:51 -080015678 val = get_param(cmd, "GetParameter");
15679 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015680 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080015681 buf, sizeof(buf)) < 0) {
15682 sigma_dut_print(dut, DUT_MSG_ERROR,
15683 "Could not get ssid bssid");
15684 return ERROR_SEND_STATUS;
15685 }
15686
15687 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
15688 send_resp(dut, conn, SIGMA_COMPLETE, buf);
15689 return STATUS_SENT;
15690 }
15691
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015692 val = get_param(cmd, "HESSID");
15693 if (val) {
15694 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
15695 if (res < 0 || res >= (int) sizeof(buf))
15696 return -1;
15697 wpa_command(intf, buf);
15698 }
15699
15700 val = get_param(cmd, "ACCS_NET_TYPE");
15701 if (val) {
15702 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
15703 val);
15704 if (res < 0 || res >= (int) sizeof(buf))
15705 return -1;
15706 wpa_command(intf, buf);
15707 }
15708
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -070015709 if (get_param(cmd, "RxMac"))
15710 sta_set_scan_unicast_probe(dut, intf, 1);
15711
vamsi krishna89ad8c62017-09-19 12:51:18 +053015712 bssid = get_param(cmd, "Bssid");
15713 ssid = get_param(cmd, "Ssid");
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -070015714 if (!bssid)
15715 bssid = get_param(cmd, "RxMac");
vamsi krishna89ad8c62017-09-19 12:51:18 +053015716
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080015717 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
15718 dut->device_type == STA_testbed) {
15719 ssid = NULL;
15720 wildcard_ssid = 1;
15721 }
15722
vamsi krishna89ad8c62017-09-19 12:51:18 +053015723 if (ssid) {
15724 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
15725 send_resp(dut, conn, SIGMA_ERROR,
15726 "ErrorCode,Too long SSID");
15727 return 0;
15728 }
15729 ascii2hexstr(ssid, ssid_hex);
15730 }
15731
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015732 short_ssid = get_param(cmd, "ShortSSID");
15733 if (short_ssid) {
15734 uint32_t short_ssid_hex;
15735
15736 short_ssid_hex = strtoul(short_ssid, NULL, 16);
15737 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
15738 (((short_ssid_hex >> 8) & 0xFF) << 16) |
15739 (((short_ssid_hex >> 16) & 0xFF) << 8) |
15740 ((short_ssid_hex >> 24) & 0xFF);
15741
15742 res = snprintf(buf, sizeof(buf),
15743 "VENDOR_ELEM_ADD 14 ff053a%08x",
15744 short_ssid_hex);
15745 if (res < 0 || res >= (int) sizeof(buf) ||
15746 wpa_command(intf, buf)) {
15747 send_resp(dut, conn, SIGMA_ERROR,
15748 "errorCode,Failed to add short SSID");
15749 return STATUS_SENT_ERROR;
15750 }
15751 }
15752
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015753 scan_freq = get_param(cmd, "ChnlFreq");
Veerendranath Jakkam132c4b42020-08-10 00:29:03 +053015754 if (scan_freq) {
15755 if (strcasecmp(scan_freq, "2G") == 0)
15756 scan_freq = "2412-2462";
15757 else if (strcasecmp(scan_freq, "5G") == 0)
15758 scan_freq = "5180-5925";
15759 }
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015760
Jouni Malinen228a2fc2020-06-22 23:37:45 +030015761 val = get_param(cmd, "WaitCompletion");
15762 if (val && atoi(val) == 1) {
15763 ctrl = open_wpa_mon(intf);
15764 if (!ctrl) {
15765 send_resp(dut, conn, SIGMA_ERROR,
15766 "errorCode,Failed to open monitor socket");
15767 return STATUS_SENT_ERROR;
15768 }
15769 }
15770
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015771 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053015772 bssid ? " bssid=": "",
15773 bssid ? bssid : "",
15774 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080015775 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015776 wildcard_ssid ? " wildcard_ssid=1" : "",
15777 scan_freq ? " freq=" : "",
15778 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015779 if (res < 0 || res >= (int) sizeof(buf)) {
15780 send_resp(dut, conn, SIGMA_ERROR,
15781 "errorCode,Could not build scan command");
15782 status = STATUS_SENT_ERROR;
15783 goto remove_s_ssid;
15784 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053015785
Veerendranathdc581b52020-08-10 03:29:08 -070015786 res = wpa_command_resp(intf, buf, scan_res, sizeof(scan_res));
15787 if (strncmp(scan_res, "FAIL-BUSY", 9) == 0) {
15788 sigma_dut_print(dut, DUT_MSG_DEBUG,
15789 "Scan request rejected with busy status, abort ongoing scan and try again");
15790 wpa_command(intf, "ABORT_SCAN");
15791 res = wpa_command(intf, buf);
15792 }
15793
15794 if (res < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015795 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
15796 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015797 status = STATUS_SENT_ERROR;
15798 } else {
15799 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015800 }
15801
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015802remove_s_ssid:
15803 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
15804 sigma_dut_print(dut, DUT_MSG_ERROR,
15805 "Failed to delete vendor element");
15806
Jouni Malinen228a2fc2020-06-22 23:37:45 +030015807 if (ctrl) {
15808 if (status == SUCCESS_SEND_STATUS) {
15809 res = get_wpa_cli_event(dut, ctrl,
15810 "CTRL-EVENT-SCAN-RESULTS",
15811 buf, sizeof(buf));
15812 if (res < 0) {
15813 send_resp(dut, conn, SIGMA_ERROR,
15814 "ErrorCode,scan did not complete");
15815 status = STATUS_SENT_ERROR;
15816 }
15817 }
15818
15819 wpa_ctrl_detach(ctrl);
15820 wpa_ctrl_close(ctrl);
15821 }
15822
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015823 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015824}
15825
15826
Jouni Malinenf7222712019-06-13 01:50:21 +030015827static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
15828 struct sigma_conn *conn,
15829 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020015830{
15831 const char *intf = get_param(cmd, "Interface");
15832 const char *bssid;
15833 char buf[4096], *pos;
15834 int freq, chan;
15835 char *ssid;
15836 char resp[100];
15837 int res;
15838 struct wpa_ctrl *ctrl;
15839
15840 bssid = get_param(cmd, "BSSID");
15841 if (!bssid) {
15842 send_resp(dut, conn, SIGMA_INVALID,
15843 "errorCode,BSSID argument is missing");
15844 return 0;
15845 }
15846
15847 ctrl = open_wpa_mon(intf);
15848 if (!ctrl) {
15849 sigma_dut_print(dut, DUT_MSG_ERROR,
15850 "Failed to open wpa_supplicant monitor connection");
15851 return -1;
15852 }
15853
15854 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
15855 send_resp(dut, conn, SIGMA_ERROR,
15856 "errorCode,Could not start scan");
15857 wpa_ctrl_detach(ctrl);
15858 wpa_ctrl_close(ctrl);
15859 return 0;
15860 }
15861
15862 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
15863 buf, sizeof(buf));
15864
15865 wpa_ctrl_detach(ctrl);
15866 wpa_ctrl_close(ctrl);
15867
15868 if (res < 0) {
15869 send_resp(dut, conn, SIGMA_ERROR,
15870 "errorCode,Scan did not complete");
15871 return 0;
15872 }
15873
15874 snprintf(buf, sizeof(buf), "BSS %s", bssid);
15875 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
15876 strncmp(buf, "id=", 3) != 0) {
15877 send_resp(dut, conn, SIGMA_ERROR,
15878 "errorCode,Specified BSSID not found");
15879 return 0;
15880 }
15881
15882 pos = strstr(buf, "\nfreq=");
15883 if (!pos) {
15884 send_resp(dut, conn, SIGMA_ERROR,
15885 "errorCode,Channel not found");
15886 return 0;
15887 }
15888 freq = atoi(pos + 6);
15889 chan = freq_to_channel(freq);
15890
15891 pos = strstr(buf, "\nssid=");
15892 if (!pos) {
15893 send_resp(dut, conn, SIGMA_ERROR,
15894 "errorCode,SSID not found");
15895 return 0;
15896 }
15897 ssid = pos + 6;
15898 pos = strchr(ssid, '\n');
15899 if (pos)
15900 *pos = '\0';
15901 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
15902 send_resp(dut, conn, SIGMA_COMPLETE, resp);
15903 return 0;
15904}
15905
15906
Jouni Malinenf7222712019-06-13 01:50:21 +030015907static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
15908 struct sigma_conn *conn,
15909 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015910{
15911#ifdef __linux__
15912 struct timeval tv;
15913 struct tm tm;
15914 time_t t;
15915 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053015916 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015917
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015918 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015919
15920 memset(&tm, 0, sizeof(tm));
15921 val = get_param(cmd, "seconds");
15922 if (val)
15923 tm.tm_sec = atoi(val);
15924 val = get_param(cmd, "minutes");
15925 if (val)
15926 tm.tm_min = atoi(val);
15927 val = get_param(cmd, "hours");
15928 if (val)
15929 tm.tm_hour = atoi(val);
15930 val = get_param(cmd, "date");
15931 if (val)
15932 tm.tm_mday = atoi(val);
15933 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053015934 if (val) {
15935 v = atoi(val);
15936 if (v < 1 || v > 12) {
15937 send_resp(dut, conn, SIGMA_INVALID,
15938 "errorCode,Invalid month");
15939 return 0;
15940 }
15941 tm.tm_mon = v - 1;
15942 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015943 val = get_param(cmd, "year");
15944 if (val) {
15945 int year = atoi(val);
15946#ifdef ANDROID
15947 if (year > 2035)
15948 year = 2035; /* years beyond 2035 not supported */
15949#endif /* ANDROID */
15950 tm.tm_year = year - 1900;
15951 }
15952 t = mktime(&tm);
15953 if (t == (time_t) -1) {
15954 send_resp(dut, conn, SIGMA_ERROR,
15955 "errorCode,Invalid date or time");
15956 return 0;
15957 }
15958
15959 memset(&tv, 0, sizeof(tv));
15960 tv.tv_sec = t;
15961
15962 if (settimeofday(&tv, NULL) < 0) {
15963 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
15964 strerror(errno));
15965 send_resp(dut, conn, SIGMA_ERROR,
15966 "errorCode,Failed to set time");
15967 return 0;
15968 }
15969
15970 return 1;
15971#endif /* __linux__ */
15972
15973 return -1;
15974}
15975
15976
Jouni Malinenf7222712019-06-13 01:50:21 +030015977static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
15978 struct sigma_conn *conn,
15979 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015980{
15981 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015982 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015983 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015984 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015985 int res;
15986 struct wpa_ctrl *ctrl;
15987
15988 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015989 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015990
15991 val = get_param(cmd, "ProdESSAssoc");
15992 if (val)
15993 prod_ess_assoc = atoi(val);
15994
15995 kill_dhcp_client(dut, intf);
15996 if (start_dhcp_client(dut, intf) < 0)
15997 return -2;
15998
15999 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
16000 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
16001 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030016002 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016003 prod_ess_assoc ? "" : "-N",
16004 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030016005 name ? "'" : "",
16006 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
16007 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016008
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053016009 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016010 if (run_hs20_osu(dut, buf) < 0) {
16011 FILE *f;
16012
16013 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
16014
16015 f = fopen("hs20-osu-client.res", "r");
16016 if (f) {
16017 char resp[400], res[300], *pos;
16018 if (!fgets(res, sizeof(res), f))
16019 res[0] = '\0';
16020 pos = strchr(res, '\n');
16021 if (pos)
16022 *pos = '\0';
16023 fclose(f);
16024 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
16025 res);
16026 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
16027 if (system(resp) != 0) {
16028 }
16029 snprintf(resp, sizeof(resp),
16030 "SSID,,BSSID,,failureReason,%s", res);
16031 send_resp(dut, conn, SIGMA_COMPLETE, resp);
16032 return 0;
16033 }
16034
16035 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
16036 return 0;
16037 }
16038
16039 if (!prod_ess_assoc)
16040 goto report;
16041
16042 ctrl = open_wpa_mon(intf);
16043 if (ctrl == NULL) {
16044 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
16045 "wpa_supplicant monitor connection");
16046 return -1;
16047 }
16048
16049 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
16050 buf, sizeof(buf));
16051
16052 wpa_ctrl_detach(ctrl);
16053 wpa_ctrl_close(ctrl);
16054
16055 if (res < 0) {
16056 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
16057 "network after OSU");
16058 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
16059 return 0;
16060 }
16061
16062report:
16063 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
16064 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
16065 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
16066 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
16067 return 0;
16068 }
16069
16070 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
16071 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016072 return 0;
16073}
16074
16075
Jouni Malinenf7222712019-06-13 01:50:21 +030016076static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
16077 struct sigma_conn *conn,
16078 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016079{
16080 const char *val;
16081 int timeout = 120;
16082
16083 val = get_param(cmd, "PolicyUpdate");
16084 if (val == NULL || atoi(val) == 0)
16085 return 1; /* No operation requested */
16086
16087 val = get_param(cmd, "Timeout");
16088 if (val)
16089 timeout = atoi(val);
16090
16091 if (timeout) {
16092 /* TODO: time out the command and return
16093 * PolicyUpdateStatus,TIMEOUT if needed. */
16094 }
16095
16096 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
16097 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
16098 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
16099 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
16100 return 0;
16101 }
16102
16103 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
16104 return 0;
16105}
16106
16107
Jouni Malinenf7222712019-06-13 01:50:21 +030016108static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
16109 struct sigma_conn *conn,
16110 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016111{
16112 struct wpa_ctrl *ctrl;
16113 const char *intf = get_param(cmd, "Interface");
16114 const char *bssid = get_param(cmd, "Bssid");
16115 const char *ssid = get_param(cmd, "SSID");
16116 const char *security = get_param(cmd, "Security");
16117 const char *passphrase = get_param(cmd, "Passphrase");
16118 const char *pin = get_param(cmd, "PIN");
16119 char buf[1000];
16120 char ssid_hex[200], passphrase_hex[200];
16121 const char *keymgmt, *cipher;
16122
16123 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020016124 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016125
16126 if (!bssid) {
16127 send_resp(dut, conn, SIGMA_ERROR,
16128 "ErrorCode,Missing Bssid argument");
16129 return 0;
16130 }
16131
16132 if (!ssid) {
16133 send_resp(dut, conn, SIGMA_ERROR,
16134 "ErrorCode,Missing SSID argument");
16135 return 0;
16136 }
16137
16138 if (!security) {
16139 send_resp(dut, conn, SIGMA_ERROR,
16140 "ErrorCode,Missing Security argument");
16141 return 0;
16142 }
16143
16144 if (!passphrase) {
16145 send_resp(dut, conn, SIGMA_ERROR,
16146 "ErrorCode,Missing Passphrase argument");
16147 return 0;
16148 }
16149
16150 if (!pin) {
16151 send_resp(dut, conn, SIGMA_ERROR,
16152 "ErrorCode,Missing PIN argument");
16153 return 0;
16154 }
16155
vamsi krishna8c9c1562017-05-12 15:51:46 +053016156 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
16157 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016158 send_resp(dut, conn, SIGMA_ERROR,
16159 "ErrorCode,Too long SSID/passphrase");
16160 return 0;
16161 }
16162
16163 ctrl = open_wpa_mon(intf);
16164 if (ctrl == NULL) {
16165 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
16166 "wpa_supplicant monitor connection");
16167 return -2;
16168 }
16169
16170 if (strcasecmp(security, "wpa2-psk") == 0) {
16171 keymgmt = "WPA2PSK";
16172 cipher = "CCMP";
16173 } else {
16174 wpa_ctrl_detach(ctrl);
16175 wpa_ctrl_close(ctrl);
16176 send_resp(dut, conn, SIGMA_ERROR,
16177 "ErrorCode,Unsupported Security value");
16178 return 0;
16179 }
16180
16181 ascii2hexstr(ssid, ssid_hex);
16182 ascii2hexstr(passphrase, passphrase_hex);
16183 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
16184 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
16185
16186 if (wpa_command(intf, buf) < 0) {
16187 wpa_ctrl_detach(ctrl);
16188 wpa_ctrl_close(ctrl);
16189 send_resp(dut, conn, SIGMA_ERROR,
16190 "ErrorCode,Failed to start registrar");
16191 return 0;
16192 }
16193
16194 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
16195 dut->er_oper_performed = 1;
16196
16197 return wps_connection_event(dut, conn, ctrl, intf, 0);
16198}
16199
16200
Jouni Malinenf7222712019-06-13 01:50:21 +030016201static enum sigma_cmd_result
16202cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
16203 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016204{
16205 struct wpa_ctrl *ctrl;
16206 const char *intf = get_param(cmd, "Interface");
16207 const char *bssid = get_param(cmd, "Bssid");
16208 char buf[100];
16209
16210 if (!bssid) {
16211 send_resp(dut, conn, SIGMA_ERROR,
16212 "ErrorCode,Missing Bssid argument");
16213 return 0;
16214 }
16215
16216 ctrl = open_wpa_mon(intf);
16217 if (ctrl == NULL) {
16218 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
16219 "wpa_supplicant monitor connection");
16220 return -2;
16221 }
16222
16223 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
16224
16225 if (wpa_command(intf, buf) < 0) {
16226 wpa_ctrl_detach(ctrl);
16227 wpa_ctrl_close(ctrl);
16228 send_resp(dut, conn, SIGMA_ERROR,
16229 "ErrorCode,Failed to start registrar");
16230 return 0;
16231 }
16232
16233 return wps_connection_event(dut, conn, ctrl, intf, 0);
16234}
16235
16236
Jouni Malinenf7222712019-06-13 01:50:21 +030016237static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
16238 struct sigma_conn *conn,
16239 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053016240{
16241 struct wpa_ctrl *ctrl;
16242 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016243 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016244 const char *config_method = get_param(cmd, "WPSConfigMethod");
16245 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053016246 int res;
16247 char buf[256];
16248 const char *events[] = {
16249 "CTRL-EVENT-CONNECTED",
16250 "WPS-OVERLAP-DETECTED",
16251 "WPS-TIMEOUT",
16252 "WPS-FAIL",
16253 NULL
16254 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016255 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053016256
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020016257 /* 60G WPS tests do not pass Interface parameter */
16258 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020016259 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020016260
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016261 if (dut->mode == SIGMA_MODE_AP)
16262 return ap_wps_registration(dut, conn, cmd);
16263
16264 if (config_method) {
16265 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
16266 * sta_wps_enter_pin before calling start_wps_registration. */
16267 if (strcasecmp(config_method, "PBC") == 0)
16268 dut->wps_method = WFA_CS_WPS_PBC;
16269 }
16270 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
16271 send_resp(dut, conn, SIGMA_ERROR,
16272 "ErrorCode,WPS parameters not yet set");
16273 return STATUS_SENT;
16274 }
16275
16276 /* Make sure WPS is enabled (also for STA mode) */
16277 dut->wps_disable = 0;
16278
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016279 if (dut->band == WPS_BAND_60G && network_mode &&
16280 strcasecmp(network_mode, "PBSS") == 0) {
16281 sigma_dut_print(dut, DUT_MSG_DEBUG,
16282 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020016283 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016284 return -2;
16285 }
16286
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020016287 if (dut->force_rsn_ie) {
16288 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
16289 dut->force_rsn_ie);
16290 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
16291 sigma_dut_print(dut, DUT_MSG_INFO,
16292 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020016293 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020016294 }
16295 }
16296
vamsi krishna9b144002017-09-20 13:28:13 +053016297 ctrl = open_wpa_mon(intf);
16298 if (!ctrl) {
16299 sigma_dut_print(dut, DUT_MSG_ERROR,
16300 "Failed to open wpa_supplicant monitor connection");
16301 return -2;
16302 }
16303
16304 role = get_param(cmd, "WpsRole");
16305 if (!role) {
16306 send_resp(dut, conn, SIGMA_INVALID,
16307 "ErrorCode,WpsRole not provided");
16308 goto fail;
16309 }
16310
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016311 if (strcasecmp(role, "Enrollee") != 0) {
16312 /* Registrar role for STA not supported */
16313 send_resp(dut, conn, SIGMA_ERROR,
16314 "ErrorCode,Unsupported WpsRole value");
16315 goto fail;
16316 }
16317
16318 if (is_60g_sigma_dut(dut)) {
16319 if (dut->wps_method == WFA_CS_WPS_PBC)
16320 snprintf(buf, sizeof(buf), "WPS_PBC");
16321 else /* WFA_CS_WPS_PIN_KEYPAD */
16322 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
16323 dut->wps_pin);
16324 if (wpa_command(intf, buf) < 0) {
16325 send_resp(dut, conn, SIGMA_ERROR,
16326 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053016327 goto fail;
16328 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016329 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
16330 if (res < 0) {
16331 send_resp(dut, conn, SIGMA_ERROR,
16332 "ErrorCode,WPS connection did not complete");
16333 goto fail;
16334 }
16335 if (strstr(buf, "WPS-TIMEOUT")) {
16336 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
16337 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
16338 send_resp(dut, conn, SIGMA_COMPLETE,
16339 "WpsState,OverlapSession");
16340 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
16341 send_resp(dut, conn, SIGMA_COMPLETE,
16342 "WpsState,Successful");
16343 } else {
16344 send_resp(dut, conn, SIGMA_COMPLETE,
16345 "WpsState,Failure");
16346 }
16347 } else {
16348 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053016349 if (wpa_command(intf, "WPS_PBC") < 0) {
16350 send_resp(dut, conn, SIGMA_ERROR,
16351 "ErrorCode,Failed to enable PBC");
16352 goto fail;
16353 }
16354 } else {
16355 /* TODO: PIN method */
16356 send_resp(dut, conn, SIGMA_ERROR,
16357 "ErrorCode,Unsupported WpsConfigMethod value");
16358 goto fail;
16359 }
16360 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
16361 if (res < 0) {
16362 send_resp(dut, conn, SIGMA_ERROR,
16363 "ErrorCode,WPS connection did not complete");
16364 goto fail;
16365 }
16366 if (strstr(buf, "WPS-TIMEOUT")) {
16367 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
16368 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
16369 send_resp(dut, conn, SIGMA_ERROR,
16370 "ErrorCode,OverlapSession");
16371 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
16372 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
16373 } else {
16374 send_resp(dut, conn, SIGMA_ERROR,
16375 "ErrorCode,WPS operation failed");
16376 }
vamsi krishna9b144002017-09-20 13:28:13 +053016377 }
16378
16379fail:
16380 wpa_ctrl_detach(ctrl);
16381 wpa_ctrl_close(ctrl);
16382 return 0;
16383}
16384
16385
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016386static int req_intf(struct sigma_cmd *cmd)
16387{
16388 return get_param(cmd, "interface") == NULL ? -1 : 0;
16389}
16390
16391
16392void sta_register_cmds(void)
16393{
16394 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
16395 cmd_sta_get_ip_config);
16396 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
16397 cmd_sta_set_ip_config);
16398 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
16399 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
16400 cmd_sta_get_mac_address);
16401 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
16402 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
16403 cmd_sta_verify_ip_connection);
16404 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
16405 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
16406 cmd_sta_set_encryption);
16407 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
16408 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
16409 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
16410 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
16411 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
16412 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
16413 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
16414 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
16415 cmd_sta_set_eapakaprime);
16416 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
16417 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
16418 /* TODO: sta_set_ibss */
16419 /* TODO: sta_set_mode */
16420 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
16421 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
16422 /* TODO: sta_up_load */
16423 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
16424 cmd_sta_preset_testparameters);
16425 /* TODO: sta_set_system */
16426 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
16427 /* TODO: sta_set_rifs_test */
16428 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
16429 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
16430 /* TODO: sta_send_coexist_mgmt */
16431 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
16432 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
16433 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
16434 sigma_dut_reg_cmd("sta_reset_default", req_intf,
16435 cmd_sta_reset_default);
16436 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
16437 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
16438 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
16439 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
16440 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020016441 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016442 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
16443 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
16444 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
16445 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
16446 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030016447 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
16448 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016449 sigma_dut_reg_cmd("sta_add_credential", req_intf,
16450 cmd_sta_add_credential);
16451 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020016452 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016453 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
16454 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
16455 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
16456 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
16457 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
16458 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030016459 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016460 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
16461 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020016462 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053016463 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016464}