blob: 5ef105151fed57bbcfcb6511c9182d61ed4d12a3 [file] [log] [blame]
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001/*
2 * Sigma Control API DUT (station/AP)
3 * Copyright (c) 2010-2011, Atheros Communications, Inc.
Jouni Malinen9d7e31d2017-12-22 18:55:04 +02004 * Copyright (c) 2011-2017, Qualcomm Atheros, Inc.
Jouni Malinenc12ea4a2018-01-05 21:07:10 +02005 * Copyright (c) 2018, The Linux Foundation
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006 * All Rights Reserved.
7 * Licensed under the Clear BSD license. See README for more details.
8 */
9
10#include "sigma_dut.h"
11#include <sys/ioctl.h>
12#include <sys/stat.h>
Jouni Malinen82905202018-04-29 17:20:10 +030013#include <sys/wait.h>
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030014#include <ctype.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015#ifdef __linux__
Lior Davidcc88b562017-01-03 18:52:09 +020016#include <regex.h>
17#include <dirent.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020018#include <sys/time.h>
19#include <netpacket/packet.h>
20#include <linux/if_ether.h>
21#ifdef ANDROID
22#include <cutils/properties.h>
23#include <android/log.h>
24#include "keystore_get.h"
25#else /* ANDROID */
26#include <ifaddrs.h>
27#endif /* ANDROID */
28#include <netdb.h>
29#endif /* __linux__ */
30#ifdef __QNXNTO__
31#include <net/if_dl.h>
32#endif /* __QNXNTO__ */
33#include "wpa_ctrl.h"
34#include "wpa_helpers.h"
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070035#include "miracast.h"
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070036#include "qca-vendor_copy.h"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020037
38/* Temporary files for sta_send_addba */
39#define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp"
40#define VI_QOS_FILE "/tmp/vi-qos.txt"
41#define VI_QOS_REFFILE "/etc/vi-qos.txt"
42
43/*
44 * MTU for Ethernet need to take into account 8-byte SNAP header
45 * to be added when encapsulating Ethernet frame into 802.11
46 */
47#ifndef IEEE80211_MAX_DATA_LEN_DMG
48#define IEEE80211_MAX_DATA_LEN_DMG 7920
49#endif
50#ifndef IEEE80211_SNAP_LEN_DMG
51#define IEEE80211_SNAP_LEN_DMG 8
52#endif
53
Ashwini Patil00402582017-04-13 12:29:39 +053054#define NON_PREF_CH_LIST_SIZE 100
Ashwini Patil5acd7382017-04-13 15:55:04 +053055#define NEIGHBOR_REPORT_SIZE 1000
56#define DEFAULT_NEIGHBOR_BSSID_INFO "17"
57#define DEFAULT_NEIGHBOR_PHY_TYPE "1"
Ashwini Patil00402582017-04-13 12:29:39 +053058
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030059#define WIL_DEFAULT_BI 100
60
61/* default remain on channel time for transmitting frames (milliseconds) */
62#define WIL_TRANSMIT_FRAME_DEFAULT_ROC 500
63#define IEEE80211_P2P_ATTR_DEVICE_ID 3
64#define IEEE80211_P2P_ATTR_GROUP_ID 15
65
66/* describes tagged bytes in template frame file */
67struct template_frame_tag {
68 int num;
69 int offset;
70 size_t len;
71};
72
Jouni Malinencd4e3c32015-10-29 12:39:56 +020073extern char *sigma_wpas_ctrl;
74extern char *sigma_cert_path;
75extern enum driver_type wifi_chip_type;
76extern char *sigma_radio_ifname[];
77
Lior David0fe101e2017-03-09 16:09:50 +020078#ifdef __linux__
79#define WIL_WMI_MAX_PAYLOAD 248
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020080#define WIL_WMI_ESE_CFG_CMDID 0xa01
Lior David0fe101e2017-03-09 16:09:50 +020081#define WIL_WMI_BF_TRIG_CMDID 0x83a
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020082#define WIL_WMI_UNIT_TEST_CMDID 0x900
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030083#define WIL_WMI_P2P_CFG_CMDID 0x910
84#define WIL_WMI_START_LISTEN_CMDID 0x914
85#define WIL_WMI_DISCOVERY_STOP_CMDID 0x917
Lior David0fe101e2017-03-09 16:09:50 +020086
87struct wil_wmi_header {
88 uint8_t mid;
89 uint8_t reserved;
90 uint16_t cmd;
91 uint32_t ts;
92} __attribute__((packed));
93
94enum wil_wmi_bf_trig_type {
95 WIL_WMI_SLS,
96 WIL_WMI_BRP_RX,
97 WIL_WMI_BRP_TX,
98};
99
100struct wil_wmi_bf_trig_cmd {
101 /* enum wil_wmi_bf_trig_type */
102 uint32_t bf_type;
103 /* cid when type == WMI_BRP_RX */
104 uint32_t sta_id;
105 uint32_t reserved;
106 /* mac address when type = WIL_WMI_SLS */
107 uint8_t dest_mac[6];
108} __attribute__((packed));
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200109
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200110enum wil_wmi_sched_scheme_advertisment {
111 WIL_WMI_ADVERTISE_ESE_DISABLED,
112 WIL_WMI_ADVERTISE_ESE_IN_BEACON,
113 WIL_WMI_ADVERTISE_ESE_IN_ANNOUNCE_FRAME,
114};
115
116enum wil_wmi_ese_slot_type {
117 WIL_WMI_ESE_SP,
118 WIL_WMI_ESE_CBAP,
119 WIL_WMI_ESE_ANNOUNCE_NO_ACK,
120};
121
122struct wil_wmi_ese_slot {
123 /* offset from start of BI in microseconds */
124 uint32_t tbtt_offset;
125 uint8_t flags;
126 /* enum wil_wmi_ese_slot_type */
127 uint8_t slot_type;
128 /* duration in microseconds */
129 uint16_t duration;
130 /* frame exchange sequence duration, microseconds */
131 uint16_t tx_op;
132 /* time between 2 blocks for periodic allocation(microseconds) */
133 uint16_t period;
134 /* number of blocks in periodic allocation */
135 uint8_t num_blocks;
136 /* for semi-active allocations */
137 uint8_t idle_period;
138 uint8_t src_aid;
139 uint8_t dst_aid;
140 uint32_t reserved;
141} __attribute__((packed));
142
143#define WIL_WMI_MAX_ESE_SLOTS 4
144struct wil_wmi_ese_cfg {
145 uint8_t serial_num;
146 /* wil_wmi_sched_scheme_advertisment */
147 uint8_t ese_advertisment;
148 uint16_t flags;
149 uint8_t num_allocs;
150 uint8_t reserved[3];
151 uint64_t start_tbtt;
152 /* allocations list */
153 struct wil_wmi_ese_slot slots[WIL_WMI_MAX_ESE_SLOTS];
154} __attribute__((packed));
155
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200156#define WIL_WMI_UT_FORCE_MCS 6
157struct wil_wmi_force_mcs {
158 /* WIL_WMI_UT_HW_SYSAPI */
159 uint16_t module_id;
160 /* WIL_WMI_UT_FORCE_MCS */
161 uint16_t subtype_id;
162 /* cid (ignored in oob_mode, affects all stations) */
163 uint32_t cid;
164 /* 1 to force MCS, 0 to restore default behavior */
165 uint32_t force_enable;
166 /* MCS index, 0-12 */
167 uint32_t mcs;
168} __attribute__((packed));
169
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200170#define WIL_WMI_UT_HW_SYSAPI 10
171#define WIL_WMI_UT_FORCE_RSN_IE 0x29
172struct wil_wmi_force_rsn_ie {
173 /* WIL_WMI_UT_HW_SYSAPI */
174 uint16_t module_id;
175 /* WIL_WMI_UT_FORCE_RSN_IE */
176 uint16_t subtype_id;
177 /* 0 = no change, 1 = remove if exists, 2 = add if does not exist */
178 uint32_t state;
179} __attribute__((packed));
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300180
181enum wil_wmi_discovery_mode {
182 WMI_DISCOVERY_MODE_NON_OFFLOAD,
183 WMI_DISCOVERY_MODE_OFFLOAD,
184 WMI_DISCOVERY_MODE_PEER2PEER,
185};
186
187struct wil_wmi_p2p_cfg_cmd {
188 /* enum wil_wmi_discovery_mode */
189 uint8_t discovery_mode;
190 /* 0-based (wireless channel - 1) */
191 uint8_t channel;
192 /* set to WIL_DEFAULT_BI */
193 uint16_t bcon_interval;
194} __attribute__((packed));
Lior David0fe101e2017-03-09 16:09:50 +0200195#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200196
197#ifdef ANDROID
198
199static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname);
200
201#define ANDROID_KEYSTORE_GET 'g'
202#define ANDROID_KEYSTORE_GET_PUBKEY 'b'
203
204static int android_keystore_get(char cmd, const char *key, unsigned char *val)
205{
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200206 /* Android 4.3 changed keystore design, so need to use keystore_get() */
207#ifndef KEYSTORE_MESSAGE_SIZE
208#define KEYSTORE_MESSAGE_SIZE 65535
209#endif /* KEYSTORE_MESSAGE_SIZE */
210
211 ssize_t len;
212 uint8_t *value = NULL;
213
214 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
215 "keystore command '%c' key '%s' --> keystore_get",
216 cmd, key);
217
218 len = keystore_get(key, strlen(key), &value);
219 if (len < 0) {
220 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
221 "keystore_get() failed");
222 return -1;
223 }
224
225 if (len > KEYSTORE_MESSAGE_SIZE)
226 len = KEYSTORE_MESSAGE_SIZE;
227 memcpy(val, value, len);
228 free(value);
229 return len;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200230}
231#endif /* ANDROID */
232
233
Vinita S. Maloo0fcb57d2020-04-24 14:03:56 +0530234#ifdef NL80211_SUPPORT
235static int nl80211_sta_set_power_save(struct sigma_dut *dut,
236 const char *intf,
237 enum nl80211_ps_state ps_state)
238{
239 struct nl_msg *msg;
240 int ifindex, ret;
241
242 ifindex = if_nametoindex(intf);
243 if (ifindex == 0) {
244 sigma_dut_print(dut, DUT_MSG_ERROR,
245 "%s: Index for interface %s not found",
246 __func__, intf);
247 return -1;
248 }
249
250 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
251 NL80211_CMD_SET_POWER_SAVE);
252 if (!msg) {
253 sigma_dut_print(dut, DUT_MSG_ERROR,
254 "%s: err in creating nl80211 msg", __func__);
255 return -1;
256 }
257
258 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) {
259 sigma_dut_print(dut, DUT_MSG_ERROR,
260 "%s: err in populating nl80211 msg", __func__);
261 nlmsg_free(msg);
262 return -1;
263 }
264
265 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
266 if (ret) {
267 sigma_dut_print(dut, DUT_MSG_ERROR,
268 "%s: err in send_and_recv_msgs, ret=%d (%s)",
269 __func__, ret, strerror(-ret));
270 return -1;
271 }
272
273 return 0;
274}
275#endif /* NL80211_SUPPORT */
276
277
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530278static int set_power_save_wcn(struct sigma_dut *dut, const char *intf, int ps)
279{
280 char buf[100];
Vinita S. Maloo0fcb57d2020-04-24 14:03:56 +0530281#ifdef NL80211_SUPPORT
282 enum nl80211_ps_state ps_state;
283
284 ps_state = ps == 1 ? NL80211_PS_ENABLED : NL80211_PS_DISABLED;
285 if (nl80211_sta_set_power_save(dut, intf, ps_state) == 0)
286 return 0;
287#endif /* NL80211_SUPPORT */
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530288
289 snprintf(buf, sizeof(buf), "iwpriv %s setPower %d", intf, ps);
290 if (system(buf) != 0) {
291 sigma_dut_print(dut, DUT_MSG_ERROR,
292 "iwpriv setPower %d failed", ps);
293 return -1;
294 }
295 return 0;
296}
297
298
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200299int set_ps(const char *intf, struct sigma_dut *dut, int enabled)
300{
301#ifdef __linux__
302 char buf[100];
303
304 if (wifi_chip_type == DRIVER_WCN) {
305 if (enabled) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530306 if (set_power_save_wcn(dut, intf, 1) < 0) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530307 snprintf(buf, sizeof(buf),
308 "iwpriv wlan0 dump 906");
309 if (system(buf) != 0)
310 goto set_power_save;
311 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200312 } else {
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530313 if (set_power_save_wcn(dut, intf, 2) < 0) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530314 snprintf(buf, sizeof(buf),
315 "iwpriv wlan0 dump 905");
316 if (system(buf) != 0)
317 goto set_power_save;
318 snprintf(buf, sizeof(buf),
319 "iwpriv wlan0 dump 912");
320 if (system(buf) != 0)
321 goto set_power_save;
322 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200323 }
324
325 return 0;
326 }
327
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530328set_power_save:
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200329 snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s",
330 intf, enabled ? "on" : "off");
331 if (system(buf) != 0) {
332 snprintf(buf, sizeof(buf), "iw dev %s set power_save %s",
333 intf, enabled ? "on" : "off");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530334 if (system(buf) != 0) {
335 sigma_dut_print(dut, DUT_MSG_ERROR,
336 "Failed to set power save %s",
337 enabled ? "on" : "off");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200338 return -1;
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530339 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200340 }
341
342 return 0;
343#else /* __linux__ */
344 return -1;
345#endif /* __linux__ */
346}
347
348
Lior Davidcc88b562017-01-03 18:52:09 +0200349#ifdef __linux__
Lior David0fe101e2017-03-09 16:09:50 +0200350
Lior Davidcc88b562017-01-03 18:52:09 +0200351static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path,
352 size_t len)
353{
354 DIR *dir, *wil_dir;
355 struct dirent *entry;
356 int ret = -1;
357 const char *root_path = "/sys/kernel/debug/ieee80211";
358
359 dir = opendir(root_path);
360 if (!dir)
361 return -2;
362
363 while ((entry = readdir(dir))) {
364 if (strcmp(entry->d_name, ".") == 0 ||
365 strcmp(entry->d_name, "..") == 0)
366 continue;
367
368 if (snprintf(path, len, "%s/%s/wil6210",
369 root_path, entry->d_name) >= (int) len) {
370 ret = -3;
371 break;
372 }
373
374 wil_dir = opendir(path);
375 if (wil_dir) {
376 closedir(wil_dir);
377 ret = 0;
378 break;
379 }
380 }
381
382 closedir(dir);
383 return ret;
384}
Lior David0fe101e2017-03-09 16:09:50 +0200385
386
387static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command,
388 void *payload, uint16_t length)
389{
390 struct {
391 struct wil_wmi_header hdr;
392 char payload[WIL_WMI_MAX_PAYLOAD];
393 } __attribute__((packed)) cmd;
394 char buf[128], fname[128];
395 size_t towrite, written;
396 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300397 int res;
Lior David0fe101e2017-03-09 16:09:50 +0200398
399 if (length > WIL_WMI_MAX_PAYLOAD) {
400 sigma_dut_print(dut, DUT_MSG_ERROR,
401 "payload too large(%u, max %u)",
402 length, WIL_WMI_MAX_PAYLOAD);
403 return -1;
404 }
405
406 memset(&cmd.hdr, 0, sizeof(cmd.hdr));
407 cmd.hdr.cmd = command;
408 memcpy(cmd.payload, payload, length);
409
410 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
411 sigma_dut_print(dut, DUT_MSG_ERROR,
412 "failed to get wil6210 debugfs dir");
413 return -1;
414 }
415
Jouni Malinen3aa72862019-05-29 23:14:51 +0300416 res = snprintf(fname, sizeof(fname), "%s/wmi_send", buf);
417 if (res < 0 || res >= sizeof(fname))
418 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200419 f = fopen(fname, "wb");
420 if (!f) {
421 sigma_dut_print(dut, DUT_MSG_ERROR,
422 "failed to open: %s", fname);
423 return -1;
424 }
425
426 towrite = sizeof(cmd.hdr) + length;
427 written = fwrite(&cmd, 1, towrite, f);
428 fclose(f);
429 if (written != towrite) {
430 sigma_dut_print(dut, DUT_MSG_ERROR,
431 "failed to send wmi %u", command);
432 return -1;
433 }
434
435 return 0;
436}
437
438
439static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid,
440 const char *pattern, unsigned int *field)
441{
442 char buf[128], fname[128];
443 FILE *f;
444 regex_t re;
445 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +0300446 int rc, ret = -1, res;
Lior David0fe101e2017-03-09 16:09:50 +0200447
448 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
449 sigma_dut_print(dut, DUT_MSG_ERROR,
450 "failed to get wil6210 debugfs dir");
451 return -1;
452 }
453
Jouni Malinen3aa72862019-05-29 23:14:51 +0300454 res = snprintf(fname, sizeof(fname), "%s/stations", buf);
455 if (res < 0 || res >= sizeof(fname))
456 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200457 f = fopen(fname, "r");
458 if (!f) {
459 sigma_dut_print(dut, DUT_MSG_ERROR,
460 "failed to open: %s", fname);
461 return -1;
462 }
463
464 if (regcomp(&re, pattern, REG_EXTENDED)) {
465 sigma_dut_print(dut, DUT_MSG_ERROR,
466 "regcomp failed: %s", pattern);
467 goto out;
468 }
469
470 /*
471 * find the entry for the mac address
472 * line is of the form: [n] 11:22:33:44:55:66 state AID aid
473 */
474 while (fgets(buf, sizeof(buf), f)) {
475 if (strcasestr(buf, bssid)) {
476 /* extract the field (CID/AID/state) */
477 rc = regexec(&re, buf, 2, m, 0);
478 if (!rc && (m[1].rm_so >= 0)) {
479 buf[m[1].rm_eo] = 0;
480 *field = atoi(&buf[m[1].rm_so]);
481 ret = 0;
482 break;
483 }
484 }
485 }
486
487 regfree(&re);
488 if (ret)
489 sigma_dut_print(dut, DUT_MSG_ERROR,
490 "could not extract field");
491
492out:
493 fclose(f);
494
495 return ret;
496}
497
498
499static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid,
500 unsigned int *cid)
501{
502 const char *pattern = "\\[([0-9]+)\\]";
503
504 return wil6210_get_sta_info_field(dut, bssid, pattern, cid);
505}
506
507
508static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac,
509 int l_rx)
510{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700511 struct wil_wmi_bf_trig_cmd cmd;
Lior David0fe101e2017-03-09 16:09:50 +0200512 unsigned int cid;
513
Rakesh Sunki556237d2017-03-30 14:49:31 -0700514 memset(&cmd, 0, sizeof(cmd));
515
Lior David0fe101e2017-03-09 16:09:50 +0200516 if (wil6210_get_cid(dut, mac, &cid))
517 return -1;
518
519 cmd.bf_type = WIL_WMI_BRP_RX;
520 cmd.sta_id = cid;
521 /* training length (l_rx) is ignored, FW always uses length 16 */
522 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
523 &cmd, sizeof(cmd));
524}
525
526
527static int wil6210_send_sls(struct sigma_dut *dut, const char *mac)
528{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700529 struct wil_wmi_bf_trig_cmd cmd;
530
531 memset(&cmd, 0, sizeof(cmd));
Lior David0fe101e2017-03-09 16:09:50 +0200532
533 if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac))
534 return -1;
535
536 cmd.bf_type = WIL_WMI_SLS;
537 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
538 &cmd, sizeof(cmd));
539}
540
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200541
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200542int wil6210_set_ese(struct sigma_dut *dut, int count,
543 struct sigma_ese_alloc *allocs)
544{
545 struct wil_wmi_ese_cfg cmd = { };
546 int i;
547
548 if (count == 0 || count > WIL_WMI_MAX_ESE_SLOTS)
549 return -1;
550
551 if (dut->ap_bcnint <= 0) {
552 sigma_dut_print(dut, DUT_MSG_ERROR,
553 "invalid beacon interval(%d), check test",
554 dut->ap_bcnint);
555 return -1;
556 }
557
558 cmd.ese_advertisment = WIL_WMI_ADVERTISE_ESE_IN_BEACON;
559 cmd.flags = 0x1d;
560 cmd.num_allocs = count;
561 for (i = 0; i < count; i++) {
562 /*
563 * Convert percent from BI (BI specified in milliseconds)
564 * to absolute duration in microseconds.
565 */
566 cmd.slots[i].duration =
567 (allocs[i].percent_bi * dut->ap_bcnint * 1000) / 100;
568 switch (allocs[i].type) {
569 case ESE_CBAP:
570 cmd.slots[i].slot_type = WIL_WMI_ESE_CBAP;
571 break;
572 case ESE_SP:
573 cmd.slots[i].slot_type = WIL_WMI_ESE_SP;
574 break;
575 default:
576 sigma_dut_print(dut, DUT_MSG_ERROR,
577 "invalid slot type(%d) at index %d",
578 allocs[i].type, i);
579 return -1;
580 }
581 cmd.slots[i].src_aid = allocs[i].src_aid;
582 cmd.slots[i].dst_aid = allocs[i].dst_aid;
583 sigma_dut_print(dut, DUT_MSG_INFO,
584 "slot %d, duration %u, type %d, srcAID %u dstAID %u",
585 i, cmd.slots[i].duration,
586 cmd.slots[i].slot_type, cmd.slots[i].src_aid,
587 cmd.slots[i].dst_aid);
588 }
589
590 return wil6210_wmi_send(dut, WIL_WMI_ESE_CFG_CMDID, &cmd, sizeof(cmd));
591}
592
593
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200594int wil6210_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
595{
596 struct wil_wmi_force_mcs cmd = { };
597
598 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
599 cmd.subtype_id = WIL_WMI_UT_FORCE_MCS;
600 cmd.force_enable = (uint32_t) force;
601 cmd.mcs = (uint32_t) mcs;
602
603 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
604 &cmd, sizeof(cmd));
605}
606
607
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200608static int wil6210_force_rsn_ie(struct sigma_dut *dut, int state)
609{
610 struct wil_wmi_force_rsn_ie cmd = { };
611
612 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
613 cmd.subtype_id = WIL_WMI_UT_FORCE_RSN_IE;
614 cmd.state = (uint32_t) state;
615
616 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
617 &cmd, sizeof(cmd));
618}
619
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300620
621/*
622 * this function is also used to configure generic remain-on-channel
623 */
624static int wil6210_p2p_cfg(struct sigma_dut *dut, int freq)
625{
626 struct wil_wmi_p2p_cfg_cmd cmd = { };
627 int channel = freq_to_channel(freq);
628
629 if (channel < 0)
630 return -1;
631 cmd.discovery_mode = WMI_DISCOVERY_MODE_NON_OFFLOAD;
632 cmd.channel = channel - 1;
633 cmd.bcon_interval = WIL_DEFAULT_BI;
634 cmd.discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER;
635
636 return wil6210_wmi_send(dut, WIL_WMI_P2P_CFG_CMDID,
637 &cmd, sizeof(cmd));
638}
639
640
641static int wil6210_remain_on_channel(struct sigma_dut *dut, int freq)
642{
643 int ret = wil6210_p2p_cfg(dut, freq);
644
645 if (ret)
646 return ret;
647
648 ret = wil6210_wmi_send(dut, WIL_WMI_START_LISTEN_CMDID, NULL, 0);
649 if (!ret) {
650 /*
651 * wait a bit to allow FW to setup the radio
652 * especially important if we switch channels
653 */
654 usleep(500000);
655 }
656
657 return ret;
658}
659
660
661static int wil6210_stop_discovery(struct sigma_dut *dut)
662{
663 return wil6210_wmi_send(dut, WIL_WMI_DISCOVERY_STOP_CMDID, NULL, 0);
664}
665
666
667static int wil6210_transmit_frame(struct sigma_dut *dut, int freq,
668 int wait_duration,
669 const char *frame, size_t frame_len)
670{
671 char buf[128], fname[128];
672 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300673 int res = 0, r;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300674 size_t written;
675
676 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
677 sigma_dut_print(dut, DUT_MSG_ERROR,
678 "failed to get wil6210 debugfs dir");
679 return -1;
680 }
Jouni Malinen3aa72862019-05-29 23:14:51 +0300681 r = snprintf(fname, sizeof(fname), "%s/tx_mgmt", buf);
682 if (r < 0 || r >= sizeof(fname))
683 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300684
685 if (wil6210_remain_on_channel(dut, freq)) {
686 sigma_dut_print(dut, DUT_MSG_ERROR,
687 "failed to listen on channel");
688 return -1;
689 }
690
691 f = fopen(fname, "wb");
692 if (!f) {
693 sigma_dut_print(dut, DUT_MSG_ERROR,
694 "failed to open: %s", fname);
695 res = -1;
696 goto out_stop;
697 }
698 written = fwrite(frame, 1, frame_len, f);
699 fclose(f);
700
701 if (written != frame_len) {
702 sigma_dut_print(dut, DUT_MSG_ERROR,
703 "failed to transmit frame (got %zd, expected %zd)",
704 written, frame_len);
705 res = -1;
706 goto out_stop;
707 }
708
709 usleep(wait_duration * 1000);
710
711out_stop:
712 wil6210_stop_discovery(dut);
713 return res;
714}
715
716
717static int find_template_frame_tag(struct template_frame_tag *tags,
718 int total_tags, int tag_num)
719{
720 int i;
721
722 for (i = 0; i < total_tags; i++) {
723 if (tag_num == tags[i].num)
724 return i;
725 }
726
727 return -1;
728}
729
730
731static int replace_p2p_attribute(struct sigma_dut *dut, char *buf, size_t len,
732 int id, const char *value, size_t val_len)
733{
734 struct wfa_p2p_attribute *attr = (struct wfa_p2p_attribute *) buf;
735
736 if (len < 3 + val_len) {
737 sigma_dut_print(dut, DUT_MSG_ERROR,
738 "not enough space to replace P2P attribute");
739 return -1;
740 }
741
742 if (attr->len != val_len) {
743 sigma_dut_print(dut, DUT_MSG_ERROR,
744 "attribute length mismatch (need %zu have %hu)",
745 val_len, attr->len);
746 return -1;
747 }
748
749 if (attr->id != id) {
750 sigma_dut_print(dut, DUT_MSG_ERROR,
751 "incorrect attribute id (expected %d actual %d)",
752 id, attr->id);
753 return -1;
754 }
755
756 memcpy(attr->variable, value, val_len);
757
758 return 0;
759}
760
761
762static int parse_template_frame_file(struct sigma_dut *dut, const char *fname,
763 char *buf, size_t *length,
764 struct template_frame_tag *tags,
765 size_t *num_tags)
766{
767 char line[512];
768 FILE *f;
769 size_t offset = 0, tag_index = 0;
770 int num, index;
771 int in_tag = 0, tag_num = 0, tag_offset = 0;
772
773 if (*length < sizeof(struct ieee80211_hdr_3addr)) {
774 sigma_dut_print(dut, DUT_MSG_ERROR,
775 "supplied buffer is too small");
776 return -1;
777 }
778
779 f = fopen(fname, "r");
780 if (!f) {
781 sigma_dut_print(dut, DUT_MSG_ERROR,
782 "failed to open template file %s", fname);
783 return -1;
784 }
785
786 /*
787 * template file format: lines beginning with # are comments and
788 * ignored.
789 * It is possible to tag bytes in the frame to make it easy
790 * to replace fields in the template, espcially if they appear
791 * in variable-sized sections (such as IEs)
792 * This is done by a line beginning with $NUM where NUM is an integer
793 * tag number. It can be followed by space(s) and comment.
794 * The next line is considered the tagged bytes. The parser will fill
795 * the tag number, offset and length of the tagged bytes.
796 * rest of the lines contain frame bytes as sequence of hex digits,
797 * 2 digits for each byte. Spaces are allowed between bytes.
798 * On bytes lines only hex digits and spaces are allowed
799 */
800 while (!feof(f)) {
801 if (!fgets(line, sizeof(line), f))
802 break;
803 index = 0;
804 while (isspace((unsigned char) line[index]))
805 index++;
806 if (!line[index] || line[index] == '#')
807 continue;
808 if (line[index] == '$') {
809 if (tags) {
810 index++;
811 tag_num = strtol(&line[index], NULL, 0);
812 tag_offset = offset;
813 in_tag = 1;
814 }
815 continue;
816 }
817 while (line[index]) {
818 if (isspace((unsigned char) line[index])) {
819 index++;
820 continue;
821 }
822 num = hex_byte(&line[index]);
823 if (num < 0)
824 break;
825 buf[offset++] = num;
826 if (offset == *length)
827 goto out;
828 index += 2;
829 }
830
831 if (in_tag) {
832 if (tag_index < *num_tags) {
833 tags[tag_index].num = tag_num;
834 tags[tag_index].offset = tag_offset;
835 tags[tag_index].len = offset - tag_offset;
836 tag_index++;
837 } else {
838 sigma_dut_print(dut, DUT_MSG_INFO,
839 "too many tags, tag ignored");
840 }
841 in_tag = 0;
842 }
843 }
844
845 if (num_tags)
846 *num_tags = tag_index;
847out:
848 fclose(f);
849 if (offset < sizeof(struct ieee80211_hdr_3addr)) {
850 sigma_dut_print(dut, DUT_MSG_ERROR,
851 "template frame is too small");
852 return -1;
853 }
854
855 *length = offset;
856 return 0;
857}
858
Lior Davidcc88b562017-01-03 18:52:09 +0200859#endif /* __linux__ */
860
861
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200862static void static_ip_file(int proto, const char *addr, const char *mask,
863 const char *gw)
864{
865 if (proto) {
866 FILE *f = fopen("static-ip", "w");
867 if (f) {
868 fprintf(f, "%d %s %s %s\n", proto, addr,
869 mask ? mask : "N/A",
870 gw ? gw : "N/A");
871 fclose(f);
872 }
873 } else {
874 unlink("static-ip");
875 }
876}
877
878
879static int send_neighbor_request(struct sigma_dut *dut, const char *intf,
880 const char *ssid)
881{
882#ifdef __linux__
883 char buf[100];
884
885 snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s",
886 intf, ssid);
887 sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf);
888
889 if (system(buf) != 0) {
890 sigma_dut_print(dut, DUT_MSG_ERROR,
891 "iwpriv neighbor request failed");
892 return -1;
893 }
894
895 sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send");
896
897 return 0;
898#else /* __linux__ */
899 return -1;
900#endif /* __linux__ */
901}
902
903
904static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf,
Ashwini Patil5acd7382017-04-13 15:55:04 +0530905 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200906{
Ashwini Patil5acd7382017-04-13 15:55:04 +0530907 const char *val;
908 int reason_code = 0;
909 char buf[1024];
910
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200911 /*
912 * In the earlier builds we used WNM_QUERY and in later
913 * builds used WNM_BSS_QUERY.
914 */
915
Ashwini Patil5acd7382017-04-13 15:55:04 +0530916 val = get_param(cmd, "BTMQuery_Reason_Code");
917 if (val)
918 reason_code = atoi(val);
919
920 val = get_param(cmd, "Cand_List");
921 if (val && atoi(val) == 1 && dut->btm_query_cand_list) {
922 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code,
923 dut->btm_query_cand_list);
924 free(dut->btm_query_cand_list);
925 dut->btm_query_cand_list = NULL;
926 } else {
927 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code);
928 }
929
930 if (wpa_command(intf, buf) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200931 sigma_dut_print(dut, DUT_MSG_ERROR,
932 "transition management query failed");
933 return -1;
934 }
935
936 sigma_dut_print(dut, DUT_MSG_DEBUG,
937 "transition management query sent");
938
939 return 0;
940}
941
942
943int is_ip_addr(const char *str)
944{
945 const char *pos = str;
946 struct in_addr addr;
947
948 while (*pos) {
949 if (*pos != '.' && (*pos < '0' || *pos > '9'))
950 return 0;
951 pos++;
952 }
953
954 return inet_aton(str, &addr);
955}
956
957
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200958int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
959 size_t buf_len)
960{
vamsi krishnaa11d0732018-05-16 12:19:48 +0530961 char tmp[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200962 char ip[16], mask[15], dns[16], sec_dns[16];
963 int is_dhcp = 0;
964 int s;
965#ifdef ANDROID
966 char prop[PROPERTY_VALUE_MAX];
vamsi krishnaa11d0732018-05-16 12:19:48 +0530967#else /* ANDROID */
968 FILE *f;
969#ifdef __linux__
970 const char *str_ps;
971#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200972#endif /* ANDROID */
973
974 ip[0] = '\0';
975 mask[0] = '\0';
976 dns[0] = '\0';
977 sec_dns[0] = '\0';
978
979 s = socket(PF_INET, SOCK_DGRAM, 0);
980 if (s >= 0) {
981 struct ifreq ifr;
982 struct sockaddr_in saddr;
983
984 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700985 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200986 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
987 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
988 "%s IP address: %s",
989 ifname, strerror(errno));
990 } else {
991 memcpy(&saddr, &ifr.ifr_addr,
992 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700993 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200994 }
995
996 if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) {
997 memcpy(&saddr, &ifr.ifr_addr,
998 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700999 strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001000 }
1001 close(s);
1002 }
1003
1004#ifdef ANDROID
1005 snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname);
1006 if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) {
1007 snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname);
1008 if (property_get(tmp, prop, NULL) != 0 &&
1009 strcmp(prop, "ok") == 0) {
1010 snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress",
1011 ifname);
1012 if (property_get(tmp, prop, NULL) != 0 &&
1013 strcmp(ip, prop) == 0)
1014 is_dhcp = 1;
1015 }
1016 }
1017
1018 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -07001019 if (property_get(tmp, prop, NULL) != 0)
1020 strlcpy(dns, prop, sizeof(dns));
1021 else if (property_get("net.dns1", prop, NULL) != 0)
1022 strlcpy(dns, prop, sizeof(dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001023
1024 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -07001025 if (property_get(tmp, prop, NULL) != 0)
1026 strlcpy(sec_dns, prop, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001027#else /* ANDROID */
1028#ifdef __linux__
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001029 if (get_driver_type(dut) == DRIVER_OPENWRT)
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301030 str_ps = "ps -w";
1031 else
1032 str_ps = "ps ax";
1033 snprintf(tmp, sizeof(tmp),
1034 "%s | grep dhclient | grep -v grep | grep -q %s",
1035 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001036 if (system(tmp) == 0)
1037 is_dhcp = 1;
1038 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301039 snprintf(tmp, sizeof(tmp),
1040 "%s | grep udhcpc | grep -v grep | grep -q %s",
1041 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001042 if (system(tmp) == 0)
1043 is_dhcp = 1;
1044 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301045 snprintf(tmp, sizeof(tmp),
1046 "%s | grep dhcpcd | grep -v grep | grep -q %s",
1047 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001048 if (system(tmp) == 0)
1049 is_dhcp = 1;
1050 }
1051 }
1052#endif /* __linux__ */
1053
1054 f = fopen("/etc/resolv.conf", "r");
1055 if (f) {
vamsi krishnaa11d0732018-05-16 12:19:48 +05301056 char *pos, *pos2;
1057
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001058 while (fgets(tmp, sizeof(tmp), f)) {
1059 if (strncmp(tmp, "nameserver", 10) != 0)
1060 continue;
1061 pos = tmp + 10;
1062 while (*pos == ' ' || *pos == '\t')
1063 pos++;
1064 pos2 = pos;
1065 while (*pos2) {
1066 if (*pos2 == '\n' || *pos2 == '\r') {
1067 *pos2 = '\0';
1068 break;
1069 }
1070 pos2++;
1071 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07001072 if (!dns[0])
1073 strlcpy(dns, pos, sizeof(dns));
1074 else if (!sec_dns[0])
1075 strlcpy(sec_dns, pos, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001076 }
1077 fclose(f);
1078 }
1079#endif /* ANDROID */
1080
1081 snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s",
1082 is_dhcp, ip, mask, dns);
1083 buf[buf_len - 1] = '\0';
1084
1085 return 0;
1086}
1087
1088
1089
1090
1091int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf,
1092 size_t buf_len)
1093{
1094#ifdef __linux__
1095#ifdef ANDROID
1096 char cmd[200], result[1000], *pos, *end;
1097 FILE *f;
1098 size_t len;
1099
1100 snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname);
1101 f = popen(cmd, "r");
1102 if (f == NULL)
1103 return -1;
1104 len = fread(result, 1, sizeof(result) - 1, f);
1105 pclose(f);
1106 if (len == 0)
1107 return -1;
1108 result[len] = '\0';
1109 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result);
1110
1111 pos = strstr(result, "inet6 ");
1112 if (pos == NULL)
1113 return -1;
1114 pos += 6;
1115 end = strchr(pos, ' ');
1116 if (end)
1117 *end = '\0';
1118 end = strchr(pos, '/');
1119 if (end)
1120 *end = '\0';
1121 snprintf(buf, buf_len, "ip,%s", pos);
1122 buf[buf_len - 1] = '\0';
1123 return 0;
1124#else /* ANDROID */
1125 struct ifaddrs *ifaddr, *ifa;
1126 int res, found = 0;
1127 char host[NI_MAXHOST];
1128
1129 if (getifaddrs(&ifaddr) < 0) {
1130 perror("getifaddrs");
1131 return -1;
1132 }
1133
1134 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
1135 if (strcasecmp(ifname, ifa->ifa_name) != 0)
1136 continue;
1137 if (ifa->ifa_addr == NULL ||
1138 ifa->ifa_addr->sa_family != AF_INET6)
1139 continue;
1140
1141 res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
1142 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
1143 if (res != 0) {
1144 sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s",
1145 gai_strerror(res));
1146 continue;
1147 }
1148 if (strncmp(host, "fe80::", 6) == 0)
1149 continue; /* skip link-local */
1150
1151 sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host);
1152 found = 1;
1153 break;
1154 }
1155
1156 freeifaddrs(ifaddr);
1157
1158 if (found) {
1159 char *pos;
1160 pos = strchr(host, '%');
1161 if (pos)
1162 *pos = '\0';
1163 snprintf(buf, buf_len, "ip,%s", host);
1164 buf[buf_len - 1] = '\0';
1165 return 0;
1166 }
1167
1168#endif /* ANDROID */
1169#endif /* __linux__ */
1170 return -1;
1171}
1172
1173
Jouni Malinenf7222712019-06-13 01:50:21 +03001174static enum sigma_cmd_result cmd_sta_get_ip_config(struct sigma_dut *dut,
1175 struct sigma_conn *conn,
1176 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001177{
1178 const char *intf = get_param(cmd, "Interface");
1179 const char *ifname;
1180 char buf[200];
1181 const char *val;
1182 int type = 1;
1183
1184 if (intf == NULL)
1185 return -1;
1186
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001187 if (strcmp(intf, get_main_ifname(dut)) == 0)
1188 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001189 else
1190 ifname = intf;
1191
1192 /*
1193 * UCC may assume the IP address to be available immediately after
1194 * association without trying to run sta_get_ip_config multiple times.
1195 * Sigma CAPI does not specify this command as a block command that
1196 * would wait for the address to become available, but to pass tests
1197 * more reliably, it looks like such a wait may be needed here.
1198 */
1199 if (wait_ip_addr(dut, ifname, 15) < 0) {
1200 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address "
1201 "for sta_get_ip_config");
1202 /*
1203 * Try to continue anyway since many UCC tests do not really
1204 * care about the return value from here..
1205 */
1206 }
1207
1208 val = get_param(cmd, "Type");
1209 if (val)
1210 type = atoi(val);
1211 if (type == 2 || dut->last_set_ip_config_ipv6) {
1212 int i;
1213
1214 /*
1215 * Since we do not have proper wait for IPv6 addresses, use a
1216 * fixed two second delay here as a workaround for UCC script
1217 * assuming IPv6 address is available when this command returns.
1218 * Some scripts did not use Type,2 properly for IPv6, so include
1219 * also the cases where the previous sta_set_ip_config indicated
1220 * use of IPv6.
1221 */
1222 sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address");
1223 for (i = 0; i < 10; i++) {
1224 sleep(1);
1225 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0)
1226 {
1227 sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address");
1228 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1229#ifdef ANDROID
1230 sigma_dut_print(dut, DUT_MSG_INFO,
1231 "Adding IPv6 rule on Android");
1232 add_ipv6_rule(dut, intf);
1233#endif /* ANDROID */
1234
1235 return 0;
1236 }
1237 }
1238 }
1239 if (type == 1) {
1240 if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0)
1241 return -2;
1242 } else if (type == 2) {
1243 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0)
1244 return -2;
1245 } else {
1246 send_resp(dut, conn, SIGMA_ERROR,
1247 "errorCode,Unsupported address type");
1248 return 0;
1249 }
1250
1251 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1252 return 0;
1253}
1254
1255
1256static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname)
1257{
1258#ifdef __linux__
1259 char buf[200];
1260 char path[128];
1261 struct stat s;
1262
1263#ifdef ANDROID
1264 snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname);
1265#else /* ANDROID */
1266 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname);
1267#endif /* ANDROID */
1268 if (stat(path, &s) == 0) {
1269 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1270 sigma_dut_print(dut, DUT_MSG_INFO,
1271 "Kill previous DHCP client: %s", buf);
1272 if (system(buf) != 0)
1273 sigma_dut_print(dut, DUT_MSG_INFO,
1274 "Failed to kill DHCP client");
1275 unlink(path);
1276 sleep(1);
1277 } else {
1278 snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname);
1279
1280 if (stat(path, &s) == 0) {
1281 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1282 sigma_dut_print(dut, DUT_MSG_INFO,
1283 "Kill previous DHCP client: %s", buf);
1284 if (system(buf) != 0)
1285 sigma_dut_print(dut, DUT_MSG_INFO,
1286 "Failed to kill DHCP client");
1287 unlink(path);
1288 sleep(1);
1289 }
1290 }
1291#endif /* __linux__ */
1292}
1293
1294
1295static int start_dhcp_client(struct sigma_dut *dut, const char *ifname)
1296{
1297#ifdef __linux__
1298 char buf[200];
1299
1300#ifdef ANDROID
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301301 if (access("/system/bin/dhcpcd", F_OK) != -1) {
1302 snprintf(buf, sizeof(buf),
1303 "/system/bin/dhcpcd -b %s", ifname);
1304 } else if (access("/system/bin/dhcptool", F_OK) != -1) {
1305 snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname);
Ankita Bajaj8454e5d2019-04-05 16:04:55 +05301306 } else if (access("/vendor/bin/dhcpcd", F_OK) != -1) {
1307 snprintf(buf, sizeof(buf), "/vendor/bin/dhcpcd -b %s", ifname);
1308 } else if (access("/vendor/bin/dhcptool", F_OK) != -1) {
1309 snprintf(buf, sizeof(buf), "/vendor/bin/dhcptool %s", ifname);
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301310 } else {
1311 sigma_dut_print(dut, DUT_MSG_ERROR,
1312 "DHCP client program missing");
1313 return 0;
1314 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001315#else /* ANDROID */
1316 snprintf(buf, sizeof(buf),
1317 "dhclient -nw -pf /var/run/dhclient-%s.pid %s",
1318 ifname, ifname);
1319#endif /* ANDROID */
1320 sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf);
1321 if (system(buf) != 0) {
1322 snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname);
1323 if (system(buf) != 0) {
1324 sigma_dut_print(dut, DUT_MSG_INFO,
1325 "Failed to start DHCP client");
1326#ifndef ANDROID
1327 return -1;
1328#endif /* ANDROID */
1329 }
1330 }
1331#endif /* __linux__ */
1332
1333 return 0;
1334}
1335
1336
1337static int clear_ip_addr(struct sigma_dut *dut, const char *ifname)
1338{
1339#ifdef __linux__
1340 char buf[200];
1341
1342 snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname);
1343 if (system(buf) != 0) {
1344 sigma_dut_print(dut, DUT_MSG_INFO,
1345 "Failed to clear IP addresses");
1346 return -1;
1347 }
1348#endif /* __linux__ */
1349
1350 return 0;
1351}
1352
1353
1354#ifdef ANDROID
1355static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname)
1356{
1357 char cmd[200], *result, *pos;
1358 FILE *fp;
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301359 int tableid;
1360 size_t len, result_len = 1000;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001361
1362 snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s",
1363 ifname);
1364 fp = popen(cmd, "r");
1365 if (fp == NULL)
1366 return -1;
1367
1368 result = malloc(result_len);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301369 if (result == NULL) {
1370 fclose(fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001371 return -1;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301372 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001373
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301374 len = fread(result, 1, result_len - 1, fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001375 fclose(fp);
1376
1377 if (len == 0) {
1378 free(result);
1379 return -1;
1380 }
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301381 result[len] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001382
1383 pos = strstr(result, "table ");
1384 if (pos == NULL) {
1385 free(result);
1386 return -1;
1387 }
1388
1389 pos += strlen("table ");
1390 tableid = atoi(pos);
1391 if (tableid != 0) {
1392 if (system("ip -6 rule del prio 22000") != 0) {
1393 /* ignore any error */
1394 }
1395 snprintf(cmd, sizeof(cmd),
1396 "ip -6 rule add from all lookup %d prio 22000",
1397 tableid);
1398 if (system(cmd) != 0) {
1399 sigma_dut_print(dut, DUT_MSG_INFO,
1400 "Failed to run %s", cmd);
1401 free(result);
1402 return -1;
1403 }
1404 } else {
1405 sigma_dut_print(dut, DUT_MSG_INFO,
1406 "No Valid Table Id found %s", pos);
1407 free(result);
1408 return -1;
1409 }
1410 free(result);
1411
1412 return 0;
1413}
1414#endif /* ANDROID */
1415
1416
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301417int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
1418 const char *ip, const char *mask)
1419{
1420 char buf[200];
1421
1422 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
1423 ifname, ip, mask);
1424 return system(buf) == 0;
1425}
1426
1427
1428int set_ipv4_gw(struct sigma_dut *dut, const char *gw)
1429{
1430 char buf[200];
1431
1432 if (!is_ip_addr(gw)) {
1433 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw);
1434 return -1;
1435 }
1436
1437 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
1438 if (!dut->no_ip_addr_set && system(buf) != 0) {
1439 snprintf(buf, sizeof(buf), "ip ro re default via %s",
1440 gw);
1441 if (system(buf) != 0)
1442 return 0;
1443 }
1444
1445 return 1;
1446}
1447
1448
Jouni Malinenf7222712019-06-13 01:50:21 +03001449static enum sigma_cmd_result cmd_sta_set_ip_config(struct sigma_dut *dut,
1450 struct sigma_conn *conn,
1451 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001452{
1453 const char *intf = get_param(cmd, "Interface");
1454 const char *ifname;
1455 char buf[200];
1456 const char *val, *ip, *mask, *gw;
1457 int type = 1;
1458
1459 if (intf == NULL)
1460 return -1;
1461
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001462 if (strcmp(intf, get_main_ifname(dut)) == 0)
1463 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001464 else
1465 ifname = intf;
1466
1467 if (if_nametoindex(ifname) == 0) {
1468 send_resp(dut, conn, SIGMA_ERROR,
1469 "ErrorCode,Unknown interface");
1470 return 0;
1471 }
1472
1473 val = get_param(cmd, "Type");
1474 if (val) {
1475 type = atoi(val);
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301476 if (type < 1 || type > 3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001477 send_resp(dut, conn, SIGMA_ERROR,
1478 "ErrorCode,Unsupported address type");
1479 return 0;
1480 }
1481 }
1482
1483 dut->last_set_ip_config_ipv6 = 0;
1484
1485 val = get_param(cmd, "dhcp");
1486 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
1487 static_ip_file(0, NULL, NULL, NULL);
1488#ifdef __linux__
1489 if (type == 2) {
1490 dut->last_set_ip_config_ipv6 = 1;
1491 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
1492 "stateless address autoconfiguration");
1493#ifdef ANDROID
1494 /*
1495 * This sleep is required as the assignment in case of
1496 * Android is taking time and is done by the kernel.
1497 * The subsequent ping for IPv6 is impacting HS20 test
1498 * case.
1499 */
1500 sleep(2);
1501 add_ipv6_rule(dut, intf);
1502#endif /* ANDROID */
1503 /* Assume this happens by default */
1504 return 1;
1505 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301506 if (type != 3) {
1507 kill_dhcp_client(dut, ifname);
1508 if (start_dhcp_client(dut, ifname) < 0)
1509 return -2;
1510 } else {
1511 sigma_dut_print(dut, DUT_MSG_DEBUG,
1512 "Using FILS HLP DHCPv4 Rapid Commit");
1513 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001514
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001515 return 1;
1516#endif /* __linux__ */
1517 return -2;
1518 }
1519
1520 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301521 if (!ip) {
1522 send_resp(dut, conn, SIGMA_INVALID,
1523 "ErrorCode,Missing IP address");
1524 return 0;
1525 }
1526
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001527 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301528 if (!mask) {
1529 send_resp(dut, conn, SIGMA_INVALID,
1530 "ErrorCode,Missing subnet mask");
1531 return 0;
1532 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001533
1534 if (type == 2) {
1535 int net = atoi(mask);
1536
1537 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
1538 return -1;
1539
1540 if (dut->no_ip_addr_set) {
1541 snprintf(buf, sizeof(buf),
1542 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
1543 ifname);
1544 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1545 if (system(buf) != 0) {
1546 sigma_dut_print(dut, DUT_MSG_DEBUG,
1547 "Failed to disable IPv6 address before association");
1548 }
1549 } else {
Veerendranath Jakkam176181c2020-05-16 00:19:21 +05301550 if (set_ipv6_addr(dut, ip, mask, ifname) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001551 send_resp(dut, conn, SIGMA_ERROR,
1552 "ErrorCode,Failed to set IPv6 address");
1553 return 0;
1554 }
1555 }
1556
1557 dut->last_set_ip_config_ipv6 = 1;
1558 static_ip_file(6, ip, mask, NULL);
1559 return 1;
1560 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301561 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001562 return -1;
1563 }
1564
1565 kill_dhcp_client(dut, ifname);
1566
1567 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301568 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001569 send_resp(dut, conn, SIGMA_ERROR,
1570 "ErrorCode,Failed to set IP address");
1571 return 0;
1572 }
1573 }
1574
1575 gw = get_param(cmd, "defaultGateway");
1576 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301577 if (set_ipv4_gw(dut, gw) < 1) {
1578 send_resp(dut, conn, SIGMA_ERROR,
1579 "ErrorCode,Failed to set default gateway");
1580 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001581 }
1582 }
1583
1584 val = get_param(cmd, "primary-dns");
1585 if (val) {
Vinita S. Maloo069e8d42021-04-29 13:15:08 +05301586#ifdef ANDROID
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001587 /* TODO */
1588 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1589 "setting", val);
Vinita S. Maloo069e8d42021-04-29 13:15:08 +05301590#else /* ANDROID */
1591 char dns_cmd[200];
1592 int len;
1593
1594 if (system("sed -i '/nameserver/d' /etc/resolv.conf") != 0) {
1595 sigma_dut_print(dut, DUT_MSG_ERROR,
1596 "Failed to clear nameserver entries in /etc/resolv.conf");
1597 return ERROR_SEND_STATUS;
1598 }
1599
1600 len = snprintf(dns_cmd, sizeof(dns_cmd),
1601 "sed -i '1 i nameserver %s' /etc/resolv.conf", val);
1602 if (len < 0 || len >= sizeof(dns_cmd))
1603 return ERROR_SEND_STATUS;
1604
1605 sigma_dut_print(dut, DUT_MSG_DEBUG, "Running %s", dns_cmd);
1606 if (system(dns_cmd) != 0) {
1607 send_resp(dut, conn, SIGMA_ERROR,
1608 "ErrorCode,Failed to set primary-dns");
1609 return STATUS_SENT_ERROR;
1610 }
1611#endif /* ANDROID */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001612 }
1613
1614 val = get_param(cmd, "secondary-dns");
1615 if (val) {
1616 /* TODO */
1617 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1618 "setting", val);
1619 }
1620
1621 static_ip_file(4, ip, mask, gw);
1622
1623 return 1;
1624}
1625
1626
Jouni Malinenf7222712019-06-13 01:50:21 +03001627static enum sigma_cmd_result cmd_sta_get_info(struct sigma_dut *dut,
1628 struct sigma_conn *conn,
1629 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001630{
1631 /* const char *intf = get_param(cmd, "Interface"); */
1632 /* TODO: could report more details here */
1633 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1634 return 0;
1635}
1636
1637
Jouni Malinenf7222712019-06-13 01:50:21 +03001638static enum sigma_cmd_result cmd_sta_get_mac_address(struct sigma_dut *dut,
1639 struct sigma_conn *conn,
1640 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001641{
1642 /* const char *intf = get_param(cmd, "Interface"); */
1643 char addr[20], resp[50];
1644
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301645 if (dut->dev_role == DEVROLE_STA_CFON)
1646 return sta_cfon_get_mac_address(dut, conn, cmd);
1647
Jouni Malinen9540e012019-11-05 17:08:42 +02001648 start_sta_mode(dut);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001649 if (get_wpa_status(get_station_ifname(dut), "address",
1650 addr, sizeof(addr)) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001651 return -2;
1652
1653 snprintf(resp, sizeof(resp), "mac,%s", addr);
1654 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1655 return 0;
1656}
1657
1658
Jouni Malinenf7222712019-06-13 01:50:21 +03001659static enum sigma_cmd_result cmd_sta_is_connected(struct sigma_dut *dut,
1660 struct sigma_conn *conn,
1661 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001662{
1663 /* const char *intf = get_param(cmd, "Interface"); */
1664 int connected = 0;
1665 char result[32];
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001666 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001667 sizeof(result)) < 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001668 sigma_dut_print(dut, DUT_MSG_INFO,
1669 "Could not get interface %s status",
1670 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001671 return -2;
1672 }
1673
1674 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1675 if (strncmp(result, "COMPLETED", 9) == 0)
1676 connected = 1;
1677
1678 if (connected)
1679 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1680 else
1681 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1682
1683 return 0;
1684}
1685
1686
Jouni Malinenf7222712019-06-13 01:50:21 +03001687static enum sigma_cmd_result
1688cmd_sta_verify_ip_connection(struct sigma_dut *dut, struct sigma_conn *conn,
1689 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001690{
1691 /* const char *intf = get_param(cmd, "Interface"); */
1692 const char *dst, *timeout;
1693 int wait_time = 90;
1694 char buf[100];
1695 int res;
1696
1697 dst = get_param(cmd, "destination");
1698 if (dst == NULL || !is_ip_addr(dst))
1699 return -1;
1700
1701 timeout = get_param(cmd, "timeout");
1702 if (timeout) {
1703 wait_time = atoi(timeout);
1704 if (wait_time < 1)
1705 wait_time = 1;
1706 }
1707
1708 /* TODO: force renewal of IP lease if DHCP is enabled */
1709
1710 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1711 res = system(buf);
1712 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1713 if (res == 0)
1714 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1715 else if (res == 256)
1716 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1717 else
1718 return -2;
1719
1720 return 0;
1721}
1722
1723
Jouni Malinenf7222712019-06-13 01:50:21 +03001724static enum sigma_cmd_result cmd_sta_get_bssid(struct sigma_dut *dut,
1725 struct sigma_conn *conn,
1726 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001727{
1728 /* const char *intf = get_param(cmd, "Interface"); */
1729 char bssid[20], resp[50];
1730
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001731 if (get_wpa_status(get_station_ifname(dut), "bssid",
1732 bssid, sizeof(bssid)) < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001733 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001734
1735 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1736 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1737 return 0;
1738}
1739
1740
1741#ifdef __SAMSUNG__
1742static int add_use_network(const char *ifname)
1743{
1744 char buf[100];
1745
1746 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1747 wpa_command(ifname, buf);
1748 return 0;
1749}
1750#endif /* __SAMSUNG__ */
1751
1752
1753static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1754 const char *ifname, struct sigma_cmd *cmd)
1755{
1756 const char *ssid = get_param(cmd, "ssid");
1757 int id;
1758 const char *val;
1759
1760 if (ssid == NULL)
1761 return -1;
1762
1763 start_sta_mode(dut);
1764
1765#ifdef __SAMSUNG__
1766 add_use_network(ifname);
1767#endif /* __SAMSUNG__ */
1768
1769 id = add_network(ifname);
1770 if (id < 0)
1771 return -2;
1772 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1773
1774 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1775 return -2;
1776
1777 dut->infra_network_id = id;
1778 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1779
1780 val = get_param(cmd, "program");
1781 if (!val)
1782 val = get_param(cmd, "prog");
1783 if (val && strcasecmp(val, "hs2") == 0) {
1784 char buf[100];
1785 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1786 wpa_command(ifname, buf);
1787
1788 val = get_param(cmd, "prefer");
1789 if (val && atoi(val) > 0)
1790 set_network(ifname, id, "priority", "1");
1791 }
1792
1793 return id;
1794}
1795
1796
Jouni Malinenf7222712019-06-13 01:50:21 +03001797static enum sigma_cmd_result cmd_sta_set_encryption(struct sigma_dut *dut,
1798 struct sigma_conn *conn,
1799 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001800{
1801 const char *intf = get_param(cmd, "Interface");
1802 const char *ssid = get_param(cmd, "ssid");
1803 const char *type = get_param(cmd, "encpType");
1804 const char *ifname;
1805 char buf[200];
1806 int id;
1807
1808 if (intf == NULL || ssid == NULL)
1809 return -1;
1810
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001811 if (strcmp(intf, get_main_ifname(dut)) == 0)
1812 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001813 else
1814 ifname = intf;
1815
1816 id = add_network_common(dut, conn, ifname, cmd);
1817 if (id < 0)
1818 return id;
1819
1820 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1821 return -2;
1822
1823 if (type && strcasecmp(type, "wep") == 0) {
1824 const char *val;
1825 int i;
1826
1827 val = get_param(cmd, "activeKey");
1828 if (val) {
1829 int keyid;
1830 keyid = atoi(val);
1831 if (keyid < 1 || keyid > 4)
1832 return -1;
1833 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1834 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1835 return -2;
1836 }
1837
1838 for (i = 0; i < 4; i++) {
1839 snprintf(buf, sizeof(buf), "key%d", i + 1);
1840 val = get_param(cmd, buf);
1841 if (val == NULL)
1842 continue;
1843 snprintf(buf, sizeof(buf), "wep_key%d", i);
1844 if (set_network(ifname, id, buf, val) < 0)
1845 return -2;
1846 }
1847 }
1848
1849 return 1;
1850}
1851
1852
Jouni Malinene4fde732019-03-25 22:29:37 +02001853static int set_akm_suites(struct sigma_dut *dut, const char *ifname,
1854 int id, const char *val)
1855{
1856 char key_mgmt[200], *end, *pos;
1857 const char *in_pos = val;
1858
Jouni Malinen8179fee2019-03-28 03:19:47 +02001859 dut->akm_values = 0;
Jouni Malinene4fde732019-03-25 22:29:37 +02001860 pos = key_mgmt;
1861 end = pos + sizeof(key_mgmt);
1862 while (*in_pos) {
1863 int res, akm = atoi(in_pos);
1864 const char *str;
1865
Jouni Malinen8179fee2019-03-28 03:19:47 +02001866 if (akm >= 0 && akm < 32)
1867 dut->akm_values |= 1 << akm;
1868
Jouni Malinene4fde732019-03-25 22:29:37 +02001869 switch (akm) {
1870 case AKM_WPA_EAP:
1871 str = "WPA-EAP";
1872 break;
1873 case AKM_WPA_PSK:
1874 str = "WPA-PSK";
1875 break;
1876 case AKM_FT_EAP:
1877 str = "FT-EAP";
1878 break;
1879 case AKM_FT_PSK:
1880 str = "FT-PSK";
1881 break;
1882 case AKM_EAP_SHA256:
1883 str = "WPA-EAP-SHA256";
1884 break;
1885 case AKM_PSK_SHA256:
1886 str = "WPA-PSK-SHA256";
1887 break;
1888 case AKM_SAE:
1889 str = "SAE";
1890 break;
1891 case AKM_FT_SAE:
1892 str = "FT-SAE";
1893 break;
1894 case AKM_SUITE_B:
1895 str = "WPA-EAP-SUITE-B-192";
1896 break;
1897 case AKM_FT_SUITE_B:
1898 str = "FT-EAP-SHA384";
1899 break;
1900 case AKM_FILS_SHA256:
1901 str = "FILS-SHA256";
1902 break;
1903 case AKM_FILS_SHA384:
1904 str = "FILS-SHA384";
1905 break;
1906 case AKM_FT_FILS_SHA256:
1907 str = "FT-FILS-SHA256";
1908 break;
1909 case AKM_FT_FILS_SHA384:
1910 str = "FT-FILS-SHA384";
1911 break;
1912 default:
1913 sigma_dut_print(dut, DUT_MSG_ERROR,
1914 "Unsupported AKMSuitetype %d", akm);
1915 return -1;
1916 }
1917
1918 res = snprintf(pos, end - pos, "%s%s",
1919 pos == key_mgmt ? "" : " ", str);
1920 if (res < 0 || res >= end - pos)
1921 return -1;
1922 pos += res;
1923
1924 in_pos = strchr(in_pos, ';');
1925 if (!in_pos)
1926 break;
1927 while (*in_pos == ';')
1928 in_pos++;
1929 }
1930 sigma_dut_print(dut, DUT_MSG_DEBUG, "AKMSuiteType %s --> %s",
1931 val, key_mgmt);
1932 return set_network(ifname, id, "key_mgmt", key_mgmt);
1933}
1934
1935
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001936static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1937 const char *ifname, struct sigma_cmd *cmd)
1938{
1939 const char *val;
1940 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001941 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001942 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301943 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001944
1945 id = add_network_common(dut, conn, ifname, cmd);
1946 if (id < 0)
1947 return id;
1948
Jouni Malinen47dcc952017-10-09 16:43:24 +03001949 val = get_param(cmd, "Type");
1950 owe = val && strcasecmp(val, "OWE") == 0;
1951
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001952 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001953 if (!val && owe)
1954 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001955 if (val == NULL) {
Jouni Malinene4fde732019-03-25 22:29:37 +02001956 /* keyMgmtType is being replaced with AKMSuiteType, so ignore
1957 * this missing parameter and assume proto=WPA2. */
1958 if (set_network(ifname, id, "proto", "WPA2") < 0)
1959 return ERROR_SEND_STATUS;
1960 } else if (strcasecmp(val, "wpa") == 0 ||
1961 strcasecmp(val, "wpa-psk") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001962 if (set_network(ifname, id, "proto", "WPA") < 0)
1963 return -2;
1964 } else if (strcasecmp(val, "wpa2") == 0 ||
1965 strcasecmp(val, "wpa2-psk") == 0 ||
1966 strcasecmp(val, "wpa2-ft") == 0 ||
1967 strcasecmp(val, "wpa2-sha256") == 0) {
1968 if (set_network(ifname, id, "proto", "WPA2") < 0)
1969 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301970 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1971 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001972 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1973 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001974 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301975 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001976 if (set_network(ifname, id, "proto", "WPA2") < 0)
1977 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001978 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001979 } else {
1980 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1981 return 0;
1982 }
1983
1984 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001985 if (val) {
1986 cipher_set = 1;
1987 if (strcasecmp(val, "tkip") == 0) {
1988 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1989 return -2;
1990 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1991 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1992 return -2;
1993 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1994 if (set_network(ifname, id, "pairwise",
1995 "CCMP TKIP") < 0)
1996 return -2;
1997 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1998 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1999 return -2;
2000 if (set_network(ifname, id, "group", "GCMP") < 0)
2001 return -2;
2002 } else {
2003 send_resp(dut, conn, SIGMA_ERROR,
2004 "errorCode,Unrecognized encpType value");
2005 return 0;
2006 }
2007 }
2008
2009 val = get_param(cmd, "PairwiseCipher");
2010 if (val) {
2011 cipher_set = 1;
2012 /* TODO: Support space separated list */
2013 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2014 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
2015 return -2;
2016 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2017 if (set_network(ifname, id, "pairwise",
2018 "CCMP-256") < 0)
2019 return -2;
2020 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2021 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
2022 return -2;
2023 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2024 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
2025 return -2;
2026 } else {
2027 send_resp(dut, conn, SIGMA_ERROR,
2028 "errorCode,Unrecognized PairwiseCipher value");
2029 return 0;
2030 }
2031 }
2032
Jouni Malinen47dcc952017-10-09 16:43:24 +03002033 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03002034 send_resp(dut, conn, SIGMA_ERROR,
2035 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002036 return 0;
2037 }
Jouni Malinenad395a22017-09-01 21:13:46 +03002038
2039 val = get_param(cmd, "GroupCipher");
2040 if (val) {
2041 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2042 if (set_network(ifname, id, "group", "GCMP-256") < 0)
2043 return -2;
2044 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2045 if (set_network(ifname, id, "group", "CCMP-256") < 0)
2046 return -2;
2047 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2048 if (set_network(ifname, id, "group", "GCMP") < 0)
2049 return -2;
2050 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2051 if (set_network(ifname, id, "group", "CCMP") < 0)
2052 return -2;
2053 } else {
2054 send_resp(dut, conn, SIGMA_ERROR,
2055 "errorCode,Unrecognized GroupCipher value");
2056 return 0;
2057 }
2058 }
2059
Jouni Malinen7b239522017-09-14 21:37:18 +03002060 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03002061 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03002062 const char *cipher;
2063
2064 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
2065 cipher = "BIP-GMAC-256";
2066 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
2067 cipher = "BIP-CMAC-256";
2068 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
2069 cipher = "BIP-GMAC-128";
2070 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
2071 cipher = "AES-128-CMAC";
2072 } else {
2073 send_resp(dut, conn, SIGMA_INVALID,
2074 "errorCode,Unsupported GroupMgntCipher");
2075 return 0;
2076 }
2077 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
2078 send_resp(dut, conn, SIGMA_INVALID,
2079 "errorCode,Failed to set GroupMgntCipher");
2080 return 0;
2081 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002082 }
2083
Jouni Malinene4fde732019-03-25 22:29:37 +02002084 val = get_param(cmd, "AKMSuiteType");
2085 if (val && set_akm_suites(dut, ifname, id, val) < 0)
2086 return ERROR_SEND_STATUS;
2087
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002088 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302089
2090 if (dut->program == PROGRAM_OCE) {
2091 dut->sta_pmf = STA_PMF_OPTIONAL;
2092 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2093 return -2;
2094 }
2095
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002096 val = get_param(cmd, "PMF");
2097 if (val) {
2098 if (strcasecmp(val, "Required") == 0 ||
2099 strcasecmp(val, "Forced_Required") == 0) {
2100 dut->sta_pmf = STA_PMF_REQUIRED;
2101 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2102 return -2;
2103 } else if (strcasecmp(val, "Optional") == 0) {
2104 dut->sta_pmf = STA_PMF_OPTIONAL;
2105 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2106 return -2;
2107 } else if (strcasecmp(val, "Disabled") == 0 ||
Kiran Kumar Lokere07da3b22018-12-16 22:42:49 -08002108 strcasecmp(val, "Disable") == 0 ||
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002109 strcasecmp(val, "Forced_Disabled") == 0) {
2110 dut->sta_pmf = STA_PMF_DISABLED;
2111 } else {
2112 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
2113 return 0;
2114 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05302115 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02002116 dut->sta_pmf = STA_PMF_REQUIRED;
2117 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2118 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002119 }
2120
Jouni Malinen0165c7f2020-03-26 11:51:58 +02002121 val = get_param(cmd, "BeaconProtection");
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05302122 if (val)
2123 dut->beacon_prot = atoi(val);
2124 if (dut->beacon_prot && set_network(ifname, id, "beacon_prot", "1") < 0)
Jouni Malinen0165c7f2020-03-26 11:51:58 +02002125 return ERROR_SEND_STATUS;
2126
Veerendranath Jakkam54fd51c2020-12-21 01:36:04 +05302127 if (dut->ocvc && set_network(ifname, id, "ocv", "1") < 0)
2128 return ERROR_SEND_STATUS;
2129
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002130 return id;
2131}
2132
2133
Jouni Malinenf7222712019-06-13 01:50:21 +03002134static enum sigma_cmd_result cmd_sta_set_psk(struct sigma_dut *dut,
2135 struct sigma_conn *conn,
2136 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002137{
2138 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002139 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002140 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002141 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002142 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002143 const char *ifname, *val, *alg;
2144 int id;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002145 char buf[50];
Jouni Malinen11e55212019-11-22 21:46:59 +02002146 int sae_pwe = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002147
2148 if (intf == NULL)
2149 return -1;
2150
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002151 if (strcmp(intf, get_main_ifname(dut)) == 0)
2152 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002153 else
2154 ifname = intf;
2155
2156 id = set_wpa_common(dut, conn, ifname, cmd);
2157 if (id < 0)
2158 return id;
2159
2160 val = get_param(cmd, "keyMgmtType");
2161 alg = get_param(cmd, "micAlg");
2162
Jouni Malinen992a81e2017-08-22 13:57:47 +03002163 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002164 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002165 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2166 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002167 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002168 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2169 return -2;
2170 }
2171 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2172 sigma_dut_print(dut, DUT_MSG_ERROR,
2173 "Failed to clear sae_groups to default");
2174 return -2;
2175 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002176 if (!pmf) {
2177 dut->sta_pmf = STA_PMF_REQUIRED;
2178 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2179 return -2;
2180 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002181 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2182 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2183 if (set_network(ifname, id, "key_mgmt",
2184 "FT-SAE FT-PSK") < 0)
2185 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002186 } else if (!akm) {
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002187 if (set_network(ifname, id, "key_mgmt",
2188 "SAE WPA-PSK") < 0)
2189 return -2;
2190 }
2191 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2192 sigma_dut_print(dut, DUT_MSG_ERROR,
2193 "Failed to clear sae_groups to default");
2194 return -2;
2195 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002196 if (!pmf) {
2197 dut->sta_pmf = STA_PMF_OPTIONAL;
2198 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2199 return -2;
2200 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002201 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002202 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2203 return -2;
2204 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2205 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2206 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302207 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2208 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2209 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002210 } else if (!akm &&
2211 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2212 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002213 if (set_network(ifname, id, "key_mgmt",
2214 "WPA-PSK WPA-PSK-SHA256") < 0)
2215 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002216 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002217 if (set_network(ifname, id, "key_mgmt",
2218 "WPA-PSK WPA-PSK-SHA256") < 0)
2219 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002220 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002221 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2222 return -2;
2223 }
2224
2225 val = get_param(cmd, "passPhrase");
2226 if (val == NULL)
2227 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002228 if (type && strcasecmp(type, "SAE") == 0) {
2229 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2230 return -2;
2231 } else {
2232 if (set_network_quoted(ifname, id, "psk", val) < 0)
2233 return -2;
2234 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002235
Jouni Malinen78d10c42019-03-25 22:34:32 +02002236 val = get_param(cmd, "PasswordId");
2237 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2238 return ERROR_SEND_STATUS;
2239
Jouni Malinen992a81e2017-08-22 13:57:47 +03002240 val = get_param(cmd, "ECGroupID");
2241 if (val) {
Jouni Malinenb54f0df2019-12-12 01:57:29 +02002242 snprintf(buf, sizeof(buf), "SET sae_groups %s", val);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002243 if (wpa_command(ifname, buf) != 0) {
2244 sigma_dut_print(dut, DUT_MSG_ERROR,
2245 "Failed to clear sae_groups");
2246 return -2;
2247 }
2248 }
2249
Jouni Malinen68143132017-09-02 02:34:08 +03002250 val = get_param(cmd, "InvalidSAEElement");
2251 if (val) {
2252 free(dut->sae_commit_override);
2253 dut->sae_commit_override = strdup(val);
2254 }
2255
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002256 val = get_param(cmd, "PMKID_Include");
2257 if (val) {
2258 snprintf(buf, sizeof(buf), "SET sae_pmkid_in_assoc %d",
2259 get_enable_disable(val));
2260 wpa_command(intf, buf);
2261 }
2262
Jouni Malineneeb43d32019-12-06 17:40:07 +02002263 val = get_param(cmd, "IgnoreH2E_RSNXE_BSSMemSel");
2264 if (val) {
2265 snprintf(buf, sizeof(buf), "SET ignore_sae_h2e_only %d",
2266 get_enable_disable(val));
2267 wpa_command(intf, buf);
2268 }
2269
Jouni Malinenf2348d22019-12-07 11:52:55 +02002270 val = get_param(cmd, "ECGroupID_RGE");
2271 if (val) {
2272 snprintf(buf, sizeof(buf), "SET extra_sae_rejected_groups %s",
2273 val);
2274 wpa_command(intf, buf);
2275 }
2276
Jouni Malinen99e55022019-12-07 13:59:41 +02002277 val = get_param(cmd, "RSNXE_Content");
2278 if (val) {
2279 const char *param;
2280
2281 if (strncasecmp(val, "AssocReq:", 9) == 0) {
2282 val += 9;
2283 param = "rsnxe_override_assoc";
2284 } else if (strncasecmp(val, "EapolM2:", 8) == 0) {
2285 val += 8;
2286 param = "rsnxe_override_eapol";
2287 } else {
2288 send_resp(dut, conn, SIGMA_ERROR,
2289 "errorCode,Unsupported RSNXE_Content value");
2290 return STATUS_SENT_ERROR;
2291 }
2292 snprintf(buf, sizeof(buf), "SET %s %s", param, val);
2293 wpa_command(intf, buf);
2294 }
2295
Jouni Malinen11e55212019-11-22 21:46:59 +02002296 val = get_param(cmd, "sae_pwe");
2297 if (val) {
2298 if (strcasecmp(val, "h2e") == 0) {
2299 dut->sae_pwe = SAE_PWE_H2E;
Jouni Malinen7244a412019-12-07 11:54:10 +02002300 } else if (strcasecmp(val, "loop") == 0 ||
2301 strcasecmp(val, "looping") == 0) {
Jouni Malinen11e55212019-11-22 21:46:59 +02002302 dut->sae_pwe = SAE_PWE_LOOP;
2303 } else {
2304 send_resp(dut, conn, SIGMA_ERROR,
2305 "errorCode,Unsupported sae_pwe value");
2306 return STATUS_SENT_ERROR;
2307 }
2308 }
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302309
2310 val = get_param(cmd, "Clear_RSNXE");
2311 if (val && strcmp(val, "1") == 0 &&
2312 (wpa_command(intf, "SET rsnxe_override_assoc ") ||
2313 wpa_command(intf, "SET rsnxe_override_eapol "))) {
2314 send_resp(dut, conn, SIGMA_ERROR,
2315 "errorCode,Failed to clear RSNXE");
Jouni Malinenb11498c2020-08-03 11:05:53 +03002316 return STATUS_SENT_ERROR;
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302317 }
2318
Jouni Malinenc0078772020-03-04 21:23:16 +02002319 if (dut->sae_pwe == SAE_PWE_LOOP && get_param(cmd, "PasswordId"))
2320 sae_pwe = 3;
2321 else if (dut->sae_pwe == SAE_PWE_LOOP)
Jouni Malinen11e55212019-11-22 21:46:59 +02002322 sae_pwe = 0;
2323 else if (dut->sae_pwe == SAE_PWE_H2E)
2324 sae_pwe = 1;
2325 else if (dut->sae_h2e_default)
2326 sae_pwe = 2;
2327 snprintf(buf, sizeof(buf), "SET sae_pwe %d", sae_pwe);
2328 if (sae_pwe >= 0 && wpa_command(ifname, buf) != 0)
2329 return ERROR_SEND_STATUS;
2330
Veerendranath Jakkam0316be12020-06-23 20:11:41 +05302331 val = get_param(cmd, "sae_pk");
2332 if (val && strcmp(val, "0") == 0 &&
2333 set_network(ifname, id, "sae_pk", "2") < 0)
2334 return ERROR_SEND_STATUS;
2335
Veerendranath Jakkama9177042020-08-10 00:14:03 +05302336 val = get_param(cmd, "sae_pk_only");
2337 if (val && strcmp(val, "1") == 0 &&
2338 set_network(ifname, id, "sae_pk", "1") < 0)
2339 return ERROR_SEND_STATUS;
2340
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002341 if (dut->program == PROGRAM_60GHZ && network_mode &&
2342 strcasecmp(network_mode, "PBSS") == 0 &&
2343 set_network(ifname, id, "pbss", "1") < 0)
2344 return -2;
2345
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002346 return 1;
2347}
2348
2349
Jouni Malinen8ac93452019-08-14 15:19:13 +03002350static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2351 struct sigma_conn *conn,
2352 const char *ifname, int id)
2353{
2354 char buf[200];
2355
2356 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2357 if (!file_exists(buf))
2358 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2359 if (!file_exists(buf))
2360 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2361 if (!file_exists(buf)) {
2362 char msg[300];
2363
2364 snprintf(msg, sizeof(msg),
2365 "ErrorCode,trustedRootCA system store (%s) not found",
2366 buf);
2367 send_resp(dut, conn, SIGMA_ERROR, msg);
2368 return STATUS_SENT_ERROR;
2369 }
2370
2371 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2372 return ERROR_SEND_STATUS;
2373
2374 return SUCCESS_SEND_STATUS;
2375}
2376
2377
2378static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2379 struct sigma_conn *conn,
2380 const char *ifname, int id,
2381 const char *val)
2382{
2383 char buf[200];
2384#ifdef ANDROID
2385 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2386 int length;
2387#endif /* ANDROID */
2388
2389 if (strcmp(val, "DEFAULT") == 0)
2390 return set_trust_root_system(dut, conn, ifname, id);
2391
2392#ifdef ANDROID
2393 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2394 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2395 if (length > 0) {
2396 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2397 buf);
2398 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2399 goto ca_cert_selected;
2400 }
2401#endif /* ANDROID */
2402
2403 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2404#ifdef __linux__
2405 if (!file_exists(buf)) {
2406 char msg[300];
2407
2408 snprintf(msg, sizeof(msg),
2409 "ErrorCode,trustedRootCA file (%s) not found", buf);
2410 send_resp(dut, conn, SIGMA_ERROR, msg);
2411 return STATUS_SENT_ERROR;
2412 }
2413#endif /* __linux__ */
2414#ifdef ANDROID
2415ca_cert_selected:
2416#endif /* ANDROID */
2417 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2418 return ERROR_SEND_STATUS;
2419
2420 return SUCCESS_SEND_STATUS;
2421}
2422
2423
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002424static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302425 const char *ifname, int username_identity,
2426 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002427{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002428 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002429 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002430 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002431 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002432 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002433
2434 id = set_wpa_common(dut, conn, ifname, cmd);
2435 if (id < 0)
2436 return id;
2437
2438 val = get_param(cmd, "keyMgmtType");
2439 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302440 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002441 trust_root = get_param(cmd, "trustedRootCA");
2442 domain = get_param(cmd, "Domain");
2443 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002444
Jouni Malinenad395a22017-09-01 21:13:46 +03002445 if (val && strcasecmp(val, "SuiteB") == 0) {
2446 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2447 0)
2448 return -2;
2449 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002450 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2451 return -2;
2452 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2453 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2454 return -2;
2455 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2456 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2457 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002458 } else if (!akm &&
2459 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2460 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002461 if (set_network(ifname, id, "key_mgmt",
2462 "WPA-EAP WPA-EAP-SHA256") < 0)
2463 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302464 } else if (akm && atoi(akm) == 14) {
2465 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2466 dut->sta_pmf == STA_PMF_REQUIRED) {
2467 if (set_network(ifname, id, "key_mgmt",
2468 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2469 return -2;
2470 } else {
2471 if (set_network(ifname, id, "key_mgmt",
2472 "WPA-EAP FILS-SHA256") < 0)
2473 return -2;
2474 }
2475
Jouni Malinen8179fee2019-03-28 03:19:47 +02002476 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302477 } else if (akm && atoi(akm) == 15) {
2478 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2479 dut->sta_pmf == STA_PMF_REQUIRED) {
2480 if (set_network(ifname, id, "key_mgmt",
2481 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2482 return -2;
2483 } else {
2484 if (set_network(ifname, id, "key_mgmt",
2485 "WPA-EAP FILS-SHA384") < 0)
2486 return -2;
2487 }
2488
Jouni Malinen8179fee2019-03-28 03:19:47 +02002489 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002490 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002491 if (set_network(ifname, id, "key_mgmt",
2492 "WPA-EAP WPA-EAP-SHA256") < 0)
2493 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002494 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002495 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2496 return -2;
2497 }
2498
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002499 if (trust_root) {
2500 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2501 !domain_suffix) {
2502 send_resp(dut, conn, SIGMA_ERROR,
2503 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2504 return STATUS_SENT_ERROR;
2505 }
2506 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002507 if (res != SUCCESS_SEND_STATUS)
2508 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002509 }
2510
Jouni Malinen53264f62019-05-03 13:04:40 +03002511 val = get_param(cmd, "ServerCert");
2512 if (val) {
2513 FILE *f;
2514 char *result = NULL, *pos;
2515
2516 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2517 val);
2518 f = fopen(buf, "r");
2519 if (f) {
2520 result = fgets(buf, sizeof(buf), f);
2521 fclose(f);
2522 }
2523 if (!result) {
2524 snprintf(buf2, sizeof(buf2),
2525 "ErrorCode,ServerCert hash could not be read from %s",
2526 buf);
2527 send_resp(dut, conn, SIGMA_ERROR, buf2);
2528 return STATUS_SENT_ERROR;
2529 }
2530 pos = strchr(buf, '\n');
2531 if (pos)
2532 *pos = '\0';
Jouni Malinen0572a742020-10-08 13:53:25 +03002533 pos = strchr(buf, '\r');
2534 if (pos)
2535 *pos = '\0';
Jouni Malinen53264f62019-05-03 13:04:40 +03002536 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2537 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2538 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002539
2540 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2541 if (file_exists(buf)) {
2542 sigma_dut_print(dut, DUT_MSG_DEBUG,
2543 "TOD policy enabled for the configured ServerCert hash");
2544 dut->sta_tod_policy = 1;
2545 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002546 }
2547
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002548 if (domain &&
2549 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002550 return ERROR_SEND_STATUS;
2551
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002552 if (domain_suffix &&
2553 set_network_quoted(ifname, id, "domain_suffix_match",
2554 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002555 return ERROR_SEND_STATUS;
2556
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302557 if (username_identity) {
2558 val = get_param(cmd, "username");
2559 if (val) {
2560 if (set_network_quoted(ifname, id, "identity", val) < 0)
2561 return -2;
2562 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002563
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302564 val = get_param(cmd, "password");
2565 if (val) {
2566 if (set_network_quoted(ifname, id, "password", val) < 0)
2567 return -2;
2568 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002569 }
2570
Jouni Malinen8179fee2019-03-28 03:19:47 +02002571 if (dut->akm_values &
2572 ((1 << AKM_FILS_SHA256) |
2573 (1 << AKM_FILS_SHA384) |
2574 (1 << AKM_FT_FILS_SHA256) |
2575 (1 << AKM_FT_FILS_SHA384)))
2576 erp = 1;
2577 if (erp && set_network(ifname, id, "erp", "1") < 0)
2578 return ERROR_SEND_STATUS;
2579
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002580 dut->sta_associate_wait_connect = 1;
2581
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002582 return id;
2583}
2584
2585
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002586static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2587{
2588 const char *val;
2589
2590 if (!cipher)
2591 return 0;
2592
2593 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2594 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2595 else if (strcasecmp(cipher,
2596 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2597 val = "ECDHE-RSA-AES256-GCM-SHA384";
2598 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2599 val = "DHE-RSA-AES256-GCM-SHA384";
2600 else if (strcasecmp(cipher,
2601 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2602 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2603 else
2604 return -1;
2605
2606 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2607 set_network_quoted(ifname, id, "phase1", "");
2608
2609 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2610}
2611
2612
Jouni Malinenf7222712019-06-13 01:50:21 +03002613static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2614 struct sigma_conn *conn,
2615 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002616{
2617 const char *intf = get_param(cmd, "Interface");
2618 const char *ifname, *val;
2619 int id;
2620 char buf[200];
2621#ifdef ANDROID
2622 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2623 int length;
2624 int jb_or_newer = 0;
2625 char prop[PROPERTY_VALUE_MAX];
2626#endif /* ANDROID */
2627
2628 if (intf == NULL)
2629 return -1;
2630
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002631 if (strcmp(intf, get_main_ifname(dut)) == 0)
2632 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002633 else
2634 ifname = intf;
2635
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302636 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002637 if (id < 0)
2638 return id;
2639
2640 if (set_network(ifname, id, "eap", "TLS") < 0)
2641 return -2;
2642
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302643 if (!get_param(cmd, "username") &&
2644 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002645 "wifi-user@wifilabs.local") < 0)
2646 return -2;
2647
2648 val = get_param(cmd, "clientCertificate");
2649 if (val == NULL)
2650 return -1;
2651#ifdef ANDROID
2652 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2653 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2654 if (length < 0) {
2655 /*
2656 * JB started reporting keystore type mismatches, so retry with
2657 * the GET_PUBKEY command if the generic GET fails.
2658 */
2659 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2660 buf, kvalue);
2661 }
2662
2663 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2664 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2665 if (strncmp(prop, "4.0", 3) != 0)
2666 jb_or_newer = 1;
2667 } else
2668 jb_or_newer = 1; /* assume newer */
2669
2670 if (jb_or_newer && length > 0) {
2671 sigma_dut_print(dut, DUT_MSG_INFO,
2672 "Use Android keystore [%s]", buf);
2673 if (set_network(ifname, id, "engine", "1") < 0)
2674 return -2;
2675 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2676 return -2;
2677 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2678 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2679 return -2;
2680 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2681 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2682 return -2;
2683 return 1;
2684 } else if (length > 0) {
2685 sigma_dut_print(dut, DUT_MSG_INFO,
2686 "Use Android keystore [%s]", buf);
2687 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2688 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2689 return -2;
2690 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2691 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2692 return -2;
2693 return 1;
2694 }
2695#endif /* ANDROID */
2696
2697 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2698#ifdef __linux__
2699 if (!file_exists(buf)) {
2700 char msg[300];
2701 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2702 "(%s) not found", buf);
2703 send_resp(dut, conn, SIGMA_ERROR, msg);
2704 return -3;
2705 }
2706#endif /* __linux__ */
2707 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2708 return -2;
2709 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2710 return -2;
2711
2712 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2713 return -2;
2714
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002715 val = get_param(cmd, "keyMgmtType");
2716 if (val && strcasecmp(val, "SuiteB") == 0) {
2717 val = get_param(cmd, "CertType");
2718 if (val && strcasecmp(val, "RSA") == 0) {
2719 if (set_network_quoted(ifname, id, "phase1",
2720 "tls_suiteb=1") < 0)
2721 return -2;
2722 } else {
2723 if (set_network_quoted(ifname, id, "openssl_ciphers",
2724 "SUITEB192") < 0)
2725 return -2;
2726 }
2727
2728 val = get_param(cmd, "TLSCipher");
2729 if (set_tls_cipher(ifname, id, val) < 0) {
2730 send_resp(dut, conn, SIGMA_ERROR,
2731 "ErrorCode,Unsupported TLSCipher value");
2732 return -3;
2733 }
2734 }
2735
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002736 return 1;
2737}
2738
2739
Jouni Malinenf7222712019-06-13 01:50:21 +03002740static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2741 struct sigma_conn *conn,
2742 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002743{
2744 const char *intf = get_param(cmd, "Interface");
2745 const char *ifname;
2746 int id;
2747
2748 if (intf == NULL)
2749 return -1;
2750
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002751 if (strcmp(intf, get_main_ifname(dut)) == 0)
2752 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002753 else
2754 ifname = intf;
2755
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302756 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002757 if (id < 0)
2758 return id;
2759
2760 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2761 send_resp(dut, conn, SIGMA_ERROR,
2762 "errorCode,Failed to set TTLS method");
2763 return 0;
2764 }
2765
2766 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2767 send_resp(dut, conn, SIGMA_ERROR,
2768 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2769 return 0;
2770 }
2771
2772 return 1;
2773}
2774
2775
Jouni Malinenf7222712019-06-13 01:50:21 +03002776static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2777 struct sigma_conn *conn,
2778 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002779{
2780 const char *intf = get_param(cmd, "Interface");
2781 const char *ifname;
2782 int id;
2783
2784 if (intf == NULL)
2785 return -1;
2786
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002787 if (strcmp(intf, get_main_ifname(dut)) == 0)
2788 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002789 else
2790 ifname = intf;
2791
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302792 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002793 if (id < 0)
2794 return id;
2795
2796 if (set_network(ifname, id, "eap", "SIM") < 0)
2797 return -2;
2798
2799 return 1;
2800}
2801
2802
Jouni Malinenf7222712019-06-13 01:50:21 +03002803static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2804 struct sigma_conn *conn,
2805 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002806{
2807 const char *intf = get_param(cmd, "Interface");
2808 const char *ifname, *val;
2809 int id;
2810 char buf[100];
2811
2812 if (intf == NULL)
2813 return -1;
2814
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002815 if (strcmp(intf, get_main_ifname(dut)) == 0)
2816 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002817 else
2818 ifname = intf;
2819
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302820 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002821 if (id < 0)
2822 return id;
2823
2824 if (set_network(ifname, id, "eap", "PEAP") < 0)
2825 return -2;
2826
2827 val = get_param(cmd, "innerEAP");
2828 if (val) {
2829 if (strcasecmp(val, "MSCHAPv2") == 0) {
2830 if (set_network_quoted(ifname, id, "phase2",
2831 "auth=MSCHAPV2") < 0)
2832 return -2;
2833 } else if (strcasecmp(val, "GTC") == 0) {
2834 if (set_network_quoted(ifname, id, "phase2",
2835 "auth=GTC") < 0)
2836 return -2;
2837 } else
2838 return -1;
2839 }
2840
2841 val = get_param(cmd, "peapVersion");
2842 if (val) {
2843 int ver = atoi(val);
2844 if (ver < 0 || ver > 1)
2845 return -1;
2846 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2847 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2848 return -2;
2849 }
2850
2851 return 1;
2852}
2853
2854
Jouni Malinenf7222712019-06-13 01:50:21 +03002855static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2856 struct sigma_conn *conn,
2857 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002858{
2859 const char *intf = get_param(cmd, "Interface");
2860 const char *ifname, *val;
2861 int id;
2862 char buf[100];
2863
2864 if (intf == NULL)
2865 return -1;
2866
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002867 if (strcmp(intf, get_main_ifname(dut)) == 0)
2868 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002869 else
2870 ifname = intf;
2871
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302872 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002873 if (id < 0)
2874 return id;
2875
2876 if (set_network(ifname, id, "eap", "FAST") < 0)
2877 return -2;
2878
2879 val = get_param(cmd, "innerEAP");
2880 if (val) {
2881 if (strcasecmp(val, "MSCHAPV2") == 0) {
2882 if (set_network_quoted(ifname, id, "phase2",
2883 "auth=MSCHAPV2") < 0)
2884 return -2;
2885 } else if (strcasecmp(val, "GTC") == 0) {
2886 if (set_network_quoted(ifname, id, "phase2",
2887 "auth=GTC") < 0)
2888 return -2;
2889 } else
2890 return -1;
2891 }
2892
2893 val = get_param(cmd, "validateServer");
2894 if (val) {
2895 /* TODO */
2896 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2897 "validateServer=%s", val);
2898 }
2899
2900 val = get_param(cmd, "pacFile");
2901 if (val) {
2902 snprintf(buf, sizeof(buf), "blob://%s", val);
2903 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2904 return -2;
2905 }
2906
2907 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2908 0)
2909 return -2;
2910
2911 return 1;
2912}
2913
2914
Jouni Malinenf7222712019-06-13 01:50:21 +03002915static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2916 struct sigma_conn *conn,
2917 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002918{
2919 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302920 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002921 const char *ifname;
2922 int id;
2923
2924 if (intf == NULL)
2925 return -1;
2926
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002927 if (strcmp(intf, get_main_ifname(dut)) == 0)
2928 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002929 else
2930 ifname = intf;
2931
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302932 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002933 if (id < 0)
2934 return id;
2935
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302936 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2937 * hexadecimal).
2938 */
2939 if (username && username[0] == '6') {
2940 if (set_network(ifname, id, "eap", "AKA'") < 0)
2941 return -2;
2942 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002943 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302944 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002945
2946 return 1;
2947}
2948
2949
Jouni Malinenf7222712019-06-13 01:50:21 +03002950static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2951 struct sigma_conn *conn,
2952 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002953{
2954 const char *intf = get_param(cmd, "Interface");
2955 const char *ifname;
2956 int id;
2957
2958 if (intf == NULL)
2959 return -1;
2960
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002961 if (strcmp(intf, get_main_ifname(dut)) == 0)
2962 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002963 else
2964 ifname = intf;
2965
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302966 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002967 if (id < 0)
2968 return id;
2969
2970 if (set_network(ifname, id, "eap", "AKA'") < 0)
2971 return -2;
2972
2973 return 1;
2974}
2975
2976
2977static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2978 struct sigma_cmd *cmd)
2979{
2980 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002981 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002982 const char *ifname;
2983 int id;
2984
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002985 if (strcmp(intf, get_main_ifname(dut)) == 0)
2986 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002987 else
2988 ifname = intf;
2989
2990 id = add_network_common(dut, conn, ifname, cmd);
2991 if (id < 0)
2992 return id;
2993
2994 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2995 return -2;
2996
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002997 if (dut->program == PROGRAM_60GHZ && network_mode &&
2998 strcasecmp(network_mode, "PBSS") == 0 &&
2999 set_network(ifname, id, "pbss", "1") < 0)
3000 return -2;
3001
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003002 return 1;
3003}
3004
3005
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003006static enum sigma_cmd_result sta_set_owe(struct sigma_dut *dut,
3007 struct sigma_conn *conn,
3008 struct sigma_cmd *cmd)
Jouni Malinen47dcc952017-10-09 16:43:24 +03003009{
3010 const char *intf = get_param(cmd, "Interface");
3011 const char *ifname, *val;
3012 int id;
3013
3014 if (intf == NULL)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003015 return INVALID_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003016
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003017 if (strcmp(intf, get_main_ifname(dut)) == 0)
3018 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003019 else
3020 ifname = intf;
3021
3022 id = set_wpa_common(dut, conn, ifname, cmd);
3023 if (id < 0)
3024 return id;
3025
3026 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003027 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003028
Hu Wangdd5eed22020-07-16 12:18:03 +08003029 if (dut->owe_ptk_workaround &&
3030 set_network(ifname, id, "owe_ptk_workaround", "1") < 0) {
3031 sigma_dut_print(dut, DUT_MSG_ERROR,
3032 "Failed to set owe_ptk_workaround to 1");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003033 return ERROR_SEND_STATUS;
Hu Wangdd5eed22020-07-16 12:18:03 +08003034 }
3035
Jouni Malinen47dcc952017-10-09 16:43:24 +03003036 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003037 if (val && strcmp(val, "0") == 0) {
3038 if (wpa_command(ifname,
3039 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
3040 sigma_dut_print(dut, DUT_MSG_ERROR,
3041 "Failed to set OWE DH Param element override");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003042 return ERROR_SEND_STATUS;
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003043 }
Hu Wangdd5eed22020-07-16 12:18:03 +08003044 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003045 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003046 "Failed to set owe_group");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003047 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003048 }
3049
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003050 return SUCCESS_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003051}
3052
3053
Jouni Malinenf7222712019-06-13 01:50:21 +03003054static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3055 struct sigma_conn *conn,
3056 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003057{
3058 const char *type = get_param(cmd, "Type");
3059
3060 if (type == NULL) {
3061 send_resp(dut, conn, SIGMA_ERROR,
3062 "ErrorCode,Missing Type argument");
3063 return 0;
3064 }
3065
3066 if (strcasecmp(type, "OPEN") == 0)
3067 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003068 if (strcasecmp(type, "OWE") == 0)
3069 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003070 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003071 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003072 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003073 return cmd_sta_set_psk(dut, conn, cmd);
3074 if (strcasecmp(type, "EAPTLS") == 0)
3075 return cmd_sta_set_eaptls(dut, conn, cmd);
3076 if (strcasecmp(type, "EAPTTLS") == 0)
3077 return cmd_sta_set_eapttls(dut, conn, cmd);
3078 if (strcasecmp(type, "EAPPEAP") == 0)
3079 return cmd_sta_set_peap(dut, conn, cmd);
3080 if (strcasecmp(type, "EAPSIM") == 0)
3081 return cmd_sta_set_eapsim(dut, conn, cmd);
3082 if (strcasecmp(type, "EAPFAST") == 0)
3083 return cmd_sta_set_eapfast(dut, conn, cmd);
3084 if (strcasecmp(type, "EAPAKA") == 0)
3085 return cmd_sta_set_eapaka(dut, conn, cmd);
3086 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3087 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003088 if (strcasecmp(type, "wep") == 0)
3089 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003090
3091 send_resp(dut, conn, SIGMA_ERROR,
3092 "ErrorCode,Unsupported Type value");
3093 return 0;
3094}
3095
3096
3097int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3098{
3099#ifdef __linux__
3100 /* special handling for ath6kl */
3101 char path[128], fname[128], *pos;
3102 ssize_t res;
3103 FILE *f;
3104
Jouni Malinene39cd562019-05-29 23:39:56 +03003105 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3106 intf);
3107 if (res < 0 || res >= sizeof(fname))
3108 return 0;
3109 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003110 if (res < 0)
3111 return 0; /* not ath6kl */
3112
3113 if (res >= (int) sizeof(path))
3114 res = sizeof(path) - 1;
3115 path[res] = '\0';
3116 pos = strrchr(path, '/');
3117 if (pos == NULL)
3118 pos = path;
3119 else
3120 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003121 res = snprintf(fname, sizeof(fname),
3122 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3123 "create_qos", pos);
3124 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003125 return 0; /* not ath6kl */
3126
3127 if (uapsd) {
3128 f = fopen(fname, "w");
3129 if (f == NULL)
3130 return -1;
3131
3132 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3133 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3134 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3135 "20000 0\n");
3136 fclose(f);
3137 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003138 res = snprintf(fname, sizeof(fname),
3139 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3140 "delete_qos", pos);
3141 if (res < 0 || res >= sizeof(fname))
3142 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003143
3144 f = fopen(fname, "w");
3145 if (f == NULL)
3146 return -1;
3147
3148 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3149 fprintf(f, "2 4\n");
3150 fclose(f);
3151 }
3152#endif /* __linux__ */
3153
3154 return 0;
3155}
3156
3157
Jouni Malinenf7222712019-06-13 01:50:21 +03003158static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3159 struct sigma_conn *conn,
3160 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003161{
3162 const char *intf = get_param(cmd, "Interface");
3163 /* const char *ssid = get_param(cmd, "ssid"); */
3164 const char *val;
3165 int max_sp_len = 4;
3166 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3167 char buf[100];
3168 int ret1, ret2;
3169
3170 val = get_param(cmd, "maxSPLength");
3171 if (val) {
3172 max_sp_len = atoi(val);
3173 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3174 max_sp_len != 4)
3175 return -1;
3176 }
3177
3178 val = get_param(cmd, "acBE");
3179 if (val)
3180 ac_be = atoi(val);
3181
3182 val = get_param(cmd, "acBK");
3183 if (val)
3184 ac_bk = atoi(val);
3185
3186 val = get_param(cmd, "acVI");
3187 if (val)
3188 ac_vi = atoi(val);
3189
3190 val = get_param(cmd, "acVO");
3191 if (val)
3192 ac_vo = atoi(val);
3193
3194 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3195
3196 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3197 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3198 ret1 = wpa_command(intf, buf);
3199
3200 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3201 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3202 ret2 = wpa_command(intf, buf);
3203
3204 if (ret1 && ret2) {
3205 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3206 "UAPSD parameters.");
3207 return -2;
3208 }
3209
3210 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3211 send_resp(dut, conn, SIGMA_ERROR,
3212 "ErrorCode,Failed to set ath6kl QoS parameters");
3213 return 0;
3214 }
3215
3216 return 1;
3217}
3218
3219
Jouni Malinenf7222712019-06-13 01:50:21 +03003220static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3221 struct sigma_conn *conn,
3222 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003223{
3224 char buf[1000];
3225 const char *intf = get_param(cmd, "Interface");
3226 const char *grp = get_param(cmd, "Group");
3227 const char *act = get_param(cmd, "Action");
3228 const char *tid = get_param(cmd, "Tid");
3229 const char *dir = get_param(cmd, "Direction");
3230 const char *psb = get_param(cmd, "Psb");
3231 const char *up = get_param(cmd, "Up");
3232 const char *fixed = get_param(cmd, "Fixed");
3233 const char *size = get_param(cmd, "Size");
3234 const char *msize = get_param(cmd, "Maxsize");
3235 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3236 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3237 const char *inact = get_param(cmd, "Inactivity");
3238 const char *sus = get_param(cmd, "Suspension");
3239 const char *mindr = get_param(cmd, "Mindatarate");
3240 const char *meandr = get_param(cmd, "Meandatarate");
3241 const char *peakdr = get_param(cmd, "Peakdatarate");
3242 const char *phyrate = get_param(cmd, "Phyrate");
3243 const char *burstsize = get_param(cmd, "Burstsize");
3244 const char *sba = get_param(cmd, "Sba");
3245 int direction;
3246 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003247 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003248 int fixed_int;
3249 int psb_ts;
3250
3251 if (intf == NULL || grp == NULL || act == NULL )
3252 return -1;
3253
3254 if (strcasecmp(act, "addts") == 0) {
3255 if (tid == NULL || dir == NULL || psb == NULL ||
3256 up == NULL || fixed == NULL || size == NULL)
3257 return -1;
3258
3259 /*
3260 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3261 * possible values, but WMM-AC and V-E test scripts use "UP,
3262 * "DOWN", and "BIDI".
3263 */
3264 if (strcasecmp(dir, "uplink") == 0 ||
3265 strcasecmp(dir, "up") == 0) {
3266 direction = 0;
3267 } else if (strcasecmp(dir, "downlink") == 0 ||
3268 strcasecmp(dir, "down") == 0) {
3269 direction = 1;
3270 } else if (strcasecmp(dir, "bidi") == 0) {
3271 direction = 2;
3272 } else {
3273 sigma_dut_print(dut, DUT_MSG_ERROR,
3274 "Direction %s not supported", dir);
3275 return -1;
3276 }
3277
3278 if (strcasecmp(psb, "legacy") == 0) {
3279 psb_ts = 0;
3280 } else if (strcasecmp(psb, "uapsd") == 0) {
3281 psb_ts = 1;
3282 } else {
3283 sigma_dut_print(dut, DUT_MSG_ERROR,
3284 "PSB %s not supported", psb);
3285 return -1;
3286 }
3287
3288 if (atoi(tid) < 0 || atoi(tid) > 7) {
3289 sigma_dut_print(dut, DUT_MSG_ERROR,
3290 "TID %s not supported", tid);
3291 return -1;
3292 }
3293
3294 if (strcasecmp(fixed, "true") == 0) {
3295 fixed_int = 1;
3296 } else {
3297 fixed_int = 0;
3298 }
3299
Peng Xu93319622017-10-04 17:58:16 -07003300 if (sba)
3301 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003302
3303 dut->dialog_token++;
3304 handle = 7000 + dut->dialog_token;
3305
3306 /*
3307 * size: convert to hex
3308 * maxsi: convert to hex
3309 * mindr: convert to hex
3310 * meandr: convert to hex
3311 * peakdr: convert to hex
3312 * burstsize: convert to hex
3313 * phyrate: convert to hex
3314 * sba: convert to hex with modification
3315 * minsi: convert to integer
3316 * sus: convert to integer
3317 * inact: convert to integer
3318 * maxsi: convert to integer
3319 */
3320
3321 /*
3322 * The Nominal MSDU Size field is 2 octets long and contains an
3323 * unsigned integer that specifies the nominal size, in octets,
3324 * of MSDUs belonging to the traffic under this traffic
3325 * specification and is defined in Figure 16. If the Fixed
3326 * subfield is set to 1, then the size of the MSDU is fixed and
3327 * is indicated by the Size Subfield. If the Fixed subfield is
3328 * set to 0, then the size of the MSDU might not be fixed and
3329 * the Size indicates the nominal MSDU size.
3330 *
3331 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3332 * and specifies the excess allocation of time (and bandwidth)
3333 * over and above the stated rates required to transport an MSDU
3334 * belonging to the traffic in this TSPEC. This field is
3335 * represented as an unsigned binary number with an implicit
3336 * binary point after the leftmost 3 bits. For example, an SBA
3337 * of 1.75 is represented as 0x3800. This field is included to
3338 * account for retransmissions. As such, the value of this field
3339 * must be greater than unity.
3340 */
3341
3342 snprintf(buf, sizeof(buf),
3343 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3344 " 0x%X 0x%X 0x%X"
3345 " 0x%X 0x%X 0x%X"
3346 " 0x%X %d %d %d %d"
3347 " %d %d",
3348 intf, handle, tid, direction, psb_ts, up,
3349 (unsigned int) ((fixed_int << 15) | atoi(size)),
3350 msize ? atoi(msize) : 0,
3351 mindr ? atoi(mindr) : 0,
3352 meandr ? atoi(meandr) : 0,
3353 peakdr ? atoi(peakdr) : 0,
3354 burstsize ? atoi(burstsize) : 0,
3355 phyrate ? atoi(phyrate) : 0,
3356 sba ? ((unsigned int) (((int) sba_fv << 13) |
3357 (int)((sba_fv - (int) sba_fv) *
3358 8192))) : 0,
3359 minsi ? atoi(minsi) : 0,
3360 sus ? atoi(sus) : 0,
3361 0, 0,
3362 inact ? atoi(inact) : 0,
3363 maxsi ? atoi(maxsi) : 0);
3364
3365 if (system(buf) != 0) {
3366 sigma_dut_print(dut, DUT_MSG_ERROR,
3367 "iwpriv addtspec request failed");
3368 send_resp(dut, conn, SIGMA_ERROR,
3369 "errorCode,Failed to execute addTspec command");
3370 return 0;
3371 }
3372
3373 sigma_dut_print(dut, DUT_MSG_INFO,
3374 "iwpriv addtspec request send");
3375
3376 /* Mapping handle to a TID */
3377 dut->tid_to_handle[atoi(tid)] = handle;
3378 } else if (strcasecmp(act, "delts") == 0) {
3379 if (tid == NULL)
3380 return -1;
3381
3382 if (atoi(tid) < 0 || atoi(tid) > 7) {
3383 sigma_dut_print(dut, DUT_MSG_ERROR,
3384 "TID %s not supported", tid);
3385 send_resp(dut, conn, SIGMA_ERROR,
3386 "errorCode,Unsupported TID");
3387 return 0;
3388 }
3389
3390 handle = dut->tid_to_handle[atoi(tid)];
3391
3392 if (handle < 7000 || handle > 7255) {
3393 /* Invalid handle ie no mapping for that TID */
3394 sigma_dut_print(dut, DUT_MSG_ERROR,
3395 "handle-> %d not found", handle);
3396 }
3397
3398 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3399 intf, handle);
3400
3401 if (system(buf) != 0) {
3402 sigma_dut_print(dut, DUT_MSG_ERROR,
3403 "iwpriv deltspec request failed");
3404 send_resp(dut, conn, SIGMA_ERROR,
3405 "errorCode,Failed to execute delTspec command");
3406 return 0;
3407 }
3408
3409 sigma_dut_print(dut, DUT_MSG_INFO,
3410 "iwpriv deltspec request send");
3411
3412 dut->tid_to_handle[atoi(tid)] = 0;
3413 } else {
3414 sigma_dut_print(dut, DUT_MSG_ERROR,
3415 "Action type %s not supported", act);
3416 send_resp(dut, conn, SIGMA_ERROR,
3417 "errorCode,Unsupported Action");
3418 return 0;
3419 }
3420
3421 return 1;
3422}
3423
3424
vamsi krishna52e16f92017-08-29 12:37:34 +05303425static int find_network(struct sigma_dut *dut, const char *ssid)
3426{
3427 char list[4096];
3428 char *pos;
3429
3430 sigma_dut_print(dut, DUT_MSG_DEBUG,
3431 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003432 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303433 list, sizeof(list)) < 0)
3434 return -1;
3435 pos = strstr(list, ssid);
3436 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3437 return -1;
3438
3439 while (pos > list && pos[-1] != '\n')
3440 pos--;
3441 dut->infra_network_id = atoi(pos);
3442 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3443 return 0;
3444}
3445
3446
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303447/**
3448 * enum qca_sta_helper_config_params - This helper enum defines the config
3449 * parameters which can be delivered to sta.
3450 */
3451enum qca_sta_helper_config_params {
3452 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE */
3453 STA_SET_RSNIE,
3454
3455 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC */
3456 STA_SET_LDPC,
3457
3458 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC */
3459 STA_SET_TX_STBC,
3460
3461 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC */
3462 STA_SET_RX_STBC,
3463
3464 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION */
3465 STA_SET_TX_MSDU,
3466
3467 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION */
3468 STA_SET_RX_MSDU,
Shivani Baranwal2a572842021-09-16 12:27:15 +05303469
3470 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_CHANNEL_WIDTH */
3471 STA_SET_CHAN_WIDTH,
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303472};
3473
3474
3475static int sta_config_params(struct sigma_dut *dut, const char *intf,
3476 enum qca_sta_helper_config_params config_cmd,
3477 int value)
Sunil Dutt44595082018-02-12 19:41:45 +05303478{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303479#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05303480 struct nl_msg *msg;
3481 int ret;
3482 struct nlattr *params;
3483 int ifindex;
3484
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303485 ifindex = if_nametoindex(intf);
3486 if (ifindex == 0) {
3487 sigma_dut_print(dut, DUT_MSG_ERROR,
3488 "%s: Interface %s does not exist",
3489 __func__, intf);
3490 return -1;
3491 }
3492
Sunil Dutt44595082018-02-12 19:41:45 +05303493 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3494 NL80211_CMD_VENDOR)) ||
3495 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3496 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3497 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3498 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303499 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)))
3500 goto fail;
3501
3502 switch (config_cmd) {
3503 case STA_SET_RSNIE:
3504 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, value))
3505 goto fail;
3506 break;
3507 case STA_SET_LDPC:
3508 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC, value))
3509 goto fail;
3510 break;
3511 case STA_SET_TX_STBC:
3512 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC, value))
3513 goto fail;
3514 break;
3515 case STA_SET_RX_STBC:
3516 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC, value))
3517 goto fail;
3518 break;
3519 case STA_SET_TX_MSDU:
3520 if (nla_put_u8(msg,
3521 QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION,
3522 value))
3523 goto fail;
3524 break;
3525 case STA_SET_RX_MSDU:
3526 if (nla_put_u8(msg,
3527 QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION,
3528 value))
3529 goto fail;
3530 break;
Shivani Baranwal2a572842021-09-16 12:27:15 +05303531 case STA_SET_CHAN_WIDTH:
3532 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_CHANNEL_WIDTH,
3533 value))
3534 goto fail;
3535 break;
Sunil Dutt44595082018-02-12 19:41:45 +05303536 }
3537 nla_nest_end(msg, params);
3538
3539 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3540 if (ret) {
3541 sigma_dut_print(dut, DUT_MSG_ERROR,
3542 "%s: err in send_and_recv_msgs, ret=%d",
3543 __func__, ret);
3544 return ret;
3545 }
3546
3547 return 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303548
3549fail:
3550 sigma_dut_print(dut, DUT_MSG_ERROR,
3551 "%s: err in adding vendor_cmd and vendor_data",
3552 __func__);
3553 nlmsg_free(msg);
Sunil Dutt44595082018-02-12 19:41:45 +05303554#endif /* NL80211_SUPPORT */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303555 return -1;
3556}
Sunil Dutt44595082018-02-12 19:41:45 +05303557
3558
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05303559void free_dscp_policy_table(struct sigma_dut *dut)
3560{
3561 struct dscp_policy_data *dscp_policy;
3562
3563 while (dut->dscp_policy_table) {
3564 dscp_policy = dut->dscp_policy_table;
3565 dut->dscp_policy_table = dscp_policy->next;
3566 free(dscp_policy);
3567 }
3568}
3569
3570
3571static int delete_nft_table(struct sigma_dut *dut, const char *table,
3572 const char *ip_type)
3573{
3574 int res;
3575 char cmd[200];
3576
3577 res = snprintf(cmd, sizeof(cmd), "nft delete table %s %s_%s", ip_type,
3578 table, ip_type);
3579 if (snprintf_error(sizeof(cmd), res)) {
3580 sigma_dut_print(dut, DUT_MSG_ERROR,
3581 "Failed to create delete table command");
3582 return -1;
3583 }
3584
3585 if (system(cmd) != 0) {
3586 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run %s", cmd);
3587 return -1;
3588 }
3589
3590 return 0;
3591}
3592
3593
3594static int remove_nft_rule(struct sigma_dut *dut, int policy_id,
3595 enum ip_version ip_ver)
3596{
3597 int res;
3598 char table[50];
3599
3600 res = snprintf(table, sizeof(table), "wifi_%s_dscp_policy_%d",
3601 dut->station_ifname, policy_id);
3602 if (snprintf_error(sizeof(table), res)) {
3603 sigma_dut_print(dut, DUT_MSG_INFO,
3604 "Failed to create table name for policy %d",
3605 policy_id);
3606 return -1;
3607 }
3608
3609
3610 if (ip_ver == IPV6)
3611 return delete_nft_table(dut, table, "ip6");
3612 else
3613 return delete_nft_table(dut, table, "ip");
3614}
3615
3616
3617static int create_nft_table(struct sigma_dut *dut, int policy_id,
3618 const char *table_name, enum ip_version ip_ver)
3619{
3620 char cmd[200];
3621 int res;
3622
3623 res = snprintf(cmd, sizeof(cmd), "nft add table %s %s",
3624 ip_ver == IPV6 ? "ip6" : "ip", table_name);
3625 if (snprintf_error(sizeof(cmd), res)) {
3626 sigma_dut_print(dut, DUT_MSG_INFO,
3627 "Failed to add rule to create table for policy id %d",
3628 policy_id);
3629 return -1;
3630 }
3631
3632 if (system(cmd) != 0) {
3633 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run %s", cmd);
3634 return -1;
3635 }
3636
3637 res = snprintf(cmd, sizeof(cmd),
3638 "nft add chain %s %s OUTPUT { type filter hook output priority 0 \\; }",
3639 ip_ver == IPV6 ? "ip6" : "ip", table_name);
3640 if (snprintf_error(sizeof(cmd), res)) {
3641 sigma_dut_print(dut, DUT_MSG_INFO,
3642 "Failed to add rule to create chain for table = %s",
3643 table_name);
3644 return -1;
3645 }
3646
3647 if (system(cmd) != 0) {
3648 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run %s", cmd);
3649 return -1;
3650 }
3651
3652 return 0;
3653}
3654
3655
3656static char * protocol_to_str(int proto)
3657{
3658 switch (proto) {
3659 case 6:
3660 return "tcp";
3661 case 17:
3662 return "udp";
3663 case 50:
3664 return "esp";
3665 default:
3666 return "unknown";
3667 }
3668}
3669
3670
3671static int remove_dscp_policy(struct sigma_dut *dut, u8 policy_id)
3672{
3673 struct dscp_policy_data *dscp_policy = dut->dscp_policy_table;
3674 struct dscp_policy_data *prev = NULL;
3675
3676 while (dscp_policy) {
3677 if (dscp_policy->policy_id == policy_id)
3678 break;
3679
3680 prev = dscp_policy;
3681 dscp_policy = dscp_policy->next;
3682 }
3683
3684 /*
3685 * Consider remove request for a policy id which does not exist as
3686 * success.
3687 */
3688 if (!dscp_policy)
3689 return 0;
3690
3691 if (strlen(dscp_policy->domain_name) == 0 &&
3692 remove_nft_rule(dut, policy_id, dscp_policy->ip_version))
3693 return -1;
3694
3695 if (prev)
3696 prev->next = dscp_policy->next;
3697 else
3698 dut->dscp_policy_table = dscp_policy->next;
3699
3700 free(dscp_policy);
3701 return 0;
3702}
3703
3704
3705static int add_nft_rule(struct sigma_dut *dut,
3706 struct dscp_policy_data *dscp_policy)
3707{
3708 char nft_cmd[1000], ip[4], table_name[100];
3709 char *pos;
3710 int ret, len, policy_id = dscp_policy->policy_id;
3711 enum ip_version ip_ver = dscp_policy->ip_version;
3712
3713 if (ip_ver == IPV6)
3714 strlcpy(ip, "ip6", sizeof(ip));
3715 else
3716 strlcpy(ip, "ip", sizeof(ip));
3717
3718 ret = snprintf(table_name, sizeof(table_name),
3719 "wifi_%s_dscp_policy_%d_%s",
3720 dut->station_ifname, policy_id, ip);
3721 if (snprintf_error(sizeof(table_name), ret))
3722 return -1;
3723
3724 if (create_nft_table(dut, policy_id, table_name, ip_ver)) {
3725 sigma_dut_print(dut, DUT_MSG_INFO,
3726 "Failed to create nft table");
3727 return -1;
3728 }
3729
3730 pos = nft_cmd;
3731 len = sizeof(nft_cmd);
3732
3733 ret = snprintf(pos, len,
3734 "nft add rule %s %s OUTPUT oifname \"%s\"",
3735 ip, table_name, dut->station_ifname);
3736 if (snprintf_error(len, ret)) {
3737 sigma_dut_print(dut, DUT_MSG_INFO,
3738 "Failed to create nft cmd %s", nft_cmd);
3739 return -1;
3740 }
3741
3742 pos += ret;
3743 len -= ret;
3744
3745 if (strlen(dscp_policy->src_ip)) {
3746 ret = snprintf(pos, len, " %s saddr %s", ip,
3747 dscp_policy->src_ip);
3748 if (snprintf_error(len, ret))
3749 return -1;
3750
3751 pos += ret;
3752 len -= ret;
3753 }
3754
3755 if (strlen(dscp_policy->dst_ip)) {
3756 ret = snprintf(pos, len, " %s daddr %s", ip,
3757 dscp_policy->dst_ip);
3758 if (snprintf_error(len, ret))
3759 return -1;
3760
3761 pos += ret;
3762 len -= ret;
3763 }
3764
3765 if (dscp_policy->src_port) {
3766 ret = snprintf(pos, len, " %s sport %d",
3767 protocol_to_str(dscp_policy->protocol),
3768 dscp_policy->src_port);
3769 if (snprintf_error(len, ret))
3770 return -1;
3771
3772 pos += ret;
3773 len -= ret;
3774 }
3775
3776 if (dscp_policy->dst_port) {
3777 ret = snprintf(pos, len, " %s dport %d",
3778 protocol_to_str(dscp_policy->protocol),
3779 dscp_policy->dst_port);
3780 if (snprintf_error(len, ret))
3781 return -1;
3782
3783 pos += ret;
3784 len -= ret;
3785 }
3786
3787 if (dscp_policy->start_port && dscp_policy->end_port) {
3788 ret = snprintf(pos, len, " %s dport %d-%d",
3789 protocol_to_str(dscp_policy->protocol),
3790 dscp_policy->start_port,
3791 dscp_policy->end_port);
3792 if (snprintf_error(len, ret))
3793 return -1;
3794
3795 pos += ret;
3796 len -= ret;
3797 }
3798
3799 ret = snprintf(pos, len, " counter %s dscp set 0x%0x", ip,
3800 dscp_policy->dscp);
3801 if (snprintf_error(len, ret))
3802 return -1;
3803
3804 ret = system(nft_cmd);
3805 sigma_dut_print(dut, DUT_MSG_INFO, "nft rule: %s err: %d",
3806 nft_cmd, ret);
3807
3808 return ret;
3809}
3810
3811
3812static void clear_all_dscp_policies(struct sigma_dut *dut)
3813{
3814 free_dscp_policy_table(dut);
3815
3816 if (system("nft flush ruleset") != 0)
3817 sigma_dut_print(dut, DUT_MSG_ERROR,
3818 "Failed to flush DSCP policy");
3819}
3820
3821
3822static int send_dscp_response(struct sigma_dut *dut,
3823 struct dscp_policy_status *status_list,
3824 int num_status)
3825{
3826 int rem_len, ret;
3827 char buf[200] = "", *pos, cmd[256];
3828
3829 pos = buf;
3830 rem_len = sizeof(buf);
3831
3832 ret = snprintf(pos, rem_len, " solicited");
3833 if (snprintf_error(rem_len, ret)) {
3834 sigma_dut_print(dut, DUT_MSG_ERROR,
3835 "Failed to write DSCP policy response command");
3836 return -1;
3837 }
3838 pos += ret;
3839 rem_len -= ret;
3840
3841 for (int i = 0; i < num_status; i++) {
3842 ret = snprintf(pos, rem_len, " policy_id=%d status=%d",
3843 status_list[i].id, status_list[i].status);
3844 if (snprintf_error(rem_len, ret)) {
3845 sigma_dut_print(dut, DUT_MSG_ERROR,
3846 "Failed to wite DSCP policy response");
3847 return -1;
3848 }
3849
3850 pos += ret;
3851 rem_len -= ret;
3852 }
3853
3854 ret = snprintf(cmd, sizeof(cmd), "DSCP_RESP%s", buf);
3855 if (snprintf_error(sizeof(cmd), ret)) {
3856 sigma_dut_print(dut, DUT_MSG_ERROR,
3857 "Failed to create DSCP Policy Response frame");
3858 return -1;
3859 }
3860
3861 if (wpa_command(dut->station_ifname, cmd) != 0) {
3862 sigma_dut_print(dut, DUT_MSG_ERROR,
3863 "Failed to send DSCP Policy Response frame");
3864 return -1;
3865 }
3866
3867 sigma_dut_print(dut, DUT_MSG_DEBUG,
3868 "DSCP Policy Response frame sent: %s", cmd);
3869 return 0;
3870}
3871
3872
3873#ifdef ANDROID
3874static void thread_cancel_handler(int sig)
3875{
3876 if (sig == SIGUSR1)
3877 pthread_exit(0);
3878}
3879#endif /* ANDROID */
3880
3881
3882static void * mon_dscp_policies(void *ptr)
3883{
3884 struct sigma_dut *dut = ptr;
3885 int ret, policy_id;
3886 struct wpa_ctrl *ctrl;
3887 char buf[4096], *pos, *end;
3888 struct dscp_policy_data *policy = NULL, *policy_table;
3889 struct dscp_policy_status status_list[10];
3890 int num_status = 0;
3891 const char *events[] = {
3892 "CTRL-EVENT-DISCONNECTED",
3893 "CTRL-EVENT-DSCP-POLICY",
3894 NULL
3895 };
3896#ifdef ANDROID
3897 struct sigaction actions;
3898#endif /* ANDROID */
3899
3900 ctrl = open_wpa_mon(get_station_ifname(dut));
3901 if (!ctrl) {
3902 sigma_dut_print(dut, DUT_MSG_ERROR,
3903 "Failed to open wpa_supplicant monitor connection");
3904 return NULL;
3905 }
3906
3907#ifdef ANDROID
3908 memset(&actions, 0, sizeof(actions));
3909 sigemptyset(&actions.sa_mask);
3910 actions.sa_flags = 0;
3911 actions.sa_handler = thread_cancel_handler;
3912 if (sigaction(SIGUSR1, &actions, NULL) == -1) {
3913 sigma_dut_print(dut, DUT_MSG_ERROR,
3914 "Failed to register exit handler for %s",
3915 __func__);
3916 wpa_ctrl_detach(ctrl);
3917 wpa_ctrl_close(ctrl);
3918 return NULL;
3919 }
3920#endif /* ANDROID */
3921
3922 while (1) {
3923 ret = get_wpa_cli_events_timeout(dut, ctrl, events,
3924 buf, sizeof(buf), 0);
3925
3926 if (ret || strlen(buf) == 0) {
3927 sigma_dut_print(dut, DUT_MSG_INFO,
3928 "Did not receive any event");
3929 continue;
3930 }
3931
3932 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3933 clear_all_dscp_policies(dut);
3934 break;
3935 }
3936
3937 if (strstr(buf, "request_start")) {
3938 num_status = 0;
3939 if (strstr(buf, "clear_all"))
3940 clear_all_dscp_policies(dut);
3941 continue;
3942 }
3943
3944 if (strstr(buf, "request_end")) {
3945 send_dscp_response(dut, status_list, num_status);
3946 continue;
3947 }
3948
3949 if (!strstr(buf, "add") && !strstr(buf, "remove") &&
3950 !strstr(buf, "reject")) {
3951 sigma_dut_print(dut, DUT_MSG_DEBUG, "Ignore event: %s",
3952 buf);
3953 continue;
3954 }
3955
3956 pos = strstr(buf, "policy_id=");
3957 if (!pos) {
3958 sigma_dut_print(dut, DUT_MSG_INFO,
3959 "Policy id not present");
3960 continue;
3961 }
3962 policy_id = atoi(pos + 10);
3963
3964 if (num_status >= ARRAY_SIZE(status_list)) {
3965 sigma_dut_print(dut, DUT_MSG_INFO,
3966 "Max policies allowed per DSCP request reached. Drop policy id %d request",
3967 policy_id);
3968 continue;
3969 }
3970 status_list[num_status].id = policy_id;
3971
3972 if (strstr(buf, "reject"))
3973 goto reject;
3974
3975 /*
3976 * In case of "add" also if policy with same policy id exist it
3977 * shall be removed. So always call remove_dscp_policy().
3978 */
3979 if (remove_dscp_policy(dut, policy_id))
3980 goto reject;
3981
3982 if (strstr(buf, "remove"))
3983 goto success;
3984
3985 policy = malloc(sizeof(*policy));
3986 if (!policy)
3987 goto reject;
3988
3989 memset(policy, 0, sizeof(*policy));
3990
3991 policy->policy_id = policy_id;
3992
3993 pos = strstr(buf, "dscp=");
3994 if (!pos) {
3995 sigma_dut_print(dut, DUT_MSG_ERROR,
3996 "DSCP info not present");
3997 goto reject;
3998 }
3999 policy->dscp = atoi(pos + 5);
4000
4001 pos = strstr(buf, "ip_version=");
4002 if (!pos) {
4003 sigma_dut_print(dut, DUT_MSG_ERROR,
4004 "IP version info not present");
4005 goto reject;
4006 }
4007 policy->ip_version = atoi(pos + 11);
4008
4009 pos = strstr(buf, "domain_name=");
4010 if (pos) {
4011 pos += 12;
4012 end = strchr(pos, ' ');
4013 if (!end)
4014 end = pos + strlen(pos);
4015
4016 if (end - pos >= (int) sizeof(policy->domain_name))
4017 goto reject;
4018
4019 memcpy(policy->domain_name, pos, end - pos);
4020 policy->domain_name[end - pos] = '\0';
4021 }
4022
4023 pos = strstr(buf, "start_port=");
4024 if (pos) {
4025 pos += 11;
4026 policy->start_port = atoi(pos);
4027 }
4028
4029 pos = strstr(buf, "end_port=");
4030 if (pos) {
4031 pos += 9;
4032 policy->end_port = atoi(pos);
4033 }
4034
4035 pos = strstr(buf, "src_ip=");
4036 if (pos) {
4037 pos += 7;
4038 end = strchr(pos, ' ');
4039 if (!end)
4040 end = pos + strlen(pos);
4041
4042 if (end - pos >= (int) sizeof(policy->src_ip))
4043 goto reject;
4044
4045 memcpy(policy->src_ip, pos, end - pos);
4046 policy->src_ip[end - pos] = '\0';
4047 }
4048
4049 pos = strstr(buf, "dst_ip=");
4050 if (pos) {
4051 pos += 7;
4052 end = strchr(pos, ' ');
4053 if (!end)
4054 end = pos + strlen(pos);
4055
4056 if (end - pos >= (int) sizeof(policy->dst_ip))
4057 goto reject;
4058
4059 memcpy(policy->dst_ip, pos, end - pos);
4060 policy->dst_ip[end - pos] = '\0';
4061 }
4062
4063 pos = strstr(buf, "src_port=");
4064 if (pos) {
4065 pos += 9;
4066 policy->src_port = atoi(pos);
4067 }
4068
4069 pos = strstr(buf, "dst_port=");
4070 if (pos) {
4071 pos += 9;
4072 policy->dst_port = atoi(pos);
4073 }
4074
4075 pos = strstr(buf, "protocol=");
4076 if (pos) {
4077 pos += 9;
4078 policy->protocol = atoi(pos);
4079 }
4080
4081 /*
4082 * Skip adding nft rules for doman name policies.
4083 * Domain name rules are applied in sigma_dut itself.
4084 */
4085 if (!strlen(policy->domain_name) && add_nft_rule(dut, policy))
4086 goto reject;
4087
4088 if (dut->dscp_policy_table) {
4089 policy_table = dut->dscp_policy_table;
4090 while (policy_table->next != NULL)
4091 policy_table = policy_table->next;
4092
4093 policy_table->next = policy;
4094 } else
4095 dut->dscp_policy_table = policy;
4096
4097success:
4098 status_list[num_status].status = DSCP_POLICY_SUCCESS;
4099 num_status++;
4100 policy = NULL;
4101 continue;
4102reject:
4103 status_list[num_status].status = DSCP_POLICY_REJECT;
4104 num_status++;
4105 free(policy);
4106 policy = NULL;
4107 }
4108
4109 free_dscp_policy_table(dut);
4110 wpa_ctrl_detach(ctrl);
4111 wpa_ctrl_close(ctrl);
4112
4113 pthread_exit(0);
4114 return NULL;
4115}
4116
4117
4118static void start_dscp_policy_mon_thread(struct sigma_dut *dut)
4119{
4120 /* Create event thread */
4121 pthread_create(&dut->dscp_policy_mon_thread, NULL, &mon_dscp_policies,
4122 (void *) dut);
4123}
4124
4125
4126void stop_dscp_policy_mon_thread(struct sigma_dut *dut)
4127{
4128 if (dut->dscp_policy_mon_thread) {
4129#ifdef ANDROID
4130 /* pthread_cancel not supported in Android */
4131 pthread_kill(dut->dscp_policy_mon_thread, SIGUSR1);
4132#else /* ANDROID */
4133 pthread_cancel(dut->dscp_policy_mon_thread);
4134#endif /* ANDROID */
4135 dut->dscp_policy_mon_thread = 0;
4136 }
4137}
4138
4139
Jouni Malinenf7222712019-06-13 01:50:21 +03004140static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
4141 struct sigma_conn *conn,
4142 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004143{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304144#ifdef NL80211_SUPPORT
4145 const char *intf = get_param(cmd, "Interface");
4146#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004147 const char *ssid = get_param(cmd, "ssid");
4148 const char *wps_param = get_param(cmd, "WPS");
4149 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03004150 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02004151 const char *network_mode = get_param(cmd, "network_mode");
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304152 const char *ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004153 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03004154 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004155 int e;
4156 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
4157 struct wpa_ctrl *ctrl = NULL;
4158 int num_network_not_found = 0;
4159 int num_disconnected = 0;
4160 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004161
4162 if (ssid == NULL)
4163 return -1;
4164
Jouni Malinen37d5c692019-08-19 16:56:55 +03004165 dut->server_cert_tod = 0;
4166
Jouni Malinen3c367e82017-06-23 17:01:47 +03004167 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05304168#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004169 if (get_driver_type(dut) == DRIVER_WCN) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304170 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Sunil Dutt44595082018-02-12 19:41:45 +05304171 dut->config_rsnie = 1;
4172 }
4173#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03004174 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
4175 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004176 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03004177 send_resp(dut, conn, SIGMA_ERROR,
4178 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
4179 return 0;
4180 }
4181 }
4182
Jouni Malinen68143132017-09-02 02:34:08 +03004183 if (dut->sae_commit_override) {
4184 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
4185 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004186 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03004187 send_resp(dut, conn, SIGMA_ERROR,
4188 "ErrorCode,Failed to set SAE commit override");
4189 return 0;
4190 }
4191 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304192#ifdef ANDROID
4193 if (dut->fils_hlp)
4194 process_fils_hlp(dut);
4195#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03004196
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004197 if (wps_param &&
4198 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
4199 wps = 1;
4200
4201 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02004202 if (dut->program == PROGRAM_60GHZ && network_mode &&
4203 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004204 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02004205 "pbss", "1") < 0)
4206 return -2;
4207
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004208 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
4209 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
4210 "parameters not yet set");
4211 return 0;
4212 }
4213 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004214 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004215 return -2;
4216 } else {
4217 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
4218 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004219 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004220 return -2;
4221 }
4222 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05304223 if (strcmp(ssid, dut->infra_ssid) == 0) {
4224 sigma_dut_print(dut, DUT_MSG_DEBUG,
4225 "sta_associate for the most recently added network");
4226 } else if (find_network(dut, ssid) < 0) {
4227 sigma_dut_print(dut, DUT_MSG_DEBUG,
4228 "sta_associate for a previously stored network profile");
4229 send_resp(dut, conn, SIGMA_ERROR,
4230 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004231 return 0;
4232 }
4233
4234 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004235 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004236 "bssid", bssid) < 0) {
4237 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4238 "Invalid bssid argument");
4239 return 0;
4240 }
4241
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304242 if ((dut->program == PROGRAM_WPA3 &&
4243 dut->sta_associate_wait_connect) ||
4244 dut->program == PROGRAM_QM) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004245 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004246 if (!ctrl)
4247 return ERROR_SEND_STATUS;
4248 }
4249
Jouni Malinen46a19b62017-06-23 14:31:27 +03004250 extra[0] = '\0';
4251 if (chan)
4252 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02004253 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03004254 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
4255 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004256 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004257 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
4258 "network id %d on %s",
4259 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004260 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004261 ret = ERROR_SEND_STATUS;
4262 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004263 }
4264 }
4265
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004266 if (!ctrl)
4267 return SUCCESS_SEND_STATUS;
4268
4269 /* Wait for connection result to be able to store server certificate
4270 * hash for trust root override testing
4271 * (dev_exec_action,ServerCertTrust). */
4272
4273 for (e = 0; e < 20; e++) {
4274 const char *events[] = {
4275 "CTRL-EVENT-EAP-PEER-CERT",
4276 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
4277 "CTRL-EVENT-DISCONNECTED",
4278 "CTRL-EVENT-CONNECTED",
4279 "CTRL-EVENT-NETWORK-NOT-FOUND",
4280 NULL
4281 };
4282 char buf[1024];
4283 int res;
4284
4285 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
4286 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02004287 send_resp(dut, conn, SIGMA_COMPLETE,
4288 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004289 ret = STATUS_SENT_ERROR;
4290 break;
4291 }
4292 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
4293 buf);
4294
4295 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
4296 strstr(buf, " depth=0")) {
4297 char *pos = strstr(buf, " hash=");
4298
4299 if (pos) {
4300 char *end;
4301
Jouni Malinen34b19cb2019-08-16 16:37:17 +03004302 if (strstr(buf, " tod=1"))
4303 tod = 1;
4304 else if (strstr(buf, " tod=2"))
4305 tod = 2;
4306 else
4307 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004308 sigma_dut_print(dut, DUT_MSG_DEBUG,
4309 "Server certificate TOD policy: %d",
4310 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03004311 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004312
4313 pos += 6;
4314 end = strchr(pos, ' ');
4315 if (end)
4316 *end = '\0';
4317 strlcpy(dut->server_cert_hash, pos,
4318 sizeof(dut->server_cert_hash));
4319 sigma_dut_print(dut, DUT_MSG_DEBUG,
4320 "Server certificate hash: %s",
4321 dut->server_cert_hash);
4322 }
4323 }
4324
4325 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
4326 send_resp(dut, conn, SIGMA_COMPLETE,
4327 "Result,TLS server certificate validation failed");
4328 ret = STATUS_SENT_ERROR;
4329 break;
4330 }
4331
4332 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
4333 num_network_not_found++;
4334
4335 if (num_network_not_found > 2) {
4336 send_resp(dut, conn, SIGMA_COMPLETE,
4337 "Result,Network not found");
4338 ret = STATUS_SENT_ERROR;
4339 break;
4340 }
4341 }
4342
4343 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
4344 num_disconnected++;
4345
4346 if (num_disconnected > 2) {
4347 send_resp(dut, conn, SIGMA_COMPLETE,
4348 "Result,Connection failed");
4349 ret = STATUS_SENT_ERROR;
4350 break;
4351 }
4352 }
4353
4354 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
4355 if (tod >= 0) {
4356 sigma_dut_print(dut, DUT_MSG_DEBUG,
4357 "Network profile TOD policy update: %d -> %d",
4358 dut->sta_tod_policy, tod);
4359 dut->sta_tod_policy = tod;
4360 }
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304361 if (dut->program == PROGRAM_QM) {
4362 unsigned char iface_mac_addr[ETH_ALEN];
4363 char ipv6[100];
4364
4365 if (get_hwaddr(ifname, iface_mac_addr) < 0) {
4366 sigma_dut_print(dut, DUT_MSG_ERROR,
4367 "%s: get_hwaddr %s failed",
4368 __func__, ifname);
4369 ret = ERROR_SEND_STATUS;
4370 break;
4371 }
4372
4373 convert_mac_addr_to_ipv6_lladdr(iface_mac_addr,
4374 ipv6,
4375 sizeof(ipv6));
4376
4377 if (set_ipv6_addr(dut, ipv6, "64", ifname) !=
4378 0) {
4379 ret = ERROR_SEND_STATUS;
4380 break;
4381 }
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05304382 start_dscp_policy_mon_thread(dut);
Veerendranath Jakkama082e342020-05-16 00:19:21 +05304383 }
Jouni Malinen134fe3c2019-06-12 04:16:49 +03004384 break;
4385 }
4386 }
4387done:
4388 if (ctrl) {
4389 wpa_ctrl_detach(ctrl);
4390 wpa_ctrl_close(ctrl);
4391 }
4392 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004393}
4394
4395
4396static int run_hs20_osu(struct sigma_dut *dut, const char *params)
4397{
4398 char buf[500], cmd[200];
4399 int res;
4400
4401 /* Use hs20-osu-client file at the current dir, if found; otherwise use
4402 * default path */
4403 res = snprintf(cmd, sizeof(cmd),
4404 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
4405 file_exists("./hs20-osu-client") ?
4406 "./hs20-osu-client" : "hs20-osu-client",
4407 sigma_wpas_ctrl,
4408 dut->summary_log ? "-s " : "",
4409 dut->summary_log ? dut->summary_log : "");
4410 if (res < 0 || res >= (int) sizeof(cmd))
4411 return -1;
4412
4413 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
4414 if (res < 0 || res >= (int) sizeof(buf))
4415 return -1;
4416 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
4417
4418 if (system(buf) != 0) {
4419 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
4420 return -1;
4421 }
4422 sigma_dut_print(dut, DUT_MSG_DEBUG,
4423 "Completed hs20-osu-client operation");
4424
4425 return 0;
4426}
4427
4428
4429static int download_ppsmo(struct sigma_dut *dut,
4430 struct sigma_conn *conn,
4431 const char *intf,
4432 struct sigma_cmd *cmd)
4433{
4434 const char *name, *path, *val;
4435 char url[500], buf[600], fbuf[100];
4436 char *fqdn = NULL;
4437
4438 name = get_param(cmd, "FileName");
4439 path = get_param(cmd, "FilePath");
4440 if (name == NULL || path == NULL)
4441 return -1;
4442
4443 if (strcasecmp(path, "VendorSpecific") == 0) {
4444 snprintf(url, sizeof(url), "PPS/%s", name);
4445 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
4446 "from the device (%s)", url);
4447 if (!file_exists(url)) {
4448 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4449 "PPS MO file does not exist");
4450 return 0;
4451 }
4452 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
4453 if (system(buf) != 0) {
4454 send_resp(dut, conn, SIGMA_ERROR,
4455 "errorCode,Failed to copy PPS MO");
4456 return 0;
4457 }
4458 } else if (strncasecmp(path, "http:", 5) != 0 &&
4459 strncasecmp(path, "https:", 6) != 0) {
4460 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4461 "Unsupported FilePath value");
4462 return 0;
4463 } else {
4464 snprintf(url, sizeof(url), "%s/%s", path, name);
4465 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
4466 url);
4467 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
4468 remove("pps-tnds.xml");
4469 if (system(buf) != 0) {
4470 send_resp(dut, conn, SIGMA_ERROR,
4471 "errorCode,Failed to download PPS MO");
4472 return 0;
4473 }
4474 }
4475
4476 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
4477 send_resp(dut, conn, SIGMA_ERROR,
4478 "errorCode,Failed to parse downloaded PPSMO");
4479 return 0;
4480 }
4481 unlink("pps-tnds.xml");
4482
4483 val = get_param(cmd, "managementTreeURI");
4484 if (val) {
4485 const char *pos, *end;
4486 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
4487 val);
4488 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
4489 send_resp(dut, conn, SIGMA_ERROR,
4490 "errorCode,Invalid managementTreeURI prefix");
4491 return 0;
4492 }
4493 pos = val + 8;
4494 end = strchr(pos, '/');
4495 if (end == NULL ||
4496 strcmp(end, "/PerProviderSubscription") != 0) {
4497 send_resp(dut, conn, SIGMA_ERROR,
4498 "errorCode,Invalid managementTreeURI postfix");
4499 return 0;
4500 }
4501 if (end - pos >= (int) sizeof(fbuf)) {
4502 send_resp(dut, conn, SIGMA_ERROR,
4503 "errorCode,Too long FQDN in managementTreeURI");
4504 return 0;
4505 }
4506 memcpy(fbuf, pos, end - pos);
4507 fbuf[end - pos] = '\0';
4508 fqdn = fbuf;
4509 sigma_dut_print(dut, DUT_MSG_INFO,
4510 "FQDN from managementTreeURI: %s", fqdn);
4511 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
4512 FILE *f = fopen("pps-fqdn", "r");
4513 if (f) {
4514 if (fgets(fbuf, sizeof(fbuf), f)) {
4515 fbuf[sizeof(fbuf) - 1] = '\0';
4516 fqdn = fbuf;
4517 sigma_dut_print(dut, DUT_MSG_DEBUG,
4518 "Use FQDN %s", fqdn);
4519 }
4520 fclose(f);
4521 }
4522 }
4523
4524 if (fqdn == NULL) {
4525 send_resp(dut, conn, SIGMA_ERROR,
4526 "errorCode,No FQDN specified");
4527 return 0;
4528 }
4529
4530 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
4531 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
4532 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
4533
4534 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
4535 if (rename("pps.xml", buf) < 0) {
4536 send_resp(dut, conn, SIGMA_ERROR,
4537 "errorCode,Could not move PPS MO");
4538 return 0;
4539 }
4540
4541 if (strcasecmp(path, "VendorSpecific") == 0) {
4542 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
4543 fqdn);
4544 if (system(buf)) {
4545 send_resp(dut, conn, SIGMA_ERROR,
4546 "errorCode,Failed to copy OSU CA cert");
4547 return 0;
4548 }
4549
4550 snprintf(buf, sizeof(buf),
4551 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
4552 fqdn);
4553 if (system(buf)) {
4554 send_resp(dut, conn, SIGMA_ERROR,
4555 "errorCode,Failed to copy AAA CA cert");
4556 return 0;
4557 }
4558 } else {
4559 snprintf(buf, sizeof(buf),
4560 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
4561 fqdn, fqdn);
4562 if (run_hs20_osu(dut, buf) < 0) {
4563 send_resp(dut, conn, SIGMA_ERROR,
4564 "errorCode,Failed to download OSU CA cert");
4565 return 0;
4566 }
4567
4568 snprintf(buf, sizeof(buf),
4569 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
4570 fqdn, fqdn);
4571 if (run_hs20_osu(dut, buf) < 0) {
4572 sigma_dut_print(dut, DUT_MSG_INFO,
4573 "Failed to download AAA CA cert");
4574 }
4575 }
4576
4577 if (file_exists("next-client-cert.pem")) {
4578 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
4579 if (rename("next-client-cert.pem", buf) < 0) {
4580 send_resp(dut, conn, SIGMA_ERROR,
4581 "errorCode,Could not move client certificate");
4582 return 0;
4583 }
4584 }
4585
4586 if (file_exists("next-client-key.pem")) {
4587 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
4588 if (rename("next-client-key.pem", buf) < 0) {
4589 send_resp(dut, conn, SIGMA_ERROR,
4590 "errorCode,Could not move client key");
4591 return 0;
4592 }
4593 }
4594
4595 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
4596 if (run_hs20_osu(dut, buf) < 0) {
4597 send_resp(dut, conn, SIGMA_ERROR,
4598 "errorCode,Failed to configure credential from "
4599 "PPSMO");
4600 return 0;
4601 }
4602
4603 return 1;
4604}
4605
4606
4607static int download_cert(struct sigma_dut *dut,
4608 struct sigma_conn *conn,
4609 const char *intf,
4610 struct sigma_cmd *cmd)
4611{
4612 const char *name, *path;
4613 char url[500], buf[600];
4614
4615 name = get_param(cmd, "FileName");
4616 path = get_param(cmd, "FilePath");
4617 if (name == NULL || path == NULL)
4618 return -1;
4619
4620 if (strcasecmp(path, "VendorSpecific") == 0) {
4621 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
4622 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4623 "certificate from the device (%s)", url);
4624 if (!file_exists(url)) {
4625 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4626 "certificate file does not exist");
4627 return 0;
4628 }
4629 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
4630 if (system(buf) != 0) {
4631 send_resp(dut, conn, SIGMA_ERROR,
4632 "errorCode,Failed to copy client "
4633 "certificate");
4634 return 0;
4635 }
4636
4637 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
4638 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4639 "private key from the device (%s)", url);
4640 if (!file_exists(url)) {
4641 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4642 "private key file does not exist");
4643 return 0;
4644 }
4645 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
4646 if (system(buf) != 0) {
4647 send_resp(dut, conn, SIGMA_ERROR,
4648 "errorCode,Failed to copy client key");
4649 return 0;
4650 }
4651 } else if (strncasecmp(path, "http:", 5) != 0 &&
4652 strncasecmp(path, "https:", 6) != 0) {
4653 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4654 "Unsupported FilePath value");
4655 return 0;
4656 } else {
4657 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
4658 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
4659 "certificate/key from %s", url);
4660 snprintf(buf, sizeof(buf),
4661 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
4662 if (system(buf) != 0) {
4663 send_resp(dut, conn, SIGMA_ERROR,
4664 "errorCode,Failed to download client "
4665 "certificate");
4666 return 0;
4667 }
4668
4669 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
4670 {
4671 send_resp(dut, conn, SIGMA_ERROR,
4672 "errorCode,Failed to copy client key");
4673 return 0;
4674 }
4675 }
4676
4677 return 1;
4678}
4679
4680
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004681static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
4682 struct sigma_conn *conn,
4683 struct sigma_cmd *cmd)
4684{
4685 const char *val;
4686 const char *intf = get_param(cmd, "interface");
4687
4688 if (!intf)
4689 return -1;
4690
4691 val = get_param(cmd, "WscIEFragment");
4692 if (val && strcasecmp(val, "enable") == 0) {
4693 sigma_dut_print(dut, DUT_MSG_DEBUG,
4694 "Enable WSC IE fragmentation");
4695
4696 dut->wsc_fragment = 1;
4697 /* set long attributes to force fragmentation */
4698 if (wpa_command(intf, "SET device_name "
4699 WPS_LONG_DEVICE_NAME) < 0)
4700 return -2;
4701 if (wpa_command(intf, "SET manufacturer "
4702 WPS_LONG_MANUFACTURER) < 0)
4703 return -2;
4704 if (wpa_command(intf, "SET model_name "
4705 WPS_LONG_MODEL_NAME) < 0)
4706 return -2;
4707 if (wpa_command(intf, "SET model_number "
4708 WPS_LONG_MODEL_NUMBER) < 0)
4709 return -2;
4710 if (wpa_command(intf, "SET serial_number "
4711 WPS_LONG_SERIAL_NUMBER) < 0)
4712 return -2;
4713 }
4714
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02004715 val = get_param(cmd, "RSN_IE");
4716 if (val) {
4717 if (strcasecmp(val, "disable") == 0)
4718 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
4719 else if (strcasecmp(val, "enable") == 0)
4720 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
4721 }
4722
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004723 val = get_param(cmd, "WpsVersion");
4724 if (val)
4725 dut->wps_forced_version = get_wps_forced_version(dut, val);
4726
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004727 val = get_param(cmd, "WscEAPFragment");
4728 if (val && strcasecmp(val, "enable") == 0)
4729 dut->eap_fragment = 1;
4730
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004731 return 1;
4732}
4733
4734
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004735static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4736 struct sigma_conn *conn,
4737 const char *intf,
4738 struct sigma_cmd *cmd)
4739{
4740 const char *val;
4741
4742 val = get_param(cmd, "FileType");
4743 if (val && strcasecmp(val, "PPSMO") == 0)
4744 return download_ppsmo(dut, conn, intf, cmd);
4745 if (val && strcasecmp(val, "CERT") == 0)
4746 return download_cert(dut, conn, intf, cmd);
4747 if (val) {
4748 send_resp(dut, conn, SIGMA_ERROR,
4749 "ErrorCode,Unsupported FileType");
4750 return 0;
4751 }
4752
4753 return 1;
4754}
4755
4756
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304757static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4758 struct sigma_conn *conn,
4759 const char *intf,
4760 struct sigma_cmd *cmd)
4761{
4762 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304763 char buf[1000];
4764 char text[20];
4765 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304766
4767 val = get_param(cmd, "OCESupport");
4768 if (val && strcasecmp(val, "Disable") == 0) {
4769 if (wpa_command(intf, "SET oce 0") < 0) {
4770 send_resp(dut, conn, SIGMA_ERROR,
4771 "ErrorCode,Failed to disable OCE");
4772 return 0;
4773 }
4774 } else if (val && strcasecmp(val, "Enable") == 0) {
4775 if (wpa_command(intf, "SET oce 1") < 0) {
4776 send_resp(dut, conn, SIGMA_ERROR,
4777 "ErrorCode,Failed to enable OCE");
4778 return 0;
4779 }
4780 }
4781
vamsi krishnaa2799492017-12-05 14:28:01 +05304782 val = get_param(cmd, "FILScap");
4783 if (val && (atoi(val) == 1)) {
4784 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4785 send_resp(dut, conn, SIGMA_ERROR,
4786 "ErrorCode,Failed to enable FILS");
4787 return 0;
4788 }
4789 } else if (val && (atoi(val) == 0)) {
4790 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4791 send_resp(dut, conn, SIGMA_ERROR,
4792 "ErrorCode,Failed to disable FILS");
4793 return 0;
4794 }
4795 }
4796
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304797 val = get_param(cmd, "FILSHLP");
4798 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004799 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304800 sizeof(text)) < 0)
4801 return -2;
4802 hwaddr_aton(text, addr);
4803 snprintf(buf, sizeof(buf),
4804 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4805 "080045100140000040004011399e00000000ffffffff00440043"
4806 "012cb30001010600fd4f46410000000000000000000000000000"
4807 "000000000000"
4808 "%02x%02x%02x%02x%02x%02x"
4809 "0000000000000000000000000000000000000000000000000000"
4810 "0000000000000000000000000000000000000000000000000000"
4811 "0000000000000000000000000000000000000000000000000000"
4812 "0000000000000000000000000000000000000000000000000000"
4813 "0000000000000000000000000000000000000000000000000000"
4814 "0000000000000000000000000000000000000000000000000000"
4815 "0000000000000000000000000000000000000000000000000000"
4816 "0000000000000000000000000000000000000000638253633501"
4817 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4818 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4819 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4820 if (wpa_command(intf, buf)) {
4821 send_resp(dut, conn, SIGMA_ERROR,
4822 "ErrorCode,Failed to add HLP");
4823 return 0;
4824 }
4825 dut->fils_hlp = 1;
4826 }
4827
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304828 return 1;
4829}
4830
4831
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004832static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4833 const char *val)
4834{
4835 int counter = 0;
4836 char token[50];
4837 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304838 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004839
Peng Xub8fc5cc2017-05-10 17:27:28 -07004840 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004841 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304842 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004843 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004844 if (strcmp(result, "disable") == 0)
4845 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4846 else
4847 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304848 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004849 counter++;
4850 }
4851}
4852
4853
4854static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4855 const char *val)
4856{
4857 char buf[100];
4858
4859 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4860 if (system(buf) != 0) {
4861 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4862 }
4863}
4864
4865
4866static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4867 const char *val)
4868{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004869 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004870 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004871 }
4872}
4873
4874
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004875static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4876 const char *val)
4877{
4878#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004879 int wmmenable = 1;
4880
4881 if (val &&
4882 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4883 wmmenable = 0;
4884
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304885 return wcn_wifi_test_config_set_u8(
4886 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4887 wmmenable);
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004888#else /* NL80211_SUPPORT */
4889 sigma_dut_print(dut, DUT_MSG_ERROR,
4890 "WMM cannot be changed without NL80211_SUPPORT defined");
4891 return -1;
4892#endif /* NL80211_SUPPORT */
4893}
4894
4895
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004896static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4897 const char *val)
4898{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004899 int sgi20;
4900
4901 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4902
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004903 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004904}
4905
4906
4907static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4908 const char *val)
4909{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304910 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004911
4912 /* Disable Tx Beam forming when using a fixed rate */
4913 ath_disable_txbf(dut, intf);
4914
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304915 v = atoi(val);
4916 if (v < 0 || v > 32) {
4917 sigma_dut_print(dut, DUT_MSG_ERROR,
4918 "Invalid Fixed MCS rate: %d", v);
4919 return;
4920 }
4921 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004922
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004923 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004924
4925 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004926 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004927}
4928
4929
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004930static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4931 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004932{
4933 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304934 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004935
4936 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4937 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4938 else
4939 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4940
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304941 ret = system(buf);
4942#ifdef NL80211_SUPPORT
4943 if (ret) {
4944 int value = (strcasecmp(val, "Enable") == 0) ? 2 : 1;
4945
4946 ret = sta_config_params(dut, intf, STA_SET_TX_MSDU, value);
4947 ret |= sta_config_params(dut, intf, STA_SET_RX_MSDU, value);
4948 }
4949#endif /* NL80211_SUPPORT */
4950 if (ret)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004951 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4952}
4953
4954
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004955static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4956 int ampdu)
4957{
4958 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004959 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004960
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004961 if (ampdu)
4962 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004963 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4964 if (system(buf) != 0) {
4965 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4966 return -1;
4967 }
4968
4969 return 0;
4970}
4971
4972
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004973static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4974 const char *val)
4975{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004976 run_iwpriv(dut, intf, "tx_stbc %s", val);
4977 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004978}
4979
4980
4981static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4982 const char *val)
4983{
4984 char buf[60];
4985
Peng Xucc317ed2017-05-18 16:44:37 -07004986 if (strcmp(val, "160") == 0) {
4987 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4988 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004989 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4990 } else if (strcmp(val, "40") == 0) {
4991 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4992 } else if (strcmp(val, "20") == 0) {
4993 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4994 } else if (strcasecmp(val, "Auto") == 0) {
4995 buf[0] = '\0';
4996 } else {
4997 sigma_dut_print(dut, DUT_MSG_ERROR,
4998 "WIDTH/CTS_WIDTH value not supported");
4999 return -1;
5000 }
5001
5002 if (buf[0] != '\0' && system(buf) != 0) {
5003 sigma_dut_print(dut, DUT_MSG_ERROR,
5004 "Failed to set WIDTH/CTS_WIDTH");
5005 return -1;
5006 }
5007
5008 return 0;
5009}
5010
5011
5012int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
5013 const char *intf, const char *val)
5014{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005015 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005016 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005017 dut->chwidth = 0;
5018 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005019 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005020 dut->chwidth = 0;
5021 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005022 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005023 dut->chwidth = 1;
5024 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005025 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005026 dut->chwidth = 2;
5027 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005028 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005029 dut->chwidth = 3;
5030 } else {
5031 send_resp(dut, conn, SIGMA_ERROR,
5032 "ErrorCode,WIDTH not supported");
5033 return -1;
5034 }
5035
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005036 return 0;
5037}
5038
5039
5040static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
5041 const char *val)
5042{
5043 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07005044 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005045
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08005046 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005047 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07005048 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08005049 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005050 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07005051 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005052 } else {
5053 sigma_dut_print(dut, DUT_MSG_ERROR,
5054 "SP_STREAM value not supported");
5055 return -1;
5056 }
5057
5058 if (system(buf) != 0) {
5059 sigma_dut_print(dut, DUT_MSG_ERROR,
5060 "Failed to set SP_STREAM");
5061 return -1;
5062 }
5063
Arif Hussainac6c5112018-05-25 17:34:00 -07005064 dut->sta_nss = sta_nss;
5065
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005066 return 0;
5067}
5068
5069
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305070static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
5071 const char *val)
5072{
5073 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05305074 int ret;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305075
5076 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05305077 ret = system(buf);
5078#ifdef NL80211_SUPPORT
5079 if (ret)
5080 ret = sta_config_params(dut, intf, STA_SET_TX_STBC,
5081 strcmp(val, "0") == 0 ? 0 : 1);
5082#endif /* NL80211_SUPPORT */
5083 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305084 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
5085
5086 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05305087 ret = system(buf);
5088#ifdef NL80211_SUPPORT
5089 if (ret)
5090 ret = sta_config_params(dut, intf, STA_SET_RX_STBC,
5091 strcmp(val, "0") == 0 ? 0 : 1);
5092#endif /* NL80211_SUPPORT */
5093 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305094 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
5095}
5096
5097
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305098static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
5099 struct sigma_conn *conn,
5100 const char *intf, int capa)
5101{
5102 char buf[32];
5103
5104 if (capa > 0 && capa < 4) {
5105 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
5106 if (wpa_command(intf, buf) < 0) {
5107 send_resp(dut, conn, SIGMA_ERROR,
5108 "ErrorCode, Failed to set cellular data capability");
5109 return 0;
5110 }
5111 return 1;
5112 }
5113
5114 sigma_dut_print(dut, DUT_MSG_ERROR,
5115 "Invalid Cellular data capability: %d", capa);
5116 send_resp(dut, conn, SIGMA_INVALID,
5117 "ErrorCode,Invalid cellular data capability");
5118 return 0;
5119}
5120
5121
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305122static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
5123 const char *intf, const char *val)
5124{
5125 if (strcasecmp(val, "Disable") == 0) {
5126 if (wpa_command(intf, "SET roaming 0") < 0) {
5127 send_resp(dut, conn, SIGMA_ERROR,
5128 "ErrorCode,Failed to disable roaming");
5129 return 0;
5130 }
5131 return 1;
5132 }
5133
5134 if (strcasecmp(val, "Enable") == 0) {
5135 if (wpa_command(intf, "SET roaming 1") < 0) {
5136 send_resp(dut, conn, SIGMA_ERROR,
5137 "ErrorCode,Failed to enable roaming");
5138 return 0;
5139 }
5140 return 1;
5141 }
5142
5143 sigma_dut_print(dut, DUT_MSG_ERROR,
5144 "Invalid value provided for roaming: %s", val);
5145 send_resp(dut, conn, SIGMA_INVALID,
5146 "ErrorCode,Unknown value provided for Roaming");
5147 return 0;
5148}
5149
5150
Ashwini Patila75de5a2017-04-13 16:35:05 +05305151static int mbo_set_assoc_disallow(struct sigma_dut *dut,
5152 struct sigma_conn *conn,
5153 const char *intf, const char *val)
5154{
5155 if (strcasecmp(val, "Disable") == 0) {
5156 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
5157 send_resp(dut, conn, SIGMA_ERROR,
5158 "ErrorCode,Failed to disable Assoc_disallow");
5159 return 0;
5160 }
5161 return 1;
5162 }
5163
5164 if (strcasecmp(val, "Enable") == 0) {
5165 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
5166 send_resp(dut, conn, SIGMA_ERROR,
5167 "ErrorCode,Failed to enable Assoc_disallow");
5168 return 0;
5169 }
5170 return 1;
5171 }
5172
5173 sigma_dut_print(dut, DUT_MSG_ERROR,
5174 "Invalid value provided for Assoc_disallow: %s", val);
5175 send_resp(dut, conn, SIGMA_INVALID,
5176 "ErrorCode,Unknown value provided for Assoc_disallow");
5177 return 0;
5178}
5179
5180
Ashwini Patilc63161e2017-04-13 16:30:23 +05305181static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
5182 const char *intf, const char *val)
5183{
5184 if (strcasecmp(val, "Reject") == 0) {
5185 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
5186 send_resp(dut, conn, SIGMA_ERROR,
5187 "ErrorCode,Failed to Reject BTM Request");
5188 return 0;
5189 }
5190 return 1;
5191 }
5192
5193 if (strcasecmp(val, "Accept") == 0) {
5194 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
5195 send_resp(dut, conn, SIGMA_ERROR,
5196 "ErrorCode,Failed to Accept BTM Request");
5197 return 0;
5198 }
5199 return 1;
5200 }
5201
5202 sigma_dut_print(dut, DUT_MSG_ERROR,
5203 "Invalid value provided for BSS_Transition: %s", val);
5204 send_resp(dut, conn, SIGMA_INVALID,
5205 "ErrorCode,Unknown value provided for BSS_Transition");
5206 return 0;
5207}
5208
5209
Ashwini Patil00402582017-04-13 12:29:39 +05305210static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
5211 struct sigma_conn *conn,
5212 const char *intf,
5213 struct sigma_cmd *cmd)
5214{
5215 const char *ch, *pref, *op_class, *reason;
5216 char buf[120];
5217 int len, ret;
5218
5219 pref = get_param(cmd, "Ch_Pref");
5220 if (!pref)
5221 return 1;
5222
5223 if (strcasecmp(pref, "clear") == 0) {
5224 free(dut->non_pref_ch_list);
5225 dut->non_pref_ch_list = NULL;
5226 } else {
5227 op_class = get_param(cmd, "Ch_Op_Class");
5228 if (!op_class) {
5229 send_resp(dut, conn, SIGMA_INVALID,
5230 "ErrorCode,Ch_Op_Class not provided");
5231 return 0;
5232 }
5233
5234 ch = get_param(cmd, "Ch_Pref_Num");
5235 if (!ch) {
5236 send_resp(dut, conn, SIGMA_INVALID,
5237 "ErrorCode,Ch_Pref_Num not provided");
5238 return 0;
5239 }
5240
5241 reason = get_param(cmd, "Ch_Reason_Code");
5242 if (!reason) {
5243 send_resp(dut, conn, SIGMA_INVALID,
5244 "ErrorCode,Ch_Reason_Code not provided");
5245 return 0;
5246 }
5247
5248 if (!dut->non_pref_ch_list) {
5249 dut->non_pref_ch_list =
5250 calloc(1, NON_PREF_CH_LIST_SIZE);
5251 if (!dut->non_pref_ch_list) {
5252 send_resp(dut, conn, SIGMA_ERROR,
5253 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
5254 return 0;
5255 }
5256 }
5257 len = strlen(dut->non_pref_ch_list);
5258 ret = snprintf(dut->non_pref_ch_list + len,
5259 NON_PREF_CH_LIST_SIZE - len,
5260 " %s:%s:%s:%s", op_class, ch, pref, reason);
5261 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
5262 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
5263 dut->non_pref_ch_list);
5264 } else {
5265 sigma_dut_print(dut, DUT_MSG_ERROR,
5266 "snprintf failed for non_pref_list, ret = %d",
5267 ret);
5268 send_resp(dut, conn, SIGMA_ERROR,
5269 "ErrorCode,snprintf failed");
5270 free(dut->non_pref_ch_list);
5271 dut->non_pref_ch_list = NULL;
5272 return 0;
5273 }
5274 }
5275
5276 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
5277 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
5278 if (ret < 0 || ret >= (int) sizeof(buf)) {
5279 sigma_dut_print(dut, DUT_MSG_DEBUG,
5280 "snprintf failed for set non_pref_chan, ret: %d",
5281 ret);
5282 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
5283 return 0;
5284 }
5285
5286 if (wpa_command(intf, buf) < 0) {
5287 send_resp(dut, conn, SIGMA_ERROR,
5288 "ErrorCode,Failed to set non-preferred channel list");
5289 return 0;
5290 }
5291
5292 return 1;
5293}
5294
5295
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005296#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005297
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08005298static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
5299 uint8_t cfg)
5300{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305301 return wcn_wifi_test_config_set_u8(
5302 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
5303 cfg);
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08005304}
5305
5306
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005307static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
5308 enum he_fragmentation_val frag)
5309{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305310 return wcn_wifi_test_config_set_u8(
5311 dut, intf,
5312 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION, frag);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005313}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005314
5315
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08005316int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
5317 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07005318{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305319 return wcn_wifi_test_config_set_u8(
5320 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF, ltf);
Subhani Shaik8e7a3052018-04-24 14:03:00 -07005321}
5322
5323
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005324static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
5325 int noack, enum qca_wlan_ac_type ac)
5326{
5327 struct nl_msg *msg;
5328 int ret = 0;
5329 struct nlattr *params;
5330 int ifindex;
5331
5332 ifindex = if_nametoindex(intf);
5333 if (ifindex == 0) {
5334 sigma_dut_print(dut, DUT_MSG_ERROR,
5335 "%s: Index for interface %s failed",
5336 __func__, intf);
5337 return -1;
5338 }
5339
5340 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5341 NL80211_CMD_VENDOR)) ||
5342 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5343 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5344 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5345 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5346 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5347 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
5348 noack) ||
5349 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
5350 ac)) {
5351 sigma_dut_print(dut, DUT_MSG_ERROR,
5352 "%s: err in adding vendor_cmd and vendor_data",
5353 __func__);
5354 nlmsg_free(msg);
5355 return -1;
5356 }
5357 nla_nest_end(msg, params);
5358
5359 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5360 if (ret) {
5361 sigma_dut_print(dut, DUT_MSG_ERROR,
5362 "%s: err in send_and_recv_msgs, ret=%d",
5363 __func__, ret);
5364 }
5365 return ret;
5366}
5367
5368
5369static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
5370 const char *val)
5371{
5372 int noack, ret;
5373 char token[100];
5374 char *result;
5375 char *saveptr;
5376 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
5377
5378 strlcpy(token, val, sizeof(token));
5379 token[sizeof(token) - 1] = '\0';
5380 result = strtok_r(token, ":", &saveptr);
5381 while (result) {
5382 noack = strcasecmp(result, "Disable") != 0;
5383 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
5384 if (ret) {
5385 sigma_dut_print(dut, DUT_MSG_ERROR,
5386 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
5387 ac, ret);
5388 }
5389 result = strtok_r(NULL, ":", &saveptr);
5390 ac++;
5391 }
5392}
5393
Vinita S. Maloo7462e812020-05-22 15:16:04 +05305394
5395static int nlvendor_sta_set_phymode(struct sigma_dut *dut, const char *intf,
5396 enum qca_wlan_vendor_phy_mode val)
5397{
5398 struct nl_msg *msg;
5399 struct nlattr *params;
5400 int ifindex, ret;
5401
5402 ifindex = if_nametoindex(intf);
5403 if (ifindex == 0) {
5404 sigma_dut_print(dut, DUT_MSG_ERROR,
5405 "%s: Index for interface %s not found",
5406 __func__, intf);
5407 return -1;
5408 }
5409
5410 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5411 NL80211_CMD_VENDOR);
5412 if (!msg) {
5413 sigma_dut_print(dut, DUT_MSG_ERROR,
5414 "%s: err in adding vendor_cmd", __func__);
5415 return -1;
5416 }
5417
5418 if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5419 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5420 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) {
5421 sigma_dut_print(dut, DUT_MSG_ERROR,
5422 "%s: err in adding vendor_attr", __func__);
5423 nlmsg_free(msg);
5424 return -1;
5425 }
5426
5427 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
5428 if (!params || nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_PHY_MODE,
5429 val)) {
5430 sigma_dut_print(dut, DUT_MSG_ERROR,
5431 "%s: err in adding vendor_data", __func__);
5432 nlmsg_free(msg);
5433 return -1;
5434 }
5435
5436 nla_nest_end(msg, params);
5437 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5438 if (ret) {
5439 sigma_dut_print(dut, DUT_MSG_ERROR,
5440 "%s: err in send_and_recv_msgs, ret=%d (%s)",
5441 __func__, ret, strerror(-ret));
5442 return ret;
5443 }
5444
5445 return 0;
5446}
5447
5448
5449static enum qca_wlan_vendor_phy_mode get_qca_vendor_phymode(const char *val)
5450{
5451 if (strcmp(val, "11a") == 0) {
5452 /* IEEE80211_MODE_11A */
5453 return QCA_WLAN_VENDOR_PHY_MODE_11A;
5454 }
5455
5456 if (strcmp(val, "11g") == 0) {
5457 /* IEEE80211_MODE_11G */
5458 return QCA_WLAN_VENDOR_PHY_MODE_11G;
5459 }
5460
5461 if (strcmp(val, "11b") == 0) {
5462 /* IEEE80211_MODE_11B */
5463 return QCA_WLAN_VENDOR_PHY_MODE_11B;
5464 }
5465
5466 if (strcmp(val, "11n") == 0 ||
5467 strcmp(val, "11nl") == 0 ||
5468 strcmp(val, "11nl(nabg)") == 0) {
5469 /* IEEE80211_MODE_11AGN */
5470 return QCA_WLAN_VENDOR_PHY_MODE_11AGN;
5471 }
5472
5473 if (strcmp(val, "11ng") == 0) {
5474 /* IEEE80211_MODE_11NG_HT40 */
5475 return QCA_WLAN_VENDOR_PHY_MODE_11NG_HT40;
5476 }
5477
5478 if (strcmp(val, "AC") == 0 ||
5479 strcasecmp(val, "11AC") == 0) {
5480 /* IEEE80211_MODE_11AC_VHT80 */
5481 return QCA_WLAN_VENDOR_PHY_MODE_11AC_VHT80;
5482 }
5483
5484 if (strcmp(val, "11na") == 0 ||
5485 strcasecmp(val, "11an") == 0) {
5486 /* IEEE80211_MODE_11NA_HT40 */
5487 return QCA_WLAN_VENDOR_PHY_MODE_11NA_HT40;
5488 }
5489
5490 if (strcmp(val, "11ax") == 0 ||
5491 strcmp(val, "auto") == 0) {
5492 /* IEEE80211_MODE_AUTO */
5493 return QCA_WLAN_VENDOR_PHY_MODE_AUTO;
5494 }
5495
5496 return -1;
5497}
5498
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005499#endif /* NL80211_SUPPORT */
5500
5501
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305502static int get_phymode(const char *val)
5503{
5504 if (strcmp(val, "11a") == 0)
5505 return 1; /* IEEE80211_MODE_11A */
5506 if (strcmp(val, "11g") == 0)
5507 return 3; /* IEEE80211_MODE_11G */
5508 if (strcmp(val, "11b") == 0)
5509 return 2; /* IEEE80211_MODE_11B */
5510 if (strcmp(val, "11n") == 0 ||
5511 strcmp(val, "11nl") == 0 ||
5512 strcmp(val, "11nl(nabg)") == 0)
5513 return 22; /* IEEE80211_MODE_11AGN */
5514 if (strcmp(val, "11ng") == 0)
5515 return 13; /* IEEE80211_MODE_11NG_HT40 */
5516 if (strcmp(val, "AC") == 0 ||
5517 strcasecmp(val, "11AC") == 0)
5518 return 19; /* IEEE80211_MODE_11AC_VHT80 */
5519 if (strcmp(val, "11na") == 0 ||
5520 strcasecmp(val, "11an") == 0)
5521 return 14; /* IEEE80211_MODE_11NA_HT40 */
5522 if (strcmp(val, "11ax") == 0 ||
5523 strcmp(val, "auto") == 0)
5524 return 0; /* IEEE80211_MODE_AUTO */
5525 return -1;
5526}
5527
5528
5529static void sta_set_phymode(struct sigma_dut *dut, const char *intf,
5530 const char *val)
5531{
5532 char buf[100];
5533 int len, phymode;
Vinita S. Maloo7462e812020-05-22 15:16:04 +05305534#ifdef NL80211_SUPPORT
5535 enum qca_wlan_vendor_phy_mode qca_phymode;
5536
5537 qca_phymode = get_qca_vendor_phymode(val);
5538 if (qca_phymode == -1) {
5539 sigma_dut_print(dut, DUT_MSG_DEBUG,
5540 "Ignoring mode change for mode: %s",
5541 val);
5542 return;
5543 }
5544
5545 if (nlvendor_sta_set_phymode(dut, intf, qca_phymode) == 0)
5546 return;
5547#endif /* NL80211_SUPPORT */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305548
5549 phymode = get_phymode(val);
5550 if (phymode == -1) {
5551 sigma_dut_print(dut, DUT_MSG_DEBUG,
5552 "Ignoring mode change for mode: %s",
5553 val);
5554 return;
5555 }
5556
5557 len = snprintf(buf, sizeof(buf), "iwpriv %s setphymode %d", intf,
5558 phymode);
5559 if (len < 0 || len >= sizeof(buf)) {
5560 sigma_dut_print(dut, DUT_MSG_ERROR,
5561 "Failed to set phymode");
5562 return;
5563 }
5564
5565 if (system(buf) != 0)
5566 sigma_dut_print(dut, DUT_MSG_ERROR,
5567 "iwpriv setting of phymode failed");
5568}
5569
5570
Jouni Malinenf7222712019-06-13 01:50:21 +03005571static enum sigma_cmd_result
5572cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
5573 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005574{
5575 const char *intf = get_param(cmd, "Interface");
5576 const char *val;
5577
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03005578 val = get_param(cmd, "FT_DS");
5579 if (val) {
5580 if (strcasecmp(val, "Enable") == 0) {
5581 dut->sta_ft_ds = 1;
5582 } else if (strcasecmp(val, "Disable") == 0) {
5583 dut->sta_ft_ds = 0;
5584 } else {
5585 send_resp(dut, conn, SIGMA_ERROR,
5586 "errorCode,Unsupported value for FT_DS");
5587 return STATUS_SENT_ERROR;
5588 }
5589 }
5590
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005591 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03005592 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
5593 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005594 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
5595 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005596
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005597 if (val && strcasecmp(val, "LOC") == 0)
5598 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02005599 if (val && strcasecmp(val, "60GHZ") == 0) {
5600 val = get_param(cmd, "WPS");
5601 if (val && strcasecmp(val, "disable") == 0) {
5602 dut->wps_disable = 1;
5603 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
5604 } else {
5605 /* wps_disable can have other value from the previous
5606 * test, so make sure it has the correct value.
5607 */
5608 dut->wps_disable = 0;
5609 }
5610
5611 val = get_param(cmd, "P2P");
5612 if (val && strcasecmp(val, "disable") == 0)
5613 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
5614 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005615
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02005616 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
5617 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
5618
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005619#ifdef ANDROID_NAN
5620 if (val && strcasecmp(val, "NAN") == 0)
5621 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
5622#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005623#ifdef MIRACAST
5624 if (val && (strcasecmp(val, "WFD") == 0 ||
5625 strcasecmp(val, "DisplayR2") == 0))
5626 return miracast_preset_testparameters(dut, conn, cmd);
5627#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005628
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07005629 if (val &&
5630 (strcasecmp(val, "MBO") == 0 || strcasecmp(val, "HE") == 0)) {
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305631 val = get_param(cmd, "Cellular_Data_Cap");
5632 if (val &&
5633 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
5634 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05305635
5636 val = get_param(cmd, "Ch_Pref");
5637 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
5638 return 0;
5639
Ashwini Patilc63161e2017-04-13 16:30:23 +05305640 val = get_param(cmd, "BSS_Transition");
5641 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
5642 return 0;
5643
Ashwini Patila75de5a2017-04-13 16:35:05 +05305644 val = get_param(cmd, "Assoc_Disallow");
5645 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
5646 return 0;
5647
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305648 val = get_param(cmd, "Roaming");
5649 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
5650 return 0;
5651
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305652 return 1;
5653 }
5654
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305655 if (val && strcasecmp(val, "OCE") == 0)
5656 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
5657
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005658#if 0
5659 val = get_param(cmd, "Supplicant");
5660 if (val && strcasecmp(val, "Default") != 0) {
5661 send_resp(dut, conn, SIGMA_ERROR,
5662 "ErrorCode,Only default(Vendor) supplicant "
5663 "supported");
5664 return 0;
5665 }
5666#endif
5667
5668 val = get_param(cmd, "RTS");
5669 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005670 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005671 case DRIVER_ATHEROS:
5672 ath_sta_set_rts(dut, intf, val);
5673 break;
5674 default:
5675#if 0
5676 send_resp(dut, conn, SIGMA_ERROR,
5677 "ErrorCode,Setting RTS not supported");
5678 return 0;
5679#else
5680 sigma_dut_print(dut, DUT_MSG_DEBUG,
5681 "Setting RTS not supported");
5682 break;
5683#endif
5684 }
5685 }
5686
5687#if 0
5688 val = get_param(cmd, "FRGMNT");
5689 if (val) {
5690 /* TODO */
5691 send_resp(dut, conn, SIGMA_ERROR,
5692 "ErrorCode,Setting FRGMNT not supported");
5693 return 0;
5694 }
5695#endif
5696
5697#if 0
5698 val = get_param(cmd, "Preamble");
5699 if (val) {
5700 /* TODO: Long/Short */
5701 send_resp(dut, conn, SIGMA_ERROR,
5702 "ErrorCode,Setting Preamble not supported");
5703 return 0;
5704 }
5705#endif
5706
5707 val = get_param(cmd, "Mode");
5708 if (val) {
5709 if (strcmp(val, "11b") == 0 ||
5710 strcmp(val, "11g") == 0 ||
5711 strcmp(val, "11a") == 0 ||
5712 strcmp(val, "11n") == 0 ||
5713 strcmp(val, "11ng") == 0 ||
5714 strcmp(val, "11nl") == 0 ||
5715 strcmp(val, "11nl(nabg)") == 0 ||
5716 strcmp(val, "AC") == 0 ||
5717 strcmp(val, "11AC") == 0 ||
5718 strcmp(val, "11ac") == 0 ||
5719 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08005720 strcmp(val, "11an") == 0 ||
5721 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005722 /* STA supports all modes by default */
5723 } else {
5724 send_resp(dut, conn, SIGMA_ERROR,
5725 "ErrorCode,Setting Mode not supported");
5726 return 0;
5727 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005728
5729 /* Change the mode only in case of testbed for HE program
5730 * and for 11a and 11g modes only. */
5731 if (dut->program == PROGRAM_HE &&
5732 dut->device_type == STA_testbed) {
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305733 sta_set_phymode(dut, intf, val);
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005734 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005735 }
5736
5737 val = get_param(cmd, "wmm");
5738 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005739 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005740 case DRIVER_ATHEROS:
5741 ath_sta_set_wmm(dut, intf, val);
5742 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005743 case DRIVER_WCN:
5744 wcn_sta_set_wmm(dut, intf, val);
5745 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005746 default:
5747 sigma_dut_print(dut, DUT_MSG_DEBUG,
5748 "Setting wmm not supported");
5749 break;
5750 }
5751 }
5752
5753 val = get_param(cmd, "Powersave");
5754 if (val) {
5755 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005756 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305757 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005758 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005759 }
5760
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005761 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005762 "P2P_SET ps 0") < 0)
5763 return -2;
5764 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005765 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5766 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005767 } else if (strcmp(val, "1") == 0 ||
5768 strcasecmp(val, "PSPoll") == 0 ||
5769 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005770 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305771 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005772 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005773 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005774 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005775 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005776 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005777 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005778 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005779 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005780 "P2P_SET ps 99") < 0)
5781 return -2;
5782 } else if (strcmp(val, "2") == 0 ||
5783 strcasecmp(val, "Fast") == 0) {
5784 /* TODO */
5785 send_resp(dut, conn, SIGMA_ERROR,
5786 "ErrorCode,Powersave=Fast not supported");
5787 return 0;
5788 } else if (strcmp(val, "3") == 0 ||
5789 strcasecmp(val, "PSNonPoll") == 0) {
5790 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005791 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5792 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005793
5794 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005795 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005796 "P2P_SET ps 1") < 0)
5797 return -2;
5798 } else
5799 return -1;
5800 }
5801
5802 val = get_param(cmd, "NoAck");
5803 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005804 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005805 case DRIVER_ATHEROS:
5806 ath_sta_set_noack(dut, intf, val);
5807 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005808#ifdef NL80211_SUPPORT
5809 case DRIVER_WCN:
5810 wcn_sta_set_noack(dut, intf, val);
5811 break;
5812#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005813 default:
5814 send_resp(dut, conn, SIGMA_ERROR,
5815 "ErrorCode,Setting NoAck not supported");
5816 return 0;
5817 }
5818 }
5819
5820 val = get_param(cmd, "IgnoreChswitchProhibit");
5821 if (val) {
5822 /* TODO: Enabled/disabled */
5823 if (strcasecmp(val, "Enabled") == 0) {
5824 send_resp(dut, conn, SIGMA_ERROR,
5825 "ErrorCode,Enabling IgnoreChswitchProhibit "
5826 "not supported");
5827 return 0;
5828 }
5829 }
5830
5831 val = get_param(cmd, "TDLS");
5832 if (val) {
5833 if (strcasecmp(val, "Disabled") == 0) {
5834 if (wpa_command(intf, "SET tdls_disabled 1")) {
5835 send_resp(dut, conn, SIGMA_ERROR,
5836 "ErrorCode,Failed to disable TDLS");
5837 return 0;
5838 }
5839 } else if (strcasecmp(val, "Enabled") == 0) {
5840 if (wpa_command(intf, "SET tdls_disabled 0")) {
5841 send_resp(dut, conn, SIGMA_ERROR,
5842 "ErrorCode,Failed to enable TDLS");
5843 return 0;
5844 }
5845 } else {
5846 send_resp(dut, conn, SIGMA_ERROR,
5847 "ErrorCode,Unsupported TDLS value");
5848 return 0;
5849 }
5850 }
5851
5852 val = get_param(cmd, "TDLSmode");
5853 if (val) {
5854 if (strcasecmp(val, "Default") == 0) {
5855 wpa_command(intf, "SET tdls_testing 0");
5856 } else if (strcasecmp(val, "APProhibit") == 0) {
5857 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5858 send_resp(dut, conn, SIGMA_ERROR,
5859 "ErrorCode,Failed to enable ignore "
5860 "APProhibit TDLS mode");
5861 return 0;
5862 }
5863 } else if (strcasecmp(val, "HiLoMac") == 0) {
5864 /* STA should respond with TDLS setup req for a TDLS
5865 * setup req */
5866 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5867 send_resp(dut, conn, SIGMA_ERROR,
5868 "ErrorCode,Failed to enable HiLoMac "
5869 "TDLS mode");
5870 return 0;
5871 }
5872 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5873 /*
5874 * Since all security modes are enabled by default when
5875 * Sigma control is used, there is no need to do
5876 * anything here.
5877 */
5878 } else if (strcasecmp(val, "ExistLink") == 0) {
5879 /*
5880 * Since we allow new TDLS Setup Request even if there
5881 * is an existing link, nothing needs to be done for
5882 * this.
5883 */
5884 } else {
5885 /* TODO:
5886 * ExistLink: STA should send TDLS setup req even if
5887 * direct link already exists
5888 */
5889 send_resp(dut, conn, SIGMA_ERROR,
5890 "ErrorCode,Unsupported TDLSmode value");
5891 return 0;
5892 }
5893 }
5894
5895 val = get_param(cmd, "FakePubKey");
5896 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5897 send_resp(dut, conn, SIGMA_ERROR,
5898 "ErrorCode,Failed to enable FakePubKey");
5899 return 0;
5900 }
5901
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005902#ifdef NL80211_SUPPORT
5903 val = get_param(cmd, "FrgmntSupport");
5904 if (val) {
5905 if (strcasecmp(val, "Enable") == 0) {
5906 if (sta_set_he_fragmentation(dut, intf,
5907 HE_FRAG_LEVEL1)) {
5908 send_resp(dut, conn, SIGMA_ERROR,
5909 "ErrorCode,Failed to enable HE Fragmentation");
5910 return 0;
5911 }
5912 } else if (strcasecmp(val, "Disable") == 0) {
5913 if (sta_set_he_fragmentation(dut, intf,
5914 HE_FRAG_DISABLE)) {
5915 send_resp(dut, conn, SIGMA_ERROR,
5916 "ErrorCode,Failed to disable HE Fragmentation");
5917 return 0;
5918 }
5919 }
5920 }
5921#endif /* NL80211_SUPPORT */
5922
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305923 val = get_param(cmd, "IncludeMSCSDescriptor");
5924 if (val && strcasecmp(val, "1") == 0) {
5925 char buf[128];
5926 int len;
5927
5928 len = snprintf(buf, sizeof(buf),
Veerendranath Jakkam62cde372020-08-19 18:03:06 +05305929 "MSCS add up_bitmap=F0 up_limit=7 stream_timeout=60000 frame_classifier=045F%032x",
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305930 0);
5931
5932 if (len < 0 || len >= sizeof(buf)) {
5933 sigma_dut_print(dut, DUT_MSG_ERROR,
5934 "Failed to build MSCS Descriptor IE");
5935 return ERROR_SEND_STATUS;
5936 }
5937
5938 if (wpa_command(intf, buf) != 0) {
5939 send_resp(dut, conn, SIGMA_ERROR,
5940 "ErrorCode,Failed to include MSCS descriptor");
5941 return STATUS_SENT_ERROR;
5942 }
5943 }
5944
Vinita S. Maloo2287f142021-02-01 16:17:09 +05305945 val = get_param(cmd, "SCSSupport");
5946 if (val) {
5947 char buf[30];
5948 int disable_scs, len;
5949
5950 if (strcasecmp(val, "Enable") == 0) {
5951 disable_scs = 0;
5952 } else if (strcasecmp(val, "Disable") == 0) {
5953 disable_scs = 1;
5954 } else {
5955 sigma_dut_print(dut, DUT_MSG_ERROR,
5956 "Invalid SCSsupport parameter");
5957 return INVALID_SEND_STATUS;
5958 }
5959
5960 len = snprintf(buf, sizeof(buf), "SET disable_scs_support %d",
5961 disable_scs);
5962 if (len < 0 || len >= sizeof(buf) ||
5963 wpa_command(intf, buf) != 0) {
5964 send_resp(dut, conn, SIGMA_ERROR,
5965 "ErrorCode,Failed to update SCS support");
5966 return STATUS_SENT_ERROR;
5967 }
5968 }
5969
Vinita S. Maloo83dee552021-04-12 16:47:47 +05305970 val = get_param(cmd, "MSCSSupport");
5971 if (val) {
5972 char buf[30];
5973 int disable_mscs, len;
5974
5975 if (strcasecmp(val, "Enable") == 0) {
5976 disable_mscs = 0;
5977 } else if (strcasecmp(val, "Disable") == 0) {
5978 disable_mscs = 1;
5979 } else {
5980 sigma_dut_print(dut, DUT_MSG_ERROR,
5981 "Invalid MSCSsupport parameter");
5982 return INVALID_SEND_STATUS;
5983 }
5984
5985 len = snprintf(buf, sizeof(buf), "SET disable_mscs_support %d",
5986 disable_mscs);
5987 if (len < 0 || len >= sizeof(buf) ||
5988 wpa_command(intf, buf) != 0) {
5989 send_resp(dut, conn, SIGMA_ERROR,
5990 "ErrorCode,Failed to update MSCS support");
5991 return STATUS_SENT_ERROR;
5992 }
5993 }
5994
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005995 return 1;
5996}
5997
5998
5999static const char * ath_get_radio_name(const char *radio_name)
6000{
6001 if (radio_name == NULL)
6002 return "wifi0";
6003 if (strcmp(radio_name, "wifi1") == 0)
6004 return "wifi1";
6005 if (strcmp(radio_name, "wifi2") == 0)
6006 return "wifi2";
6007 return "wifi0";
6008}
6009
6010
6011static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
6012 const char *val)
6013{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006014 unsigned int vht_mcsmap = 0;
6015 int txchainmask = 0;
6016 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
6017
6018 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
6019 if (dut->testbed_flag_txsp == 1) {
6020 vht_mcsmap = 0xfffc;
6021 dut->testbed_flag_txsp = 0;
6022 } else {
6023 vht_mcsmap = 0xfffe;
6024 }
6025 txchainmask = 1;
6026 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
6027 if (dut->testbed_flag_txsp == 1) {
6028 vht_mcsmap = 0xfff0;
6029 dut->testbed_flag_txsp = 0;
6030 } else {
6031 vht_mcsmap = 0xfffa;
6032 }
6033 txchainmask = 3;
6034 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
6035 if (dut->testbed_flag_txsp == 1) {
6036 vht_mcsmap = 0xffc0;
6037 dut->testbed_flag_txsp = 0;
6038 } else {
6039 vht_mcsmap = 0xffea;
6040 }
6041 txchainmask = 7;
6042 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
6043 if (dut->testbed_flag_txsp == 1) {
6044 vht_mcsmap = 0xff00;
6045 dut->testbed_flag_txsp = 0;
6046 } else {
6047 vht_mcsmap = 0xffaa;
6048 }
6049 txchainmask = 15;
6050 } else {
6051 if (dut->testbed_flag_txsp == 1) {
6052 vht_mcsmap = 0xffc0;
6053 dut->testbed_flag_txsp = 0;
6054 } else {
6055 vht_mcsmap = 0xffea;
6056 }
6057 }
6058
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006059 if (txchainmask)
6060 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006061
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006062 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006063}
6064
6065
6066static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
6067 const char *val)
6068{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006069 unsigned int vht_mcsmap = 0;
6070 int rxchainmask = 0;
6071 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
6072
6073 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
6074 if (dut->testbed_flag_rxsp == 1) {
6075 vht_mcsmap = 0xfffc;
6076 dut->testbed_flag_rxsp = 0;
6077 } else {
6078 vht_mcsmap = 0xfffe;
6079 }
6080 rxchainmask = 1;
6081 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
6082 if (dut->testbed_flag_rxsp == 1) {
6083 vht_mcsmap = 0xfff0;
6084 dut->testbed_flag_rxsp = 0;
6085 } else {
6086 vht_mcsmap = 0xfffa;
6087 }
6088 rxchainmask = 3;
6089 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
6090 if (dut->testbed_flag_rxsp == 1) {
6091 vht_mcsmap = 0xffc0;
6092 dut->testbed_flag_rxsp = 0;
6093 } else {
6094 vht_mcsmap = 0xffea;
6095 }
6096 rxchainmask = 7;
6097 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
6098 if (dut->testbed_flag_rxsp == 1) {
6099 vht_mcsmap = 0xff00;
6100 dut->testbed_flag_rxsp = 0;
6101 } else {
6102 vht_mcsmap = 0xffaa;
6103 }
6104 rxchainmask = 15;
6105 } else {
6106 if (dut->testbed_flag_rxsp == 1) {
6107 vht_mcsmap = 0xffc0;
6108 dut->testbed_flag_rxsp = 0;
6109 } else {
6110 vht_mcsmap = 0xffea;
6111 }
6112 }
6113
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006114 if (rxchainmask)
6115 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006116
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006117 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006118}
6119
6120
6121void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
6122{
6123 if (strcasecmp(val, "enable") == 0) {
6124 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
6125 != 0) {
6126 sigma_dut_print(dut, DUT_MSG_ERROR,
6127 "Disable BB_VHTSIGB_CRC_CALC failed");
6128 }
6129
6130 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
6131 != 0) {
6132 sigma_dut_print(dut, DUT_MSG_ERROR,
6133 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
6134 }
6135 } else {
6136 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
6137 != 0) {
6138 sigma_dut_print(dut, DUT_MSG_ERROR,
6139 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
6140 }
6141
6142 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
6143 != 0) {
6144 sigma_dut_print(dut, DUT_MSG_ERROR,
6145 "Enable BB_VHTSIGB_CRC_CALC failed");
6146 }
6147 }
6148}
6149
6150
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006151static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
6152 const char *val)
6153{
6154 char buf[60];
6155
Shivani Baranwal2a572842021-09-16 12:27:15 +05306156#ifdef NL80211_SUPPORT
6157 enum nl80211_chan_width qca_channel_width;
6158
6159 if (strcmp(val, "20") == 0) {
6160 qca_channel_width = NL80211_CHAN_WIDTH_20;
6161 dut->chwidth = 0;
6162 } else if (strcmp(val, "40") == 0) {
6163 qca_channel_width = NL80211_CHAN_WIDTH_40;
6164 dut->chwidth = 1;
6165 } else if (strcmp(val, "80") == 0) {
6166 qca_channel_width = NL80211_CHAN_WIDTH_80;
6167 dut->chwidth = 2;
6168 } else if (strcmp(val, "160") == 0) {
6169 qca_channel_width = NL80211_CHAN_WIDTH_160;
6170 dut->chwidth = 3;
6171 } else if (strcasecmp(val, "Auto") == 0) {
6172 return 0;
6173 } else {
6174 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
6175 val);
6176 return -1;
6177 }
6178 if (sta_config_params(dut, intf, STA_SET_CHAN_WIDTH,
6179 qca_channel_width) == 0)
6180 return 0;
6181#endif /* NL80211_SUPPORT */
6182
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006183 if (strcmp(val, "20") == 0) {
6184 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
6185 dut->chwidth = 0;
6186 } else if (strcmp(val, "40") == 0) {
6187 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
6188 dut->chwidth = 1;
6189 } else if (strcmp(val, "80") == 0) {
6190 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
6191 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05306192 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006193 buf[0] = '\0';
6194 } else {
6195 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
6196 val);
6197 return -1;
6198 }
6199
6200 if (buf[0] != '\0' && system(buf) != 0) {
6201 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
6202 return -1;
6203 }
6204
6205 return 0;
6206}
6207
6208
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006209static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
6210 const char *intf, int addbareject)
6211{
6212#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05306213 return wcn_wifi_test_config_set_u8(
6214 dut, intf,
6215 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
6216 !addbareject);
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006217#else /* NL80211_SUPPORT */
6218 sigma_dut_print(dut, DUT_MSG_ERROR,
6219 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
6220 return -1;
6221#endif /* NL80211_SUPPORT */
6222}
6223
6224
6225static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
6226 int addbareject)
6227{
6228 int ret;
6229
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006230 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006231 case DRIVER_WCN:
6232 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
6233 if (ret) {
6234 sigma_dut_print(dut, DUT_MSG_ERROR,
6235 "nlvendor_sta_set_addba_reject failed, ret:%d",
6236 ret);
6237 return ret;
6238 }
6239 break;
6240 default:
6241 sigma_dut_print(dut, DUT_MSG_ERROR,
6242 "errorCode,Unsupported ADDBA_REJECT with the current driver");
6243 ret = -1;
6244 break;
6245 }
6246
6247 return ret;
6248}
6249
6250
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08006251static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
6252 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006253{
6254#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05306255 return wcn_wifi_test_config_set_u8(
6256 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
6257 enable);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006258#else /* NL80211_SUPPORT */
6259 sigma_dut_print(dut, DUT_MSG_ERROR,
6260 "Disable addba not possible without NL80211_SUPPORT defined");
6261 return -1;
6262#endif /* NL80211_SUPPORT */
6263}
6264
6265
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306266#ifdef NL80211_SUPPORT
6267static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
6268{
6269 struct nl_msg *msg;
6270 int ret = 0;
6271 int ifindex;
6272
6273 ifindex = if_nametoindex(intf);
6274 if (ifindex == 0) {
6275 sigma_dut_print(dut, DUT_MSG_ERROR,
6276 "%s: Index for interface %s failed",
6277 __func__, intf);
6278 return -1;
6279 }
6280
6281 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6282 NL80211_CMD_SET_WIPHY)) ||
6283 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
6284 sigma_dut_print(dut, DUT_MSG_ERROR,
6285 "%s: err in adding RTS threshold",
6286 __func__);
6287 nlmsg_free(msg);
6288 return -1;
6289 }
6290
6291 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6292 if (ret) {
6293 sigma_dut_print(dut, DUT_MSG_ERROR,
6294 "%s: err in send_and_recv_msgs, ret=%d",
6295 __func__, ret);
6296 }
6297 return ret;
6298}
6299#endif /* NL80211_SUPPORT */
6300
6301
6302static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
6303{
6304 char buf[100];
6305
6306#ifdef NL80211_SUPPORT
6307 if (nl80211_sta_set_rts(dut, intf, val) == 0)
6308 return 0;
6309 sigma_dut_print(dut, DUT_MSG_DEBUG,
6310 "Fall back to using iwconfig for setting RTS threshold");
6311#endif /* NL80211_SUPPORT */
6312
6313 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
6314 if (system(buf) != 0) {
6315 sigma_dut_print(dut, DUT_MSG_ERROR,
6316 "Failed to set RTS threshold %d", val);
6317 return -1;
6318 }
6319 return 0;
6320}
6321
6322
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006323static enum sigma_cmd_result
6324cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
6325 struct sigma_conn *conn, struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006326{
6327 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006328 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006329 char buf[128];
6330 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006331
6332 val = get_param(cmd, "40_INTOLERANT");
6333 if (val) {
6334 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6335 /* TODO: iwpriv ht40intol through wpa_supplicant */
6336 send_resp(dut, conn, SIGMA_ERROR,
6337 "ErrorCode,40_INTOLERANT not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006338 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006339 }
6340 }
6341
6342 val = get_param(cmd, "ADDBA_REJECT");
6343 if (val) {
6344 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6345 /* reject any ADDBA with status "decline" */
6346 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006347 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006348 } else {
6349 /* accept ADDBA */
6350 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006351 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006352 }
6353 }
6354
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006355 if (addbareject >= 0 &&
6356 sta_set_addba_reject(dut, intf, addbareject) < 0) {
6357 send_resp(dut, conn, SIGMA_ERROR,
6358 "ErrorCode,set addba_reject failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006359 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08006360 }
6361
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006362 val = get_param(cmd, "AMPDU");
6363 if (val) {
6364 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6365 /* enable AMPDU Aggregation */
6366 if (ampdu == 0) {
6367 send_resp(dut, conn, SIGMA_ERROR,
6368 "ErrorCode,Mismatch in "
6369 "addba_reject/ampdu - "
6370 "not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006371 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006372 }
6373 ampdu = 1;
6374 } else {
6375 /* disable AMPDU Aggregation */
6376 if (ampdu == 1) {
6377 send_resp(dut, conn, SIGMA_ERROR,
6378 "ErrorCode,Mismatch in "
6379 "addba_reject/ampdu - "
6380 "not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006381 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006382 }
6383 ampdu = 0;
6384 }
6385 }
6386
6387 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006388 int ret;
6389
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006390 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
6391 ampdu ? "Enabling" : "Disabling");
6392 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07006393 if (wpa_command(intf, buf) < 0 &&
6394 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006395 send_resp(dut, conn, SIGMA_ERROR,
6396 "ErrorCode,set aggr failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006397 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006398 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006399
6400 if (ampdu == 0) {
6401 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08006402 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08006403 if (ret) {
6404 sigma_dut_print(dut, DUT_MSG_ERROR,
6405 "Failed to disable addba, ret:%d",
6406 ret);
6407 }
6408 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006409 }
6410
6411 val = get_param(cmd, "AMSDU");
6412 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006413 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006414 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08006415 case DRIVER_WCN:
6416 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006417 break;
6418 default:
6419 if (strcmp(val, "1") == 0 ||
6420 strcasecmp(val, "Enable") == 0) {
6421 /* Enable AMSDU Aggregation */
6422 send_resp(dut, conn, SIGMA_ERROR,
6423 "ErrorCode,AMSDU aggregation not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006424 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006425 }
6426 break;
6427 }
6428 }
6429
6430 val = get_param(cmd, "STBC_RX");
6431 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006432 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006433 case DRIVER_ATHEROS:
6434 ath_sta_set_stbc(dut, intf, val);
6435 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05306436 case DRIVER_WCN:
6437 wcn_sta_set_stbc(dut, intf, val);
6438 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006439 default:
6440 send_resp(dut, conn, SIGMA_ERROR,
6441 "ErrorCode,STBC_RX not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006442 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006443 }
6444 }
6445
6446 val = get_param(cmd, "WIDTH");
6447 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006448 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006449 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08006450 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006451 send_resp(dut, conn, SIGMA_ERROR,
6452 "ErrorCode,Failed to set WIDTH");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006453 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006454 }
6455 break;
6456 case DRIVER_ATHEROS:
6457 if (ath_set_width(dut, conn, intf, val) < 0)
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006458 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006459 break;
6460 default:
6461 sigma_dut_print(dut, DUT_MSG_ERROR,
6462 "Setting WIDTH not supported");
6463 break;
6464 }
6465 }
6466
6467 val = get_param(cmd, "SMPS");
6468 if (val) {
6469 /* TODO: Dynamic/0, Static/1, No Limit/2 */
6470 send_resp(dut, conn, SIGMA_ERROR,
6471 "ErrorCode,SMPS not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006472 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006473 }
6474
6475 val = get_param(cmd, "TXSP_STREAM");
6476 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006477 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006478 case DRIVER_WCN:
6479 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
6480 send_resp(dut, conn, SIGMA_ERROR,
6481 "ErrorCode,Failed to set TXSP_STREAM");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006482 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006483 }
6484 break;
6485 case DRIVER_ATHEROS:
6486 ath_sta_set_txsp_stream(dut, intf, val);
6487 break;
6488 default:
6489 sigma_dut_print(dut, DUT_MSG_ERROR,
6490 "Setting TXSP_STREAM not supported");
6491 break;
6492 }
6493 }
6494
6495 val = get_param(cmd, "RXSP_STREAM");
6496 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006497 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006498 case DRIVER_WCN:
6499 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
6500 send_resp(dut, conn, SIGMA_ERROR,
6501 "ErrorCode,Failed to set RXSP_STREAM");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006502 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006503 }
6504 break;
6505 case DRIVER_ATHEROS:
6506 ath_sta_set_rxsp_stream(dut, intf, val);
6507 break;
6508 default:
6509 sigma_dut_print(dut, DUT_MSG_ERROR,
6510 "Setting RXSP_STREAM not supported");
6511 break;
6512 }
6513 }
6514
6515 val = get_param(cmd, "DYN_BW_SGNL");
6516 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006517 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006518 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08006519 if (strcasecmp(val, "enable") == 0) {
6520 snprintf(buf, sizeof(buf),
6521 "iwpriv %s cwmenable 1", intf);
6522 if (system(buf) != 0) {
6523 sigma_dut_print(dut, DUT_MSG_ERROR,
6524 "iwpriv cwmenable 1 failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006525 return ERROR_SEND_STATUS;
Peng Xuc59afd32016-11-21 15:01:11 -08006526 }
6527 } else if (strcasecmp(val, "disable") == 0) {
6528 snprintf(buf, sizeof(buf),
6529 "iwpriv %s cwmenable 0", intf);
6530 if (system(buf) != 0) {
6531 sigma_dut_print(dut, DUT_MSG_ERROR,
6532 "iwpriv cwmenable 0 failed");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006533 return ERROR_SEND_STATUS;
Peng Xuc59afd32016-11-21 15:01:11 -08006534 }
6535 } else {
6536 sigma_dut_print(dut, DUT_MSG_ERROR,
6537 "Unsupported DYN_BW_SGL");
6538 }
6539
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006540 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
6541 if (system(buf) != 0) {
6542 sigma_dut_print(dut, DUT_MSG_ERROR,
6543 "Failed to set cts_cbw in DYN_BW_SGNL");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006544 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006545 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006546 break;
6547 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006548 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006549 ath_config_dyn_bw_sig(dut, intf, val);
6550 break;
6551 default:
6552 sigma_dut_print(dut, DUT_MSG_ERROR,
6553 "Failed to set DYN_BW_SGNL");
6554 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006555 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006556 }
6557
6558 val = get_param(cmd, "RTS_FORCE");
6559 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006560 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006561 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306562 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006563 sigma_dut_print(dut, DUT_MSG_ERROR,
6564 "Failed to set RTS_FORCE 64");
6565 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03006566 res = snprintf(buf, sizeof(buf),
6567 "wifitool %s beeliner_fw_test 100 1",
6568 intf);
6569 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08006570 sigma_dut_print(dut, DUT_MSG_ERROR,
6571 "wifitool beeliner_fw_test 100 1 failed");
6572 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006573 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306574 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006575 sigma_dut_print(dut, DUT_MSG_ERROR,
6576 "Failed to set RTS_FORCE 2347");
6577 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006578 } else {
6579 send_resp(dut, conn, SIGMA_ERROR,
6580 "ErrorCode,RTS_FORCE value not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006581 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006582 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006583 }
6584
6585 val = get_param(cmd, "CTS_WIDTH");
6586 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006587 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006588 case DRIVER_WCN:
6589 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
6590 send_resp(dut, conn, SIGMA_ERROR,
6591 "ErrorCode,Failed to set CTS_WIDTH");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006592 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006593 }
6594 break;
6595 case DRIVER_ATHEROS:
6596 ath_set_cts_width(dut, intf, val);
6597 break;
6598 default:
6599 sigma_dut_print(dut, DUT_MSG_ERROR,
6600 "Setting CTS_WIDTH not supported");
6601 break;
6602 }
6603 }
6604
6605 val = get_param(cmd, "BW_SGNL");
6606 if (val) {
6607 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006608 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006609 } else if (strcasecmp(val, "Disable") == 0) {
6610 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006611 } else {
6612 send_resp(dut, conn, SIGMA_ERROR,
6613 "ErrorCode,BW_SGNL value not supported");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006614 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006615 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006616 }
6617
6618 val = get_param(cmd, "Band");
6619 if (val) {
6620 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
6621 /* STA supports all bands by default */
6622 } else {
6623 send_resp(dut, conn, SIGMA_ERROR,
6624 "ErrorCode,Unsupported Band");
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006625 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006626 }
6627 }
6628
6629 val = get_param(cmd, "zero_crc");
6630 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006631 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006632 case DRIVER_ATHEROS:
6633 ath_set_zero_crc(dut, val);
6634 break;
6635 default:
6636 break;
6637 }
6638 }
6639
Jouni Malinen3d96a1e2021-06-09 16:45:06 +03006640 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006641}
6642
6643
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006644static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
6645{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006646 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006647#ifdef __linux__
6648 case DRIVER_WIL6210:
6649 return wil6210_set_force_mcs(dut, force, mcs);
6650#endif /* __linux__ */
6651 default:
6652 sigma_dut_print(dut, DUT_MSG_ERROR,
6653 "Unsupported sta_set_force_mcs with the current driver");
6654 return -1;
6655 }
6656}
6657
6658
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006659static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
6660{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006661 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006662#ifdef __linux__
6663 case DRIVER_WIL6210:
6664 return wil6210_force_rsn_ie(dut, state);
6665#endif /* __linux__ */
6666 default:
6667 sigma_dut_print(dut, DUT_MSG_ERROR,
6668 "Unsupported sta_60g_force_rsn_ie with the current driver");
6669 return -1;
6670 }
6671}
6672
6673
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006674static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
6675 struct sigma_cmd *cmd)
6676{
6677 const char *val;
6678 char buf[100];
6679
6680 val = get_param(cmd, "MSDUSize");
6681 if (val) {
6682 int mtu;
6683
6684 dut->amsdu_size = atoi(val);
6685 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
6686 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
6687 sigma_dut_print(dut, DUT_MSG_ERROR,
6688 "MSDUSize %d is above max %d or below min %d",
6689 dut->amsdu_size,
6690 IEEE80211_MAX_DATA_LEN_DMG,
6691 IEEE80211_SNAP_LEN_DMG);
6692 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006693 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006694 }
6695
6696 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
6697 sigma_dut_print(dut, DUT_MSG_DEBUG,
6698 "Setting amsdu_size to %d", mtu);
6699 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006700 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006701
6702 if (system(buf) != 0) {
6703 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
6704 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006705 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006706 }
6707 }
6708
6709 val = get_param(cmd, "BAckRcvBuf");
6710 if (val) {
6711 dut->back_rcv_buf = atoi(val);
6712 if (dut->back_rcv_buf == 0) {
6713 sigma_dut_print(dut, DUT_MSG_ERROR,
6714 "Failed to convert %s or value is 0",
6715 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006716 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006717 }
6718
6719 sigma_dut_print(dut, DUT_MSG_DEBUG,
6720 "Setting BAckRcvBuf to %s", val);
6721 }
6722
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006723 val = get_param(cmd, "MCS_FixedRate");
6724 if (val) {
6725 if (sta_set_force_mcs(dut, 1, atoi(val))) {
6726 sigma_dut_print(dut, DUT_MSG_ERROR,
6727 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006728 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006729 }
6730 }
6731
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006732 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006733}
6734
6735
6736static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
6737 struct sigma_cmd *cmd)
6738{
6739 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006740 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006741 const char *val;
6742 char buf[100];
6743
6744 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006745 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006746 if (wpa_command(ifname, "PING") != 0) {
6747 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006748 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006749 }
6750
6751 wpa_command(ifname, "FLUSH");
6752 net_id = add_network_common(dut, conn, ifname, cmd);
6753 if (net_id < 0) {
6754 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
6755 return net_id;
6756 }
6757
6758 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
6759 if (set_network(ifname, net_id, "mode", "2") < 0) {
6760 sigma_dut_print(dut, DUT_MSG_ERROR,
6761 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006762 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006763 }
6764
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006765 if (set_network(ifname, net_id, "pbss", "1") < 0)
6766 return -2;
6767
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006768 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006769 "Supplicant set network with mode 2. network_id %d",
6770 net_id);
6771
6772 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6773 sigma_dut_print(dut, DUT_MSG_INFO,
6774 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006775 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006776 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006777
6778 val = get_param(cmd, "Security");
6779 if (val && strcasecmp(val, "OPEN") == 0) {
6780 dut->ap_key_mgmt = AP_OPEN;
6781 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6782 sigma_dut_print(dut, DUT_MSG_ERROR,
6783 "Failed to set supplicant to %s security",
6784 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006785 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006786 }
6787 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6788 dut->ap_key_mgmt = AP_WPA2_PSK;
6789 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6790 sigma_dut_print(dut, DUT_MSG_ERROR,
6791 "Failed to set supplicant to %s security",
6792 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006793 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006794 }
6795
6796 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6797 sigma_dut_print(dut, DUT_MSG_ERROR,
6798 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006799 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006800 }
6801 } else if (val) {
6802 sigma_dut_print(dut, DUT_MSG_ERROR,
6803 "Requested Security %s is not supported on 60GHz",
6804 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006805 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006806 }
6807
6808 val = get_param(cmd, "Encrypt");
6809 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6810 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6811 sigma_dut_print(dut, DUT_MSG_ERROR,
6812 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006813 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006814 }
6815 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6816 sigma_dut_print(dut, DUT_MSG_ERROR,
6817 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006818 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006819 }
6820 } else if (val) {
6821 sigma_dut_print(dut, DUT_MSG_ERROR,
6822 "Requested Encrypt %s is not supported on 60 GHz",
6823 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006824 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006825 }
6826
6827 val = get_param(cmd, "PSK");
6828 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6829 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6830 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006831 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006832 }
6833
6834 /* Convert 60G channel to freq */
6835 switch (dut->ap_channel) {
6836 case 1:
6837 val = "58320";
6838 break;
6839 case 2:
6840 val = "60480";
6841 break;
6842 case 3:
6843 val = "62640";
6844 break;
6845 default:
6846 sigma_dut_print(dut, DUT_MSG_ERROR,
6847 "Failed to configure channel %d. Not supported",
6848 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006849 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006850 }
6851
6852 if (set_network(ifname, net_id, "frequency", val) < 0) {
6853 sigma_dut_print(dut, DUT_MSG_ERROR,
6854 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006855 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006856 }
6857
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006858 if (dut->eap_fragment) {
6859 sigma_dut_print(dut, DUT_MSG_DEBUG,
6860 "Set EAP fragment size to 128 bytes.");
6861 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6862 return ERROR_SEND_STATUS;
6863 }
6864
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006865 sigma_dut_print(dut, DUT_MSG_DEBUG,
6866 "Supplicant set network with frequency");
6867
6868 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6869 if (wpa_command(ifname, buf) < 0) {
6870 sigma_dut_print(dut, DUT_MSG_INFO,
6871 "Failed to select network id %d on %s",
6872 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006873 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006874 }
6875
6876 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6877
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006878 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006879}
6880
6881
Lior David67543f52017-01-03 19:04:22 +02006882static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6883{
6884 char buf[128], fname[128];
6885 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006886 int res;
Lior David67543f52017-01-03 19:04:22 +02006887
6888 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6889 sigma_dut_print(dut, DUT_MSG_ERROR,
6890 "failed to get wil6210 debugfs dir");
6891 return -1;
6892 }
6893
Jouni Malinen3aa72862019-05-29 23:14:51 +03006894 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6895 if (res < 0 || res >= sizeof(fname))
6896 return -1;
Lior David67543f52017-01-03 19:04:22 +02006897 f = fopen(fname, "w");
6898 if (!f) {
6899 sigma_dut_print(dut, DUT_MSG_ERROR,
6900 "failed to open: %s", fname);
6901 return -1;
6902 }
6903
6904 fprintf(f, "%d\n", abft_len);
6905 fclose(f);
6906
6907 return 0;
6908}
6909
6910
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006911int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6912 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006913{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006914 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006915 case DRIVER_WIL6210:
6916 return wil6210_set_abft_len(dut, abft_len);
6917 default:
6918 sigma_dut_print(dut, DUT_MSG_ERROR,
6919 "set abft_len not supported");
6920 return -1;
6921 }
6922}
6923
6924
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006925static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6926 struct sigma_cmd *cmd)
6927{
6928 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006929 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006930
6931 if (dut->dev_role != DEVROLE_PCP) {
6932 send_resp(dut, conn, SIGMA_INVALID,
6933 "ErrorCode,Invalid DevRole");
6934 return 0;
6935 }
6936
6937 val = get_param(cmd, "SSID");
6938 if (val) {
6939 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6940 send_resp(dut, conn, SIGMA_INVALID,
6941 "ErrorCode,Invalid SSID");
6942 return -1;
6943 }
6944
Peng Xub8fc5cc2017-05-10 17:27:28 -07006945 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006946 }
6947
6948 val = get_param(cmd, "CHANNEL");
6949 if (val) {
6950 const char *pos;
6951
6952 dut->ap_channel = atoi(val);
6953 pos = strchr(val, ';');
6954 if (pos) {
6955 pos++;
6956 dut->ap_channel_1 = atoi(pos);
6957 }
6958 }
6959
6960 switch (dut->ap_channel) {
6961 case 1:
6962 case 2:
6963 case 3:
6964 break;
6965 default:
6966 sigma_dut_print(dut, DUT_MSG_ERROR,
6967 "Channel %d is not supported", dut->ap_channel);
6968 send_resp(dut, conn, SIGMA_ERROR,
6969 "Requested channel is not supported");
6970 return -1;
6971 }
6972
6973 val = get_param(cmd, "BCNINT");
6974 if (val)
6975 dut->ap_bcnint = atoi(val);
6976
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006977 val = get_param(cmd, "AllocType");
6978 if (val) {
6979 send_resp(dut, conn, SIGMA_ERROR,
6980 "ErrorCode,AllocType is not supported yet");
6981 return -1;
6982 }
6983
6984 val = get_param(cmd, "PercentBI");
6985 if (val) {
6986 send_resp(dut, conn, SIGMA_ERROR,
6987 "ErrorCode,PercentBI is not supported yet");
6988 return -1;
6989 }
6990
6991 val = get_param(cmd, "CBAPOnly");
6992 if (val) {
6993 send_resp(dut, conn, SIGMA_ERROR,
6994 "ErrorCode,CBAPOnly is not supported yet");
6995 return -1;
6996 }
6997
6998 val = get_param(cmd, "AMPDU");
6999 if (val) {
7000 if (strcasecmp(val, "Enable") == 0)
7001 dut->ap_ampdu = 1;
7002 else if (strcasecmp(val, "Disable") == 0)
7003 dut->ap_ampdu = 2;
7004 else {
7005 send_resp(dut, conn, SIGMA_ERROR,
7006 "ErrorCode,AMPDU value is not Enable nor Disabled");
7007 return -1;
7008 }
7009 }
7010
7011 val = get_param(cmd, "AMSDU");
7012 if (val) {
7013 if (strcasecmp(val, "Enable") == 0)
7014 dut->ap_amsdu = 1;
7015 else if (strcasecmp(val, "Disable") == 0)
7016 dut->ap_amsdu = 2;
7017 }
7018
7019 val = get_param(cmd, "NumMSDU");
7020 if (val) {
7021 send_resp(dut, conn, SIGMA_ERROR,
7022 "ErrorCode, NumMSDU is not supported yet");
7023 return -1;
7024 }
7025
7026 val = get_param(cmd, "ABFTLRang");
7027 if (val) {
7028 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02007029 "ABFTLRang parameter %s", val);
7030 if (strcmp(val, "Gt1") == 0)
7031 abft_len = 2; /* 2 slots in this case */
7032 }
7033
7034 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
7035 send_resp(dut, conn, SIGMA_ERROR,
7036 "ErrorCode, Can't set ABFT length");
7037 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007038 }
7039
7040 if (sta_pcp_start(dut, conn, cmd) < 0) {
7041 send_resp(dut, conn, SIGMA_ERROR,
7042 "ErrorCode, Can't start PCP role");
7043 return -1;
7044 }
7045
7046 return sta_set_60g_common(dut, conn, cmd);
7047}
7048
7049
7050static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
7051 struct sigma_cmd *cmd)
7052{
7053 const char *val = get_param(cmd, "DiscoveryMode");
7054
7055 if (dut->dev_role != DEVROLE_STA) {
7056 send_resp(dut, conn, SIGMA_INVALID,
7057 "ErrorCode,Invalid DevRole");
7058 return 0;
7059 }
7060
7061 if (val) {
7062 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
7063 /* Ignore Discovery mode till Driver expose API. */
7064#if 0
7065 if (strcasecmp(val, "1") == 0) {
7066 send_resp(dut, conn, SIGMA_INVALID,
7067 "ErrorCode,DiscoveryMode 1 not supported");
7068 return 0;
7069 }
7070
7071 if (strcasecmp(val, "0") == 0) {
7072 /* OK */
7073 } else {
7074 send_resp(dut, conn, SIGMA_INVALID,
7075 "ErrorCode,DiscoveryMode not supported");
7076 return 0;
7077 }
7078#endif
7079 }
7080
7081 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007082 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007083 return sta_set_60g_common(dut, conn, cmd);
7084}
7085
7086
Jouni Malinenf7222712019-06-13 01:50:21 +03007087static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
7088 struct sigma_conn *conn,
7089 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007090{
7091 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02007092 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05307093
Jouni Malinened77e672018-01-10 16:45:13 +02007094 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08007095 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02007096 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05307097 wpa_command(intf, "DISCONNECT");
7098 return 1;
7099 }
7100
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007101 disconnect_station(dut);
7102 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
7103 * due to cached results. */
7104 wpa_command(intf, "SET ignore_old_scan_res 1");
7105 wpa_command(intf, "BSS_FLUSH");
7106 return 1;
7107}
7108
7109
Jouni Malinenf7222712019-06-13 01:50:21 +03007110static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
7111 struct sigma_conn *conn,
7112 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007113{
7114 const char *intf = get_param(cmd, "Interface");
7115 const char *bssid = get_param(cmd, "bssid");
7116 const char *val = get_param(cmd, "CHANNEL");
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007117 const char *freq_val = get_param(cmd, "ChnlFreq");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007118 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05307119 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05307120 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007121 int res;
7122 int chan = 0;
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007123 int freq = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007124 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05307125 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007126 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007127
7128 if (bssid == NULL) {
7129 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
7130 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007131 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007132 }
7133
7134 if (val)
7135 chan = atoi(val);
7136
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007137 if (freq_val)
7138 freq = atoi(freq_val);
7139
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007140 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
7141 /* The current network may be from sta_associate or
7142 * sta_hs2_associate
7143 */
7144 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
7145 0 ||
7146 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007147 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007148 }
7149
7150 ctrl = open_wpa_mon(intf);
7151 if (ctrl == NULL) {
7152 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
7153 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007154 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007155 }
7156
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007157 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05307158 sizeof(result)) < 0 ||
7159 strncmp(result, "COMPLETED", 9) != 0) {
7160 sigma_dut_print(dut, DUT_MSG_DEBUG,
7161 "sta_reassoc: Not connected");
7162 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007163 } else if (dut->sta_ft_ds) {
7164 sigma_dut_print(dut, DUT_MSG_DEBUG,
7165 "sta_reassoc: Use FT-over-DS");
7166 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05307167 }
7168
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05307169 if (dut->rsne_override) {
7170#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007171 if (get_driver_type(dut) == DRIVER_WCN &&
7172 dut->config_rsnie == 0) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05307173 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05307174 dut->config_rsnie = 1;
7175 }
7176#endif /* NL80211_SUPPORT */
7177 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
7178 dut->rsne_override);
7179 if (wpa_command(intf, buf) < 0) {
7180 send_resp(dut, conn, SIGMA_ERROR,
7181 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
7182 return 0;
7183 }
7184 }
7185
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007186 if (ft_ds) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007187 if (chan || freq) {
7188 if (!freq)
7189 freq = channel_to_freq(dut, chan);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007190 if (!freq) {
7191 sigma_dut_print(dut, DUT_MSG_ERROR,
7192 "Invalid channel number provided: %d",
7193 chan);
7194 send_resp(dut, conn, SIGMA_INVALID,
7195 "ErrorCode,Invalid channel number");
7196 goto close_mon_conn;
7197 }
7198 res = snprintf(buf, sizeof(buf),
7199 "SCAN TYPE=ONLY freq=%d", freq);
7200 } else {
7201 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
7202 }
7203 if (res < 0 || res >= (int) sizeof(buf)) {
7204 send_resp(dut, conn, SIGMA_ERROR,
7205 "ErrorCode,snprintf failed");
7206 goto close_mon_conn;
7207 }
7208 if (wpa_command(intf, buf) < 0) {
7209 sigma_dut_print(dut, DUT_MSG_INFO,
7210 "Failed to start scan");
7211 send_resp(dut, conn, SIGMA_ERROR,
7212 "ErrorCode,scan failed");
7213 goto close_mon_conn;
7214 }
7215
7216 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
7217 buf, sizeof(buf));
7218 if (res < 0) {
7219 sigma_dut_print(dut, DUT_MSG_INFO,
7220 "Scan did not complete");
7221 send_resp(dut, conn, SIGMA_ERROR,
7222 "ErrorCode,scan did not complete");
7223 goto close_mon_conn;
7224 }
7225
7226 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
7227 if (res > 0 && res < (int) sizeof(buf))
7228 res = wpa_command(intf, buf);
7229
7230 if (res < 0 || res >= (int) sizeof(buf)) {
7231 send_resp(dut, conn, SIGMA_ERROR,
7232 "errorCode,FT_DS command failed");
7233 status = STATUS_SENT_ERROR;
7234 goto close_mon_conn;
7235 }
7236 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07007237 if (chan || freq) {
7238 if (!freq)
7239 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05307240 if (!freq) {
7241 sigma_dut_print(dut, DUT_MSG_ERROR,
7242 "Invalid channel number provided: %d",
7243 chan);
7244 send_resp(dut, conn, SIGMA_INVALID,
7245 "ErrorCode,Invalid channel number");
7246 goto close_mon_conn;
7247 }
7248 res = snprintf(buf, sizeof(buf),
7249 "SCAN TYPE=ONLY freq=%d", freq);
7250 } else {
7251 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
7252 }
7253 if (res < 0 || res >= (int) sizeof(buf)) {
7254 send_resp(dut, conn, SIGMA_ERROR,
7255 "ErrorCode,snprintf failed");
7256 goto close_mon_conn;
7257 }
7258 if (wpa_command(intf, buf) < 0) {
7259 sigma_dut_print(dut, DUT_MSG_INFO,
7260 "Failed to start scan");
7261 send_resp(dut, conn, SIGMA_ERROR,
7262 "ErrorCode,scan failed");
7263 goto close_mon_conn;
7264 }
7265
7266 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
7267 buf, sizeof(buf));
7268 if (res < 0) {
7269 sigma_dut_print(dut, DUT_MSG_INFO,
7270 "Scan did not complete");
7271 send_resp(dut, conn, SIGMA_ERROR,
7272 "ErrorCode,scan did not complete");
7273 goto close_mon_conn;
7274 }
7275
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007276 if (set_network(intf, dut->infra_network_id, "bssid", "any")
7277 < 0) {
7278 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
7279 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007280 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05307281 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007282 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05307283 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007284 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05307285 if (res < 0 || res >= (int) sizeof(buf) ||
7286 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007287 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05307288 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05307289 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007290 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007291 sigma_dut_print(dut, DUT_MSG_INFO,
7292 "sta_reassoc: Run %s successful", buf);
7293 } else if (wpa_command(intf, "REASSOCIATE")) {
7294 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
7295 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05307296 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007297 }
7298
7299 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
7300 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05307301 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007302 send_resp(dut, conn, SIGMA_ERROR,
7303 "errorCode,Connection did not complete");
7304 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05307305 goto close_mon_conn;
7306 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007307 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007308
Ashwini Patil467efef2017-05-25 12:18:27 +05307309close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007310 wpa_ctrl_detach(ctrl);
7311 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05307312 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007313}
7314
7315
7316static void hs2_clear_credentials(const char *intf)
7317{
7318 wpa_command(intf, "REMOVE_CRED all");
7319}
7320
7321
Lior Davidcc88b562017-01-03 18:52:09 +02007322#ifdef __linux__
7323static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
7324 unsigned int *aid)
7325{
Lior David0fe101e2017-03-09 16:09:50 +02007326 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02007327
Lior David0fe101e2017-03-09 16:09:50 +02007328 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02007329}
7330#endif /* __linux__ */
7331
7332
7333static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
7334 unsigned int *aid)
7335{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007336 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02007337#ifdef __linux__
7338 case DRIVER_WIL6210:
7339 return wil6210_get_aid(dut, bssid, aid);
7340#endif /* __linux__ */
7341 default:
7342 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
7343 return -1;
7344 }
7345}
7346
7347
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007348static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
7349 struct sigma_cmd *cmd)
7350{
7351 char buf[MAX_CMD_LEN];
7352 char bss_list[MAX_CMD_LEN];
7353 const char *parameter = get_param(cmd, "Parameter");
7354
7355 if (parameter == NULL)
7356 return -1;
7357
Lior Davidcc88b562017-01-03 18:52:09 +02007358 if (strcasecmp(parameter, "AID") == 0) {
7359 unsigned int aid = 0;
7360 char bssid[20];
7361
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007362 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02007363 bssid, sizeof(bssid)) < 0) {
7364 sigma_dut_print(dut, DUT_MSG_ERROR,
7365 "could not get bssid");
7366 return -2;
7367 }
7368
7369 if (sta_get_aid_60g(dut, bssid, &aid))
7370 return -2;
7371
7372 snprintf(buf, sizeof(buf), "aid,%d", aid);
7373 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
7374 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7375 return 0;
7376 }
7377
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007378 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
7379 char *bss_line;
7380 char *bss_id = NULL;
7381 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307382 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007383
7384 if (ifname == NULL) {
7385 sigma_dut_print(dut, DUT_MSG_INFO,
7386 "For get DiscoveredDevList need Interface name.");
7387 return -1;
7388 }
7389
7390 /*
7391 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
7392 * of BSSIDs in "bssid=<BSSID>\n"
7393 */
7394 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
7395 bss_list,
7396 sizeof(bss_list)) < 0) {
7397 sigma_dut_print(dut, DUT_MSG_ERROR,
7398 "Failed to get bss list");
7399 return -1;
7400 }
7401
7402 sigma_dut_print(dut, DUT_MSG_DEBUG,
7403 "bss list for ifname:%s is:%s",
7404 ifname, bss_list);
7405
7406 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307407 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007408 while (bss_line) {
7409 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
7410 bss_id) {
7411 int len;
7412
7413 len = snprintf(buf + strlen(buf),
7414 sizeof(buf) - strlen(buf),
7415 ",%s", bss_id);
7416 free(bss_id);
7417 bss_id = NULL;
7418 if (len < 0) {
7419 sigma_dut_print(dut,
7420 DUT_MSG_ERROR,
7421 "Failed to read BSSID");
7422 send_resp(dut, conn, SIGMA_ERROR,
7423 "ErrorCode,Failed to read BSS ID");
7424 return 0;
7425 }
7426
7427 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
7428 sigma_dut_print(dut,
7429 DUT_MSG_ERROR,
7430 "Response buf too small for list");
7431 send_resp(dut, conn,
7432 SIGMA_ERROR,
7433 "ErrorCode,Response buf too small for list");
7434 return 0;
7435 }
7436 }
7437
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307438 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007439 }
7440
7441 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
7442 buf);
7443 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7444 return 0;
7445 }
7446
7447 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7448 return 0;
7449}
7450
7451
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007452static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
7453 struct sigma_cmd *cmd)
7454{
7455 char buf[MAX_CMD_LEN];
7456 const char *parameter = get_param(cmd, "Parameter");
7457
7458 if (!parameter)
7459 return -1;
7460
7461 if (strcasecmp(parameter, "RSSI") == 0) {
7462 char rssi[10];
7463
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007464 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007465 rssi, sizeof(rssi)) < 0) {
7466 sigma_dut_print(dut, DUT_MSG_ERROR,
7467 "Could not get RSSI");
7468 return -2;
7469 }
7470
7471 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
7472 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
7473 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7474 return 0;
7475 }
7476
7477 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7478 return 0;
7479}
7480
7481
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05307482#ifdef NL80211_SUPPORT
7483
7484struct station_info {
7485 uint64_t filled;
7486 uint32_t beacon_mic_error_count;
7487 uint32_t beacon_replay_count;
7488};
7489
7490
7491static int qca_get_sta_info_handler(struct nl_msg *msg, void *arg)
7492{
7493 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7494 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7495 struct station_info *data = arg;
7496 struct nlattr *info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1];
7497 static struct nla_policy info_policy[
7498 QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1] = {
7499 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT] = {
7500 .type = NLA_U32
7501 },
7502 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT] = {
7503 .type = NLA_U32
7504 },
7505 };
7506
7507 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7508 genlmsg_attrlen(gnlh, 0), NULL);
7509
7510 if (!tb[NL80211_ATTR_VENDOR_DATA])
7511 return NL_SKIP;
7512
7513 if (nla_parse_nested(info, QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX,
7514 tb[NL80211_ATTR_VENDOR_DATA], info_policy)) {
7515 return NL_SKIP;
7516 }
7517
7518 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]) {
7519 data->filled |=
7520 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT);
7521 data->beacon_mic_error_count =
7522 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]);
7523 }
7524
7525 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]) {
7526 data->filled |=
7527 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT);
7528 data->beacon_replay_count =
7529 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]);
7530 }
7531
7532 return NL_SKIP;
7533}
7534
7535
7536static int qca_nl80211_get_sta_info(struct sigma_dut *dut, const char *intf,
7537 struct station_info *sta_data)
7538{
7539 struct nl_msg *msg;
7540 int ifindex, ret;
7541
7542 ifindex = if_nametoindex(intf);
7543 if (ifindex == 0) {
7544 sigma_dut_print(dut, DUT_MSG_ERROR,
7545 "%s: Index for interface %s not found",
7546 __func__, intf);
7547 return -1;
7548 }
7549
7550 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7551 NL80211_CMD_VENDOR)) ||
7552 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7553 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7554 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7555 QCA_NL80211_VENDOR_SUBCMD_GET_STA_INFO)) {
7556 sigma_dut_print(dut, DUT_MSG_ERROR,
7557 "%s: err in adding vendor_cmd", __func__);
7558 nlmsg_free(msg);
7559 return -1;
7560 }
7561
7562 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg,
7563 qca_get_sta_info_handler, sta_data);
7564 if (ret) {
7565 sigma_dut_print(dut, DUT_MSG_ERROR,
7566 "%s: err in send_and_recv_msgs, ret=%d",
7567 __func__, ret);
7568 }
7569 return ret;
7570}
7571#endif /* NL80211_SUPPORT */
7572
7573
7574static int get_bip_mic_error_count(struct sigma_dut *dut,
7575 const char *ifname,
7576 unsigned int *count)
7577{
7578#ifdef NL80211_SUPPORT
7579 struct station_info sta_data;
7580#endif /* NL80211_SUPPORT */
7581
7582 if (get_driver_type(dut) != DRIVER_WCN) {
7583 sigma_dut_print(dut, DUT_MSG_ERROR,
7584 "BIP MIC error count not supported");
7585 return -1;
7586 }
7587
7588#ifdef NL80211_SUPPORT
7589 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
7590 !(sta_data.filled &
7591 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT))) {
7592 sigma_dut_print(dut, DUT_MSG_ERROR,
7593 "BIP MIC error count fetching failed");
7594 return -1;
7595 }
7596
7597 *count = sta_data.beacon_mic_error_count;
7598 return 0;
7599#else /* NL80211_SUPPORT */
7600 sigma_dut_print(dut, DUT_MSG_ERROR,
7601 "BIP MIC error count cannot be fetched without NL80211_SUPPORT defined");
7602 return -1;
7603#endif /* NL80211_SUPPORT */
7604}
7605
7606
7607static int get_cmac_replay_count(struct sigma_dut *dut, const char *ifname,
7608 unsigned int *count)
7609{
7610#ifdef NL80211_SUPPORT
7611 struct station_info sta_data;
7612#endif /* NL80211_SUPPORT */
7613
7614 if (get_driver_type(dut) != DRIVER_WCN) {
7615 sigma_dut_print(dut, DUT_MSG_ERROR,
7616 "CMAC reply count not supported");
7617 return -1;
7618 }
7619
7620#ifdef NL80211_SUPPORT
7621 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
7622 !(sta_data.filled &
7623 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT))) {
7624 sigma_dut_print(dut, DUT_MSG_ERROR,
7625 "CMAC replay count fetching failed");
7626 return -1;
7627 }
7628
7629 *count = sta_data.beacon_replay_count;
7630 return 0;
7631#else /* NL80211_SUPPORT */
7632 sigma_dut_print(dut, DUT_MSG_ERROR,
7633 "CMAC replay count cannot be fetched without NL80211_SUPPORT defined");
7634 return -1;
7635#endif /* NL80211_SUPPORT */
7636}
7637
7638
7639static enum sigma_cmd_result sta_get_parameter_wpa3(struct sigma_dut *dut,
7640 struct sigma_conn *conn,
7641 struct sigma_cmd *cmd)
7642{
7643 char buf[MAX_CMD_LEN];
7644 const char *ifname = get_param(cmd, "interface");
7645 const char *parameter = get_param(cmd, "Parameter");
7646 unsigned int val;
7647
7648 if (!ifname || !parameter)
7649 return INVALID_SEND_STATUS;
7650
7651 if (strcasecmp(parameter, "BIPMICErrors") == 0) {
7652 if (get_bip_mic_error_count(dut, ifname, &val)) {
7653 send_resp(dut, conn, SIGMA_ERROR,
7654 "ErrorCode,Failed to get BIPMICErrors");
7655 return STATUS_SENT_ERROR;
7656 }
7657 snprintf(buf, sizeof(buf), "BIPMICErrors,%d", val);
7658 sigma_dut_print(dut, DUT_MSG_INFO, "BIPMICErrors %s", buf);
7659 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7660 return STATUS_SENT;
7661 }
7662
7663 if (strcasecmp(parameter, "CMACReplays") == 0) {
7664 if (get_cmac_replay_count(dut, ifname, &val)) {
7665 send_resp(dut, conn, SIGMA_ERROR,
7666 "ErrorCode,Failed to get CMACReplays");
7667 return STATUS_SENT_ERROR;
7668 }
7669 snprintf(buf, sizeof(buf), "CMACReplays,%d", val);
7670 sigma_dut_print(dut, DUT_MSG_INFO, "CMACReplays %s", buf);
7671 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7672 return STATUS_SENT;
7673 }
7674
7675 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7676 return STATUS_SENT_ERROR;
7677}
7678
7679
Jouni Malinenca0abd32020-02-09 20:18:10 +02007680static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
7681 struct sigma_conn *conn,
7682 struct sigma_cmd *cmd)
7683{
7684 const char *intf = get_param(cmd, "Interface");
7685 char buf[4096], bssid[20], resp[200], *pos, *tmp;
7686
7687 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
7688 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
7689 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
7690 send_resp(dut, conn, SIGMA_ERROR,
7691 "ErrorCode,PMKSA_GET not supported");
7692 return STATUS_SENT_ERROR;
7693 }
7694
7695 if (strncmp(buf, "FAIL", 4) == 0 ||
7696 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
7697 send_resp(dut, conn, SIGMA_ERROR,
7698 "ErrorCode,Could not find current network");
7699 return STATUS_SENT_ERROR;
7700 }
7701
7702 pos = buf;
7703 while (pos) {
7704 if (strncmp(pos, bssid, 17) == 0) {
7705 pos = strchr(pos, ' ');
7706 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307707 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007708 pos++;
7709 pos = strchr(pos, ' ');
7710 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307711 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007712 pos++;
7713 tmp = strchr(pos, ' ');
7714 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307715 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007716 *tmp = '\0';
7717 break;
7718 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02007719 pos = strchr(pos, '\n');
7720 if (pos)
7721 pos++;
7722 }
7723
7724 if (!pos) {
7725 send_resp(dut, conn, SIGMA_ERROR,
7726 "ErrorCode,PMK not available");
7727 return STATUS_SENT_ERROR;
7728 }
7729
7730 snprintf(resp, sizeof(resp), "PMK,%s", pos);
7731 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7732 return STATUS_SENT;
7733}
7734
7735
Jouni Malinenf7222712019-06-13 01:50:21 +03007736static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
7737 struct sigma_conn *conn,
7738 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007739{
7740 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02007741 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007742
Jouni Malinenca0abd32020-02-09 20:18:10 +02007743 if (!parameter)
7744 return INVALID_SEND_STATUS;
7745
7746 if (strcasecmp(parameter, "PMK") == 0)
7747 return sta_get_pmk(dut, conn, cmd);
7748
7749 if (!program)
7750 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007751
7752 if (strcasecmp(program, "P2PNFC") == 0)
7753 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
7754
7755 if (strcasecmp(program, "60ghz") == 0)
7756 return sta_get_parameter_60g(dut, conn, cmd);
7757
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007758 if (strcasecmp(program, "he") == 0)
7759 return sta_get_parameter_he(dut, conn, cmd);
7760
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007761#ifdef ANDROID_NAN
7762 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07007763 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007764#endif /* ANDROID_NAN */
7765
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007766#ifdef MIRACAST
7767 if (strcasecmp(program, "WFD") == 0 ||
7768 strcasecmp(program, "DisplayR2") == 0)
7769 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
7770#endif /* MIRACAST */
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05307771 if (strcasecmp(program, "WPA3") == 0)
7772 return sta_get_parameter_wpa3(dut, conn, cmd);
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007773
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007774 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7775 return 0;
7776}
7777
7778
7779static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
7780 const char *type)
7781{
7782 char buf[100];
7783
7784 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007785 run_iwpriv(dut, intf, "chwidth 2");
7786 run_iwpriv(dut, intf, "mode 11ACVHT80");
7787 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007788 }
7789
7790 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007791 run_iwpriv(dut, intf, "chwidth 0");
7792 run_iwpriv(dut, intf, "mode 11naht40");
7793 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007794 }
7795
7796 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007797 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007798
7799 /* Reset CTS width */
7800 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
7801 intf);
7802 if (system(buf) != 0) {
7803 sigma_dut_print(dut, DUT_MSG_ERROR,
7804 "wifitool %s beeliner_fw_test 54 0 failed",
7805 intf);
7806 }
7807
7808 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007809 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007810
7811 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
7812 if (system(buf) != 0) {
7813 sigma_dut_print(dut, DUT_MSG_ERROR,
7814 "iwpriv rts failed");
7815 }
7816 }
7817
7818 if (type && strcasecmp(type, "Testbed") == 0) {
7819 dut->testbed_flag_txsp = 1;
7820 dut->testbed_flag_rxsp = 1;
7821 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007822 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007823
7824 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007825 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007826
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007827 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007828
7829 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007830 run_iwpriv(dut, intf, "tx_stbc 0");
7831 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007832
7833 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007834 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007835 }
7836
7837 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007838 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07007839 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007840
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007841 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007842 }
7843}
7844
7845
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007846#ifdef NL80211_SUPPORT
7847static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
7848 enum he_mcs_config mcs)
7849{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307850 return wcn_wifi_test_config_set_u8(
7851 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS, mcs);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007852}
7853#endif /* NL80211_SUPPORT */
7854
7855
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007856static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
7857 const char *intf, int enable)
7858{
7859#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307860 return wcn_wifi_test_config_set_u8(
7861 dut, intf,
7862 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
7863 enable);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007864#else /* NL80211_SUPPORT */
7865 sigma_dut_print(dut, DUT_MSG_ERROR,
7866 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
7867 return -1;
7868#endif /* NL80211_SUPPORT */
7869}
7870
7871
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007872static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
7873 const char *intf, int enable)
7874{
7875#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307876 return wcn_wifi_test_config_set_u8(
7877 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7878 enable);
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007879#else /* NL80211_SUPPORT */
7880 sigma_dut_print(dut, DUT_MSG_ERROR,
7881 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7882 return -1;
7883#endif /* NL80211_SUPPORT */
7884}
7885
7886
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007887#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007888
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007889static int sta_set_he_testbed_def(struct sigma_dut *dut,
7890 const char *intf, int cfg)
7891{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307892 return wcn_wifi_test_config_set_u8(
7893 dut, intf,
7894 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7895 cfg);
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007896}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007897
7898
7899static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7900{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307901 return wcn_wifi_test_config_set_u8(
7902 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7903 cfg);
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007904}
7905
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007906#endif /* NL80211_SUPPORT */
7907
7908
Qiwei Caib6806972020-01-15 13:52:11 +08007909int sta_set_addba_buf_size(struct sigma_dut *dut,
7910 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007911{
7912#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307913 return wcn_wifi_test_config_set_u16(
7914 dut, intf,
7915 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE, bufsize);
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007916#else /* NL80211_SUPPORT */
7917 sigma_dut_print(dut, DUT_MSG_ERROR,
7918 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7919 return -1;
7920#endif /* NL80211_SUPPORT */
7921}
7922
7923
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -07007924static int sta_set_scan_unicast_probe(struct sigma_dut *dut,
7925 const char *intf, int val)
7926{
7927#ifdef NL80211_SUPPORT
7928 return wcn_wifi_test_config_set_u8(
7929 dut, intf,
7930 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_USE_BSSID_IN_PROBE_REQ_RA,
7931 val);
7932#else /* NL80211_SUPPORT */
7933 sigma_dut_print(dut, DUT_MSG_ERROR,
7934 "Unicast RA in Probe Request frame cannot be set without NL80211_SUPPORT defined");
7935 return -1;
7936#endif /* NL80211_SUPPORT */
7937}
7938
7939
Kiran Kumar Lokere09dbcef2021-08-09 00:01:41 -07007940static int sta_set_rx_ctrl_multi_bss(struct sigma_dut *dut, const char *intf,
7941 int enable)
7942{
7943#ifdef NL80211_SUPPORT
7944 return wcn_wifi_test_config_set_u8(
7945 dut, intf,
7946 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_RX_CTRL_FRAME_TO_MBSS,
7947 enable);
7948#else /* NL80211_SUPPORT */
7949 sigma_dut_print(dut, DUT_MSG_ERROR,
7950 "Rx ctrl frame to Multi-BSS cannot be changed without NL80211_SUPPORT defined");
7951 return -1;
7952#endif /* NL80211_SUPPORT */
7953}
7954
7955
7956static int sta_set_bcast_twt_support(struct sigma_dut *dut, const char *intf,
7957 int enable)
7958{
7959#ifdef NL80211_SUPPORT
7960 return wcn_wifi_test_config_set_u8(
7961 dut, intf,
7962 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BCAST_TWT_SUPPORT,
7963 enable);
7964#else /* NL80211_SUPPORT */
7965 sigma_dut_print(dut, DUT_MSG_ERROR,
7966 "BCAST TWT cannot be changed without NL80211_SUPPORT defined");
7967 return -1;
7968#endif /* NL80211_SUPPORT */
7969}
7970
7971
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007972static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
7973 int enable)
7974{
7975#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307976 return wcn_wifi_test_config_set_u8(
7977 dut, intf,
7978 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7979 enable);
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007980#else /* NL80211_SUPPORT */
7981 sigma_dut_print(dut, DUT_MSG_ERROR,
7982 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7983 return -1;
7984#endif /* NL80211_SUPPORT */
7985}
7986
7987
Arif Hussain9765f7d2018-07-03 08:28:26 -07007988static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7989 int val)
7990{
7991#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307992 return wcn_wifi_test_config_set_u8(
7993 dut, intf,
7994 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7995 val);
Arif Hussain9765f7d2018-07-03 08:28:26 -07007996#else /* NL80211_SUPPORT */
7997 sigma_dut_print(dut, DUT_MSG_ERROR,
7998 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7999 return -1;
8000#endif /* NL80211_SUPPORT */
8001}
8002
8003
Arif Hussain68d23f52018-07-11 13:39:08 -07008004#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008005static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
8006 enum qca_wlan_he_mac_padding_dur val)
8007{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308008 return wcn_wifi_test_config_set_u8(
8009 dut, intf,
8010 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR, val);
Arif Hussain68d23f52018-07-11 13:39:08 -07008011}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008012#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008013
8014
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07008015static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
8016 int val)
8017{
8018#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308019 return wcn_wifi_test_config_set_u8(
8020 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
8021 val);
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07008022#else /* NL80211_SUPPORT */
8023 sigma_dut_print(dut, DUT_MSG_ERROR,
8024 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
8025 return -1;
8026#endif /* NL80211_SUPPORT */
8027}
8028
8029
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -07008030static int sta_set_mgmt_data_tx_disable_cfg(struct sigma_dut *dut,
8031 const char *intf, int val)
8032{
8033#ifdef NL80211_SUPPORT
8034 return wcn_wifi_test_config_set_u8(
8035 dut, intf,
8036 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISABLE_DATA_MGMT_RSP_TX,
8037 val);
8038#else /* NL80211_SUPPORT */
8039 sigma_dut_print(dut, DUT_MSG_ERROR,
8040 "Tx disable config cannot be set without NL80211_SUPPORT defined");
8041 return -1;
8042#endif /* NL80211_SUPPORT */
8043}
8044
8045
Kiran Kumar Lokere1809da12021-06-24 00:45:38 -07008046static int sta_set_keep_alive_data_cfg(struct sigma_dut *dut, const char *intf,
8047 int val)
8048{
8049#ifdef NL80211_SUPPORT
8050 return wcn_wifi_test_config_set_u8(
8051 dut, intf,
8052 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_KEEP_ALIVE_FRAME_TYPE,
8053 val);
8054#else /* NL80211_SUPPORT */
8055 sigma_dut_print(dut, DUT_MSG_ERROR,
8056 "Keep alive data type cannot be set without NL80211_SUPPORT defined");
8057 return -1;
8058#endif /* NL80211_SUPPORT */
8059}
8060
8061
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008062#ifdef NL80211_SUPPORT
8063static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
8064{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308065 return wcn_wifi_test_config_set_flag(
8066 dut, intf,
8067 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG);
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008068}
8069#endif /* NL80211_SUPPORT */
8070
8071
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008072static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
8073 int val)
8074{
8075#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308076 return wcn_wifi_test_config_set_u8(
8077 dut, intf,
8078 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA, val);
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008079#else /* NL80211_SUPPORT */
8080 sigma_dut_print(dut, DUT_MSG_ERROR,
8081 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
8082 return -1;
8083#endif /* NL80211_SUPPORT */
8084}
8085
8086
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -07008087static int sta_set_er_su_ppdu_type_tx(struct sigma_dut *dut, const char *intf,
8088 int val)
8089{
8090#ifdef NL80211_SUPPORT
8091 return wcn_wifi_test_config_set_u8(
8092 dut, intf,
8093 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ER_SU_PPDU_TYPE, val);
8094#else /* NL80211_SUPPORT */
8095 sigma_dut_print(dut, DUT_MSG_ERROR,
8096 "ER-SU PPDU type cannot be set without NL80211_SUPPORT defined");
8097 return -1;
8098#endif /* NL80211_SUPPORT */
8099}
8100
8101
8102static int sta_set_ru_242_tone_tx(struct sigma_dut *dut, const char *intf,
8103 int val)
8104{
8105#ifdef NL80211_SUPPORT
8106 return wcn_wifi_test_config_set_u8(
8107 dut, intf,
8108 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_RU_242_TONE_TX, val);
8109#else /* NL80211_SUPPORT */
8110 sigma_dut_print(dut, DUT_MSG_ERROR,
8111 "RU 242 tone cannot be set without NL80211_SUPPORT defined");
8112 return -1;
8113#endif /* NL80211_SUPPORT */
8114}
8115
8116
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008117static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
8118 int val)
8119{
8120#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308121 return wcn_wifi_test_config_set_u8(
8122 dut, intf,
8123 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP, val);
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008124#else /* NL80211_SUPPORT */
8125 sigma_dut_print(dut, DUT_MSG_ERROR,
8126 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
8127 return -1;
8128#endif /* NL80211_SUPPORT */
8129}
8130
8131
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008132#ifdef NL80211_SUPPORT
8133
8134struct features_info {
8135 unsigned char flags[8];
8136 size_t flags_len;
8137};
8138
8139static int features_info_handler(struct nl_msg *msg, void *arg)
8140{
8141 struct nlattr *tb[NL80211_ATTR_MAX + 1];
8142 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
8143 struct features_info *info = arg;
8144 struct nlattr *nl_vend, *attr;
8145
8146 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
8147 genlmsg_attrlen(gnlh, 0), NULL);
8148
8149 nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
8150 if (nl_vend) {
8151 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
8152
8153 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
8154 nla_data(nl_vend), nla_len(nl_vend), NULL);
8155
8156 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_FEATURE_FLAGS];
8157 if (attr) {
8158 int len = nla_len(attr);
8159
Vamsi Krishna79a91132021-08-16 21:40:22 +05308160 if (info && len <= sizeof(info->flags)) {
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008161 memcpy(info->flags, nla_data(attr), len);
8162 info->flags_len = len;
8163 }
8164 }
8165 }
8166
8167 return NL_SKIP;
8168}
8169
8170
8171static int check_feature(enum qca_wlan_vendor_features feature,
8172 struct features_info *info)
8173{
8174 size_t idx = feature / 8;
8175
Vamsi Krishna79a91132021-08-16 21:40:22 +05308176 if (!info)
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008177 return 0;
8178
8179 return (idx < info->flags_len) &&
8180 (info->flags[idx] & BIT(feature % 8));
8181}
8182
8183#endif /* NL80211_SUPPORT */
8184
8185
8186static void sta_get_twt_feature_async_supp(struct sigma_dut *dut,
8187 const char *intf)
8188{
8189#ifdef NL80211_SUPPORT
8190 struct nl_msg *msg;
8191 struct features_info info = { 0 };
8192 int ifindex, ret;
8193
8194 ifindex = if_nametoindex(intf);
8195 if (ifindex == 0) {
8196 sigma_dut_print(dut, DUT_MSG_ERROR,
8197 "%s: Index for interface %s failed",
8198 __func__, intf);
8199 return;
8200 }
8201
8202 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8203 NL80211_CMD_VENDOR)) ||
8204 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8205 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8206 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8207 QCA_NL80211_VENDOR_SUBCMD_GET_FEATURES)) {
8208 sigma_dut_print(dut, DUT_MSG_ERROR,
8209 "%s: err in adding vendor_cmd and vendor_data",
8210 __func__);
8211 nlmsg_free(msg);
8212 return;
8213 }
8214
8215 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, features_info_handler,
8216 &info);
8217 if (ret) {
8218 sigma_dut_print(dut, DUT_MSG_ERROR,
8219 "%s: err in send_and_recv_msgs, ret=%d",
8220 __func__, ret);
8221 return;
8222 }
8223
8224 if (check_feature(QCA_WLAN_VENDOR_FEATURE_TWT_ASYNC_SUPPORT, &info))
8225 dut->sta_async_twt_supp = 1;
8226 else
8227 dut->sta_async_twt_supp = 0;
8228
8229 sigma_dut_print(dut, DUT_MSG_DEBUG,
8230 "%s: sta_async_twt_supp %d",
8231 __func__, dut->sta_async_twt_supp);
8232#else /* NL80211_SUPPORT */
8233 sigma_dut_print(dut, DUT_MSG_INFO,
8234 "TWT async supp get cannot be done without NL80211_SUPPORT defined");
8235 dut->sta_async_twt_supp = 0;
8236#endif /* NL80211_SUPPORT */
8237}
8238
8239
Arif Hussain480d5f42019-03-12 14:40:42 -07008240static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
8241 int val)
8242{
8243#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05308244 return wcn_wifi_test_config_set_u8(
8245 dut, intf,
8246 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT, val);
Arif Hussain480d5f42019-03-12 14:40:42 -07008247#else /* NL80211_SUPPORT */
8248 sigma_dut_print(dut, DUT_MSG_ERROR,
8249 "TWT Request cannot be changed without NL80211_SUPPORT defined");
8250 return -1;
8251#endif /* NL80211_SUPPORT */
8252}
8253
8254
Kiran Kumar Lokere4f2d4b02021-04-01 00:07:39 -07008255static int sta_set_bss_max_idle_period(struct sigma_dut *dut, const char *intf,
8256 int val)
8257{
8258#ifdef NL80211_SUPPORT
8259 return wcn_wifi_test_config_set_u16(
8260 dut, intf,
8261 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BSS_MAX_IDLE_PERIOD, val);
8262#else /* NL80211_SUPPORT */
8263 sigma_dut_print(dut, DUT_MSG_ERROR,
8264 "BSS max idle period cannot be set without NL80211_SUPPORT defined");
8265 return -1;
8266#endif /* NL80211_SUPPORT */
8267}
8268
8269
Kiran Kumar Lokere07ad92b2021-08-09 00:27:14 -07008270static int sta_set_bss_max_idle_support(struct sigma_dut *dut, const char *intf,
8271 int val)
8272{
8273#ifdef NL80211_SUPPORT
8274 return wcn_wifi_test_config_set_u8(
8275 dut, intf,
8276 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BSS_MAX_IDLE_PERIOD_ENABLE,
8277 val);
8278#else /* NL80211_SUPPORT */
8279 sigma_dut_print(dut, DUT_MSG_ERROR,
8280 "BSS max idle support cannot be set without NL80211_SUPPORT defined");
8281 return -1;
8282#endif /* NL80211_SUPPORT */
8283}
8284
8285
Srinivas Girigowda0525e292020-11-12 13:28:21 -08008286static int sta_set_fullbw_ulmumimo(struct sigma_dut *dut, const char *intf,
8287 int val)
8288{
8289#ifdef NL80211_SUPPORT
8290 return wcn_wifi_test_config_set_u8(
8291 dut, intf,
8292 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FULL_BW_UL_MU_MIMO, val);
8293#else /* NL80211_SUPPORT */
8294 sigma_dut_print(dut, DUT_MSG_ERROR,
8295 "Full BW UL MU MIMO cannot be changed without NL80211_SUPPORT defined");
8296 return -1;
8297#endif /* NL80211_SUPPORT */
8298}
8299
8300
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -07008301static int sta_set_punctured_preamble_rx(struct sigma_dut *dut,
8302 const char *intf, int val)
8303{
8304#ifdef NL80211_SUPPORT
8305 return wcn_wifi_test_config_set_u8(
8306 dut, intf,
8307 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PUNCTURED_PREAMBLE_RX,
8308 val);
8309#else /* NL80211_SUPPORT */
8310 sigma_dut_print(dut, DUT_MSG_ERROR,
8311 "Punctured preamble Rx cannot be set without NL80211_SUPPORT defined");
8312 return -1;
8313#endif /* NL80211_SUPPORT */
8314}
8315
8316
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008317static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
8318 const char *type)
8319{
8320 char buf[60];
8321
8322 if (dut->program == PROGRAM_HE) {
8323 /* resetting phymode to auto in case of HE program */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05308324 sta_set_phymode(dut, intf, "auto");
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008325
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07008326 /* reset the rate to Auto rate */
8327 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
8328 intf);
8329 if (system(buf) != 0) {
8330 sigma_dut_print(dut, DUT_MSG_ERROR,
8331 "iwpriv %s set_11ax_rate 0xff failed",
8332 intf);
8333 }
8334
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07008335 /* reset the LDPC setting */
8336 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
8337 if (system(buf) != 0) {
8338 sigma_dut_print(dut, DUT_MSG_ERROR,
8339 "iwpriv %s ldpc 1 failed", intf);
8340 }
8341
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08008342 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05308343 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08008344
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008345 /* remove all network profiles */
8346 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008347
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08008348 /* Configure ADDBA Req/Rsp buffer size to be 64 */
8349 sta_set_addba_buf_size(dut, intf, 64);
8350
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07008351 if (dut->sta_async_twt_supp == -1)
8352 sta_get_twt_feature_async_supp(dut, intf);
8353
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -07008354 sta_set_scan_unicast_probe(dut, intf, 0);
8355
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08008356#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008357 /* Reset the device HE capabilities to its default supported
8358 * configuration. */
8359 sta_set_he_testbed_def(dut, intf, 0);
8360
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08008361 /* Disable noackpolicy for all AC */
8362 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
8363 sigma_dut_print(dut, DUT_MSG_ERROR,
8364 "Disable of noackpolicy for all AC failed");
8365 }
8366#endif /* NL80211_SUPPORT */
8367
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08008368 /* Enable WMM by default */
8369 if (wcn_sta_set_wmm(dut, intf, "on")) {
8370 sigma_dut_print(dut, DUT_MSG_ERROR,
8371 "Enable of WMM in sta_reset_default_wcn failed");
8372 }
8373
8374 /* Disable ADDBA_REJECT by default */
8375 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
8376 sigma_dut_print(dut, DUT_MSG_ERROR,
8377 "Disable of addba_reject in sta_reset_default_wcn failed");
8378 }
8379
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08008380 /* Enable sending of ADDBA by default */
8381 if (nlvendor_config_send_addba(dut, intf, 1)) {
8382 sigma_dut_print(dut, DUT_MSG_ERROR,
8383 "Enable sending of ADDBA in sta_reset_default_wcn failed");
8384 }
8385
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08008386 /* Enable AMPDU by default */
8387 iwpriv_sta_set_ampdu(dut, intf, 1);
8388
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008389#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08008390 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008391 sigma_dut_print(dut, DUT_MSG_ERROR,
8392 "Set LTF config to default in sta_reset_default_wcn failed");
8393 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07008394
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08008395 /* set the beamformee NSTS(maximum number of
8396 * space-time streams) to default DUT config
8397 */
8398 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07008399 sigma_dut_print(dut, DUT_MSG_ERROR,
8400 "Failed to set BeamformeeSTS");
8401 }
Arif Hussain68d23f52018-07-11 13:39:08 -07008402
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -07008403 if (sta_set_mgmt_data_tx_disable_cfg(dut, intf, 0)) {
8404 sigma_dut_print(dut, DUT_MSG_ERROR,
8405 "Failed to reset mgmt/data Tx disable config");
8406 }
8407
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008408 if (sta_set_mac_padding_duration(
8409 dut, intf,
8410 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008411 sigma_dut_print(dut, DUT_MSG_ERROR,
8412 "Failed to set MAC padding duration");
8413 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008414
8415 if (sta_set_mu_edca_override(dut, intf, 0)) {
8416 sigma_dut_print(dut, DUT_MSG_ERROR,
8417 "ErrorCode,Failed to set MU EDCA override disable");
8418 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008419
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -07008420 if (sta_set_ru_242_tone_tx(dut, intf, 0)) {
8421 sigma_dut_print(dut, DUT_MSG_ERROR,
8422 "Failed to set RU 242 tone Tx");
8423 }
8424
8425 if (sta_set_er_su_ppdu_type_tx(dut, intf, 0)) {
8426 sigma_dut_print(dut, DUT_MSG_ERROR,
8427 "Failed to set ER-SU PPDU type Tx");
8428 }
8429
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008430 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
8431 sigma_dut_print(dut, DUT_MSG_ERROR,
8432 "Failed to set OM ctrl supp");
8433 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07008434
8435 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
8436 sigma_dut_print(dut, DUT_MSG_ERROR,
8437 "Failed to set Tx SU PPDU enable");
8438 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008439
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07008440 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
8441 sigma_dut_print(dut, DUT_MSG_ERROR,
8442 "failed to send TB PPDU Tx cfg");
8443 }
8444
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008445 if (sta_set_he_om_ctrl_reset(dut, intf)) {
8446 sigma_dut_print(dut, DUT_MSG_ERROR,
8447 "Failed to set OM ctrl reset");
8448 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08008449
8450 /* +HTC-HE support default on */
8451 if (sta_set_he_htc_supp(dut, intf, 1)) {
8452 sigma_dut_print(dut, DUT_MSG_ERROR,
8453 "Setting of +HTC-HE support failed");
8454 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008455#endif /* NL80211_SUPPORT */
8456
Arif Hussain8d5b27b2018-05-14 14:31:03 -07008457 if (sta_set_tx_beamformee(dut, intf, 1)) {
8458 sigma_dut_print(dut, DUT_MSG_ERROR,
8459 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
8460 }
8461
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07008462 wpa_command(intf, "SET oce 1");
8463
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008464 /* Set nss to 1 and MCS 0-7 in case of testbed */
8465 if (type && strcasecmp(type, "Testbed") == 0) {
8466#ifdef NL80211_SUPPORT
8467 int ret;
8468#endif /* NL80211_SUPPORT */
8469
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07008470 wpa_command(intf, "SET oce 0");
8471
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008472 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
8473 if (system(buf) != 0) {
8474 sigma_dut_print(dut, DUT_MSG_ERROR,
8475 "iwpriv %s nss failed", intf);
8476 }
8477
8478#ifdef NL80211_SUPPORT
8479 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
8480 if (ret) {
8481 sigma_dut_print(dut, DUT_MSG_ERROR,
8482 "Setting of MCS failed, ret:%d",
8483 ret);
8484 }
8485#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08008486
8487 /* Disable STBC as default */
8488 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08008489
8490 /* Disable AMSDU as default */
8491 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08008492
8493#ifdef NL80211_SUPPORT
8494 /* HE fragmentation default off */
8495 if (sta_set_he_fragmentation(dut, intf,
8496 HE_FRAG_DISABLE)) {
8497 sigma_dut_print(dut, DUT_MSG_ERROR,
8498 "Setting of HE fragmentation failed");
8499 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08008500
8501 /* set the beamformee NSTS(maximum number of
8502 * space-time streams) to default testbed config
8503 */
8504 if (sta_set_beamformee_sts(dut, intf, 3)) {
8505 sigma_dut_print(dut, DUT_MSG_ERROR,
8506 "Failed to set BeamformeeSTS");
8507 }
8508
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -07008509 if (sta_set_punctured_preamble_rx(dut, intf, 0)) {
8510 sigma_dut_print(dut, DUT_MSG_ERROR,
8511 "Failed to reset PreamblePunctRx support");
8512 }
8513
Kiran Kumar Lokere727687f2021-06-24 00:35:49 -07008514 if (sta_set_bss_max_idle_period(dut, intf, 0)) {
8515 sigma_dut_print(dut, DUT_MSG_ERROR,
8516 "Failed to reset BSS max idle period");
8517 }
8518
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08008519 /* +HTC-HE support default off */
8520 if (sta_set_he_htc_supp(dut, intf, 0)) {
8521 sigma_dut_print(dut, DUT_MSG_ERROR,
8522 "Setting of +HTC-HE support failed");
8523 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008524
8525 /* Set device HE capabilities to testbed default
8526 * configuration. */
8527 if (sta_set_he_testbed_def(dut, intf, 1)) {
8528 sigma_dut_print(dut, DUT_MSG_DEBUG,
8529 "Failed to set HE defaults");
8530 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08008531
8532 /* Disable VHT support in 2.4 GHz for testbed */
8533 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08008534#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08008535
8536 /* Enable WEP/TKIP with HE capability in testbed */
8537 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
8538 sigma_dut_print(dut, DUT_MSG_ERROR,
8539 "Enabling HE config with WEP/TKIP failed");
8540 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008541 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008542
8543 /* Defaults in case of DUT */
8544 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07008545 /* Enable STBC by default */
8546 wcn_sta_set_stbc(dut, intf, "1");
8547
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008548 /* set nss to 2 */
8549 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
8550 if (system(buf) != 0) {
8551 sigma_dut_print(dut, DUT_MSG_ERROR,
8552 "iwpriv %s nss 2 failed", intf);
8553 }
Arif Hussainac6c5112018-05-25 17:34:00 -07008554 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008555
8556#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07008557 /* Set HE_MCS to 0-11 */
8558 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008559 sigma_dut_print(dut, DUT_MSG_ERROR,
8560 "Setting of MCS failed");
8561 }
8562#endif /* NL80211_SUPPORT */
8563
8564 /* Disable WEP/TKIP with HE capability in DUT */
8565 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
8566 sigma_dut_print(dut, DUT_MSG_ERROR,
8567 "Enabling HE config with WEP/TKIP failed");
8568 }
8569 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008570 }
8571}
8572
8573
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308574static int sta_set_client_privacy(struct sigma_dut *dut,
8575 struct sigma_conn *conn, const char *intf,
8576 int enable)
8577{
8578 if (enable &&
8579 (wpa_command(intf, "SET mac_addr 1") < 0 ||
8580 wpa_command(intf, "SET rand_addr_lifetime 1") < 0 ||
Veerendranath Jakkam39fd5c42020-12-21 02:02:21 +05308581 (wpa_command(intf, "MAC_RAND_SCAN enable=1 all") < 0 &&
8582 wpa_command(intf, "SET preassoc_mac_addr 1") < 0) ||
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308583 wpa_command(intf, "SET gas_rand_mac_addr 1") < 0 ||
8584 wpa_command(intf, "SET gas_rand_addr_lifetime 1") < 0))
8585 return -1;
8586
8587 if (!enable &&
8588 (wpa_command(intf, "SET mac_addr 0") < 0 ||
Veerendranath Jakkam39fd5c42020-12-21 02:02:21 +05308589 (wpa_command(intf, "MAC_RAND_SCAN enable=0 all") < 0 &&
8590 wpa_command(intf, "SET preassoc_mac_addr 0") < 0) ||
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308591 wpa_command(intf, "SET gas_rand_mac_addr 0") < 0))
8592 return -1;
8593
8594 dut->client_privacy = enable;
8595 return 0;
8596}
8597
8598
Jouni Malinenf7222712019-06-13 01:50:21 +03008599static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
8600 struct sigma_conn *conn,
8601 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008602{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008603 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008604 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008605 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008606 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308607 const char *dev_role = get_param(cmd, "DevRole");
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05308608 char resp[20];
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308609 char buf[100];
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05308610 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008611
Jouni Malinenb21f0542019-11-04 17:53:38 +02008612 if (dut->station_ifname_2g &&
8613 strcmp(dut->station_ifname_2g, intf) == 0)
8614 dut->use_5g = 0;
8615 else if (dut->station_ifname_5g &&
8616 strcmp(dut->station_ifname_5g, intf) == 0)
8617 dut->use_5g = 1;
8618
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008619 if (!program)
8620 program = get_param(cmd, "prog");
8621 dut->program = sigma_program_to_enum(program);
Vinita S. Maloof7a2cbf2020-11-18 19:29:44 +05308622
8623 if (dut->program == PROGRAM_WFD && dut->user_config_timeout)
8624 dut->default_timeout = dut->user_config_timeout;
8625
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008626 dut->device_type = STA_unknown;
8627 type = get_param(cmd, "type");
8628 if (type && strcasecmp(type, "Testbed") == 0)
8629 dut->device_type = STA_testbed;
8630 if (type && strcasecmp(type, "DUT") == 0)
8631 dut->device_type = STA_dut;
8632
8633 if (dut->program == PROGRAM_TDLS) {
8634 /* Clear TDLS testing mode */
8635 wpa_command(intf, "SET tdls_disabled 0");
8636 wpa_command(intf, "SET tdls_testing 0");
8637 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008638 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05308639 /* Enable the WCN driver in TDLS Explicit trigger mode
8640 */
8641 wpa_command(intf, "SET tdls_external_control 0");
8642 wpa_command(intf, "SET tdls_trigger_control 0");
8643 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008644 }
8645
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008646#ifdef MIRACAST
8647 if (dut->program == PROGRAM_WFD ||
8648 dut->program == PROGRAM_DISPLAYR2)
8649 miracast_sta_reset_default(dut, conn, cmd);
8650#endif /* MIRACAST */
8651
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008652 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008653 case DRIVER_ATHEROS:
8654 sta_reset_default_ath(dut, intf, type);
8655 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008656 case DRIVER_WCN:
8657 sta_reset_default_wcn(dut, intf, type);
8658 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008659 default:
8660 break;
8661 }
8662
8663#ifdef ANDROID_NAN
8664 if (dut->program == PROGRAM_NAN)
8665 nan_cmd_sta_reset_default(dut, conn, cmd);
8666#endif /* ANDROID_NAN */
8667
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05308668 if (dut->program == PROGRAM_LOC &&
8669 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
8670 return ERROR_SEND_STATUS;
8671
Jouni Malinenba630452018-06-22 11:49:59 +03008672 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008673 unlink("SP/wi-fi.org/pps.xml");
8674 if (system("rm -r SP/*") != 0) {
8675 }
8676 unlink("next-client-cert.pem");
8677 unlink("next-client-key.pem");
8678 }
8679
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008680 /* For WPS program of the 60 GHz band the band type needs to be saved */
8681 if (dut->program == PROGRAM_WPS) {
8682 if (band && strcasecmp(band, "60GHz") == 0) {
8683 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008684 /* For 60 GHz enable WPS for WPS TCs */
8685 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008686 } else {
8687 dut->band = WPS_BAND_NON_60G;
8688 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008689 } else if (dut->program == PROGRAM_60GHZ) {
8690 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
8691 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008692 }
8693
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02008694 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008695 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008696 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008697
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008698 sigma_dut_print(dut, DUT_MSG_INFO,
8699 "WPS 60 GHz program, wps_disable = %d",
8700 dut->wps_disable);
8701
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008702 if (!dev_role) {
8703 send_resp(dut, conn, SIGMA_ERROR,
8704 "errorCode,Missing DevRole argument");
8705 return 0;
8706 }
8707
8708 if (strcasecmp(dev_role, "STA") == 0)
8709 dut->dev_role = DEVROLE_STA;
8710 else if (strcasecmp(dev_role, "PCP") == 0)
8711 dut->dev_role = DEVROLE_PCP;
8712 else {
8713 send_resp(dut, conn, SIGMA_ERROR,
8714 "errorCode,Unknown DevRole");
8715 return 0;
8716 }
8717
8718 if (dut->device_type == STA_unknown) {
8719 sigma_dut_print(dut, DUT_MSG_ERROR,
8720 "Device type is not STA testbed or DUT");
8721 send_resp(dut, conn, SIGMA_ERROR,
8722 "errorCode,Unknown device type");
8723 return 0;
8724 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008725
8726 sigma_dut_print(dut, DUT_MSG_DEBUG,
8727 "Setting msdu_size to MAX: 7912");
8728 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008729 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008730
8731 if (system(buf) != 0) {
8732 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
8733 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008734 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008735 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008736
8737 if (sta_set_force_mcs(dut, 0, 1)) {
8738 sigma_dut_print(dut, DUT_MSG_ERROR,
8739 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008740 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008741 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008742 }
8743
8744 wpa_command(intf, "WPS_ER_STOP");
8745 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05308746 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008747 wpa_command(intf, "SET radio_disabled 0");
8748
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02008749 dut->wps_forced_version = 0;
8750
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008751 if (dut->wsc_fragment) {
8752 dut->wsc_fragment = 0;
8753 wpa_command(intf, "SET device_name Test client");
8754 wpa_command(intf, "SET manufacturer ");
8755 wpa_command(intf, "SET model_name ");
8756 wpa_command(intf, "SET model_number ");
8757 wpa_command(intf, "SET serial_number ");
8758 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02008759 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
8760 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
8761 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
8762 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008763
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008764 if (dut->tmp_mac_addr && dut->set_macaddr) {
8765 dut->tmp_mac_addr = 0;
8766 if (system(dut->set_macaddr) != 0) {
8767 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
8768 "temporary MAC address");
8769 }
8770 }
8771
8772 set_ps(intf, dut, 0);
8773
Jouni Malinenba630452018-06-22 11:49:59 +03008774 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
8775 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008776 wpa_command(intf, "SET interworking 1");
8777 wpa_command(intf, "SET hs20 1");
8778 }
8779
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008780 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03008781 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008782 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008783 wpa_command(intf, "SET pmf 1");
8784 } else {
8785 wpa_command(intf, "SET pmf 0");
8786 }
8787
8788 hs2_clear_credentials(intf);
8789 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
8790 wpa_command(intf, "SET access_network_type 15");
8791
8792 static_ip_file(0, NULL, NULL, NULL);
8793 kill_dhcp_client(dut, intf);
8794 clear_ip_addr(dut, intf);
8795
8796 dut->er_oper_performed = 0;
8797 dut->er_oper_bssid[0] = '\0';
8798
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008799 if (dut->program == PROGRAM_LOC) {
8800 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008801 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008802 }
8803
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07008804 if (dut->program == PROGRAM_MBO || dut->program == PROGRAM_HE) {
Ashwini Patil00402582017-04-13 12:29:39 +05308805 free(dut->non_pref_ch_list);
8806 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05308807 free(dut->btm_query_cand_list);
8808 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05308809 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05308810 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05308811 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05308812 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05308813 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05308814 }
8815
Jouni Malinen3c367e82017-06-23 17:01:47 +03008816 free(dut->rsne_override);
8817 dut->rsne_override = NULL;
8818
Jouni Malinen68143132017-09-02 02:34:08 +03008819 free(dut->sae_commit_override);
8820 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03008821 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02008822 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03008823
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008824 dut->sta_associate_wait_connect = 0;
8825 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03008826 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008827 dut->sta_tod_policy = 0;
8828
Jouni Malinend86e5822017-08-29 03:55:32 +03008829 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02008830 free(dut->dpp_peer_uri);
8831 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02008832 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02008833 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03008834 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03008835
Jouni Malinenfac9cad2017-10-10 18:35:55 +03008836 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
8837
vamsi krishnaa2799492017-12-05 14:28:01 +05308838 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308839 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05308840 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05308841 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
8842 dut->fils_hlp = 0;
8843#ifdef ANDROID
8844 hlp_thread_cleanup(dut);
8845#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05308846 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308847
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308848 if (dut->program == PROGRAM_QM) {
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308849 wpa_command(intf, "SET interworking 1");
Vinita S. Maloo2287f142021-02-01 16:17:09 +05308850 wpa_command(intf, "SET disable_scs_support 0");
Vinita S. Maloo83dee552021-04-12 16:47:47 +05308851 wpa_command(intf, "SET disable_mscs_support 0");
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +05308852 dut->qm_domain_name[0] = '\0';
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308853 snprintf(buf, sizeof(buf),
8854 "ip -6 route replace fe80::/64 dev %s table local",
8855 intf);
8856 if (system(buf) != 0)
8857 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s",
8858 buf);
Veerendranath Jakkam9ceb3b12021-09-10 03:18:17 +05308859
8860 stop_dscp_policy_mon_thread(dut);
8861 clear_all_dscp_policies(dut);
Veerendranath Jakkamea7f0692021-08-11 19:13:12 +05308862 }
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308863
Jouni Malinen8179fee2019-03-28 03:19:47 +02008864 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03008865 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02008866
Sunil Dutt076081f2018-02-05 19:45:50 +05308867#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008868 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05308869 dut->config_rsnie == 1) {
8870 dut->config_rsnie = 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308871 sta_config_params(dut, intf, STA_SET_RSNIE, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05308872 }
8873#endif /* NL80211_SUPPORT */
8874
Sunil Duttfebf8a82018-02-09 18:50:13 +05308875 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
8876 dut->dev_role = DEVROLE_STA_CFON;
8877 return sta_cfon_reset_default(dut, conn, cmd);
8878 }
8879
Jouni Malinen439352d2018-09-13 03:42:23 +03008880 wpa_command(intf, "SET setband AUTO");
8881
Veerendranath Jakkamc1f71b62021-01-23 03:09:51 +05308882 ret = wpa_command_resp(intf, "GET_CAPABILITY ocv", resp, sizeof(resp));
8883 dut->ocvc = ret == 0 && strncmp(resp, "supported", 9) == 0;
8884
8885 ret = wpa_command_resp(intf, "GET_CAPABILITY beacon_prot", resp,
8886 sizeof(resp));
8887 dut->beacon_prot = ret == 0 && strncmp(resp, "supported", 9) == 0;
8888
Veerendranath Jakkam47867202020-12-21 01:53:52 +05308889 if (sta_set_client_privacy(dut, conn, intf,
8890 dut->program == PROGRAM_WPA3 &&
8891 dut->device_type == STA_dut &&
8892 dut->client_privacy_default)) {
8893 sigma_dut_print(dut, DUT_MSG_ERROR,
8894 "Failed to set client privacy functionality");
8895 /* sta_reset_default command is not really supposed to fail,
8896 * so allow this to continue. */
8897 }
8898
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05308899 dut->saquery_oci_freq = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308900
Sunil Duttfebf8a82018-02-09 18:50:13 +05308901 if (dut->program != PROGRAM_VHT)
8902 return cmd_sta_p2p_reset(dut, conn, cmd);
8903
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08008904 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008905}
8906
8907
Jouni Malinenf7222712019-06-13 01:50:21 +03008908static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
8909 struct sigma_conn *conn,
8910 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008911{
8912 const char *program = get_param(cmd, "Program");
8913
8914 if (program == NULL)
8915 return -1;
8916#ifdef ANDROID_NAN
8917 if (strcasecmp(program, "NAN") == 0)
8918 return nan_cmd_sta_get_events(dut, conn, cmd);
8919#endif /* ANDROID_NAN */
8920 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8921 return 0;
8922}
8923
8924
Jouni Malinen82905202018-04-29 17:20:10 +03008925static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
8926 struct sigma_cmd *cmd)
8927{
8928 const char *url = get_param(cmd, "url");
8929 const char *method = get_param(cmd, "method");
8930 pid_t pid;
8931 int status;
8932
8933 if (!url || !method)
8934 return -1;
8935
8936 /* TODO: Add support for method,post */
8937 if (strcasecmp(method, "get") != 0) {
8938 send_resp(dut, conn, SIGMA_ERROR,
8939 "ErrorCode,Unsupported method");
8940 return 0;
8941 }
8942
8943 pid = fork();
8944 if (pid < 0) {
8945 perror("fork");
8946 return -1;
8947 }
8948
8949 if (pid == 0) {
8950 char * argv[5] = { "wget", "-O", "/dev/null",
8951 (char *) url, NULL };
8952
8953 execv("/usr/bin/wget", argv);
8954 perror("execv");
8955 exit(0);
8956 return -1;
8957 }
8958
8959 if (waitpid(pid, &status, 0) < 0) {
8960 perror("waitpid");
8961 return -1;
8962 }
8963
8964 if (WIFEXITED(status)) {
8965 const char *errmsg;
8966
8967 if (WEXITSTATUS(status) == 0)
8968 return 1;
8969 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
8970 WEXITSTATUS(status));
8971 switch (WEXITSTATUS(status)) {
8972 case 4:
8973 errmsg = "errmsg,Network failure";
8974 break;
8975 case 8:
8976 errmsg = "errmsg,Server issued an error response";
8977 break;
8978 default:
8979 errmsg = "errmsg,Unknown failure from wget";
8980 break;
8981 }
8982 send_resp(dut, conn, SIGMA_ERROR, errmsg);
8983 return 0;
8984 }
8985
8986 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
8987 return 0;
8988}
8989
8990
Jouni Malinenf7222712019-06-13 01:50:21 +03008991static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
8992 struct sigma_conn *conn,
8993 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008994{
8995 const char *program = get_param(cmd, "Prog");
8996
Jouni Malinen82905202018-04-29 17:20:10 +03008997 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008998 return -1;
8999#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03009000 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009001 return nan_cmd_sta_exec_action(dut, conn, cmd);
9002#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03009003
9004 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07009005 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03009006
9007 if (get_param(cmd, "url"))
9008 return sta_exec_action_url(dut, conn, cmd);
9009
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009010 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
9011 return 0;
9012}
9013
9014
Jouni Malinenf7222712019-06-13 01:50:21 +03009015static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
9016 struct sigma_conn *conn,
9017 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009018{
9019 const char *intf = get_param(cmd, "Interface");
9020 const char *val, *mcs32, *rate;
9021
9022 val = get_param(cmd, "GREENFIELD");
9023 if (val) {
9024 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
9025 /* Enable GD */
9026 send_resp(dut, conn, SIGMA_ERROR,
9027 "ErrorCode,GF not supported");
9028 return 0;
9029 }
9030 }
9031
9032 val = get_param(cmd, "SGI20");
9033 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009034 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009035 case DRIVER_ATHEROS:
9036 ath_sta_set_sgi(dut, intf, val);
9037 break;
9038 default:
9039 send_resp(dut, conn, SIGMA_ERROR,
9040 "ErrorCode,SGI20 not supported");
9041 return 0;
9042 }
9043 }
9044
9045 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
9046 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
9047 if (mcs32 && rate) {
9048 /* TODO */
9049 send_resp(dut, conn, SIGMA_ERROR,
9050 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
9051 return 0;
9052 } else if (mcs32 && !rate) {
9053 /* TODO */
9054 send_resp(dut, conn, SIGMA_ERROR,
9055 "ErrorCode,MCS32 not supported");
9056 return 0;
9057 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009058 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009059 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07009060 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009061 ath_sta_set_11nrates(dut, intf, rate);
9062 break;
9063 default:
9064 send_resp(dut, conn, SIGMA_ERROR,
9065 "ErrorCode,MCS32_FIXEDRATE not supported");
9066 return 0;
9067 }
9068 }
9069
9070 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9071}
9072
9073
Arif Hussain7b47d2d2018-05-09 10:44:02 -07009074static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
9075 int mcs_config)
9076{
9077#ifdef NL80211_SUPPORT
9078 int ret;
9079
9080 switch (mcs_config) {
9081 case HE_80_MCS0_7:
9082 case HE_80_MCS0_9:
9083 case HE_80_MCS0_11:
9084 ret = sta_set_he_mcs(dut, intf, mcs_config);
9085 if (ret) {
9086 sigma_dut_print(dut, DUT_MSG_ERROR,
9087 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
9088 mcs_config, ret);
9089 }
9090 break;
9091 default:
9092 sigma_dut_print(dut, DUT_MSG_ERROR,
9093 "cmd_set_max_he_mcs: Invalid mcs %d",
9094 mcs_config);
9095 break;
9096 }
9097#else /* NL80211_SUPPORT */
9098 sigma_dut_print(dut, DUT_MSG_ERROR,
9099 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
9100#endif /* NL80211_SUPPORT */
9101}
9102
9103
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009104struct wait_event {
9105 struct sigma_dut *dut;
9106 int cmd;
9107 unsigned int twt_op;
9108};
9109
9110#ifdef NL80211_SUPPORT
9111
9112static int twt_event_handler(struct nl_msg *msg, void *arg)
9113{
9114 struct wait_event *wait = arg;
9115 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9116 struct nlattr *tb[NL80211_ATTR_MAX + 1];
9117 uint32_t subcmd;
9118 uint8_t *data = NULL;
9119 size_t len = 0;
9120 struct nlattr *twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_MAX + 1];
9121 struct nlattr *twt_status[QCA_WLAN_VENDOR_ATTR_TWT_SETUP_MAX + 1];
9122 int cmd_id;
9123 unsigned char val;
9124
9125 if (!wait)
9126 return NL_SKIP;
9127
9128 if (gnlh->cmd != NL80211_CMD_VENDOR) {
9129 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9130 "%s: NL cmd is not vendor %d", __func__,
9131 gnlh->cmd);
9132 return NL_SKIP;
9133 }
9134
9135 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
9136 genlmsg_attrlen(gnlh, 0), NULL);
9137
9138 if (!tb[NL80211_ATTR_VENDOR_ID] || !tb[NL80211_ATTR_VENDOR_SUBCMD]) {
9139 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9140 "%s: vendor ID not found", __func__);
9141 return NL_SKIP;
9142 }
9143 subcmd = nla_get_u32(tb[NL80211_ATTR_VENDOR_SUBCMD]);
9144
9145 if (subcmd != QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) {
9146 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9147 "%s: Not a TWT_cmd %d", __func__, subcmd);
9148 return NL_SKIP;
9149 }
9150 if (tb[NL80211_ATTR_VENDOR_DATA]) {
9151 data = nla_data(tb[NL80211_ATTR_VENDOR_DATA]);
9152 len = nla_len(tb[NL80211_ATTR_VENDOR_DATA]);
9153 } else {
9154 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9155 "%s: vendor data not present", __func__);
9156 return NL_SKIP;
9157 }
9158 if (!data || !len) {
9159 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9160 "Invalid vendor data or len");
9161 return NL_SKIP;
9162 }
9163 sigma_dut_print(wait->dut, DUT_MSG_DEBUG,
9164 "event data len %ld", len);
9165 hex_dump(wait->dut, data, len);
9166 if (nla_parse(twt_rsp, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_MAX,
9167 (struct nlattr *) data, len, NULL)) {
9168 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9169 "vendor data parse error");
9170 return NL_SKIP;
9171 }
9172
9173 val = nla_get_u8(twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION]);
9174 if (val != wait->twt_op) {
9175 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9176 "Invalid TWT operation, expected %d, rcvd %d",
9177 wait->twt_op, val);
9178 return NL_SKIP;
9179 }
9180 if (nla_parse_nested(twt_status, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_MAX,
9181 twt_rsp[QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS],
9182 NULL)) {
9183 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9184 "nla_parse failed for TWT event");
9185 return NL_SKIP;
9186 }
9187
9188 cmd_id = QCA_WLAN_VENDOR_ATTR_TWT_SETUP_STATUS;
9189 if (!twt_status[cmd_id]) {
9190 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9191 "%s TWT resp status missing", __func__);
9192 wait->cmd = -1;
9193 } else {
9194 val = nla_get_u8(twt_status[cmd_id]);
9195 if (val != QCA_WLAN_VENDOR_TWT_STATUS_OK) {
9196 sigma_dut_print(wait->dut, DUT_MSG_ERROR,
9197 "%s TWT resp status %d", __func__, val);
9198 wait->cmd = -1;
9199 } else {
9200 wait->cmd = 1;
9201 }
9202 }
9203
9204 return NL_SKIP;
9205}
9206
9207
9208static int wait_on_nl_socket(struct nl_sock *sock, struct sigma_dut *dut,
9209 unsigned int timeout)
9210{
9211 fd_set read_fd_set;
9212 int retval;
9213 int sock_fd;
9214 struct timeval time_out;
9215
9216 time_out.tv_sec = timeout;
9217 time_out.tv_usec = 0;
9218
9219 FD_ZERO(&read_fd_set);
9220
9221 if (!sock)
9222 return -1;
9223
9224 sock_fd = nl_socket_get_fd(sock);
9225 FD_SET(sock_fd, &read_fd_set);
9226
9227 retval = select(sock_fd + 1, &read_fd_set, NULL, NULL, &time_out);
9228
9229 if (retval == 0)
9230 sigma_dut_print(dut, DUT_MSG_ERROR,
9231 "%s: TWT event response timedout", __func__);
9232
9233 if (retval < 0)
9234 sigma_dut_print(dut, DUT_MSG_ERROR, "%s:no NL msgs, ret=%d",
9235 __func__, retval);
9236
9237 return retval;
9238}
9239
9240
9241#define TWT_ASYNC_EVENT_WAIT_TIME_SEC 6
9242
9243static int twt_async_event_wait(struct sigma_dut *dut, unsigned int twt_op)
9244{
9245 struct nl_cb *cb;
9246 int err_code = 0, select_retval = 0;
9247 struct wait_event wait_info;
9248
9249 cb = nl_socket_get_cb(dut->nl_ctx->event_sock);
9250 if (!cb) {
9251 sigma_dut_print(dut, DUT_MSG_ERROR,
9252 "event callback not found");
9253 return ERROR_SEND_STATUS;
9254 }
9255
9256 wait_info.cmd = 0;
9257 wait_info.dut = dut;
9258 wait_info.twt_op = twt_op;
9259
9260 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, twt_event_handler, &wait_info);
9261
9262 while (!wait_info.cmd) {
9263 select_retval = wait_on_nl_socket(
9264 dut->nl_ctx->event_sock, dut,
9265 TWT_ASYNC_EVENT_WAIT_TIME_SEC);
9266
9267 if (select_retval > 0) {
9268 err_code = nl_recvmsgs(dut->nl_ctx->event_sock, cb);
9269 if (err_code < 0) {
9270 sigma_dut_print(dut, DUT_MSG_ERROR,
9271 "%s: nl rcv failed, err_code %d",
9272 __func__, err_code);
9273 break;
9274 }
9275 } else {
9276 sigma_dut_print(dut, DUT_MSG_ERROR,
9277 "%s: wait on socket failed %d",
9278 __func__, select_retval);
9279 err_code = 1;
9280 break;
9281 }
9282
9283 }
9284 nl_cb_put(cb);
9285
9286 if (wait_info.cmd < 0)
9287 err_code = 1;
9288
9289 sigma_dut_print(dut, DUT_MSG_DEBUG,
9290 "%s: rcvd cmd %d, err_code %d, s_ret %d",
9291 __func__, wait_info.cmd, err_code, select_retval);
9292
9293 return err_code;
9294}
9295
9296#endif /* NL80211_SUPPORT */
9297
9298
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009299static int sta_twt_send_suspend(struct sigma_dut *dut, struct sigma_conn *conn,
9300 struct sigma_cmd *cmd)
9301{
9302#ifdef NL80211_SUPPORT
9303 struct nlattr *attr, *attr1;
9304 struct nl_msg *msg;
9305 int ifindex, ret;
9306 const char *intf = get_param(cmd, "Interface");
9307
9308 ifindex = if_nametoindex(intf);
9309 if (ifindex == 0) {
9310 sigma_dut_print(dut, DUT_MSG_ERROR,
9311 "%s: Index for interface %s failed",
9312 __func__, intf);
9313 return ERROR_SEND_STATUS;
9314 }
9315
9316 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9317 NL80211_CMD_VENDOR)) ||
9318 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9319 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9320 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9321 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
9322 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9323 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9324 QCA_WLAN_TWT_SUSPEND) ||
9325 !(attr1 = nla_nest_start(msg,
Kiran Kumar Lokere7ede00c2021-08-09 00:59:52 -07009326 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS))) {
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009327 sigma_dut_print(dut, DUT_MSG_ERROR,
9328 "%s: err in adding vendor_cmd and vendor_data",
9329 __func__);
9330 nlmsg_free(msg);
9331 return ERROR_SEND_STATUS;
9332 }
9333 nla_nest_end(msg, attr1);
9334 nla_nest_end(msg, attr);
9335
9336 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9337 if (ret) {
9338 sigma_dut_print(dut, DUT_MSG_ERROR,
9339 "%s: err in send_and_recv_msgs, ret=%d",
9340 __func__, ret);
9341 }
9342
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009343 if (!dut->sta_async_twt_supp)
9344 return ret;
9345
9346 return twt_async_event_wait(dut, QCA_WLAN_TWT_SUSPEND);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009347#else /* NL80211_SUPPORT */
9348 sigma_dut_print(dut, DUT_MSG_ERROR,
9349 "TWT suspend cannot be done without NL80211_SUPPORT defined");
9350 return ERROR_SEND_STATUS;
9351#endif /* NL80211_SUPPORT */
9352}
9353
9354
9355static int sta_twt_send_nudge(struct sigma_dut *dut, struct sigma_conn *conn,
9356 struct sigma_cmd *cmd,
9357 unsigned int suspend_duration)
9358{
9359#ifdef NL80211_SUPPORT
9360 struct nlattr *attr, *attr1;
9361 struct nl_msg *msg;
9362 int ifindex, ret;
9363 const char *intf = get_param(cmd, "Interface");
9364 int next_twt_size = 1;
9365
9366 ifindex = if_nametoindex(intf);
9367 if (ifindex == 0) {
9368 sigma_dut_print(dut, DUT_MSG_ERROR,
9369 "%s: Index for interface %s failed",
9370 __func__, intf);
9371 return ERROR_SEND_STATUS;
9372 }
9373
9374 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9375 NL80211_CMD_VENDOR)) ||
9376 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9377 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9378 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9379 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
9380 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9381 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9382 QCA_WLAN_TWT_NUDGE) ||
9383 !(attr1 = nla_nest_start(msg,
9384 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
9385 (suspend_duration &&
9386 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_WAKE_TIME,
9387 suspend_duration)) ||
9388 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_NEXT_TWT_SIZE,
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009389 next_twt_size) ||
9390 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_FLOW_ID, 0)) {
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009391 sigma_dut_print(dut, DUT_MSG_ERROR,
9392 "%s: err in adding vendor_cmd and vendor_data",
9393 __func__);
9394 nlmsg_free(msg);
9395 return ERROR_SEND_STATUS;
9396 }
9397 nla_nest_end(msg, attr1);
9398 nla_nest_end(msg, attr);
9399
9400 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9401 if (ret) {
9402 sigma_dut_print(dut, DUT_MSG_ERROR,
9403 "%s: err in send_and_recv_msgs, ret=%d",
9404 __func__, ret);
9405 }
9406
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009407 if (!dut->sta_async_twt_supp)
9408 return ret;
9409
9410 return twt_async_event_wait(dut, QCA_WLAN_TWT_NUDGE);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009411#else /* NL80211_SUPPORT */
9412 sigma_dut_print(dut, DUT_MSG_ERROR,
9413 "TWT suspend cannot be done without NL80211_SUPPORT defined");
9414 return ERROR_SEND_STATUS;
9415#endif /* NL80211_SUPPORT */
9416}
9417
9418
9419static int sta_twt_suspend_or_nudge(struct sigma_dut *dut,
9420 struct sigma_conn *conn,
9421 struct sigma_cmd *cmd)
9422{
9423 const char *val;
9424
9425 val = get_param(cmd, "TWT_SuspendDuration");
9426 if (val) {
9427 unsigned int suspend_duration;
9428
9429 suspend_duration = atoi(val);
9430 suspend_duration = suspend_duration * 1000 * 1000;
9431 return sta_twt_send_nudge(dut, conn, cmd, suspend_duration);
9432 }
9433
9434 return sta_twt_send_suspend(dut, conn, cmd);
9435}
9436
9437
9438static int sta_twt_resume(struct sigma_dut *dut, struct sigma_conn *conn,
9439 struct sigma_cmd *cmd)
9440{
9441#ifdef NL80211_SUPPORT
9442 struct nlattr *attr, *attr1;
9443 struct nl_msg *msg;
9444 int ifindex, ret;
9445 const char *intf = get_param(cmd, "Interface");
9446 int next2_twt_size = 1;
9447 unsigned int resume_duration = 0;
9448 const char *val;
9449
9450 ifindex = if_nametoindex(intf);
9451 if (ifindex == 0) {
9452 sigma_dut_print(dut, DUT_MSG_ERROR,
9453 "%s: Index for interface %s failed",
9454 __func__, intf);
9455 return ERROR_SEND_STATUS;
9456 }
9457
9458 val = get_param(cmd, "TWT_ResumeDuration");
9459 if (val) {
9460 resume_duration = atoi(val);
9461 resume_duration = resume_duration * 1000 * 1000;
9462 }
9463
9464 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9465 NL80211_CMD_VENDOR)) ||
9466 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9467 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9468 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9469 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
9470 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9471 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9472 QCA_WLAN_TWT_RESUME) ||
9473 !(attr1 = nla_nest_start(msg,
9474 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
9475 (resume_duration &&
9476 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_RESUME_NEXT2_TWT,
9477 resume_duration)) ||
9478 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_RESUME_NEXT_TWT_SIZE,
9479 next2_twt_size)) {
9480 sigma_dut_print(dut, DUT_MSG_ERROR,
9481 "%s: err in adding vendor_cmd and vendor_data",
9482 __func__);
9483 nlmsg_free(msg);
9484 return ERROR_SEND_STATUS;
9485 }
9486 nla_nest_end(msg, attr1);
9487 nla_nest_end(msg, attr);
9488
9489 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9490 if (ret) {
9491 sigma_dut_print(dut, DUT_MSG_ERROR,
9492 "%s: err in send_and_recv_msgs, ret=%d",
9493 __func__, ret);
9494 }
9495
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009496 if (!dut->sta_async_twt_supp)
9497 return ret;
9498
9499 return twt_async_event_wait(dut, QCA_WLAN_TWT_RESUME);
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009500#else /* NL80211_SUPPORT */
9501 sigma_dut_print(dut, DUT_MSG_ERROR,
9502 "TWT resume cannot be done without NL80211_SUPPORT defined");
9503 return ERROR_SEND_STATUS;
9504#endif /* NL80211_SUPPORT */
9505}
9506
9507
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009508#define TWT_REQUEST_CMD 0
9509#define TWT_SUGGEST_CMD 1
9510#define TWT_DEMAND_CMD 2
9511
Arif Hussain480d5f42019-03-12 14:40:42 -07009512static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
9513 struct sigma_cmd *cmd)
9514{
9515#ifdef NL80211_SUPPORT
9516 struct nlattr *params;
9517 struct nlattr *attr;
Arif Hussain480d5f42019-03-12 14:40:42 -07009518 struct nl_msg *msg;
9519 int ifindex, ret;
9520 const char *val;
9521 const char *intf = get_param(cmd, "Interface");
9522 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
9523 wake_interval_mantissa = 512;
9524 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009525 protection = 0, cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009526 int bcast_twt = 0;
9527 int bcast_twt_id = 0, bcast_twt_recommdn = 0, bcast_twt_persis = 0;
Arif Hussain480d5f42019-03-12 14:40:42 -07009528
9529 ifindex = if_nametoindex(intf);
9530 if (ifindex == 0) {
9531 sigma_dut_print(dut, DUT_MSG_ERROR,
9532 "%s: Index for interface %s failed",
9533 __func__, intf);
9534 return -1;
9535 }
9536
9537 val = get_param(cmd, "FlowType");
9538 if (val) {
9539 flow_type = atoi(val);
9540 if (flow_type != 0 && flow_type != 1) {
9541 sigma_dut_print(dut, DUT_MSG_ERROR,
9542 "TWT: Invalid FlowType %d", flow_type);
9543 return -1;
9544 }
9545 }
9546
9547 val = get_param(cmd, "TWT_Trigger");
9548 if (val) {
9549 twt_trigger = atoi(val);
9550 if (twt_trigger != 0 && twt_trigger != 1) {
9551 sigma_dut_print(dut, DUT_MSG_ERROR,
9552 "TWT: Invalid TWT_Trigger %d",
9553 twt_trigger);
9554 return -1;
9555 }
9556 }
9557
9558 val = get_param(cmd, "Protection");
9559 if (val) {
9560 protection = atoi(val);
9561 if (protection != 0 && protection != 1) {
9562 sigma_dut_print(dut, DUT_MSG_ERROR,
9563 "TWT: Invalid Protection %d",
9564 protection);
9565 return -1;
9566 }
9567 }
9568
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009569 val = get_param(cmd, "SetupCommand");
9570 if (val) {
9571 cmd_type = atoi(val);
9572 if (cmd_type == TWT_REQUEST_CMD)
9573 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_REQUEST;
9574 else if (cmd_type == TWT_SUGGEST_CMD)
9575 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
9576 else if (cmd_type == TWT_DEMAND_CMD)
9577 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_DEMAND;
9578 else
9579 sigma_dut_print(dut, DUT_MSG_ERROR,
9580 "Default suggest is used for cmd %d",
9581 cmd_type);
9582 }
9583
Arif Hussain480d5f42019-03-12 14:40:42 -07009584 val = get_param(cmd, "TargetWakeTime");
9585 if (val)
9586 target_wake_time = atoi(val);
9587
9588 val = get_param(cmd, "WakeIntervalMantissa");
9589 if (val)
9590 wake_interval_mantissa = atoi(val);
9591
9592 val = get_param(cmd, "WakeIntervalExp");
9593 if (val)
9594 wake_interval_exp = atoi(val);
9595
9596 val = get_param(cmd, "NominalMinWakeDur");
9597 if (val)
9598 nominal_min_wake_dur = atoi(val);
9599
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009600 val = get_param(cmd, "BTWT_ID");
9601 if (val) {
9602 bcast_twt_id = atoi(val);
9603 bcast_twt = 1;
9604 }
9605
9606 val = get_param(cmd, "BTWT_Persistence");
9607 if (val) {
9608 bcast_twt_persis = atoi(val);
9609 bcast_twt = 1;
9610 }
9611
9612 val = get_param(cmd, "BTWT_Recommendation");
9613 if (val) {
9614 bcast_twt_recommdn = atoi(val);
9615 bcast_twt = 1;
9616 }
9617
9618 if (bcast_twt)
9619 sigma_dut_print(dut, DUT_MSG_DEBUG,
9620 "BCAST_TWT: ID %d, RECOMM %d, PERSIS %d",
9621 bcast_twt_id, bcast_twt_recommdn,
9622 bcast_twt_persis);
9623
Arif Hussain480d5f42019-03-12 14:40:42 -07009624 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9625 NL80211_CMD_VENDOR)) ||
9626 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9627 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9628 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009629 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009630 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009631 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9632 QCA_WLAN_TWT_SET) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009633 !(params = nla_nest_start(
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009634 msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009635 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
9636 wake_interval_exp) ||
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07009637 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, cmd_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07009638 (twt_trigger &&
9639 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009640 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
9641 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07009642 (protection &&
9643 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009644 (bcast_twt &&
9645 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST)) ||
9646 (bcast_twt &&
9647 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_ID,
9648 bcast_twt_id)) ||
9649 (bcast_twt &&
9650 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_PERSISTENCE,
9651 bcast_twt_persis)) ||
9652 (bcast_twt &&
9653 nla_put_u8(msg,
9654 QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_RECOMMENDATION,
9655 bcast_twt_recommdn)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009656 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
9657 target_wake_time) ||
9658 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
9659 nominal_min_wake_dur) ||
9660 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
9661 wake_interval_mantissa)) {
9662 sigma_dut_print(dut, DUT_MSG_ERROR,
9663 "%s: err in adding vendor_cmd and vendor_data",
9664 __func__);
9665 nlmsg_free(msg);
9666 return -1;
9667 }
Arif Hussain480d5f42019-03-12 14:40:42 -07009668 nla_nest_end(msg, params);
9669 nla_nest_end(msg, attr);
9670
9671 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9672 if (ret) {
9673 sigma_dut_print(dut, DUT_MSG_ERROR,
9674 "%s: err in send_and_recv_msgs, ret=%d",
9675 __func__, ret);
9676 }
9677
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009678 if (!dut->sta_async_twt_supp)
9679 return ret;
9680
9681 return twt_async_event_wait(dut, QCA_WLAN_TWT_SET);
Arif Hussain480d5f42019-03-12 14:40:42 -07009682#else /* NL80211_SUPPORT */
9683 sigma_dut_print(dut, DUT_MSG_ERROR,
9684 "TWT request cannot be done without NL80211_SUPPORT defined");
9685 return -1;
9686#endif /* NL80211_SUPPORT */
9687}
9688
9689
9690static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
9691 struct sigma_cmd *cmd)
9692{
9693 #ifdef NL80211_SUPPORT
9694 struct nlattr *params;
9695 struct nlattr *attr;
Arif Hussain480d5f42019-03-12 14:40:42 -07009696 int ifindex, ret;
9697 struct nl_msg *msg;
9698 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009699 int bcast_twt = 0;
9700 int bcast_twt_id = 0;
9701 const char *val;
Arif Hussain480d5f42019-03-12 14:40:42 -07009702
9703 ifindex = if_nametoindex(intf);
9704 if (ifindex == 0) {
9705 sigma_dut_print(dut, DUT_MSG_ERROR,
9706 "%s: Index for interface %s failed",
9707 __func__, intf);
9708 return -1;
9709 }
9710
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009711 val = get_param(cmd, "BTWT_ID");
9712 if (val) {
9713 bcast_twt_id = atoi(val);
9714 bcast_twt = 1;
9715 }
9716
Arif Hussain480d5f42019-03-12 14:40:42 -07009717 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9718 NL80211_CMD_VENDOR)) ||
9719 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9720 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9721 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009722 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009723 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009724 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
9725 QCA_WLAN_TWT_TERMINATE) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07009726 !(params = nla_nest_start(
9727 msg,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009728 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
Kiran Kumar Lokere68c93de2021-06-24 01:06:47 -07009729 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0) ||
9730 (bcast_twt &&
9731 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST)) ||
9732 (bcast_twt &&
9733 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST_ID,
9734 bcast_twt_id))) {
Arif Hussain480d5f42019-03-12 14:40:42 -07009735 sigma_dut_print(dut, DUT_MSG_ERROR,
9736 "%s: err in adding vendor_cmd and vendor_data",
9737 __func__);
9738 nlmsg_free(msg);
9739 return -1;
9740 }
Arif Hussain480d5f42019-03-12 14:40:42 -07009741 nla_nest_end(msg, params);
9742 nla_nest_end(msg, attr);
9743
9744 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9745 if (ret) {
9746 sigma_dut_print(dut, DUT_MSG_ERROR,
9747 "%s: err in send_and_recv_msgs, ret=%d",
9748 __func__, ret);
9749 }
9750
Kiran Kumar Lokeref61a7432021-06-24 00:19:19 -07009751 if (!dut->sta_async_twt_supp)
9752 return ret;
9753
9754 return twt_async_event_wait(dut, QCA_WLAN_TWT_TERMINATE);
Arif Hussain480d5f42019-03-12 14:40:42 -07009755#else /* NL80211_SUPPORT */
9756 sigma_dut_print(dut, DUT_MSG_ERROR,
9757 "TWT teardown cannot be done without NL80211_SUPPORT defined");
9758 return -1;
9759#endif /* NL80211_SUPPORT */
9760}
9761
9762
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08009763static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
9764 struct sigma_cmd *cmd)
9765{
9766#ifdef NL80211_SUPPORT
9767 struct nlattr *params;
9768 struct nlattr *attr;
9769 struct nlattr *attr1;
9770 struct nl_msg *msg;
9771 int ifindex, ret;
9772 const char *val;
9773 const char *intf = get_param(cmd, "Interface");
9774 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
9775 ulmu_data_dis = 0;
9776
9777 ifindex = if_nametoindex(intf);
9778 if (ifindex == 0) {
9779 sigma_dut_print(dut, DUT_MSG_ERROR,
9780 "%s: Index for interface %s failed",
9781 __func__, intf);
9782 return -1;
9783 }
9784 val = get_param(cmd, "OMCtrl_RxNSS");
9785 if (val)
9786 rx_nss = atoi(val);
9787
9788 val = get_param(cmd, "OMCtrl_ChnlWidth");
9789 if (val)
9790 ch_bw = atoi(val);
9791
9792 val = get_param(cmd, "OMCtrl_ULMUDisable");
9793 if (val)
9794 ulmu_dis = atoi(val);
9795
9796 val = get_param(cmd, "OMCtrl_TxNSTS");
9797 if (val)
9798 tx_nsts = atoi(val);
9799
9800 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
9801 if (val)
9802 ulmu_data_dis = atoi(val);
9803
9804 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9805 NL80211_CMD_VENDOR)) ||
9806 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9807 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9808 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9809 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9810 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9811 !(params = nla_nest_start(
9812 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
9813 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9814 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
9815 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
9816 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
9817 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
9818 ulmu_data_dis) ||
9819 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
9820 ulmu_dis)) {
9821 sigma_dut_print(dut, DUT_MSG_ERROR,
9822 "%s: err in adding vendor_cmd and vendor_data",
9823 __func__);
9824 nlmsg_free(msg);
9825 return -1;
9826 }
9827 nla_nest_end(msg, attr1);
9828 nla_nest_end(msg, params);
9829 nla_nest_end(msg, attr);
9830
9831 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9832 if (ret) {
9833 sigma_dut_print(dut, DUT_MSG_ERROR,
9834 "%s: err in send_and_recv_msgs, ret=%d",
9835 __func__, ret);
9836 }
9837
9838 return ret;
9839#else /* NL80211_SUPPORT */
9840 sigma_dut_print(dut, DUT_MSG_ERROR,
9841 "OMI TX cannot be processed without NL80211_SUPPORT defined");
9842 return -1;
9843#endif /* NL80211_SUPPORT */
9844}
9845
9846
Jouni Malinen224e3902021-06-09 16:41:27 +03009847static enum sigma_cmd_result
9848cmd_sta_set_wireless_vht(struct sigma_dut *dut, struct sigma_conn *conn,
9849 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009850{
9851 const char *intf = get_param(cmd, "Interface");
9852 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07009853 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009854 int tkip = -1;
9855 int wep = -1;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309856 int iwpriv_status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009857
Arif Hussaina37e9552018-06-20 17:05:59 -07009858 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009859 val = get_param(cmd, "SGI80");
9860 if (val) {
9861 int sgi80;
9862
9863 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009864 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009865 }
9866
9867 val = get_param(cmd, "TxBF");
9868 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009869 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009870 case DRIVER_WCN:
9871 if (sta_set_tx_beamformee(dut, intf, 1)) {
9872 send_resp(dut, conn, SIGMA_ERROR,
9873 "ErrorCode,Failed to set TX beamformee enable");
Jouni Malinen224e3902021-06-09 16:41:27 +03009874 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009875 }
9876 break;
9877 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009878 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009879 send_resp(dut, conn, SIGMA_ERROR,
9880 "ErrorCode,Setting vhtsubfee failed");
Jouni Malinen224e3902021-06-09 16:41:27 +03009881 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009882 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009883 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009884 send_resp(dut, conn, SIGMA_ERROR,
9885 "ErrorCode,Setting vhtsubfer failed");
Jouni Malinen224e3902021-06-09 16:41:27 +03009886 return STATUS_SENT_ERROR;
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009887 }
9888 break;
9889 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009890 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009891 "Unsupported driver type");
9892 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009893 }
9894 }
9895
9896 val = get_param(cmd, "MU_TxBF");
9897 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009898 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009899 case DRIVER_ATHEROS:
9900 ath_sta_set_txsp_stream(dut, intf, "1SS");
9901 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009902 run_iwpriv(dut, intf, "vhtmubfee 1");
9903 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05309904 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009905 case DRIVER_WCN:
9906 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
9907 send_resp(dut, conn, SIGMA_ERROR,
9908 "ErrorCode,Failed to set RX/TXSP_STREAM");
Jouni Malinen224e3902021-06-09 16:41:27 +03009909 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009910 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05309911 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009912 default:
9913 sigma_dut_print(dut, DUT_MSG_ERROR,
9914 "Setting SP_STREAM not supported");
9915 break;
9916 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009917 }
9918
9919 val = get_param(cmd, "LDPC");
9920 if (val) {
9921 int ldpc;
9922
9923 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309924 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", ldpc);
9925 if (iwpriv_status)
9926 sta_config_params(dut, intf, STA_SET_LDPC, ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009927 }
9928
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08009929 val = get_param(cmd, "BCC");
9930 if (val) {
9931 int bcc;
9932
9933 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9934 /* use LDPC iwpriv itself to set bcc coding, bcc coding
9935 * is mutually exclusive to bcc */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309936 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", !bcc);
9937 if (iwpriv_status)
9938 sta_config_params(dut, intf, STA_SET_LDPC, !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08009939 }
9940
Arif Hussain7b47d2d2018-05-09 10:44:02 -07009941 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
9942 if (val && dut->sta_nss == 1)
9943 cmd_set_max_he_mcs(dut, intf, atoi(val));
9944
9945 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
9946 if (val && dut->sta_nss == 2)
9947 cmd_set_max_he_mcs(dut, intf, atoi(val));
9948
Arif Hussainac6c5112018-05-25 17:34:00 -07009949 val = get_param(cmd, "MCS_FixedRate");
9950 if (val) {
9951#ifdef NL80211_SUPPORT
9952 int mcs, ratecode = 0;
9953 enum he_mcs_config mcs_config;
9954 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03009955 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07009956
9957 ratecode = (0x07 & dut->sta_nss) << 5;
9958 mcs = atoi(val);
9959 /* Add the MCS to the ratecode */
9960 if (mcs >= 0 && mcs <= 11) {
9961 ratecode += mcs;
9962 if (dut->device_type == STA_testbed &&
9963 mcs > 7 && mcs <= 11) {
9964 if (mcs <= 9)
9965 mcs_config = HE_80_MCS0_9;
9966 else
9967 mcs_config = HE_80_MCS0_11;
9968 ret = sta_set_he_mcs(dut, intf, mcs_config);
9969 if (ret) {
9970 sigma_dut_print(dut, DUT_MSG_ERROR,
9971 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
9972 mcs, mcs_config, ret);
9973 }
9974 }
9975 snprintf(buf, sizeof(buf),
9976 "iwpriv %s set_11ax_rate 0x%03x",
9977 intf, ratecode);
9978 if (system(buf) != 0) {
9979 sigma_dut_print(dut, DUT_MSG_ERROR,
9980 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
9981 ratecode);
9982 }
9983 } else {
9984 sigma_dut_print(dut, DUT_MSG_ERROR,
9985 "MCS_FixedRate: HE MCS %d not supported",
9986 mcs);
9987 }
9988#else /* NL80211_SUPPORT */
9989 sigma_dut_print(dut, DUT_MSG_ERROR,
9990 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
9991#endif /* NL80211_SUPPORT */
9992 }
9993
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009994 val = get_param(cmd, "opt_md_notif_ie");
9995 if (val) {
9996 char *result = NULL;
9997 char delim[] = ";";
9998 char token[30];
9999 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010000 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010001
Peng Xub8fc5cc2017-05-10 17:27:28 -070010002 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010003 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010004
10005 /* Extract the NSS information */
10006 if (result) {
10007 value = atoi(result);
10008 switch (value) {
10009 case 1:
10010 config_val = 1;
10011 break;
10012 case 2:
10013 config_val = 3;
10014 break;
10015 case 3:
10016 config_val = 7;
10017 break;
10018 case 4:
10019 config_val = 15;
10020 break;
10021 default:
10022 config_val = 3;
10023 break;
10024 }
10025
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010026 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
10027 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010028
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010029 }
10030
10031 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010032 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010033 if (result) {
10034 value = atoi(result);
10035 switch (value) {
10036 case 20:
10037 config_val = 0;
10038 break;
10039 case 40:
10040 config_val = 1;
10041 break;
10042 case 80:
10043 config_val = 2;
10044 break;
10045 case 160:
10046 config_val = 3;
10047 break;
10048 default:
10049 config_val = 2;
10050 break;
10051 }
10052
10053 dut->chwidth = config_val;
10054
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010055 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010056 }
10057
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010058 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010059 }
10060
10061 val = get_param(cmd, "nss_mcs_cap");
10062 if (val) {
10063 int nss, mcs;
10064 char token[20];
10065 char *result = NULL;
10066 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010067 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010068
Peng Xub8fc5cc2017-05-10 17:27:28 -070010069 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010070 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010071 if (!result) {
10072 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010073 "NSS not specified");
10074 send_resp(dut, conn, SIGMA_ERROR,
10075 "errorCode,NSS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +030010076 return STATUS_SENT_ERROR;
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010077 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010078 nss = atoi(result);
10079
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010080 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -070010081 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010082
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010083 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010084 if (result == NULL) {
10085 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010086 "MCS not specified");
10087 send_resp(dut, conn, SIGMA_ERROR,
10088 "errorCode,MCS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +030010089 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010090 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010091 result = strtok_r(result, "-", &saveptr);
10092 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010093 if (!result) {
10094 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010095 "MCS not specified");
10096 send_resp(dut, conn, SIGMA_ERROR,
10097 "errorCode,MCS not specified");
Jouni Malinen224e3902021-06-09 16:41:27 +030010098 return STATUS_SENT_ERROR;
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +053010099 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010100 mcs = atoi(result);
10101
Arif Hussaina37e9552018-06-20 17:05:59 -070010102 if (program && strcasecmp(program, "HE") == 0) {
10103#ifdef NL80211_SUPPORT
10104 enum he_mcs_config mcs_config;
10105 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010106
Arif Hussaina37e9552018-06-20 17:05:59 -070010107 if (mcs >= 0 && mcs <= 7) {
10108 mcs_config = HE_80_MCS0_7;
10109 } else if (mcs > 7 && mcs <= 9) {
10110 mcs_config = HE_80_MCS0_9;
10111 } else if (mcs > 9 && mcs <= 11) {
10112 mcs_config = HE_80_MCS0_11;
10113 } else {
10114 sigma_dut_print(dut, DUT_MSG_ERROR,
10115 "nss_mcs_cap: HE: Invalid mcs: %d",
10116 mcs);
10117 send_resp(dut, conn, SIGMA_ERROR,
10118 "errorCode,Invalid MCS");
Jouni Malinen224e3902021-06-09 16:41:27 +030010119 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010120 }
Arif Hussaina37e9552018-06-20 17:05:59 -070010121
10122 ret = sta_set_he_mcs(dut, intf, mcs_config);
10123 if (ret) {
10124 sigma_dut_print(dut, DUT_MSG_ERROR,
10125 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
10126 mcs_config, ret);
10127 send_resp(dut, conn, SIGMA_ERROR,
10128 "errorCode,Failed to set MCS");
Jouni Malinen224e3902021-06-09 16:41:27 +030010129 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010130 }
Arif Hussaina37e9552018-06-20 17:05:59 -070010131#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010132 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -070010133 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
10134#endif /* NL80211_SUPPORT */
10135 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010136 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -070010137
10138 switch (nss) {
10139 case 1:
10140 switch (mcs) {
10141 case 7:
10142 vht_mcsmap = 0xfffc;
10143 break;
10144 case 8:
10145 vht_mcsmap = 0xfffd;
10146 break;
10147 case 9:
10148 vht_mcsmap = 0xfffe;
10149 break;
10150 default:
10151 vht_mcsmap = 0xfffe;
10152 break;
10153 }
10154 break;
10155 case 2:
10156 switch (mcs) {
10157 case 7:
10158 vht_mcsmap = 0xfff0;
10159 break;
10160 case 8:
10161 vht_mcsmap = 0xfff5;
10162 break;
10163 case 9:
10164 vht_mcsmap = 0xfffa;
10165 break;
10166 default:
10167 vht_mcsmap = 0xfffa;
10168 break;
10169 }
10170 break;
10171 case 3:
10172 switch (mcs) {
10173 case 7:
10174 vht_mcsmap = 0xffc0;
10175 break;
10176 case 8:
10177 vht_mcsmap = 0xffd5;
10178 break;
10179 case 9:
10180 vht_mcsmap = 0xffea;
10181 break;
10182 default:
10183 vht_mcsmap = 0xffea;
10184 break;
10185 }
10186 break;
10187 default:
10188 vht_mcsmap = 0xffea;
10189 break;
10190 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010191 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010192 }
10193 }
10194
10195 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
10196
10197 val = get_param(cmd, "Vht_tkip");
10198 if (val)
10199 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
10200
10201 val = get_param(cmd, "Vht_wep");
10202 if (val)
10203 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
10204
10205 if (tkip != -1 || wep != -1) {
10206 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010207 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010208 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010209 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010210 } else {
Jouni Malinen224e3902021-06-09 16:41:27 +030010211 send_resp(dut, conn, SIGMA_ERROR,
10212 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
10213 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010214 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010215 }
10216
Kiran Kumar Lokere09dbcef2021-08-09 00:01:41 -070010217 val = get_param(cmd, "TWTSchedSTASupport");
10218 if (val) {
10219 int set_val;
10220
10221 switch (get_driver_type(dut)) {
10222 case DRIVER_WCN:
10223 if (strcasecmp(val, "Enable") == 0) {
10224 set_val = 1;
10225 } else if (strcasecmp(val, "Disable") == 0) {
10226 set_val = 0;
10227 } else {
10228 send_resp(dut, conn, SIGMA_ERROR,
10229 "ErrorCode,Invalid TWTSchedSTASupport");
10230 return STATUS_SENT_ERROR;
10231 }
10232
10233 if (sta_set_bcast_twt_support(dut, intf, set_val)) {
10234 send_resp(dut, conn, SIGMA_ERROR,
10235 "ErrorCode,Failed to set TWTSchedSTASupport");
10236 return STATUS_SENT_ERROR;
10237 }
10238 break;
10239 default:
10240 sigma_dut_print(dut, DUT_MSG_ERROR,
10241 "Setting TWTSchedSTASupport not supported");
10242 break;
10243 }
10244 }
10245
10246 val = get_param(cmd, "MBSSID_RxCtrl");
10247 if (val) {
10248 int set_val;
10249
10250 switch (get_driver_type(dut)) {
10251 case DRIVER_WCN:
10252 if (strcasecmp(val, "Enable") == 0) {
10253 set_val = 1;
10254 } else if (strcasecmp(val, "Disable") == 0) {
10255 set_val = 0;
10256 } else {
10257 send_resp(dut, conn, SIGMA_ERROR,
10258 "ErrorCode,Invalid MBSSID_RxCtrl");
10259 return STATUS_SENT_ERROR;
10260 }
10261
10262 if (sta_set_rx_ctrl_multi_bss(dut, intf, set_val)) {
10263 send_resp(dut, conn, SIGMA_ERROR,
10264 "ErrorCode,Failed to set MBSSID_RxCtrl");
10265 return STATUS_SENT_ERROR;
10266 }
10267 break;
10268 default:
10269 sigma_dut_print(dut, DUT_MSG_ERROR,
10270 "Setting MBSSID_RxCtrl not supported");
10271 break;
10272 }
10273 }
10274
Arif Hussain55f00da2018-07-03 08:28:26 -070010275 val = get_param(cmd, "txBandwidth");
10276 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010277 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -070010278 case DRIVER_WCN:
10279 if (wcn_sta_set_width(dut, intf, val) < 0) {
10280 send_resp(dut, conn, SIGMA_ERROR,
10281 "ErrorCode,Failed to set txBandwidth");
Jouni Malinen224e3902021-06-09 16:41:27 +030010282 return STATUS_SENT_ERROR;
Arif Hussain55f00da2018-07-03 08:28:26 -070010283 }
10284 break;
10285 case DRIVER_ATHEROS:
10286 if (ath_set_width(dut, conn, intf, val) < 0) {
10287 send_resp(dut, conn, SIGMA_ERROR,
10288 "ErrorCode,Failed to set txBandwidth");
Jouni Malinen224e3902021-06-09 16:41:27 +030010289 return STATUS_SENT_ERROR;
Arif Hussain55f00da2018-07-03 08:28:26 -070010290 }
10291 break;
10292 default:
10293 sigma_dut_print(dut, DUT_MSG_ERROR,
10294 "Setting txBandwidth not supported");
10295 break;
10296 }
10297 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010298
Arif Hussain9765f7d2018-07-03 08:28:26 -070010299 val = get_param(cmd, "BeamformeeSTS");
10300 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -070010301 if (sta_set_tx_beamformee(dut, intf, 1)) {
10302 send_resp(dut, conn, SIGMA_ERROR,
10303 "ErrorCode,Failed to set TX beamformee enable");
Jouni Malinen224e3902021-06-09 16:41:27 +030010304 return STATUS_SENT_ERROR;
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -070010305 }
10306
Arif Hussain9765f7d2018-07-03 08:28:26 -070010307 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
10308 send_resp(dut, conn, SIGMA_ERROR,
10309 "ErrorCode,Failed to set BeamformeeSTS");
Jouni Malinen224e3902021-06-09 16:41:27 +030010310 return STATUS_SENT_ERROR;
Arif Hussain9765f7d2018-07-03 08:28:26 -070010311 }
10312 }
10313
Arif Hussain68d23f52018-07-11 13:39:08 -070010314 val = get_param(cmd, "Trig_MAC_Padding_Dur");
10315 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -070010316#ifdef NL80211_SUPPORT
10317 enum qca_wlan_he_mac_padding_dur set_val;
10318
10319 switch (atoi(val)) {
10320 case 16:
10321 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
10322 break;
10323 case 8:
10324 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
10325 break;
10326 default:
10327 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
10328 break;
10329 }
10330 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -070010331 send_resp(dut, conn, SIGMA_ERROR,
10332 "ErrorCode,Failed to set MAC padding duration");
Jouni Malinen224e3902021-06-09 16:41:27 +030010333 return STATUS_SENT_ERROR;
Arif Hussain68d23f52018-07-11 13:39:08 -070010334 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -070010335#else /* NL80211_SUPPORT */
10336 sigma_dut_print(dut, DUT_MSG_ERROR,
10337 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
10338#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -070010339 }
10340
Arif Hussain480d5f42019-03-12 14:40:42 -070010341 val = get_param(cmd, "TWT_ReqSupport");
10342 if (val) {
10343 int set_val;
10344
10345 if (strcasecmp(val, "Enable") == 0) {
10346 set_val = 1;
10347 } else if (strcasecmp(val, "Disable") == 0) {
10348 set_val = 0;
10349 } else {
10350 send_resp(dut, conn, SIGMA_ERROR,
10351 "ErrorCode,Invalid TWT_ReqSupport");
Jouni Malinen224e3902021-06-09 16:41:27 +030010352 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070010353 }
10354
10355 if (sta_set_twt_req_support(dut, intf, set_val)) {
10356 sigma_dut_print(dut, DUT_MSG_ERROR,
10357 "Failed to set TWT req support %d",
10358 set_val);
10359 send_resp(dut, conn, SIGMA_ERROR,
10360 "ErrorCode,Failed to set TWT_ReqSupport");
Jouni Malinen224e3902021-06-09 16:41:27 +030010361 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070010362 }
10363 }
10364
Kiran Kumar Lokered0ec5ed2021-04-01 00:15:04 -070010365 val = get_param(cmd, "PreamblePunctRx");
10366 if (val && get_driver_type(dut) == DRIVER_WCN) {
10367 int set_val;
10368
10369 if (strcasecmp(val, "Enable") == 0) {
10370 set_val = 1;
10371 } else if (strcasecmp(val, "Disable") == 0) {
10372 set_val = 0;
10373 } else {
10374 send_resp(dut, conn, SIGMA_ERROR,
10375 "ErrorCode,Invalid PreamblePunctRx");
10376 return STATUS_SENT_ERROR;
10377 }
10378
10379 if (sta_set_punctured_preamble_rx(dut, intf, set_val)) {
10380 sigma_dut_print(dut, DUT_MSG_ERROR,
10381 "Failed to set PreamblePunctRx support %d",
10382 set_val);
10383 send_resp(dut, conn, SIGMA_ERROR,
10384 "ErrorCode,Failed to set PreamblePunctRx");
10385 return STATUS_SENT_ERROR;
10386 }
10387 }
10388
Srinivas Girigowda0525e292020-11-12 13:28:21 -080010389 val = get_param(cmd, "FullBW_ULMUMIMO");
10390 if (val) {
10391 int set_val;
10392
10393 if (strcasecmp(val, "Enable") == 0) {
10394 set_val = 1;
10395 } else if (strcasecmp(val, "Disable") == 0) {
10396 set_val = 0;
10397 } else {
10398 send_resp(dut, conn, SIGMA_ERROR,
10399 "ErrorCode,Invalid FullBW_ULMUMIMO");
10400 return STATUS_SENT_ERROR;
10401 }
10402
10403 if (sta_set_fullbw_ulmumimo(dut, intf, set_val)) {
10404 sigma_dut_print(dut, DUT_MSG_ERROR,
10405 "Failed to set FullBW_ULMUMIMO %d",
10406 set_val);
10407 send_resp(dut, conn, SIGMA_ERROR,
10408 "ErrorCode,Failed to set FullBW_ULMUMIMO");
10409 return STATUS_SENT_ERROR;
10410 }
10411 }
10412
Srinivas Girigowda6707f032020-10-26 15:24:46 -070010413 val = get_param(cmd, "TWTInfoFrameTx");
10414 if (val) {
10415 if (strcasecmp(val, "Enable") == 0) {
10416 /* No-op */
10417 } else if (strcasecmp(val, "Disable") == 0) {
10418 /* No-op */
10419 } else {
10420 send_resp(dut, conn, SIGMA_ERROR,
10421 "ErrorCode,Invalid TWTInfoFrameTx");
10422 return STATUS_SENT_ERROR;
10423 }
10424 }
10425
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -070010426 val = get_param(cmd, "MU_EDCA");
10427 if (val && (strcasecmp(val, "Override") == 0)) {
10428 if (sta_set_mu_edca_override(dut, intf, 1)) {
10429 send_resp(dut, conn, SIGMA_ERROR,
10430 "ErrorCode,Failed to set MU EDCA override");
Jouni Malinen224e3902021-06-09 16:41:27 +030010431 return STATUS_SENT_ERROR;
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -070010432 }
10433 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010434
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -070010435 val = get_param(cmd, "PPDUTxType");
10436 if (val && strcasecmp(val, "ER-SU") == 0) {
10437 if (sta_set_er_su_ppdu_type_tx(dut, intf, 1)) {
10438 send_resp(dut, conn, SIGMA_ERROR,
10439 "ErrorCode,Failed to set ER-SU PPDU type Tx");
10440 return STATUS_SENT_ERROR;
10441 }
10442 }
10443
10444 val = get_param(cmd, "RUAllocTone");
10445 if (val && strcasecmp(val, "242") == 0) {
10446 if (sta_set_ru_242_tone_tx(dut, intf, 1)) {
10447 send_resp(dut, conn, SIGMA_ERROR,
10448 "ErrorCode,Failed to set RU 242 tone Tx");
10449 return STATUS_SENT_ERROR;
10450 }
10451 }
10452
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -070010453 val = get_param(cmd, "OMControl");
10454 if (val) {
10455 int set_val = 1;
10456
10457 if (strcasecmp(val, "Enable") == 0)
10458 set_val = 1;
10459 else if (strcasecmp(val, "Disable") == 0)
10460 set_val = 0;
10461
10462 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
10463 send_resp(dut, conn, SIGMA_ERROR,
10464 "ErrorCode,Failed to set OM ctrl supp");
Jouni Malinen224e3902021-06-09 16:41:27 +030010465 return STATUS_SENT_ERROR;
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -070010466 }
10467 }
10468
Kiran Kumar Lokere4f2d4b02021-04-01 00:07:39 -070010469 val = get_param(cmd, "BSSMaxIdlePeriod");
10470 if (val && sta_set_bss_max_idle_period(dut, intf, atoi(val))) {
10471 send_resp(dut, conn, SIGMA_ERROR,
10472 "ErrorCode,Failed to set BSS max idle period");
10473 return STATUS_SENT_ERROR;
10474 }
10475
Kiran Kumar Lokere07ad92b2021-08-09 00:27:14 -070010476 val = get_param(cmd, "BSS_max_idle");
10477 if (val) {
10478 int set_val = 0;
10479
10480 if (strcasecmp(val, "Enable") == 0)
10481 set_val = 1;
10482 else if (strcasecmp(val, "Disable") == 0)
10483 set_val = 0;
10484 if (sta_set_bss_max_idle_support(dut, intf, set_val)) {
10485 send_resp(dut, conn, SIGMA_ERROR,
10486 "ErrorCode,Failed to set BSS max idle support");
10487 return STATUS_SENT_ERROR;
10488 }
10489 }
10490
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010491 val = get_param(cmd, "ADDBAResp_BufSize");
10492 if (val) {
10493 int buf_size;
10494
10495 if (strcasecmp(val, "gt64") == 0)
10496 buf_size = 256;
10497 else
10498 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010499 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010500 sta_set_addba_buf_size(dut, intf, buf_size)) {
10501 send_resp(dut, conn, SIGMA_ERROR,
10502 "ErrorCode,set addbaresp_buff_size failed");
Jouni Malinen224e3902021-06-09 16:41:27 +030010503 return STATUS_SENT_ERROR;
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010504 }
10505 }
10506
10507 val = get_param(cmd, "ADDBAReq_BufSize");
10508 if (val) {
10509 int buf_size;
10510
10511 if (strcasecmp(val, "gt64") == 0)
10512 buf_size = 256;
10513 else
10514 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010515 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010516 sta_set_addba_buf_size(dut, intf, buf_size)) {
10517 send_resp(dut, conn, SIGMA_ERROR,
10518 "ErrorCode,set addbareq_buff_size failed");
Jouni Malinen224e3902021-06-09 16:41:27 +030010519 return STATUS_SENT_ERROR;
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -070010520 }
10521 }
10522
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010523 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
10524}
10525
10526
10527static int sta_set_wireless_60g(struct sigma_dut *dut,
10528 struct sigma_conn *conn,
10529 struct sigma_cmd *cmd)
10530{
10531 const char *dev_role = get_param(cmd, "DevRole");
10532
10533 if (!dev_role) {
10534 send_resp(dut, conn, SIGMA_INVALID,
10535 "ErrorCode,DevRole not specified");
10536 return 0;
10537 }
10538
10539 if (strcasecmp(dev_role, "PCP") == 0)
10540 return sta_set_60g_pcp(dut, conn, cmd);
10541 if (strcasecmp(dev_role, "STA") == 0)
10542 return sta_set_60g_sta(dut, conn, cmd);
10543 send_resp(dut, conn, SIGMA_INVALID,
10544 "ErrorCode,DevRole not supported");
10545 return 0;
10546}
10547
10548
Ankita Bajaj0d5825b2017-10-25 16:20:17 +053010549static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
10550 struct sigma_cmd *cmd)
10551{
10552 int status;
10553 const char *intf = get_param(cmd, "Interface");
10554 const char *val = get_param(cmd, "DevRole");
10555
10556 if (val && strcasecmp(val, "STA-CFON") == 0) {
10557 status = sta_cfon_set_wireless(dut, conn, cmd);
10558 if (status)
10559 return status;
10560 }
10561 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
10562}
10563
10564
Jouni Malinen67433fc2020-06-26 22:50:33 +030010565static enum sigma_cmd_result
10566sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
10567 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +053010568{
10569 const char *intf = get_param(cmd, "Interface");
10570 const char *val;
10571
10572 val = get_param(cmd, "ocvc");
10573 if (val)
10574 dut->ocvc = atoi(val);
10575
Jouni Malinen67433fc2020-06-26 22:50:33 +030010576 val = get_param(cmd, "ClientPrivacy");
Veerendranath Jakkam47867202020-12-21 01:53:52 +053010577 if (val && dut->client_privacy != atoi(val) &&
10578 sta_set_client_privacy(dut, conn, intf, atoi(val))) {
10579 send_resp(dut, conn, SIGMA_ERROR,
10580 "errorCode,Failed to configure random MAC address use");
10581 return STATUS_SENT_ERROR;
Jouni Malinen67433fc2020-06-26 22:50:33 +030010582 }
10583
Vamsi Krishnac1633d22020-05-06 18:31:21 +053010584 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
10585}
10586
10587
Jouni Malinenf7222712019-06-13 01:50:21 +030010588static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
10589 struct sigma_conn *conn,
10590 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010591{
10592 const char *val;
10593
10594 val = get_param(cmd, "Program");
10595 if (val) {
10596 if (strcasecmp(val, "11n") == 0)
10597 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -080010598 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010599 return cmd_sta_set_wireless_vht(dut, conn, cmd);
10600 if (strcasecmp(val, "60ghz") == 0)
10601 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +053010602 if (strcasecmp(val, "OCE") == 0)
10603 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +020010604 /* sta_set_wireless in WPS program is only used for 60G */
10605 if (is_60g_sigma_dut(dut))
10606 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +053010607 if (strcasecmp(val, "WPA3") == 0)
10608 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010609 send_resp(dut, conn, SIGMA_ERROR,
10610 "ErrorCode,Program value not supported");
10611 } else {
10612 send_resp(dut, conn, SIGMA_ERROR,
10613 "ErrorCode,Program argument not available");
10614 }
10615
10616 return 0;
10617}
10618
10619
10620static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
10621 int tid)
10622{
10623 char buf[100];
10624 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
10625
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +053010626 if (tid < 0 ||
10627 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
10628 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
10629 return;
10630 }
10631
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010632 /*
10633 * Two ways to ensure that addba request with a
10634 * non zero TID could be sent out. EV 117296
10635 */
10636 snprintf(buf, sizeof(buf),
10637 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
10638 tid);
10639 if (system(buf) != 0) {
10640 sigma_dut_print(dut, DUT_MSG_ERROR,
10641 "Ping did not send out");
10642 }
10643
10644 snprintf(buf, sizeof(buf),
10645 "iwconfig %s | grep Access | awk '{print $6}' > %s",
10646 intf, VI_QOS_TMP_FILE);
10647 if (system(buf) != 0)
10648 return;
10649
10650 snprintf(buf, sizeof(buf),
10651 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
10652 intf, VI_QOS_TMP_FILE);
10653 if (system(buf) != 0)
10654 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
10655
10656 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
10657 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
10658 if (system(buf) != 0) {
10659 sigma_dut_print(dut, DUT_MSG_ERROR,
10660 "VI_QOS_TEMP_FILE generation error failed");
10661 }
10662 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
10663 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
10664 if (system(buf) != 0) {
10665 sigma_dut_print(dut, DUT_MSG_ERROR,
10666 "VI_QOS_FILE generation failed");
10667 }
10668
10669 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
10670 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
10671 if (system(buf) != 0) {
10672 sigma_dut_print(dut, DUT_MSG_ERROR,
10673 "VI_QOS_FILE generation failed");
10674 }
10675
10676 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
10677 if (system(buf) != 0) {
10678 }
10679}
10680
10681
10682static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
10683 struct sigma_cmd *cmd)
10684{
10685 const char *intf = get_param(cmd, "Interface");
10686 const char *val;
10687 int tid = 0;
10688 char buf[100];
10689
10690 val = get_param(cmd, "TID");
10691 if (val) {
10692 tid = atoi(val);
10693 if (tid)
10694 ath_sta_inject_frame(dut, intf, tid);
10695 }
10696
10697 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010698 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010699
10700 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
10701 if (system(buf) != 0) {
10702 sigma_dut_print(dut, DUT_MSG_ERROR,
10703 "wifitool senddelba failed");
10704 }
10705
10706 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
10707 if (system(buf) != 0) {
10708 sigma_dut_print(dut, DUT_MSG_ERROR,
10709 "wifitool sendaddba failed");
10710 }
10711
10712 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
10713
10714 return 1;
10715}
10716
10717
Lior David9981b512017-01-20 13:16:40 +020010718#ifdef __linux__
10719
10720static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
10721 int agg_size)
10722{
10723 char dir[128], buf[128];
10724 FILE *f;
10725 regex_t re;
10726 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +030010727 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +020010728
10729 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
10730 sigma_dut_print(dut, DUT_MSG_ERROR,
10731 "failed to get wil6210 debugfs dir");
10732 return -1;
10733 }
10734
Jouni Malinen3aa72862019-05-29 23:14:51 +030010735 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
10736 if (res < 0 || res >= sizeof(buf))
10737 return -1;
Lior David9981b512017-01-20 13:16:40 +020010738 f = fopen(buf, "r");
10739 if (!f) {
10740 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010741 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +030010742 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
10743 if (res < 0 || res >= sizeof(buf))
10744 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010745 f = fopen(buf, "r");
10746 if (!f) {
10747 sigma_dut_print(dut, DUT_MSG_ERROR,
10748 "failed to open: %s", buf);
10749 return -1;
10750 }
Lior David9981b512017-01-20 13:16:40 +020010751 }
10752
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +020010753 /* can be either VRING tx... or RING... */
10754 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +020010755 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
10756 goto out;
10757 }
10758
10759 /* find TX VRING for the mac address */
10760 found = 0;
10761 while (fgets(buf, sizeof(buf), f)) {
10762 if (strcasestr(buf, dest_mac)) {
10763 found = 1;
10764 break;
10765 }
10766 }
10767
10768 if (!found) {
10769 sigma_dut_print(dut, DUT_MSG_ERROR,
10770 "no TX VRING for %s", dest_mac);
10771 goto out;
10772 }
10773
10774 /* extract VRING ID, "VRING tx_<id> = {" */
10775 if (!fgets(buf, sizeof(buf), f)) {
10776 sigma_dut_print(dut, DUT_MSG_ERROR,
10777 "no VRING start line for %s", dest_mac);
10778 goto out;
10779 }
10780
10781 rc = regexec(&re, buf, 2, m, 0);
10782 regfree(&re);
10783 if (rc || m[1].rm_so < 0) {
10784 sigma_dut_print(dut, DUT_MSG_ERROR,
10785 "no VRING TX ID for %s", dest_mac);
10786 goto out;
10787 }
10788 buf[m[1].rm_eo] = 0;
10789 vring_id = atoi(&buf[m[1].rm_so]);
10790
10791 /* send the addba command */
10792 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +030010793 res = snprintf(buf, sizeof(buf), "%s/back", dir);
10794 if (res < 0 || res >= sizeof(buf))
10795 return -1;
Lior David9981b512017-01-20 13:16:40 +020010796 f = fopen(buf, "w");
10797 if (!f) {
10798 sigma_dut_print(dut, DUT_MSG_ERROR,
10799 "failed to open: %s", buf);
10800 return -1;
10801 }
10802
10803 fprintf(f, "add %d %d\n", vring_id, agg_size);
10804
10805 ret = 0;
10806
10807out:
10808 fclose(f);
10809
10810 return ret;
10811}
10812
10813
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020010814int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10815 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010816{
10817 const char *val;
10818 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010819
10820 val = get_param(cmd, "TID");
10821 if (val) {
10822 tid = atoi(val);
10823 if (tid != 0) {
10824 sigma_dut_print(dut, DUT_MSG_ERROR,
10825 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
10826 tid);
10827 }
10828 }
10829
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020010830 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010831 if (!val) {
10832 sigma_dut_print(dut, DUT_MSG_ERROR,
10833 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020010834 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010835 }
10836
Lior David9981b512017-01-20 13:16:40 +020010837 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010838 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010839
10840 return 1;
10841}
10842
Lior David9981b512017-01-20 13:16:40 +020010843#endif /* __linux__ */
10844
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010845
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010846static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
10847 struct sigma_cmd *cmd)
10848{
10849#ifdef NL80211_SUPPORT
10850 const char *intf = get_param(cmd, "Interface");
10851 const char *val;
10852 int tid = -1;
10853 int bufsize = 64;
10854 struct nl_msg *msg;
10855 int ret = 0;
10856 struct nlattr *params;
10857 int ifindex;
10858
10859 val = get_param(cmd, "TID");
10860 if (val)
10861 tid = atoi(val);
10862
10863 if (tid == -1) {
10864 send_resp(dut, conn, SIGMA_ERROR,
10865 "ErrorCode,sta_send_addba tid invalid");
10866 return 0;
10867 }
10868
10869 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
10870
10871 ifindex = if_nametoindex(intf);
10872 if (ifindex == 0) {
10873 sigma_dut_print(dut, DUT_MSG_ERROR,
10874 "%s: Index for interface %s failed",
10875 __func__, intf);
10876 send_resp(dut, conn, SIGMA_ERROR,
10877 "ErrorCode,sta_send_addba interface invalid");
10878 return 0;
10879 }
10880
10881 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10882 NL80211_CMD_VENDOR)) ||
10883 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
10884 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10885 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10886 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
10887 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10888 nla_put_u8(msg,
10889 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
10890 QCA_WLAN_ADD_BA) ||
10891 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
10892 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -070010893 nla_put_u16(msg,
10894 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
10895 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010896 sigma_dut_print(dut, DUT_MSG_ERROR,
10897 "%s: err in adding vendor_cmd and vendor_data",
10898 __func__);
10899 nlmsg_free(msg);
10900 send_resp(dut, conn, SIGMA_ERROR,
10901 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
10902 return 0;
10903 }
10904 nla_nest_end(msg, params);
10905
10906 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
10907 if (ret) {
10908 sigma_dut_print(dut, DUT_MSG_ERROR,
10909 "%s: err in send_and_recv_msgs, ret=%d",
10910 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +053010911 if (ret == -EOPNOTSUPP)
10912 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010913 send_resp(dut, conn, SIGMA_ERROR,
10914 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
10915 return 0;
10916 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010917#else /* NL80211_SUPPORT */
10918 sigma_dut_print(dut, DUT_MSG_ERROR,
10919 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010920#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +053010921
10922 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010923}
10924
10925
Jouni Malinenf7222712019-06-13 01:50:21 +030010926static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
10927 struct sigma_conn *conn,
10928 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010929{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010930 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010931 case DRIVER_ATHEROS:
10932 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -080010933 case DRIVER_WCN:
10934 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +020010935#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010936 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +020010937 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +020010938#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010939 default:
10940 /*
10941 * There is no driver specific implementation for other drivers.
10942 * Ignore the command and report COMPLETE since the following
10943 * throughput test operation will end up sending ADDBA anyway.
10944 */
10945 return 1;
10946 }
10947}
10948
10949
10950int inject_eth_frame(int s, const void *data, size_t len,
10951 unsigned short ethtype, char *dst, char *src)
10952{
10953 struct iovec iov[4] = {
10954 {
10955 .iov_base = dst,
10956 .iov_len = ETH_ALEN,
10957 },
10958 {
10959 .iov_base = src,
10960 .iov_len = ETH_ALEN,
10961 },
10962 {
10963 .iov_base = &ethtype,
10964 .iov_len = sizeof(unsigned short),
10965 },
10966 {
10967 .iov_base = (void *) data,
10968 .iov_len = len,
10969 }
10970 };
10971 struct msghdr msg = {
10972 .msg_name = NULL,
10973 .msg_namelen = 0,
10974 .msg_iov = iov,
10975 .msg_iovlen = 4,
10976 .msg_control = NULL,
10977 .msg_controllen = 0,
10978 .msg_flags = 0,
10979 };
10980
10981 return sendmsg(s, &msg, 0);
10982}
10983
10984#if defined(__linux__) || defined(__QNXNTO__)
10985
10986int inject_frame(int s, const void *data, size_t len, int encrypt)
10987{
10988#define IEEE80211_RADIOTAP_F_WEP 0x04
10989#define IEEE80211_RADIOTAP_F_FRAG 0x08
10990 unsigned char rtap_hdr[] = {
10991 0x00, 0x00, /* radiotap version */
10992 0x0e, 0x00, /* radiotap length */
10993 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
10994 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
10995 0x00, /* padding */
10996 0x00, 0x00, /* RX and TX flags to indicate that */
10997 0x00, 0x00, /* this is the injected frame directly */
10998 };
10999 struct iovec iov[2] = {
11000 {
11001 .iov_base = &rtap_hdr,
11002 .iov_len = sizeof(rtap_hdr),
11003 },
11004 {
11005 .iov_base = (void *) data,
11006 .iov_len = len,
11007 }
11008 };
11009 struct msghdr msg = {
11010 .msg_name = NULL,
11011 .msg_namelen = 0,
11012 .msg_iov = iov,
11013 .msg_iovlen = 2,
11014 .msg_control = NULL,
11015 .msg_controllen = 0,
11016 .msg_flags = 0,
11017 };
11018
11019 if (encrypt)
11020 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
11021
11022 return sendmsg(s, &msg, 0);
11023}
11024
11025
11026int open_monitor(const char *ifname)
11027{
11028#ifdef __QNXNTO__
11029 struct sockaddr_dl ll;
11030 int s;
11031
11032 memset(&ll, 0, sizeof(ll));
11033 ll.sdl_family = AF_LINK;
11034 ll.sdl_index = if_nametoindex(ifname);
11035 if (ll.sdl_index == 0) {
11036 perror("if_nametoindex");
11037 return -1;
11038 }
11039 s = socket(PF_INET, SOCK_RAW, 0);
11040#else /* __QNXNTO__ */
11041 struct sockaddr_ll ll;
11042 int s;
11043
11044 memset(&ll, 0, sizeof(ll));
11045 ll.sll_family = AF_PACKET;
11046 ll.sll_ifindex = if_nametoindex(ifname);
11047 if (ll.sll_ifindex == 0) {
11048 perror("if_nametoindex");
11049 return -1;
11050 }
11051 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
11052#endif /* __QNXNTO__ */
11053 if (s < 0) {
11054 perror("socket[PF_PACKET,SOCK_RAW]");
11055 return -1;
11056 }
11057
11058 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
11059 perror("monitor socket bind");
11060 close(s);
11061 return -1;
11062 }
11063
11064 return s;
11065}
11066
11067
11068static int hex2num(char c)
11069{
11070 if (c >= '0' && c <= '9')
11071 return c - '0';
11072 if (c >= 'a' && c <= 'f')
11073 return c - 'a' + 10;
11074 if (c >= 'A' && c <= 'F')
11075 return c - 'A' + 10;
11076 return -1;
11077}
11078
11079
11080int hwaddr_aton(const char *txt, unsigned char *addr)
11081{
11082 int i;
11083
11084 for (i = 0; i < 6; i++) {
11085 int a, b;
11086
11087 a = hex2num(*txt++);
11088 if (a < 0)
11089 return -1;
11090 b = hex2num(*txt++);
11091 if (b < 0)
11092 return -1;
11093 *addr++ = (a << 4) | b;
11094 if (i < 5 && *txt++ != ':')
11095 return -1;
11096 }
11097
11098 return 0;
11099}
11100
11101#endif /* defined(__linux__) || defined(__QNXNTO__) */
11102
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011103
11104#ifdef NL80211_SUPPORT
11105static int nl80211_send_frame_cmd(struct sigma_dut *dut, const char *intf,
11106 const u8 *data, size_t data_len, int freq)
11107{
11108 struct nl_msg *msg;
11109 int ret = 0;
11110 int ifindex;
11111
11112 ifindex = if_nametoindex(intf);
11113 if (ifindex == 0) {
11114 sigma_dut_print(dut, DUT_MSG_ERROR,
11115 "%s: Index for interface %s failed",
11116 __func__, intf);
11117 return -1;
11118 }
11119
11120 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
11121 NL80211_CMD_FRAME)) ||
11122 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11123 nla_put(msg, NL80211_ATTR_FRAME, data_len, data)) {
11124 sigma_dut_print(dut, DUT_MSG_ERROR,
11125 "%s: Error in adding NL80211_CMD_FRAME",
11126 __func__);
11127 nlmsg_free(msg);
11128 return -1;
11129 }
11130
11131 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
11132 if (ret) {
11133 sigma_dut_print(dut, DUT_MSG_ERROR,
11134 "nl80211: Frame command failed: ret=%d (%s) req=%u",
11135 ret, strerror(-ret), freq);
11136 return -1;
11137 }
11138
11139 return 0;
11140}
11141#endif /* NL80211_SUPPORT */
11142
11143
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011144enum send_frame_type {
11145 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
11146};
11147enum send_frame_protection {
11148 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
11149};
11150
11151
11152static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011153 const char *intf, enum send_frame_type frame,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011154 enum send_frame_protection protected,
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011155 const char *dest, int use_monitor)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011156{
11157#ifdef __linux__
11158 unsigned char buf[1000], *pos;
11159 int s, res;
11160 char bssid[20], addr[20];
11161 char result[32], ssid[100];
11162 size_t ssid_len;
11163
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011164 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011165 sizeof(result)) < 0 ||
11166 strncmp(result, "COMPLETED", 9) != 0) {
11167 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
11168 return 0;
11169 }
11170
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011171 if (get_wpa_status(get_station_ifname(dut), "bssid",
11172 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011173 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
11174 "current BSSID");
11175 return 0;
11176 }
11177
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011178 if (get_wpa_status(get_station_ifname(dut), "address",
11179 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011180 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
11181 "own MAC address");
11182 return 0;
11183 }
11184
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011185 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011186 < 0) {
11187 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
11188 "current SSID");
11189 return 0;
11190 }
11191 ssid_len = strlen(ssid);
11192
11193 pos = buf;
11194
11195 /* Frame Control */
11196 switch (frame) {
11197 case DISASSOC:
11198 *pos++ = 0xa0;
11199 break;
11200 case DEAUTH:
11201 *pos++ = 0xc0;
11202 break;
11203 case SAQUERY:
11204 *pos++ = 0xd0;
11205 break;
11206 case AUTH:
11207 *pos++ = 0xb0;
11208 break;
11209 case ASSOCREQ:
11210 *pos++ = 0x00;
11211 break;
11212 case REASSOCREQ:
11213 *pos++ = 0x20;
11214 break;
11215 case DLS_REQ:
11216 *pos++ = 0xd0;
11217 break;
11218 }
11219
11220 if (protected == INCORRECT_KEY)
11221 *pos++ = 0x40; /* Set Protected field to 1 */
11222 else
11223 *pos++ = 0x00;
11224
11225 /* Duration */
11226 *pos++ = 0x00;
11227 *pos++ = 0x00;
11228
11229 /* addr1 = DA (current AP) */
11230 hwaddr_aton(bssid, pos);
11231 pos += 6;
11232 /* addr2 = SA (own address) */
11233 hwaddr_aton(addr, pos);
11234 pos += 6;
11235 /* addr3 = BSSID (current AP) */
11236 hwaddr_aton(bssid, pos);
11237 pos += 6;
11238
11239 /* Seq# (to be filled by driver/mac80211) */
11240 *pos++ = 0x00;
11241 *pos++ = 0x00;
11242
11243 if (protected == INCORRECT_KEY) {
11244 /* CCMP parameters */
11245 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
11246 pos += 8;
11247 }
11248
11249 if (protected == INCORRECT_KEY) {
11250 switch (frame) {
11251 case DEAUTH:
11252 /* Reason code (encrypted) */
11253 memcpy(pos, "\xa7\x39", 2);
11254 pos += 2;
11255 break;
11256 case DISASSOC:
11257 /* Reason code (encrypted) */
11258 memcpy(pos, "\xa7\x39", 2);
11259 pos += 2;
11260 break;
11261 case SAQUERY:
11262 /* Category|Action|TransID (encrypted) */
11263 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
11264 pos += 4;
11265 break;
11266 default:
11267 return -1;
11268 }
11269
11270 /* CCMP MIC */
11271 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
11272 pos += 8;
11273 } else {
11274 switch (frame) {
11275 case DEAUTH:
11276 /* reason code = 8 */
11277 *pos++ = 0x08;
11278 *pos++ = 0x00;
11279 break;
11280 case DISASSOC:
11281 /* reason code = 8 */
11282 *pos++ = 0x08;
11283 *pos++ = 0x00;
11284 break;
11285 case SAQUERY:
11286 /* Category - SA Query */
11287 *pos++ = 0x08;
11288 /* SA query Action - Request */
11289 *pos++ = 0x00;
11290 /* Transaction ID */
11291 *pos++ = 0x12;
11292 *pos++ = 0x34;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011293 if (dut->saquery_oci_freq) {
11294 /* OCI IE - Extended ID */
11295 *pos++ = 0xFF;
11296 *pos++ = 0x04;
11297 *pos++ = 0x36;
11298 /* Operating Class */
11299 *pos++ = 0x74;
11300 /* Primary Channel */
11301 *pos++ = freq_to_channel(dut->saquery_oci_freq);
11302 /* Frequency Segment 1 Channel Number */
11303 *pos++ = 0x00;
11304 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011305 break;
11306 case AUTH:
11307 /* Auth Alg (Open) */
11308 *pos++ = 0x00;
11309 *pos++ = 0x00;
11310 /* Seq# */
11311 *pos++ = 0x01;
11312 *pos++ = 0x00;
11313 /* Status code */
11314 *pos++ = 0x00;
11315 *pos++ = 0x00;
11316 break;
11317 case ASSOCREQ:
11318 /* Capability Information */
11319 *pos++ = 0x31;
11320 *pos++ = 0x04;
11321 /* Listen Interval */
11322 *pos++ = 0x0a;
11323 *pos++ = 0x00;
11324 /* SSID */
11325 *pos++ = 0x00;
11326 *pos++ = ssid_len;
11327 memcpy(pos, ssid, ssid_len);
11328 pos += ssid_len;
11329 /* Supported Rates */
11330 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
11331 10);
11332 pos += 10;
11333 /* Extended Supported Rates */
11334 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
11335 pos += 6;
11336 /* RSN */
11337 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
11338 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
11339 "\x00\x00\x00\x00\x0f\xac\x06", 28);
11340 pos += 28;
11341 break;
11342 case REASSOCREQ:
11343 /* Capability Information */
11344 *pos++ = 0x31;
11345 *pos++ = 0x04;
11346 /* Listen Interval */
11347 *pos++ = 0x0a;
11348 *pos++ = 0x00;
11349 /* Current AP */
11350 hwaddr_aton(bssid, pos);
11351 pos += 6;
11352 /* SSID */
11353 *pos++ = 0x00;
11354 *pos++ = ssid_len;
11355 memcpy(pos, ssid, ssid_len);
11356 pos += ssid_len;
11357 /* Supported Rates */
11358 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
11359 10);
11360 pos += 10;
11361 /* Extended Supported Rates */
11362 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
11363 pos += 6;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011364 /* RSNE - Group and Pairwise ciphers */
11365 memcpy(pos,
11366 "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04",
11367 14);
11368 pos += 14;
11369 /* RSNE - AKM Suite count */
11370 *pos++ = 0x01;
11371 *pos++ = 0x00;
11372 /* RSNE - AKM Suites */
11373 if (dut->program == PROGRAM_WPA3)
11374 memcpy(pos, "\x00\x0f\xac\x08", 4);
11375 else
11376 memcpy(pos, "\x00\x0f\xac\x02", 4);
11377 pos += 4;
11378 /* RSNE - Capabilities */
11379 *pos++ = 0xc0;
11380 if (dut->ocvc)
11381 *pos++ = 0x40;
11382 else
11383 *pos++ = 0x00;
11384 /* RSNE - PMKID list and Group Management Ciphers */
11385 memcpy(pos, "\x00\x00\x00\x0f\xac\x06", 6);
11386 pos += 6;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011387 break;
11388 case DLS_REQ:
11389 /* Category - DLS */
11390 *pos++ = 0x02;
11391 /* DLS Action - Request */
11392 *pos++ = 0x00;
11393 /* Destination MACAddress */
11394 if (dest)
11395 hwaddr_aton(dest, pos);
11396 else
11397 memset(pos, 0, 6);
11398 pos += 6;
11399 /* Source MACAddress */
11400 hwaddr_aton(addr, pos);
11401 pos += 6;
11402 /* Capability Information */
11403 *pos++ = 0x10; /* Privacy */
11404 *pos++ = 0x06; /* QoS */
11405 /* DLS Timeout Value */
11406 *pos++ = 0x00;
11407 *pos++ = 0x01;
11408 /* Supported rates */
11409 *pos++ = 0x01;
11410 *pos++ = 0x08;
11411 *pos++ = 0x0c; /* 6 Mbps */
11412 *pos++ = 0x12; /* 9 Mbps */
11413 *pos++ = 0x18; /* 12 Mbps */
11414 *pos++ = 0x24; /* 18 Mbps */
11415 *pos++ = 0x30; /* 24 Mbps */
11416 *pos++ = 0x48; /* 36 Mbps */
11417 *pos++ = 0x60; /* 48 Mbps */
11418 *pos++ = 0x6c; /* 54 Mbps */
11419 /* TODO: Extended Supported Rates */
11420 /* TODO: HT Capabilities */
11421 break;
11422 }
11423 }
11424
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011425 if (use_monitor) {
11426 s = open_monitor("sigmadut");
11427 if (s < 0) {
11428 send_resp(dut, conn, SIGMA_ERROR,
11429 "errorCode,Failed to open monitor socket");
11430 return 0;
11431 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011432
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011433 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
11434 if (res < 0) {
11435 send_resp(dut, conn, SIGMA_ERROR,
11436 "errorCode,Failed to inject frame");
11437 close(s);
11438 return 0;
11439 }
11440 if (res < pos - buf) {
11441 send_resp(dut, conn, SIGMA_ERROR,
11442 "errorCode,Only partial frame sent");
11443 close(s);
11444 return 0;
11445 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011446
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011447 close(s);
11448 } else {
11449#ifdef NL80211_SUPPORT
11450 int freq;
11451 char freq_str[10];
11452
11453 if (get_wpa_status(get_station_ifname(dut), "freq",
11454 freq_str, sizeof(freq_str)) < 0) {
11455 send_resp(dut, conn, SIGMA_ERROR,
11456 "errorCode,Could not get current operating frequency");
11457 return 0;
11458 }
11459 freq = atoi(freq_str);
11460
11461 if (nl80211_send_frame_cmd(dut, intf, buf, pos - buf, freq)) {
11462 send_resp(dut, conn, SIGMA_ERROR,
11463 "errorCode,Failed to inject frame");
11464 return 0;
11465 }
11466#else /* NL80211_SUPPORT */
11467 send_resp(dut, conn, SIGMA_ERROR,
11468 "errorCode,Failed to inject frame (no NL80211_SUPPORT)");
11469 return 0;
11470#endif /* NL80211_SUPPORT */
11471 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011472
11473 return 1;
11474#else /* __linux__ */
11475 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
11476 "yet supported");
11477 return 0;
11478#endif /* __linux__ */
11479}
11480
11481
11482static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
11483 struct sigma_conn *conn,
11484 struct sigma_cmd *cmd)
11485{
11486 const char *intf = get_param(cmd, "Interface");
11487 const char *sta, *val;
11488 unsigned char addr[ETH_ALEN];
11489 char buf[100];
11490
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011491 if (!intf)
11492 return -1;
11493
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011494 sta = get_param(cmd, "peer");
11495 if (sta == NULL)
11496 sta = get_param(cmd, "station");
11497 if (sta == NULL) {
11498 send_resp(dut, conn, SIGMA_ERROR,
11499 "ErrorCode,Missing peer address");
11500 return 0;
11501 }
11502 if (hwaddr_aton(sta, addr) < 0) {
11503 send_resp(dut, conn, SIGMA_ERROR,
11504 "ErrorCode,Invalid peer address");
11505 return 0;
11506 }
11507
11508 val = get_param(cmd, "type");
11509 if (val == NULL)
11510 return -1;
11511
11512 if (strcasecmp(val, "DISCOVERY") == 0) {
11513 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
11514 if (wpa_command(intf, buf) < 0) {
11515 send_resp(dut, conn, SIGMA_ERROR,
11516 "ErrorCode,Failed to send TDLS discovery");
11517 return 0;
11518 }
11519 return 1;
11520 }
11521
11522 if (strcasecmp(val, "SETUP") == 0) {
11523 int status = 0, timeout = 0;
11524
11525 val = get_param(cmd, "Status");
11526 if (val)
11527 status = atoi(val);
11528
11529 val = get_param(cmd, "Timeout");
11530 if (val)
11531 timeout = atoi(val);
11532
11533 if (status != 0 && status != 37) {
11534 send_resp(dut, conn, SIGMA_ERROR,
11535 "ErrorCode,Unsupported status value");
11536 return 0;
11537 }
11538
11539 if (timeout != 0 && timeout != 301) {
11540 send_resp(dut, conn, SIGMA_ERROR,
11541 "ErrorCode,Unsupported timeout value");
11542 return 0;
11543 }
11544
11545 if (status && timeout) {
11546 send_resp(dut, conn, SIGMA_ERROR,
11547 "ErrorCode,Unsupported timeout+status "
11548 "combination");
11549 return 0;
11550 }
11551
11552 if (status == 37 &&
11553 wpa_command(intf, "SET tdls_testing 0x200")) {
11554 send_resp(dut, conn, SIGMA_ERROR,
11555 "ErrorCode,Failed to enable "
11556 "decline setup response test mode");
11557 return 0;
11558 }
11559
11560 if (timeout == 301) {
11561 int res;
11562 if (dut->no_tpk_expiration)
11563 res = wpa_command(intf,
11564 "SET tdls_testing 0x108");
11565 else
11566 res = wpa_command(intf,
11567 "SET tdls_testing 0x8");
11568 if (res) {
11569 send_resp(dut, conn, SIGMA_ERROR,
11570 "ErrorCode,Failed to set short TPK "
11571 "lifetime");
11572 return 0;
11573 }
11574 }
11575
11576 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
11577 if (wpa_command(intf, buf) < 0) {
11578 send_resp(dut, conn, SIGMA_ERROR,
11579 "ErrorCode,Failed to send TDLS setup");
11580 return 0;
11581 }
11582 return 1;
11583 }
11584
11585 if (strcasecmp(val, "TEARDOWN") == 0) {
11586 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
11587 if (wpa_command(intf, buf) < 0) {
11588 send_resp(dut, conn, SIGMA_ERROR,
11589 "ErrorCode,Failed to send TDLS teardown");
11590 return 0;
11591 }
11592 return 1;
11593 }
11594
11595 send_resp(dut, conn, SIGMA_ERROR,
11596 "ErrorCode,Unsupported TDLS frame");
11597 return 0;
11598}
11599
11600
11601static int sta_ap_known(const char *ifname, const char *bssid)
11602{
11603 char buf[4096];
11604
Jouni Malinendd32f192018-09-15 02:55:19 +030011605 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011606 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
11607 return 0;
11608 if (strncmp(buf, "id=", 3) != 0)
11609 return 0;
11610 return 1;
11611}
11612
11613
11614static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
11615 const char *bssid)
11616{
11617 int res;
11618 struct wpa_ctrl *ctrl;
11619 char buf[256];
11620
11621 if (sta_ap_known(ifname, bssid))
11622 return 0;
11623 sigma_dut_print(dut, DUT_MSG_DEBUG,
11624 "AP not in BSS table - start scan");
11625
11626 ctrl = open_wpa_mon(ifname);
11627 if (ctrl == NULL) {
11628 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11629 "wpa_supplicant monitor connection");
11630 return -1;
11631 }
11632
11633 if (wpa_command(ifname, "SCAN") < 0) {
11634 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
11635 wpa_ctrl_detach(ctrl);
11636 wpa_ctrl_close(ctrl);
11637 return -1;
11638 }
11639
11640 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
11641 buf, sizeof(buf));
11642
11643 wpa_ctrl_detach(ctrl);
11644 wpa_ctrl_close(ctrl);
11645
11646 if (res < 0) {
11647 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
11648 return -1;
11649 }
11650
11651 if (sta_ap_known(ifname, bssid))
11652 return 0;
11653 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
11654 return -1;
11655}
11656
11657
11658static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
11659 struct sigma_conn *conn,
11660 struct sigma_cmd *cmd,
11661 const char *intf)
11662{
11663 char buf[200];
11664
11665 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
11666 if (system(buf) != 0) {
11667 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
11668 "ndsend");
11669 return 0;
11670 }
11671
11672 return 1;
11673}
11674
11675
11676static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
11677 struct sigma_conn *conn,
11678 struct sigma_cmd *cmd,
11679 const char *intf)
11680{
11681 char buf[200];
11682 const char *ip = get_param(cmd, "SenderIP");
11683
Peng Xu26b356d2017-10-04 17:58:16 -070011684 if (!ip)
11685 return 0;
11686
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011687 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
11688 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11689 if (system(buf) == 0) {
11690 sigma_dut_print(dut, DUT_MSG_INFO,
11691 "Neighbor Solicitation got a response "
11692 "for %s@%s", ip, intf);
11693 }
11694
11695 return 1;
11696}
11697
11698
11699static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
11700 struct sigma_conn *conn,
11701 struct sigma_cmd *cmd,
11702 const char *ifname)
11703{
11704 char buf[200];
11705 const char *ip = get_param(cmd, "SenderIP");
11706
11707 if (ip == NULL) {
11708 send_resp(dut, conn, SIGMA_ERROR,
11709 "ErrorCode,Missing SenderIP parameter");
11710 return 0;
11711 }
11712 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
11713 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11714 if (system(buf) != 0) {
11715 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
11716 "for %s@%s", ip, ifname);
11717 }
11718
11719 return 1;
11720}
11721
11722
11723static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
11724 struct sigma_conn *conn,
11725 struct sigma_cmd *cmd,
11726 const char *ifname)
11727{
11728 char buf[200];
11729 char ip[16];
11730 int s;
Peng Xub3756882017-10-04 14:39:09 -070011731 struct ifreq ifr;
11732 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011733
11734 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070011735 if (s < 0) {
11736 perror("socket");
11737 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011738 }
11739
Peng Xub3756882017-10-04 14:39:09 -070011740 memset(&ifr, 0, sizeof(ifr));
11741 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
11742 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
11743 sigma_dut_print(dut, DUT_MSG_INFO,
11744 "Failed to get %s IP address: %s",
11745 ifname, strerror(errno));
11746 close(s);
11747 return -1;
11748 }
11749 close(s);
11750
11751 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
11752 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
11753
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011754 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
11755 ip);
11756 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11757 if (system(buf) != 0) {
11758 }
11759
11760 return 1;
11761}
11762
11763
11764static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
11765 struct sigma_conn *conn,
11766 struct sigma_cmd *cmd,
11767 const char *ifname)
11768{
11769 char buf[200], addr[20];
11770 char dst[ETH_ALEN], src[ETH_ALEN];
11771 short ethtype = htons(ETH_P_ARP);
11772 char *pos;
11773 int s, res;
11774 const char *val;
11775 struct sockaddr_in taddr;
11776
11777 val = get_param(cmd, "dest");
11778 if (val)
11779 hwaddr_aton(val, (unsigned char *) dst);
11780
11781 val = get_param(cmd, "DestIP");
11782 if (val)
11783 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070011784 else
11785 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011786
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011787 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011788 sizeof(addr)) < 0)
11789 return -2;
11790 hwaddr_aton(addr, (unsigned char *) src);
11791
11792 pos = buf;
11793 *pos++ = 0x00;
11794 *pos++ = 0x01;
11795 *pos++ = 0x08;
11796 *pos++ = 0x00;
11797 *pos++ = 0x06;
11798 *pos++ = 0x04;
11799 *pos++ = 0x00;
11800 *pos++ = 0x02;
11801 memcpy(pos, src, ETH_ALEN);
11802 pos += ETH_ALEN;
11803 memcpy(pos, &taddr.sin_addr, 4);
11804 pos += 4;
11805 memcpy(pos, dst, ETH_ALEN);
11806 pos += ETH_ALEN;
11807 memcpy(pos, &taddr.sin_addr, 4);
11808 pos += 4;
11809
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011810 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011811 if (s < 0) {
11812 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
11813 "monitor socket");
11814 return 0;
11815 }
11816
11817 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
11818 if (res < 0) {
11819 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
11820 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053011821 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011822 return 0;
11823 }
11824
11825 close(s);
11826
11827 return 1;
11828}
11829
11830
11831static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
11832 struct sigma_conn *conn,
11833 struct sigma_cmd *cmd,
11834 const char *intf, const char *dest)
11835{
11836 char buf[100];
11837
11838 if (if_nametoindex("sigmadut") == 0) {
11839 snprintf(buf, sizeof(buf),
11840 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011841 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011842 if (system(buf) != 0 ||
11843 if_nametoindex("sigmadut") == 0) {
11844 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11845 "monitor interface with '%s'", buf);
11846 return -2;
11847 }
11848 }
11849
11850 if (system("ifconfig sigmadut up") != 0) {
11851 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11852 "monitor interface up");
11853 return -2;
11854 }
11855
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011856 return sta_inject_frame(dut, conn, intf, DLS_REQ, UNPROTECTED, dest, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011857}
11858
11859
11860static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
11861 struct sigma_conn *conn,
11862 struct sigma_cmd *cmd)
11863{
11864 const char *intf = get_param(cmd, "Interface");
11865 const char *dest = get_param(cmd, "Dest");
11866 const char *type = get_param(cmd, "FrameName");
11867 const char *val;
11868 char buf[200], *pos, *end;
11869 int count, count2;
11870
11871 if (type == NULL)
11872 type = get_param(cmd, "Type");
11873
11874 if (intf == NULL || dest == NULL || type == NULL)
11875 return -1;
11876
11877 if (strcasecmp(type, "NeighAdv") == 0)
11878 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
11879
11880 if (strcasecmp(type, "NeighSolicitReq") == 0)
11881 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
11882
11883 if (strcasecmp(type, "ARPProbe") == 0)
11884 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
11885
11886 if (strcasecmp(type, "ARPAnnounce") == 0)
11887 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
11888
11889 if (strcasecmp(type, "ARPReply") == 0)
11890 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
11891
11892 if (strcasecmp(type, "DLS-request") == 0 ||
11893 strcasecmp(type, "DLSrequest") == 0)
11894 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
11895 dest);
11896
11897 if (strcasecmp(type, "ANQPQuery") != 0 &&
11898 strcasecmp(type, "Query") != 0) {
11899 send_resp(dut, conn, SIGMA_ERROR,
11900 "ErrorCode,Unsupported HS 2.0 send frame type");
11901 return 0;
11902 }
11903
11904 if (sta_scan_ap(dut, intf, dest) < 0) {
11905 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
11906 "the requested AP");
11907 return 0;
11908 }
11909
11910 pos = buf;
11911 end = buf + sizeof(buf);
11912 count = 0;
11913 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
11914
11915 val = get_param(cmd, "ANQP_CAP_LIST");
11916 if (val && atoi(val)) {
11917 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
11918 count++;
11919 }
11920
11921 val = get_param(cmd, "VENUE_NAME");
11922 if (val && atoi(val)) {
11923 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
11924 count++;
11925 }
11926
11927 val = get_param(cmd, "NETWORK_AUTH_TYPE");
11928 if (val && atoi(val)) {
11929 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
11930 count++;
11931 }
11932
11933 val = get_param(cmd, "ROAMING_CONS");
11934 if (val && atoi(val)) {
11935 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
11936 count++;
11937 }
11938
11939 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
11940 if (val && atoi(val)) {
11941 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
11942 count++;
11943 }
11944
11945 val = get_param(cmd, "NAI_REALM_LIST");
11946 if (val && atoi(val)) {
11947 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
11948 count++;
11949 }
11950
11951 val = get_param(cmd, "3GPP_INFO");
11952 if (val && atoi(val)) {
11953 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
11954 count++;
11955 }
11956
11957 val = get_param(cmd, "DOMAIN_LIST");
11958 if (val && atoi(val)) {
11959 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
11960 count++;
11961 }
11962
Jouni Malinen34cf9532018-04-29 19:26:33 +030011963 val = get_param(cmd, "Venue_URL");
11964 if (val && atoi(val)) {
11965 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
11966 count++;
11967 }
11968
Jouni Malinend3bca5d2018-04-29 17:25:23 +030011969 val = get_param(cmd, "Advice_Of_Charge");
11970 if (val && atoi(val)) {
11971 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
11972 count++;
11973 }
11974
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011975 if (count && wpa_command(intf, buf)) {
11976 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
11977 return 0;
11978 }
11979
11980 pos = buf;
11981 end = buf + sizeof(buf);
11982 count2 = 0;
11983 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
11984
11985 val = get_param(cmd, "HS_CAP_LIST");
11986 if (val && atoi(val)) {
11987 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
11988 count2++;
11989 }
11990
11991 val = get_param(cmd, "OPER_NAME");
11992 if (val && atoi(val)) {
11993 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
11994 count2++;
11995 }
11996
11997 val = get_param(cmd, "WAN_METRICS");
11998 if (!val)
11999 val = get_param(cmd, "WAN_MAT");
12000 if (!val)
12001 val = get_param(cmd, "WAN_MET");
12002 if (val && atoi(val)) {
12003 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
12004 count2++;
12005 }
12006
12007 val = get_param(cmd, "CONNECTION_CAPABILITY");
12008 if (val && atoi(val)) {
12009 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
12010 count2++;
12011 }
12012
12013 val = get_param(cmd, "OP_CLASS");
12014 if (val && atoi(val)) {
12015 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
12016 count2++;
12017 }
12018
12019 val = get_param(cmd, "OSU_PROVIDER_LIST");
12020 if (val && atoi(val)) {
12021 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
12022 count2++;
12023 }
12024
Jouni Malinenf67afec2018-04-29 19:24:58 +030012025 val = get_param(cmd, "OPER_ICON_METADATA");
12026 if (!val)
12027 val = get_param(cmd, "OPERATOR_ICON_METADATA");
12028 if (val && atoi(val)) {
12029 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
12030 count2++;
12031 }
12032
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012033 if (count && count2) {
12034 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
12035 "second query");
12036 sleep(1);
12037 }
12038
12039 if (count2 && wpa_command(intf, buf)) {
12040 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
12041 "failed");
12042 return 0;
12043 }
12044
12045 val = get_param(cmd, "NAI_HOME_REALM_LIST");
12046 if (val) {
12047 if (count || count2) {
12048 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
12049 "sending out second query");
12050 sleep(1);
12051 }
12052
12053 if (strcmp(val, "1") == 0)
12054 val = "mail.example.com";
12055 snprintf(buf, end - pos,
12056 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
12057 dest, val);
12058 if (wpa_command(intf, buf)) {
12059 send_resp(dut, conn, SIGMA_ERROR,
12060 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
12061 "failed");
12062 return 0;
12063 }
12064 }
12065
12066 val = get_param(cmd, "ICON_REQUEST");
12067 if (val) {
12068 if (count || count2) {
12069 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
12070 "sending out second query");
12071 sleep(1);
12072 }
12073
12074 snprintf(buf, end - pos,
12075 "HS20_ICON_REQUEST %s %s", dest, val);
12076 if (wpa_command(intf, buf)) {
12077 send_resp(dut, conn, SIGMA_ERROR,
12078 "ErrorCode,HS20_ICON_REQUEST failed");
12079 return 0;
12080 }
12081 }
12082
12083 return 1;
12084}
12085
12086
12087static int ath_sta_send_frame_vht(struct sigma_dut *dut,
12088 struct sigma_conn *conn,
12089 struct sigma_cmd *cmd)
12090{
12091 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012092 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012093 int chwidth, nss;
12094
12095 val = get_param(cmd, "framename");
12096 if (!val)
12097 return -1;
12098 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
12099
12100 /* Command sequence to generate Op mode notification */
12101 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012102 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012103
12104 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012105 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012106
12107 /* Extract Channel width */
12108 val = get_param(cmd, "Channel_width");
12109 if (val) {
12110 switch (atoi(val)) {
12111 case 20:
12112 chwidth = 0;
12113 break;
12114 case 40:
12115 chwidth = 1;
12116 break;
12117 case 80:
12118 chwidth = 2;
12119 break;
12120 case 160:
12121 chwidth = 3;
12122 break;
12123 default:
12124 chwidth = 2;
12125 break;
12126 }
12127
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012128 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012129 }
12130
12131 /* Extract NSS */
12132 val = get_param(cmd, "NSS");
12133 if (val) {
12134 switch (atoi(val)) {
12135 case 1:
12136 nss = 1;
12137 break;
12138 case 2:
12139 nss = 3;
12140 break;
12141 case 3:
12142 nss = 7;
12143 break;
12144 default:
12145 /* We do not support NSS > 3 */
12146 nss = 3;
12147 break;
12148 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012149 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012150 }
12151
12152 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012153 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012154 }
12155
12156 return 1;
12157}
12158
12159
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012160static int wcn_sta_set_pmf_config(struct sigma_dut *dut, const char *intf,
12161 enum send_frame_protection protected)
12162{
12163#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053012164 return wcn_wifi_test_config_set_u8(
12165 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PMF_PROTECTION,
12166 protected);
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012167#else /* NL80211_SUPPORT */
12168 sigma_dut_print(dut, DUT_MSG_ERROR,
12169 "PMF config cannot be set without NL80211_SUPPORT defined");
12170 return -1;
12171#endif /* NL80211_SUPPORT */
12172}
12173
12174
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012175static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
12176 struct sigma_conn *conn,
12177 struct sigma_cmd *cmd)
12178{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012179 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012180 case DRIVER_ATHEROS:
12181 return ath_sta_send_frame_vht(dut, conn, cmd);
12182 default:
12183 send_resp(dut, conn, SIGMA_ERROR,
12184 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
12185 return 0;
12186 }
12187}
12188
12189
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012190static int wcn_sta_send_disassoc(struct sigma_dut *dut, const char *intf)
12191{
12192#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053012193 return wcn_wifi_test_config_set_flag(
12194 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISASSOC_TX);
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012195#else /* NL80211_SUPPORT */
12196 sigma_dut_print(dut, DUT_MSG_ERROR,
12197 "Disassoc Tx cannot be done without NL80211_SUPPORT defined");
12198 return -1;
12199#endif /* NL80211_SUPPORT */
12200}
12201
12202
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012203static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
12204 struct sigma_cmd *cmd)
12205{
12206 const char *val;
12207 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012208 enum send_frame_protection protected;
12209 const char *pmf;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012210
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030012211 if (!intf)
12212 return -1;
12213
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012214 val = get_param(cmd, "framename");
12215 if (!val)
12216 return -1;
12217 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
12218
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070012219 pmf = get_param(cmd, "PMFProtected");
12220 if (!pmf)
12221 pmf = get_param(cmd, "Protected");
12222 if (pmf) {
12223 if (strcasecmp(pmf, "Correct-key") == 0 ||
12224 strcasecmp(pmf, "CorrectKey") == 0) {
12225 protected = CORRECT_KEY;
12226 } else if (strcasecmp(pmf, "IncorrectKey") == 0) {
12227 protected = INCORRECT_KEY;
12228 } else if (strcasecmp(pmf, "Unprotected") == 0) {
12229 protected = UNPROTECTED;
12230 } else {
12231 send_resp(dut, conn, SIGMA_ERROR,
12232 "errorCode,Unsupported PMFProtected");
12233 return STATUS_SENT_ERROR;
12234 }
12235 sigma_dut_print(dut, DUT_MSG_DEBUG, "Config PMF protection %d",
12236 protected);
12237 wcn_sta_set_pmf_config(dut, intf, protected);
12238 }
12239
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012240 /* Command sequence to generate Op mode notification */
12241 if (val && strcasecmp(val, "action") == 0) {
12242 val = get_param(cmd, "PPDUTxType");
12243 if (val && strcasecmp(val, "TB") == 0) {
12244 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
12245 sigma_dut_print(dut, DUT_MSG_ERROR,
12246 "failed to send TB PPDU Tx cfg");
12247 send_resp(dut, conn, SIGMA_ERROR,
12248 "ErrorCode,set TB PPDU Tx cfg failed");
12249 return 0;
12250 }
12251 return 1;
12252 }
12253
12254 sigma_dut_print(dut, DUT_MSG_ERROR,
12255 "Action Tx type is not defined");
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012256
12257 return SUCCESS_SEND_STATUS;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012258 }
12259
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070012260 if (strcasecmp(val, "disassoc") == 0)
12261 wcn_sta_send_disassoc(dut, intf);
12262
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012263 return 1;
12264}
12265
12266
12267static int cmd_sta_send_frame_he(struct sigma_dut *dut,
12268 struct sigma_conn *conn,
12269 struct sigma_cmd *cmd)
12270{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012271 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070012272 case DRIVER_WCN:
12273 return wcn_sta_send_frame_he(dut, conn, cmd);
12274 default:
12275 send_resp(dut, conn, SIGMA_ERROR,
12276 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
12277 return 0;
12278 }
12279}
12280
12281
Lior David0fe101e2017-03-09 16:09:50 +020012282#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012283
12284static int
12285wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
12286 const char *frame_name, const char *dest_mac)
12287{
12288 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
12289 const char *ssid = get_param(cmd, "ssid");
12290 const char *countstr = get_param(cmd, "count");
12291 const char *channelstr = get_param(cmd, "channel");
12292 const char *group_id = get_param(cmd, "groupid");
12293 const char *client_id = get_param(cmd, "clientmac");
12294 int count, channel, freq, i;
12295 const char *fname;
12296 char frame[1024], src_mac[20], group_id_attr[25],
12297 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
12298 const char *group_ssid;
12299 const int group_ssid_prefix_len = 9;
12300 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
12301 size_t framelen = sizeof(frame);
12302 struct template_frame_tag tags[2];
12303 size_t tags_total = ARRAY_SIZE(tags);
12304 int tag_index, len, dst_len;
12305
12306 if (!countstr || !channelstr) {
12307 sigma_dut_print(dut, DUT_MSG_ERROR,
12308 "Missing argument: count, channel");
12309 return -1;
12310 }
12311 if (isprobereq && !ssid) {
12312 sigma_dut_print(dut, DUT_MSG_ERROR,
12313 "Missing argument: ssid");
12314 return -1;
12315 }
12316 if (!isprobereq && (!group_id || !client_id)) {
12317 sigma_dut_print(dut, DUT_MSG_ERROR,
12318 "Missing argument: group_id, client_id");
12319 return -1;
12320 }
12321
12322 count = atoi(countstr);
12323 channel = atoi(channelstr);
12324 freq = channel_to_freq(dut, channel);
12325
12326 if (!freq) {
12327 sigma_dut_print(dut, DUT_MSG_ERROR,
12328 "invalid channel: %s", channelstr);
12329 return -1;
12330 }
12331
12332 if (isprobereq) {
12333 if (strcasecmp(ssid, "wildcard") == 0) {
12334 fname = "probe_req_wildcard.txt";
12335 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
12336 fname = "probe_req_P2P_Wildcard.txt";
12337 } else {
12338 sigma_dut_print(dut, DUT_MSG_ERROR,
12339 "invalid probe request type");
12340 return -1;
12341 }
12342 } else {
12343 fname = "P2P_device_discovery_req.txt";
12344 }
12345
12346 if (parse_template_frame_file(dut, fname, frame, &framelen,
12347 tags, &tags_total)) {
12348 sigma_dut_print(dut, DUT_MSG_ERROR,
12349 "invalid frame template: %s", fname);
12350 return -1;
12351 }
12352
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012353 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012354 src_mac, sizeof(src_mac)) < 0 ||
12355 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
12356 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
12357 return -1;
12358 /* Use wildcard BSSID, since we are in PBSS */
12359 memset(&hdr->addr3, 0xFF, ETH_ALEN);
12360
12361 if (!isprobereq) {
12362 tag_index = find_template_frame_tag(tags, tags_total, 1);
12363 if (tag_index < 0) {
12364 sigma_dut_print(dut, DUT_MSG_ERROR,
12365 "can't find device id attribute");
12366 return -1;
12367 }
12368 if (parse_mac_address(dut, client_id,
12369 (unsigned char *) client_mac)) {
12370 sigma_dut_print(dut, DUT_MSG_ERROR,
12371 "invalid client_id: %s", client_id);
12372 return -1;
12373 }
12374 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
12375 framelen - tags[tag_index].offset,
12376 IEEE80211_P2P_ATTR_DEVICE_ID,
12377 client_mac, ETH_ALEN)) {
12378 sigma_dut_print(dut, DUT_MSG_ERROR,
12379 "fail to replace device id attribute");
12380 return -1;
12381 }
12382
12383 /*
12384 * group_id arg contains device MAC address followed by
12385 * space and SSID (DIRECT-somessid).
12386 * group id attribute contains device address (6 bytes)
12387 * followed by SSID prefix DIRECT-XX (9 bytes)
12388 */
12389 if (strlen(group_id) < sizeof(device_macstr)) {
12390 sigma_dut_print(dut, DUT_MSG_ERROR,
12391 "group_id arg too short");
12392 return -1;
12393 }
12394 memcpy(device_macstr, group_id, sizeof(device_macstr));
12395 device_macstr[sizeof(device_macstr) - 1] = '\0';
12396 if (parse_mac_address(dut, device_macstr,
12397 (unsigned char *) group_id_attr)) {
12398 sigma_dut_print(dut, DUT_MSG_ERROR,
12399 "fail to parse device address from group_id");
12400 return -1;
12401 }
12402 group_ssid = strchr(group_id, ' ');
12403 if (!group_ssid) {
12404 sigma_dut_print(dut, DUT_MSG_ERROR,
12405 "invalid group_id arg, no ssid");
12406 return -1;
12407 }
12408 group_ssid++;
12409 len = strlen(group_ssid);
12410 if (len < group_ssid_prefix_len) {
12411 sigma_dut_print(dut, DUT_MSG_ERROR,
12412 "group_id SSID too short");
12413 return -1;
12414 }
12415 dst_len = sizeof(group_id_attr) - ETH_ALEN;
12416 if (len > dst_len) {
12417 sigma_dut_print(dut, DUT_MSG_ERROR,
12418 "group_id SSID (%s) too long",
12419 group_ssid);
12420 return -1;
12421 }
12422
12423 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
12424 tag_index = find_template_frame_tag(tags, tags_total, 2);
12425 if (tag_index < 0) {
12426 sigma_dut_print(dut, DUT_MSG_ERROR,
12427 "can't find group id attribute");
12428 return -1;
12429 }
12430 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
12431 framelen - tags[tag_index].offset,
12432 IEEE80211_P2P_ATTR_GROUP_ID,
12433 group_id_attr,
12434 sizeof(group_id_attr))) {
12435 sigma_dut_print(dut, DUT_MSG_ERROR,
12436 "fail to replace group id attribute");
12437 return -1;
12438 }
12439 }
12440
12441 for (i = 0; i < count; i++) {
12442 if (wil6210_transmit_frame(dut, freq,
12443 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
12444 frame, framelen)) {
12445 sigma_dut_print(dut, DUT_MSG_ERROR,
12446 "fail to transmit probe request frame");
12447 return -1;
12448 }
12449 }
12450
12451 return 0;
12452}
12453
12454
Lior David0fe101e2017-03-09 16:09:50 +020012455int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
12456 struct sigma_cmd *cmd)
12457{
12458 const char *frame_name = get_param(cmd, "framename");
12459 const char *mac = get_param(cmd, "dest_mac");
12460
12461 if (!frame_name || !mac) {
12462 sigma_dut_print(dut, DUT_MSG_ERROR,
12463 "framename and dest_mac must be provided");
12464 return -1;
12465 }
12466
12467 if (strcasecmp(frame_name, "brp") == 0) {
12468 const char *l_rx = get_param(cmd, "L-RX");
12469 int l_rx_i;
12470
12471 if (!l_rx) {
12472 sigma_dut_print(dut, DUT_MSG_ERROR,
12473 "L-RX must be provided");
12474 return -1;
12475 }
12476 l_rx_i = atoi(l_rx);
12477
12478 sigma_dut_print(dut, DUT_MSG_INFO,
12479 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
12480 mac, l_rx);
12481 if (l_rx_i != 16) {
12482 sigma_dut_print(dut, DUT_MSG_ERROR,
12483 "unsupported L-RX: %s", l_rx);
12484 return -1;
12485 }
12486
12487 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
12488 return -1;
12489 } else if (strcasecmp(frame_name, "ssw") == 0) {
12490 sigma_dut_print(dut, DUT_MSG_INFO,
12491 "dev_send_frame: SLS, dest_mac %s", mac);
12492 if (wil6210_send_sls(dut, mac))
12493 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012494 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
12495 (strcasecmp(frame_name, "devdiscreq") == 0)) {
12496 sigma_dut_print(dut, DUT_MSG_INFO,
12497 "dev_send_frame: %s, dest_mac %s", frame_name,
12498 mac);
12499 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
12500 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020012501 } else {
12502 sigma_dut_print(dut, DUT_MSG_ERROR,
12503 "unsupported frame type: %s", frame_name);
12504 return -1;
12505 }
12506
12507 return 1;
12508}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030012509
Lior David0fe101e2017-03-09 16:09:50 +020012510#endif /* __linux__ */
12511
12512
12513static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
12514 struct sigma_conn *conn,
12515 struct sigma_cmd *cmd)
12516{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012517 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020012518#ifdef __linux__
12519 case DRIVER_WIL6210:
12520 return wil6210_send_frame_60g(dut, conn, cmd);
12521#endif /* __linux__ */
12522 default:
12523 send_resp(dut, conn, SIGMA_ERROR,
12524 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
12525 return 0;
12526 }
12527}
12528
12529
Ashwini Patildb59b3c2017-04-13 15:19:23 +053012530static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
12531 const char *intf, struct sigma_cmd *cmd)
12532{
12533 const char *val, *addr;
12534 char buf[100];
12535
12536 addr = get_param(cmd, "DestMac");
12537 if (!addr) {
12538 send_resp(dut, conn, SIGMA_INVALID,
12539 "ErrorCode,AP MAC address is missing");
12540 return 0;
12541 }
12542
12543 val = get_param(cmd, "ANQPQuery_ID");
12544 if (!val) {
12545 send_resp(dut, conn, SIGMA_INVALID,
12546 "ErrorCode,Missing ANQPQuery_ID");
12547 return 0;
12548 }
12549
12550 if (strcasecmp(val, "NeighborReportReq") == 0) {
12551 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
12552 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
12553 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
12554 } else {
12555 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
12556 val);
12557 send_resp(dut, conn, SIGMA_INVALID,
12558 "ErrorCode,Invalid ANQPQuery_ID");
12559 return 0;
12560 }
12561
Ashwini Patild174f2c2017-04-13 16:49:46 +053012562 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
12563 * (Address3 = Wildcard BSSID when sent to not-associated AP;
12564 * if associated, AP BSSID).
12565 */
12566 if (wpa_command(intf, "SET gas_address3 1") < 0) {
12567 send_resp(dut, conn, SIGMA_ERROR,
12568 "ErrorCode,Failed to set gas_address3");
12569 return 0;
12570 }
12571
Ashwini Patildb59b3c2017-04-13 15:19:23 +053012572 if (wpa_command(intf, buf) < 0) {
12573 send_resp(dut, conn, SIGMA_ERROR,
12574 "ErrorCode,Failed to send ANQP query");
12575 return 0;
12576 }
12577
12578 return 1;
12579}
12580
12581
12582static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
12583 struct sigma_conn *conn,
12584 const char *intf,
12585 struct sigma_cmd *cmd)
12586{
12587 const char *val = get_param(cmd, "FrameName");
12588
12589 if (val && strcasecmp(val, "ANQPQuery") == 0)
12590 return mbo_send_anqp_query(dut, conn, intf, cmd);
12591
12592 return 2;
12593}
12594
12595
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053012596static enum sigma_cmd_result cmd_sta_send_frame_wpa3(struct sigma_dut *dut,
12597 struct sigma_conn *conn,
12598 const char *intf,
12599 struct sigma_cmd *cmd)
12600{
12601 const char *val = get_param(cmd, "framename");
12602
12603 if (!val)
12604 return INVALID_SEND_STATUS;
12605
12606 if (strcasecmp(val, "SAQueryReq") == 0) {
12607 val = get_param(cmd, "OCIChannel");
12608
12609 if (!val) {
12610 send_resp(dut, conn, SIGMA_ERROR,
12611 "errorCode,OCIChannel not present");
12612 return STATUS_SENT_ERROR;
12613 }
12614
12615 dut->saquery_oci_freq = channel_to_freq(dut, atoi(val));
12616 if (!dut->saquery_oci_freq) {
12617 send_resp(dut, conn, SIGMA_ERROR,
12618 "errorCode,Invalid OCIChannel number");
12619 return STATUS_SENT_ERROR;
12620 }
12621
12622 return sta_inject_frame(dut, conn, intf, SAQUERY, CORRECT_KEY,
12623 NULL, 0);
12624 }
12625
12626 if (strcasecmp(val, "reassocreq") == 0)
12627 return sta_inject_frame(dut, conn, intf, REASSOCREQ,
12628 CORRECT_KEY, NULL, 0);
12629
Veerendranath9f81dfb2020-08-10 01:21:29 -070012630 if (strcasecmp(val, "ANQPQuery") == 0) {
12631 char buf[50];
12632 const char *dest = get_param(cmd, "DestMac");
12633 const char *chan = get_param(cmd, "channel");
Veerendranath Jakkam78862fc2020-11-19 21:23:27 +053012634 const char *freq_str = get_param(cmd, "ChnlFreq");
Veerendranath9f81dfb2020-08-10 01:21:29 -070012635 int len, freq;
12636
Veerendranath Jakkam78862fc2020-11-19 21:23:27 +053012637 if (freq_str)
12638 freq = atoi(freq_str);
12639 else
12640 freq = chan ? channel_to_freq(dut, atoi(chan)) : 0;
12641
Veerendranath9f81dfb2020-08-10 01:21:29 -070012642 if (!dest || !freq)
12643 return INVALID_SEND_STATUS;
12644
12645 len = snprintf(buf, sizeof(buf), "ANQP_GET %s freq=%d 257",
12646 dest, freq);
12647 if (len < 0 || len >= sizeof(buf)) {
12648 sigma_dut_print(dut, DUT_MSG_ERROR,
12649 "Failed to allocate buf");
12650 return ERROR_SEND_STATUS;
12651 }
12652
12653 if (wpa_command(intf, buf) != 0) {
12654 send_resp(dut, conn, SIGMA_ERROR,
12655 "ErrorCode,Failed to send ANQP Query frame");
12656 return STATUS_SENT_ERROR;
12657 }
12658
12659 sigma_dut_print(dut, DUT_MSG_DEBUG,
12660 "ANQP Query sent: %s", buf);
12661
12662 return SUCCESS_SEND_STATUS;
12663 }
12664
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053012665 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported framename");
12666 return STATUS_SENT_ERROR;
12667}
12668
12669
Vinita S. Malooca85fd22021-01-15 02:54:34 +053012670static int
12671get_type4_frame_classifier(struct sigma_dut *dut, struct sigma_cmd *cmd,
12672 char *pos, int rem_len, int num_of_scs_desc,
12673 int num_of_tclas_elem)
12674{
12675 const char *val;
12676 int ipv6;
12677 int len, total_len = 0;
12678
12679 val = get_param_fmt(cmd, "TCLASElem_Version_%d_%d", num_of_scs_desc,
12680 num_of_tclas_elem);
12681 if (!val) {
12682 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: ip_version empty",
12683 __func__);
12684 return -1;
12685 }
12686
12687 if (strcmp(val, "6") == 0) {
12688 ipv6 = 1;
12689 } else if (strcmp(val, "4") == 0) {
12690 ipv6 = 0;
12691 } else {
12692 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: ip_version invalid",
12693 __func__);
12694 return -1;
12695 }
12696
12697 len = snprintf(pos, rem_len, " ip_version=%s", ipv6 ? "ipv6" : "ipv4");
12698 if (len < 0 || len >= rem_len)
12699 return -1;
12700
12701 pos += len;
12702 rem_len -= len;
12703 total_len += len;
12704
12705 val = get_param_fmt(cmd, "TCLASElem_SourceIPAddr_%d_%d",
12706 num_of_scs_desc, num_of_tclas_elem);
12707 if (val) {
12708 len = snprintf(pos, rem_len, " src_ip=%s", val);
12709 if (len < 0 || len >= rem_len)
12710 return -1;
12711
12712 pos += len;
12713 rem_len -= len;
12714 total_len += len;
12715 }
12716
12717 val = get_param_fmt(cmd, "TCLASElem_DestinationIPAddr_%d_%d",
12718 num_of_scs_desc, num_of_tclas_elem);
12719 if (val) {
12720 len = snprintf(pos, rem_len, " dst_ip=%s", val);
12721 if (len < 0 || len >= rem_len)
12722 return -1;
12723
12724 pos += len;
12725 rem_len -= len;
12726 total_len += len;
12727 }
12728
12729 val = get_param_fmt(cmd, "TCLASElem_SourcePort_%d_%d", num_of_scs_desc,
12730 num_of_tclas_elem);
12731 if (val) {
12732 len = snprintf(pos, rem_len, " src_port=%s", val);
12733 if (len < 0 || len >= rem_len)
12734 return -1;
12735
12736 pos += len;
12737 rem_len -= len;
12738 total_len += len;
12739 }
12740
12741 val = get_param_fmt(cmd, "TCLASElem_DestinationPort_%d_%d",
12742 num_of_scs_desc, num_of_tclas_elem);
12743 if (val) {
12744 len = snprintf(pos, rem_len, " dst_port=%s", val);
12745 if (len < 0 || len >= rem_len)
12746 return -1;
12747
12748 pos += len;
12749 rem_len -= len;
12750 total_len += len;
12751 }
12752
12753 val = get_param_fmt(cmd, "TCLASElem_DSCP_%d_%d", num_of_scs_desc,
12754 num_of_tclas_elem);
12755 if (val) {
12756 len = snprintf(pos, rem_len, " dscp=%s", val);
12757 if (len < 0 || len >= rem_len)
12758 return -1;
12759
12760 pos += len;
12761 rem_len -= len;
12762 total_len += len;
12763 }
12764
12765 val = get_param_fmt(cmd, "TCLASElem_ProtocolNxtHeader_%d_%d",
12766 num_of_scs_desc, num_of_tclas_elem);
12767 if (val) {
12768 char *prot;
12769
12770 switch (atoi(val)) {
12771 case 17:
12772 prot = "udp";
12773 break;
12774 case 6:
12775 prot = "tcp";
12776 break;
12777 case 50:
12778 prot = "esp";
12779 break;
12780 default:
12781 sigma_dut_print(dut, DUT_MSG_ERROR,
12782 "Invalid protocol %d", atoi(val));
12783 return -1;
12784 }
12785
12786 if (ipv6)
12787 len = snprintf(pos, rem_len, " next_header=%s", prot);
12788 else
12789 len = snprintf(pos, rem_len, " protocol=%s", prot);
12790 if (len < 0 || len >= rem_len)
12791 return -1;
12792
12793 pos += len;
12794 rem_len -= len;
12795 total_len += len;
12796 }
12797
12798 return total_len;
12799}
12800
12801
12802static int
12803get_type10_frame_classifier(struct sigma_dut *dut, struct sigma_cmd *cmd,
12804 char *pos, int rem_len, int num_of_scs_desc,
12805 int num_of_tclas_elem)
12806{
12807 const char *val;
12808 int len, total_len = 0;
12809
12810 val = get_param_fmt(cmd, "TCLASElem_ProtoInstance_%d_%d",
12811 num_of_scs_desc, num_of_tclas_elem);
12812 if (val) {
12813 len = snprintf(pos, rem_len, " prot_instance=%s",
12814 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_ProtoNumNextHeader_%d_%d",
12824 num_of_scs_desc, num_of_tclas_elem);
12825 if (val) {
12826 char *prot;
12827
12828 switch (atoi(val)) {
12829 case 17:
12830 prot = "udp";
12831 break;
12832 case 6:
12833 prot = "tcp";
12834 break;
12835 case 50:
12836 prot = "esp";
12837 break;
12838 default:
12839 sigma_dut_print(dut, DUT_MSG_ERROR,
12840 "Invalid protocol %d",
12841 atoi(val));
12842 return -1;
12843 }
12844
12845 len = snprintf(pos, rem_len, " prot_number=%s", prot);
12846 if (len < 0 || len >= rem_len)
12847 return -1;
12848
12849 pos += len;
12850 rem_len -= len;
12851 total_len += len;
12852 }
12853
12854 val = get_param_fmt(cmd, "TCLASElem_FilterValue_%d_%d",
12855 num_of_scs_desc, num_of_tclas_elem);
12856 if (val) {
12857 len = snprintf(pos, rem_len, " filter_value=%s", (val + 2));
12858 if (len < 0 || len >= rem_len)
12859 return -1;
12860
12861 pos += len;
12862 rem_len -= len;
12863 total_len += len;
12864 }
12865
12866 val = get_param_fmt(cmd, "TCLASElem_FilterMask_%d_%d", num_of_scs_desc,
12867 num_of_tclas_elem);
12868 if (val && strlen(val) >= 2) {
12869 len = snprintf(pos, rem_len, " filter_mask=%s", val + 2);
12870 if (len < 0 || len >= rem_len)
12871 return -1;
12872
12873 pos += len;
12874 rem_len -= len;
12875 total_len += len;
12876 }
12877
12878 return total_len;
12879}
12880
12881
12882static enum sigma_cmd_result
12883cmd_sta_send_frame_scs(struct sigma_dut *dut, struct sigma_conn *conn,
12884 const char *intf, struct sigma_cmd *cmd)
12885{
12886 char buf[4096], *pos;
12887 const char *val, *scs_id, *classifier_type;
12888 int len, rem_len, total_bytes;
12889 int num_of_scs_desc = 0, num_of_tclas_elem = 0;
12890
12891 scs_id = get_param(cmd, "SCSDescrElem_SCSID_1");
12892 if (!scs_id) {
12893 sigma_dut_print(dut, DUT_MSG_ERROR, "SCS ID empty");
12894 return INVALID_SEND_STATUS;
12895 }
12896
12897 rem_len = sizeof(buf);
12898 pos = buf;
12899
12900 len = snprintf(buf, sizeof(buf), "SCS");
12901 if (len < 0 || len > rem_len)
12902 goto fail;
12903
12904 pos += len;
12905 rem_len -= len;
12906
12907 while (scs_id) {
12908 num_of_scs_desc++;
12909
12910 val = get_param_fmt(cmd, "SCSDescrElem_RequestType_%d",
12911 num_of_scs_desc);
12912 if (!val)
12913 return INVALID_SEND_STATUS;
12914
12915 if (strcasecmp(val, "Add") == 0) {
12916 len = snprintf(pos, rem_len, " scs_id=%s add",
12917 scs_id);
12918 } else if (strcasecmp(val, "Change") == 0) {
12919 len = snprintf(pos, rem_len, " scs_id=%s change",
12920 scs_id);
12921 } else if (strcasecmp(val, "Remove") == 0) {
12922 len = snprintf(pos, rem_len, " scs_id=%s remove",
12923 scs_id);
12924 if (len < 0 || len >= rem_len)
12925 goto fail;
12926
12927 pos += len;
12928 rem_len -= len;
12929 goto scs_desc_end;
12930 } else {
12931 sigma_dut_print(dut, DUT_MSG_ERROR,
12932 "%s: request type - %s is invalid",
12933 __func__, val);
12934 return INVALID_SEND_STATUS;
12935 }
12936
12937 if (len < 0 || len >= rem_len)
12938 goto fail;
12939
12940 pos += len;
12941 rem_len -= len;
12942
12943 val = get_param_fmt(cmd, "IntraAccessCatElem_UP_%d",
12944 num_of_scs_desc);
12945 if (!val) {
12946 sigma_dut_print(dut, DUT_MSG_ERROR,
12947 "IntraAccess Priority empty");
12948 return INVALID_SEND_STATUS;
12949 }
12950
12951 len = snprintf(pos, rem_len, " scs_up=%s", val);
12952 if (len < 0 || len >= rem_len)
12953 goto fail;
12954
12955 pos += len;
12956 rem_len -= len;
12957
12958 classifier_type = get_param_fmt(cmd,
12959 "TCLASElem_ClassifierType_%d_1",
12960 num_of_scs_desc);
12961 if (!classifier_type) {
12962 sigma_dut_print(dut, DUT_MSG_ERROR,
12963 "classifier type missing");
12964 return INVALID_SEND_STATUS;
12965 }
12966
12967 while (classifier_type) {
12968 num_of_tclas_elem++;
12969
12970 len = snprintf(pos, rem_len, " classifier_type=%s",
12971 classifier_type);
12972 if (len < 0 || len >= rem_len)
12973 goto fail;
12974
12975 pos += len;
12976 rem_len -= len;
12977
12978 if (strcmp(classifier_type, "10") == 0) {
12979 total_bytes = get_type10_frame_classifier(
12980 dut, cmd, pos, rem_len,
12981 num_of_scs_desc,
12982 num_of_tclas_elem);
12983 } else if (strcmp(classifier_type, "4") == 0) {
12984 total_bytes = get_type4_frame_classifier(
12985 dut, cmd, pos, rem_len,
12986 num_of_scs_desc,
12987 num_of_tclas_elem);
12988 } else {
12989 sigma_dut_print(dut, DUT_MSG_ERROR,
12990 "classifier_type invalid");
12991 goto fail;
12992 }
12993
12994 if (total_bytes < 0)
12995 goto fail;
12996
12997 pos += total_bytes;
12998 rem_len -= total_bytes;
12999
13000 classifier_type = get_param_fmt(
13001 cmd, "TCLASElem_ClassifierType_%d_%d",
13002 num_of_scs_desc, num_of_tclas_elem + 1);
13003 }
13004
13005 if (num_of_tclas_elem > 1) {
13006 val = get_param_fmt(cmd,
13007 "TCLASProcessingElem_Processing_%d",
13008 num_of_scs_desc);
13009 if (!val) {
13010 sigma_dut_print(dut, DUT_MSG_ERROR,
13011 "Tclas_processing element %d empty",
13012 num_of_scs_desc);
13013 goto fail;
13014 }
13015
13016 len = snprintf(pos, rem_len,
13017 " tclas_processing=%s", val);
13018 if (len < 0 || len >= rem_len)
13019 goto fail;
13020
13021 pos += len;
13022 rem_len -= len;
13023 }
13024scs_desc_end:
13025 num_of_tclas_elem = 0;
13026 scs_id = get_param_fmt(cmd, "SCSDescrElem_SCSID_%d",
13027 num_of_scs_desc + 1);
13028 }
13029
13030 if (wpa_command(intf, buf) != 0) {
13031 send_resp(dut, conn, SIGMA_ERROR,
13032 "ErrorCode,Failed to send SCS frame request");
13033 return STATUS_SENT_ERROR;
13034 }
13035
13036 sigma_dut_print(dut, DUT_MSG_DEBUG,
13037 "SCS frame request sent: %s", buf);
13038
13039 return SUCCESS_SEND_STATUS;
13040fail:
13041 sigma_dut_print(dut, DUT_MSG_ERROR,
13042 "Failed to create SCS frame request");
13043 return ERROR_SEND_STATUS;
13044}
13045
13046
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013047static enum sigma_cmd_result
13048cmd_sta_send_frame_mscs(struct sigma_dut *dut, struct sigma_conn *conn,
13049 const char *intf, struct sigma_cmd *cmd)
13050{
13051 char buf[128], *pos;
13052 const char *val, *classifier_type = "04", *type;
13053 int len, rem_len;
13054 u8 up_bitmap;
13055
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013056 type = get_param(cmd, "Request_Type");
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013057 if (!type) {
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013058 sigma_dut_print(dut, DUT_MSG_ERROR,
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013059 "%s: type not valid", __func__);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013060 return INVALID_SEND_STATUS;
13061 }
13062
13063 rem_len = sizeof(buf);
13064 pos = buf;
13065 if (strcasecmp(type, "add") == 0) {
13066 len = snprintf(pos, rem_len, "MSCS add");
13067 } else if (strcasecmp(type, "update") == 0) {
13068 len = snprintf(pos, rem_len, "MSCS change");
13069 } else if (strcasecmp(type, "remove") == 0) {
13070 if (wpa_command(intf, "MSCS remove") != 0) {
13071 send_resp(dut, conn, SIGMA_ERROR,
13072 "ErrorCode,Failed to send MSCS frame req");
13073 return STATUS_SENT_ERROR;
13074 }
13075 return SUCCESS_SEND_STATUS;
13076 } else {
13077 sigma_dut_print(dut, DUT_MSG_ERROR,
13078 "%s: request type invalid", __func__);
13079 return INVALID_SEND_STATUS;
13080 }
13081
13082 if (len < 0 || len >= rem_len)
13083 goto fail;
13084
13085 pos += len;
13086 rem_len -= len;
13087
13088 val = get_param(cmd, "User_Priority_Bitmap");
13089 if (!val) {
13090 sigma_dut_print(dut, DUT_MSG_ERROR,
13091 "%s: user priority bitmap empty", __func__);
13092 return INVALID_SEND_STATUS;
13093 }
13094
13095 switch (atoi(val)) {
13096 case 0:
13097 up_bitmap = 0x00;
13098 break;
13099 case 1:
13100 up_bitmap = 0xF0;
13101 break;
13102 case 2:
13103 up_bitmap = 0xF6;
13104 break;
13105 default:
13106 sigma_dut_print(dut, DUT_MSG_ERROR,
13107 "%s: Unknown User_Priority_Bitmap value %d",
13108 __func__, atoi(val));
13109 return INVALID_SEND_STATUS;
13110 }
13111
13112 len = snprintf(pos, rem_len, " up_bitmap=%02x", up_bitmap);
13113 if (len < 0 || len >= rem_len)
13114 goto fail;
13115
13116 pos += len;
13117 rem_len -= len;
13118
13119 val = get_param(cmd, "User_Priority_Limit");
13120 if (!val) {
13121 sigma_dut_print(dut, DUT_MSG_ERROR,
13122 "%s: invalid user priority limit", __func__);
13123 return INVALID_SEND_STATUS;
13124 }
13125
13126 len = snprintf(pos, rem_len, " up_limit=%s", val);
13127 if (len < 0 || len >= rem_len)
13128 goto fail;
13129
13130 pos += len;
13131 rem_len -= len;
13132
13133 val = get_param(cmd, "Stream_Timeout");
13134 if (!val)
13135 val = get_param(cmd, "Stream_Timtout");
13136 if (!val) {
13137 sigma_dut_print(dut, DUT_MSG_ERROR,
13138 "%s: invalid stream timeout", __func__);
13139 return INVALID_SEND_STATUS;
13140 }
13141
13142 len = snprintf(pos, rem_len, " stream_timeout=%s", val);
13143 if (len < 0 || len >= rem_len)
13144 goto fail;
13145
13146 pos += len;
13147 rem_len -= len;
13148
13149 val = get_param(cmd, "TCLAS_Mask");
13150 if (!val) {
13151 sigma_dut_print(dut, DUT_MSG_ERROR,
13152 "%s: invalid tclas mask", __func__);
13153 return INVALID_SEND_STATUS;
13154 }
13155
13156 len = snprintf(pos, rem_len, " frame_classifier=%s%lx%032x",
13157 classifier_type, strtol(val, NULL, 2), 0);
13158 if (len < 0 || len >= rem_len)
13159 goto fail;
13160
13161 if (wpa_command(intf, buf) != 0) {
13162 send_resp(dut, conn, SIGMA_ERROR,
13163 "ErrorCode,Failed to send MSCS frame req");
13164 return STATUS_SENT_ERROR;
13165 }
13166
13167 sigma_dut_print(dut, DUT_MSG_DEBUG,
13168 "MSCS frame request sent: %s", buf);
13169
13170 return SUCCESS_SEND_STATUS;
13171fail:
13172 sigma_dut_print(dut, DUT_MSG_ERROR,
13173 "Failed to create MSCS frame req");
13174 return ERROR_SEND_STATUS;
13175}
13176
13177
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013178static enum sigma_cmd_result
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053013179cmd_sta_send_frame_dscp_query(struct sigma_dut *dut, struct sigma_conn *conn,
13180 const char *intf, struct sigma_cmd *cmd)
13181{
13182 char buf[150], *pos;
13183 const char *val;
13184 int len, rem_len;
13185
13186 rem_len = sizeof(buf);
13187 pos = buf;
13188
13189 len = snprintf(pos, rem_len, "DSCP_QUERY");
13190 if (len < 0 || len >= rem_len)
13191 goto fail;
13192
13193 pos += len;
13194 rem_len -= len;
13195
13196 val = get_param(cmd, "Wildcard");
13197 if (val && strcasecmp(val, "Yes") == 0) {
13198 len = snprintf(pos, rem_len, " wildcard");
13199 if (len < 0 || len >= rem_len)
13200 goto fail;
13201 } else if (strlen(dut->qm_domain_name)) {
13202 len = snprintf(pos, rem_len, " domain_name=%s",
13203 dut->qm_domain_name);
13204 if (len < 0 || len >= rem_len)
13205 goto fail;
13206 } else {
13207 sigma_dut_print(dut, DUT_MSG_ERROR,
13208 "Invalid DSCP Query configuration");
13209 return INVALID_SEND_STATUS;
13210 }
13211
13212 if (wpa_command(intf, buf) != 0) {
13213 send_resp(dut, conn, SIGMA_ERROR,
13214 "ErrorCode,Failed to send DSCP policy query frame");
13215 return STATUS_SENT_ERROR;
13216 }
13217
13218 sigma_dut_print(dut, DUT_MSG_DEBUG,
13219 "DSCP policy query frame sent: %s", buf);
13220 return SUCCESS_SEND_STATUS;
13221fail:
13222 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to send DSCP query");
13223 return ERROR_SEND_STATUS;
13224}
13225
13226
13227static enum sigma_cmd_result
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013228cmd_sta_send_frame_qm(struct sigma_dut *dut, struct sigma_conn *conn,
13229 const char *intf, struct sigma_cmd *cmd)
13230{
13231 const char *val;
13232
13233 val = get_param(cmd, "FrameName");
13234 if (val) {
13235 if (strcasecmp(val, "MSCSReq") == 0)
13236 return cmd_sta_send_frame_mscs(dut, conn, intf, cmd);
13237 if (strcasecmp(val, "SCSReq") == 0)
13238 return cmd_sta_send_frame_scs(dut, conn, intf, cmd);
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053013239 if (strcasecmp(val, "DSCPPolicyQuery") == 0)
13240 return cmd_sta_send_frame_dscp_query(dut, conn, intf,
13241 cmd);
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013242
13243 sigma_dut_print(dut, DUT_MSG_ERROR,
13244 "%s: frame name - %s is invalid",
13245 __func__, val);
13246 }
13247
13248 return INVALID_SEND_STATUS;
13249}
13250
13251
Jouni Malinenf7222712019-06-13 01:50:21 +030013252enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
13253 struct sigma_conn *conn,
13254 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013255{
13256 const char *intf = get_param(cmd, "Interface");
13257 const char *val;
13258 enum send_frame_type frame;
13259 enum send_frame_protection protected;
13260 char buf[100];
13261 unsigned char addr[ETH_ALEN];
13262 int res;
13263
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030013264 if (!intf)
13265 return -1;
13266
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013267 val = get_param(cmd, "program");
13268 if (val == NULL)
13269 val = get_param(cmd, "frame");
13270 if (val && strcasecmp(val, "TDLS") == 0)
13271 return cmd_sta_send_frame_tdls(dut, conn, cmd);
13272 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030013273 strcasecmp(val, "HS2-R2") == 0 ||
13274 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013275 return cmd_sta_send_frame_hs2(dut, conn, cmd);
13276 if (val && strcasecmp(val, "VHT") == 0)
13277 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070013278 if (val && strcasecmp(val, "HE") == 0)
13279 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070013280 if (val && strcasecmp(val, "LOC") == 0)
13281 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020013282 if (val && strcasecmp(val, "60GHz") == 0)
13283 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053013284 if (val && strcasecmp(val, "MBO") == 0) {
13285 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
13286 if (res != 2)
13287 return res;
13288 }
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053013289 if (val && strcasecmp(val, "WPA3") == 0)
13290 return cmd_sta_send_frame_wpa3(dut, conn, intf, cmd);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053013291 if (val && strcasecmp(val, "QM") == 0)
Vinita S. Malooca85fd22021-01-15 02:54:34 +053013292 return cmd_sta_send_frame_qm(dut, conn, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013293
13294 val = get_param(cmd, "TD_DISC");
13295 if (val) {
13296 if (hwaddr_aton(val, addr) < 0)
13297 return -1;
13298 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
13299 if (wpa_command(intf, buf) < 0) {
13300 send_resp(dut, conn, SIGMA_ERROR,
13301 "ErrorCode,Failed to send TDLS discovery");
13302 return 0;
13303 }
13304 return 1;
13305 }
13306
13307 val = get_param(cmd, "TD_Setup");
13308 if (val) {
13309 if (hwaddr_aton(val, addr) < 0)
13310 return -1;
13311 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
13312 if (wpa_command(intf, buf) < 0) {
13313 send_resp(dut, conn, SIGMA_ERROR,
13314 "ErrorCode,Failed to start TDLS setup");
13315 return 0;
13316 }
13317 return 1;
13318 }
13319
13320 val = get_param(cmd, "TD_TearDown");
13321 if (val) {
13322 if (hwaddr_aton(val, addr) < 0)
13323 return -1;
13324 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
13325 if (wpa_command(intf, buf) < 0) {
13326 send_resp(dut, conn, SIGMA_ERROR,
13327 "ErrorCode,Failed to tear down TDLS link");
13328 return 0;
13329 }
13330 return 1;
13331 }
13332
13333 val = get_param(cmd, "TD_ChannelSwitch");
13334 if (val) {
13335 /* TODO */
13336 send_resp(dut, conn, SIGMA_ERROR,
13337 "ErrorCode,TD_ChannelSwitch not yet supported");
13338 return 0;
13339 }
13340
13341 val = get_param(cmd, "TD_NF");
13342 if (val) {
13343 /* TODO */
13344 send_resp(dut, conn, SIGMA_ERROR,
13345 "ErrorCode,TD_NF not yet supported");
13346 return 0;
13347 }
13348
13349 val = get_param(cmd, "PMFFrameType");
13350 if (val == NULL)
13351 val = get_param(cmd, "FrameName");
13352 if (val == NULL)
13353 val = get_param(cmd, "Type");
13354 if (val == NULL)
13355 return -1;
13356 if (strcasecmp(val, "disassoc") == 0)
13357 frame = DISASSOC;
13358 else if (strcasecmp(val, "deauth") == 0)
13359 frame = DEAUTH;
13360 else if (strcasecmp(val, "saquery") == 0)
13361 frame = SAQUERY;
13362 else if (strcasecmp(val, "auth") == 0)
13363 frame = AUTH;
13364 else if (strcasecmp(val, "assocreq") == 0)
13365 frame = ASSOCREQ;
13366 else if (strcasecmp(val, "reassocreq") == 0)
13367 frame = REASSOCREQ;
13368 else if (strcasecmp(val, "neigreq") == 0) {
13369 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
13370
13371 val = get_param(cmd, "ssid");
13372 if (val == NULL)
13373 return -1;
13374
13375 res = send_neighbor_request(dut, intf, val);
13376 if (res) {
13377 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
13378 "Failed to send neighbor report request");
13379 return 0;
13380 }
13381
13382 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053013383 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
13384 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013385 sigma_dut_print(dut, DUT_MSG_DEBUG,
13386 "Got Transition Management Query");
13387
Ashwini Patil5acd7382017-04-13 15:55:04 +053013388 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013389 if (res) {
13390 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
13391 "Failed to send Transition Management Query");
13392 return 0;
13393 }
13394
13395 return 1;
13396 } else {
13397 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13398 "PMFFrameType");
13399 return 0;
13400 }
13401
13402 val = get_param(cmd, "PMFProtected");
13403 if (val == NULL)
13404 val = get_param(cmd, "Protected");
13405 if (val == NULL)
13406 return -1;
13407 if (strcasecmp(val, "Correct-key") == 0 ||
13408 strcasecmp(val, "CorrectKey") == 0)
13409 protected = CORRECT_KEY;
13410 else if (strcasecmp(val, "IncorrectKey") == 0)
13411 protected = INCORRECT_KEY;
13412 else if (strcasecmp(val, "Unprotected") == 0)
13413 protected = UNPROTECTED;
13414 else {
13415 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13416 "PMFProtected");
13417 return 0;
13418 }
13419
13420 if (protected != UNPROTECTED &&
13421 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
13422 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
13423 "PMFProtected for auth/assocreq/reassocreq");
13424 return 0;
13425 }
13426
13427 if (if_nametoindex("sigmadut") == 0) {
13428 snprintf(buf, sizeof(buf),
13429 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013430 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013431 if (system(buf) != 0 ||
13432 if_nametoindex("sigmadut") == 0) {
13433 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
13434 "monitor interface with '%s'", buf);
13435 return -2;
13436 }
13437 }
13438
13439 if (system("ifconfig sigmadut up") != 0) {
13440 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
13441 "monitor interface up");
13442 return -2;
13443 }
13444
Veerendranath Jakkam49774122020-07-05 09:52:18 +053013445 return sta_inject_frame(dut, conn, intf, frame, protected, NULL, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013446}
13447
13448
13449static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
13450 struct sigma_conn *conn,
13451 struct sigma_cmd *cmd,
13452 const char *ifname)
13453{
13454 char buf[200];
13455 const char *val;
13456
13457 val = get_param(cmd, "ClearARP");
13458 if (val && atoi(val) == 1) {
13459 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
13460 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13461 if (system(buf) != 0) {
13462 send_resp(dut, conn, SIGMA_ERROR,
13463 "errorCode,Failed to clear ARP cache");
13464 return 0;
13465 }
13466 }
13467
13468 return 1;
13469}
13470
13471
13472int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
13473 struct sigma_cmd *cmd)
13474{
13475 const char *intf = get_param(cmd, "Interface");
13476 const char *val;
13477
13478 if (intf == NULL)
13479 return -1;
13480
13481 val = get_param(cmd, "program");
13482 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030013483 strcasecmp(val, "HS2-R2") == 0 ||
13484 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013485 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
13486
13487 return -1;
13488}
13489
13490
Jouni Malinenf7222712019-06-13 01:50:21 +030013491static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
13492 struct sigma_conn *conn,
13493 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013494{
13495 const char *intf = get_param(cmd, "Interface");
13496 const char *mac = get_param(cmd, "MAC");
13497
13498 if (intf == NULL || mac == NULL)
13499 return -1;
13500
13501 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
13502 "interface %s to %s", intf, mac);
13503
13504 if (dut->set_macaddr) {
13505 char buf[128];
13506 int res;
13507 if (strcasecmp(mac, "default") == 0) {
13508 res = snprintf(buf, sizeof(buf), "%s",
13509 dut->set_macaddr);
13510 dut->tmp_mac_addr = 0;
13511 } else {
13512 res = snprintf(buf, sizeof(buf), "%s %s",
13513 dut->set_macaddr, mac);
13514 dut->tmp_mac_addr = 1;
13515 }
13516 if (res < 0 || res >= (int) sizeof(buf))
13517 return -1;
13518 if (system(buf) != 0) {
13519 send_resp(dut, conn, SIGMA_ERROR,
13520 "errorCode,Failed to set MAC "
13521 "address");
13522 return 0;
13523 }
13524 return 1;
13525 }
13526
13527 if (strcasecmp(mac, "default") == 0)
13528 return 1;
13529
13530 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13531 "command");
13532 return 0;
13533}
13534
13535
13536static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
13537 struct sigma_conn *conn, const char *intf,
13538 int val)
13539{
13540 char buf[200];
13541 int res;
13542
13543 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
13544 intf, val);
13545 if (res < 0 || res >= (int) sizeof(buf))
13546 return -1;
13547 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13548 if (system(buf) != 0) {
13549 send_resp(dut, conn, SIGMA_ERROR,
13550 "errorCode,Failed to configure offchannel mode");
13551 return 0;
13552 }
13553
13554 return 1;
13555}
13556
13557
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013558static int off_chan_val(enum sec_ch_offset off)
13559{
13560 switch (off) {
13561 case SEC_CH_NO:
13562 return 0;
13563 case SEC_CH_40ABOVE:
13564 return 40;
13565 case SEC_CH_40BELOW:
13566 return -40;
13567 }
13568
13569 return 0;
13570}
13571
13572
13573static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
13574 const char *intf, int off_ch_num,
13575 enum sec_ch_offset sec)
13576{
13577 char buf[200];
13578 int res;
13579
13580 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
13581 intf, off_ch_num);
13582 if (res < 0 || res >= (int) sizeof(buf))
13583 return -1;
13584 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13585 if (system(buf) != 0) {
13586 send_resp(dut, conn, SIGMA_ERROR,
13587 "errorCode,Failed to set offchan");
13588 return 0;
13589 }
13590
13591 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
13592 intf, off_chan_val(sec));
13593 if (res < 0 || res >= (int) sizeof(buf))
13594 return -1;
13595 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13596 if (system(buf) != 0) {
13597 send_resp(dut, conn, SIGMA_ERROR,
13598 "errorCode,Failed to set sec chan offset");
13599 return 0;
13600 }
13601
13602 return 1;
13603}
13604
13605
13606static int tdls_set_offchannel_offset(struct sigma_dut *dut,
13607 struct sigma_conn *conn,
13608 const char *intf, int off_ch_num,
13609 enum sec_ch_offset sec)
13610{
13611 char buf[200];
13612 int res;
13613
13614 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
13615 off_ch_num);
13616 if (res < 0 || res >= (int) sizeof(buf))
13617 return -1;
13618 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13619
13620 if (wpa_command(intf, buf) < 0) {
13621 send_resp(dut, conn, SIGMA_ERROR,
13622 "ErrorCode,Failed to set offchan");
13623 return 0;
13624 }
13625 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
13626 off_chan_val(sec));
13627 if (res < 0 || res >= (int) sizeof(buf))
13628 return -1;
13629
13630 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13631
13632 if (wpa_command(intf, buf) < 0) {
13633 send_resp(dut, conn, SIGMA_ERROR,
13634 "ErrorCode,Failed to set sec chan offset");
13635 return 0;
13636 }
13637
13638 return 1;
13639}
13640
13641
13642static int tdls_set_offchannel_mode(struct sigma_dut *dut,
13643 struct sigma_conn *conn,
13644 const char *intf, int val)
13645{
13646 char buf[200];
13647 int res;
13648
13649 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
13650 val);
13651 if (res < 0 || res >= (int) sizeof(buf))
13652 return -1;
13653 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
13654
13655 if (wpa_command(intf, buf) < 0) {
13656 send_resp(dut, conn, SIGMA_ERROR,
13657 "ErrorCode,Failed to configure offchannel mode");
13658 return 0;
13659 }
13660
13661 return 1;
13662}
13663
13664
13665static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
13666 struct sigma_conn *conn,
13667 struct sigma_cmd *cmd)
13668{
13669 const char *val;
13670 enum {
13671 CHSM_NOT_SET,
13672 CHSM_ENABLE,
13673 CHSM_DISABLE,
13674 CHSM_REJREQ,
13675 CHSM_UNSOLRESP
13676 } chsm = CHSM_NOT_SET;
13677 int off_ch_num = -1;
13678 enum sec_ch_offset sec_ch = SEC_CH_NO;
13679 int res;
13680
13681 val = get_param(cmd, "Uapsd");
13682 if (val) {
13683 char buf[100];
13684 if (strcasecmp(val, "Enable") == 0)
13685 snprintf(buf, sizeof(buf), "SET ps 99");
13686 else if (strcasecmp(val, "Disable") == 0)
13687 snprintf(buf, sizeof(buf), "SET ps 98");
13688 else {
13689 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
13690 "Unsupported uapsd parameter value");
13691 return 0;
13692 }
13693 if (wpa_command(intf, buf)) {
13694 send_resp(dut, conn, SIGMA_ERROR,
13695 "ErrorCode,Failed to change U-APSD "
13696 "powersave mode");
13697 return 0;
13698 }
13699 }
13700
13701 val = get_param(cmd, "TPKTIMER");
13702 if (val && strcasecmp(val, "DISABLE") == 0) {
13703 if (wpa_command(intf, "SET tdls_testing 0x100")) {
13704 send_resp(dut, conn, SIGMA_ERROR,
13705 "ErrorCode,Failed to enable no TPK "
13706 "expiration test mode");
13707 return 0;
13708 }
13709 dut->no_tpk_expiration = 1;
13710 }
13711
13712 val = get_param(cmd, "ChSwitchMode");
13713 if (val) {
13714 if (strcasecmp(val, "Enable") == 0 ||
13715 strcasecmp(val, "Initiate") == 0)
13716 chsm = CHSM_ENABLE;
13717 else if (strcasecmp(val, "Disable") == 0 ||
13718 strcasecmp(val, "passive") == 0)
13719 chsm = CHSM_DISABLE;
13720 else if (strcasecmp(val, "RejReq") == 0)
13721 chsm = CHSM_REJREQ;
13722 else if (strcasecmp(val, "UnSolResp") == 0)
13723 chsm = CHSM_UNSOLRESP;
13724 else {
13725 send_resp(dut, conn, SIGMA_ERROR,
13726 "ErrorCode,Unknown ChSwitchMode value");
13727 return 0;
13728 }
13729 }
13730
13731 val = get_param(cmd, "OffChNum");
13732 if (val) {
13733 off_ch_num = atoi(val);
13734 if (off_ch_num == 0) {
13735 send_resp(dut, conn, SIGMA_ERROR,
13736 "ErrorCode,Invalid OffChNum");
13737 return 0;
13738 }
13739 }
13740
13741 val = get_param(cmd, "SecChOffset");
13742 if (val) {
13743 if (strcmp(val, "20") == 0)
13744 sec_ch = SEC_CH_NO;
13745 else if (strcasecmp(val, "40above") == 0)
13746 sec_ch = SEC_CH_40ABOVE;
13747 else if (strcasecmp(val, "40below") == 0)
13748 sec_ch = SEC_CH_40BELOW;
13749 else {
13750 send_resp(dut, conn, SIGMA_ERROR,
13751 "ErrorCode,Unknown SecChOffset value");
13752 return 0;
13753 }
13754 }
13755
13756 if (chsm == CHSM_NOT_SET) {
13757 /* no offchannel changes requested */
13758 return 1;
13759 }
13760
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013761 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
13762 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013763 send_resp(dut, conn, SIGMA_ERROR,
13764 "ErrorCode,Unknown interface");
13765 return 0;
13766 }
13767
13768 switch (chsm) {
13769 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030013770 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013771 break;
13772 case CHSM_ENABLE:
13773 if (off_ch_num < 0) {
13774 send_resp(dut, conn, SIGMA_ERROR,
13775 "ErrorCode,Missing OffChNum argument");
13776 return 0;
13777 }
13778 if (wifi_chip_type == DRIVER_WCN) {
13779 res = tdls_set_offchannel_offset(dut, conn, intf,
13780 off_ch_num, sec_ch);
13781 } else {
13782 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
13783 sec_ch);
13784 }
13785 if (res != 1)
13786 return res;
13787 if (wifi_chip_type == DRIVER_WCN)
13788 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
13789 else
13790 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
13791 break;
13792 case CHSM_DISABLE:
13793 if (wifi_chip_type == DRIVER_WCN)
13794 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
13795 else
13796 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
13797 break;
13798 case CHSM_REJREQ:
13799 if (wifi_chip_type == DRIVER_WCN)
13800 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
13801 else
13802 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
13803 break;
13804 case CHSM_UNSOLRESP:
13805 if (off_ch_num < 0) {
13806 send_resp(dut, conn, SIGMA_ERROR,
13807 "ErrorCode,Missing OffChNum argument");
13808 return 0;
13809 }
13810 if (wifi_chip_type == DRIVER_WCN) {
13811 res = tdls_set_offchannel_offset(dut, conn, intf,
13812 off_ch_num, sec_ch);
13813 } else {
13814 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
13815 sec_ch);
13816 }
13817 if (res != 1)
13818 return res;
13819 if (wifi_chip_type == DRIVER_WCN)
13820 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
13821 else
13822 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
13823 break;
13824 }
13825
13826 return res;
13827}
13828
13829
13830static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
13831 struct sigma_conn *conn,
13832 struct sigma_cmd *cmd)
13833{
13834 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053013835 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013836
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070013837 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080013838
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013839 val = get_param(cmd, "nss_mcs_opt");
13840 if (val) {
13841 /* String (nss_operating_mode; mcs_operating_mode) */
13842 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053013843 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013844
13845 token = strdup(val);
13846 if (!token)
13847 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053013848 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053013849 if (!result) {
13850 sigma_dut_print(dut, DUT_MSG_ERROR,
13851 "VHT NSS not specified");
13852 goto failed;
13853 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013854 if (strcasecmp(result, "def") != 0) {
13855 nss = atoi(result);
13856 if (nss == 4)
13857 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013858 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013859 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013860
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013861 }
13862
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053013863 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053013864 if (!result) {
13865 sigma_dut_print(dut, DUT_MSG_ERROR,
13866 "VHT MCS not specified");
13867 goto failed;
13868 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013869 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013870 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013871 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013872 } else {
13873 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013874 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013875 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013876 }
13877 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070013878 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013879 }
13880
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053013881 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013882 return 1;
13883failed:
13884 free(token);
13885 return 0;
13886}
13887
13888
13889static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
13890 struct sigma_conn *conn,
13891 struct sigma_cmd *cmd)
13892{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013893 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013894 case DRIVER_ATHEROS:
13895 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
13896 default:
13897 send_resp(dut, conn, SIGMA_ERROR,
13898 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
13899 return 0;
13900 }
13901}
13902
13903
Jouni Malinen1702fe32021-06-08 19:08:01 +030013904static enum sigma_cmd_result
13905wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
13906 struct sigma_conn *conn, struct sigma_cmd *cmd)
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013907{
13908 const char *val;
13909 char *token = NULL, *result;
13910 char buf[60];
13911
13912 val = get_param(cmd, "nss_mcs_opt");
13913 if (val) {
13914 /* String (nss_operating_mode; mcs_operating_mode) */
13915 int nss, mcs, ratecode;
13916 char *saveptr;
13917
13918 token = strdup(val);
13919 if (!token)
Jouni Malinen1702fe32021-06-08 19:08:01 +030013920 return ERROR_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013921
13922 result = strtok_r(token, ";", &saveptr);
13923 if (!result) {
13924 sigma_dut_print(dut, DUT_MSG_ERROR,
13925 "HE NSS not specified");
13926 goto failed;
13927 }
13928 nss = 1;
13929 if (strcasecmp(result, "def") != 0)
13930 nss = atoi(result);
13931
13932 result = strtok_r(NULL, ";", &saveptr);
13933 if (!result) {
13934 sigma_dut_print(dut, DUT_MSG_ERROR,
13935 "HE MCS not specified");
13936 goto failed;
13937 }
13938 mcs = 7;
13939 if (strcasecmp(result, "def") != 0)
13940 mcs = atoi(result);
13941
Arif Hussain557bf412018-05-25 17:29:36 -070013942 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013943 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070013944 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013945 } else if (nss > 2) {
13946 sigma_dut_print(dut, DUT_MSG_ERROR,
13947 "HE NSS %d not supported", nss);
13948 goto failed;
13949 }
13950
Arif Hussain557bf412018-05-25 17:29:36 -070013951 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
13952 if (system(buf) != 0) {
13953 sigma_dut_print(dut, DUT_MSG_ERROR,
13954 "nss_mcs_opt: iwpriv %s nss %d failed",
13955 intf, nss);
13956 goto failed;
13957 }
Arif Hussainac6c5112018-05-25 17:34:00 -070013958 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070013959
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013960 /* Add the MCS to the ratecode */
13961 if (mcs >= 0 && mcs <= 11) {
13962 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070013963#ifdef NL80211_SUPPORT
13964 if (dut->device_type == STA_testbed) {
13965 enum he_mcs_config mcs_config;
13966 int ret;
13967
13968 if (mcs <= 7)
13969 mcs_config = HE_80_MCS0_7;
13970 else if (mcs <= 9)
13971 mcs_config = HE_80_MCS0_9;
13972 else
13973 mcs_config = HE_80_MCS0_11;
13974 ret = sta_set_he_mcs(dut, intf, mcs_config);
13975 if (ret) {
13976 sigma_dut_print(dut, DUT_MSG_ERROR,
13977 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
13978 mcs, mcs_config, ret);
13979 goto failed;
13980 }
13981 }
13982#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013983 } else {
13984 sigma_dut_print(dut, DUT_MSG_ERROR,
13985 "HE MCS %d not supported", mcs);
13986 goto failed;
13987 }
13988 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
13989 intf, ratecode);
13990 if (system(buf) != 0) {
13991 sigma_dut_print(dut, DUT_MSG_ERROR,
13992 "iwpriv setting of 11ax rates failed");
13993 goto failed;
13994 }
13995 free(token);
13996 }
13997
13998 val = get_param(cmd, "GI");
13999 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014000 int fix_rate_sgi;
14001
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014002 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070014003 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014004 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014005 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070014006 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
14007 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014008 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014009 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070014010 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
14011 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014012 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014013 } else {
14014 send_resp(dut, conn, SIGMA_ERROR,
14015 "errorCode,GI value not supported");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014016 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014017 }
14018 if (system(buf) != 0) {
14019 send_resp(dut, conn, SIGMA_ERROR,
14020 "errorCode,Failed to set shortgi");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014021 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014022 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014023 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
14024 intf, fix_rate_sgi);
14025 if (system(buf) != 0) {
14026 send_resp(dut, conn, SIGMA_ERROR,
14027 "errorCode,Failed to set fix rate shortgi");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014028 return STATUS_SENT_ERROR;
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080014029 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014030 }
14031
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014032 val = get_param(cmd, "LTF");
14033 if (val) {
14034#ifdef NL80211_SUPPORT
14035 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080014036 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014037 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080014038 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014039 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080014040 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014041 } else {
14042 send_resp(dut, conn, SIGMA_ERROR,
14043 "errorCode, LTF value not supported");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014044 return STATUS_SENT_ERROR;
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014045 }
14046#else /* NL80211_SUPPORT */
14047 sigma_dut_print(dut, DUT_MSG_ERROR,
14048 "LTF cannot be set without NL80211_SUPPORT defined");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014049 return ERROR_SEND_STATUS;
Subhani Shaik8e7a3052018-04-24 14:03:00 -070014050#endif /* NL80211_SUPPORT */
14051 }
14052
Kiran Kumar Lokere1809da12021-06-24 00:45:38 -070014053 val = get_param(cmd, "KeepAlive");
14054 if (val) {
14055 int set_val = QCA_WLAN_KEEP_ALIVE_DEFAULT;
14056
14057 if (strcasecmp(val, "Data") == 0)
14058 set_val = QCA_WLAN_KEEP_ALIVE_DATA;
14059 else if (strcasecmp(val, "Mgmt") == 0)
14060 set_val = QCA_WLAN_KEEP_ALIVE_MGMT;
14061
14062 if (sta_set_keep_alive_data_cfg(dut, intf, set_val)) {
14063 send_resp(dut, conn, SIGMA_ERROR,
14064 "ErrorCode,Failed to set keep alive type config");
14065 return STATUS_SENT_ERROR;
14066 }
14067 }
14068
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070014069 val = get_param(cmd, "TxSUPPDU");
14070 if (val) {
14071 int set_val = 1;
14072
14073 if (strcasecmp(val, "Enable") == 0)
14074 set_val = 1;
14075 else if (strcasecmp(val, "Disable") == 0)
14076 set_val = 0;
14077
14078 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
14079 send_resp(dut, conn, SIGMA_ERROR,
14080 "ErrorCode,Failed to set Tx SU PPDU config");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014081 return STATUS_SENT_ERROR;
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070014082 }
14083 }
14084
Kiran Kumar Lokere54b72522021-04-01 00:22:44 -070014085 val = get_param(cmd, "Mgmt_Data_TX_Resp_Frame");
14086 if (val) {
14087 int set_val = 0;
14088
14089 if (strcasecmp(val, "Enable") == 0)
14090 set_val = 0;
14091 else if (strcasecmp(val, "Disable") == 0)
14092 set_val = 1;
14093
14094 if (sta_set_mgmt_data_tx_disable_cfg(dut, intf, set_val)) {
14095 send_resp(dut, conn, SIGMA_ERROR,
14096 "ErrorCode,Failed to set mgmt/data Tx disable config");
14097 return STATUS_SENT_ERROR;
14098 }
14099 }
14100
Arif Hussain480d5f42019-03-12 14:40:42 -070014101 val = get_param(cmd, "TWT_Setup");
14102 if (val) {
14103 if (strcasecmp(val, "Request") == 0) {
14104 if (sta_twt_request(dut, conn, cmd)) {
14105 send_resp(dut, conn, SIGMA_ERROR,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070014106 "ErrorCode,TWT setup failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014107 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070014108 }
14109 } else if (strcasecmp(val, "Teardown") == 0) {
14110 if (sta_twt_teardown(dut, conn, cmd)) {
14111 send_resp(dut, conn, SIGMA_ERROR,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070014112 "ErrorCode,TWT teardown failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014113 return STATUS_SENT_ERROR;
Arif Hussain480d5f42019-03-12 14:40:42 -070014114 }
14115 }
14116 }
14117
Srinivas Girigowda6707f032020-10-26 15:24:46 -070014118 val = get_param(cmd, "TWT_Operation");
14119 if (val) {
14120 if (strcasecmp(val, "Suspend") == 0) {
14121 if (sta_twt_suspend_or_nudge(dut, conn, cmd)) {
14122 send_resp(dut, conn, SIGMA_ERROR,
14123 "ErrorCode,TWT suspend failed");
14124 return STATUS_SENT_ERROR;
14125 }
14126 } else if (strcasecmp(val, "Resume") == 0) {
14127 if (sta_twt_resume(dut, conn, cmd)) {
14128 send_resp(dut, conn, SIGMA_ERROR,
14129 "ErrorCode,TWT resume failed");
14130 return STATUS_SENT_ERROR;
14131 }
14132 }
14133 }
14134
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080014135 val = get_param(cmd, "transmitOMI");
14136 if (val && sta_transmit_omi(dut, conn, cmd)) {
14137 send_resp(dut, conn, SIGMA_ERROR,
14138 "ErrorCode,sta_transmit_omi failed");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014139 return STATUS_SENT_ERROR;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070014140 }
14141
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014142 val = get_param(cmd, "Powersave");
14143 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014144 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014145
14146 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014147 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014148 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014149 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014150 } else {
14151 sigma_dut_print(dut, DUT_MSG_ERROR,
14152 "Unsupported Powersave value '%s'",
14153 val);
Jouni Malinen1702fe32021-06-08 19:08:01 +030014154 return INVALID_SEND_STATUS;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014155 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014156 if (set_power_save_wcn(dut, intf, ps) < 0)
Jouni Malinen1702fe32021-06-08 19:08:01 +030014157 return ERROR_SEND_STATUS;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080014158 }
14159
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080014160 val = get_param(cmd, "MU_EDCA");
14161 if (val) {
14162 if (strcasecmp(val, "Override") == 0) {
14163 if (sta_set_mu_edca_override(dut, intf, 1)) {
14164 send_resp(dut, conn, SIGMA_ERROR,
14165 "errorCode,MU EDCA override set failed");
14166 return STATUS_SENT;
14167 }
14168 } else if (strcasecmp(val, "Disable") == 0) {
14169 if (sta_set_mu_edca_override(dut, intf, 0)) {
14170 send_resp(dut, conn, SIGMA_ERROR,
14171 "errorCode,MU EDCA override disable failed");
14172 return STATUS_SENT;
14173 }
14174 }
14175 }
14176
Kiran Kumar Lokerefa7c7b92021-08-09 00:50:55 -070014177 val = get_param(cmd, "RUAllocTone");
14178 if (val && strcasecmp(val, "242") == 0) {
14179 if (sta_set_ru_242_tone_tx(dut, intf, 1)) {
14180 send_resp(dut, conn, SIGMA_ERROR,
14181 "ErrorCode,Failed to set RU 242 tone Tx");
14182 return STATUS_SENT_ERROR;
14183 }
14184 }
14185
14186 val = get_param(cmd, "PPDUTxType");
14187 if (val && strcasecmp(val, "ER-SU") == 0) {
14188 if (sta_set_er_su_ppdu_type_tx(dut, intf, 1)) {
14189 send_resp(dut, conn, SIGMA_ERROR,
14190 "ErrorCode,Failed to set ER-SU PPDU type Tx");
14191 return STATUS_SENT_ERROR;
14192 }
14193 }
14194
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -070014195 val = get_param(cmd, "Ch_Pref");
14196 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
14197 return STATUS_SENT;
14198
14199 val = get_param(cmd, "Cellular_Data_Cap");
14200 if (val && mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
14201 return STATUS_SENT;
14202
Jouni Malinen1702fe32021-06-08 19:08:01 +030014203 return SUCCESS_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014204
14205failed:
14206 free(token);
Jouni Malinen1702fe32021-06-08 19:08:01 +030014207 return ERROR_SEND_STATUS;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014208}
14209
14210
Jouni Malinen1702fe32021-06-08 19:08:01 +030014211static enum sigma_cmd_result
14212cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
14213 struct sigma_conn *conn, struct sigma_cmd *cmd)
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014214{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014215 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014216 case DRIVER_WCN:
14217 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
14218 default:
14219 send_resp(dut, conn, SIGMA_ERROR,
14220 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
Jouni Malinen1702fe32021-06-08 19:08:01 +030014221 return STATUS_SENT_ERROR;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014222 }
14223}
14224
14225
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014226static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
14227 struct sigma_conn *conn,
14228 struct sigma_cmd *cmd)
14229{
14230 const char *val;
14231
14232 val = get_param(cmd, "powersave");
14233 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014234 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014235
14236 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014237 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014238 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014239 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014240 } else {
14241 sigma_dut_print(dut, DUT_MSG_ERROR,
14242 "Unsupported power save config");
14243 return -1;
14244 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053014245 if (set_power_save_wcn(dut, intf, ps) < 0)
14246 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080014247 return 1;
14248 }
14249
14250 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
14251
14252 return 0;
14253}
14254
14255
Ashwini Patil5acd7382017-04-13 15:55:04 +053014256static int btm_query_candidate_list(struct sigma_dut *dut,
14257 struct sigma_conn *conn,
14258 struct sigma_cmd *cmd)
14259{
14260 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
14261 int len, ret;
14262 char buf[10];
14263
14264 /*
14265 * Neighbor Report elements format:
14266 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
14267 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
14268 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
14269 */
14270
14271 bssid = get_param(cmd, "Nebor_BSSID");
14272 if (!bssid) {
14273 send_resp(dut, conn, SIGMA_INVALID,
14274 "errorCode,Nebor_BSSID is missing");
14275 return 0;
14276 }
14277
14278 info = get_param(cmd, "Nebor_Bssid_Info");
14279 if (!info) {
14280 sigma_dut_print(dut, DUT_MSG_INFO,
14281 "Using default value for Nebor_Bssid_Info: %s",
14282 DEFAULT_NEIGHBOR_BSSID_INFO);
14283 info = DEFAULT_NEIGHBOR_BSSID_INFO;
14284 }
14285
14286 op_class = get_param(cmd, "Nebor_Op_Class");
14287 if (!op_class) {
14288 send_resp(dut, conn, SIGMA_INVALID,
14289 "errorCode,Nebor_Op_Class is missing");
14290 return 0;
14291 }
14292
14293 ch = get_param(cmd, "Nebor_Op_Ch");
14294 if (!ch) {
14295 send_resp(dut, conn, SIGMA_INVALID,
14296 "errorCode,Nebor_Op_Ch is missing");
14297 return 0;
14298 }
14299
14300 phy_type = get_param(cmd, "Nebor_Phy_Type");
14301 if (!phy_type) {
14302 sigma_dut_print(dut, DUT_MSG_INFO,
14303 "Using default value for Nebor_Phy_Type: %s",
14304 DEFAULT_NEIGHBOR_PHY_TYPE);
14305 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
14306 }
14307
14308 /* Parse optional subelements */
14309 buf[0] = '\0';
14310 pref = get_param(cmd, "Nebor_Pref");
14311 if (pref) {
14312 /* hexdump for preferrence subelement */
14313 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
14314 if (ret < 0 || ret >= (int) sizeof(buf)) {
14315 sigma_dut_print(dut, DUT_MSG_ERROR,
14316 "snprintf failed for optional subelement ret: %d",
14317 ret);
14318 send_resp(dut, conn, SIGMA_ERROR,
14319 "errorCode,snprintf failed for subelement");
14320 return 0;
14321 }
14322 }
14323
14324 if (!dut->btm_query_cand_list) {
14325 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
14326 if (!dut->btm_query_cand_list) {
14327 send_resp(dut, conn, SIGMA_ERROR,
14328 "errorCode,Failed to allocate memory for btm_query_cand_list");
14329 return 0;
14330 }
14331 }
14332
14333 len = strlen(dut->btm_query_cand_list);
14334 ret = snprintf(dut->btm_query_cand_list + len,
14335 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
14336 bssid, info, op_class, ch, phy_type, buf);
14337 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
14338 sigma_dut_print(dut, DUT_MSG_ERROR,
14339 "snprintf failed for neighbor report list ret: %d",
14340 ret);
14341 send_resp(dut, conn, SIGMA_ERROR,
14342 "errorCode,snprintf failed for neighbor report");
14343 free(dut->btm_query_cand_list);
14344 dut->btm_query_cand_list = NULL;
14345 return 0;
14346 }
14347
14348 return 1;
14349}
14350
14351
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014352int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
14353 struct sigma_ese_alloc *allocs, int *allocs_size)
14354{
14355 int max_count = *allocs_size;
14356 int count = 0, i;
14357 const char *val;
14358
14359 do {
14360 val = get_param_indexed(cmd, "AllocID", count);
14361 if (val)
14362 count++;
14363 } while (val);
14364
14365 if (count == 0 || count > max_count) {
14366 sigma_dut_print(dut, DUT_MSG_ERROR,
14367 "Invalid number of allocations(%d)", count);
14368 return -1;
14369 }
14370
14371 for (i = 0; i < count; i++) {
14372 val = get_param_indexed(cmd, "PercentBI", i);
14373 if (!val) {
14374 sigma_dut_print(dut, DUT_MSG_ERROR,
14375 "Missing PercentBI parameter at index %d",
14376 i);
14377 return -1;
14378 }
14379 allocs[i].percent_bi = atoi(val);
14380
14381 val = get_param_indexed(cmd, "SrcAID", i);
14382 if (val)
14383 allocs[i].src_aid = strtol(val, NULL, 0);
14384 else
14385 allocs[i].src_aid = ESE_BCAST_AID;
14386
14387 val = get_param_indexed(cmd, "DestAID", i);
14388 if (val)
14389 allocs[i].dst_aid = strtol(val, NULL, 0);
14390 else
14391 allocs[i].dst_aid = ESE_BCAST_AID;
14392
14393 allocs[i].type = ESE_CBAP;
14394 sigma_dut_print(dut, DUT_MSG_INFO,
14395 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
14396 i, allocs[i].percent_bi, allocs[i].src_aid,
14397 allocs[i].dst_aid);
14398 }
14399
14400 *allocs_size = count;
14401 return 0;
14402}
14403
14404
14405static int sta_set_60g_ese(struct sigma_dut *dut, int count,
14406 struct sigma_ese_alloc *allocs)
14407{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014408 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014409#ifdef __linux__
14410 case DRIVER_WIL6210:
14411 if (wil6210_set_ese(dut, count, allocs))
14412 return -1;
14413 return 1;
14414#endif /* __linux__ */
14415 default:
14416 sigma_dut_print(dut, DUT_MSG_ERROR,
14417 "Unsupported sta_set_60g_ese with the current driver");
14418 return -1;
14419 }
14420}
14421
14422
14423static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
14424 struct sigma_conn *conn,
14425 struct sigma_cmd *cmd)
14426{
14427 const char *val;
14428
14429 val = get_param(cmd, "ExtSchIE");
14430 if (val && !strcasecmp(val, "Enable")) {
14431 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
14432 int count = MAX_ESE_ALLOCS;
14433
14434 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
14435 return -1;
14436 return sta_set_60g_ese(dut, count, allocs);
14437 }
14438
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020014439 val = get_param(cmd, "MCS_FixedRate");
14440 if (val) {
14441 int sta_mcs = atoi(val);
14442
14443 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
14444 sta_mcs);
14445 wil6210_set_force_mcs(dut, 1, sta_mcs);
14446
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014447 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020014448 }
14449
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014450 send_resp(dut, conn, SIGMA_ERROR,
14451 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014452 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014453}
14454
14455
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053014456static int wcn_sta_override_oci(struct sigma_dut *dut, const char *intf,
14457 const char *oci_frametype, uint32_t oci_freq)
14458{
14459#ifdef NL80211_SUPPORT
14460 struct nl_msg *msg;
14461 int ret = 0;
14462 struct nlattr *params;
14463 struct nlattr *attr;
14464 int ifindex;
14465 u8 frame_type;
14466
14467 ifindex = if_nametoindex(intf);
14468 if (ifindex == 0) {
14469 sigma_dut_print(dut, DUT_MSG_ERROR,
14470 "%s: Index for interface %s failed",
14471 __func__, intf);
14472 return -1;
14473 }
14474
14475 if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
14476 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_REQ;
14477 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
14478 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_RESP;
14479 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
14480 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_FT_REASSOC_REQ;
14481 } else {
14482 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: Unknown frametype %s",
14483 __func__, oci_frametype);
14484 return -1;
14485 }
14486
14487
14488 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
14489 NL80211_CMD_VENDOR)) ||
14490 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
14491 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
14492 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
14493 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
14494 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
14495 !(params = nla_nest_start(
14496 msg,
14497 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OCI_OVERRIDE)) ||
14498 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FRAME_TYPE,
14499 frame_type) ||
14500 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FREQUENCY,
14501 oci_freq)) {
14502 sigma_dut_print(dut, DUT_MSG_ERROR,
14503 "%s: err in adding vendor_cmd and vendor_data",
14504 __func__);
14505 nlmsg_free(msg);
14506 return -1;
14507 }
14508 nla_nest_end(msg, params);
14509 nla_nest_end(msg, attr);
14510
14511 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
14512 if (ret) {
14513 sigma_dut_print(dut, DUT_MSG_ERROR,
14514 "%s: err in send_and_recv_msgs, ret=%d",
14515 __func__, ret);
14516 }
14517 return ret;
14518#else /* NL80211_SUPPORT */
14519 sigma_dut_print(dut, DUT_MSG_ERROR,
14520 "OCI override not possible without NL80211_SUPPORT defined");
14521 return -1;
14522#endif /* NL80211_SUPPORT */
14523}
14524
14525
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053014526static int wcn_sta_ignore_csa(struct sigma_dut *dut, const char *intf,
14527 uint8_t ignore_csa)
14528{
14529#ifdef NL80211_SUPPORT
14530 return wcn_wifi_test_config_set_u8(
14531 dut, intf,
14532 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_CSA, ignore_csa);
14533#else /* NL80211_SUPPORT */
14534 sigma_dut_print(dut, DUT_MSG_ERROR,
14535 "IgnoreCSA can't be set without NL80211_SUPPORT defined");
14536 return -1;
14537#endif /* NL80211_SUPPORT */
14538}
14539
14540
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053014541static int wcn_sta_set_rsnxe_used(struct sigma_dut *dut, const char *intf,
14542 uint8_t rsnxe_used)
14543{
14544#ifdef NL80211_SUPPORT
14545 return wcn_wifi_test_config_set_u8(
14546 dut, intf,
14547 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FT_REASSOCREQ_RSNXE_USED,
14548 rsnxe_used);
14549#else /* NL80211_SUPPORT */
14550 sigma_dut_print(dut, DUT_MSG_ERROR,
14551 "RSNXE_Used can't be set without NL80211_SUPPORT defined");
14552 return -1;
14553#endif /* NL80211_SUPPORT */
14554}
14555
14556
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053014557static int wcn_sta_ignore_sa_query_timeout(struct sigma_dut *dut,
14558 const char *intf,
14559 uint8_t ignore_sa_query_timeout)
14560{
14561#ifdef NL80211_SUPPORT
14562 return wcn_wifi_test_config_set_u8(
14563 dut, intf,
14564 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_SA_QUERY_TIMEOUT,
14565 ignore_sa_query_timeout);
14566#else /* NL80211_SUPPORT */
14567 sigma_dut_print(dut, DUT_MSG_ERROR,
14568 "Ignore SA Query timeout can't be set without NL80211_SUPPORT defined");
14569 return -1;
14570#endif /* NL80211_SUPPORT */
14571}
14572
14573
Jouni Malinen6250cb02020-04-15 13:54:45 +030014574static enum sigma_cmd_result
14575cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
14576 struct sigma_conn *conn,
14577 struct sigma_cmd *cmd)
14578{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014579 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030014580
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053014581 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030014582 if (val && atoi(val) == 1) {
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053014583 if (wifi_chip_type == DRIVER_WCN) {
14584 if (wcn_sta_set_rsnxe_used(dut, intf, 1)) {
14585 send_resp(dut, conn, SIGMA_ERROR,
14586 "errorCode,Failed to set ft_rsnxe_used");
14587 return STATUS_SENT_ERROR;
14588 }
14589 return SUCCESS_SEND_STATUS;
14590 } else if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
Jouni Malinen6250cb02020-04-15 13:54:45 +030014591 send_resp(dut, conn, SIGMA_ERROR,
14592 "errorCode,Failed to set ft_rsnxe_used");
14593 return STATUS_SENT_ERROR;
14594 }
14595 return SUCCESS_SEND_STATUS;
14596 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014597
14598 oci_chan = get_param(cmd, "OCIChannel");
14599 oci_frametype = get_param(cmd, "OCIFrameType");
14600 if (oci_chan && oci_frametype) {
14601 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
14602 char buf[100];
14603
14604 if (!oci_freq) {
14605 send_resp(dut, conn, SIGMA_ERROR,
14606 "errorCode,Invalid OCIChannel number");
14607 return STATUS_SENT_ERROR;
14608 }
14609
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053014610 if (wifi_chip_type == DRIVER_WCN &&
14611 (strcasecmp(oci_frametype, "SAQueryReq") == 0 ||
14612 strcasecmp(oci_frametype, "SAQueryResp") == 0 ||
14613 strcasecmp(oci_frametype, "Reassocreq") == 0)) {
14614 if (wcn_sta_override_oci(dut, intf, oci_frametype,
14615 oci_freq)) {
14616 send_resp(dut, conn, SIGMA_ERROR,
14617 "errorCode,Failed to override OCI");
14618 return STATUS_SENT_ERROR;
14619 }
14620 return SUCCESS_SEND_STATUS;
14621 }
14622
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014623 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
14624 snprintf(buf, sizeof(buf),
14625 "SET oci_freq_override_eapol %d", oci_freq);
14626 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
14627 snprintf(buf, sizeof(buf),
14628 "SET oci_freq_override_saquery_req %d",
14629 oci_freq);
14630 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
14631 snprintf(buf, sizeof(buf),
14632 "SET oci_freq_override_saquery_resp %d",
14633 oci_freq);
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053014634 } else if (strcasecmp(oci_frametype, "GrpKeyM2") == 0) {
14635 snprintf(buf, sizeof(buf),
14636 "SET oci_freq_override_eapol_g2 %d",
14637 oci_freq);
14638 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
14639 snprintf(buf, sizeof(buf),
14640 "SET oci_freq_override_ft_assoc %d",
14641 oci_freq);
Vamsi Krishnad29bc762020-05-08 23:23:30 +053014642 } else {
14643 send_resp(dut, conn, SIGMA_ERROR,
14644 "errorCode,Unsupported OCIFrameType");
14645 return STATUS_SENT_ERROR;
14646 }
14647 if (wpa_command(intf, buf) < 0) {
14648 send_resp(dut, conn, SIGMA_ERROR,
14649 "errorCode,Failed to set oci_freq_override");
14650 return STATUS_SENT_ERROR;
14651 }
14652 return SUCCESS_SEND_STATUS;
14653 }
14654
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053014655 val = get_param(cmd, "IgnoreCSA");
14656 if (val && atoi(val) == 1) {
14657 if (wifi_chip_type == DRIVER_WCN) {
14658 if (wcn_sta_ignore_csa(dut, intf, 1)) {
14659 send_resp(dut, conn, SIGMA_ERROR,
14660 "errorCode,Failed to set ignore CSA");
14661 return STATUS_SENT_ERROR;
14662 }
14663 return SUCCESS_SEND_STATUS;
14664 }
14665 }
14666
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053014667 val = get_param(cmd, "Deauth_Per_SAQueryResp");
14668 if (val && atoi(val) == 0) {
14669 if (wifi_chip_type == DRIVER_WCN) {
14670 if (wcn_sta_ignore_sa_query_timeout(dut, intf, 1)) {
14671 send_resp(dut, conn, SIGMA_ERROR,
14672 "errorCode,Failed to set ignore SA Query timeout");
14673 return STATUS_SENT_ERROR;
14674 }
14675 return SUCCESS_SEND_STATUS;
14676 }
14677 }
14678
Jouni Malinen6250cb02020-04-15 13:54:45 +030014679 send_resp(dut, conn, SIGMA_ERROR,
14680 "errorCode,Unsupported WPA3 rfeature");
14681 return STATUS_SENT_ERROR;
14682}
14683
14684
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053014685static enum sigma_cmd_result
14686cmd_sta_set_rfeature_qm(const char *intf, struct sigma_dut *dut,
14687 struct sigma_conn *conn, struct sigma_cmd *cmd)
14688{
14689 const char *val;
14690
14691 val = get_param(cmd, "DomainName_Domain");
14692 if (val) {
14693 if (strlen(val) >= sizeof(dut->qm_domain_name))
14694 return ERROR_SEND_STATUS;
14695
14696 strlcpy(dut->qm_domain_name, val, sizeof(dut->qm_domain_name));
14697 return SUCCESS_SEND_STATUS;
14698 }
14699
14700 send_resp(dut, conn, SIGMA_ERROR,
14701 "errorCode,Unsupported QM rfeature");
14702 return STATUS_SENT_ERROR;
14703}
14704
14705
Jouni Malinenf7222712019-06-13 01:50:21 +030014706static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
14707 struct sigma_conn *conn,
14708 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014709{
14710 const char *intf = get_param(cmd, "Interface");
14711 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053014712 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014713
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053014714 if (!prog)
14715 prog = get_param(cmd, "Program");
14716
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014717 if (intf == NULL || prog == NULL)
14718 return -1;
14719
Ashwini Patil5acd7382017-04-13 15:55:04 +053014720 /* BSS Transition candidate list for BTM query */
14721 val = get_param(cmd, "Nebor_BSSID");
14722 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
14723 return 0;
14724
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014725 if (strcasecmp(prog, "TDLS") == 0)
14726 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
14727
14728 if (strcasecmp(prog, "VHT") == 0)
14729 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
14730
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080014731 if (strcasecmp(prog, "HE") == 0)
14732 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
14733
Ashwini Patil68d02cd2017-01-10 15:39:16 +053014734 if (strcasecmp(prog, "MBO") == 0) {
14735 val = get_param(cmd, "Cellular_Data_Cap");
14736 if (val &&
14737 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
14738 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053014739
14740 val = get_param(cmd, "Ch_Pref");
14741 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
14742 return 0;
14743
Ashwini Patil68d02cd2017-01-10 15:39:16 +053014744 return 1;
14745 }
14746
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020014747 if (strcasecmp(prog, "60GHz") == 0)
14748 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
14749
Jouni Malinen6250cb02020-04-15 13:54:45 +030014750 if (strcasecmp(prog, "WPA3") == 0)
14751 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
Veerendranath Jakkam329a3cd2021-09-11 18:10:13 +053014752 if (strcasecmp(prog, "QM") == 0)
14753 return cmd_sta_set_rfeature_qm(intf, dut, conn, cmd);
Jouni Malinen6250cb02020-04-15 13:54:45 +030014754
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014755 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
14756 return 0;
14757}
14758
14759
Jouni Malinenf7222712019-06-13 01:50:21 +030014760static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
14761 struct sigma_conn *conn,
14762 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014763{
14764 const char *intf = get_param(cmd, "Interface");
14765 const char *mode = get_param(cmd, "Mode");
14766 int res;
14767
14768 if (intf == NULL || mode == NULL)
14769 return -1;
14770
14771 if (strcasecmp(mode, "On") == 0)
14772 res = wpa_command(intf, "SET radio_disabled 0");
14773 else if (strcasecmp(mode, "Off") == 0)
14774 res = wpa_command(intf, "SET radio_disabled 1");
14775 else
14776 return -1;
14777
14778 if (res) {
14779 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
14780 "radio mode");
14781 return 0;
14782 }
14783
14784 return 1;
14785}
14786
14787
Jouni Malinenf7222712019-06-13 01:50:21 +030014788static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
14789 struct sigma_conn *conn,
14790 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014791{
14792 const char *intf = get_param(cmd, "Interface");
14793 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014794 const char *prog = get_param(cmd, "program");
14795 const char *powersave = get_param(cmd, "powersave");
14796 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014797
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014798 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014799 return -1;
14800
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014801 if (prog && strcasecmp(prog, "60GHz") == 0) {
14802 /*
14803 * The CAPI mode parameter does not exist in 60G
14804 * unscheduled PS.
14805 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080014806 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014807 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014808 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020014809 strcasecmp(prog, "HE") == 0) {
14810 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014811 } else {
14812 if (mode == NULL)
14813 return -1;
14814
14815 if (strcasecmp(mode, "On") == 0)
14816 res = set_ps(intf, dut, 1);
14817 else if (strcasecmp(mode, "Off") == 0)
14818 res = set_ps(intf, dut, 0);
14819 else
14820 return -1;
14821 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014822
14823 if (res) {
14824 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
14825 "power save mode");
14826 return 0;
14827 }
14828
14829 return 1;
14830}
14831
14832
Jouni Malinenf7222712019-06-13 01:50:21 +030014833static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
14834 struct sigma_conn *conn,
14835 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014836{
14837 const char *intf = get_param(cmd, "Interface");
14838 const char *val, *bssid;
14839 int res;
14840 char *buf;
14841 size_t buf_len;
14842
14843 val = get_param(cmd, "BSSID_FILTER");
14844 if (val == NULL)
14845 return -1;
14846
14847 bssid = get_param(cmd, "BSSID_List");
14848 if (atoi(val) == 0 || bssid == NULL) {
14849 /* Disable BSSID filter */
14850 if (wpa_command(intf, "SET bssid_filter ")) {
14851 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
14852 "to disable BSSID filter");
14853 return 0;
14854 }
14855
14856 return 1;
14857 }
14858
14859 buf_len = 100 + strlen(bssid);
14860 buf = malloc(buf_len);
14861 if (buf == NULL)
14862 return -1;
14863
14864 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
14865 res = wpa_command(intf, buf);
14866 free(buf);
14867 if (res) {
14868 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
14869 "BSSID filter");
14870 return 0;
14871 }
14872
14873 return 1;
14874}
14875
14876
Jouni Malinenf7222712019-06-13 01:50:21 +030014877static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
14878 struct sigma_conn *conn,
14879 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014880{
14881 const char *intf = get_param(cmd, "Interface");
14882 const char *val;
14883
14884 /* TODO: ARP */
14885
14886 val = get_param(cmd, "HS2_CACHE_PROFILE");
14887 if (val && strcasecmp(val, "All") == 0)
14888 hs2_clear_credentials(intf);
14889
14890 return 1;
14891}
14892
14893
Jouni Malinenf7222712019-06-13 01:50:21 +030014894static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
14895 struct sigma_conn *conn,
14896 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014897{
14898 const char *intf = get_param(cmd, "Interface");
14899 const char *key_type = get_param(cmd, "KeyType");
14900 char buf[100], resp[200];
14901
14902 if (key_type == NULL)
14903 return -1;
14904
14905 if (strcasecmp(key_type, "GTK") == 0) {
14906 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
14907 strncmp(buf, "FAIL", 4) == 0) {
14908 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
14909 "not fetch current GTK");
14910 return 0;
14911 }
14912 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
14913 send_resp(dut, conn, SIGMA_COMPLETE, resp);
14914 return 0;
14915 } else {
14916 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
14917 "KeyType");
14918 return 0;
14919 }
14920
14921 return 1;
14922}
14923
14924
14925static int hs2_set_policy(struct sigma_dut *dut)
14926{
14927#ifdef ANDROID
14928 system("ip rule del prio 23000");
14929 if (system("ip rule add from all lookup main prio 23000") != 0) {
14930 sigma_dut_print(dut, DUT_MSG_ERROR,
14931 "Failed to run:ip rule add from all lookup main prio");
14932 return -1;
14933 }
14934 if (system("ip route flush cache") != 0) {
14935 sigma_dut_print(dut, DUT_MSG_ERROR,
14936 "Failed to run ip route flush cache");
14937 return -1;
14938 }
14939 return 1;
14940#else /* ANDROID */
14941 return 0;
14942#endif /* ANDROID */
14943}
14944
14945
Jouni Malinenf7222712019-06-13 01:50:21 +030014946static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
14947 struct sigma_conn *conn,
14948 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014949{
14950 const char *intf = get_param(cmd, "Interface");
14951 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030014952 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014953 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030014954 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014955 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
14956 int tries = 0;
14957 int ignore_blacklist = 0;
14958 const char *events[] = {
14959 "CTRL-EVENT-CONNECTED",
14960 "INTERWORKING-BLACKLISTED",
14961 "INTERWORKING-NO-MATCH",
14962 NULL
14963 };
14964
14965 start_sta_mode(dut);
14966
Jouni Malinen439352d2018-09-13 03:42:23 +030014967 if (band) {
14968 if (strcmp(band, "2.4") == 0) {
14969 wpa_command(intf, "SET setband 2G");
14970 } else if (strcmp(band, "5") == 0) {
14971 wpa_command(intf, "SET setband 5G");
14972 } else {
14973 send_resp(dut, conn, SIGMA_ERROR,
14974 "errorCode,Unsupported band");
14975 return 0;
14976 }
14977 }
14978
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014979 blacklisted[0] = '\0';
14980 if (val && atoi(val))
14981 ignore_blacklist = 1;
14982
14983try_again:
14984 ctrl = open_wpa_mon(intf);
14985 if (ctrl == NULL) {
14986 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14987 "wpa_supplicant monitor connection");
14988 return -2;
14989 }
14990
14991 tries++;
14992 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
14993 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
14994 "Interworking connection");
14995 wpa_ctrl_detach(ctrl);
14996 wpa_ctrl_close(ctrl);
14997 return 0;
14998 }
14999
15000 buf[0] = '\0';
15001 while (1) {
15002 char *pos;
15003 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
15004 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
15005 if (!pos)
15006 break;
15007 pos += 25;
15008 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
15009 pos);
15010 if (!blacklisted[0])
15011 memcpy(blacklisted, pos, strlen(pos) + 1);
15012 }
15013
15014 if (ignore_blacklist && blacklisted[0]) {
15015 char *end;
15016 end = strchr(blacklisted, ' ');
15017 if (end)
15018 *end = '\0';
15019 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
15020 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030015021 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
15022 blacklisted);
15023 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015024 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
15025 wpa_ctrl_detach(ctrl);
15026 wpa_ctrl_close(ctrl);
15027 return 0;
15028 }
15029 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
15030 buf, sizeof(buf));
15031 }
15032
15033 wpa_ctrl_detach(ctrl);
15034 wpa_ctrl_close(ctrl);
15035
15036 if (res < 0) {
15037 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
15038 "connect");
15039 return 0;
15040 }
15041
15042 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
15043 strstr(buf, "INTERWORKING-BLACKLISTED")) {
15044 if (tries < 2) {
15045 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
15046 goto try_again;
15047 }
15048 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
15049 "matching credentials found");
15050 return 0;
15051 }
15052
15053 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
15054 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
15055 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
15056 "get current BSSID/SSID");
15057 return 0;
15058 }
15059
15060 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
15061 send_resp(dut, conn, SIGMA_COMPLETE, resp);
15062 hs2_set_policy(dut);
15063 return 0;
15064}
15065
15066
Jouni Malinenf7222712019-06-13 01:50:21 +030015067static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
15068 struct sigma_conn *conn,
15069 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030015070{
15071 const char *intf = get_param(cmd, "Interface");
15072 const char *display = get_param(cmd, "Display");
15073 struct wpa_ctrl *ctrl;
15074 char buf[300], params[400], *pos;
15075 char bssid[20];
15076 int info_avail = 0;
15077 unsigned int old_timeout;
15078 int res;
15079
15080 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
15081 send_resp(dut, conn, SIGMA_ERROR,
15082 "ErrorCode,Could not get current BSSID");
15083 return 0;
15084 }
15085 ctrl = open_wpa_mon(intf);
15086 if (!ctrl) {
15087 sigma_dut_print(dut, DUT_MSG_ERROR,
15088 "Failed to open wpa_supplicant monitor connection");
15089 return -2;
15090 }
15091
15092 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
15093 wpa_command(intf, buf);
15094
15095 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
15096 if (res < 0) {
15097 send_resp(dut, conn, SIGMA_ERROR,
15098 "ErrorCode,Could not complete GAS query");
15099 goto fail;
15100 }
15101
15102 old_timeout = dut->default_timeout;
15103 dut->default_timeout = 2;
15104 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
15105 dut->default_timeout = old_timeout;
15106 if (res < 0)
15107 goto done;
15108 pos = strchr(buf, ' ');
15109 if (!pos)
15110 goto done;
15111 pos++;
15112 pos = strchr(pos, ' ');
15113 if (!pos)
15114 goto done;
15115 pos++;
15116 info_avail = 1;
15117 snprintf(params, sizeof(params), "browser %s", pos);
15118
15119 if (display && strcasecmp(display, "Yes") == 0) {
15120 pid_t pid;
15121
15122 pid = fork();
15123 if (pid < 0) {
15124 perror("fork");
15125 return -1;
15126 }
15127
15128 if (pid == 0) {
15129 run_hs20_osu(dut, params);
15130 exit(0);
15131 }
15132 }
15133
15134done:
15135 snprintf(buf, sizeof(buf), "Info_available,%s",
15136 info_avail ? "Yes" : "No");
15137 send_resp(dut, conn, SIGMA_COMPLETE, buf);
15138fail:
15139 wpa_ctrl_detach(ctrl);
15140 wpa_ctrl_close(ctrl);
15141 return 0;
15142}
15143
15144
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015145static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
15146 struct sigma_conn *conn,
15147 const char *ifname,
15148 struct sigma_cmd *cmd)
15149{
15150 const char *val;
15151 int id;
15152
15153 id = add_cred(ifname);
15154 if (id < 0)
15155 return -2;
15156 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
15157
15158 val = get_param(cmd, "prefer");
15159 if (val && atoi(val) > 0)
15160 set_cred(ifname, id, "priority", "1");
15161
15162 val = get_param(cmd, "REALM");
15163 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
15164 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15165 "realm");
15166 return 0;
15167 }
15168
15169 val = get_param(cmd, "HOME_FQDN");
15170 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
15171 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15172 "home_fqdn");
15173 return 0;
15174 }
15175
15176 val = get_param(cmd, "Username");
15177 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
15178 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15179 "username");
15180 return 0;
15181 }
15182
15183 val = get_param(cmd, "Password");
15184 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
15185 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15186 "password");
15187 return 0;
15188 }
15189
15190 val = get_param(cmd, "ROOT_CA");
15191 if (val) {
15192 char fname[200];
15193 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
15194#ifdef __linux__
15195 if (!file_exists(fname)) {
15196 char msg[300];
15197 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
15198 "file (%s) not found", fname);
15199 send_resp(dut, conn, SIGMA_ERROR, msg);
15200 return 0;
15201 }
15202#endif /* __linux__ */
15203 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
15204 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15205 "not set root CA");
15206 return 0;
15207 }
15208 }
15209
15210 return 1;
15211}
15212
15213
15214static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
15215{
15216 FILE *in, *out;
15217 char buf[500];
15218 int found = 0;
15219
15220 in = fopen("devdetail.xml", "r");
15221 if (in == NULL)
15222 return -1;
15223 out = fopen("devdetail.xml.tmp", "w");
15224 if (out == NULL) {
15225 fclose(in);
15226 return -1;
15227 }
15228
15229 while (fgets(buf, sizeof(buf), in)) {
15230 char *pos = strstr(buf, "<IMSI>");
15231 if (pos) {
15232 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
15233 imsi);
15234 pos += 6;
15235 *pos = '\0';
15236 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
15237 found++;
15238 } else {
15239 fprintf(out, "%s", buf);
15240 }
15241 }
15242
15243 fclose(out);
15244 fclose(in);
15245 if (found)
15246 rename("devdetail.xml.tmp", "devdetail.xml");
15247 else
15248 unlink("devdetail.xml.tmp");
15249
15250 return 0;
15251}
15252
15253
15254static int sta_add_credential_sim(struct sigma_dut *dut,
15255 struct sigma_conn *conn,
15256 const char *ifname, struct sigma_cmd *cmd)
15257{
15258 const char *val, *imsi = NULL;
15259 int id;
15260 char buf[200];
15261 int res;
15262 const char *pos;
15263 size_t mnc_len;
15264 char plmn_mcc[4];
15265 char plmn_mnc[4];
15266
15267 id = add_cred(ifname);
15268 if (id < 0)
15269 return -2;
15270 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
15271
15272 val = get_param(cmd, "prefer");
15273 if (val && atoi(val) > 0)
15274 set_cred(ifname, id, "priority", "1");
15275
15276 val = get_param(cmd, "PLMN_MCC");
15277 if (val == NULL) {
15278 send_resp(dut, conn, SIGMA_ERROR,
15279 "errorCode,Missing PLMN_MCC");
15280 return 0;
15281 }
15282 if (strlen(val) != 3) {
15283 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
15284 return 0;
15285 }
15286 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
15287
15288 val = get_param(cmd, "PLMN_MNC");
15289 if (val == NULL) {
15290 send_resp(dut, conn, SIGMA_ERROR,
15291 "errorCode,Missing PLMN_MNC");
15292 return 0;
15293 }
15294 if (strlen(val) != 2 && strlen(val) != 3) {
15295 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
15296 return 0;
15297 }
15298 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
15299
15300 val = get_param(cmd, "IMSI");
15301 if (val == NULL) {
15302 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
15303 "IMSI");
15304 return 0;
15305 }
15306
15307 imsi = pos = val;
15308
15309 if (strncmp(plmn_mcc, pos, 3) != 0) {
15310 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
15311 return 0;
15312 }
15313 pos += 3;
15314
15315 mnc_len = strlen(plmn_mnc);
15316 if (mnc_len < 2) {
15317 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
15318 return 0;
15319 }
15320
15321 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
15322 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
15323 return 0;
15324 }
15325 pos += mnc_len;
15326
15327 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
15328 if (res < 0 || res >= (int) sizeof(buf))
15329 return -1;
15330 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
15331 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15332 "not set IMSI");
15333 return 0;
15334 }
15335
15336 val = get_param(cmd, "Password");
15337 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
15338 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15339 "not set password");
15340 return 0;
15341 }
15342
Jouni Malinenba630452018-06-22 11:49:59 +030015343 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015344 /*
15345 * Set provisioning_sp for the test cases where SIM/USIM
15346 * provisioning is used.
15347 */
15348 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
15349 "wi-fi.org") < 0) {
15350 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15351 "not set provisioning_sp");
15352 return 0;
15353 }
15354
15355 update_devdetail_imsi(dut, imsi);
15356 }
15357
15358 return 1;
15359}
15360
15361
15362static int sta_add_credential_cert(struct sigma_dut *dut,
15363 struct sigma_conn *conn,
15364 const char *ifname,
15365 struct sigma_cmd *cmd)
15366{
15367 const char *val;
15368 int id;
15369
15370 id = add_cred(ifname);
15371 if (id < 0)
15372 return -2;
15373 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
15374
15375 val = get_param(cmd, "prefer");
15376 if (val && atoi(val) > 0)
15377 set_cred(ifname, id, "priority", "1");
15378
15379 val = get_param(cmd, "REALM");
15380 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
15381 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15382 "realm");
15383 return 0;
15384 }
15385
15386 val = get_param(cmd, "HOME_FQDN");
15387 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
15388 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15389 "home_fqdn");
15390 return 0;
15391 }
15392
15393 val = get_param(cmd, "Username");
15394 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
15395 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
15396 "username");
15397 return 0;
15398 }
15399
15400 val = get_param(cmd, "clientCertificate");
15401 if (val) {
15402 char fname[200];
15403 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
15404#ifdef __linux__
15405 if (!file_exists(fname)) {
15406 char msg[300];
15407 snprintf(msg, sizeof(msg),
15408 "ErrorCode,clientCertificate "
15409 "file (%s) not found", fname);
15410 send_resp(dut, conn, SIGMA_ERROR, msg);
15411 return 0;
15412 }
15413#endif /* __linux__ */
15414 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
15415 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15416 "not set client_cert");
15417 return 0;
15418 }
15419 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
15420 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15421 "not set private_key");
15422 return 0;
15423 }
15424 }
15425
15426 val = get_param(cmd, "ROOT_CA");
15427 if (val) {
15428 char fname[200];
15429 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
15430#ifdef __linux__
15431 if (!file_exists(fname)) {
15432 char msg[300];
15433 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
15434 "file (%s) not found", fname);
15435 send_resp(dut, conn, SIGMA_ERROR, msg);
15436 return 0;
15437 }
15438#endif /* __linux__ */
15439 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
15440 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
15441 "not set root CA");
15442 return 0;
15443 }
15444 }
15445
15446 return 1;
15447}
15448
15449
Jouni Malinenf7222712019-06-13 01:50:21 +030015450static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
15451 struct sigma_conn *conn,
15452 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015453{
15454 const char *intf = get_param(cmd, "Interface");
15455 const char *type;
15456
15457 start_sta_mode(dut);
15458
15459 type = get_param(cmd, "Type");
15460 if (!type)
15461 return -1;
15462
15463 if (strcasecmp(type, "uname_pwd") == 0)
15464 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
15465
15466 if (strcasecmp(type, "sim") == 0)
15467 return sta_add_credential_sim(dut, conn, intf, cmd);
15468
15469 if (strcasecmp(type, "cert") == 0)
15470 return sta_add_credential_cert(dut, conn, intf, cmd);
15471
15472 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
15473 "type");
15474 return 0;
15475}
15476
15477
Jouni Malinenf7222712019-06-13 01:50:21 +030015478static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
15479 struct sigma_conn *conn,
15480 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015481{
15482 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015483 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Veerendranathdc581b52020-08-10 03:29:08 -070015484 char buf[4096], scan_res[20];
vamsi krishna89ad8c62017-09-19 12:51:18 +053015485 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080015486 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015487 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015488 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030015489 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015490
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020015491 start_sta_mode(dut);
15492
Arif Hussain66a4af02019-02-07 15:04:51 -080015493 val = get_param(cmd, "GetParameter");
15494 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015495 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080015496 buf, sizeof(buf)) < 0) {
15497 sigma_dut_print(dut, DUT_MSG_ERROR,
15498 "Could not get ssid bssid");
15499 return ERROR_SEND_STATUS;
15500 }
15501
15502 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
15503 send_resp(dut, conn, SIGMA_COMPLETE, buf);
15504 return STATUS_SENT;
15505 }
15506
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015507 val = get_param(cmd, "HESSID");
15508 if (val) {
15509 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
15510 if (res < 0 || res >= (int) sizeof(buf))
15511 return -1;
15512 wpa_command(intf, buf);
15513 }
15514
15515 val = get_param(cmd, "ACCS_NET_TYPE");
15516 if (val) {
15517 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
15518 val);
15519 if (res < 0 || res >= (int) sizeof(buf))
15520 return -1;
15521 wpa_command(intf, buf);
15522 }
15523
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -070015524 if (get_param(cmd, "RxMac"))
15525 sta_set_scan_unicast_probe(dut, intf, 1);
15526
vamsi krishna89ad8c62017-09-19 12:51:18 +053015527 bssid = get_param(cmd, "Bssid");
15528 ssid = get_param(cmd, "Ssid");
Kiran Kumar Lokere69d89952021-08-08 23:41:46 -070015529 if (!bssid)
15530 bssid = get_param(cmd, "RxMac");
vamsi krishna89ad8c62017-09-19 12:51:18 +053015531
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080015532 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
15533 dut->device_type == STA_testbed) {
15534 ssid = NULL;
15535 wildcard_ssid = 1;
15536 }
15537
vamsi krishna89ad8c62017-09-19 12:51:18 +053015538 if (ssid) {
15539 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
15540 send_resp(dut, conn, SIGMA_ERROR,
15541 "ErrorCode,Too long SSID");
15542 return 0;
15543 }
15544 ascii2hexstr(ssid, ssid_hex);
15545 }
15546
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015547 short_ssid = get_param(cmd, "ShortSSID");
15548 if (short_ssid) {
15549 uint32_t short_ssid_hex;
15550
15551 short_ssid_hex = strtoul(short_ssid, NULL, 16);
15552 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
15553 (((short_ssid_hex >> 8) & 0xFF) << 16) |
15554 (((short_ssid_hex >> 16) & 0xFF) << 8) |
15555 ((short_ssid_hex >> 24) & 0xFF);
15556
15557 res = snprintf(buf, sizeof(buf),
15558 "VENDOR_ELEM_ADD 14 ff053a%08x",
15559 short_ssid_hex);
15560 if (res < 0 || res >= (int) sizeof(buf) ||
15561 wpa_command(intf, buf)) {
15562 send_resp(dut, conn, SIGMA_ERROR,
15563 "errorCode,Failed to add short SSID");
15564 return STATUS_SENT_ERROR;
15565 }
15566 }
15567
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015568 scan_freq = get_param(cmd, "ChnlFreq");
Veerendranath Jakkam132c4b42020-08-10 00:29:03 +053015569 if (scan_freq) {
15570 if (strcasecmp(scan_freq, "2G") == 0)
15571 scan_freq = "2412-2462";
15572 else if (strcasecmp(scan_freq, "5G") == 0)
15573 scan_freq = "5180-5925";
15574 }
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015575
Jouni Malinen228a2fc2020-06-22 23:37:45 +030015576 val = get_param(cmd, "WaitCompletion");
15577 if (val && atoi(val) == 1) {
15578 ctrl = open_wpa_mon(intf);
15579 if (!ctrl) {
15580 send_resp(dut, conn, SIGMA_ERROR,
15581 "errorCode,Failed to open monitor socket");
15582 return STATUS_SENT_ERROR;
15583 }
15584 }
15585
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015586 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053015587 bssid ? " bssid=": "",
15588 bssid ? bssid : "",
15589 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080015590 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080015591 wildcard_ssid ? " wildcard_ssid=1" : "",
15592 scan_freq ? " freq=" : "",
15593 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015594 if (res < 0 || res >= (int) sizeof(buf)) {
15595 send_resp(dut, conn, SIGMA_ERROR,
15596 "errorCode,Could not build scan command");
15597 status = STATUS_SENT_ERROR;
15598 goto remove_s_ssid;
15599 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053015600
Veerendranathdc581b52020-08-10 03:29:08 -070015601 res = wpa_command_resp(intf, buf, scan_res, sizeof(scan_res));
15602 if (strncmp(scan_res, "FAIL-BUSY", 9) == 0) {
15603 sigma_dut_print(dut, DUT_MSG_DEBUG,
15604 "Scan request rejected with busy status, abort ongoing scan and try again");
15605 wpa_command(intf, "ABORT_SCAN");
15606 res = wpa_command(intf, buf);
15607 }
15608
15609 if (res < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015610 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
15611 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015612 status = STATUS_SENT_ERROR;
15613 } else {
15614 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015615 }
15616
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015617remove_s_ssid:
15618 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
15619 sigma_dut_print(dut, DUT_MSG_ERROR,
15620 "Failed to delete vendor element");
15621
Jouni Malinen228a2fc2020-06-22 23:37:45 +030015622 if (ctrl) {
15623 if (status == SUCCESS_SEND_STATUS) {
15624 res = get_wpa_cli_event(dut, ctrl,
15625 "CTRL-EVENT-SCAN-RESULTS",
15626 buf, sizeof(buf));
15627 if (res < 0) {
15628 send_resp(dut, conn, SIGMA_ERROR,
15629 "ErrorCode,scan did not complete");
15630 status = STATUS_SENT_ERROR;
15631 }
15632 }
15633
15634 wpa_ctrl_detach(ctrl);
15635 wpa_ctrl_close(ctrl);
15636 }
15637
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080015638 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015639}
15640
15641
Jouni Malinenf7222712019-06-13 01:50:21 +030015642static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
15643 struct sigma_conn *conn,
15644 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020015645{
15646 const char *intf = get_param(cmd, "Interface");
15647 const char *bssid;
15648 char buf[4096], *pos;
15649 int freq, chan;
15650 char *ssid;
15651 char resp[100];
15652 int res;
15653 struct wpa_ctrl *ctrl;
15654
15655 bssid = get_param(cmd, "BSSID");
15656 if (!bssid) {
15657 send_resp(dut, conn, SIGMA_INVALID,
15658 "errorCode,BSSID argument is missing");
15659 return 0;
15660 }
15661
15662 ctrl = open_wpa_mon(intf);
15663 if (!ctrl) {
15664 sigma_dut_print(dut, DUT_MSG_ERROR,
15665 "Failed to open wpa_supplicant monitor connection");
15666 return -1;
15667 }
15668
15669 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
15670 send_resp(dut, conn, SIGMA_ERROR,
15671 "errorCode,Could not start scan");
15672 wpa_ctrl_detach(ctrl);
15673 wpa_ctrl_close(ctrl);
15674 return 0;
15675 }
15676
15677 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
15678 buf, sizeof(buf));
15679
15680 wpa_ctrl_detach(ctrl);
15681 wpa_ctrl_close(ctrl);
15682
15683 if (res < 0) {
15684 send_resp(dut, conn, SIGMA_ERROR,
15685 "errorCode,Scan did not complete");
15686 return 0;
15687 }
15688
15689 snprintf(buf, sizeof(buf), "BSS %s", bssid);
15690 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
15691 strncmp(buf, "id=", 3) != 0) {
15692 send_resp(dut, conn, SIGMA_ERROR,
15693 "errorCode,Specified BSSID not found");
15694 return 0;
15695 }
15696
15697 pos = strstr(buf, "\nfreq=");
15698 if (!pos) {
15699 send_resp(dut, conn, SIGMA_ERROR,
15700 "errorCode,Channel not found");
15701 return 0;
15702 }
15703 freq = atoi(pos + 6);
15704 chan = freq_to_channel(freq);
15705
15706 pos = strstr(buf, "\nssid=");
15707 if (!pos) {
15708 send_resp(dut, conn, SIGMA_ERROR,
15709 "errorCode,SSID not found");
15710 return 0;
15711 }
15712 ssid = pos + 6;
15713 pos = strchr(ssid, '\n');
15714 if (pos)
15715 *pos = '\0';
15716 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
15717 send_resp(dut, conn, SIGMA_COMPLETE, resp);
15718 return 0;
15719}
15720
15721
Jouni Malinenf7222712019-06-13 01:50:21 +030015722static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
15723 struct sigma_conn *conn,
15724 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015725{
15726#ifdef __linux__
15727 struct timeval tv;
15728 struct tm tm;
15729 time_t t;
15730 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053015731 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015732
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015733 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015734
15735 memset(&tm, 0, sizeof(tm));
15736 val = get_param(cmd, "seconds");
15737 if (val)
15738 tm.tm_sec = atoi(val);
15739 val = get_param(cmd, "minutes");
15740 if (val)
15741 tm.tm_min = atoi(val);
15742 val = get_param(cmd, "hours");
15743 if (val)
15744 tm.tm_hour = atoi(val);
15745 val = get_param(cmd, "date");
15746 if (val)
15747 tm.tm_mday = atoi(val);
15748 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053015749 if (val) {
15750 v = atoi(val);
15751 if (v < 1 || v > 12) {
15752 send_resp(dut, conn, SIGMA_INVALID,
15753 "errorCode,Invalid month");
15754 return 0;
15755 }
15756 tm.tm_mon = v - 1;
15757 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015758 val = get_param(cmd, "year");
15759 if (val) {
15760 int year = atoi(val);
15761#ifdef ANDROID
15762 if (year > 2035)
15763 year = 2035; /* years beyond 2035 not supported */
15764#endif /* ANDROID */
15765 tm.tm_year = year - 1900;
15766 }
15767 t = mktime(&tm);
15768 if (t == (time_t) -1) {
15769 send_resp(dut, conn, SIGMA_ERROR,
15770 "errorCode,Invalid date or time");
15771 return 0;
15772 }
15773
15774 memset(&tv, 0, sizeof(tv));
15775 tv.tv_sec = t;
15776
15777 if (settimeofday(&tv, NULL) < 0) {
15778 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
15779 strerror(errno));
15780 send_resp(dut, conn, SIGMA_ERROR,
15781 "errorCode,Failed to set time");
15782 return 0;
15783 }
15784
15785 return 1;
15786#endif /* __linux__ */
15787
15788 return -1;
15789}
15790
15791
Jouni Malinenf7222712019-06-13 01:50:21 +030015792static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
15793 struct sigma_conn *conn,
15794 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015795{
15796 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015797 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015798 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015799 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015800 int res;
15801 struct wpa_ctrl *ctrl;
15802
15803 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015804 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015805
15806 val = get_param(cmd, "ProdESSAssoc");
15807 if (val)
15808 prod_ess_assoc = atoi(val);
15809
15810 kill_dhcp_client(dut, intf);
15811 if (start_dhcp_client(dut, intf) < 0)
15812 return -2;
15813
15814 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
15815 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
15816 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015817 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015818 prod_ess_assoc ? "" : "-N",
15819 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030015820 name ? "'" : "",
15821 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
15822 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015823
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053015824 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015825 if (run_hs20_osu(dut, buf) < 0) {
15826 FILE *f;
15827
15828 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
15829
15830 f = fopen("hs20-osu-client.res", "r");
15831 if (f) {
15832 char resp[400], res[300], *pos;
15833 if (!fgets(res, sizeof(res), f))
15834 res[0] = '\0';
15835 pos = strchr(res, '\n');
15836 if (pos)
15837 *pos = '\0';
15838 fclose(f);
15839 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
15840 res);
15841 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
15842 if (system(resp) != 0) {
15843 }
15844 snprintf(resp, sizeof(resp),
15845 "SSID,,BSSID,,failureReason,%s", res);
15846 send_resp(dut, conn, SIGMA_COMPLETE, resp);
15847 return 0;
15848 }
15849
15850 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
15851 return 0;
15852 }
15853
15854 if (!prod_ess_assoc)
15855 goto report;
15856
15857 ctrl = open_wpa_mon(intf);
15858 if (ctrl == NULL) {
15859 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
15860 "wpa_supplicant monitor connection");
15861 return -1;
15862 }
15863
15864 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
15865 buf, sizeof(buf));
15866
15867 wpa_ctrl_detach(ctrl);
15868 wpa_ctrl_close(ctrl);
15869
15870 if (res < 0) {
15871 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
15872 "network after OSU");
15873 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
15874 return 0;
15875 }
15876
15877report:
15878 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
15879 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
15880 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
15881 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
15882 return 0;
15883 }
15884
15885 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
15886 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015887 return 0;
15888}
15889
15890
Jouni Malinenf7222712019-06-13 01:50:21 +030015891static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
15892 struct sigma_conn *conn,
15893 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015894{
15895 const char *val;
15896 int timeout = 120;
15897
15898 val = get_param(cmd, "PolicyUpdate");
15899 if (val == NULL || atoi(val) == 0)
15900 return 1; /* No operation requested */
15901
15902 val = get_param(cmd, "Timeout");
15903 if (val)
15904 timeout = atoi(val);
15905
15906 if (timeout) {
15907 /* TODO: time out the command and return
15908 * PolicyUpdateStatus,TIMEOUT if needed. */
15909 }
15910
15911 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
15912 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
15913 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
15914 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
15915 return 0;
15916 }
15917
15918 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
15919 return 0;
15920}
15921
15922
Jouni Malinenf7222712019-06-13 01:50:21 +030015923static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
15924 struct sigma_conn *conn,
15925 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015926{
15927 struct wpa_ctrl *ctrl;
15928 const char *intf = get_param(cmd, "Interface");
15929 const char *bssid = get_param(cmd, "Bssid");
15930 const char *ssid = get_param(cmd, "SSID");
15931 const char *security = get_param(cmd, "Security");
15932 const char *passphrase = get_param(cmd, "Passphrase");
15933 const char *pin = get_param(cmd, "PIN");
15934 char buf[1000];
15935 char ssid_hex[200], passphrase_hex[200];
15936 const char *keymgmt, *cipher;
15937
15938 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020015939 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015940
15941 if (!bssid) {
15942 send_resp(dut, conn, SIGMA_ERROR,
15943 "ErrorCode,Missing Bssid argument");
15944 return 0;
15945 }
15946
15947 if (!ssid) {
15948 send_resp(dut, conn, SIGMA_ERROR,
15949 "ErrorCode,Missing SSID argument");
15950 return 0;
15951 }
15952
15953 if (!security) {
15954 send_resp(dut, conn, SIGMA_ERROR,
15955 "ErrorCode,Missing Security argument");
15956 return 0;
15957 }
15958
15959 if (!passphrase) {
15960 send_resp(dut, conn, SIGMA_ERROR,
15961 "ErrorCode,Missing Passphrase argument");
15962 return 0;
15963 }
15964
15965 if (!pin) {
15966 send_resp(dut, conn, SIGMA_ERROR,
15967 "ErrorCode,Missing PIN argument");
15968 return 0;
15969 }
15970
vamsi krishna8c9c1562017-05-12 15:51:46 +053015971 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
15972 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015973 send_resp(dut, conn, SIGMA_ERROR,
15974 "ErrorCode,Too long SSID/passphrase");
15975 return 0;
15976 }
15977
15978 ctrl = open_wpa_mon(intf);
15979 if (ctrl == NULL) {
15980 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
15981 "wpa_supplicant monitor connection");
15982 return -2;
15983 }
15984
15985 if (strcasecmp(security, "wpa2-psk") == 0) {
15986 keymgmt = "WPA2PSK";
15987 cipher = "CCMP";
15988 } else {
15989 wpa_ctrl_detach(ctrl);
15990 wpa_ctrl_close(ctrl);
15991 send_resp(dut, conn, SIGMA_ERROR,
15992 "ErrorCode,Unsupported Security value");
15993 return 0;
15994 }
15995
15996 ascii2hexstr(ssid, ssid_hex);
15997 ascii2hexstr(passphrase, passphrase_hex);
15998 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
15999 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
16000
16001 if (wpa_command(intf, buf) < 0) {
16002 wpa_ctrl_detach(ctrl);
16003 wpa_ctrl_close(ctrl);
16004 send_resp(dut, conn, SIGMA_ERROR,
16005 "ErrorCode,Failed to start registrar");
16006 return 0;
16007 }
16008
16009 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
16010 dut->er_oper_performed = 1;
16011
16012 return wps_connection_event(dut, conn, ctrl, intf, 0);
16013}
16014
16015
Jouni Malinenf7222712019-06-13 01:50:21 +030016016static enum sigma_cmd_result
16017cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
16018 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016019{
16020 struct wpa_ctrl *ctrl;
16021 const char *intf = get_param(cmd, "Interface");
16022 const char *bssid = get_param(cmd, "Bssid");
16023 char buf[100];
16024
16025 if (!bssid) {
16026 send_resp(dut, conn, SIGMA_ERROR,
16027 "ErrorCode,Missing Bssid argument");
16028 return 0;
16029 }
16030
16031 ctrl = open_wpa_mon(intf);
16032 if (ctrl == NULL) {
16033 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
16034 "wpa_supplicant monitor connection");
16035 return -2;
16036 }
16037
16038 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
16039
16040 if (wpa_command(intf, buf) < 0) {
16041 wpa_ctrl_detach(ctrl);
16042 wpa_ctrl_close(ctrl);
16043 send_resp(dut, conn, SIGMA_ERROR,
16044 "ErrorCode,Failed to start registrar");
16045 return 0;
16046 }
16047
16048 return wps_connection_event(dut, conn, ctrl, intf, 0);
16049}
16050
16051
Jouni Malinenf7222712019-06-13 01:50:21 +030016052static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
16053 struct sigma_conn *conn,
16054 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053016055{
16056 struct wpa_ctrl *ctrl;
16057 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016058 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016059 const char *config_method = get_param(cmd, "WPSConfigMethod");
16060 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053016061 int res;
16062 char buf[256];
16063 const char *events[] = {
16064 "CTRL-EVENT-CONNECTED",
16065 "WPS-OVERLAP-DETECTED",
16066 "WPS-TIMEOUT",
16067 "WPS-FAIL",
16068 NULL
16069 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016070 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053016071
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020016072 /* 60G WPS tests do not pass Interface parameter */
16073 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020016074 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020016075
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016076 if (dut->mode == SIGMA_MODE_AP)
16077 return ap_wps_registration(dut, conn, cmd);
16078
16079 if (config_method) {
16080 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
16081 * sta_wps_enter_pin before calling start_wps_registration. */
16082 if (strcasecmp(config_method, "PBC") == 0)
16083 dut->wps_method = WFA_CS_WPS_PBC;
16084 }
16085 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
16086 send_resp(dut, conn, SIGMA_ERROR,
16087 "ErrorCode,WPS parameters not yet set");
16088 return STATUS_SENT;
16089 }
16090
16091 /* Make sure WPS is enabled (also for STA mode) */
16092 dut->wps_disable = 0;
16093
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016094 if (dut->band == WPS_BAND_60G && network_mode &&
16095 strcasecmp(network_mode, "PBSS") == 0) {
16096 sigma_dut_print(dut, DUT_MSG_DEBUG,
16097 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020016098 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020016099 return -2;
16100 }
16101
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020016102 if (dut->force_rsn_ie) {
16103 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
16104 dut->force_rsn_ie);
16105 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
16106 sigma_dut_print(dut, DUT_MSG_INFO,
16107 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020016108 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020016109 }
16110 }
16111
vamsi krishna9b144002017-09-20 13:28:13 +053016112 ctrl = open_wpa_mon(intf);
16113 if (!ctrl) {
16114 sigma_dut_print(dut, DUT_MSG_ERROR,
16115 "Failed to open wpa_supplicant monitor connection");
16116 return -2;
16117 }
16118
16119 role = get_param(cmd, "WpsRole");
16120 if (!role) {
16121 send_resp(dut, conn, SIGMA_INVALID,
16122 "ErrorCode,WpsRole not provided");
16123 goto fail;
16124 }
16125
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016126 if (strcasecmp(role, "Enrollee") != 0) {
16127 /* Registrar role for STA not supported */
16128 send_resp(dut, conn, SIGMA_ERROR,
16129 "ErrorCode,Unsupported WpsRole value");
16130 goto fail;
16131 }
16132
16133 if (is_60g_sigma_dut(dut)) {
16134 if (dut->wps_method == WFA_CS_WPS_PBC)
16135 snprintf(buf, sizeof(buf), "WPS_PBC");
16136 else /* WFA_CS_WPS_PIN_KEYPAD */
16137 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
16138 dut->wps_pin);
16139 if (wpa_command(intf, buf) < 0) {
16140 send_resp(dut, conn, SIGMA_ERROR,
16141 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053016142 goto fail;
16143 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020016144 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
16145 if (res < 0) {
16146 send_resp(dut, conn, SIGMA_ERROR,
16147 "ErrorCode,WPS connection did not complete");
16148 goto fail;
16149 }
16150 if (strstr(buf, "WPS-TIMEOUT")) {
16151 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
16152 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
16153 send_resp(dut, conn, SIGMA_COMPLETE,
16154 "WpsState,OverlapSession");
16155 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
16156 send_resp(dut, conn, SIGMA_COMPLETE,
16157 "WpsState,Successful");
16158 } else {
16159 send_resp(dut, conn, SIGMA_COMPLETE,
16160 "WpsState,Failure");
16161 }
16162 } else {
16163 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053016164 if (wpa_command(intf, "WPS_PBC") < 0) {
16165 send_resp(dut, conn, SIGMA_ERROR,
16166 "ErrorCode,Failed to enable PBC");
16167 goto fail;
16168 }
16169 } else {
16170 /* TODO: PIN method */
16171 send_resp(dut, conn, SIGMA_ERROR,
16172 "ErrorCode,Unsupported WpsConfigMethod value");
16173 goto fail;
16174 }
16175 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
16176 if (res < 0) {
16177 send_resp(dut, conn, SIGMA_ERROR,
16178 "ErrorCode,WPS connection did not complete");
16179 goto fail;
16180 }
16181 if (strstr(buf, "WPS-TIMEOUT")) {
16182 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
16183 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
16184 send_resp(dut, conn, SIGMA_ERROR,
16185 "ErrorCode,OverlapSession");
16186 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
16187 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
16188 } else {
16189 send_resp(dut, conn, SIGMA_ERROR,
16190 "ErrorCode,WPS operation failed");
16191 }
vamsi krishna9b144002017-09-20 13:28:13 +053016192 }
16193
16194fail:
16195 wpa_ctrl_detach(ctrl);
16196 wpa_ctrl_close(ctrl);
16197 return 0;
16198}
16199
16200
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016201static int req_intf(struct sigma_cmd *cmd)
16202{
16203 return get_param(cmd, "interface") == NULL ? -1 : 0;
16204}
16205
16206
16207void sta_register_cmds(void)
16208{
16209 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
16210 cmd_sta_get_ip_config);
16211 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
16212 cmd_sta_set_ip_config);
16213 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
16214 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
16215 cmd_sta_get_mac_address);
16216 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
16217 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
16218 cmd_sta_verify_ip_connection);
16219 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
16220 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
16221 cmd_sta_set_encryption);
16222 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
16223 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
16224 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
16225 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
16226 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
16227 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
16228 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
16229 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
16230 cmd_sta_set_eapakaprime);
16231 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
16232 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
16233 /* TODO: sta_set_ibss */
16234 /* TODO: sta_set_mode */
16235 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
16236 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
16237 /* TODO: sta_up_load */
16238 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
16239 cmd_sta_preset_testparameters);
16240 /* TODO: sta_set_system */
16241 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
16242 /* TODO: sta_set_rifs_test */
16243 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
16244 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
16245 /* TODO: sta_send_coexist_mgmt */
16246 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
16247 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
16248 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
16249 sigma_dut_reg_cmd("sta_reset_default", req_intf,
16250 cmd_sta_reset_default);
16251 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
16252 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
16253 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
16254 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
16255 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020016256 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016257 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
16258 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
16259 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
16260 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
16261 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030016262 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
16263 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016264 sigma_dut_reg_cmd("sta_add_credential", req_intf,
16265 cmd_sta_add_credential);
16266 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020016267 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016268 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
16269 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
16270 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
16271 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
16272 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
16273 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030016274 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016275 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
16276 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020016277 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053016278 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016279}