blob: 766682cd3ce2122b7fb85313197be5a2594b3ebb [file] [log] [blame]
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001/*
2 * Sigma Control API DUT (station/AP)
3 * Copyright (c) 2010-2011, Atheros Communications, Inc.
Jouni Malinen9d7e31d2017-12-22 18:55:04 +02004 * Copyright (c) 2011-2017, Qualcomm Atheros, Inc.
Jouni Malinenc12ea4a2018-01-05 21:07:10 +02005 * Copyright (c) 2018, The Linux Foundation
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006 * All Rights Reserved.
7 * Licensed under the Clear BSD license. See README for more details.
8 */
9
10#include "sigma_dut.h"
11#include <sys/ioctl.h>
12#include <sys/stat.h>
Jouni Malinen82905202018-04-29 17:20:10 +030013#include <sys/wait.h>
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030014#include <ctype.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015#ifdef __linux__
Lior Davidcc88b562017-01-03 18:52:09 +020016#include <regex.h>
17#include <dirent.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020018#include <sys/time.h>
19#include <netpacket/packet.h>
20#include <linux/if_ether.h>
21#ifdef ANDROID
22#include <cutils/properties.h>
23#include <android/log.h>
24#include "keystore_get.h"
25#else /* ANDROID */
26#include <ifaddrs.h>
27#endif /* ANDROID */
28#include <netdb.h>
29#endif /* __linux__ */
30#ifdef __QNXNTO__
31#include <net/if_dl.h>
32#endif /* __QNXNTO__ */
33#include "wpa_ctrl.h"
34#include "wpa_helpers.h"
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070035#include "miracast.h"
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070036#include "qca-vendor_copy.h"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020037
38/* Temporary files for sta_send_addba */
39#define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp"
40#define VI_QOS_FILE "/tmp/vi-qos.txt"
41#define VI_QOS_REFFILE "/etc/vi-qos.txt"
42
43/*
44 * MTU for Ethernet need to take into account 8-byte SNAP header
45 * to be added when encapsulating Ethernet frame into 802.11
46 */
47#ifndef IEEE80211_MAX_DATA_LEN_DMG
48#define IEEE80211_MAX_DATA_LEN_DMG 7920
49#endif
50#ifndef IEEE80211_SNAP_LEN_DMG
51#define IEEE80211_SNAP_LEN_DMG 8
52#endif
53
Ashwini Patil00402582017-04-13 12:29:39 +053054#define NON_PREF_CH_LIST_SIZE 100
Ashwini Patil5acd7382017-04-13 15:55:04 +053055#define NEIGHBOR_REPORT_SIZE 1000
56#define DEFAULT_NEIGHBOR_BSSID_INFO "17"
57#define DEFAULT_NEIGHBOR_PHY_TYPE "1"
Ashwini Patil00402582017-04-13 12:29:39 +053058
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030059#define WIL_DEFAULT_BI 100
60
61/* default remain on channel time for transmitting frames (milliseconds) */
62#define WIL_TRANSMIT_FRAME_DEFAULT_ROC 500
63#define IEEE80211_P2P_ATTR_DEVICE_ID 3
64#define IEEE80211_P2P_ATTR_GROUP_ID 15
65
66/* describes tagged bytes in template frame file */
67struct template_frame_tag {
68 int num;
69 int offset;
70 size_t len;
71};
72
Jouni Malinencd4e3c32015-10-29 12:39:56 +020073extern char *sigma_wpas_ctrl;
74extern char *sigma_cert_path;
75extern enum driver_type wifi_chip_type;
76extern char *sigma_radio_ifname[];
77
Lior David0fe101e2017-03-09 16:09:50 +020078#ifdef __linux__
79#define WIL_WMI_MAX_PAYLOAD 248
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020080#define WIL_WMI_ESE_CFG_CMDID 0xa01
Lior David0fe101e2017-03-09 16:09:50 +020081#define WIL_WMI_BF_TRIG_CMDID 0x83a
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020082#define WIL_WMI_UNIT_TEST_CMDID 0x900
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030083#define WIL_WMI_P2P_CFG_CMDID 0x910
84#define WIL_WMI_START_LISTEN_CMDID 0x914
85#define WIL_WMI_DISCOVERY_STOP_CMDID 0x917
Lior David0fe101e2017-03-09 16:09:50 +020086
87struct wil_wmi_header {
88 uint8_t mid;
89 uint8_t reserved;
90 uint16_t cmd;
91 uint32_t ts;
92} __attribute__((packed));
93
94enum wil_wmi_bf_trig_type {
95 WIL_WMI_SLS,
96 WIL_WMI_BRP_RX,
97 WIL_WMI_BRP_TX,
98};
99
100struct wil_wmi_bf_trig_cmd {
101 /* enum wil_wmi_bf_trig_type */
102 uint32_t bf_type;
103 /* cid when type == WMI_BRP_RX */
104 uint32_t sta_id;
105 uint32_t reserved;
106 /* mac address when type = WIL_WMI_SLS */
107 uint8_t dest_mac[6];
108} __attribute__((packed));
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200109
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200110enum wil_wmi_sched_scheme_advertisment {
111 WIL_WMI_ADVERTISE_ESE_DISABLED,
112 WIL_WMI_ADVERTISE_ESE_IN_BEACON,
113 WIL_WMI_ADVERTISE_ESE_IN_ANNOUNCE_FRAME,
114};
115
116enum wil_wmi_ese_slot_type {
117 WIL_WMI_ESE_SP,
118 WIL_WMI_ESE_CBAP,
119 WIL_WMI_ESE_ANNOUNCE_NO_ACK,
120};
121
122struct wil_wmi_ese_slot {
123 /* offset from start of BI in microseconds */
124 uint32_t tbtt_offset;
125 uint8_t flags;
126 /* enum wil_wmi_ese_slot_type */
127 uint8_t slot_type;
128 /* duration in microseconds */
129 uint16_t duration;
130 /* frame exchange sequence duration, microseconds */
131 uint16_t tx_op;
132 /* time between 2 blocks for periodic allocation(microseconds) */
133 uint16_t period;
134 /* number of blocks in periodic allocation */
135 uint8_t num_blocks;
136 /* for semi-active allocations */
137 uint8_t idle_period;
138 uint8_t src_aid;
139 uint8_t dst_aid;
140 uint32_t reserved;
141} __attribute__((packed));
142
143#define WIL_WMI_MAX_ESE_SLOTS 4
144struct wil_wmi_ese_cfg {
145 uint8_t serial_num;
146 /* wil_wmi_sched_scheme_advertisment */
147 uint8_t ese_advertisment;
148 uint16_t flags;
149 uint8_t num_allocs;
150 uint8_t reserved[3];
151 uint64_t start_tbtt;
152 /* allocations list */
153 struct wil_wmi_ese_slot slots[WIL_WMI_MAX_ESE_SLOTS];
154} __attribute__((packed));
155
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200156#define WIL_WMI_UT_FORCE_MCS 6
157struct wil_wmi_force_mcs {
158 /* WIL_WMI_UT_HW_SYSAPI */
159 uint16_t module_id;
160 /* WIL_WMI_UT_FORCE_MCS */
161 uint16_t subtype_id;
162 /* cid (ignored in oob_mode, affects all stations) */
163 uint32_t cid;
164 /* 1 to force MCS, 0 to restore default behavior */
165 uint32_t force_enable;
166 /* MCS index, 0-12 */
167 uint32_t mcs;
168} __attribute__((packed));
169
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200170#define WIL_WMI_UT_HW_SYSAPI 10
171#define WIL_WMI_UT_FORCE_RSN_IE 0x29
172struct wil_wmi_force_rsn_ie {
173 /* WIL_WMI_UT_HW_SYSAPI */
174 uint16_t module_id;
175 /* WIL_WMI_UT_FORCE_RSN_IE */
176 uint16_t subtype_id;
177 /* 0 = no change, 1 = remove if exists, 2 = add if does not exist */
178 uint32_t state;
179} __attribute__((packed));
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300180
181enum wil_wmi_discovery_mode {
182 WMI_DISCOVERY_MODE_NON_OFFLOAD,
183 WMI_DISCOVERY_MODE_OFFLOAD,
184 WMI_DISCOVERY_MODE_PEER2PEER,
185};
186
187struct wil_wmi_p2p_cfg_cmd {
188 /* enum wil_wmi_discovery_mode */
189 uint8_t discovery_mode;
190 /* 0-based (wireless channel - 1) */
191 uint8_t channel;
192 /* set to WIL_DEFAULT_BI */
193 uint16_t bcon_interval;
194} __attribute__((packed));
Lior David0fe101e2017-03-09 16:09:50 +0200195#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200196
197#ifdef ANDROID
198
199static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname);
200
201#define ANDROID_KEYSTORE_GET 'g'
202#define ANDROID_KEYSTORE_GET_PUBKEY 'b'
203
204static int android_keystore_get(char cmd, const char *key, unsigned char *val)
205{
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200206 /* Android 4.3 changed keystore design, so need to use keystore_get() */
207#ifndef KEYSTORE_MESSAGE_SIZE
208#define KEYSTORE_MESSAGE_SIZE 65535
209#endif /* KEYSTORE_MESSAGE_SIZE */
210
211 ssize_t len;
212 uint8_t *value = NULL;
213
214 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
215 "keystore command '%c' key '%s' --> keystore_get",
216 cmd, key);
217
218 len = keystore_get(key, strlen(key), &value);
219 if (len < 0) {
220 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
221 "keystore_get() failed");
222 return -1;
223 }
224
225 if (len > KEYSTORE_MESSAGE_SIZE)
226 len = KEYSTORE_MESSAGE_SIZE;
227 memcpy(val, value, len);
228 free(value);
229 return len;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200230}
231#endif /* ANDROID */
232
233
Vinita S. Maloo0fcb57d2020-04-24 14:03:56 +0530234#ifdef NL80211_SUPPORT
235static int nl80211_sta_set_power_save(struct sigma_dut *dut,
236 const char *intf,
237 enum nl80211_ps_state ps_state)
238{
239 struct nl_msg *msg;
240 int ifindex, ret;
241
242 ifindex = if_nametoindex(intf);
243 if (ifindex == 0) {
244 sigma_dut_print(dut, DUT_MSG_ERROR,
245 "%s: Index for interface %s not found",
246 __func__, intf);
247 return -1;
248 }
249
250 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
251 NL80211_CMD_SET_POWER_SAVE);
252 if (!msg) {
253 sigma_dut_print(dut, DUT_MSG_ERROR,
254 "%s: err in creating nl80211 msg", __func__);
255 return -1;
256 }
257
258 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) {
259 sigma_dut_print(dut, DUT_MSG_ERROR,
260 "%s: err in populating nl80211 msg", __func__);
261 nlmsg_free(msg);
262 return -1;
263 }
264
265 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
266 if (ret) {
267 sigma_dut_print(dut, DUT_MSG_ERROR,
268 "%s: err in send_and_recv_msgs, ret=%d (%s)",
269 __func__, ret, strerror(-ret));
270 return -1;
271 }
272
273 return 0;
274}
275#endif /* NL80211_SUPPORT */
276
277
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530278static int set_power_save_wcn(struct sigma_dut *dut, const char *intf, int ps)
279{
280 char buf[100];
Vinita S. Maloo0fcb57d2020-04-24 14:03:56 +0530281#ifdef NL80211_SUPPORT
282 enum nl80211_ps_state ps_state;
283
284 ps_state = ps == 1 ? NL80211_PS_ENABLED : NL80211_PS_DISABLED;
285 if (nl80211_sta_set_power_save(dut, intf, ps_state) == 0)
286 return 0;
287#endif /* NL80211_SUPPORT */
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530288
289 snprintf(buf, sizeof(buf), "iwpriv %s setPower %d", intf, ps);
290 if (system(buf) != 0) {
291 sigma_dut_print(dut, DUT_MSG_ERROR,
292 "iwpriv setPower %d failed", ps);
293 return -1;
294 }
295 return 0;
296}
297
298
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200299int set_ps(const char *intf, struct sigma_dut *dut, int enabled)
300{
301#ifdef __linux__
302 char buf[100];
303
304 if (wifi_chip_type == DRIVER_WCN) {
305 if (enabled) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530306 if (set_power_save_wcn(dut, intf, 1) < 0) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530307 snprintf(buf, sizeof(buf),
308 "iwpriv wlan0 dump 906");
309 if (system(buf) != 0)
310 goto set_power_save;
311 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200312 } else {
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530313 if (set_power_save_wcn(dut, intf, 2) < 0) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530314 snprintf(buf, sizeof(buf),
315 "iwpriv wlan0 dump 905");
316 if (system(buf) != 0)
317 goto set_power_save;
318 snprintf(buf, sizeof(buf),
319 "iwpriv wlan0 dump 912");
320 if (system(buf) != 0)
321 goto set_power_save;
322 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200323 }
324
325 return 0;
326 }
327
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530328set_power_save:
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200329 snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s",
330 intf, enabled ? "on" : "off");
331 if (system(buf) != 0) {
332 snprintf(buf, sizeof(buf), "iw dev %s set power_save %s",
333 intf, enabled ? "on" : "off");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530334 if (system(buf) != 0) {
335 sigma_dut_print(dut, DUT_MSG_ERROR,
336 "Failed to set power save %s",
337 enabled ? "on" : "off");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200338 return -1;
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530339 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200340 }
341
342 return 0;
343#else /* __linux__ */
344 return -1;
345#endif /* __linux__ */
346}
347
348
Lior Davidcc88b562017-01-03 18:52:09 +0200349#ifdef __linux__
Lior David0fe101e2017-03-09 16:09:50 +0200350
Lior Davidcc88b562017-01-03 18:52:09 +0200351static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path,
352 size_t len)
353{
354 DIR *dir, *wil_dir;
355 struct dirent *entry;
356 int ret = -1;
357 const char *root_path = "/sys/kernel/debug/ieee80211";
358
359 dir = opendir(root_path);
360 if (!dir)
361 return -2;
362
363 while ((entry = readdir(dir))) {
364 if (strcmp(entry->d_name, ".") == 0 ||
365 strcmp(entry->d_name, "..") == 0)
366 continue;
367
368 if (snprintf(path, len, "%s/%s/wil6210",
369 root_path, entry->d_name) >= (int) len) {
370 ret = -3;
371 break;
372 }
373
374 wil_dir = opendir(path);
375 if (wil_dir) {
376 closedir(wil_dir);
377 ret = 0;
378 break;
379 }
380 }
381
382 closedir(dir);
383 return ret;
384}
Lior David0fe101e2017-03-09 16:09:50 +0200385
386
387static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command,
388 void *payload, uint16_t length)
389{
390 struct {
391 struct wil_wmi_header hdr;
392 char payload[WIL_WMI_MAX_PAYLOAD];
393 } __attribute__((packed)) cmd;
394 char buf[128], fname[128];
395 size_t towrite, written;
396 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300397 int res;
Lior David0fe101e2017-03-09 16:09:50 +0200398
399 if (length > WIL_WMI_MAX_PAYLOAD) {
400 sigma_dut_print(dut, DUT_MSG_ERROR,
401 "payload too large(%u, max %u)",
402 length, WIL_WMI_MAX_PAYLOAD);
403 return -1;
404 }
405
406 memset(&cmd.hdr, 0, sizeof(cmd.hdr));
407 cmd.hdr.cmd = command;
408 memcpy(cmd.payload, payload, length);
409
410 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
411 sigma_dut_print(dut, DUT_MSG_ERROR,
412 "failed to get wil6210 debugfs dir");
413 return -1;
414 }
415
Jouni Malinen3aa72862019-05-29 23:14:51 +0300416 res = snprintf(fname, sizeof(fname), "%s/wmi_send", buf);
417 if (res < 0 || res >= sizeof(fname))
418 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200419 f = fopen(fname, "wb");
420 if (!f) {
421 sigma_dut_print(dut, DUT_MSG_ERROR,
422 "failed to open: %s", fname);
423 return -1;
424 }
425
426 towrite = sizeof(cmd.hdr) + length;
427 written = fwrite(&cmd, 1, towrite, f);
428 fclose(f);
429 if (written != towrite) {
430 sigma_dut_print(dut, DUT_MSG_ERROR,
431 "failed to send wmi %u", command);
432 return -1;
433 }
434
435 return 0;
436}
437
438
439static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid,
440 const char *pattern, unsigned int *field)
441{
442 char buf[128], fname[128];
443 FILE *f;
444 regex_t re;
445 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +0300446 int rc, ret = -1, res;
Lior David0fe101e2017-03-09 16:09:50 +0200447
448 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
449 sigma_dut_print(dut, DUT_MSG_ERROR,
450 "failed to get wil6210 debugfs dir");
451 return -1;
452 }
453
Jouni Malinen3aa72862019-05-29 23:14:51 +0300454 res = snprintf(fname, sizeof(fname), "%s/stations", buf);
455 if (res < 0 || res >= sizeof(fname))
456 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200457 f = fopen(fname, "r");
458 if (!f) {
459 sigma_dut_print(dut, DUT_MSG_ERROR,
460 "failed to open: %s", fname);
461 return -1;
462 }
463
464 if (regcomp(&re, pattern, REG_EXTENDED)) {
465 sigma_dut_print(dut, DUT_MSG_ERROR,
466 "regcomp failed: %s", pattern);
467 goto out;
468 }
469
470 /*
471 * find the entry for the mac address
472 * line is of the form: [n] 11:22:33:44:55:66 state AID aid
473 */
474 while (fgets(buf, sizeof(buf), f)) {
475 if (strcasestr(buf, bssid)) {
476 /* extract the field (CID/AID/state) */
477 rc = regexec(&re, buf, 2, m, 0);
478 if (!rc && (m[1].rm_so >= 0)) {
479 buf[m[1].rm_eo] = 0;
480 *field = atoi(&buf[m[1].rm_so]);
481 ret = 0;
482 break;
483 }
484 }
485 }
486
487 regfree(&re);
488 if (ret)
489 sigma_dut_print(dut, DUT_MSG_ERROR,
490 "could not extract field");
491
492out:
493 fclose(f);
494
495 return ret;
496}
497
498
499static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid,
500 unsigned int *cid)
501{
502 const char *pattern = "\\[([0-9]+)\\]";
503
504 return wil6210_get_sta_info_field(dut, bssid, pattern, cid);
505}
506
507
508static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac,
509 int l_rx)
510{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700511 struct wil_wmi_bf_trig_cmd cmd;
Lior David0fe101e2017-03-09 16:09:50 +0200512 unsigned int cid;
513
Rakesh Sunki556237d2017-03-30 14:49:31 -0700514 memset(&cmd, 0, sizeof(cmd));
515
Lior David0fe101e2017-03-09 16:09:50 +0200516 if (wil6210_get_cid(dut, mac, &cid))
517 return -1;
518
519 cmd.bf_type = WIL_WMI_BRP_RX;
520 cmd.sta_id = cid;
521 /* training length (l_rx) is ignored, FW always uses length 16 */
522 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
523 &cmd, sizeof(cmd));
524}
525
526
527static int wil6210_send_sls(struct sigma_dut *dut, const char *mac)
528{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700529 struct wil_wmi_bf_trig_cmd cmd;
530
531 memset(&cmd, 0, sizeof(cmd));
Lior David0fe101e2017-03-09 16:09:50 +0200532
533 if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac))
534 return -1;
535
536 cmd.bf_type = WIL_WMI_SLS;
537 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
538 &cmd, sizeof(cmd));
539}
540
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200541
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200542int wil6210_set_ese(struct sigma_dut *dut, int count,
543 struct sigma_ese_alloc *allocs)
544{
545 struct wil_wmi_ese_cfg cmd = { };
546 int i;
547
548 if (count == 0 || count > WIL_WMI_MAX_ESE_SLOTS)
549 return -1;
550
551 if (dut->ap_bcnint <= 0) {
552 sigma_dut_print(dut, DUT_MSG_ERROR,
553 "invalid beacon interval(%d), check test",
554 dut->ap_bcnint);
555 return -1;
556 }
557
558 cmd.ese_advertisment = WIL_WMI_ADVERTISE_ESE_IN_BEACON;
559 cmd.flags = 0x1d;
560 cmd.num_allocs = count;
561 for (i = 0; i < count; i++) {
562 /*
563 * Convert percent from BI (BI specified in milliseconds)
564 * to absolute duration in microseconds.
565 */
566 cmd.slots[i].duration =
567 (allocs[i].percent_bi * dut->ap_bcnint * 1000) / 100;
568 switch (allocs[i].type) {
569 case ESE_CBAP:
570 cmd.slots[i].slot_type = WIL_WMI_ESE_CBAP;
571 break;
572 case ESE_SP:
573 cmd.slots[i].slot_type = WIL_WMI_ESE_SP;
574 break;
575 default:
576 sigma_dut_print(dut, DUT_MSG_ERROR,
577 "invalid slot type(%d) at index %d",
578 allocs[i].type, i);
579 return -1;
580 }
581 cmd.slots[i].src_aid = allocs[i].src_aid;
582 cmd.slots[i].dst_aid = allocs[i].dst_aid;
583 sigma_dut_print(dut, DUT_MSG_INFO,
584 "slot %d, duration %u, type %d, srcAID %u dstAID %u",
585 i, cmd.slots[i].duration,
586 cmd.slots[i].slot_type, cmd.slots[i].src_aid,
587 cmd.slots[i].dst_aid);
588 }
589
590 return wil6210_wmi_send(dut, WIL_WMI_ESE_CFG_CMDID, &cmd, sizeof(cmd));
591}
592
593
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200594int wil6210_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
595{
596 struct wil_wmi_force_mcs cmd = { };
597
598 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
599 cmd.subtype_id = WIL_WMI_UT_FORCE_MCS;
600 cmd.force_enable = (uint32_t) force;
601 cmd.mcs = (uint32_t) mcs;
602
603 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
604 &cmd, sizeof(cmd));
605}
606
607
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200608static int wil6210_force_rsn_ie(struct sigma_dut *dut, int state)
609{
610 struct wil_wmi_force_rsn_ie cmd = { };
611
612 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
613 cmd.subtype_id = WIL_WMI_UT_FORCE_RSN_IE;
614 cmd.state = (uint32_t) state;
615
616 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
617 &cmd, sizeof(cmd));
618}
619
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300620
621/*
622 * this function is also used to configure generic remain-on-channel
623 */
624static int wil6210_p2p_cfg(struct sigma_dut *dut, int freq)
625{
626 struct wil_wmi_p2p_cfg_cmd cmd = { };
627 int channel = freq_to_channel(freq);
628
629 if (channel < 0)
630 return -1;
631 cmd.discovery_mode = WMI_DISCOVERY_MODE_NON_OFFLOAD;
632 cmd.channel = channel - 1;
633 cmd.bcon_interval = WIL_DEFAULT_BI;
634 cmd.discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER;
635
636 return wil6210_wmi_send(dut, WIL_WMI_P2P_CFG_CMDID,
637 &cmd, sizeof(cmd));
638}
639
640
641static int wil6210_remain_on_channel(struct sigma_dut *dut, int freq)
642{
643 int ret = wil6210_p2p_cfg(dut, freq);
644
645 if (ret)
646 return ret;
647
648 ret = wil6210_wmi_send(dut, WIL_WMI_START_LISTEN_CMDID, NULL, 0);
649 if (!ret) {
650 /*
651 * wait a bit to allow FW to setup the radio
652 * especially important if we switch channels
653 */
654 usleep(500000);
655 }
656
657 return ret;
658}
659
660
661static int wil6210_stop_discovery(struct sigma_dut *dut)
662{
663 return wil6210_wmi_send(dut, WIL_WMI_DISCOVERY_STOP_CMDID, NULL, 0);
664}
665
666
667static int wil6210_transmit_frame(struct sigma_dut *dut, int freq,
668 int wait_duration,
669 const char *frame, size_t frame_len)
670{
671 char buf[128], fname[128];
672 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300673 int res = 0, r;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300674 size_t written;
675
676 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
677 sigma_dut_print(dut, DUT_MSG_ERROR,
678 "failed to get wil6210 debugfs dir");
679 return -1;
680 }
Jouni Malinen3aa72862019-05-29 23:14:51 +0300681 r = snprintf(fname, sizeof(fname), "%s/tx_mgmt", buf);
682 if (r < 0 || r >= sizeof(fname))
683 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300684
685 if (wil6210_remain_on_channel(dut, freq)) {
686 sigma_dut_print(dut, DUT_MSG_ERROR,
687 "failed to listen on channel");
688 return -1;
689 }
690
691 f = fopen(fname, "wb");
692 if (!f) {
693 sigma_dut_print(dut, DUT_MSG_ERROR,
694 "failed to open: %s", fname);
695 res = -1;
696 goto out_stop;
697 }
698 written = fwrite(frame, 1, frame_len, f);
699 fclose(f);
700
701 if (written != frame_len) {
702 sigma_dut_print(dut, DUT_MSG_ERROR,
703 "failed to transmit frame (got %zd, expected %zd)",
704 written, frame_len);
705 res = -1;
706 goto out_stop;
707 }
708
709 usleep(wait_duration * 1000);
710
711out_stop:
712 wil6210_stop_discovery(dut);
713 return res;
714}
715
716
717static int find_template_frame_tag(struct template_frame_tag *tags,
718 int total_tags, int tag_num)
719{
720 int i;
721
722 for (i = 0; i < total_tags; i++) {
723 if (tag_num == tags[i].num)
724 return i;
725 }
726
727 return -1;
728}
729
730
731static int replace_p2p_attribute(struct sigma_dut *dut, char *buf, size_t len,
732 int id, const char *value, size_t val_len)
733{
734 struct wfa_p2p_attribute *attr = (struct wfa_p2p_attribute *) buf;
735
736 if (len < 3 + val_len) {
737 sigma_dut_print(dut, DUT_MSG_ERROR,
738 "not enough space to replace P2P attribute");
739 return -1;
740 }
741
742 if (attr->len != val_len) {
743 sigma_dut_print(dut, DUT_MSG_ERROR,
744 "attribute length mismatch (need %zu have %hu)",
745 val_len, attr->len);
746 return -1;
747 }
748
749 if (attr->id != id) {
750 sigma_dut_print(dut, DUT_MSG_ERROR,
751 "incorrect attribute id (expected %d actual %d)",
752 id, attr->id);
753 return -1;
754 }
755
756 memcpy(attr->variable, value, val_len);
757
758 return 0;
759}
760
761
762static int parse_template_frame_file(struct sigma_dut *dut, const char *fname,
763 char *buf, size_t *length,
764 struct template_frame_tag *tags,
765 size_t *num_tags)
766{
767 char line[512];
768 FILE *f;
769 size_t offset = 0, tag_index = 0;
770 int num, index;
771 int in_tag = 0, tag_num = 0, tag_offset = 0;
772
773 if (*length < sizeof(struct ieee80211_hdr_3addr)) {
774 sigma_dut_print(dut, DUT_MSG_ERROR,
775 "supplied buffer is too small");
776 return -1;
777 }
778
779 f = fopen(fname, "r");
780 if (!f) {
781 sigma_dut_print(dut, DUT_MSG_ERROR,
782 "failed to open template file %s", fname);
783 return -1;
784 }
785
786 /*
787 * template file format: lines beginning with # are comments and
788 * ignored.
789 * It is possible to tag bytes in the frame to make it easy
790 * to replace fields in the template, espcially if they appear
791 * in variable-sized sections (such as IEs)
792 * This is done by a line beginning with $NUM where NUM is an integer
793 * tag number. It can be followed by space(s) and comment.
794 * The next line is considered the tagged bytes. The parser will fill
795 * the tag number, offset and length of the tagged bytes.
796 * rest of the lines contain frame bytes as sequence of hex digits,
797 * 2 digits for each byte. Spaces are allowed between bytes.
798 * On bytes lines only hex digits and spaces are allowed
799 */
800 while (!feof(f)) {
801 if (!fgets(line, sizeof(line), f))
802 break;
803 index = 0;
804 while (isspace((unsigned char) line[index]))
805 index++;
806 if (!line[index] || line[index] == '#')
807 continue;
808 if (line[index] == '$') {
809 if (tags) {
810 index++;
811 tag_num = strtol(&line[index], NULL, 0);
812 tag_offset = offset;
813 in_tag = 1;
814 }
815 continue;
816 }
817 while (line[index]) {
818 if (isspace((unsigned char) line[index])) {
819 index++;
820 continue;
821 }
822 num = hex_byte(&line[index]);
823 if (num < 0)
824 break;
825 buf[offset++] = num;
826 if (offset == *length)
827 goto out;
828 index += 2;
829 }
830
831 if (in_tag) {
832 if (tag_index < *num_tags) {
833 tags[tag_index].num = tag_num;
834 tags[tag_index].offset = tag_offset;
835 tags[tag_index].len = offset - tag_offset;
836 tag_index++;
837 } else {
838 sigma_dut_print(dut, DUT_MSG_INFO,
839 "too many tags, tag ignored");
840 }
841 in_tag = 0;
842 }
843 }
844
845 if (num_tags)
846 *num_tags = tag_index;
847out:
848 fclose(f);
849 if (offset < sizeof(struct ieee80211_hdr_3addr)) {
850 sigma_dut_print(dut, DUT_MSG_ERROR,
851 "template frame is too small");
852 return -1;
853 }
854
855 *length = offset;
856 return 0;
857}
858
Lior Davidcc88b562017-01-03 18:52:09 +0200859#endif /* __linux__ */
860
861
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200862static void static_ip_file(int proto, const char *addr, const char *mask,
863 const char *gw)
864{
865 if (proto) {
866 FILE *f = fopen("static-ip", "w");
867 if (f) {
868 fprintf(f, "%d %s %s %s\n", proto, addr,
869 mask ? mask : "N/A",
870 gw ? gw : "N/A");
871 fclose(f);
872 }
873 } else {
874 unlink("static-ip");
875 }
876}
877
878
879static int send_neighbor_request(struct sigma_dut *dut, const char *intf,
880 const char *ssid)
881{
882#ifdef __linux__
883 char buf[100];
884
885 snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s",
886 intf, ssid);
887 sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf);
888
889 if (system(buf) != 0) {
890 sigma_dut_print(dut, DUT_MSG_ERROR,
891 "iwpriv neighbor request failed");
892 return -1;
893 }
894
895 sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send");
896
897 return 0;
898#else /* __linux__ */
899 return -1;
900#endif /* __linux__ */
901}
902
903
904static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf,
Ashwini Patil5acd7382017-04-13 15:55:04 +0530905 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200906{
Ashwini Patil5acd7382017-04-13 15:55:04 +0530907 const char *val;
908 int reason_code = 0;
909 char buf[1024];
910
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200911 /*
912 * In the earlier builds we used WNM_QUERY and in later
913 * builds used WNM_BSS_QUERY.
914 */
915
Ashwini Patil5acd7382017-04-13 15:55:04 +0530916 val = get_param(cmd, "BTMQuery_Reason_Code");
917 if (val)
918 reason_code = atoi(val);
919
920 val = get_param(cmd, "Cand_List");
921 if (val && atoi(val) == 1 && dut->btm_query_cand_list) {
922 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code,
923 dut->btm_query_cand_list);
924 free(dut->btm_query_cand_list);
925 dut->btm_query_cand_list = NULL;
926 } else {
927 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code);
928 }
929
930 if (wpa_command(intf, buf) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200931 sigma_dut_print(dut, DUT_MSG_ERROR,
932 "transition management query failed");
933 return -1;
934 }
935
936 sigma_dut_print(dut, DUT_MSG_DEBUG,
937 "transition management query sent");
938
939 return 0;
940}
941
942
943int is_ip_addr(const char *str)
944{
945 const char *pos = str;
946 struct in_addr addr;
947
948 while (*pos) {
949 if (*pos != '.' && (*pos < '0' || *pos > '9'))
950 return 0;
951 pos++;
952 }
953
954 return inet_aton(str, &addr);
955}
956
957
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200958int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
959 size_t buf_len)
960{
vamsi krishnaa11d0732018-05-16 12:19:48 +0530961 char tmp[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200962 char ip[16], mask[15], dns[16], sec_dns[16];
963 int is_dhcp = 0;
964 int s;
965#ifdef ANDROID
966 char prop[PROPERTY_VALUE_MAX];
vamsi krishnaa11d0732018-05-16 12:19:48 +0530967#else /* ANDROID */
968 FILE *f;
969#ifdef __linux__
970 const char *str_ps;
971#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200972#endif /* ANDROID */
973
974 ip[0] = '\0';
975 mask[0] = '\0';
976 dns[0] = '\0';
977 sec_dns[0] = '\0';
978
979 s = socket(PF_INET, SOCK_DGRAM, 0);
980 if (s >= 0) {
981 struct ifreq ifr;
982 struct sockaddr_in saddr;
983
984 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700985 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200986 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
987 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
988 "%s IP address: %s",
989 ifname, strerror(errno));
990 } else {
991 memcpy(&saddr, &ifr.ifr_addr,
992 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700993 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200994 }
995
996 if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) {
997 memcpy(&saddr, &ifr.ifr_addr,
998 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700999 strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001000 }
1001 close(s);
1002 }
1003
1004#ifdef ANDROID
1005 snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname);
1006 if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) {
1007 snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname);
1008 if (property_get(tmp, prop, NULL) != 0 &&
1009 strcmp(prop, "ok") == 0) {
1010 snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress",
1011 ifname);
1012 if (property_get(tmp, prop, NULL) != 0 &&
1013 strcmp(ip, prop) == 0)
1014 is_dhcp = 1;
1015 }
1016 }
1017
1018 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -07001019 if (property_get(tmp, prop, NULL) != 0)
1020 strlcpy(dns, prop, sizeof(dns));
1021 else if (property_get("net.dns1", prop, NULL) != 0)
1022 strlcpy(dns, prop, sizeof(dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001023
1024 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -07001025 if (property_get(tmp, prop, NULL) != 0)
1026 strlcpy(sec_dns, prop, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001027#else /* ANDROID */
1028#ifdef __linux__
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001029 if (get_driver_type(dut) == DRIVER_OPENWRT)
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301030 str_ps = "ps -w";
1031 else
1032 str_ps = "ps ax";
1033 snprintf(tmp, sizeof(tmp),
1034 "%s | grep dhclient | grep -v grep | grep -q %s",
1035 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001036 if (system(tmp) == 0)
1037 is_dhcp = 1;
1038 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301039 snprintf(tmp, sizeof(tmp),
1040 "%s | grep udhcpc | grep -v grep | grep -q %s",
1041 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001042 if (system(tmp) == 0)
1043 is_dhcp = 1;
1044 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301045 snprintf(tmp, sizeof(tmp),
1046 "%s | grep dhcpcd | grep -v grep | grep -q %s",
1047 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001048 if (system(tmp) == 0)
1049 is_dhcp = 1;
1050 }
1051 }
1052#endif /* __linux__ */
1053
1054 f = fopen("/etc/resolv.conf", "r");
1055 if (f) {
vamsi krishnaa11d0732018-05-16 12:19:48 +05301056 char *pos, *pos2;
1057
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001058 while (fgets(tmp, sizeof(tmp), f)) {
1059 if (strncmp(tmp, "nameserver", 10) != 0)
1060 continue;
1061 pos = tmp + 10;
1062 while (*pos == ' ' || *pos == '\t')
1063 pos++;
1064 pos2 = pos;
1065 while (*pos2) {
1066 if (*pos2 == '\n' || *pos2 == '\r') {
1067 *pos2 = '\0';
1068 break;
1069 }
1070 pos2++;
1071 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07001072 if (!dns[0])
1073 strlcpy(dns, pos, sizeof(dns));
1074 else if (!sec_dns[0])
1075 strlcpy(sec_dns, pos, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001076 }
1077 fclose(f);
1078 }
1079#endif /* ANDROID */
1080
1081 snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s",
1082 is_dhcp, ip, mask, dns);
1083 buf[buf_len - 1] = '\0';
1084
1085 return 0;
1086}
1087
1088
1089
1090
1091int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf,
1092 size_t buf_len)
1093{
1094#ifdef __linux__
1095#ifdef ANDROID
1096 char cmd[200], result[1000], *pos, *end;
1097 FILE *f;
1098 size_t len;
1099
1100 snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname);
1101 f = popen(cmd, "r");
1102 if (f == NULL)
1103 return -1;
1104 len = fread(result, 1, sizeof(result) - 1, f);
1105 pclose(f);
1106 if (len == 0)
1107 return -1;
1108 result[len] = '\0';
1109 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result);
1110
1111 pos = strstr(result, "inet6 ");
1112 if (pos == NULL)
1113 return -1;
1114 pos += 6;
1115 end = strchr(pos, ' ');
1116 if (end)
1117 *end = '\0';
1118 end = strchr(pos, '/');
1119 if (end)
1120 *end = '\0';
1121 snprintf(buf, buf_len, "ip,%s", pos);
1122 buf[buf_len - 1] = '\0';
1123 return 0;
1124#else /* ANDROID */
1125 struct ifaddrs *ifaddr, *ifa;
1126 int res, found = 0;
1127 char host[NI_MAXHOST];
1128
1129 if (getifaddrs(&ifaddr) < 0) {
1130 perror("getifaddrs");
1131 return -1;
1132 }
1133
1134 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
1135 if (strcasecmp(ifname, ifa->ifa_name) != 0)
1136 continue;
1137 if (ifa->ifa_addr == NULL ||
1138 ifa->ifa_addr->sa_family != AF_INET6)
1139 continue;
1140
1141 res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
1142 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
1143 if (res != 0) {
1144 sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s",
1145 gai_strerror(res));
1146 continue;
1147 }
1148 if (strncmp(host, "fe80::", 6) == 0)
1149 continue; /* skip link-local */
1150
1151 sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host);
1152 found = 1;
1153 break;
1154 }
1155
1156 freeifaddrs(ifaddr);
1157
1158 if (found) {
1159 char *pos;
1160 pos = strchr(host, '%');
1161 if (pos)
1162 *pos = '\0';
1163 snprintf(buf, buf_len, "ip,%s", host);
1164 buf[buf_len - 1] = '\0';
1165 return 0;
1166 }
1167
1168#endif /* ANDROID */
1169#endif /* __linux__ */
1170 return -1;
1171}
1172
1173
Jouni Malinenf7222712019-06-13 01:50:21 +03001174static enum sigma_cmd_result cmd_sta_get_ip_config(struct sigma_dut *dut,
1175 struct sigma_conn *conn,
1176 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001177{
1178 const char *intf = get_param(cmd, "Interface");
1179 const char *ifname;
1180 char buf[200];
1181 const char *val;
1182 int type = 1;
1183
1184 if (intf == NULL)
1185 return -1;
1186
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001187 if (strcmp(intf, get_main_ifname(dut)) == 0)
1188 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001189 else
1190 ifname = intf;
1191
1192 /*
1193 * UCC may assume the IP address to be available immediately after
1194 * association without trying to run sta_get_ip_config multiple times.
1195 * Sigma CAPI does not specify this command as a block command that
1196 * would wait for the address to become available, but to pass tests
1197 * more reliably, it looks like such a wait may be needed here.
1198 */
1199 if (wait_ip_addr(dut, ifname, 15) < 0) {
1200 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address "
1201 "for sta_get_ip_config");
1202 /*
1203 * Try to continue anyway since many UCC tests do not really
1204 * care about the return value from here..
1205 */
1206 }
1207
1208 val = get_param(cmd, "Type");
1209 if (val)
1210 type = atoi(val);
1211 if (type == 2 || dut->last_set_ip_config_ipv6) {
1212 int i;
1213
1214 /*
1215 * Since we do not have proper wait for IPv6 addresses, use a
1216 * fixed two second delay here as a workaround for UCC script
1217 * assuming IPv6 address is available when this command returns.
1218 * Some scripts did not use Type,2 properly for IPv6, so include
1219 * also the cases where the previous sta_set_ip_config indicated
1220 * use of IPv6.
1221 */
1222 sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address");
1223 for (i = 0; i < 10; i++) {
1224 sleep(1);
1225 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0)
1226 {
1227 sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address");
1228 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1229#ifdef ANDROID
1230 sigma_dut_print(dut, DUT_MSG_INFO,
1231 "Adding IPv6 rule on Android");
1232 add_ipv6_rule(dut, intf);
1233#endif /* ANDROID */
1234
1235 return 0;
1236 }
1237 }
1238 }
1239 if (type == 1) {
1240 if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0)
1241 return -2;
1242 } else if (type == 2) {
1243 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0)
1244 return -2;
1245 } else {
1246 send_resp(dut, conn, SIGMA_ERROR,
1247 "errorCode,Unsupported address type");
1248 return 0;
1249 }
1250
1251 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1252 return 0;
1253}
1254
1255
1256static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname)
1257{
1258#ifdef __linux__
1259 char buf[200];
1260 char path[128];
1261 struct stat s;
1262
1263#ifdef ANDROID
1264 snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname);
1265#else /* ANDROID */
1266 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname);
1267#endif /* ANDROID */
1268 if (stat(path, &s) == 0) {
1269 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1270 sigma_dut_print(dut, DUT_MSG_INFO,
1271 "Kill previous DHCP client: %s", buf);
1272 if (system(buf) != 0)
1273 sigma_dut_print(dut, DUT_MSG_INFO,
1274 "Failed to kill DHCP client");
1275 unlink(path);
1276 sleep(1);
1277 } else {
1278 snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname);
1279
1280 if (stat(path, &s) == 0) {
1281 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1282 sigma_dut_print(dut, DUT_MSG_INFO,
1283 "Kill previous DHCP client: %s", buf);
1284 if (system(buf) != 0)
1285 sigma_dut_print(dut, DUT_MSG_INFO,
1286 "Failed to kill DHCP client");
1287 unlink(path);
1288 sleep(1);
1289 }
1290 }
1291#endif /* __linux__ */
1292}
1293
1294
1295static int start_dhcp_client(struct sigma_dut *dut, const char *ifname)
1296{
1297#ifdef __linux__
1298 char buf[200];
1299
1300#ifdef ANDROID
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301301 if (access("/system/bin/dhcpcd", F_OK) != -1) {
1302 snprintf(buf, sizeof(buf),
1303 "/system/bin/dhcpcd -b %s", ifname);
1304 } else if (access("/system/bin/dhcptool", F_OK) != -1) {
1305 snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname);
Ankita Bajaj8454e5d2019-04-05 16:04:55 +05301306 } else if (access("/vendor/bin/dhcpcd", F_OK) != -1) {
1307 snprintf(buf, sizeof(buf), "/vendor/bin/dhcpcd -b %s", ifname);
1308 } else if (access("/vendor/bin/dhcptool", F_OK) != -1) {
1309 snprintf(buf, sizeof(buf), "/vendor/bin/dhcptool %s", ifname);
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301310 } else {
1311 sigma_dut_print(dut, DUT_MSG_ERROR,
1312 "DHCP client program missing");
1313 return 0;
1314 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001315#else /* ANDROID */
1316 snprintf(buf, sizeof(buf),
1317 "dhclient -nw -pf /var/run/dhclient-%s.pid %s",
1318 ifname, ifname);
1319#endif /* ANDROID */
1320 sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf);
1321 if (system(buf) != 0) {
1322 snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname);
1323 if (system(buf) != 0) {
1324 sigma_dut_print(dut, DUT_MSG_INFO,
1325 "Failed to start DHCP client");
1326#ifndef ANDROID
1327 return -1;
1328#endif /* ANDROID */
1329 }
1330 }
1331#endif /* __linux__ */
1332
1333 return 0;
1334}
1335
1336
1337static int clear_ip_addr(struct sigma_dut *dut, const char *ifname)
1338{
1339#ifdef __linux__
1340 char buf[200];
1341
1342 snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname);
1343 if (system(buf) != 0) {
1344 sigma_dut_print(dut, DUT_MSG_INFO,
1345 "Failed to clear IP addresses");
1346 return -1;
1347 }
1348#endif /* __linux__ */
1349
1350 return 0;
1351}
1352
1353
1354#ifdef ANDROID
1355static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname)
1356{
1357 char cmd[200], *result, *pos;
1358 FILE *fp;
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301359 int tableid;
1360 size_t len, result_len = 1000;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001361
1362 snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s",
1363 ifname);
1364 fp = popen(cmd, "r");
1365 if (fp == NULL)
1366 return -1;
1367
1368 result = malloc(result_len);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301369 if (result == NULL) {
1370 fclose(fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001371 return -1;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301372 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001373
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301374 len = fread(result, 1, result_len - 1, fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001375 fclose(fp);
1376
1377 if (len == 0) {
1378 free(result);
1379 return -1;
1380 }
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301381 result[len] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001382
1383 pos = strstr(result, "table ");
1384 if (pos == NULL) {
1385 free(result);
1386 return -1;
1387 }
1388
1389 pos += strlen("table ");
1390 tableid = atoi(pos);
1391 if (tableid != 0) {
1392 if (system("ip -6 rule del prio 22000") != 0) {
1393 /* ignore any error */
1394 }
1395 snprintf(cmd, sizeof(cmd),
1396 "ip -6 rule add from all lookup %d prio 22000",
1397 tableid);
1398 if (system(cmd) != 0) {
1399 sigma_dut_print(dut, DUT_MSG_INFO,
1400 "Failed to run %s", cmd);
1401 free(result);
1402 return -1;
1403 }
1404 } else {
1405 sigma_dut_print(dut, DUT_MSG_INFO,
1406 "No Valid Table Id found %s", pos);
1407 free(result);
1408 return -1;
1409 }
1410 free(result);
1411
1412 return 0;
1413}
1414#endif /* ANDROID */
1415
1416
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301417int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
1418 const char *ip, const char *mask)
1419{
1420 char buf[200];
1421
1422 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
1423 ifname, ip, mask);
1424 return system(buf) == 0;
1425}
1426
1427
1428int set_ipv4_gw(struct sigma_dut *dut, const char *gw)
1429{
1430 char buf[200];
1431
1432 if (!is_ip_addr(gw)) {
1433 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw);
1434 return -1;
1435 }
1436
1437 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
1438 if (!dut->no_ip_addr_set && system(buf) != 0) {
1439 snprintf(buf, sizeof(buf), "ip ro re default via %s",
1440 gw);
1441 if (system(buf) != 0)
1442 return 0;
1443 }
1444
1445 return 1;
1446}
1447
1448
Jouni Malinenf7222712019-06-13 01:50:21 +03001449static enum sigma_cmd_result cmd_sta_set_ip_config(struct sigma_dut *dut,
1450 struct sigma_conn *conn,
1451 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001452{
1453 const char *intf = get_param(cmd, "Interface");
1454 const char *ifname;
1455 char buf[200];
1456 const char *val, *ip, *mask, *gw;
1457 int type = 1;
1458
1459 if (intf == NULL)
1460 return -1;
1461
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001462 if (strcmp(intf, get_main_ifname(dut)) == 0)
1463 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001464 else
1465 ifname = intf;
1466
1467 if (if_nametoindex(ifname) == 0) {
1468 send_resp(dut, conn, SIGMA_ERROR,
1469 "ErrorCode,Unknown interface");
1470 return 0;
1471 }
1472
1473 val = get_param(cmd, "Type");
1474 if (val) {
1475 type = atoi(val);
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301476 if (type < 1 || type > 3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001477 send_resp(dut, conn, SIGMA_ERROR,
1478 "ErrorCode,Unsupported address type");
1479 return 0;
1480 }
1481 }
1482
1483 dut->last_set_ip_config_ipv6 = 0;
1484
1485 val = get_param(cmd, "dhcp");
1486 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
1487 static_ip_file(0, NULL, NULL, NULL);
1488#ifdef __linux__
1489 if (type == 2) {
1490 dut->last_set_ip_config_ipv6 = 1;
1491 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
1492 "stateless address autoconfiguration");
1493#ifdef ANDROID
1494 /*
1495 * This sleep is required as the assignment in case of
1496 * Android is taking time and is done by the kernel.
1497 * The subsequent ping for IPv6 is impacting HS20 test
1498 * case.
1499 */
1500 sleep(2);
1501 add_ipv6_rule(dut, intf);
1502#endif /* ANDROID */
1503 /* Assume this happens by default */
1504 return 1;
1505 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301506 if (type != 3) {
1507 kill_dhcp_client(dut, ifname);
1508 if (start_dhcp_client(dut, ifname) < 0)
1509 return -2;
1510 } else {
1511 sigma_dut_print(dut, DUT_MSG_DEBUG,
1512 "Using FILS HLP DHCPv4 Rapid Commit");
1513 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001514
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001515 return 1;
1516#endif /* __linux__ */
1517 return -2;
1518 }
1519
1520 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301521 if (!ip) {
1522 send_resp(dut, conn, SIGMA_INVALID,
1523 "ErrorCode,Missing IP address");
1524 return 0;
1525 }
1526
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001527 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301528 if (!mask) {
1529 send_resp(dut, conn, SIGMA_INVALID,
1530 "ErrorCode,Missing subnet mask");
1531 return 0;
1532 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001533
1534 if (type == 2) {
1535 int net = atoi(mask);
1536
1537 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
1538 return -1;
1539
1540 if (dut->no_ip_addr_set) {
1541 snprintf(buf, sizeof(buf),
1542 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
1543 ifname);
1544 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1545 if (system(buf) != 0) {
1546 sigma_dut_print(dut, DUT_MSG_DEBUG,
1547 "Failed to disable IPv6 address before association");
1548 }
1549 } else {
Veerendranath Jakkam176181c2020-05-16 00:19:21 +05301550 if (set_ipv6_addr(dut, ip, mask, ifname) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001551 send_resp(dut, conn, SIGMA_ERROR,
1552 "ErrorCode,Failed to set IPv6 address");
1553 return 0;
1554 }
1555 }
1556
1557 dut->last_set_ip_config_ipv6 = 1;
1558 static_ip_file(6, ip, mask, NULL);
1559 return 1;
1560 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301561 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001562 return -1;
1563 }
1564
1565 kill_dhcp_client(dut, ifname);
1566
1567 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301568 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001569 send_resp(dut, conn, SIGMA_ERROR,
1570 "ErrorCode,Failed to set IP address");
1571 return 0;
1572 }
1573 }
1574
1575 gw = get_param(cmd, "defaultGateway");
1576 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301577 if (set_ipv4_gw(dut, gw) < 1) {
1578 send_resp(dut, conn, SIGMA_ERROR,
1579 "ErrorCode,Failed to set default gateway");
1580 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001581 }
1582 }
1583
1584 val = get_param(cmd, "primary-dns");
1585 if (val) {
1586 /* TODO */
1587 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1588 "setting", val);
1589 }
1590
1591 val = get_param(cmd, "secondary-dns");
1592 if (val) {
1593 /* TODO */
1594 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1595 "setting", val);
1596 }
1597
1598 static_ip_file(4, ip, mask, gw);
1599
1600 return 1;
1601}
1602
1603
Jouni Malinenf7222712019-06-13 01:50:21 +03001604static enum sigma_cmd_result cmd_sta_get_info(struct sigma_dut *dut,
1605 struct sigma_conn *conn,
1606 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001607{
1608 /* const char *intf = get_param(cmd, "Interface"); */
1609 /* TODO: could report more details here */
1610 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1611 return 0;
1612}
1613
1614
Jouni Malinenf7222712019-06-13 01:50:21 +03001615static enum sigma_cmd_result cmd_sta_get_mac_address(struct sigma_dut *dut,
1616 struct sigma_conn *conn,
1617 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001618{
1619 /* const char *intf = get_param(cmd, "Interface"); */
1620 char addr[20], resp[50];
1621
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301622 if (dut->dev_role == DEVROLE_STA_CFON)
1623 return sta_cfon_get_mac_address(dut, conn, cmd);
1624
Jouni Malinen9540e012019-11-05 17:08:42 +02001625 start_sta_mode(dut);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001626 if (get_wpa_status(get_station_ifname(dut), "address",
1627 addr, sizeof(addr)) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001628 return -2;
1629
1630 snprintf(resp, sizeof(resp), "mac,%s", addr);
1631 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1632 return 0;
1633}
1634
1635
Jouni Malinenf7222712019-06-13 01:50:21 +03001636static enum sigma_cmd_result cmd_sta_is_connected(struct sigma_dut *dut,
1637 struct sigma_conn *conn,
1638 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001639{
1640 /* const char *intf = get_param(cmd, "Interface"); */
1641 int connected = 0;
1642 char result[32];
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001643 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001644 sizeof(result)) < 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001645 sigma_dut_print(dut, DUT_MSG_INFO,
1646 "Could not get interface %s status",
1647 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001648 return -2;
1649 }
1650
1651 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1652 if (strncmp(result, "COMPLETED", 9) == 0)
1653 connected = 1;
1654
1655 if (connected)
1656 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1657 else
1658 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1659
1660 return 0;
1661}
1662
1663
Jouni Malinenf7222712019-06-13 01:50:21 +03001664static enum sigma_cmd_result
1665cmd_sta_verify_ip_connection(struct sigma_dut *dut, struct sigma_conn *conn,
1666 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001667{
1668 /* const char *intf = get_param(cmd, "Interface"); */
1669 const char *dst, *timeout;
1670 int wait_time = 90;
1671 char buf[100];
1672 int res;
1673
1674 dst = get_param(cmd, "destination");
1675 if (dst == NULL || !is_ip_addr(dst))
1676 return -1;
1677
1678 timeout = get_param(cmd, "timeout");
1679 if (timeout) {
1680 wait_time = atoi(timeout);
1681 if (wait_time < 1)
1682 wait_time = 1;
1683 }
1684
1685 /* TODO: force renewal of IP lease if DHCP is enabled */
1686
1687 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1688 res = system(buf);
1689 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1690 if (res == 0)
1691 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1692 else if (res == 256)
1693 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1694 else
1695 return -2;
1696
1697 return 0;
1698}
1699
1700
Jouni Malinenf7222712019-06-13 01:50:21 +03001701static enum sigma_cmd_result cmd_sta_get_bssid(struct sigma_dut *dut,
1702 struct sigma_conn *conn,
1703 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001704{
1705 /* const char *intf = get_param(cmd, "Interface"); */
1706 char bssid[20], resp[50];
1707
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001708 if (get_wpa_status(get_station_ifname(dut), "bssid",
1709 bssid, sizeof(bssid)) < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001710 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001711
1712 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1713 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1714 return 0;
1715}
1716
1717
1718#ifdef __SAMSUNG__
1719static int add_use_network(const char *ifname)
1720{
1721 char buf[100];
1722
1723 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1724 wpa_command(ifname, buf);
1725 return 0;
1726}
1727#endif /* __SAMSUNG__ */
1728
1729
1730static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1731 const char *ifname, struct sigma_cmd *cmd)
1732{
1733 const char *ssid = get_param(cmd, "ssid");
1734 int id;
1735 const char *val;
1736
1737 if (ssid == NULL)
1738 return -1;
1739
1740 start_sta_mode(dut);
1741
1742#ifdef __SAMSUNG__
1743 add_use_network(ifname);
1744#endif /* __SAMSUNG__ */
1745
1746 id = add_network(ifname);
1747 if (id < 0)
1748 return -2;
1749 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1750
1751 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1752 return -2;
1753
1754 dut->infra_network_id = id;
1755 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1756
1757 val = get_param(cmd, "program");
1758 if (!val)
1759 val = get_param(cmd, "prog");
1760 if (val && strcasecmp(val, "hs2") == 0) {
1761 char buf[100];
1762 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1763 wpa_command(ifname, buf);
1764
1765 val = get_param(cmd, "prefer");
1766 if (val && atoi(val) > 0)
1767 set_network(ifname, id, "priority", "1");
1768 }
1769
1770 return id;
1771}
1772
1773
Jouni Malinenf7222712019-06-13 01:50:21 +03001774static enum sigma_cmd_result cmd_sta_set_encryption(struct sigma_dut *dut,
1775 struct sigma_conn *conn,
1776 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001777{
1778 const char *intf = get_param(cmd, "Interface");
1779 const char *ssid = get_param(cmd, "ssid");
1780 const char *type = get_param(cmd, "encpType");
1781 const char *ifname;
1782 char buf[200];
1783 int id;
1784
1785 if (intf == NULL || ssid == NULL)
1786 return -1;
1787
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001788 if (strcmp(intf, get_main_ifname(dut)) == 0)
1789 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001790 else
1791 ifname = intf;
1792
1793 id = add_network_common(dut, conn, ifname, cmd);
1794 if (id < 0)
1795 return id;
1796
1797 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1798 return -2;
1799
1800 if (type && strcasecmp(type, "wep") == 0) {
1801 const char *val;
1802 int i;
1803
1804 val = get_param(cmd, "activeKey");
1805 if (val) {
1806 int keyid;
1807 keyid = atoi(val);
1808 if (keyid < 1 || keyid > 4)
1809 return -1;
1810 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1811 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1812 return -2;
1813 }
1814
1815 for (i = 0; i < 4; i++) {
1816 snprintf(buf, sizeof(buf), "key%d", i + 1);
1817 val = get_param(cmd, buf);
1818 if (val == NULL)
1819 continue;
1820 snprintf(buf, sizeof(buf), "wep_key%d", i);
1821 if (set_network(ifname, id, buf, val) < 0)
1822 return -2;
1823 }
1824 }
1825
1826 return 1;
1827}
1828
1829
Jouni Malinene4fde732019-03-25 22:29:37 +02001830static int set_akm_suites(struct sigma_dut *dut, const char *ifname,
1831 int id, const char *val)
1832{
1833 char key_mgmt[200], *end, *pos;
1834 const char *in_pos = val;
1835
Jouni Malinen8179fee2019-03-28 03:19:47 +02001836 dut->akm_values = 0;
Jouni Malinene4fde732019-03-25 22:29:37 +02001837 pos = key_mgmt;
1838 end = pos + sizeof(key_mgmt);
1839 while (*in_pos) {
1840 int res, akm = atoi(in_pos);
1841 const char *str;
1842
Jouni Malinen8179fee2019-03-28 03:19:47 +02001843 if (akm >= 0 && akm < 32)
1844 dut->akm_values |= 1 << akm;
1845
Jouni Malinene4fde732019-03-25 22:29:37 +02001846 switch (akm) {
1847 case AKM_WPA_EAP:
1848 str = "WPA-EAP";
1849 break;
1850 case AKM_WPA_PSK:
1851 str = "WPA-PSK";
1852 break;
1853 case AKM_FT_EAP:
1854 str = "FT-EAP";
1855 break;
1856 case AKM_FT_PSK:
1857 str = "FT-PSK";
1858 break;
1859 case AKM_EAP_SHA256:
1860 str = "WPA-EAP-SHA256";
1861 break;
1862 case AKM_PSK_SHA256:
1863 str = "WPA-PSK-SHA256";
1864 break;
1865 case AKM_SAE:
1866 str = "SAE";
1867 break;
1868 case AKM_FT_SAE:
1869 str = "FT-SAE";
1870 break;
1871 case AKM_SUITE_B:
1872 str = "WPA-EAP-SUITE-B-192";
1873 break;
1874 case AKM_FT_SUITE_B:
1875 str = "FT-EAP-SHA384";
1876 break;
1877 case AKM_FILS_SHA256:
1878 str = "FILS-SHA256";
1879 break;
1880 case AKM_FILS_SHA384:
1881 str = "FILS-SHA384";
1882 break;
1883 case AKM_FT_FILS_SHA256:
1884 str = "FT-FILS-SHA256";
1885 break;
1886 case AKM_FT_FILS_SHA384:
1887 str = "FT-FILS-SHA384";
1888 break;
1889 default:
1890 sigma_dut_print(dut, DUT_MSG_ERROR,
1891 "Unsupported AKMSuitetype %d", akm);
1892 return -1;
1893 }
1894
1895 res = snprintf(pos, end - pos, "%s%s",
1896 pos == key_mgmt ? "" : " ", str);
1897 if (res < 0 || res >= end - pos)
1898 return -1;
1899 pos += res;
1900
1901 in_pos = strchr(in_pos, ';');
1902 if (!in_pos)
1903 break;
1904 while (*in_pos == ';')
1905 in_pos++;
1906 }
1907 sigma_dut_print(dut, DUT_MSG_DEBUG, "AKMSuiteType %s --> %s",
1908 val, key_mgmt);
1909 return set_network(ifname, id, "key_mgmt", key_mgmt);
1910}
1911
1912
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001913static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1914 const char *ifname, struct sigma_cmd *cmd)
1915{
1916 const char *val;
1917 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001918 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001919 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301920 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001921
1922 id = add_network_common(dut, conn, ifname, cmd);
1923 if (id < 0)
1924 return id;
1925
Jouni Malinen47dcc952017-10-09 16:43:24 +03001926 val = get_param(cmd, "Type");
1927 owe = val && strcasecmp(val, "OWE") == 0;
1928
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001929 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001930 if (!val && owe)
1931 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001932 if (val == NULL) {
Jouni Malinene4fde732019-03-25 22:29:37 +02001933 /* keyMgmtType is being replaced with AKMSuiteType, so ignore
1934 * this missing parameter and assume proto=WPA2. */
1935 if (set_network(ifname, id, "proto", "WPA2") < 0)
1936 return ERROR_SEND_STATUS;
1937 } else if (strcasecmp(val, "wpa") == 0 ||
1938 strcasecmp(val, "wpa-psk") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001939 if (set_network(ifname, id, "proto", "WPA") < 0)
1940 return -2;
1941 } else if (strcasecmp(val, "wpa2") == 0 ||
1942 strcasecmp(val, "wpa2-psk") == 0 ||
1943 strcasecmp(val, "wpa2-ft") == 0 ||
1944 strcasecmp(val, "wpa2-sha256") == 0) {
1945 if (set_network(ifname, id, "proto", "WPA2") < 0)
1946 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301947 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1948 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001949 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1950 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001951 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301952 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001953 if (set_network(ifname, id, "proto", "WPA2") < 0)
1954 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001955 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001956 } else {
1957 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1958 return 0;
1959 }
1960
1961 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001962 if (val) {
1963 cipher_set = 1;
1964 if (strcasecmp(val, "tkip") == 0) {
1965 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1966 return -2;
1967 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1968 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1969 return -2;
1970 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1971 if (set_network(ifname, id, "pairwise",
1972 "CCMP TKIP") < 0)
1973 return -2;
1974 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1975 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1976 return -2;
1977 if (set_network(ifname, id, "group", "GCMP") < 0)
1978 return -2;
1979 } else {
1980 send_resp(dut, conn, SIGMA_ERROR,
1981 "errorCode,Unrecognized encpType value");
1982 return 0;
1983 }
1984 }
1985
1986 val = get_param(cmd, "PairwiseCipher");
1987 if (val) {
1988 cipher_set = 1;
1989 /* TODO: Support space separated list */
1990 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1991 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
1992 return -2;
1993 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1994 if (set_network(ifname, id, "pairwise",
1995 "CCMP-256") < 0)
1996 return -2;
1997 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1998 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1999 return -2;
2000 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2001 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
2002 return -2;
2003 } else {
2004 send_resp(dut, conn, SIGMA_ERROR,
2005 "errorCode,Unrecognized PairwiseCipher value");
2006 return 0;
2007 }
2008 }
2009
Jouni Malinen47dcc952017-10-09 16:43:24 +03002010 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03002011 send_resp(dut, conn, SIGMA_ERROR,
2012 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002013 return 0;
2014 }
Jouni Malinenad395a22017-09-01 21:13:46 +03002015
2016 val = get_param(cmd, "GroupCipher");
2017 if (val) {
2018 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2019 if (set_network(ifname, id, "group", "GCMP-256") < 0)
2020 return -2;
2021 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2022 if (set_network(ifname, id, "group", "CCMP-256") < 0)
2023 return -2;
2024 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2025 if (set_network(ifname, id, "group", "GCMP") < 0)
2026 return -2;
2027 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2028 if (set_network(ifname, id, "group", "CCMP") < 0)
2029 return -2;
2030 } else {
2031 send_resp(dut, conn, SIGMA_ERROR,
2032 "errorCode,Unrecognized GroupCipher value");
2033 return 0;
2034 }
2035 }
2036
Jouni Malinen7b239522017-09-14 21:37:18 +03002037 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03002038 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03002039 const char *cipher;
2040
2041 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
2042 cipher = "BIP-GMAC-256";
2043 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
2044 cipher = "BIP-CMAC-256";
2045 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
2046 cipher = "BIP-GMAC-128";
2047 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
2048 cipher = "AES-128-CMAC";
2049 } else {
2050 send_resp(dut, conn, SIGMA_INVALID,
2051 "errorCode,Unsupported GroupMgntCipher");
2052 return 0;
2053 }
2054 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
2055 send_resp(dut, conn, SIGMA_INVALID,
2056 "errorCode,Failed to set GroupMgntCipher");
2057 return 0;
2058 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002059 }
2060
Jouni Malinene4fde732019-03-25 22:29:37 +02002061 val = get_param(cmd, "AKMSuiteType");
2062 if (val && set_akm_suites(dut, ifname, id, val) < 0)
2063 return ERROR_SEND_STATUS;
2064
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002065 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302066
2067 if (dut->program == PROGRAM_OCE) {
2068 dut->sta_pmf = STA_PMF_OPTIONAL;
2069 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2070 return -2;
2071 }
2072
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002073 val = get_param(cmd, "PMF");
2074 if (val) {
2075 if (strcasecmp(val, "Required") == 0 ||
2076 strcasecmp(val, "Forced_Required") == 0) {
2077 dut->sta_pmf = STA_PMF_REQUIRED;
2078 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2079 return -2;
2080 } else if (strcasecmp(val, "Optional") == 0) {
2081 dut->sta_pmf = STA_PMF_OPTIONAL;
2082 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2083 return -2;
2084 } else if (strcasecmp(val, "Disabled") == 0 ||
Kiran Kumar Lokere07da3b22018-12-16 22:42:49 -08002085 strcasecmp(val, "Disable") == 0 ||
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002086 strcasecmp(val, "Forced_Disabled") == 0) {
2087 dut->sta_pmf = STA_PMF_DISABLED;
2088 } else {
2089 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
2090 return 0;
2091 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05302092 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02002093 dut->sta_pmf = STA_PMF_REQUIRED;
2094 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2095 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002096 }
2097
Jouni Malinen0165c7f2020-03-26 11:51:58 +02002098 val = get_param(cmd, "BeaconProtection");
2099 if (val && atoi(val) == 1 &&
2100 set_network(ifname, id, "beacon_prot", "1") < 0)
2101 return ERROR_SEND_STATUS;
2102
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002103 return id;
2104}
2105
2106
Jouni Malinenf7222712019-06-13 01:50:21 +03002107static enum sigma_cmd_result cmd_sta_set_psk(struct sigma_dut *dut,
2108 struct sigma_conn *conn,
2109 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002110{
2111 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002112 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002113 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002114 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002115 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002116 const char *ifname, *val, *alg;
2117 int id;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002118 char buf[50];
Jouni Malinen11e55212019-11-22 21:46:59 +02002119 int sae_pwe = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002120
2121 if (intf == NULL)
2122 return -1;
2123
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002124 if (strcmp(intf, get_main_ifname(dut)) == 0)
2125 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002126 else
2127 ifname = intf;
2128
2129 id = set_wpa_common(dut, conn, ifname, cmd);
2130 if (id < 0)
2131 return id;
2132
2133 val = get_param(cmd, "keyMgmtType");
2134 alg = get_param(cmd, "micAlg");
2135
Jouni Malinen992a81e2017-08-22 13:57:47 +03002136 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002137 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002138 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2139 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002140 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002141 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2142 return -2;
2143 }
2144 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2145 sigma_dut_print(dut, DUT_MSG_ERROR,
2146 "Failed to clear sae_groups to default");
2147 return -2;
2148 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002149 if (!pmf) {
2150 dut->sta_pmf = STA_PMF_REQUIRED;
2151 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2152 return -2;
2153 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002154 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2155 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2156 if (set_network(ifname, id, "key_mgmt",
2157 "FT-SAE FT-PSK") < 0)
2158 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002159 } else if (!akm) {
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002160 if (set_network(ifname, id, "key_mgmt",
2161 "SAE WPA-PSK") < 0)
2162 return -2;
2163 }
2164 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2165 sigma_dut_print(dut, DUT_MSG_ERROR,
2166 "Failed to clear sae_groups to default");
2167 return -2;
2168 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002169 if (!pmf) {
2170 dut->sta_pmf = STA_PMF_OPTIONAL;
2171 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2172 return -2;
2173 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002174 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002175 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2176 return -2;
2177 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2178 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2179 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302180 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2181 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2182 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002183 } else if (!akm &&
2184 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2185 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002186 if (set_network(ifname, id, "key_mgmt",
2187 "WPA-PSK WPA-PSK-SHA256") < 0)
2188 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002189 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002190 if (set_network(ifname, id, "key_mgmt",
2191 "WPA-PSK WPA-PSK-SHA256") < 0)
2192 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002193 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002194 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2195 return -2;
2196 }
2197
2198 val = get_param(cmd, "passPhrase");
2199 if (val == NULL)
2200 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002201 if (type && strcasecmp(type, "SAE") == 0) {
2202 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2203 return -2;
2204 } else {
2205 if (set_network_quoted(ifname, id, "psk", val) < 0)
2206 return -2;
2207 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002208
Jouni Malinen78d10c42019-03-25 22:34:32 +02002209 val = get_param(cmd, "PasswordId");
2210 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2211 return ERROR_SEND_STATUS;
2212
Jouni Malinen992a81e2017-08-22 13:57:47 +03002213 val = get_param(cmd, "ECGroupID");
2214 if (val) {
Jouni Malinenb54f0df2019-12-12 01:57:29 +02002215 snprintf(buf, sizeof(buf), "SET sae_groups %s", val);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002216 if (wpa_command(ifname, buf) != 0) {
2217 sigma_dut_print(dut, DUT_MSG_ERROR,
2218 "Failed to clear sae_groups");
2219 return -2;
2220 }
2221 }
2222
Jouni Malinen68143132017-09-02 02:34:08 +03002223 val = get_param(cmd, "InvalidSAEElement");
2224 if (val) {
2225 free(dut->sae_commit_override);
2226 dut->sae_commit_override = strdup(val);
2227 }
2228
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002229 val = get_param(cmd, "PMKID_Include");
2230 if (val) {
2231 snprintf(buf, sizeof(buf), "SET sae_pmkid_in_assoc %d",
2232 get_enable_disable(val));
2233 wpa_command(intf, buf);
2234 }
2235
Jouni Malineneeb43d32019-12-06 17:40:07 +02002236 val = get_param(cmd, "IgnoreH2E_RSNXE_BSSMemSel");
2237 if (val) {
2238 snprintf(buf, sizeof(buf), "SET ignore_sae_h2e_only %d",
2239 get_enable_disable(val));
2240 wpa_command(intf, buf);
2241 }
2242
Jouni Malinenf2348d22019-12-07 11:52:55 +02002243 val = get_param(cmd, "ECGroupID_RGE");
2244 if (val) {
2245 snprintf(buf, sizeof(buf), "SET extra_sae_rejected_groups %s",
2246 val);
2247 wpa_command(intf, buf);
2248 }
2249
Jouni Malinen99e55022019-12-07 13:59:41 +02002250 val = get_param(cmd, "RSNXE_Content");
2251 if (val) {
2252 const char *param;
2253
2254 if (strncasecmp(val, "AssocReq:", 9) == 0) {
2255 val += 9;
2256 param = "rsnxe_override_assoc";
2257 } else if (strncasecmp(val, "EapolM2:", 8) == 0) {
2258 val += 8;
2259 param = "rsnxe_override_eapol";
2260 } else {
2261 send_resp(dut, conn, SIGMA_ERROR,
2262 "errorCode,Unsupported RSNXE_Content value");
2263 return STATUS_SENT_ERROR;
2264 }
2265 snprintf(buf, sizeof(buf), "SET %s %s", param, val);
2266 wpa_command(intf, buf);
2267 }
2268
Jouni Malinen11e55212019-11-22 21:46:59 +02002269 val = get_param(cmd, "sae_pwe");
2270 if (val) {
2271 if (strcasecmp(val, "h2e") == 0) {
2272 dut->sae_pwe = SAE_PWE_H2E;
Jouni Malinen7244a412019-12-07 11:54:10 +02002273 } else if (strcasecmp(val, "loop") == 0 ||
2274 strcasecmp(val, "looping") == 0) {
Jouni Malinen11e55212019-11-22 21:46:59 +02002275 dut->sae_pwe = SAE_PWE_LOOP;
2276 } else {
2277 send_resp(dut, conn, SIGMA_ERROR,
2278 "errorCode,Unsupported sae_pwe value");
2279 return STATUS_SENT_ERROR;
2280 }
2281 }
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302282
2283 val = get_param(cmd, "Clear_RSNXE");
2284 if (val && strcmp(val, "1") == 0 &&
2285 (wpa_command(intf, "SET rsnxe_override_assoc ") ||
2286 wpa_command(intf, "SET rsnxe_override_eapol "))) {
2287 send_resp(dut, conn, SIGMA_ERROR,
2288 "errorCode,Failed to clear RSNXE");
Jouni Malinenb11498c2020-08-03 11:05:53 +03002289 return STATUS_SENT_ERROR;
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302290 }
2291
Jouni Malinenc0078772020-03-04 21:23:16 +02002292 if (dut->sae_pwe == SAE_PWE_LOOP && get_param(cmd, "PasswordId"))
2293 sae_pwe = 3;
2294 else if (dut->sae_pwe == SAE_PWE_LOOP)
Jouni Malinen11e55212019-11-22 21:46:59 +02002295 sae_pwe = 0;
2296 else if (dut->sae_pwe == SAE_PWE_H2E)
2297 sae_pwe = 1;
2298 else if (dut->sae_h2e_default)
2299 sae_pwe = 2;
2300 snprintf(buf, sizeof(buf), "SET sae_pwe %d", sae_pwe);
2301 if (sae_pwe >= 0 && wpa_command(ifname, buf) != 0)
2302 return ERROR_SEND_STATUS;
2303
Veerendranath Jakkam0316be12020-06-23 20:11:41 +05302304 val = get_param(cmd, "sae_pk");
2305 if (val && strcmp(val, "0") == 0 &&
2306 set_network(ifname, id, "sae_pk", "2") < 0)
2307 return ERROR_SEND_STATUS;
2308
Veerendranath Jakkama9177042020-08-10 00:14:03 +05302309 val = get_param(cmd, "sae_pk_only");
2310 if (val && strcmp(val, "1") == 0 &&
2311 set_network(ifname, id, "sae_pk", "1") < 0)
2312 return ERROR_SEND_STATUS;
2313
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002314 if (dut->program == PROGRAM_60GHZ && network_mode &&
2315 strcasecmp(network_mode, "PBSS") == 0 &&
2316 set_network(ifname, id, "pbss", "1") < 0)
2317 return -2;
2318
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002319 return 1;
2320}
2321
2322
Jouni Malinen8ac93452019-08-14 15:19:13 +03002323static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2324 struct sigma_conn *conn,
2325 const char *ifname, int id)
2326{
2327 char buf[200];
2328
2329 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2330 if (!file_exists(buf))
2331 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2332 if (!file_exists(buf))
2333 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2334 if (!file_exists(buf)) {
2335 char msg[300];
2336
2337 snprintf(msg, sizeof(msg),
2338 "ErrorCode,trustedRootCA system store (%s) not found",
2339 buf);
2340 send_resp(dut, conn, SIGMA_ERROR, msg);
2341 return STATUS_SENT_ERROR;
2342 }
2343
2344 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2345 return ERROR_SEND_STATUS;
2346
2347 return SUCCESS_SEND_STATUS;
2348}
2349
2350
2351static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2352 struct sigma_conn *conn,
2353 const char *ifname, int id,
2354 const char *val)
2355{
2356 char buf[200];
2357#ifdef ANDROID
2358 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2359 int length;
2360#endif /* ANDROID */
2361
2362 if (strcmp(val, "DEFAULT") == 0)
2363 return set_trust_root_system(dut, conn, ifname, id);
2364
2365#ifdef ANDROID
2366 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2367 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2368 if (length > 0) {
2369 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2370 buf);
2371 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2372 goto ca_cert_selected;
2373 }
2374#endif /* ANDROID */
2375
2376 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2377#ifdef __linux__
2378 if (!file_exists(buf)) {
2379 char msg[300];
2380
2381 snprintf(msg, sizeof(msg),
2382 "ErrorCode,trustedRootCA file (%s) not found", buf);
2383 send_resp(dut, conn, SIGMA_ERROR, msg);
2384 return STATUS_SENT_ERROR;
2385 }
2386#endif /* __linux__ */
2387#ifdef ANDROID
2388ca_cert_selected:
2389#endif /* ANDROID */
2390 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2391 return ERROR_SEND_STATUS;
2392
2393 return SUCCESS_SEND_STATUS;
2394}
2395
2396
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002397static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302398 const char *ifname, int username_identity,
2399 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002400{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002401 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002402 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002403 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002404 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002405 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002406
2407 id = set_wpa_common(dut, conn, ifname, cmd);
2408 if (id < 0)
2409 return id;
2410
2411 val = get_param(cmd, "keyMgmtType");
2412 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302413 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002414 trust_root = get_param(cmd, "trustedRootCA");
2415 domain = get_param(cmd, "Domain");
2416 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002417
Jouni Malinenad395a22017-09-01 21:13:46 +03002418 if (val && strcasecmp(val, "SuiteB") == 0) {
2419 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2420 0)
2421 return -2;
2422 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002423 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2424 return -2;
2425 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2426 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2427 return -2;
2428 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2429 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2430 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002431 } else if (!akm &&
2432 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2433 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002434 if (set_network(ifname, id, "key_mgmt",
2435 "WPA-EAP WPA-EAP-SHA256") < 0)
2436 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302437 } else if (akm && atoi(akm) == 14) {
2438 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2439 dut->sta_pmf == STA_PMF_REQUIRED) {
2440 if (set_network(ifname, id, "key_mgmt",
2441 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2442 return -2;
2443 } else {
2444 if (set_network(ifname, id, "key_mgmt",
2445 "WPA-EAP FILS-SHA256") < 0)
2446 return -2;
2447 }
2448
Jouni Malinen8179fee2019-03-28 03:19:47 +02002449 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302450 } else if (akm && atoi(akm) == 15) {
2451 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2452 dut->sta_pmf == STA_PMF_REQUIRED) {
2453 if (set_network(ifname, id, "key_mgmt",
2454 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2455 return -2;
2456 } else {
2457 if (set_network(ifname, id, "key_mgmt",
2458 "WPA-EAP FILS-SHA384") < 0)
2459 return -2;
2460 }
2461
Jouni Malinen8179fee2019-03-28 03:19:47 +02002462 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002463 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002464 if (set_network(ifname, id, "key_mgmt",
2465 "WPA-EAP WPA-EAP-SHA256") < 0)
2466 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002467 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002468 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2469 return -2;
2470 }
2471
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002472 if (trust_root) {
2473 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2474 !domain_suffix) {
2475 send_resp(dut, conn, SIGMA_ERROR,
2476 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2477 return STATUS_SENT_ERROR;
2478 }
2479 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002480 if (res != SUCCESS_SEND_STATUS)
2481 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002482 }
2483
Jouni Malinen53264f62019-05-03 13:04:40 +03002484 val = get_param(cmd, "ServerCert");
2485 if (val) {
2486 FILE *f;
2487 char *result = NULL, *pos;
2488
2489 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2490 val);
2491 f = fopen(buf, "r");
2492 if (f) {
2493 result = fgets(buf, sizeof(buf), f);
2494 fclose(f);
2495 }
2496 if (!result) {
2497 snprintf(buf2, sizeof(buf2),
2498 "ErrorCode,ServerCert hash could not be read from %s",
2499 buf);
2500 send_resp(dut, conn, SIGMA_ERROR, buf2);
2501 return STATUS_SENT_ERROR;
2502 }
2503 pos = strchr(buf, '\n');
2504 if (pos)
2505 *pos = '\0';
2506 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2507 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2508 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002509
2510 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2511 if (file_exists(buf)) {
2512 sigma_dut_print(dut, DUT_MSG_DEBUG,
2513 "TOD policy enabled for the configured ServerCert hash");
2514 dut->sta_tod_policy = 1;
2515 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002516 }
2517
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002518 if (domain &&
2519 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002520 return ERROR_SEND_STATUS;
2521
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002522 if (domain_suffix &&
2523 set_network_quoted(ifname, id, "domain_suffix_match",
2524 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002525 return ERROR_SEND_STATUS;
2526
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302527 if (username_identity) {
2528 val = get_param(cmd, "username");
2529 if (val) {
2530 if (set_network_quoted(ifname, id, "identity", val) < 0)
2531 return -2;
2532 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002533
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302534 val = get_param(cmd, "password");
2535 if (val) {
2536 if (set_network_quoted(ifname, id, "password", val) < 0)
2537 return -2;
2538 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002539 }
2540
Jouni Malinen8179fee2019-03-28 03:19:47 +02002541 if (dut->akm_values &
2542 ((1 << AKM_FILS_SHA256) |
2543 (1 << AKM_FILS_SHA384) |
2544 (1 << AKM_FT_FILS_SHA256) |
2545 (1 << AKM_FT_FILS_SHA384)))
2546 erp = 1;
2547 if (erp && set_network(ifname, id, "erp", "1") < 0)
2548 return ERROR_SEND_STATUS;
2549
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002550 dut->sta_associate_wait_connect = 1;
2551
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002552 return id;
2553}
2554
2555
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002556static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2557{
2558 const char *val;
2559
2560 if (!cipher)
2561 return 0;
2562
2563 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2564 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2565 else if (strcasecmp(cipher,
2566 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2567 val = "ECDHE-RSA-AES256-GCM-SHA384";
2568 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2569 val = "DHE-RSA-AES256-GCM-SHA384";
2570 else if (strcasecmp(cipher,
2571 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2572 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2573 else
2574 return -1;
2575
2576 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2577 set_network_quoted(ifname, id, "phase1", "");
2578
2579 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2580}
2581
2582
Jouni Malinenf7222712019-06-13 01:50:21 +03002583static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2584 struct sigma_conn *conn,
2585 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002586{
2587 const char *intf = get_param(cmd, "Interface");
2588 const char *ifname, *val;
2589 int id;
2590 char buf[200];
2591#ifdef ANDROID
2592 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2593 int length;
2594 int jb_or_newer = 0;
2595 char prop[PROPERTY_VALUE_MAX];
2596#endif /* ANDROID */
2597
2598 if (intf == NULL)
2599 return -1;
2600
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002601 if (strcmp(intf, get_main_ifname(dut)) == 0)
2602 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002603 else
2604 ifname = intf;
2605
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302606 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002607 if (id < 0)
2608 return id;
2609
2610 if (set_network(ifname, id, "eap", "TLS") < 0)
2611 return -2;
2612
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302613 if (!get_param(cmd, "username") &&
2614 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002615 "wifi-user@wifilabs.local") < 0)
2616 return -2;
2617
2618 val = get_param(cmd, "clientCertificate");
2619 if (val == NULL)
2620 return -1;
2621#ifdef ANDROID
2622 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2623 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2624 if (length < 0) {
2625 /*
2626 * JB started reporting keystore type mismatches, so retry with
2627 * the GET_PUBKEY command if the generic GET fails.
2628 */
2629 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2630 buf, kvalue);
2631 }
2632
2633 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2634 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2635 if (strncmp(prop, "4.0", 3) != 0)
2636 jb_or_newer = 1;
2637 } else
2638 jb_or_newer = 1; /* assume newer */
2639
2640 if (jb_or_newer && length > 0) {
2641 sigma_dut_print(dut, DUT_MSG_INFO,
2642 "Use Android keystore [%s]", buf);
2643 if (set_network(ifname, id, "engine", "1") < 0)
2644 return -2;
2645 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2646 return -2;
2647 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2648 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2649 return -2;
2650 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2651 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2652 return -2;
2653 return 1;
2654 } else if (length > 0) {
2655 sigma_dut_print(dut, DUT_MSG_INFO,
2656 "Use Android keystore [%s]", buf);
2657 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2658 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2659 return -2;
2660 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2661 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2662 return -2;
2663 return 1;
2664 }
2665#endif /* ANDROID */
2666
2667 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2668#ifdef __linux__
2669 if (!file_exists(buf)) {
2670 char msg[300];
2671 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2672 "(%s) not found", buf);
2673 send_resp(dut, conn, SIGMA_ERROR, msg);
2674 return -3;
2675 }
2676#endif /* __linux__ */
2677 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2678 return -2;
2679 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2680 return -2;
2681
2682 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2683 return -2;
2684
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002685 val = get_param(cmd, "keyMgmtType");
2686 if (val && strcasecmp(val, "SuiteB") == 0) {
2687 val = get_param(cmd, "CertType");
2688 if (val && strcasecmp(val, "RSA") == 0) {
2689 if (set_network_quoted(ifname, id, "phase1",
2690 "tls_suiteb=1") < 0)
2691 return -2;
2692 } else {
2693 if (set_network_quoted(ifname, id, "openssl_ciphers",
2694 "SUITEB192") < 0)
2695 return -2;
2696 }
2697
2698 val = get_param(cmd, "TLSCipher");
2699 if (set_tls_cipher(ifname, id, val) < 0) {
2700 send_resp(dut, conn, SIGMA_ERROR,
2701 "ErrorCode,Unsupported TLSCipher value");
2702 return -3;
2703 }
2704 }
2705
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002706 return 1;
2707}
2708
2709
Jouni Malinenf7222712019-06-13 01:50:21 +03002710static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2711 struct sigma_conn *conn,
2712 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002713{
2714 const char *intf = get_param(cmd, "Interface");
2715 const char *ifname;
2716 int id;
2717
2718 if (intf == NULL)
2719 return -1;
2720
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002721 if (strcmp(intf, get_main_ifname(dut)) == 0)
2722 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002723 else
2724 ifname = intf;
2725
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302726 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002727 if (id < 0)
2728 return id;
2729
2730 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2731 send_resp(dut, conn, SIGMA_ERROR,
2732 "errorCode,Failed to set TTLS method");
2733 return 0;
2734 }
2735
2736 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2737 send_resp(dut, conn, SIGMA_ERROR,
2738 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2739 return 0;
2740 }
2741
2742 return 1;
2743}
2744
2745
Jouni Malinenf7222712019-06-13 01:50:21 +03002746static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2747 struct sigma_conn *conn,
2748 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002749{
2750 const char *intf = get_param(cmd, "Interface");
2751 const char *ifname;
2752 int id;
2753
2754 if (intf == NULL)
2755 return -1;
2756
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002757 if (strcmp(intf, get_main_ifname(dut)) == 0)
2758 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002759 else
2760 ifname = intf;
2761
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302762 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002763 if (id < 0)
2764 return id;
2765
2766 if (set_network(ifname, id, "eap", "SIM") < 0)
2767 return -2;
2768
2769 return 1;
2770}
2771
2772
Jouni Malinenf7222712019-06-13 01:50:21 +03002773static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2774 struct sigma_conn *conn,
2775 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002776{
2777 const char *intf = get_param(cmd, "Interface");
2778 const char *ifname, *val;
2779 int id;
2780 char buf[100];
2781
2782 if (intf == NULL)
2783 return -1;
2784
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002785 if (strcmp(intf, get_main_ifname(dut)) == 0)
2786 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002787 else
2788 ifname = intf;
2789
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302790 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002791 if (id < 0)
2792 return id;
2793
2794 if (set_network(ifname, id, "eap", "PEAP") < 0)
2795 return -2;
2796
2797 val = get_param(cmd, "innerEAP");
2798 if (val) {
2799 if (strcasecmp(val, "MSCHAPv2") == 0) {
2800 if (set_network_quoted(ifname, id, "phase2",
2801 "auth=MSCHAPV2") < 0)
2802 return -2;
2803 } else if (strcasecmp(val, "GTC") == 0) {
2804 if (set_network_quoted(ifname, id, "phase2",
2805 "auth=GTC") < 0)
2806 return -2;
2807 } else
2808 return -1;
2809 }
2810
2811 val = get_param(cmd, "peapVersion");
2812 if (val) {
2813 int ver = atoi(val);
2814 if (ver < 0 || ver > 1)
2815 return -1;
2816 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2817 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2818 return -2;
2819 }
2820
2821 return 1;
2822}
2823
2824
Jouni Malinenf7222712019-06-13 01:50:21 +03002825static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2826 struct sigma_conn *conn,
2827 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002828{
2829 const char *intf = get_param(cmd, "Interface");
2830 const char *ifname, *val;
2831 int id;
2832 char buf[100];
2833
2834 if (intf == NULL)
2835 return -1;
2836
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002837 if (strcmp(intf, get_main_ifname(dut)) == 0)
2838 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002839 else
2840 ifname = intf;
2841
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302842 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002843 if (id < 0)
2844 return id;
2845
2846 if (set_network(ifname, id, "eap", "FAST") < 0)
2847 return -2;
2848
2849 val = get_param(cmd, "innerEAP");
2850 if (val) {
2851 if (strcasecmp(val, "MSCHAPV2") == 0) {
2852 if (set_network_quoted(ifname, id, "phase2",
2853 "auth=MSCHAPV2") < 0)
2854 return -2;
2855 } else if (strcasecmp(val, "GTC") == 0) {
2856 if (set_network_quoted(ifname, id, "phase2",
2857 "auth=GTC") < 0)
2858 return -2;
2859 } else
2860 return -1;
2861 }
2862
2863 val = get_param(cmd, "validateServer");
2864 if (val) {
2865 /* TODO */
2866 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2867 "validateServer=%s", val);
2868 }
2869
2870 val = get_param(cmd, "pacFile");
2871 if (val) {
2872 snprintf(buf, sizeof(buf), "blob://%s", val);
2873 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2874 return -2;
2875 }
2876
2877 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2878 0)
2879 return -2;
2880
2881 return 1;
2882}
2883
2884
Jouni Malinenf7222712019-06-13 01:50:21 +03002885static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2886 struct sigma_conn *conn,
2887 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002888{
2889 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302890 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002891 const char *ifname;
2892 int id;
2893
2894 if (intf == NULL)
2895 return -1;
2896
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002897 if (strcmp(intf, get_main_ifname(dut)) == 0)
2898 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002899 else
2900 ifname = intf;
2901
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302902 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002903 if (id < 0)
2904 return id;
2905
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302906 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2907 * hexadecimal).
2908 */
2909 if (username && username[0] == '6') {
2910 if (set_network(ifname, id, "eap", "AKA'") < 0)
2911 return -2;
2912 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002913 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302914 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002915
2916 return 1;
2917}
2918
2919
Jouni Malinenf7222712019-06-13 01:50:21 +03002920static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2921 struct sigma_conn *conn,
2922 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002923{
2924 const char *intf = get_param(cmd, "Interface");
2925 const char *ifname;
2926 int id;
2927
2928 if (intf == NULL)
2929 return -1;
2930
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002931 if (strcmp(intf, get_main_ifname(dut)) == 0)
2932 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002933 else
2934 ifname = intf;
2935
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302936 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002937 if (id < 0)
2938 return id;
2939
2940 if (set_network(ifname, id, "eap", "AKA'") < 0)
2941 return -2;
2942
2943 return 1;
2944}
2945
2946
2947static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2948 struct sigma_cmd *cmd)
2949{
2950 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002951 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002952 const char *ifname;
2953 int id;
2954
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002955 if (strcmp(intf, get_main_ifname(dut)) == 0)
2956 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002957 else
2958 ifname = intf;
2959
2960 id = add_network_common(dut, conn, ifname, cmd);
2961 if (id < 0)
2962 return id;
2963
2964 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2965 return -2;
2966
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002967 if (dut->program == PROGRAM_60GHZ && network_mode &&
2968 strcasecmp(network_mode, "PBSS") == 0 &&
2969 set_network(ifname, id, "pbss", "1") < 0)
2970 return -2;
2971
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002972 return 1;
2973}
2974
2975
Jouni Malinen8e3f8812020-10-05 10:02:03 +03002976static enum sigma_cmd_result sta_set_owe(struct sigma_dut *dut,
2977 struct sigma_conn *conn,
2978 struct sigma_cmd *cmd)
Jouni Malinen47dcc952017-10-09 16:43:24 +03002979{
2980 const char *intf = get_param(cmd, "Interface");
2981 const char *ifname, *val;
2982 int id;
2983
2984 if (intf == NULL)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03002985 return INVALID_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03002986
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002987 if (strcmp(intf, get_main_ifname(dut)) == 0)
2988 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002989 else
2990 ifname = intf;
2991
2992 id = set_wpa_common(dut, conn, ifname, cmd);
2993 if (id < 0)
2994 return id;
2995
2996 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03002997 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03002998
Hu Wangdd5eed22020-07-16 12:18:03 +08002999 if (dut->owe_ptk_workaround &&
3000 set_network(ifname, id, "owe_ptk_workaround", "1") < 0) {
3001 sigma_dut_print(dut, DUT_MSG_ERROR,
3002 "Failed to set owe_ptk_workaround to 1");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003003 return ERROR_SEND_STATUS;
Hu Wangdd5eed22020-07-16 12:18:03 +08003004 }
3005
Jouni Malinen47dcc952017-10-09 16:43:24 +03003006 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003007 if (val && strcmp(val, "0") == 0) {
3008 if (wpa_command(ifname,
3009 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
3010 sigma_dut_print(dut, DUT_MSG_ERROR,
3011 "Failed to set OWE DH Param element override");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003012 return ERROR_SEND_STATUS;
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003013 }
Hu Wangdd5eed22020-07-16 12:18:03 +08003014 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003015 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003016 "Failed to set owe_group");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003017 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003018 }
3019
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003020 return SUCCESS_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003021}
3022
3023
Jouni Malinenf7222712019-06-13 01:50:21 +03003024static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3025 struct sigma_conn *conn,
3026 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003027{
3028 const char *type = get_param(cmd, "Type");
3029
3030 if (type == NULL) {
3031 send_resp(dut, conn, SIGMA_ERROR,
3032 "ErrorCode,Missing Type argument");
3033 return 0;
3034 }
3035
3036 if (strcasecmp(type, "OPEN") == 0)
3037 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003038 if (strcasecmp(type, "OWE") == 0)
3039 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003040 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003041 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003042 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003043 return cmd_sta_set_psk(dut, conn, cmd);
3044 if (strcasecmp(type, "EAPTLS") == 0)
3045 return cmd_sta_set_eaptls(dut, conn, cmd);
3046 if (strcasecmp(type, "EAPTTLS") == 0)
3047 return cmd_sta_set_eapttls(dut, conn, cmd);
3048 if (strcasecmp(type, "EAPPEAP") == 0)
3049 return cmd_sta_set_peap(dut, conn, cmd);
3050 if (strcasecmp(type, "EAPSIM") == 0)
3051 return cmd_sta_set_eapsim(dut, conn, cmd);
3052 if (strcasecmp(type, "EAPFAST") == 0)
3053 return cmd_sta_set_eapfast(dut, conn, cmd);
3054 if (strcasecmp(type, "EAPAKA") == 0)
3055 return cmd_sta_set_eapaka(dut, conn, cmd);
3056 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3057 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003058 if (strcasecmp(type, "wep") == 0)
3059 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003060
3061 send_resp(dut, conn, SIGMA_ERROR,
3062 "ErrorCode,Unsupported Type value");
3063 return 0;
3064}
3065
3066
3067int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3068{
3069#ifdef __linux__
3070 /* special handling for ath6kl */
3071 char path[128], fname[128], *pos;
3072 ssize_t res;
3073 FILE *f;
3074
Jouni Malinene39cd562019-05-29 23:39:56 +03003075 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3076 intf);
3077 if (res < 0 || res >= sizeof(fname))
3078 return 0;
3079 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003080 if (res < 0)
3081 return 0; /* not ath6kl */
3082
3083 if (res >= (int) sizeof(path))
3084 res = sizeof(path) - 1;
3085 path[res] = '\0';
3086 pos = strrchr(path, '/');
3087 if (pos == NULL)
3088 pos = path;
3089 else
3090 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003091 res = snprintf(fname, sizeof(fname),
3092 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3093 "create_qos", pos);
3094 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003095 return 0; /* not ath6kl */
3096
3097 if (uapsd) {
3098 f = fopen(fname, "w");
3099 if (f == NULL)
3100 return -1;
3101
3102 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3103 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3104 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3105 "20000 0\n");
3106 fclose(f);
3107 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003108 res = snprintf(fname, sizeof(fname),
3109 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3110 "delete_qos", pos);
3111 if (res < 0 || res >= sizeof(fname))
3112 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003113
3114 f = fopen(fname, "w");
3115 if (f == NULL)
3116 return -1;
3117
3118 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3119 fprintf(f, "2 4\n");
3120 fclose(f);
3121 }
3122#endif /* __linux__ */
3123
3124 return 0;
3125}
3126
3127
Jouni Malinenf7222712019-06-13 01:50:21 +03003128static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3129 struct sigma_conn *conn,
3130 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003131{
3132 const char *intf = get_param(cmd, "Interface");
3133 /* const char *ssid = get_param(cmd, "ssid"); */
3134 const char *val;
3135 int max_sp_len = 4;
3136 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3137 char buf[100];
3138 int ret1, ret2;
3139
3140 val = get_param(cmd, "maxSPLength");
3141 if (val) {
3142 max_sp_len = atoi(val);
3143 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3144 max_sp_len != 4)
3145 return -1;
3146 }
3147
3148 val = get_param(cmd, "acBE");
3149 if (val)
3150 ac_be = atoi(val);
3151
3152 val = get_param(cmd, "acBK");
3153 if (val)
3154 ac_bk = atoi(val);
3155
3156 val = get_param(cmd, "acVI");
3157 if (val)
3158 ac_vi = atoi(val);
3159
3160 val = get_param(cmd, "acVO");
3161 if (val)
3162 ac_vo = atoi(val);
3163
3164 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3165
3166 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3167 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3168 ret1 = wpa_command(intf, buf);
3169
3170 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3171 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3172 ret2 = wpa_command(intf, buf);
3173
3174 if (ret1 && ret2) {
3175 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3176 "UAPSD parameters.");
3177 return -2;
3178 }
3179
3180 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3181 send_resp(dut, conn, SIGMA_ERROR,
3182 "ErrorCode,Failed to set ath6kl QoS parameters");
3183 return 0;
3184 }
3185
3186 return 1;
3187}
3188
3189
Jouni Malinenf7222712019-06-13 01:50:21 +03003190static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3191 struct sigma_conn *conn,
3192 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003193{
3194 char buf[1000];
3195 const char *intf = get_param(cmd, "Interface");
3196 const char *grp = get_param(cmd, "Group");
3197 const char *act = get_param(cmd, "Action");
3198 const char *tid = get_param(cmd, "Tid");
3199 const char *dir = get_param(cmd, "Direction");
3200 const char *psb = get_param(cmd, "Psb");
3201 const char *up = get_param(cmd, "Up");
3202 const char *fixed = get_param(cmd, "Fixed");
3203 const char *size = get_param(cmd, "Size");
3204 const char *msize = get_param(cmd, "Maxsize");
3205 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3206 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3207 const char *inact = get_param(cmd, "Inactivity");
3208 const char *sus = get_param(cmd, "Suspension");
3209 const char *mindr = get_param(cmd, "Mindatarate");
3210 const char *meandr = get_param(cmd, "Meandatarate");
3211 const char *peakdr = get_param(cmd, "Peakdatarate");
3212 const char *phyrate = get_param(cmd, "Phyrate");
3213 const char *burstsize = get_param(cmd, "Burstsize");
3214 const char *sba = get_param(cmd, "Sba");
3215 int direction;
3216 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003217 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003218 int fixed_int;
3219 int psb_ts;
3220
3221 if (intf == NULL || grp == NULL || act == NULL )
3222 return -1;
3223
3224 if (strcasecmp(act, "addts") == 0) {
3225 if (tid == NULL || dir == NULL || psb == NULL ||
3226 up == NULL || fixed == NULL || size == NULL)
3227 return -1;
3228
3229 /*
3230 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3231 * possible values, but WMM-AC and V-E test scripts use "UP,
3232 * "DOWN", and "BIDI".
3233 */
3234 if (strcasecmp(dir, "uplink") == 0 ||
3235 strcasecmp(dir, "up") == 0) {
3236 direction = 0;
3237 } else if (strcasecmp(dir, "downlink") == 0 ||
3238 strcasecmp(dir, "down") == 0) {
3239 direction = 1;
3240 } else if (strcasecmp(dir, "bidi") == 0) {
3241 direction = 2;
3242 } else {
3243 sigma_dut_print(dut, DUT_MSG_ERROR,
3244 "Direction %s not supported", dir);
3245 return -1;
3246 }
3247
3248 if (strcasecmp(psb, "legacy") == 0) {
3249 psb_ts = 0;
3250 } else if (strcasecmp(psb, "uapsd") == 0) {
3251 psb_ts = 1;
3252 } else {
3253 sigma_dut_print(dut, DUT_MSG_ERROR,
3254 "PSB %s not supported", psb);
3255 return -1;
3256 }
3257
3258 if (atoi(tid) < 0 || atoi(tid) > 7) {
3259 sigma_dut_print(dut, DUT_MSG_ERROR,
3260 "TID %s not supported", tid);
3261 return -1;
3262 }
3263
3264 if (strcasecmp(fixed, "true") == 0) {
3265 fixed_int = 1;
3266 } else {
3267 fixed_int = 0;
3268 }
3269
Peng Xu93319622017-10-04 17:58:16 -07003270 if (sba)
3271 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003272
3273 dut->dialog_token++;
3274 handle = 7000 + dut->dialog_token;
3275
3276 /*
3277 * size: convert to hex
3278 * maxsi: convert to hex
3279 * mindr: convert to hex
3280 * meandr: convert to hex
3281 * peakdr: convert to hex
3282 * burstsize: convert to hex
3283 * phyrate: convert to hex
3284 * sba: convert to hex with modification
3285 * minsi: convert to integer
3286 * sus: convert to integer
3287 * inact: convert to integer
3288 * maxsi: convert to integer
3289 */
3290
3291 /*
3292 * The Nominal MSDU Size field is 2 octets long and contains an
3293 * unsigned integer that specifies the nominal size, in octets,
3294 * of MSDUs belonging to the traffic under this traffic
3295 * specification and is defined in Figure 16. If the Fixed
3296 * subfield is set to 1, then the size of the MSDU is fixed and
3297 * is indicated by the Size Subfield. If the Fixed subfield is
3298 * set to 0, then the size of the MSDU might not be fixed and
3299 * the Size indicates the nominal MSDU size.
3300 *
3301 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3302 * and specifies the excess allocation of time (and bandwidth)
3303 * over and above the stated rates required to transport an MSDU
3304 * belonging to the traffic in this TSPEC. This field is
3305 * represented as an unsigned binary number with an implicit
3306 * binary point after the leftmost 3 bits. For example, an SBA
3307 * of 1.75 is represented as 0x3800. This field is included to
3308 * account for retransmissions. As such, the value of this field
3309 * must be greater than unity.
3310 */
3311
3312 snprintf(buf, sizeof(buf),
3313 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3314 " 0x%X 0x%X 0x%X"
3315 " 0x%X 0x%X 0x%X"
3316 " 0x%X %d %d %d %d"
3317 " %d %d",
3318 intf, handle, tid, direction, psb_ts, up,
3319 (unsigned int) ((fixed_int << 15) | atoi(size)),
3320 msize ? atoi(msize) : 0,
3321 mindr ? atoi(mindr) : 0,
3322 meandr ? atoi(meandr) : 0,
3323 peakdr ? atoi(peakdr) : 0,
3324 burstsize ? atoi(burstsize) : 0,
3325 phyrate ? atoi(phyrate) : 0,
3326 sba ? ((unsigned int) (((int) sba_fv << 13) |
3327 (int)((sba_fv - (int) sba_fv) *
3328 8192))) : 0,
3329 minsi ? atoi(minsi) : 0,
3330 sus ? atoi(sus) : 0,
3331 0, 0,
3332 inact ? atoi(inact) : 0,
3333 maxsi ? atoi(maxsi) : 0);
3334
3335 if (system(buf) != 0) {
3336 sigma_dut_print(dut, DUT_MSG_ERROR,
3337 "iwpriv addtspec request failed");
3338 send_resp(dut, conn, SIGMA_ERROR,
3339 "errorCode,Failed to execute addTspec command");
3340 return 0;
3341 }
3342
3343 sigma_dut_print(dut, DUT_MSG_INFO,
3344 "iwpriv addtspec request send");
3345
3346 /* Mapping handle to a TID */
3347 dut->tid_to_handle[atoi(tid)] = handle;
3348 } else if (strcasecmp(act, "delts") == 0) {
3349 if (tid == NULL)
3350 return -1;
3351
3352 if (atoi(tid) < 0 || atoi(tid) > 7) {
3353 sigma_dut_print(dut, DUT_MSG_ERROR,
3354 "TID %s not supported", tid);
3355 send_resp(dut, conn, SIGMA_ERROR,
3356 "errorCode,Unsupported TID");
3357 return 0;
3358 }
3359
3360 handle = dut->tid_to_handle[atoi(tid)];
3361
3362 if (handle < 7000 || handle > 7255) {
3363 /* Invalid handle ie no mapping for that TID */
3364 sigma_dut_print(dut, DUT_MSG_ERROR,
3365 "handle-> %d not found", handle);
3366 }
3367
3368 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3369 intf, handle);
3370
3371 if (system(buf) != 0) {
3372 sigma_dut_print(dut, DUT_MSG_ERROR,
3373 "iwpriv deltspec request failed");
3374 send_resp(dut, conn, SIGMA_ERROR,
3375 "errorCode,Failed to execute delTspec command");
3376 return 0;
3377 }
3378
3379 sigma_dut_print(dut, DUT_MSG_INFO,
3380 "iwpriv deltspec request send");
3381
3382 dut->tid_to_handle[atoi(tid)] = 0;
3383 } else {
3384 sigma_dut_print(dut, DUT_MSG_ERROR,
3385 "Action type %s not supported", act);
3386 send_resp(dut, conn, SIGMA_ERROR,
3387 "errorCode,Unsupported Action");
3388 return 0;
3389 }
3390
3391 return 1;
3392}
3393
3394
vamsi krishna52e16f92017-08-29 12:37:34 +05303395static int find_network(struct sigma_dut *dut, const char *ssid)
3396{
3397 char list[4096];
3398 char *pos;
3399
3400 sigma_dut_print(dut, DUT_MSG_DEBUG,
3401 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003402 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303403 list, sizeof(list)) < 0)
3404 return -1;
3405 pos = strstr(list, ssid);
3406 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3407 return -1;
3408
3409 while (pos > list && pos[-1] != '\n')
3410 pos--;
3411 dut->infra_network_id = atoi(pos);
3412 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3413 return 0;
3414}
3415
3416
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303417/**
3418 * enum qca_sta_helper_config_params - This helper enum defines the config
3419 * parameters which can be delivered to sta.
3420 */
3421enum qca_sta_helper_config_params {
3422 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE */
3423 STA_SET_RSNIE,
3424
3425 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC */
3426 STA_SET_LDPC,
3427
3428 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC */
3429 STA_SET_TX_STBC,
3430
3431 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC */
3432 STA_SET_RX_STBC,
3433
3434 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION */
3435 STA_SET_TX_MSDU,
3436
3437 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION */
3438 STA_SET_RX_MSDU,
3439};
3440
3441
3442static int sta_config_params(struct sigma_dut *dut, const char *intf,
3443 enum qca_sta_helper_config_params config_cmd,
3444 int value)
Sunil Dutt44595082018-02-12 19:41:45 +05303445{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303446#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05303447 struct nl_msg *msg;
3448 int ret;
3449 struct nlattr *params;
3450 int ifindex;
3451
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303452 ifindex = if_nametoindex(intf);
3453 if (ifindex == 0) {
3454 sigma_dut_print(dut, DUT_MSG_ERROR,
3455 "%s: Interface %s does not exist",
3456 __func__, intf);
3457 return -1;
3458 }
3459
Sunil Dutt44595082018-02-12 19:41:45 +05303460 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3461 NL80211_CMD_VENDOR)) ||
3462 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3463 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3464 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3465 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303466 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)))
3467 goto fail;
3468
3469 switch (config_cmd) {
3470 case STA_SET_RSNIE:
3471 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, value))
3472 goto fail;
3473 break;
3474 case STA_SET_LDPC:
3475 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC, value))
3476 goto fail;
3477 break;
3478 case STA_SET_TX_STBC:
3479 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC, value))
3480 goto fail;
3481 break;
3482 case STA_SET_RX_STBC:
3483 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC, value))
3484 goto fail;
3485 break;
3486 case STA_SET_TX_MSDU:
3487 if (nla_put_u8(msg,
3488 QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION,
3489 value))
3490 goto fail;
3491 break;
3492 case STA_SET_RX_MSDU:
3493 if (nla_put_u8(msg,
3494 QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION,
3495 value))
3496 goto fail;
3497 break;
Sunil Dutt44595082018-02-12 19:41:45 +05303498 }
3499 nla_nest_end(msg, params);
3500
3501 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3502 if (ret) {
3503 sigma_dut_print(dut, DUT_MSG_ERROR,
3504 "%s: err in send_and_recv_msgs, ret=%d",
3505 __func__, ret);
3506 return ret;
3507 }
3508
3509 return 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303510
3511fail:
3512 sigma_dut_print(dut, DUT_MSG_ERROR,
3513 "%s: err in adding vendor_cmd and vendor_data",
3514 __func__);
3515 nlmsg_free(msg);
Sunil Dutt44595082018-02-12 19:41:45 +05303516#endif /* NL80211_SUPPORT */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303517 return -1;
3518}
Sunil Dutt44595082018-02-12 19:41:45 +05303519
3520
Jouni Malinenf7222712019-06-13 01:50:21 +03003521static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3522 struct sigma_conn *conn,
3523 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003524{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303525#ifdef NL80211_SUPPORT
3526 const char *intf = get_param(cmd, "Interface");
3527#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003528 const char *ssid = get_param(cmd, "ssid");
3529 const char *wps_param = get_param(cmd, "WPS");
3530 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003531 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003532 const char *network_mode = get_param(cmd, "network_mode");
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303533 const char *ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003534 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003535 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003536 int e;
3537 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3538 struct wpa_ctrl *ctrl = NULL;
3539 int num_network_not_found = 0;
3540 int num_disconnected = 0;
3541 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003542
3543 if (ssid == NULL)
3544 return -1;
3545
Jouni Malinen37d5c692019-08-19 16:56:55 +03003546 dut->server_cert_tod = 0;
3547
Jouni Malinen3c367e82017-06-23 17:01:47 +03003548 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303549#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003550 if (get_driver_type(dut) == DRIVER_WCN) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303551 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Sunil Dutt44595082018-02-12 19:41:45 +05303552 dut->config_rsnie = 1;
3553 }
3554#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003555 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3556 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003557 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03003558 send_resp(dut, conn, SIGMA_ERROR,
3559 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3560 return 0;
3561 }
3562 }
3563
Jouni Malinen68143132017-09-02 02:34:08 +03003564 if (dut->sae_commit_override) {
3565 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3566 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003567 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03003568 send_resp(dut, conn, SIGMA_ERROR,
3569 "ErrorCode,Failed to set SAE commit override");
3570 return 0;
3571 }
3572 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303573#ifdef ANDROID
3574 if (dut->fils_hlp)
3575 process_fils_hlp(dut);
3576#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003577
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003578 if (wps_param &&
3579 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3580 wps = 1;
3581
Vamsi Krishnac1633d22020-05-06 18:31:21 +05303582 if (dut->ocvc &&
3583 set_network(get_station_ifname(dut), dut->infra_network_id,
3584 "ocv", "1") < 0)
3585 return ERROR_SEND_STATUS;
3586
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003587 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003588 if (dut->program == PROGRAM_60GHZ && network_mode &&
3589 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003590 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003591 "pbss", "1") < 0)
3592 return -2;
3593
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003594 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3595 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3596 "parameters not yet set");
3597 return 0;
3598 }
3599 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003600 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003601 return -2;
3602 } else {
3603 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3604 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003605 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003606 return -2;
3607 }
3608 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303609 if (strcmp(ssid, dut->infra_ssid) == 0) {
3610 sigma_dut_print(dut, DUT_MSG_DEBUG,
3611 "sta_associate for the most recently added network");
3612 } else if (find_network(dut, ssid) < 0) {
3613 sigma_dut_print(dut, DUT_MSG_DEBUG,
3614 "sta_associate for a previously stored network profile");
3615 send_resp(dut, conn, SIGMA_ERROR,
3616 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003617 return 0;
3618 }
3619
3620 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003621 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003622 "bssid", bssid) < 0) {
3623 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3624 "Invalid bssid argument");
3625 return 0;
3626 }
3627
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303628 if ((dut->program == PROGRAM_WPA3 &&
3629 dut->sta_associate_wait_connect) ||
3630 dut->program == PROGRAM_QM) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003631 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003632 if (!ctrl)
3633 return ERROR_SEND_STATUS;
3634 }
3635
Jouni Malinen46a19b62017-06-23 14:31:27 +03003636 extra[0] = '\0';
3637 if (chan)
3638 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003639 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003640 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3641 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003642 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003643 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3644 "network id %d on %s",
3645 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003646 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003647 ret = ERROR_SEND_STATUS;
3648 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003649 }
3650 }
3651
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003652 if (!ctrl)
3653 return SUCCESS_SEND_STATUS;
3654
3655 /* Wait for connection result to be able to store server certificate
3656 * hash for trust root override testing
3657 * (dev_exec_action,ServerCertTrust). */
3658
3659 for (e = 0; e < 20; e++) {
3660 const char *events[] = {
3661 "CTRL-EVENT-EAP-PEER-CERT",
3662 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3663 "CTRL-EVENT-DISCONNECTED",
3664 "CTRL-EVENT-CONNECTED",
3665 "CTRL-EVENT-NETWORK-NOT-FOUND",
3666 NULL
3667 };
3668 char buf[1024];
3669 int res;
3670
3671 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3672 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02003673 send_resp(dut, conn, SIGMA_COMPLETE,
3674 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003675 ret = STATUS_SENT_ERROR;
3676 break;
3677 }
3678 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3679 buf);
3680
3681 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3682 strstr(buf, " depth=0")) {
3683 char *pos = strstr(buf, " hash=");
3684
3685 if (pos) {
3686 char *end;
3687
Jouni Malinen34b19cb2019-08-16 16:37:17 +03003688 if (strstr(buf, " tod=1"))
3689 tod = 1;
3690 else if (strstr(buf, " tod=2"))
3691 tod = 2;
3692 else
3693 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003694 sigma_dut_print(dut, DUT_MSG_DEBUG,
3695 "Server certificate TOD policy: %d",
3696 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03003697 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003698
3699 pos += 6;
3700 end = strchr(pos, ' ');
3701 if (end)
3702 *end = '\0';
3703 strlcpy(dut->server_cert_hash, pos,
3704 sizeof(dut->server_cert_hash));
3705 sigma_dut_print(dut, DUT_MSG_DEBUG,
3706 "Server certificate hash: %s",
3707 dut->server_cert_hash);
3708 }
3709 }
3710
3711 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3712 send_resp(dut, conn, SIGMA_COMPLETE,
3713 "Result,TLS server certificate validation failed");
3714 ret = STATUS_SENT_ERROR;
3715 break;
3716 }
3717
3718 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3719 num_network_not_found++;
3720
3721 if (num_network_not_found > 2) {
3722 send_resp(dut, conn, SIGMA_COMPLETE,
3723 "Result,Network not found");
3724 ret = STATUS_SENT_ERROR;
3725 break;
3726 }
3727 }
3728
3729 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3730 num_disconnected++;
3731
3732 if (num_disconnected > 2) {
3733 send_resp(dut, conn, SIGMA_COMPLETE,
3734 "Result,Connection failed");
3735 ret = STATUS_SENT_ERROR;
3736 break;
3737 }
3738 }
3739
3740 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3741 if (tod >= 0) {
3742 sigma_dut_print(dut, DUT_MSG_DEBUG,
3743 "Network profile TOD policy update: %d -> %d",
3744 dut->sta_tod_policy, tod);
3745 dut->sta_tod_policy = tod;
3746 }
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303747 if (dut->program == PROGRAM_QM) {
3748 unsigned char iface_mac_addr[ETH_ALEN];
3749 char ipv6[100];
3750
3751 if (get_hwaddr(ifname, iface_mac_addr) < 0) {
3752 sigma_dut_print(dut, DUT_MSG_ERROR,
3753 "%s: get_hwaddr %s failed",
3754 __func__, ifname);
3755 ret = ERROR_SEND_STATUS;
3756 break;
3757 }
3758
3759 convert_mac_addr_to_ipv6_lladdr(iface_mac_addr,
3760 ipv6,
3761 sizeof(ipv6));
3762
3763 if (set_ipv6_addr(dut, ipv6, "64", ifname) !=
3764 0) {
3765 ret = ERROR_SEND_STATUS;
3766 break;
3767 }
3768 }
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003769 break;
3770 }
3771 }
3772done:
3773 if (ctrl) {
3774 wpa_ctrl_detach(ctrl);
3775 wpa_ctrl_close(ctrl);
3776 }
3777 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003778}
3779
3780
3781static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3782{
3783 char buf[500], cmd[200];
3784 int res;
3785
3786 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3787 * default path */
3788 res = snprintf(cmd, sizeof(cmd),
3789 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3790 file_exists("./hs20-osu-client") ?
3791 "./hs20-osu-client" : "hs20-osu-client",
3792 sigma_wpas_ctrl,
3793 dut->summary_log ? "-s " : "",
3794 dut->summary_log ? dut->summary_log : "");
3795 if (res < 0 || res >= (int) sizeof(cmd))
3796 return -1;
3797
3798 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3799 if (res < 0 || res >= (int) sizeof(buf))
3800 return -1;
3801 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3802
3803 if (system(buf) != 0) {
3804 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3805 return -1;
3806 }
3807 sigma_dut_print(dut, DUT_MSG_DEBUG,
3808 "Completed hs20-osu-client operation");
3809
3810 return 0;
3811}
3812
3813
3814static int download_ppsmo(struct sigma_dut *dut,
3815 struct sigma_conn *conn,
3816 const char *intf,
3817 struct sigma_cmd *cmd)
3818{
3819 const char *name, *path, *val;
3820 char url[500], buf[600], fbuf[100];
3821 char *fqdn = NULL;
3822
3823 name = get_param(cmd, "FileName");
3824 path = get_param(cmd, "FilePath");
3825 if (name == NULL || path == NULL)
3826 return -1;
3827
3828 if (strcasecmp(path, "VendorSpecific") == 0) {
3829 snprintf(url, sizeof(url), "PPS/%s", name);
3830 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3831 "from the device (%s)", url);
3832 if (!file_exists(url)) {
3833 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3834 "PPS MO file does not exist");
3835 return 0;
3836 }
3837 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3838 if (system(buf) != 0) {
3839 send_resp(dut, conn, SIGMA_ERROR,
3840 "errorCode,Failed to copy PPS MO");
3841 return 0;
3842 }
3843 } else if (strncasecmp(path, "http:", 5) != 0 &&
3844 strncasecmp(path, "https:", 6) != 0) {
3845 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3846 "Unsupported FilePath value");
3847 return 0;
3848 } else {
3849 snprintf(url, sizeof(url), "%s/%s", path, name);
3850 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3851 url);
3852 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3853 remove("pps-tnds.xml");
3854 if (system(buf) != 0) {
3855 send_resp(dut, conn, SIGMA_ERROR,
3856 "errorCode,Failed to download PPS MO");
3857 return 0;
3858 }
3859 }
3860
3861 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3862 send_resp(dut, conn, SIGMA_ERROR,
3863 "errorCode,Failed to parse downloaded PPSMO");
3864 return 0;
3865 }
3866 unlink("pps-tnds.xml");
3867
3868 val = get_param(cmd, "managementTreeURI");
3869 if (val) {
3870 const char *pos, *end;
3871 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3872 val);
3873 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3874 send_resp(dut, conn, SIGMA_ERROR,
3875 "errorCode,Invalid managementTreeURI prefix");
3876 return 0;
3877 }
3878 pos = val + 8;
3879 end = strchr(pos, '/');
3880 if (end == NULL ||
3881 strcmp(end, "/PerProviderSubscription") != 0) {
3882 send_resp(dut, conn, SIGMA_ERROR,
3883 "errorCode,Invalid managementTreeURI postfix");
3884 return 0;
3885 }
3886 if (end - pos >= (int) sizeof(fbuf)) {
3887 send_resp(dut, conn, SIGMA_ERROR,
3888 "errorCode,Too long FQDN in managementTreeURI");
3889 return 0;
3890 }
3891 memcpy(fbuf, pos, end - pos);
3892 fbuf[end - pos] = '\0';
3893 fqdn = fbuf;
3894 sigma_dut_print(dut, DUT_MSG_INFO,
3895 "FQDN from managementTreeURI: %s", fqdn);
3896 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3897 FILE *f = fopen("pps-fqdn", "r");
3898 if (f) {
3899 if (fgets(fbuf, sizeof(fbuf), f)) {
3900 fbuf[sizeof(fbuf) - 1] = '\0';
3901 fqdn = fbuf;
3902 sigma_dut_print(dut, DUT_MSG_DEBUG,
3903 "Use FQDN %s", fqdn);
3904 }
3905 fclose(f);
3906 }
3907 }
3908
3909 if (fqdn == NULL) {
3910 send_resp(dut, conn, SIGMA_ERROR,
3911 "errorCode,No FQDN specified");
3912 return 0;
3913 }
3914
3915 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3916 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3917 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3918
3919 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3920 if (rename("pps.xml", buf) < 0) {
3921 send_resp(dut, conn, SIGMA_ERROR,
3922 "errorCode,Could not move PPS MO");
3923 return 0;
3924 }
3925
3926 if (strcasecmp(path, "VendorSpecific") == 0) {
3927 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3928 fqdn);
3929 if (system(buf)) {
3930 send_resp(dut, conn, SIGMA_ERROR,
3931 "errorCode,Failed to copy OSU CA cert");
3932 return 0;
3933 }
3934
3935 snprintf(buf, sizeof(buf),
3936 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3937 fqdn);
3938 if (system(buf)) {
3939 send_resp(dut, conn, SIGMA_ERROR,
3940 "errorCode,Failed to copy AAA CA cert");
3941 return 0;
3942 }
3943 } else {
3944 snprintf(buf, sizeof(buf),
3945 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3946 fqdn, fqdn);
3947 if (run_hs20_osu(dut, buf) < 0) {
3948 send_resp(dut, conn, SIGMA_ERROR,
3949 "errorCode,Failed to download OSU CA cert");
3950 return 0;
3951 }
3952
3953 snprintf(buf, sizeof(buf),
3954 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3955 fqdn, fqdn);
3956 if (run_hs20_osu(dut, buf) < 0) {
3957 sigma_dut_print(dut, DUT_MSG_INFO,
3958 "Failed to download AAA CA cert");
3959 }
3960 }
3961
3962 if (file_exists("next-client-cert.pem")) {
3963 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3964 if (rename("next-client-cert.pem", buf) < 0) {
3965 send_resp(dut, conn, SIGMA_ERROR,
3966 "errorCode,Could not move client certificate");
3967 return 0;
3968 }
3969 }
3970
3971 if (file_exists("next-client-key.pem")) {
3972 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3973 if (rename("next-client-key.pem", buf) < 0) {
3974 send_resp(dut, conn, SIGMA_ERROR,
3975 "errorCode,Could not move client key");
3976 return 0;
3977 }
3978 }
3979
3980 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3981 if (run_hs20_osu(dut, buf) < 0) {
3982 send_resp(dut, conn, SIGMA_ERROR,
3983 "errorCode,Failed to configure credential from "
3984 "PPSMO");
3985 return 0;
3986 }
3987
3988 return 1;
3989}
3990
3991
3992static int download_cert(struct sigma_dut *dut,
3993 struct sigma_conn *conn,
3994 const char *intf,
3995 struct sigma_cmd *cmd)
3996{
3997 const char *name, *path;
3998 char url[500], buf[600];
3999
4000 name = get_param(cmd, "FileName");
4001 path = get_param(cmd, "FilePath");
4002 if (name == NULL || path == NULL)
4003 return -1;
4004
4005 if (strcasecmp(path, "VendorSpecific") == 0) {
4006 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
4007 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4008 "certificate from the device (%s)", url);
4009 if (!file_exists(url)) {
4010 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4011 "certificate file does not exist");
4012 return 0;
4013 }
4014 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
4015 if (system(buf) != 0) {
4016 send_resp(dut, conn, SIGMA_ERROR,
4017 "errorCode,Failed to copy client "
4018 "certificate");
4019 return 0;
4020 }
4021
4022 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
4023 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4024 "private key from the device (%s)", url);
4025 if (!file_exists(url)) {
4026 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4027 "private key file does not exist");
4028 return 0;
4029 }
4030 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
4031 if (system(buf) != 0) {
4032 send_resp(dut, conn, SIGMA_ERROR,
4033 "errorCode,Failed to copy client key");
4034 return 0;
4035 }
4036 } else if (strncasecmp(path, "http:", 5) != 0 &&
4037 strncasecmp(path, "https:", 6) != 0) {
4038 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4039 "Unsupported FilePath value");
4040 return 0;
4041 } else {
4042 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
4043 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
4044 "certificate/key from %s", url);
4045 snprintf(buf, sizeof(buf),
4046 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
4047 if (system(buf) != 0) {
4048 send_resp(dut, conn, SIGMA_ERROR,
4049 "errorCode,Failed to download client "
4050 "certificate");
4051 return 0;
4052 }
4053
4054 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
4055 {
4056 send_resp(dut, conn, SIGMA_ERROR,
4057 "errorCode,Failed to copy client key");
4058 return 0;
4059 }
4060 }
4061
4062 return 1;
4063}
4064
4065
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004066static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
4067 struct sigma_conn *conn,
4068 struct sigma_cmd *cmd)
4069{
4070 const char *val;
4071 const char *intf = get_param(cmd, "interface");
4072
4073 if (!intf)
4074 return -1;
4075
4076 val = get_param(cmd, "WscIEFragment");
4077 if (val && strcasecmp(val, "enable") == 0) {
4078 sigma_dut_print(dut, DUT_MSG_DEBUG,
4079 "Enable WSC IE fragmentation");
4080
4081 dut->wsc_fragment = 1;
4082 /* set long attributes to force fragmentation */
4083 if (wpa_command(intf, "SET device_name "
4084 WPS_LONG_DEVICE_NAME) < 0)
4085 return -2;
4086 if (wpa_command(intf, "SET manufacturer "
4087 WPS_LONG_MANUFACTURER) < 0)
4088 return -2;
4089 if (wpa_command(intf, "SET model_name "
4090 WPS_LONG_MODEL_NAME) < 0)
4091 return -2;
4092 if (wpa_command(intf, "SET model_number "
4093 WPS_LONG_MODEL_NUMBER) < 0)
4094 return -2;
4095 if (wpa_command(intf, "SET serial_number "
4096 WPS_LONG_SERIAL_NUMBER) < 0)
4097 return -2;
4098 }
4099
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02004100 val = get_param(cmd, "RSN_IE");
4101 if (val) {
4102 if (strcasecmp(val, "disable") == 0)
4103 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
4104 else if (strcasecmp(val, "enable") == 0)
4105 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
4106 }
4107
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004108 val = get_param(cmd, "WpsVersion");
4109 if (val)
4110 dut->wps_forced_version = get_wps_forced_version(dut, val);
4111
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004112 val = get_param(cmd, "WscEAPFragment");
4113 if (val && strcasecmp(val, "enable") == 0)
4114 dut->eap_fragment = 1;
4115
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004116 return 1;
4117}
4118
4119
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004120static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4121 struct sigma_conn *conn,
4122 const char *intf,
4123 struct sigma_cmd *cmd)
4124{
4125 const char *val;
4126
4127 val = get_param(cmd, "FileType");
4128 if (val && strcasecmp(val, "PPSMO") == 0)
4129 return download_ppsmo(dut, conn, intf, cmd);
4130 if (val && strcasecmp(val, "CERT") == 0)
4131 return download_cert(dut, conn, intf, cmd);
4132 if (val) {
4133 send_resp(dut, conn, SIGMA_ERROR,
4134 "ErrorCode,Unsupported FileType");
4135 return 0;
4136 }
4137
4138 return 1;
4139}
4140
4141
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304142static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4143 struct sigma_conn *conn,
4144 const char *intf,
4145 struct sigma_cmd *cmd)
4146{
4147 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304148 char buf[1000];
4149 char text[20];
4150 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304151
4152 val = get_param(cmd, "OCESupport");
4153 if (val && strcasecmp(val, "Disable") == 0) {
4154 if (wpa_command(intf, "SET oce 0") < 0) {
4155 send_resp(dut, conn, SIGMA_ERROR,
4156 "ErrorCode,Failed to disable OCE");
4157 return 0;
4158 }
4159 } else if (val && strcasecmp(val, "Enable") == 0) {
4160 if (wpa_command(intf, "SET oce 1") < 0) {
4161 send_resp(dut, conn, SIGMA_ERROR,
4162 "ErrorCode,Failed to enable OCE");
4163 return 0;
4164 }
4165 }
4166
vamsi krishnaa2799492017-12-05 14:28:01 +05304167 val = get_param(cmd, "FILScap");
4168 if (val && (atoi(val) == 1)) {
4169 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4170 send_resp(dut, conn, SIGMA_ERROR,
4171 "ErrorCode,Failed to enable FILS");
4172 return 0;
4173 }
4174 } else if (val && (atoi(val) == 0)) {
4175 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4176 send_resp(dut, conn, SIGMA_ERROR,
4177 "ErrorCode,Failed to disable FILS");
4178 return 0;
4179 }
4180 }
4181
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304182 val = get_param(cmd, "FILSHLP");
4183 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004184 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304185 sizeof(text)) < 0)
4186 return -2;
4187 hwaddr_aton(text, addr);
4188 snprintf(buf, sizeof(buf),
4189 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4190 "080045100140000040004011399e00000000ffffffff00440043"
4191 "012cb30001010600fd4f46410000000000000000000000000000"
4192 "000000000000"
4193 "%02x%02x%02x%02x%02x%02x"
4194 "0000000000000000000000000000000000000000000000000000"
4195 "0000000000000000000000000000000000000000000000000000"
4196 "0000000000000000000000000000000000000000000000000000"
4197 "0000000000000000000000000000000000000000000000000000"
4198 "0000000000000000000000000000000000000000000000000000"
4199 "0000000000000000000000000000000000000000000000000000"
4200 "0000000000000000000000000000000000000000000000000000"
4201 "0000000000000000000000000000000000000000638253633501"
4202 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4203 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4204 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4205 if (wpa_command(intf, buf)) {
4206 send_resp(dut, conn, SIGMA_ERROR,
4207 "ErrorCode,Failed to add HLP");
4208 return 0;
4209 }
4210 dut->fils_hlp = 1;
4211 }
4212
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304213 return 1;
4214}
4215
4216
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004217static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4218 const char *val)
4219{
4220 int counter = 0;
4221 char token[50];
4222 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304223 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004224
Peng Xub8fc5cc2017-05-10 17:27:28 -07004225 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004226 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304227 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004228 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004229 if (strcmp(result, "disable") == 0)
4230 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4231 else
4232 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304233 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004234 counter++;
4235 }
4236}
4237
4238
4239static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4240 const char *val)
4241{
4242 char buf[100];
4243
4244 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4245 if (system(buf) != 0) {
4246 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4247 }
4248}
4249
4250
4251static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4252 const char *val)
4253{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004254 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004255 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004256 }
4257}
4258
4259
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004260static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4261 const char *val)
4262{
4263#ifdef NL80211_SUPPORT
4264 struct nl_msg *msg;
4265 int ret = 0;
4266 struct nlattr *params;
4267 int ifindex;
4268 int wmmenable = 1;
4269
4270 if (val &&
4271 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4272 wmmenable = 0;
4273
4274 ifindex = if_nametoindex(intf);
4275 if (ifindex == 0) {
4276 sigma_dut_print(dut, DUT_MSG_ERROR,
4277 "%s: Index for interface %s failed",
4278 __func__, intf);
4279 return -1;
4280 }
4281
4282 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4283 NL80211_CMD_VENDOR)) ||
4284 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4285 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4286 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4287 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4288 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4289 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4290 wmmenable)) {
4291 sigma_dut_print(dut, DUT_MSG_ERROR,
4292 "%s: err in adding vendor_cmd and vendor_data",
4293 __func__);
4294 nlmsg_free(msg);
4295 return -1;
4296 }
4297 nla_nest_end(msg, params);
4298
4299 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4300 if (ret) {
4301 sigma_dut_print(dut, DUT_MSG_ERROR,
4302 "%s: err in send_and_recv_msgs, ret=%d",
4303 __func__, ret);
4304 }
4305 return ret;
4306#else /* NL80211_SUPPORT */
4307 sigma_dut_print(dut, DUT_MSG_ERROR,
4308 "WMM cannot be changed without NL80211_SUPPORT defined");
4309 return -1;
4310#endif /* NL80211_SUPPORT */
4311}
4312
4313
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004314static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4315 const char *val)
4316{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004317 int sgi20;
4318
4319 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4320
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004321 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004322}
4323
4324
4325static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4326 const char *val)
4327{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304328 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004329
4330 /* Disable Tx Beam forming when using a fixed rate */
4331 ath_disable_txbf(dut, intf);
4332
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304333 v = atoi(val);
4334 if (v < 0 || v > 32) {
4335 sigma_dut_print(dut, DUT_MSG_ERROR,
4336 "Invalid Fixed MCS rate: %d", v);
4337 return;
4338 }
4339 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004340
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004341 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004342
4343 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004344 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004345}
4346
4347
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004348static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4349 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004350{
4351 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304352 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004353
4354 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4355 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4356 else
4357 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4358
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304359 ret = system(buf);
4360#ifdef NL80211_SUPPORT
4361 if (ret) {
4362 int value = (strcasecmp(val, "Enable") == 0) ? 2 : 1;
4363
4364 ret = sta_config_params(dut, intf, STA_SET_TX_MSDU, value);
4365 ret |= sta_config_params(dut, intf, STA_SET_RX_MSDU, value);
4366 }
4367#endif /* NL80211_SUPPORT */
4368 if (ret)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004369 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4370}
4371
4372
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004373static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4374 int ampdu)
4375{
4376 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004377 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004378
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004379 if (ampdu)
4380 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004381 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4382 if (system(buf) != 0) {
4383 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4384 return -1;
4385 }
4386
4387 return 0;
4388}
4389
4390
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004391static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4392 const char *val)
4393{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004394 run_iwpriv(dut, intf, "tx_stbc %s", val);
4395 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004396}
4397
4398
4399static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4400 const char *val)
4401{
4402 char buf[60];
4403
Peng Xucc317ed2017-05-18 16:44:37 -07004404 if (strcmp(val, "160") == 0) {
4405 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4406 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004407 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4408 } else if (strcmp(val, "40") == 0) {
4409 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4410 } else if (strcmp(val, "20") == 0) {
4411 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4412 } else if (strcasecmp(val, "Auto") == 0) {
4413 buf[0] = '\0';
4414 } else {
4415 sigma_dut_print(dut, DUT_MSG_ERROR,
4416 "WIDTH/CTS_WIDTH value not supported");
4417 return -1;
4418 }
4419
4420 if (buf[0] != '\0' && system(buf) != 0) {
4421 sigma_dut_print(dut, DUT_MSG_ERROR,
4422 "Failed to set WIDTH/CTS_WIDTH");
4423 return -1;
4424 }
4425
4426 return 0;
4427}
4428
4429
4430int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4431 const char *intf, const char *val)
4432{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004433 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004434 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004435 dut->chwidth = 0;
4436 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004437 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004438 dut->chwidth = 0;
4439 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004440 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004441 dut->chwidth = 1;
4442 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004443 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004444 dut->chwidth = 2;
4445 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004446 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004447 dut->chwidth = 3;
4448 } else {
4449 send_resp(dut, conn, SIGMA_ERROR,
4450 "ErrorCode,WIDTH not supported");
4451 return -1;
4452 }
4453
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004454 return 0;
4455}
4456
4457
4458static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4459 const char *val)
4460{
4461 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004462 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004463
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004464 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004465 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004466 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004467 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004468 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004469 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004470 } else {
4471 sigma_dut_print(dut, DUT_MSG_ERROR,
4472 "SP_STREAM value not supported");
4473 return -1;
4474 }
4475
4476 if (system(buf) != 0) {
4477 sigma_dut_print(dut, DUT_MSG_ERROR,
4478 "Failed to set SP_STREAM");
4479 return -1;
4480 }
4481
Arif Hussainac6c5112018-05-25 17:34:00 -07004482 dut->sta_nss = sta_nss;
4483
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004484 return 0;
4485}
4486
4487
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304488static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4489 const char *val)
4490{
4491 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304492 int ret;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304493
4494 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304495 ret = system(buf);
4496#ifdef NL80211_SUPPORT
4497 if (ret)
4498 ret = sta_config_params(dut, intf, STA_SET_TX_STBC,
4499 strcmp(val, "0") == 0 ? 0 : 1);
4500#endif /* NL80211_SUPPORT */
4501 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304502 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4503
4504 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304505 ret = system(buf);
4506#ifdef NL80211_SUPPORT
4507 if (ret)
4508 ret = sta_config_params(dut, intf, STA_SET_RX_STBC,
4509 strcmp(val, "0") == 0 ? 0 : 1);
4510#endif /* NL80211_SUPPORT */
4511 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304512 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4513}
4514
4515
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304516static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4517 struct sigma_conn *conn,
4518 const char *intf, int capa)
4519{
4520 char buf[32];
4521
4522 if (capa > 0 && capa < 4) {
4523 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4524 if (wpa_command(intf, buf) < 0) {
4525 send_resp(dut, conn, SIGMA_ERROR,
4526 "ErrorCode, Failed to set cellular data capability");
4527 return 0;
4528 }
4529 return 1;
4530 }
4531
4532 sigma_dut_print(dut, DUT_MSG_ERROR,
4533 "Invalid Cellular data capability: %d", capa);
4534 send_resp(dut, conn, SIGMA_INVALID,
4535 "ErrorCode,Invalid cellular data capability");
4536 return 0;
4537}
4538
4539
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304540static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4541 const char *intf, const char *val)
4542{
4543 if (strcasecmp(val, "Disable") == 0) {
4544 if (wpa_command(intf, "SET roaming 0") < 0) {
4545 send_resp(dut, conn, SIGMA_ERROR,
4546 "ErrorCode,Failed to disable roaming");
4547 return 0;
4548 }
4549 return 1;
4550 }
4551
4552 if (strcasecmp(val, "Enable") == 0) {
4553 if (wpa_command(intf, "SET roaming 1") < 0) {
4554 send_resp(dut, conn, SIGMA_ERROR,
4555 "ErrorCode,Failed to enable roaming");
4556 return 0;
4557 }
4558 return 1;
4559 }
4560
4561 sigma_dut_print(dut, DUT_MSG_ERROR,
4562 "Invalid value provided for roaming: %s", val);
4563 send_resp(dut, conn, SIGMA_INVALID,
4564 "ErrorCode,Unknown value provided for Roaming");
4565 return 0;
4566}
4567
4568
Ashwini Patila75de5a2017-04-13 16:35:05 +05304569static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4570 struct sigma_conn *conn,
4571 const char *intf, const char *val)
4572{
4573 if (strcasecmp(val, "Disable") == 0) {
4574 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4575 send_resp(dut, conn, SIGMA_ERROR,
4576 "ErrorCode,Failed to disable Assoc_disallow");
4577 return 0;
4578 }
4579 return 1;
4580 }
4581
4582 if (strcasecmp(val, "Enable") == 0) {
4583 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4584 send_resp(dut, conn, SIGMA_ERROR,
4585 "ErrorCode,Failed to enable Assoc_disallow");
4586 return 0;
4587 }
4588 return 1;
4589 }
4590
4591 sigma_dut_print(dut, DUT_MSG_ERROR,
4592 "Invalid value provided for Assoc_disallow: %s", val);
4593 send_resp(dut, conn, SIGMA_INVALID,
4594 "ErrorCode,Unknown value provided for Assoc_disallow");
4595 return 0;
4596}
4597
4598
Ashwini Patilc63161e2017-04-13 16:30:23 +05304599static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4600 const char *intf, const char *val)
4601{
4602 if (strcasecmp(val, "Reject") == 0) {
4603 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4604 send_resp(dut, conn, SIGMA_ERROR,
4605 "ErrorCode,Failed to Reject BTM Request");
4606 return 0;
4607 }
4608 return 1;
4609 }
4610
4611 if (strcasecmp(val, "Accept") == 0) {
4612 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4613 send_resp(dut, conn, SIGMA_ERROR,
4614 "ErrorCode,Failed to Accept BTM Request");
4615 return 0;
4616 }
4617 return 1;
4618 }
4619
4620 sigma_dut_print(dut, DUT_MSG_ERROR,
4621 "Invalid value provided for BSS_Transition: %s", val);
4622 send_resp(dut, conn, SIGMA_INVALID,
4623 "ErrorCode,Unknown value provided for BSS_Transition");
4624 return 0;
4625}
4626
4627
Ashwini Patil00402582017-04-13 12:29:39 +05304628static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4629 struct sigma_conn *conn,
4630 const char *intf,
4631 struct sigma_cmd *cmd)
4632{
4633 const char *ch, *pref, *op_class, *reason;
4634 char buf[120];
4635 int len, ret;
4636
4637 pref = get_param(cmd, "Ch_Pref");
4638 if (!pref)
4639 return 1;
4640
4641 if (strcasecmp(pref, "clear") == 0) {
4642 free(dut->non_pref_ch_list);
4643 dut->non_pref_ch_list = NULL;
4644 } else {
4645 op_class = get_param(cmd, "Ch_Op_Class");
4646 if (!op_class) {
4647 send_resp(dut, conn, SIGMA_INVALID,
4648 "ErrorCode,Ch_Op_Class not provided");
4649 return 0;
4650 }
4651
4652 ch = get_param(cmd, "Ch_Pref_Num");
4653 if (!ch) {
4654 send_resp(dut, conn, SIGMA_INVALID,
4655 "ErrorCode,Ch_Pref_Num not provided");
4656 return 0;
4657 }
4658
4659 reason = get_param(cmd, "Ch_Reason_Code");
4660 if (!reason) {
4661 send_resp(dut, conn, SIGMA_INVALID,
4662 "ErrorCode,Ch_Reason_Code not provided");
4663 return 0;
4664 }
4665
4666 if (!dut->non_pref_ch_list) {
4667 dut->non_pref_ch_list =
4668 calloc(1, NON_PREF_CH_LIST_SIZE);
4669 if (!dut->non_pref_ch_list) {
4670 send_resp(dut, conn, SIGMA_ERROR,
4671 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4672 return 0;
4673 }
4674 }
4675 len = strlen(dut->non_pref_ch_list);
4676 ret = snprintf(dut->non_pref_ch_list + len,
4677 NON_PREF_CH_LIST_SIZE - len,
4678 " %s:%s:%s:%s", op_class, ch, pref, reason);
4679 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4680 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4681 dut->non_pref_ch_list);
4682 } else {
4683 sigma_dut_print(dut, DUT_MSG_ERROR,
4684 "snprintf failed for non_pref_list, ret = %d",
4685 ret);
4686 send_resp(dut, conn, SIGMA_ERROR,
4687 "ErrorCode,snprintf failed");
4688 free(dut->non_pref_ch_list);
4689 dut->non_pref_ch_list = NULL;
4690 return 0;
4691 }
4692 }
4693
4694 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4695 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4696 if (ret < 0 || ret >= (int) sizeof(buf)) {
4697 sigma_dut_print(dut, DUT_MSG_DEBUG,
4698 "snprintf failed for set non_pref_chan, ret: %d",
4699 ret);
4700 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4701 return 0;
4702 }
4703
4704 if (wpa_command(intf, buf) < 0) {
4705 send_resp(dut, conn, SIGMA_ERROR,
4706 "ErrorCode,Failed to set non-preferred channel list");
4707 return 0;
4708 }
4709
4710 return 1;
4711}
4712
4713
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004714#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004715
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004716static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4717 uint8_t cfg)
4718{
4719 struct nl_msg *msg;
4720 int ret = 0;
4721 struct nlattr *params;
4722 int ifindex;
4723
4724 ifindex = if_nametoindex(intf);
4725 if (ifindex == 0) {
4726 sigma_dut_print(dut, DUT_MSG_ERROR,
4727 "%s: Index for interface %s failed",
4728 __func__, intf);
4729 return -1;
4730 }
4731
4732 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4733 NL80211_CMD_VENDOR)) ||
4734 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4735 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4736 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4737 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4738 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4739 nla_put_u8(msg,
4740 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4741 cfg)) {
4742 sigma_dut_print(dut, DUT_MSG_ERROR,
4743 "%s: err in adding vendor_cmd and vendor_data",
4744 __func__);
4745 nlmsg_free(msg);
4746 return -1;
4747 }
4748 nla_nest_end(msg, params);
4749
4750 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4751 if (ret) {
4752 sigma_dut_print(dut, DUT_MSG_ERROR,
4753 "%s: err in send_and_recv_msgs, ret=%d",
4754 __func__, ret);
4755 }
4756 return ret;
4757}
4758
4759
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004760static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4761 enum he_fragmentation_val frag)
4762{
4763 struct nl_msg *msg;
4764 int ret = 0;
4765 struct nlattr *params;
4766 int ifindex;
4767
4768 ifindex = if_nametoindex(intf);
4769 if (ifindex == 0) {
4770 sigma_dut_print(dut, DUT_MSG_ERROR,
4771 "%s: Index for interface %s failed",
4772 __func__, intf);
4773 return -1;
4774 }
4775
4776 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4777 NL80211_CMD_VENDOR)) ||
4778 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4779 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4780 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4781 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4782 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4783 nla_put_u8(msg,
4784 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
4785 frag)) {
4786 sigma_dut_print(dut, DUT_MSG_ERROR,
4787 "%s: err in adding vendor_cmd and vendor_data",
4788 __func__);
4789 nlmsg_free(msg);
4790 return -1;
4791 }
4792 nla_nest_end(msg, params);
4793
4794 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4795 if (ret) {
4796 sigma_dut_print(dut, DUT_MSG_ERROR,
4797 "%s: err in send_and_recv_msgs, ret=%d",
4798 __func__, ret);
4799 }
4800 return ret;
4801}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004802
4803
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08004804int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
4805 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004806{
4807 struct nl_msg *msg;
4808 int ret = 0;
4809 struct nlattr *params;
4810 int ifindex;
4811
4812 ifindex = if_nametoindex(intf);
4813 if (ifindex == 0) {
4814 sigma_dut_print(dut, DUT_MSG_ERROR,
4815 "%s: Index for interface %s failed",
4816 __func__, intf);
4817 return -1;
4818 }
4819
4820 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4821 NL80211_CMD_VENDOR)) ||
4822 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4823 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4824 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4825 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4826 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4827 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
4828 ltf)) {
4829 sigma_dut_print(dut, DUT_MSG_ERROR,
4830 "%s: err in adding vendor_cmd and vendor_data",
4831 __func__);
4832 nlmsg_free(msg);
4833 return -1;
4834 }
4835 nla_nest_end(msg, params);
4836
4837 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4838 if (ret) {
4839 sigma_dut_print(dut, DUT_MSG_ERROR,
4840 "%s: err in send_and_recv_msgs, ret=%d",
4841 __func__, ret);
4842 }
4843 return ret;
4844}
4845
4846
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004847static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4848 int noack, enum qca_wlan_ac_type ac)
4849{
4850 struct nl_msg *msg;
4851 int ret = 0;
4852 struct nlattr *params;
4853 int ifindex;
4854
4855 ifindex = if_nametoindex(intf);
4856 if (ifindex == 0) {
4857 sigma_dut_print(dut, DUT_MSG_ERROR,
4858 "%s: Index for interface %s failed",
4859 __func__, intf);
4860 return -1;
4861 }
4862
4863 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4864 NL80211_CMD_VENDOR)) ||
4865 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4866 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4867 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4868 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4869 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4870 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4871 noack) ||
4872 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4873 ac)) {
4874 sigma_dut_print(dut, DUT_MSG_ERROR,
4875 "%s: err in adding vendor_cmd and vendor_data",
4876 __func__);
4877 nlmsg_free(msg);
4878 return -1;
4879 }
4880 nla_nest_end(msg, params);
4881
4882 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4883 if (ret) {
4884 sigma_dut_print(dut, DUT_MSG_ERROR,
4885 "%s: err in send_and_recv_msgs, ret=%d",
4886 __func__, ret);
4887 }
4888 return ret;
4889}
4890
4891
4892static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4893 const char *val)
4894{
4895 int noack, ret;
4896 char token[100];
4897 char *result;
4898 char *saveptr;
4899 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4900
4901 strlcpy(token, val, sizeof(token));
4902 token[sizeof(token) - 1] = '\0';
4903 result = strtok_r(token, ":", &saveptr);
4904 while (result) {
4905 noack = strcasecmp(result, "Disable") != 0;
4906 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4907 if (ret) {
4908 sigma_dut_print(dut, DUT_MSG_ERROR,
4909 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4910 ac, ret);
4911 }
4912 result = strtok_r(NULL, ":", &saveptr);
4913 ac++;
4914 }
4915}
4916
Vinita S. Maloo7462e812020-05-22 15:16:04 +05304917
4918static int nlvendor_sta_set_phymode(struct sigma_dut *dut, const char *intf,
4919 enum qca_wlan_vendor_phy_mode val)
4920{
4921 struct nl_msg *msg;
4922 struct nlattr *params;
4923 int ifindex, ret;
4924
4925 ifindex = if_nametoindex(intf);
4926 if (ifindex == 0) {
4927 sigma_dut_print(dut, DUT_MSG_ERROR,
4928 "%s: Index for interface %s not found",
4929 __func__, intf);
4930 return -1;
4931 }
4932
4933 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4934 NL80211_CMD_VENDOR);
4935 if (!msg) {
4936 sigma_dut_print(dut, DUT_MSG_ERROR,
4937 "%s: err in adding vendor_cmd", __func__);
4938 return -1;
4939 }
4940
4941 if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4942 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4943 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) {
4944 sigma_dut_print(dut, DUT_MSG_ERROR,
4945 "%s: err in adding vendor_attr", __func__);
4946 nlmsg_free(msg);
4947 return -1;
4948 }
4949
4950 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
4951 if (!params || nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_PHY_MODE,
4952 val)) {
4953 sigma_dut_print(dut, DUT_MSG_ERROR,
4954 "%s: err in adding vendor_data", __func__);
4955 nlmsg_free(msg);
4956 return -1;
4957 }
4958
4959 nla_nest_end(msg, params);
4960 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4961 if (ret) {
4962 sigma_dut_print(dut, DUT_MSG_ERROR,
4963 "%s: err in send_and_recv_msgs, ret=%d (%s)",
4964 __func__, ret, strerror(-ret));
4965 return ret;
4966 }
4967
4968 return 0;
4969}
4970
4971
4972static enum qca_wlan_vendor_phy_mode get_qca_vendor_phymode(const char *val)
4973{
4974 if (strcmp(val, "11a") == 0) {
4975 /* IEEE80211_MODE_11A */
4976 return QCA_WLAN_VENDOR_PHY_MODE_11A;
4977 }
4978
4979 if (strcmp(val, "11g") == 0) {
4980 /* IEEE80211_MODE_11G */
4981 return QCA_WLAN_VENDOR_PHY_MODE_11G;
4982 }
4983
4984 if (strcmp(val, "11b") == 0) {
4985 /* IEEE80211_MODE_11B */
4986 return QCA_WLAN_VENDOR_PHY_MODE_11B;
4987 }
4988
4989 if (strcmp(val, "11n") == 0 ||
4990 strcmp(val, "11nl") == 0 ||
4991 strcmp(val, "11nl(nabg)") == 0) {
4992 /* IEEE80211_MODE_11AGN */
4993 return QCA_WLAN_VENDOR_PHY_MODE_11AGN;
4994 }
4995
4996 if (strcmp(val, "11ng") == 0) {
4997 /* IEEE80211_MODE_11NG_HT40 */
4998 return QCA_WLAN_VENDOR_PHY_MODE_11NG_HT40;
4999 }
5000
5001 if (strcmp(val, "AC") == 0 ||
5002 strcasecmp(val, "11AC") == 0) {
5003 /* IEEE80211_MODE_11AC_VHT80 */
5004 return QCA_WLAN_VENDOR_PHY_MODE_11AC_VHT80;
5005 }
5006
5007 if (strcmp(val, "11na") == 0 ||
5008 strcasecmp(val, "11an") == 0) {
5009 /* IEEE80211_MODE_11NA_HT40 */
5010 return QCA_WLAN_VENDOR_PHY_MODE_11NA_HT40;
5011 }
5012
5013 if (strcmp(val, "11ax") == 0 ||
5014 strcmp(val, "auto") == 0) {
5015 /* IEEE80211_MODE_AUTO */
5016 return QCA_WLAN_VENDOR_PHY_MODE_AUTO;
5017 }
5018
5019 return -1;
5020}
5021
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005022#endif /* NL80211_SUPPORT */
5023
5024
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305025static int get_phymode(const char *val)
5026{
5027 if (strcmp(val, "11a") == 0)
5028 return 1; /* IEEE80211_MODE_11A */
5029 if (strcmp(val, "11g") == 0)
5030 return 3; /* IEEE80211_MODE_11G */
5031 if (strcmp(val, "11b") == 0)
5032 return 2; /* IEEE80211_MODE_11B */
5033 if (strcmp(val, "11n") == 0 ||
5034 strcmp(val, "11nl") == 0 ||
5035 strcmp(val, "11nl(nabg)") == 0)
5036 return 22; /* IEEE80211_MODE_11AGN */
5037 if (strcmp(val, "11ng") == 0)
5038 return 13; /* IEEE80211_MODE_11NG_HT40 */
5039 if (strcmp(val, "AC") == 0 ||
5040 strcasecmp(val, "11AC") == 0)
5041 return 19; /* IEEE80211_MODE_11AC_VHT80 */
5042 if (strcmp(val, "11na") == 0 ||
5043 strcasecmp(val, "11an") == 0)
5044 return 14; /* IEEE80211_MODE_11NA_HT40 */
5045 if (strcmp(val, "11ax") == 0 ||
5046 strcmp(val, "auto") == 0)
5047 return 0; /* IEEE80211_MODE_AUTO */
5048 return -1;
5049}
5050
5051
5052static void sta_set_phymode(struct sigma_dut *dut, const char *intf,
5053 const char *val)
5054{
5055 char buf[100];
5056 int len, phymode;
Vinita S. Maloo7462e812020-05-22 15:16:04 +05305057#ifdef NL80211_SUPPORT
5058 enum qca_wlan_vendor_phy_mode qca_phymode;
5059
5060 qca_phymode = get_qca_vendor_phymode(val);
5061 if (qca_phymode == -1) {
5062 sigma_dut_print(dut, DUT_MSG_DEBUG,
5063 "Ignoring mode change for mode: %s",
5064 val);
5065 return;
5066 }
5067
5068 if (nlvendor_sta_set_phymode(dut, intf, qca_phymode) == 0)
5069 return;
5070#endif /* NL80211_SUPPORT */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305071
5072 phymode = get_phymode(val);
5073 if (phymode == -1) {
5074 sigma_dut_print(dut, DUT_MSG_DEBUG,
5075 "Ignoring mode change for mode: %s",
5076 val);
5077 return;
5078 }
5079
5080 len = snprintf(buf, sizeof(buf), "iwpriv %s setphymode %d", intf,
5081 phymode);
5082 if (len < 0 || len >= sizeof(buf)) {
5083 sigma_dut_print(dut, DUT_MSG_ERROR,
5084 "Failed to set phymode");
5085 return;
5086 }
5087
5088 if (system(buf) != 0)
5089 sigma_dut_print(dut, DUT_MSG_ERROR,
5090 "iwpriv setting of phymode failed");
5091}
5092
5093
Jouni Malinenf7222712019-06-13 01:50:21 +03005094static enum sigma_cmd_result
5095cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
5096 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005097{
5098 const char *intf = get_param(cmd, "Interface");
5099 const char *val;
5100
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03005101 val = get_param(cmd, "FT_DS");
5102 if (val) {
5103 if (strcasecmp(val, "Enable") == 0) {
5104 dut->sta_ft_ds = 1;
5105 } else if (strcasecmp(val, "Disable") == 0) {
5106 dut->sta_ft_ds = 0;
5107 } else {
5108 send_resp(dut, conn, SIGMA_ERROR,
5109 "errorCode,Unsupported value for FT_DS");
5110 return STATUS_SENT_ERROR;
5111 }
5112 }
5113
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005114 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03005115 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
5116 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005117 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
5118 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005119
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005120 if (val && strcasecmp(val, "LOC") == 0)
5121 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02005122 if (val && strcasecmp(val, "60GHZ") == 0) {
5123 val = get_param(cmd, "WPS");
5124 if (val && strcasecmp(val, "disable") == 0) {
5125 dut->wps_disable = 1;
5126 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
5127 } else {
5128 /* wps_disable can have other value from the previous
5129 * test, so make sure it has the correct value.
5130 */
5131 dut->wps_disable = 0;
5132 }
5133
5134 val = get_param(cmd, "P2P");
5135 if (val && strcasecmp(val, "disable") == 0)
5136 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
5137 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005138
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02005139 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
5140 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
5141
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005142#ifdef ANDROID_NAN
5143 if (val && strcasecmp(val, "NAN") == 0)
5144 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
5145#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005146#ifdef MIRACAST
5147 if (val && (strcasecmp(val, "WFD") == 0 ||
5148 strcasecmp(val, "DisplayR2") == 0))
5149 return miracast_preset_testparameters(dut, conn, cmd);
5150#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005151
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07005152 if (val &&
5153 (strcasecmp(val, "MBO") == 0 || strcasecmp(val, "HE") == 0)) {
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305154 val = get_param(cmd, "Cellular_Data_Cap");
5155 if (val &&
5156 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
5157 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05305158
5159 val = get_param(cmd, "Ch_Pref");
5160 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
5161 return 0;
5162
Ashwini Patilc63161e2017-04-13 16:30:23 +05305163 val = get_param(cmd, "BSS_Transition");
5164 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
5165 return 0;
5166
Ashwini Patila75de5a2017-04-13 16:35:05 +05305167 val = get_param(cmd, "Assoc_Disallow");
5168 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
5169 return 0;
5170
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305171 val = get_param(cmd, "Roaming");
5172 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
5173 return 0;
5174
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305175 return 1;
5176 }
5177
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305178 if (val && strcasecmp(val, "OCE") == 0)
5179 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
5180
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005181#if 0
5182 val = get_param(cmd, "Supplicant");
5183 if (val && strcasecmp(val, "Default") != 0) {
5184 send_resp(dut, conn, SIGMA_ERROR,
5185 "ErrorCode,Only default(Vendor) supplicant "
5186 "supported");
5187 return 0;
5188 }
5189#endif
5190
5191 val = get_param(cmd, "RTS");
5192 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005193 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005194 case DRIVER_ATHEROS:
5195 ath_sta_set_rts(dut, intf, val);
5196 break;
5197 default:
5198#if 0
5199 send_resp(dut, conn, SIGMA_ERROR,
5200 "ErrorCode,Setting RTS not supported");
5201 return 0;
5202#else
5203 sigma_dut_print(dut, DUT_MSG_DEBUG,
5204 "Setting RTS not supported");
5205 break;
5206#endif
5207 }
5208 }
5209
5210#if 0
5211 val = get_param(cmd, "FRGMNT");
5212 if (val) {
5213 /* TODO */
5214 send_resp(dut, conn, SIGMA_ERROR,
5215 "ErrorCode,Setting FRGMNT not supported");
5216 return 0;
5217 }
5218#endif
5219
5220#if 0
5221 val = get_param(cmd, "Preamble");
5222 if (val) {
5223 /* TODO: Long/Short */
5224 send_resp(dut, conn, SIGMA_ERROR,
5225 "ErrorCode,Setting Preamble not supported");
5226 return 0;
5227 }
5228#endif
5229
5230 val = get_param(cmd, "Mode");
5231 if (val) {
5232 if (strcmp(val, "11b") == 0 ||
5233 strcmp(val, "11g") == 0 ||
5234 strcmp(val, "11a") == 0 ||
5235 strcmp(val, "11n") == 0 ||
5236 strcmp(val, "11ng") == 0 ||
5237 strcmp(val, "11nl") == 0 ||
5238 strcmp(val, "11nl(nabg)") == 0 ||
5239 strcmp(val, "AC") == 0 ||
5240 strcmp(val, "11AC") == 0 ||
5241 strcmp(val, "11ac") == 0 ||
5242 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08005243 strcmp(val, "11an") == 0 ||
5244 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005245 /* STA supports all modes by default */
5246 } else {
5247 send_resp(dut, conn, SIGMA_ERROR,
5248 "ErrorCode,Setting Mode not supported");
5249 return 0;
5250 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005251
5252 /* Change the mode only in case of testbed for HE program
5253 * and for 11a and 11g modes only. */
5254 if (dut->program == PROGRAM_HE &&
5255 dut->device_type == STA_testbed) {
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305256 sta_set_phymode(dut, intf, val);
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005257 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005258 }
5259
5260 val = get_param(cmd, "wmm");
5261 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005262 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005263 case DRIVER_ATHEROS:
5264 ath_sta_set_wmm(dut, intf, val);
5265 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005266 case DRIVER_WCN:
5267 wcn_sta_set_wmm(dut, intf, val);
5268 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005269 default:
5270 sigma_dut_print(dut, DUT_MSG_DEBUG,
5271 "Setting wmm not supported");
5272 break;
5273 }
5274 }
5275
5276 val = get_param(cmd, "Powersave");
5277 if (val) {
5278 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005279 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305280 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005281 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005282 }
5283
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005284 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005285 "P2P_SET ps 0") < 0)
5286 return -2;
5287 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005288 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5289 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005290 } else if (strcmp(val, "1") == 0 ||
5291 strcasecmp(val, "PSPoll") == 0 ||
5292 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005293 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305294 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005295 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005296 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005297 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005298 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005299 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005300 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005301 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005302 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005303 "P2P_SET ps 99") < 0)
5304 return -2;
5305 } else if (strcmp(val, "2") == 0 ||
5306 strcasecmp(val, "Fast") == 0) {
5307 /* TODO */
5308 send_resp(dut, conn, SIGMA_ERROR,
5309 "ErrorCode,Powersave=Fast not supported");
5310 return 0;
5311 } else if (strcmp(val, "3") == 0 ||
5312 strcasecmp(val, "PSNonPoll") == 0) {
5313 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005314 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5315 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005316
5317 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005318 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005319 "P2P_SET ps 1") < 0)
5320 return -2;
5321 } else
5322 return -1;
5323 }
5324
5325 val = get_param(cmd, "NoAck");
5326 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005327 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005328 case DRIVER_ATHEROS:
5329 ath_sta_set_noack(dut, intf, val);
5330 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005331#ifdef NL80211_SUPPORT
5332 case DRIVER_WCN:
5333 wcn_sta_set_noack(dut, intf, val);
5334 break;
5335#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005336 default:
5337 send_resp(dut, conn, SIGMA_ERROR,
5338 "ErrorCode,Setting NoAck not supported");
5339 return 0;
5340 }
5341 }
5342
5343 val = get_param(cmd, "IgnoreChswitchProhibit");
5344 if (val) {
5345 /* TODO: Enabled/disabled */
5346 if (strcasecmp(val, "Enabled") == 0) {
5347 send_resp(dut, conn, SIGMA_ERROR,
5348 "ErrorCode,Enabling IgnoreChswitchProhibit "
5349 "not supported");
5350 return 0;
5351 }
5352 }
5353
5354 val = get_param(cmd, "TDLS");
5355 if (val) {
5356 if (strcasecmp(val, "Disabled") == 0) {
5357 if (wpa_command(intf, "SET tdls_disabled 1")) {
5358 send_resp(dut, conn, SIGMA_ERROR,
5359 "ErrorCode,Failed to disable TDLS");
5360 return 0;
5361 }
5362 } else if (strcasecmp(val, "Enabled") == 0) {
5363 if (wpa_command(intf, "SET tdls_disabled 0")) {
5364 send_resp(dut, conn, SIGMA_ERROR,
5365 "ErrorCode,Failed to enable TDLS");
5366 return 0;
5367 }
5368 } else {
5369 send_resp(dut, conn, SIGMA_ERROR,
5370 "ErrorCode,Unsupported TDLS value");
5371 return 0;
5372 }
5373 }
5374
5375 val = get_param(cmd, "TDLSmode");
5376 if (val) {
5377 if (strcasecmp(val, "Default") == 0) {
5378 wpa_command(intf, "SET tdls_testing 0");
5379 } else if (strcasecmp(val, "APProhibit") == 0) {
5380 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5381 send_resp(dut, conn, SIGMA_ERROR,
5382 "ErrorCode,Failed to enable ignore "
5383 "APProhibit TDLS mode");
5384 return 0;
5385 }
5386 } else if (strcasecmp(val, "HiLoMac") == 0) {
5387 /* STA should respond with TDLS setup req for a TDLS
5388 * setup req */
5389 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5390 send_resp(dut, conn, SIGMA_ERROR,
5391 "ErrorCode,Failed to enable HiLoMac "
5392 "TDLS mode");
5393 return 0;
5394 }
5395 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5396 /*
5397 * Since all security modes are enabled by default when
5398 * Sigma control is used, there is no need to do
5399 * anything here.
5400 */
5401 } else if (strcasecmp(val, "ExistLink") == 0) {
5402 /*
5403 * Since we allow new TDLS Setup Request even if there
5404 * is an existing link, nothing needs to be done for
5405 * this.
5406 */
5407 } else {
5408 /* TODO:
5409 * ExistLink: STA should send TDLS setup req even if
5410 * direct link already exists
5411 */
5412 send_resp(dut, conn, SIGMA_ERROR,
5413 "ErrorCode,Unsupported TDLSmode value");
5414 return 0;
5415 }
5416 }
5417
5418 val = get_param(cmd, "FakePubKey");
5419 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5420 send_resp(dut, conn, SIGMA_ERROR,
5421 "ErrorCode,Failed to enable FakePubKey");
5422 return 0;
5423 }
5424
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005425#ifdef NL80211_SUPPORT
5426 val = get_param(cmd, "FrgmntSupport");
5427 if (val) {
5428 if (strcasecmp(val, "Enable") == 0) {
5429 if (sta_set_he_fragmentation(dut, intf,
5430 HE_FRAG_LEVEL1)) {
5431 send_resp(dut, conn, SIGMA_ERROR,
5432 "ErrorCode,Failed to enable HE Fragmentation");
5433 return 0;
5434 }
5435 } else if (strcasecmp(val, "Disable") == 0) {
5436 if (sta_set_he_fragmentation(dut, intf,
5437 HE_FRAG_DISABLE)) {
5438 send_resp(dut, conn, SIGMA_ERROR,
5439 "ErrorCode,Failed to disable HE Fragmentation");
5440 return 0;
5441 }
5442 }
5443 }
5444#endif /* NL80211_SUPPORT */
5445
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305446 val = get_param(cmd, "IncludeMSCSDescriptor");
5447 if (val && strcasecmp(val, "1") == 0) {
5448 char buf[128];
5449 int len;
5450
5451 len = snprintf(buf, sizeof(buf),
Veerendranath Jakkam62cde372020-08-19 18:03:06 +05305452 "MSCS add up_bitmap=F0 up_limit=7 stream_timeout=60000 frame_classifier=045F%032x",
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305453 0);
5454
5455 if (len < 0 || len >= sizeof(buf)) {
5456 sigma_dut_print(dut, DUT_MSG_ERROR,
5457 "Failed to build MSCS Descriptor IE");
5458 return ERROR_SEND_STATUS;
5459 }
5460
5461 if (wpa_command(intf, buf) != 0) {
5462 send_resp(dut, conn, SIGMA_ERROR,
5463 "ErrorCode,Failed to include MSCS descriptor");
5464 return STATUS_SENT_ERROR;
5465 }
5466 }
5467
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005468 return 1;
5469}
5470
5471
5472static const char * ath_get_radio_name(const char *radio_name)
5473{
5474 if (radio_name == NULL)
5475 return "wifi0";
5476 if (strcmp(radio_name, "wifi1") == 0)
5477 return "wifi1";
5478 if (strcmp(radio_name, "wifi2") == 0)
5479 return "wifi2";
5480 return "wifi0";
5481}
5482
5483
5484static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5485 const char *val)
5486{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005487 unsigned int vht_mcsmap = 0;
5488 int txchainmask = 0;
5489 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5490
5491 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5492 if (dut->testbed_flag_txsp == 1) {
5493 vht_mcsmap = 0xfffc;
5494 dut->testbed_flag_txsp = 0;
5495 } else {
5496 vht_mcsmap = 0xfffe;
5497 }
5498 txchainmask = 1;
5499 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5500 if (dut->testbed_flag_txsp == 1) {
5501 vht_mcsmap = 0xfff0;
5502 dut->testbed_flag_txsp = 0;
5503 } else {
5504 vht_mcsmap = 0xfffa;
5505 }
5506 txchainmask = 3;
5507 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5508 if (dut->testbed_flag_txsp == 1) {
5509 vht_mcsmap = 0xffc0;
5510 dut->testbed_flag_txsp = 0;
5511 } else {
5512 vht_mcsmap = 0xffea;
5513 }
5514 txchainmask = 7;
5515 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5516 if (dut->testbed_flag_txsp == 1) {
5517 vht_mcsmap = 0xff00;
5518 dut->testbed_flag_txsp = 0;
5519 } else {
5520 vht_mcsmap = 0xffaa;
5521 }
5522 txchainmask = 15;
5523 } else {
5524 if (dut->testbed_flag_txsp == 1) {
5525 vht_mcsmap = 0xffc0;
5526 dut->testbed_flag_txsp = 0;
5527 } else {
5528 vht_mcsmap = 0xffea;
5529 }
5530 }
5531
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005532 if (txchainmask)
5533 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005534
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005535 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005536}
5537
5538
5539static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5540 const char *val)
5541{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005542 unsigned int vht_mcsmap = 0;
5543 int rxchainmask = 0;
5544 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5545
5546 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5547 if (dut->testbed_flag_rxsp == 1) {
5548 vht_mcsmap = 0xfffc;
5549 dut->testbed_flag_rxsp = 0;
5550 } else {
5551 vht_mcsmap = 0xfffe;
5552 }
5553 rxchainmask = 1;
5554 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5555 if (dut->testbed_flag_rxsp == 1) {
5556 vht_mcsmap = 0xfff0;
5557 dut->testbed_flag_rxsp = 0;
5558 } else {
5559 vht_mcsmap = 0xfffa;
5560 }
5561 rxchainmask = 3;
5562 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5563 if (dut->testbed_flag_rxsp == 1) {
5564 vht_mcsmap = 0xffc0;
5565 dut->testbed_flag_rxsp = 0;
5566 } else {
5567 vht_mcsmap = 0xffea;
5568 }
5569 rxchainmask = 7;
5570 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5571 if (dut->testbed_flag_rxsp == 1) {
5572 vht_mcsmap = 0xff00;
5573 dut->testbed_flag_rxsp = 0;
5574 } else {
5575 vht_mcsmap = 0xffaa;
5576 }
5577 rxchainmask = 15;
5578 } else {
5579 if (dut->testbed_flag_rxsp == 1) {
5580 vht_mcsmap = 0xffc0;
5581 dut->testbed_flag_rxsp = 0;
5582 } else {
5583 vht_mcsmap = 0xffea;
5584 }
5585 }
5586
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005587 if (rxchainmask)
5588 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005589
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005590 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005591}
5592
5593
5594void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5595{
5596 if (strcasecmp(val, "enable") == 0) {
5597 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5598 != 0) {
5599 sigma_dut_print(dut, DUT_MSG_ERROR,
5600 "Disable BB_VHTSIGB_CRC_CALC failed");
5601 }
5602
5603 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5604 != 0) {
5605 sigma_dut_print(dut, DUT_MSG_ERROR,
5606 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5607 }
5608 } else {
5609 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5610 != 0) {
5611 sigma_dut_print(dut, DUT_MSG_ERROR,
5612 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5613 }
5614
5615 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5616 != 0) {
5617 sigma_dut_print(dut, DUT_MSG_ERROR,
5618 "Enable BB_VHTSIGB_CRC_CALC failed");
5619 }
5620 }
5621}
5622
5623
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005624static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5625 const char *val)
5626{
5627 char buf[60];
5628
5629 if (strcmp(val, "20") == 0) {
5630 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5631 dut->chwidth = 0;
5632 } else if (strcmp(val, "40") == 0) {
5633 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5634 dut->chwidth = 1;
5635 } else if (strcmp(val, "80") == 0) {
5636 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5637 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305638 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005639 buf[0] = '\0';
5640 } else {
5641 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5642 val);
5643 return -1;
5644 }
5645
5646 if (buf[0] != '\0' && system(buf) != 0) {
5647 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5648 return -1;
5649 }
5650
5651 return 0;
5652}
5653
5654
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005655static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5656 const char *intf, int addbareject)
5657{
5658#ifdef NL80211_SUPPORT
5659 struct nl_msg *msg;
5660 int ret = 0;
5661 struct nlattr *params;
5662 int ifindex;
5663
5664 ifindex = if_nametoindex(intf);
5665 if (ifindex == 0) {
5666 sigma_dut_print(dut, DUT_MSG_ERROR,
5667 "%s: Index for interface %s failed",
5668 __func__, intf);
5669 return -1;
5670 }
5671
5672 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5673 NL80211_CMD_VENDOR)) ||
5674 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5675 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5676 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5677 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5678 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5679 nla_put_u8(msg,
5680 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5681 !addbareject)) {
5682 sigma_dut_print(dut, DUT_MSG_ERROR,
5683 "%s: err in adding vendor_cmd and vendor_data",
5684 __func__);
5685 nlmsg_free(msg);
5686 return -1;
5687 }
5688 nla_nest_end(msg, params);
5689
5690 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5691 if (ret) {
5692 sigma_dut_print(dut, DUT_MSG_ERROR,
5693 "%s: err in send_and_recv_msgs, ret=%d",
5694 __func__, ret);
5695 }
5696 return ret;
5697#else /* NL80211_SUPPORT */
5698 sigma_dut_print(dut, DUT_MSG_ERROR,
5699 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5700 return -1;
5701#endif /* NL80211_SUPPORT */
5702}
5703
5704
5705static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5706 int addbareject)
5707{
5708 int ret;
5709
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005710 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005711 case DRIVER_WCN:
5712 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5713 if (ret) {
5714 sigma_dut_print(dut, DUT_MSG_ERROR,
5715 "nlvendor_sta_set_addba_reject failed, ret:%d",
5716 ret);
5717 return ret;
5718 }
5719 break;
5720 default:
5721 sigma_dut_print(dut, DUT_MSG_ERROR,
5722 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5723 ret = -1;
5724 break;
5725 }
5726
5727 return ret;
5728}
5729
5730
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005731static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5732 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005733{
5734#ifdef NL80211_SUPPORT
5735 struct nl_msg *msg;
5736 int ret = 0;
5737 struct nlattr *params;
5738 int ifindex;
5739
5740 ifindex = if_nametoindex(intf);
5741 if (ifindex == 0) {
5742 sigma_dut_print(dut, DUT_MSG_ERROR,
5743 "%s: Index for interface %s failed",
5744 __func__, intf);
5745 return -1;
5746 }
5747
5748 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5749 NL80211_CMD_VENDOR)) ||
5750 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5751 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5752 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5753 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5754 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5755 nla_put_u8(msg,
5756 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005757 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005758 sigma_dut_print(dut, DUT_MSG_ERROR,
5759 "%s: err in adding vendor_cmd and vendor_data",
5760 __func__);
5761 nlmsg_free(msg);
5762 return -1;
5763 }
5764 nla_nest_end(msg, params);
5765
5766 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5767 if (ret) {
5768 sigma_dut_print(dut, DUT_MSG_ERROR,
5769 "%s: err in send_and_recv_msgs, ret=%d",
5770 __func__, ret);
5771 }
5772 return ret;
5773#else /* NL80211_SUPPORT */
5774 sigma_dut_print(dut, DUT_MSG_ERROR,
5775 "Disable addba not possible without NL80211_SUPPORT defined");
5776 return -1;
5777#endif /* NL80211_SUPPORT */
5778}
5779
5780
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305781#ifdef NL80211_SUPPORT
5782static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5783{
5784 struct nl_msg *msg;
5785 int ret = 0;
5786 int ifindex;
5787
5788 ifindex = if_nametoindex(intf);
5789 if (ifindex == 0) {
5790 sigma_dut_print(dut, DUT_MSG_ERROR,
5791 "%s: Index for interface %s failed",
5792 __func__, intf);
5793 return -1;
5794 }
5795
5796 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5797 NL80211_CMD_SET_WIPHY)) ||
5798 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5799 sigma_dut_print(dut, DUT_MSG_ERROR,
5800 "%s: err in adding RTS threshold",
5801 __func__);
5802 nlmsg_free(msg);
5803 return -1;
5804 }
5805
5806 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5807 if (ret) {
5808 sigma_dut_print(dut, DUT_MSG_ERROR,
5809 "%s: err in send_and_recv_msgs, ret=%d",
5810 __func__, ret);
5811 }
5812 return ret;
5813}
5814#endif /* NL80211_SUPPORT */
5815
5816
5817static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5818{
5819 char buf[100];
5820
5821#ifdef NL80211_SUPPORT
5822 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5823 return 0;
5824 sigma_dut_print(dut, DUT_MSG_DEBUG,
5825 "Fall back to using iwconfig for setting RTS threshold");
5826#endif /* NL80211_SUPPORT */
5827
5828 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5829 if (system(buf) != 0) {
5830 sigma_dut_print(dut, DUT_MSG_ERROR,
5831 "Failed to set RTS threshold %d", val);
5832 return -1;
5833 }
5834 return 0;
5835}
5836
5837
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005838static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5839 struct sigma_conn *conn,
5840 struct sigma_cmd *cmd)
5841{
5842 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005843 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005844 char buf[128];
5845 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005846
5847 val = get_param(cmd, "40_INTOLERANT");
5848 if (val) {
5849 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5850 /* TODO: iwpriv ht40intol through wpa_supplicant */
5851 send_resp(dut, conn, SIGMA_ERROR,
5852 "ErrorCode,40_INTOLERANT not supported");
5853 return 0;
5854 }
5855 }
5856
5857 val = get_param(cmd, "ADDBA_REJECT");
5858 if (val) {
5859 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5860 /* reject any ADDBA with status "decline" */
5861 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005862 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005863 } else {
5864 /* accept ADDBA */
5865 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005866 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005867 }
5868 }
5869
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005870 if (addbareject >= 0 &&
5871 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5872 send_resp(dut, conn, SIGMA_ERROR,
5873 "ErrorCode,set addba_reject failed");
5874 return 0;
5875 }
5876
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005877 val = get_param(cmd, "AMPDU");
5878 if (val) {
5879 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5880 /* enable AMPDU Aggregation */
5881 if (ampdu == 0) {
5882 send_resp(dut, conn, SIGMA_ERROR,
5883 "ErrorCode,Mismatch in "
5884 "addba_reject/ampdu - "
5885 "not supported");
5886 return 0;
5887 }
5888 ampdu = 1;
5889 } else {
5890 /* disable AMPDU Aggregation */
5891 if (ampdu == 1) {
5892 send_resp(dut, conn, SIGMA_ERROR,
5893 "ErrorCode,Mismatch in "
5894 "addba_reject/ampdu - "
5895 "not supported");
5896 return 0;
5897 }
5898 ampdu = 0;
5899 }
5900 }
5901
5902 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005903 int ret;
5904
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005905 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5906 ampdu ? "Enabling" : "Disabling");
5907 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005908 if (wpa_command(intf, buf) < 0 &&
5909 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005910 send_resp(dut, conn, SIGMA_ERROR,
5911 "ErrorCode,set aggr failed");
5912 return 0;
5913 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005914
5915 if (ampdu == 0) {
5916 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005917 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005918 if (ret) {
5919 sigma_dut_print(dut, DUT_MSG_ERROR,
5920 "Failed to disable addba, ret:%d",
5921 ret);
5922 }
5923 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005924 }
5925
5926 val = get_param(cmd, "AMSDU");
5927 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005928 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005929 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005930 case DRIVER_WCN:
5931 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005932 break;
5933 default:
5934 if (strcmp(val, "1") == 0 ||
5935 strcasecmp(val, "Enable") == 0) {
5936 /* Enable AMSDU Aggregation */
5937 send_resp(dut, conn, SIGMA_ERROR,
5938 "ErrorCode,AMSDU aggregation not supported");
5939 return 0;
5940 }
5941 break;
5942 }
5943 }
5944
5945 val = get_param(cmd, "STBC_RX");
5946 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005947 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005948 case DRIVER_ATHEROS:
5949 ath_sta_set_stbc(dut, intf, val);
5950 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305951 case DRIVER_WCN:
5952 wcn_sta_set_stbc(dut, intf, val);
5953 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005954 default:
5955 send_resp(dut, conn, SIGMA_ERROR,
5956 "ErrorCode,STBC_RX not supported");
5957 return 0;
5958 }
5959 }
5960
5961 val = get_param(cmd, "WIDTH");
5962 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005963 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005964 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005965 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005966 send_resp(dut, conn, SIGMA_ERROR,
5967 "ErrorCode,Failed to set WIDTH");
5968 return 0;
5969 }
5970 break;
5971 case DRIVER_ATHEROS:
5972 if (ath_set_width(dut, conn, intf, val) < 0)
5973 return 0;
5974 break;
5975 default:
5976 sigma_dut_print(dut, DUT_MSG_ERROR,
5977 "Setting WIDTH not supported");
5978 break;
5979 }
5980 }
5981
5982 val = get_param(cmd, "SMPS");
5983 if (val) {
5984 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5985 send_resp(dut, conn, SIGMA_ERROR,
5986 "ErrorCode,SMPS not supported");
5987 return 0;
5988 }
5989
5990 val = get_param(cmd, "TXSP_STREAM");
5991 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005992 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005993 case DRIVER_WCN:
5994 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5995 send_resp(dut, conn, SIGMA_ERROR,
5996 "ErrorCode,Failed to set TXSP_STREAM");
5997 return 0;
5998 }
5999 break;
6000 case DRIVER_ATHEROS:
6001 ath_sta_set_txsp_stream(dut, intf, val);
6002 break;
6003 default:
6004 sigma_dut_print(dut, DUT_MSG_ERROR,
6005 "Setting TXSP_STREAM not supported");
6006 break;
6007 }
6008 }
6009
6010 val = get_param(cmd, "RXSP_STREAM");
6011 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006012 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006013 case DRIVER_WCN:
6014 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
6015 send_resp(dut, conn, SIGMA_ERROR,
6016 "ErrorCode,Failed to set RXSP_STREAM");
6017 return 0;
6018 }
6019 break;
6020 case DRIVER_ATHEROS:
6021 ath_sta_set_rxsp_stream(dut, intf, val);
6022 break;
6023 default:
6024 sigma_dut_print(dut, DUT_MSG_ERROR,
6025 "Setting RXSP_STREAM not supported");
6026 break;
6027 }
6028 }
6029
6030 val = get_param(cmd, "DYN_BW_SGNL");
6031 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006032 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006033 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08006034 if (strcasecmp(val, "enable") == 0) {
6035 snprintf(buf, sizeof(buf),
6036 "iwpriv %s cwmenable 1", intf);
6037 if (system(buf) != 0) {
6038 sigma_dut_print(dut, DUT_MSG_ERROR,
6039 "iwpriv cwmenable 1 failed");
6040 return 0;
6041 }
6042 } else if (strcasecmp(val, "disable") == 0) {
6043 snprintf(buf, sizeof(buf),
6044 "iwpriv %s cwmenable 0", intf);
6045 if (system(buf) != 0) {
6046 sigma_dut_print(dut, DUT_MSG_ERROR,
6047 "iwpriv cwmenable 0 failed");
6048 return 0;
6049 }
6050 } else {
6051 sigma_dut_print(dut, DUT_MSG_ERROR,
6052 "Unsupported DYN_BW_SGL");
6053 }
6054
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006055 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
6056 if (system(buf) != 0) {
6057 sigma_dut_print(dut, DUT_MSG_ERROR,
6058 "Failed to set cts_cbw in DYN_BW_SGNL");
6059 return 0;
6060 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006061 break;
6062 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006063 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006064 ath_config_dyn_bw_sig(dut, intf, val);
6065 break;
6066 default:
6067 sigma_dut_print(dut, DUT_MSG_ERROR,
6068 "Failed to set DYN_BW_SGNL");
6069 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006070 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006071 }
6072
6073 val = get_param(cmd, "RTS_FORCE");
6074 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006075 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006076 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306077 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006078 sigma_dut_print(dut, DUT_MSG_ERROR,
6079 "Failed to set RTS_FORCE 64");
6080 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03006081 res = snprintf(buf, sizeof(buf),
6082 "wifitool %s beeliner_fw_test 100 1",
6083 intf);
6084 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08006085 sigma_dut_print(dut, DUT_MSG_ERROR,
6086 "wifitool beeliner_fw_test 100 1 failed");
6087 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006088 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306089 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006090 sigma_dut_print(dut, DUT_MSG_ERROR,
6091 "Failed to set RTS_FORCE 2347");
6092 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006093 } else {
6094 send_resp(dut, conn, SIGMA_ERROR,
6095 "ErrorCode,RTS_FORCE value not supported");
6096 return 0;
6097 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006098 }
6099
6100 val = get_param(cmd, "CTS_WIDTH");
6101 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006102 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006103 case DRIVER_WCN:
6104 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
6105 send_resp(dut, conn, SIGMA_ERROR,
6106 "ErrorCode,Failed to set CTS_WIDTH");
6107 return 0;
6108 }
6109 break;
6110 case DRIVER_ATHEROS:
6111 ath_set_cts_width(dut, intf, val);
6112 break;
6113 default:
6114 sigma_dut_print(dut, DUT_MSG_ERROR,
6115 "Setting CTS_WIDTH not supported");
6116 break;
6117 }
6118 }
6119
6120 val = get_param(cmd, "BW_SGNL");
6121 if (val) {
6122 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006123 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006124 } else if (strcasecmp(val, "Disable") == 0) {
6125 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006126 } else {
6127 send_resp(dut, conn, SIGMA_ERROR,
6128 "ErrorCode,BW_SGNL value not supported");
6129 return 0;
6130 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006131 }
6132
6133 val = get_param(cmd, "Band");
6134 if (val) {
6135 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
6136 /* STA supports all bands by default */
6137 } else {
6138 send_resp(dut, conn, SIGMA_ERROR,
6139 "ErrorCode,Unsupported Band");
6140 return 0;
6141 }
6142 }
6143
6144 val = get_param(cmd, "zero_crc");
6145 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006146 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006147 case DRIVER_ATHEROS:
6148 ath_set_zero_crc(dut, val);
6149 break;
6150 default:
6151 break;
6152 }
6153 }
6154
6155 return 1;
6156}
6157
6158
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006159static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
6160{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006161 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006162#ifdef __linux__
6163 case DRIVER_WIL6210:
6164 return wil6210_set_force_mcs(dut, force, mcs);
6165#endif /* __linux__ */
6166 default:
6167 sigma_dut_print(dut, DUT_MSG_ERROR,
6168 "Unsupported sta_set_force_mcs with the current driver");
6169 return -1;
6170 }
6171}
6172
6173
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006174static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
6175{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006176 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006177#ifdef __linux__
6178 case DRIVER_WIL6210:
6179 return wil6210_force_rsn_ie(dut, state);
6180#endif /* __linux__ */
6181 default:
6182 sigma_dut_print(dut, DUT_MSG_ERROR,
6183 "Unsupported sta_60g_force_rsn_ie with the current driver");
6184 return -1;
6185 }
6186}
6187
6188
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006189static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
6190 struct sigma_cmd *cmd)
6191{
6192 const char *val;
6193 char buf[100];
6194
6195 val = get_param(cmd, "MSDUSize");
6196 if (val) {
6197 int mtu;
6198
6199 dut->amsdu_size = atoi(val);
6200 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
6201 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
6202 sigma_dut_print(dut, DUT_MSG_ERROR,
6203 "MSDUSize %d is above max %d or below min %d",
6204 dut->amsdu_size,
6205 IEEE80211_MAX_DATA_LEN_DMG,
6206 IEEE80211_SNAP_LEN_DMG);
6207 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006208 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006209 }
6210
6211 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
6212 sigma_dut_print(dut, DUT_MSG_DEBUG,
6213 "Setting amsdu_size to %d", mtu);
6214 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006215 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006216
6217 if (system(buf) != 0) {
6218 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
6219 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006220 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006221 }
6222 }
6223
6224 val = get_param(cmd, "BAckRcvBuf");
6225 if (val) {
6226 dut->back_rcv_buf = atoi(val);
6227 if (dut->back_rcv_buf == 0) {
6228 sigma_dut_print(dut, DUT_MSG_ERROR,
6229 "Failed to convert %s or value is 0",
6230 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006231 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006232 }
6233
6234 sigma_dut_print(dut, DUT_MSG_DEBUG,
6235 "Setting BAckRcvBuf to %s", val);
6236 }
6237
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006238 val = get_param(cmd, "MCS_FixedRate");
6239 if (val) {
6240 if (sta_set_force_mcs(dut, 1, atoi(val))) {
6241 sigma_dut_print(dut, DUT_MSG_ERROR,
6242 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006243 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006244 }
6245 }
6246
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006247 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006248}
6249
6250
6251static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
6252 struct sigma_cmd *cmd)
6253{
6254 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006255 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006256 const char *val;
6257 char buf[100];
6258
6259 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006260 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006261 if (wpa_command(ifname, "PING") != 0) {
6262 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006263 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006264 }
6265
6266 wpa_command(ifname, "FLUSH");
6267 net_id = add_network_common(dut, conn, ifname, cmd);
6268 if (net_id < 0) {
6269 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
6270 return net_id;
6271 }
6272
6273 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
6274 if (set_network(ifname, net_id, "mode", "2") < 0) {
6275 sigma_dut_print(dut, DUT_MSG_ERROR,
6276 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006277 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006278 }
6279
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006280 if (set_network(ifname, net_id, "pbss", "1") < 0)
6281 return -2;
6282
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006283 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006284 "Supplicant set network with mode 2. network_id %d",
6285 net_id);
6286
6287 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6288 sigma_dut_print(dut, DUT_MSG_INFO,
6289 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006290 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006291 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006292
6293 val = get_param(cmd, "Security");
6294 if (val && strcasecmp(val, "OPEN") == 0) {
6295 dut->ap_key_mgmt = AP_OPEN;
6296 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6297 sigma_dut_print(dut, DUT_MSG_ERROR,
6298 "Failed to set supplicant to %s security",
6299 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006300 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006301 }
6302 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6303 dut->ap_key_mgmt = AP_WPA2_PSK;
6304 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6305 sigma_dut_print(dut, DUT_MSG_ERROR,
6306 "Failed to set supplicant to %s security",
6307 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006308 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006309 }
6310
6311 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6312 sigma_dut_print(dut, DUT_MSG_ERROR,
6313 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006314 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006315 }
6316 } else if (val) {
6317 sigma_dut_print(dut, DUT_MSG_ERROR,
6318 "Requested Security %s is not supported on 60GHz",
6319 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006320 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006321 }
6322
6323 val = get_param(cmd, "Encrypt");
6324 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6325 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6326 sigma_dut_print(dut, DUT_MSG_ERROR,
6327 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006328 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006329 }
6330 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6331 sigma_dut_print(dut, DUT_MSG_ERROR,
6332 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006333 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006334 }
6335 } else if (val) {
6336 sigma_dut_print(dut, DUT_MSG_ERROR,
6337 "Requested Encrypt %s is not supported on 60 GHz",
6338 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006339 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006340 }
6341
6342 val = get_param(cmd, "PSK");
6343 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6344 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6345 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006346 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006347 }
6348
6349 /* Convert 60G channel to freq */
6350 switch (dut->ap_channel) {
6351 case 1:
6352 val = "58320";
6353 break;
6354 case 2:
6355 val = "60480";
6356 break;
6357 case 3:
6358 val = "62640";
6359 break;
6360 default:
6361 sigma_dut_print(dut, DUT_MSG_ERROR,
6362 "Failed to configure channel %d. Not supported",
6363 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006364 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006365 }
6366
6367 if (set_network(ifname, net_id, "frequency", val) < 0) {
6368 sigma_dut_print(dut, DUT_MSG_ERROR,
6369 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006370 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006371 }
6372
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006373 if (dut->eap_fragment) {
6374 sigma_dut_print(dut, DUT_MSG_DEBUG,
6375 "Set EAP fragment size to 128 bytes.");
6376 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6377 return ERROR_SEND_STATUS;
6378 }
6379
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006380 sigma_dut_print(dut, DUT_MSG_DEBUG,
6381 "Supplicant set network with frequency");
6382
6383 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6384 if (wpa_command(ifname, buf) < 0) {
6385 sigma_dut_print(dut, DUT_MSG_INFO,
6386 "Failed to select network id %d on %s",
6387 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006388 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006389 }
6390
6391 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6392
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006393 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006394}
6395
6396
Lior David67543f52017-01-03 19:04:22 +02006397static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6398{
6399 char buf[128], fname[128];
6400 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006401 int res;
Lior David67543f52017-01-03 19:04:22 +02006402
6403 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6404 sigma_dut_print(dut, DUT_MSG_ERROR,
6405 "failed to get wil6210 debugfs dir");
6406 return -1;
6407 }
6408
Jouni Malinen3aa72862019-05-29 23:14:51 +03006409 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6410 if (res < 0 || res >= sizeof(fname))
6411 return -1;
Lior David67543f52017-01-03 19:04:22 +02006412 f = fopen(fname, "w");
6413 if (!f) {
6414 sigma_dut_print(dut, DUT_MSG_ERROR,
6415 "failed to open: %s", fname);
6416 return -1;
6417 }
6418
6419 fprintf(f, "%d\n", abft_len);
6420 fclose(f);
6421
6422 return 0;
6423}
6424
6425
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006426int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6427 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006428{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006429 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006430 case DRIVER_WIL6210:
6431 return wil6210_set_abft_len(dut, abft_len);
6432 default:
6433 sigma_dut_print(dut, DUT_MSG_ERROR,
6434 "set abft_len not supported");
6435 return -1;
6436 }
6437}
6438
6439
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006440static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6441 struct sigma_cmd *cmd)
6442{
6443 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006444 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006445
6446 if (dut->dev_role != DEVROLE_PCP) {
6447 send_resp(dut, conn, SIGMA_INVALID,
6448 "ErrorCode,Invalid DevRole");
6449 return 0;
6450 }
6451
6452 val = get_param(cmd, "SSID");
6453 if (val) {
6454 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6455 send_resp(dut, conn, SIGMA_INVALID,
6456 "ErrorCode,Invalid SSID");
6457 return -1;
6458 }
6459
Peng Xub8fc5cc2017-05-10 17:27:28 -07006460 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006461 }
6462
6463 val = get_param(cmd, "CHANNEL");
6464 if (val) {
6465 const char *pos;
6466
6467 dut->ap_channel = atoi(val);
6468 pos = strchr(val, ';');
6469 if (pos) {
6470 pos++;
6471 dut->ap_channel_1 = atoi(pos);
6472 }
6473 }
6474
6475 switch (dut->ap_channel) {
6476 case 1:
6477 case 2:
6478 case 3:
6479 break;
6480 default:
6481 sigma_dut_print(dut, DUT_MSG_ERROR,
6482 "Channel %d is not supported", dut->ap_channel);
6483 send_resp(dut, conn, SIGMA_ERROR,
6484 "Requested channel is not supported");
6485 return -1;
6486 }
6487
6488 val = get_param(cmd, "BCNINT");
6489 if (val)
6490 dut->ap_bcnint = atoi(val);
6491
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006492 val = get_param(cmd, "AllocType");
6493 if (val) {
6494 send_resp(dut, conn, SIGMA_ERROR,
6495 "ErrorCode,AllocType is not supported yet");
6496 return -1;
6497 }
6498
6499 val = get_param(cmd, "PercentBI");
6500 if (val) {
6501 send_resp(dut, conn, SIGMA_ERROR,
6502 "ErrorCode,PercentBI is not supported yet");
6503 return -1;
6504 }
6505
6506 val = get_param(cmd, "CBAPOnly");
6507 if (val) {
6508 send_resp(dut, conn, SIGMA_ERROR,
6509 "ErrorCode,CBAPOnly is not supported yet");
6510 return -1;
6511 }
6512
6513 val = get_param(cmd, "AMPDU");
6514 if (val) {
6515 if (strcasecmp(val, "Enable") == 0)
6516 dut->ap_ampdu = 1;
6517 else if (strcasecmp(val, "Disable") == 0)
6518 dut->ap_ampdu = 2;
6519 else {
6520 send_resp(dut, conn, SIGMA_ERROR,
6521 "ErrorCode,AMPDU value is not Enable nor Disabled");
6522 return -1;
6523 }
6524 }
6525
6526 val = get_param(cmd, "AMSDU");
6527 if (val) {
6528 if (strcasecmp(val, "Enable") == 0)
6529 dut->ap_amsdu = 1;
6530 else if (strcasecmp(val, "Disable") == 0)
6531 dut->ap_amsdu = 2;
6532 }
6533
6534 val = get_param(cmd, "NumMSDU");
6535 if (val) {
6536 send_resp(dut, conn, SIGMA_ERROR,
6537 "ErrorCode, NumMSDU is not supported yet");
6538 return -1;
6539 }
6540
6541 val = get_param(cmd, "ABFTLRang");
6542 if (val) {
6543 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006544 "ABFTLRang parameter %s", val);
6545 if (strcmp(val, "Gt1") == 0)
6546 abft_len = 2; /* 2 slots in this case */
6547 }
6548
6549 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6550 send_resp(dut, conn, SIGMA_ERROR,
6551 "ErrorCode, Can't set ABFT length");
6552 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006553 }
6554
6555 if (sta_pcp_start(dut, conn, cmd) < 0) {
6556 send_resp(dut, conn, SIGMA_ERROR,
6557 "ErrorCode, Can't start PCP role");
6558 return -1;
6559 }
6560
6561 return sta_set_60g_common(dut, conn, cmd);
6562}
6563
6564
6565static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6566 struct sigma_cmd *cmd)
6567{
6568 const char *val = get_param(cmd, "DiscoveryMode");
6569
6570 if (dut->dev_role != DEVROLE_STA) {
6571 send_resp(dut, conn, SIGMA_INVALID,
6572 "ErrorCode,Invalid DevRole");
6573 return 0;
6574 }
6575
6576 if (val) {
6577 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6578 /* Ignore Discovery mode till Driver expose API. */
6579#if 0
6580 if (strcasecmp(val, "1") == 0) {
6581 send_resp(dut, conn, SIGMA_INVALID,
6582 "ErrorCode,DiscoveryMode 1 not supported");
6583 return 0;
6584 }
6585
6586 if (strcasecmp(val, "0") == 0) {
6587 /* OK */
6588 } else {
6589 send_resp(dut, conn, SIGMA_INVALID,
6590 "ErrorCode,DiscoveryMode not supported");
6591 return 0;
6592 }
6593#endif
6594 }
6595
6596 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006597 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006598 return sta_set_60g_common(dut, conn, cmd);
6599}
6600
6601
Jouni Malinenf7222712019-06-13 01:50:21 +03006602static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6603 struct sigma_conn *conn,
6604 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006605{
6606 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006607 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306608
Jouni Malinened77e672018-01-10 16:45:13 +02006609 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006610 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006611 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306612 wpa_command(intf, "DISCONNECT");
6613 return 1;
6614 }
6615
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006616 disconnect_station(dut);
6617 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6618 * due to cached results. */
6619 wpa_command(intf, "SET ignore_old_scan_res 1");
6620 wpa_command(intf, "BSS_FLUSH");
6621 return 1;
6622}
6623
6624
Jouni Malinenf7222712019-06-13 01:50:21 +03006625static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6626 struct sigma_conn *conn,
6627 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006628{
6629 const char *intf = get_param(cmd, "Interface");
6630 const char *bssid = get_param(cmd, "bssid");
6631 const char *val = get_param(cmd, "CHANNEL");
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006632 const char *freq_val = get_param(cmd, "ChnlFreq");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006633 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306634 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306635 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006636 int res;
6637 int chan = 0;
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006638 int freq = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006639 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306640 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006641 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006642
6643 if (bssid == NULL) {
6644 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6645 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006646 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006647 }
6648
6649 if (val)
6650 chan = atoi(val);
6651
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006652 if (freq_val)
6653 freq = atoi(freq_val);
6654
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006655 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6656 /* The current network may be from sta_associate or
6657 * sta_hs2_associate
6658 */
6659 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6660 0 ||
6661 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006662 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006663 }
6664
6665 ctrl = open_wpa_mon(intf);
6666 if (ctrl == NULL) {
6667 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6668 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006669 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006670 }
6671
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006672 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05306673 sizeof(result)) < 0 ||
6674 strncmp(result, "COMPLETED", 9) != 0) {
6675 sigma_dut_print(dut, DUT_MSG_DEBUG,
6676 "sta_reassoc: Not connected");
6677 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006678 } else if (dut->sta_ft_ds) {
6679 sigma_dut_print(dut, DUT_MSG_DEBUG,
6680 "sta_reassoc: Use FT-over-DS");
6681 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306682 }
6683
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306684 if (dut->rsne_override) {
6685#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006686 if (get_driver_type(dut) == DRIVER_WCN &&
6687 dut->config_rsnie == 0) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05306688 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306689 dut->config_rsnie = 1;
6690 }
6691#endif /* NL80211_SUPPORT */
6692 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6693 dut->rsne_override);
6694 if (wpa_command(intf, buf) < 0) {
6695 send_resp(dut, conn, SIGMA_ERROR,
6696 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6697 return 0;
6698 }
6699 }
6700
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006701 if (ft_ds) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006702 if (chan || freq) {
6703 if (!freq)
6704 freq = channel_to_freq(dut, chan);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006705 if (!freq) {
6706 sigma_dut_print(dut, DUT_MSG_ERROR,
6707 "Invalid channel number provided: %d",
6708 chan);
6709 send_resp(dut, conn, SIGMA_INVALID,
6710 "ErrorCode,Invalid channel number");
6711 goto close_mon_conn;
6712 }
6713 res = snprintf(buf, sizeof(buf),
6714 "SCAN TYPE=ONLY freq=%d", freq);
6715 } else {
6716 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6717 }
6718 if (res < 0 || res >= (int) sizeof(buf)) {
6719 send_resp(dut, conn, SIGMA_ERROR,
6720 "ErrorCode,snprintf failed");
6721 goto close_mon_conn;
6722 }
6723 if (wpa_command(intf, buf) < 0) {
6724 sigma_dut_print(dut, DUT_MSG_INFO,
6725 "Failed to start scan");
6726 send_resp(dut, conn, SIGMA_ERROR,
6727 "ErrorCode,scan failed");
6728 goto close_mon_conn;
6729 }
6730
6731 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6732 buf, sizeof(buf));
6733 if (res < 0) {
6734 sigma_dut_print(dut, DUT_MSG_INFO,
6735 "Scan did not complete");
6736 send_resp(dut, conn, SIGMA_ERROR,
6737 "ErrorCode,scan did not complete");
6738 goto close_mon_conn;
6739 }
6740
6741 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6742 if (res > 0 && res < (int) sizeof(buf))
6743 res = wpa_command(intf, buf);
6744
6745 if (res < 0 || res >= (int) sizeof(buf)) {
6746 send_resp(dut, conn, SIGMA_ERROR,
6747 "errorCode,FT_DS command failed");
6748 status = STATUS_SENT_ERROR;
6749 goto close_mon_conn;
6750 }
6751 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006752 if (chan || freq) {
6753 if (!freq)
6754 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306755 if (!freq) {
6756 sigma_dut_print(dut, DUT_MSG_ERROR,
6757 "Invalid channel number provided: %d",
6758 chan);
6759 send_resp(dut, conn, SIGMA_INVALID,
6760 "ErrorCode,Invalid channel number");
6761 goto close_mon_conn;
6762 }
6763 res = snprintf(buf, sizeof(buf),
6764 "SCAN TYPE=ONLY freq=%d", freq);
6765 } else {
6766 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6767 }
6768 if (res < 0 || res >= (int) sizeof(buf)) {
6769 send_resp(dut, conn, SIGMA_ERROR,
6770 "ErrorCode,snprintf failed");
6771 goto close_mon_conn;
6772 }
6773 if (wpa_command(intf, buf) < 0) {
6774 sigma_dut_print(dut, DUT_MSG_INFO,
6775 "Failed to start scan");
6776 send_resp(dut, conn, SIGMA_ERROR,
6777 "ErrorCode,scan failed");
6778 goto close_mon_conn;
6779 }
6780
6781 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6782 buf, sizeof(buf));
6783 if (res < 0) {
6784 sigma_dut_print(dut, DUT_MSG_INFO,
6785 "Scan did not complete");
6786 send_resp(dut, conn, SIGMA_ERROR,
6787 "ErrorCode,scan did not complete");
6788 goto close_mon_conn;
6789 }
6790
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006791 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6792 < 0) {
6793 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6794 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006795 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306796 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006797 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306798 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006799 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306800 if (res < 0 || res >= (int) sizeof(buf) ||
6801 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006802 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306803 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306804 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006805 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006806 sigma_dut_print(dut, DUT_MSG_INFO,
6807 "sta_reassoc: Run %s successful", buf);
6808 } else if (wpa_command(intf, "REASSOCIATE")) {
6809 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6810 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306811 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006812 }
6813
6814 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6815 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306816 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006817 send_resp(dut, conn, SIGMA_ERROR,
6818 "errorCode,Connection did not complete");
6819 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306820 goto close_mon_conn;
6821 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006822 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006823
Ashwini Patil467efef2017-05-25 12:18:27 +05306824close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006825 wpa_ctrl_detach(ctrl);
6826 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306827 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006828}
6829
6830
6831static void hs2_clear_credentials(const char *intf)
6832{
6833 wpa_command(intf, "REMOVE_CRED all");
6834}
6835
6836
Lior Davidcc88b562017-01-03 18:52:09 +02006837#ifdef __linux__
6838static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6839 unsigned int *aid)
6840{
Lior David0fe101e2017-03-09 16:09:50 +02006841 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006842
Lior David0fe101e2017-03-09 16:09:50 +02006843 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006844}
6845#endif /* __linux__ */
6846
6847
6848static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6849 unsigned int *aid)
6850{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006851 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02006852#ifdef __linux__
6853 case DRIVER_WIL6210:
6854 return wil6210_get_aid(dut, bssid, aid);
6855#endif /* __linux__ */
6856 default:
6857 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6858 return -1;
6859 }
6860}
6861
6862
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006863static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6864 struct sigma_cmd *cmd)
6865{
6866 char buf[MAX_CMD_LEN];
6867 char bss_list[MAX_CMD_LEN];
6868 const char *parameter = get_param(cmd, "Parameter");
6869
6870 if (parameter == NULL)
6871 return -1;
6872
Lior Davidcc88b562017-01-03 18:52:09 +02006873 if (strcasecmp(parameter, "AID") == 0) {
6874 unsigned int aid = 0;
6875 char bssid[20];
6876
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006877 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02006878 bssid, sizeof(bssid)) < 0) {
6879 sigma_dut_print(dut, DUT_MSG_ERROR,
6880 "could not get bssid");
6881 return -2;
6882 }
6883
6884 if (sta_get_aid_60g(dut, bssid, &aid))
6885 return -2;
6886
6887 snprintf(buf, sizeof(buf), "aid,%d", aid);
6888 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6889 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6890 return 0;
6891 }
6892
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006893 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6894 char *bss_line;
6895 char *bss_id = NULL;
6896 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306897 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006898
6899 if (ifname == NULL) {
6900 sigma_dut_print(dut, DUT_MSG_INFO,
6901 "For get DiscoveredDevList need Interface name.");
6902 return -1;
6903 }
6904
6905 /*
6906 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6907 * of BSSIDs in "bssid=<BSSID>\n"
6908 */
6909 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6910 bss_list,
6911 sizeof(bss_list)) < 0) {
6912 sigma_dut_print(dut, DUT_MSG_ERROR,
6913 "Failed to get bss list");
6914 return -1;
6915 }
6916
6917 sigma_dut_print(dut, DUT_MSG_DEBUG,
6918 "bss list for ifname:%s is:%s",
6919 ifname, bss_list);
6920
6921 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306922 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006923 while (bss_line) {
6924 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6925 bss_id) {
6926 int len;
6927
6928 len = snprintf(buf + strlen(buf),
6929 sizeof(buf) - strlen(buf),
6930 ",%s", bss_id);
6931 free(bss_id);
6932 bss_id = NULL;
6933 if (len < 0) {
6934 sigma_dut_print(dut,
6935 DUT_MSG_ERROR,
6936 "Failed to read BSSID");
6937 send_resp(dut, conn, SIGMA_ERROR,
6938 "ErrorCode,Failed to read BSS ID");
6939 return 0;
6940 }
6941
6942 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6943 sigma_dut_print(dut,
6944 DUT_MSG_ERROR,
6945 "Response buf too small for list");
6946 send_resp(dut, conn,
6947 SIGMA_ERROR,
6948 "ErrorCode,Response buf too small for list");
6949 return 0;
6950 }
6951 }
6952
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306953 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006954 }
6955
6956 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6957 buf);
6958 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6959 return 0;
6960 }
6961
6962 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6963 return 0;
6964}
6965
6966
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006967static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6968 struct sigma_cmd *cmd)
6969{
6970 char buf[MAX_CMD_LEN];
6971 const char *parameter = get_param(cmd, "Parameter");
6972
6973 if (!parameter)
6974 return -1;
6975
6976 if (strcasecmp(parameter, "RSSI") == 0) {
6977 char rssi[10];
6978
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006979 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006980 rssi, sizeof(rssi)) < 0) {
6981 sigma_dut_print(dut, DUT_MSG_ERROR,
6982 "Could not get RSSI");
6983 return -2;
6984 }
6985
6986 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6987 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6988 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6989 return 0;
6990 }
6991
6992 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6993 return 0;
6994}
6995
6996
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05306997#ifdef NL80211_SUPPORT
6998
6999struct station_info {
7000 uint64_t filled;
7001 uint32_t beacon_mic_error_count;
7002 uint32_t beacon_replay_count;
7003};
7004
7005
7006static int qca_get_sta_info_handler(struct nl_msg *msg, void *arg)
7007{
7008 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7009 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7010 struct station_info *data = arg;
7011 struct nlattr *info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1];
7012 static struct nla_policy info_policy[
7013 QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1] = {
7014 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT] = {
7015 .type = NLA_U32
7016 },
7017 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT] = {
7018 .type = NLA_U32
7019 },
7020 };
7021
7022 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7023 genlmsg_attrlen(gnlh, 0), NULL);
7024
7025 if (!tb[NL80211_ATTR_VENDOR_DATA])
7026 return NL_SKIP;
7027
7028 if (nla_parse_nested(info, QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX,
7029 tb[NL80211_ATTR_VENDOR_DATA], info_policy)) {
7030 return NL_SKIP;
7031 }
7032
7033 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]) {
7034 data->filled |=
7035 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT);
7036 data->beacon_mic_error_count =
7037 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]);
7038 }
7039
7040 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]) {
7041 data->filled |=
7042 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT);
7043 data->beacon_replay_count =
7044 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]);
7045 }
7046
7047 return NL_SKIP;
7048}
7049
7050
7051static int qca_nl80211_get_sta_info(struct sigma_dut *dut, const char *intf,
7052 struct station_info *sta_data)
7053{
7054 struct nl_msg *msg;
7055 int ifindex, ret;
7056
7057 ifindex = if_nametoindex(intf);
7058 if (ifindex == 0) {
7059 sigma_dut_print(dut, DUT_MSG_ERROR,
7060 "%s: Index for interface %s not found",
7061 __func__, intf);
7062 return -1;
7063 }
7064
7065 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7066 NL80211_CMD_VENDOR)) ||
7067 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7068 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7069 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7070 QCA_NL80211_VENDOR_SUBCMD_GET_STA_INFO)) {
7071 sigma_dut_print(dut, DUT_MSG_ERROR,
7072 "%s: err in adding vendor_cmd", __func__);
7073 nlmsg_free(msg);
7074 return -1;
7075 }
7076
7077 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg,
7078 qca_get_sta_info_handler, sta_data);
7079 if (ret) {
7080 sigma_dut_print(dut, DUT_MSG_ERROR,
7081 "%s: err in send_and_recv_msgs, ret=%d",
7082 __func__, ret);
7083 }
7084 return ret;
7085}
7086#endif /* NL80211_SUPPORT */
7087
7088
7089static int get_bip_mic_error_count(struct sigma_dut *dut,
7090 const char *ifname,
7091 unsigned int *count)
7092{
7093#ifdef NL80211_SUPPORT
7094 struct station_info sta_data;
7095#endif /* NL80211_SUPPORT */
7096
7097 if (get_driver_type(dut) != DRIVER_WCN) {
7098 sigma_dut_print(dut, DUT_MSG_ERROR,
7099 "BIP MIC error count not supported");
7100 return -1;
7101 }
7102
7103#ifdef NL80211_SUPPORT
7104 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
7105 !(sta_data.filled &
7106 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT))) {
7107 sigma_dut_print(dut, DUT_MSG_ERROR,
7108 "BIP MIC error count fetching failed");
7109 return -1;
7110 }
7111
7112 *count = sta_data.beacon_mic_error_count;
7113 return 0;
7114#else /* NL80211_SUPPORT */
7115 sigma_dut_print(dut, DUT_MSG_ERROR,
7116 "BIP MIC error count cannot be fetched without NL80211_SUPPORT defined");
7117 return -1;
7118#endif /* NL80211_SUPPORT */
7119}
7120
7121
7122static int get_cmac_replay_count(struct sigma_dut *dut, const char *ifname,
7123 unsigned int *count)
7124{
7125#ifdef NL80211_SUPPORT
7126 struct station_info sta_data;
7127#endif /* NL80211_SUPPORT */
7128
7129 if (get_driver_type(dut) != DRIVER_WCN) {
7130 sigma_dut_print(dut, DUT_MSG_ERROR,
7131 "CMAC reply count not supported");
7132 return -1;
7133 }
7134
7135#ifdef NL80211_SUPPORT
7136 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
7137 !(sta_data.filled &
7138 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT))) {
7139 sigma_dut_print(dut, DUT_MSG_ERROR,
7140 "CMAC replay count fetching failed");
7141 return -1;
7142 }
7143
7144 *count = sta_data.beacon_replay_count;
7145 return 0;
7146#else /* NL80211_SUPPORT */
7147 sigma_dut_print(dut, DUT_MSG_ERROR,
7148 "CMAC replay count cannot be fetched without NL80211_SUPPORT defined");
7149 return -1;
7150#endif /* NL80211_SUPPORT */
7151}
7152
7153
7154static enum sigma_cmd_result sta_get_parameter_wpa3(struct sigma_dut *dut,
7155 struct sigma_conn *conn,
7156 struct sigma_cmd *cmd)
7157{
7158 char buf[MAX_CMD_LEN];
7159 const char *ifname = get_param(cmd, "interface");
7160 const char *parameter = get_param(cmd, "Parameter");
7161 unsigned int val;
7162
7163 if (!ifname || !parameter)
7164 return INVALID_SEND_STATUS;
7165
7166 if (strcasecmp(parameter, "BIPMICErrors") == 0) {
7167 if (get_bip_mic_error_count(dut, ifname, &val)) {
7168 send_resp(dut, conn, SIGMA_ERROR,
7169 "ErrorCode,Failed to get BIPMICErrors");
7170 return STATUS_SENT_ERROR;
7171 }
7172 snprintf(buf, sizeof(buf), "BIPMICErrors,%d", val);
7173 sigma_dut_print(dut, DUT_MSG_INFO, "BIPMICErrors %s", buf);
7174 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7175 return STATUS_SENT;
7176 }
7177
7178 if (strcasecmp(parameter, "CMACReplays") == 0) {
7179 if (get_cmac_replay_count(dut, ifname, &val)) {
7180 send_resp(dut, conn, SIGMA_ERROR,
7181 "ErrorCode,Failed to get CMACReplays");
7182 return STATUS_SENT_ERROR;
7183 }
7184 snprintf(buf, sizeof(buf), "CMACReplays,%d", val);
7185 sigma_dut_print(dut, DUT_MSG_INFO, "CMACReplays %s", buf);
7186 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7187 return STATUS_SENT;
7188 }
7189
7190 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7191 return STATUS_SENT_ERROR;
7192}
7193
7194
Jouni Malinenca0abd32020-02-09 20:18:10 +02007195static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
7196 struct sigma_conn *conn,
7197 struct sigma_cmd *cmd)
7198{
7199 const char *intf = get_param(cmd, "Interface");
7200 char buf[4096], bssid[20], resp[200], *pos, *tmp;
7201
7202 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
7203 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
7204 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
7205 send_resp(dut, conn, SIGMA_ERROR,
7206 "ErrorCode,PMKSA_GET not supported");
7207 return STATUS_SENT_ERROR;
7208 }
7209
7210 if (strncmp(buf, "FAIL", 4) == 0 ||
7211 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
7212 send_resp(dut, conn, SIGMA_ERROR,
7213 "ErrorCode,Could not find current network");
7214 return STATUS_SENT_ERROR;
7215 }
7216
7217 pos = buf;
7218 while (pos) {
7219 if (strncmp(pos, bssid, 17) == 0) {
7220 pos = strchr(pos, ' ');
7221 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307222 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007223 pos++;
7224 pos = strchr(pos, ' ');
7225 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307226 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007227 pos++;
7228 tmp = strchr(pos, ' ');
7229 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307230 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007231 *tmp = '\0';
7232 break;
7233 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02007234 pos = strchr(pos, '\n');
7235 if (pos)
7236 pos++;
7237 }
7238
7239 if (!pos) {
7240 send_resp(dut, conn, SIGMA_ERROR,
7241 "ErrorCode,PMK not available");
7242 return STATUS_SENT_ERROR;
7243 }
7244
7245 snprintf(resp, sizeof(resp), "PMK,%s", pos);
7246 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7247 return STATUS_SENT;
7248}
7249
7250
Jouni Malinenf7222712019-06-13 01:50:21 +03007251static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
7252 struct sigma_conn *conn,
7253 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007254{
7255 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02007256 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007257
Jouni Malinenca0abd32020-02-09 20:18:10 +02007258 if (!parameter)
7259 return INVALID_SEND_STATUS;
7260
7261 if (strcasecmp(parameter, "PMK") == 0)
7262 return sta_get_pmk(dut, conn, cmd);
7263
7264 if (!program)
7265 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007266
7267 if (strcasecmp(program, "P2PNFC") == 0)
7268 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
7269
7270 if (strcasecmp(program, "60ghz") == 0)
7271 return sta_get_parameter_60g(dut, conn, cmd);
7272
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007273 if (strcasecmp(program, "he") == 0)
7274 return sta_get_parameter_he(dut, conn, cmd);
7275
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007276#ifdef ANDROID_NAN
7277 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07007278 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007279#endif /* ANDROID_NAN */
7280
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007281#ifdef MIRACAST
7282 if (strcasecmp(program, "WFD") == 0 ||
7283 strcasecmp(program, "DisplayR2") == 0)
7284 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
7285#endif /* MIRACAST */
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05307286 if (strcasecmp(program, "WPA3") == 0)
7287 return sta_get_parameter_wpa3(dut, conn, cmd);
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007288
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007289 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7290 return 0;
7291}
7292
7293
7294static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
7295 const char *type)
7296{
7297 char buf[100];
7298
7299 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007300 run_iwpriv(dut, intf, "chwidth 2");
7301 run_iwpriv(dut, intf, "mode 11ACVHT80");
7302 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007303 }
7304
7305 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007306 run_iwpriv(dut, intf, "chwidth 0");
7307 run_iwpriv(dut, intf, "mode 11naht40");
7308 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007309 }
7310
7311 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007312 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007313
7314 /* Reset CTS width */
7315 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
7316 intf);
7317 if (system(buf) != 0) {
7318 sigma_dut_print(dut, DUT_MSG_ERROR,
7319 "wifitool %s beeliner_fw_test 54 0 failed",
7320 intf);
7321 }
7322
7323 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007324 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007325
7326 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
7327 if (system(buf) != 0) {
7328 sigma_dut_print(dut, DUT_MSG_ERROR,
7329 "iwpriv rts failed");
7330 }
7331 }
7332
7333 if (type && strcasecmp(type, "Testbed") == 0) {
7334 dut->testbed_flag_txsp = 1;
7335 dut->testbed_flag_rxsp = 1;
7336 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007337 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007338
7339 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007340 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007341
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007342 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007343
7344 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007345 run_iwpriv(dut, intf, "tx_stbc 0");
7346 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007347
7348 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007349 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007350 }
7351
7352 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007353 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07007354 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007355
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007356 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007357 }
7358}
7359
7360
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007361#ifdef NL80211_SUPPORT
7362static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
7363 enum he_mcs_config mcs)
7364{
7365 struct nl_msg *msg;
7366 int ret = 0;
7367 struct nlattr *params;
7368 int ifindex;
7369
7370 ifindex = if_nametoindex(intf);
7371 if (ifindex == 0) {
7372 sigma_dut_print(dut, DUT_MSG_ERROR,
7373 "%s: Index for interface %s failed",
7374 __func__, intf);
7375 return -1;
7376 }
7377
7378 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7379 NL80211_CMD_VENDOR)) ||
7380 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7381 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7382 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7383 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7384 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7385 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
7386 mcs)) {
7387 sigma_dut_print(dut, DUT_MSG_ERROR,
7388 "%s: err in adding vendor_cmd and vendor_data",
7389 __func__);
7390 nlmsg_free(msg);
7391 return -1;
7392 }
7393 nla_nest_end(msg, params);
7394
7395 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7396 if (ret) {
7397 sigma_dut_print(dut, DUT_MSG_ERROR,
7398 "%s: err in send_and_recv_msgs, ret=%d",
7399 __func__, ret);
7400 }
7401 return ret;
7402}
7403#endif /* NL80211_SUPPORT */
7404
7405
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007406static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
7407 const char *intf, int enable)
7408{
7409#ifdef NL80211_SUPPORT
7410 struct nl_msg *msg;
7411 int ret = 0;
7412 struct nlattr *params;
7413 int ifindex;
7414
7415 ifindex = if_nametoindex(intf);
7416 if (ifindex == 0) {
7417 sigma_dut_print(dut, DUT_MSG_ERROR,
7418 "%s: Index for interface %s failed",
7419 __func__, intf);
7420 return -1;
7421 }
7422
7423 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7424 NL80211_CMD_VENDOR)) ||
7425 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7426 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7427 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7428 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7429 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7430 nla_put_u8(msg,
7431 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
7432 enable)) {
7433 sigma_dut_print(dut, DUT_MSG_ERROR,
7434 "%s: err in adding vendor_cmd and vendor_data",
7435 __func__);
7436 nlmsg_free(msg);
7437 return -1;
7438 }
7439 nla_nest_end(msg, params);
7440
7441 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7442 if (ret) {
7443 sigma_dut_print(dut, DUT_MSG_ERROR,
7444 "%s: err in send_and_recv_msgs, ret=%d",
7445 __func__, ret);
7446 }
7447 return ret;
7448#else /* NL80211_SUPPORT */
7449 sigma_dut_print(dut, DUT_MSG_ERROR,
7450 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
7451 return -1;
7452#endif /* NL80211_SUPPORT */
7453}
7454
7455
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007456static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
7457 const char *intf, int enable)
7458{
7459#ifdef NL80211_SUPPORT
7460 struct nl_msg *msg;
7461 int ret = 0;
7462 struct nlattr *params;
7463 int ifindex;
7464
7465 ifindex = if_nametoindex(intf);
7466 if (ifindex == 0) {
7467 sigma_dut_print(dut, DUT_MSG_ERROR,
7468 "%s: Index for interface %s failed",
7469 __func__, intf);
7470 return -1;
7471 }
7472
7473 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7474 NL80211_CMD_VENDOR)) ||
7475 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7476 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7477 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7478 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7479 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7480 nla_put_u8(msg,
7481 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7482 enable)) {
7483 sigma_dut_print(dut, DUT_MSG_ERROR,
7484 "%s: err in adding vendor_cmd and vendor_data",
7485 __func__);
7486 nlmsg_free(msg);
7487 return -1;
7488 }
7489 nla_nest_end(msg, params);
7490
7491 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7492 if (ret) {
7493 sigma_dut_print(dut, DUT_MSG_ERROR,
7494 "%s: err in send_and_recv_msgs, ret=%d",
7495 __func__, ret);
7496 }
7497 return ret;
7498#else /* NL80211_SUPPORT */
7499 sigma_dut_print(dut, DUT_MSG_ERROR,
7500 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7501 return -1;
7502#endif /* NL80211_SUPPORT */
7503}
7504
7505
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007506#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007507
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007508static int sta_set_he_testbed_def(struct sigma_dut *dut,
7509 const char *intf, int cfg)
7510{
7511 struct nl_msg *msg;
7512 int ret = 0;
7513 struct nlattr *params;
7514 int ifindex;
7515
7516 ifindex = if_nametoindex(intf);
7517 if (ifindex == 0) {
7518 sigma_dut_print(dut, DUT_MSG_ERROR,
7519 "%s: Index for interface %s failed",
7520 __func__, intf);
7521 return -1;
7522 }
7523
7524 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7525 NL80211_CMD_VENDOR)) ||
7526 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7527 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7528 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7529 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7530 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7531 nla_put_u8(msg,
7532 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7533 cfg)) {
7534 sigma_dut_print(dut, DUT_MSG_ERROR,
7535 "%s: err in adding vendor_cmd and vendor_data",
7536 __func__);
7537 nlmsg_free(msg);
7538 return -1;
7539 }
7540 nla_nest_end(msg, params);
7541
7542 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7543 if (ret) {
7544 sigma_dut_print(dut, DUT_MSG_ERROR,
7545 "%s: err in send_and_recv_msgs, ret=%d",
7546 __func__, ret);
7547 }
7548 return ret;
7549}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007550
7551
7552static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7553{
7554 struct nl_msg *msg;
7555 int ret = 0;
7556 struct nlattr *params;
7557 int ifindex;
7558
7559 ifindex = if_nametoindex(intf);
7560 if (ifindex == 0) {
7561 sigma_dut_print(dut, DUT_MSG_ERROR,
7562 "%s: Index for interface %s failed",
7563 __func__, intf);
7564 return -1;
7565 }
7566
7567 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7568 NL80211_CMD_VENDOR)) ||
7569 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7570 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7571 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7572 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7573 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7574 nla_put_u8(msg,
7575 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7576 cfg)) {
7577 sigma_dut_print(dut, DUT_MSG_ERROR,
7578 "%s: err in adding vendor_cmd and vendor_data",
7579 __func__);
7580 nlmsg_free(msg);
7581 return -1;
7582 }
7583 nla_nest_end(msg, params);
7584
7585 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7586 if (ret) {
7587 sigma_dut_print(dut, DUT_MSG_ERROR,
7588 "%s: err in send_and_recv_msgs, ret=%d",
7589 __func__, ret);
7590 }
7591 return ret;
7592}
7593
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007594#endif /* NL80211_SUPPORT */
7595
7596
Qiwei Caib6806972020-01-15 13:52:11 +08007597int sta_set_addba_buf_size(struct sigma_dut *dut,
7598 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007599{
7600#ifdef NL80211_SUPPORT
7601 struct nl_msg *msg;
7602 int ret = 0;
7603 struct nlattr *params;
7604 int ifindex;
7605
7606 ifindex = if_nametoindex(intf);
7607 if (ifindex == 0) {
7608 sigma_dut_print(dut, DUT_MSG_ERROR,
7609 "%s: Index for interface %s failed",
7610 __func__, intf);
7611 return -1;
7612 }
7613
7614 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7615 NL80211_CMD_VENDOR)) ||
7616 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7617 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7618 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7619 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7620 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07007621 nla_put_u16(msg,
7622 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
7623 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007624 sigma_dut_print(dut, DUT_MSG_ERROR,
7625 "%s: err in adding vendor_cmd and vendor_data",
7626 __func__);
7627 nlmsg_free(msg);
7628 return -1;
7629 }
7630 nla_nest_end(msg, params);
7631
7632 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7633 if (ret) {
7634 sigma_dut_print(dut, DUT_MSG_ERROR,
7635 "%s: err in send_and_recv_msgs, ret=%d",
7636 __func__, ret);
7637 }
7638 return ret;
7639#else /* NL80211_SUPPORT */
7640 sigma_dut_print(dut, DUT_MSG_ERROR,
7641 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7642 return -1;
7643#endif /* NL80211_SUPPORT */
7644}
7645
7646
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007647static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
7648 int enable)
7649{
7650#ifdef NL80211_SUPPORT
7651 struct nl_msg *msg;
7652 int ret = 0;
7653 struct nlattr *params;
7654 int ifindex;
7655
7656 ifindex = if_nametoindex(intf);
7657 if (ifindex == 0) {
7658 sigma_dut_print(dut, DUT_MSG_ERROR,
7659 "%s: Index for interface %s failed",
7660 __func__, intf);
7661 return -1;
7662 }
7663
7664 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7665 NL80211_CMD_VENDOR)) ||
7666 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7667 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7668 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7669 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7670 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7671 nla_put_u8(msg,
7672 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7673 enable)) {
7674 sigma_dut_print(dut, DUT_MSG_ERROR,
7675 "%s: err in adding vendor_cmd and vendor_data",
7676 __func__);
7677 nlmsg_free(msg);
7678 return -1;
7679 }
7680 nla_nest_end(msg, params);
7681
7682 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7683 if (ret) {
7684 sigma_dut_print(dut, DUT_MSG_ERROR,
7685 "%s: err in send_and_recv_msgs, ret=%d",
7686 __func__, ret);
7687 }
7688 return ret;
7689#else /* NL80211_SUPPORT */
7690 sigma_dut_print(dut, DUT_MSG_ERROR,
7691 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7692 return -1;
7693#endif /* NL80211_SUPPORT */
7694}
7695
7696
Arif Hussain9765f7d2018-07-03 08:28:26 -07007697static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7698 int val)
7699{
7700#ifdef NL80211_SUPPORT
7701 struct nl_msg *msg;
7702 int ret = 0;
7703 struct nlattr *params;
7704 int ifindex;
7705
7706 ifindex = if_nametoindex(intf);
7707 if (ifindex == 0) {
7708 sigma_dut_print(dut, DUT_MSG_ERROR,
7709 "%s: Index for interface %s failed, val:%d",
7710 __func__, intf, val);
7711 return -1;
7712 }
7713
7714 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7715 NL80211_CMD_VENDOR)) ||
7716 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7717 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7718 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7719 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7720 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7721 nla_put_u8(msg,
7722 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7723 val)) {
7724 sigma_dut_print(dut, DUT_MSG_ERROR,
7725 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7726 __func__, val);
7727 nlmsg_free(msg);
7728 return -1;
7729 }
7730 nla_nest_end(msg, params);
7731
7732 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7733 if (ret) {
7734 sigma_dut_print(dut, DUT_MSG_ERROR,
7735 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7736 __func__, ret, val);
7737 }
7738 return ret;
7739#else /* NL80211_SUPPORT */
7740 sigma_dut_print(dut, DUT_MSG_ERROR,
7741 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7742 return -1;
7743#endif /* NL80211_SUPPORT */
7744}
7745
7746
Arif Hussain68d23f52018-07-11 13:39:08 -07007747#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007748static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7749 enum qca_wlan_he_mac_padding_dur val)
7750{
Arif Hussain68d23f52018-07-11 13:39:08 -07007751 struct nl_msg *msg;
7752 int ret = 0;
7753 struct nlattr *params;
7754 int ifindex;
7755
7756 ifindex = if_nametoindex(intf);
7757 if (ifindex == 0) {
7758 sigma_dut_print(dut, DUT_MSG_ERROR,
7759 "%s: Index for interface %s failed, val:%d",
7760 __func__, intf, val);
7761 return -1;
7762 }
7763
7764 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7765 NL80211_CMD_VENDOR)) ||
7766 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7767 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7768 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7769 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7770 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7771 nla_put_u8(msg,
7772 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
7773 val)) {
7774 sigma_dut_print(dut, DUT_MSG_ERROR,
7775 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7776 __func__, val);
7777 nlmsg_free(msg);
7778 return -1;
7779 }
7780 nla_nest_end(msg, params);
7781
7782 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7783 if (ret) {
7784 sigma_dut_print(dut, DUT_MSG_ERROR,
7785 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7786 __func__, ret, val);
7787 }
7788 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07007789}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007790#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007791
7792
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007793static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7794 int val)
7795{
7796#ifdef NL80211_SUPPORT
7797 struct nl_msg *msg;
7798 int ret = 0;
7799 struct nlattr *params;
7800 int ifindex;
7801
7802 ifindex = if_nametoindex(intf);
7803 if (ifindex == 0) {
7804 sigma_dut_print(dut, DUT_MSG_ERROR,
7805 "%s: Index for interface %s failed, val:%d",
7806 __func__, intf, val);
7807 return -1;
7808 }
7809
7810 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7811 NL80211_CMD_VENDOR)) ||
7812 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7813 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7814 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7815 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7816 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7817 nla_put_u8(msg,
7818 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7819 val)) {
7820 sigma_dut_print(dut, DUT_MSG_ERROR,
7821 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7822 __func__, val);
7823 nlmsg_free(msg);
7824 return -1;
7825 }
7826 nla_nest_end(msg, params);
7827
7828 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7829 if (ret) {
7830 sigma_dut_print(dut, DUT_MSG_ERROR,
7831 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7832 __func__, ret, val);
7833 }
7834 return ret;
7835#else /* NL80211_SUPPORT */
7836 sigma_dut_print(dut, DUT_MSG_ERROR,
7837 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7838 return -1;
7839#endif /* NL80211_SUPPORT */
7840}
7841
7842
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007843#ifdef NL80211_SUPPORT
7844static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7845{
7846 struct nl_msg *msg;
7847 int ret = 0;
7848 struct nlattr *params;
7849 int ifindex;
7850
7851 ifindex = if_nametoindex(intf);
7852 if (ifindex == 0) {
7853 sigma_dut_print(dut, DUT_MSG_ERROR,
7854 "%s: Index for interface %s failed",
7855 __func__, intf);
7856 return -1;
7857 }
7858
7859 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7860 NL80211_CMD_VENDOR)) ||
7861 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7862 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7863 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7864 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7865 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7866 nla_put_flag(msg,
7867 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
7868 sigma_dut_print(dut, DUT_MSG_ERROR,
7869 "%s: err in adding vendor_cmd and vendor_data",
7870 __func__);
7871 nlmsg_free(msg);
7872 return -1;
7873 }
7874 nla_nest_end(msg, params);
7875
7876 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7877 if (ret) {
7878 sigma_dut_print(dut, DUT_MSG_ERROR,
7879 "%s: err in send_and_recv_msgs, ret=%d",
7880 __func__, ret);
7881 }
7882 return ret;
7883}
7884#endif /* NL80211_SUPPORT */
7885
7886
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007887static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7888 int val)
7889{
7890#ifdef NL80211_SUPPORT
7891 struct nl_msg *msg;
7892 int ret = 0;
7893 struct nlattr *params;
7894 int ifindex;
7895
7896 ifindex = if_nametoindex(intf);
7897 if (ifindex == 0) {
7898 sigma_dut_print(dut, DUT_MSG_ERROR,
7899 "%s: Index for interface %s failed, val:%d",
7900 __func__, intf, val);
7901 return -1;
7902 }
7903
7904 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7905 NL80211_CMD_VENDOR)) ||
7906 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7907 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7908 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7909 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7910 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7911 nla_put_u8(msg,
7912 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
7913 val)) {
7914 sigma_dut_print(dut, DUT_MSG_ERROR,
7915 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7916 __func__, val);
7917 nlmsg_free(msg);
7918 return -1;
7919 }
7920 nla_nest_end(msg, params);
7921
7922 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7923 if (ret) {
7924 sigma_dut_print(dut, DUT_MSG_ERROR,
7925 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7926 __func__, ret, val);
7927 }
7928 return ret;
7929#else /* NL80211_SUPPORT */
7930 sigma_dut_print(dut, DUT_MSG_ERROR,
7931 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7932 return -1;
7933#endif /* NL80211_SUPPORT */
7934}
7935
7936
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007937static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7938 int val)
7939{
7940#ifdef NL80211_SUPPORT
7941 struct nl_msg *msg;
7942 int ret = 0;
7943 struct nlattr *params;
7944 int ifindex;
7945
7946 ifindex = if_nametoindex(intf);
7947 if (ifindex == 0) {
7948 sigma_dut_print(dut, DUT_MSG_ERROR,
7949 "%s: Index for interface %s failed, val:%d",
7950 __func__, intf, val);
7951 return -1;
7952 }
7953
7954 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7955 NL80211_CMD_VENDOR)) ||
7956 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7957 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7958 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7959 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7960 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7961 nla_put_u8(msg,
7962 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
7963 val)) {
7964 sigma_dut_print(dut, DUT_MSG_ERROR,
7965 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7966 __func__, val);
7967 nlmsg_free(msg);
7968 return -1;
7969 }
7970 nla_nest_end(msg, params);
7971
7972 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7973 if (ret) {
7974 sigma_dut_print(dut, DUT_MSG_ERROR,
7975 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7976 __func__, ret, val);
7977 }
7978 return ret;
7979#else /* NL80211_SUPPORT */
7980 sigma_dut_print(dut, DUT_MSG_ERROR,
7981 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7982 return -1;
7983#endif /* NL80211_SUPPORT */
7984}
7985
7986
Arif Hussain480d5f42019-03-12 14:40:42 -07007987static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7988 int val)
7989{
7990#ifdef NL80211_SUPPORT
7991 struct nl_msg *msg;
7992 int ret;
7993 struct nlattr *params;
7994 int ifindex;
7995
7996 ifindex = if_nametoindex(intf);
7997 if (ifindex == 0) {
7998 sigma_dut_print(dut, DUT_MSG_ERROR,
7999 "%s: Index for interface %s failed, val:%d",
8000 __func__, intf, val);
8001 return -1;
8002 }
8003
8004 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8005 NL80211_CMD_VENDOR)) ||
8006 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8007 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8008 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8009 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8010 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8011 nla_put_u8(msg,
8012 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT,
8013 val)) {
8014 sigma_dut_print(dut, DUT_MSG_ERROR,
8015 "%s: err in adding vendor_cmd and vendor_data, val: %d",
8016 __func__, val);
8017 nlmsg_free(msg);
8018 return -1;
8019 }
8020 nla_nest_end(msg, params);
8021
8022 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8023 if (ret) {
8024 sigma_dut_print(dut, DUT_MSG_ERROR,
8025 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
8026 __func__, ret, val);
8027 }
8028 return ret;
8029#else /* NL80211_SUPPORT */
8030 sigma_dut_print(dut, DUT_MSG_ERROR,
8031 "TWT Request cannot be changed without NL80211_SUPPORT defined");
8032 return -1;
8033#endif /* NL80211_SUPPORT */
8034}
8035
8036
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008037static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
8038 const char *type)
8039{
8040 char buf[60];
8041
8042 if (dut->program == PROGRAM_HE) {
8043 /* resetting phymode to auto in case of HE program */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05308044 sta_set_phymode(dut, intf, "auto");
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008045
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07008046 /* reset the rate to Auto rate */
8047 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
8048 intf);
8049 if (system(buf) != 0) {
8050 sigma_dut_print(dut, DUT_MSG_ERROR,
8051 "iwpriv %s set_11ax_rate 0xff failed",
8052 intf);
8053 }
8054
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07008055 /* reset the LDPC setting */
8056 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
8057 if (system(buf) != 0) {
8058 sigma_dut_print(dut, DUT_MSG_ERROR,
8059 "iwpriv %s ldpc 1 failed", intf);
8060 }
8061
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08008062 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05308063 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08008064
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008065 /* remove all network profiles */
8066 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008067
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08008068 /* Configure ADDBA Req/Rsp buffer size to be 64 */
8069 sta_set_addba_buf_size(dut, intf, 64);
8070
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08008071#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008072 /* Reset the device HE capabilities to its default supported
8073 * configuration. */
8074 sta_set_he_testbed_def(dut, intf, 0);
8075
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08008076 /* Disable noackpolicy for all AC */
8077 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
8078 sigma_dut_print(dut, DUT_MSG_ERROR,
8079 "Disable of noackpolicy for all AC failed");
8080 }
8081#endif /* NL80211_SUPPORT */
8082
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08008083 /* Enable WMM by default */
8084 if (wcn_sta_set_wmm(dut, intf, "on")) {
8085 sigma_dut_print(dut, DUT_MSG_ERROR,
8086 "Enable of WMM in sta_reset_default_wcn failed");
8087 }
8088
8089 /* Disable ADDBA_REJECT by default */
8090 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
8091 sigma_dut_print(dut, DUT_MSG_ERROR,
8092 "Disable of addba_reject in sta_reset_default_wcn failed");
8093 }
8094
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08008095 /* Enable sending of ADDBA by default */
8096 if (nlvendor_config_send_addba(dut, intf, 1)) {
8097 sigma_dut_print(dut, DUT_MSG_ERROR,
8098 "Enable sending of ADDBA in sta_reset_default_wcn failed");
8099 }
8100
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08008101 /* Enable AMPDU by default */
8102 iwpriv_sta_set_ampdu(dut, intf, 1);
8103
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008104#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08008105 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008106 sigma_dut_print(dut, DUT_MSG_ERROR,
8107 "Set LTF config to default in sta_reset_default_wcn failed");
8108 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07008109
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08008110 /* set the beamformee NSTS(maximum number of
8111 * space-time streams) to default DUT config
8112 */
8113 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07008114 sigma_dut_print(dut, DUT_MSG_ERROR,
8115 "Failed to set BeamformeeSTS");
8116 }
Arif Hussain68d23f52018-07-11 13:39:08 -07008117
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008118 if (sta_set_mac_padding_duration(
8119 dut, intf,
8120 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008121 sigma_dut_print(dut, DUT_MSG_ERROR,
8122 "Failed to set MAC padding duration");
8123 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008124
8125 if (sta_set_mu_edca_override(dut, intf, 0)) {
8126 sigma_dut_print(dut, DUT_MSG_ERROR,
8127 "ErrorCode,Failed to set MU EDCA override disable");
8128 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008129
8130 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
8131 sigma_dut_print(dut, DUT_MSG_ERROR,
8132 "Failed to set OM ctrl supp");
8133 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07008134
8135 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
8136 sigma_dut_print(dut, DUT_MSG_ERROR,
8137 "Failed to set Tx SU PPDU enable");
8138 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008139
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07008140 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
8141 sigma_dut_print(dut, DUT_MSG_ERROR,
8142 "failed to send TB PPDU Tx cfg");
8143 }
8144
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008145 if (sta_set_he_om_ctrl_reset(dut, intf)) {
8146 sigma_dut_print(dut, DUT_MSG_ERROR,
8147 "Failed to set OM ctrl reset");
8148 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08008149
8150 /* +HTC-HE support default on */
8151 if (sta_set_he_htc_supp(dut, intf, 1)) {
8152 sigma_dut_print(dut, DUT_MSG_ERROR,
8153 "Setting of +HTC-HE support failed");
8154 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008155#endif /* NL80211_SUPPORT */
8156
Arif Hussain8d5b27b2018-05-14 14:31:03 -07008157 if (sta_set_tx_beamformee(dut, intf, 1)) {
8158 sigma_dut_print(dut, DUT_MSG_ERROR,
8159 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
8160 }
8161
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07008162 wpa_command(intf, "SET oce 1");
8163
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008164 /* Set nss to 1 and MCS 0-7 in case of testbed */
8165 if (type && strcasecmp(type, "Testbed") == 0) {
8166#ifdef NL80211_SUPPORT
8167 int ret;
8168#endif /* NL80211_SUPPORT */
8169
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07008170 wpa_command(intf, "SET oce 0");
8171
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008172 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
8173 if (system(buf) != 0) {
8174 sigma_dut_print(dut, DUT_MSG_ERROR,
8175 "iwpriv %s nss failed", intf);
8176 }
8177
8178#ifdef NL80211_SUPPORT
8179 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
8180 if (ret) {
8181 sigma_dut_print(dut, DUT_MSG_ERROR,
8182 "Setting of MCS failed, ret:%d",
8183 ret);
8184 }
8185#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08008186
8187 /* Disable STBC as default */
8188 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08008189
8190 /* Disable AMSDU as default */
8191 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08008192
8193#ifdef NL80211_SUPPORT
8194 /* HE fragmentation default off */
8195 if (sta_set_he_fragmentation(dut, intf,
8196 HE_FRAG_DISABLE)) {
8197 sigma_dut_print(dut, DUT_MSG_ERROR,
8198 "Setting of HE fragmentation failed");
8199 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08008200
8201 /* set the beamformee NSTS(maximum number of
8202 * space-time streams) to default testbed config
8203 */
8204 if (sta_set_beamformee_sts(dut, intf, 3)) {
8205 sigma_dut_print(dut, DUT_MSG_ERROR,
8206 "Failed to set BeamformeeSTS");
8207 }
8208
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08008209 /* +HTC-HE support default off */
8210 if (sta_set_he_htc_supp(dut, intf, 0)) {
8211 sigma_dut_print(dut, DUT_MSG_ERROR,
8212 "Setting of +HTC-HE support failed");
8213 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008214
8215 /* Set device HE capabilities to testbed default
8216 * configuration. */
8217 if (sta_set_he_testbed_def(dut, intf, 1)) {
8218 sigma_dut_print(dut, DUT_MSG_DEBUG,
8219 "Failed to set HE defaults");
8220 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08008221
8222 /* Disable VHT support in 2.4 GHz for testbed */
8223 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08008224#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08008225
8226 /* Enable WEP/TKIP with HE capability in testbed */
8227 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
8228 sigma_dut_print(dut, DUT_MSG_ERROR,
8229 "Enabling HE config with WEP/TKIP failed");
8230 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008231 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008232
8233 /* Defaults in case of DUT */
8234 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07008235 /* Enable STBC by default */
8236 wcn_sta_set_stbc(dut, intf, "1");
8237
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008238 /* set nss to 2 */
8239 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
8240 if (system(buf) != 0) {
8241 sigma_dut_print(dut, DUT_MSG_ERROR,
8242 "iwpriv %s nss 2 failed", intf);
8243 }
Arif Hussainac6c5112018-05-25 17:34:00 -07008244 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008245
8246#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07008247 /* Set HE_MCS to 0-11 */
8248 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008249 sigma_dut_print(dut, DUT_MSG_ERROR,
8250 "Setting of MCS failed");
8251 }
8252#endif /* NL80211_SUPPORT */
8253
8254 /* Disable WEP/TKIP with HE capability in DUT */
8255 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
8256 sigma_dut_print(dut, DUT_MSG_ERROR,
8257 "Enabling HE config with WEP/TKIP failed");
8258 }
8259 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008260 }
8261}
8262
8263
Jouni Malinenf7222712019-06-13 01:50:21 +03008264static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
8265 struct sigma_conn *conn,
8266 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008267{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008268 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008269 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008270 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008271 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308272 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008273
Jouni Malinenb21f0542019-11-04 17:53:38 +02008274 if (dut->station_ifname_2g &&
8275 strcmp(dut->station_ifname_2g, intf) == 0)
8276 dut->use_5g = 0;
8277 else if (dut->station_ifname_5g &&
8278 strcmp(dut->station_ifname_5g, intf) == 0)
8279 dut->use_5g = 1;
8280
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008281 if (!program)
8282 program = get_param(cmd, "prog");
8283 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008284 dut->device_type = STA_unknown;
8285 type = get_param(cmd, "type");
8286 if (type && strcasecmp(type, "Testbed") == 0)
8287 dut->device_type = STA_testbed;
8288 if (type && strcasecmp(type, "DUT") == 0)
8289 dut->device_type = STA_dut;
8290
8291 if (dut->program == PROGRAM_TDLS) {
8292 /* Clear TDLS testing mode */
8293 wpa_command(intf, "SET tdls_disabled 0");
8294 wpa_command(intf, "SET tdls_testing 0");
8295 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008296 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05308297 /* Enable the WCN driver in TDLS Explicit trigger mode
8298 */
8299 wpa_command(intf, "SET tdls_external_control 0");
8300 wpa_command(intf, "SET tdls_trigger_control 0");
8301 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008302 }
8303
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008304#ifdef MIRACAST
8305 if (dut->program == PROGRAM_WFD ||
8306 dut->program == PROGRAM_DISPLAYR2)
8307 miracast_sta_reset_default(dut, conn, cmd);
8308#endif /* MIRACAST */
8309
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008310 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008311 case DRIVER_ATHEROS:
8312 sta_reset_default_ath(dut, intf, type);
8313 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008314 case DRIVER_WCN:
8315 sta_reset_default_wcn(dut, intf, type);
8316 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008317 default:
8318 break;
8319 }
8320
8321#ifdef ANDROID_NAN
8322 if (dut->program == PROGRAM_NAN)
8323 nan_cmd_sta_reset_default(dut, conn, cmd);
8324#endif /* ANDROID_NAN */
8325
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05308326 if (dut->program == PROGRAM_LOC &&
8327 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
8328 return ERROR_SEND_STATUS;
8329
Jouni Malinenba630452018-06-22 11:49:59 +03008330 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008331 unlink("SP/wi-fi.org/pps.xml");
8332 if (system("rm -r SP/*") != 0) {
8333 }
8334 unlink("next-client-cert.pem");
8335 unlink("next-client-key.pem");
8336 }
8337
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008338 /* For WPS program of the 60 GHz band the band type needs to be saved */
8339 if (dut->program == PROGRAM_WPS) {
8340 if (band && strcasecmp(band, "60GHz") == 0) {
8341 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008342 /* For 60 GHz enable WPS for WPS TCs */
8343 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008344 } else {
8345 dut->band = WPS_BAND_NON_60G;
8346 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008347 } else if (dut->program == PROGRAM_60GHZ) {
8348 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
8349 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008350 }
8351
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02008352 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008353 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008354 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008355
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008356 sigma_dut_print(dut, DUT_MSG_INFO,
8357 "WPS 60 GHz program, wps_disable = %d",
8358 dut->wps_disable);
8359
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008360 if (!dev_role) {
8361 send_resp(dut, conn, SIGMA_ERROR,
8362 "errorCode,Missing DevRole argument");
8363 return 0;
8364 }
8365
8366 if (strcasecmp(dev_role, "STA") == 0)
8367 dut->dev_role = DEVROLE_STA;
8368 else if (strcasecmp(dev_role, "PCP") == 0)
8369 dut->dev_role = DEVROLE_PCP;
8370 else {
8371 send_resp(dut, conn, SIGMA_ERROR,
8372 "errorCode,Unknown DevRole");
8373 return 0;
8374 }
8375
8376 if (dut->device_type == STA_unknown) {
8377 sigma_dut_print(dut, DUT_MSG_ERROR,
8378 "Device type is not STA testbed or DUT");
8379 send_resp(dut, conn, SIGMA_ERROR,
8380 "errorCode,Unknown device type");
8381 return 0;
8382 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008383
8384 sigma_dut_print(dut, DUT_MSG_DEBUG,
8385 "Setting msdu_size to MAX: 7912");
8386 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008387 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008388
8389 if (system(buf) != 0) {
8390 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
8391 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008392 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008393 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008394
8395 if (sta_set_force_mcs(dut, 0, 1)) {
8396 sigma_dut_print(dut, DUT_MSG_ERROR,
8397 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008398 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008399 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008400 }
8401
8402 wpa_command(intf, "WPS_ER_STOP");
8403 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05308404 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008405 wpa_command(intf, "SET radio_disabled 0");
8406
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02008407 dut->wps_forced_version = 0;
8408
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008409 if (dut->wsc_fragment) {
8410 dut->wsc_fragment = 0;
8411 wpa_command(intf, "SET device_name Test client");
8412 wpa_command(intf, "SET manufacturer ");
8413 wpa_command(intf, "SET model_name ");
8414 wpa_command(intf, "SET model_number ");
8415 wpa_command(intf, "SET serial_number ");
8416 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02008417 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
8418 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
8419 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
8420 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008421
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008422 if (dut->tmp_mac_addr && dut->set_macaddr) {
8423 dut->tmp_mac_addr = 0;
8424 if (system(dut->set_macaddr) != 0) {
8425 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
8426 "temporary MAC address");
8427 }
8428 }
8429
8430 set_ps(intf, dut, 0);
8431
Jouni Malinenba630452018-06-22 11:49:59 +03008432 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
8433 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008434 wpa_command(intf, "SET interworking 1");
8435 wpa_command(intf, "SET hs20 1");
8436 }
8437
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008438 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03008439 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008440 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008441 wpa_command(intf, "SET pmf 1");
8442 } else {
8443 wpa_command(intf, "SET pmf 0");
8444 }
8445
8446 hs2_clear_credentials(intf);
8447 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
8448 wpa_command(intf, "SET access_network_type 15");
8449
8450 static_ip_file(0, NULL, NULL, NULL);
8451 kill_dhcp_client(dut, intf);
8452 clear_ip_addr(dut, intf);
8453
8454 dut->er_oper_performed = 0;
8455 dut->er_oper_bssid[0] = '\0';
8456
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008457 if (dut->program == PROGRAM_LOC) {
8458 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008459 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008460 }
8461
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07008462 if (dut->program == PROGRAM_MBO || dut->program == PROGRAM_HE) {
Ashwini Patil00402582017-04-13 12:29:39 +05308463 free(dut->non_pref_ch_list);
8464 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05308465 free(dut->btm_query_cand_list);
8466 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05308467 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05308468 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05308469 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05308470 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05308471 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05308472 }
8473
Jouni Malinen3c367e82017-06-23 17:01:47 +03008474 free(dut->rsne_override);
8475 dut->rsne_override = NULL;
8476
Jouni Malinen68143132017-09-02 02:34:08 +03008477 free(dut->sae_commit_override);
8478 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03008479 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02008480 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03008481
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008482 dut->sta_associate_wait_connect = 0;
8483 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03008484 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008485 dut->sta_tod_policy = 0;
8486
Jouni Malinend86e5822017-08-29 03:55:32 +03008487 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02008488 free(dut->dpp_peer_uri);
8489 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02008490 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02008491 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03008492 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03008493
Jouni Malinenfac9cad2017-10-10 18:35:55 +03008494 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
8495
vamsi krishnaa2799492017-12-05 14:28:01 +05308496 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308497 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05308498 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05308499 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
8500 dut->fils_hlp = 0;
8501#ifdef ANDROID
8502 hlp_thread_cleanup(dut);
8503#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05308504 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308505
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308506 if (dut->program == PROGRAM_QM)
8507 wpa_command(intf, "SET interworking 1");
8508
Jouni Malinen8179fee2019-03-28 03:19:47 +02008509 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03008510 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02008511
Sunil Dutt076081f2018-02-05 19:45:50 +05308512#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008513 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05308514 dut->config_rsnie == 1) {
8515 dut->config_rsnie = 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308516 sta_config_params(dut, intf, STA_SET_RSNIE, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05308517 }
8518#endif /* NL80211_SUPPORT */
8519
Sunil Duttfebf8a82018-02-09 18:50:13 +05308520 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
8521 dut->dev_role = DEVROLE_STA_CFON;
8522 return sta_cfon_reset_default(dut, conn, cmd);
8523 }
8524
Jouni Malinen439352d2018-09-13 03:42:23 +03008525 wpa_command(intf, "SET setband AUTO");
8526
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308527 dut->ocvc = 0;
Jouni Malinen67433fc2020-06-26 22:50:33 +03008528 dut->client_privacy = 0;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05308529 dut->saquery_oci_freq = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308530
Sunil Duttfebf8a82018-02-09 18:50:13 +05308531 if (dut->program != PROGRAM_VHT)
8532 return cmd_sta_p2p_reset(dut, conn, cmd);
8533
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08008534 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008535}
8536
8537
Jouni Malinenf7222712019-06-13 01:50:21 +03008538static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
8539 struct sigma_conn *conn,
8540 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008541{
8542 const char *program = get_param(cmd, "Program");
8543
8544 if (program == NULL)
8545 return -1;
8546#ifdef ANDROID_NAN
8547 if (strcasecmp(program, "NAN") == 0)
8548 return nan_cmd_sta_get_events(dut, conn, cmd);
8549#endif /* ANDROID_NAN */
8550 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8551 return 0;
8552}
8553
8554
Jouni Malinen82905202018-04-29 17:20:10 +03008555static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
8556 struct sigma_cmd *cmd)
8557{
8558 const char *url = get_param(cmd, "url");
8559 const char *method = get_param(cmd, "method");
8560 pid_t pid;
8561 int status;
8562
8563 if (!url || !method)
8564 return -1;
8565
8566 /* TODO: Add support for method,post */
8567 if (strcasecmp(method, "get") != 0) {
8568 send_resp(dut, conn, SIGMA_ERROR,
8569 "ErrorCode,Unsupported method");
8570 return 0;
8571 }
8572
8573 pid = fork();
8574 if (pid < 0) {
8575 perror("fork");
8576 return -1;
8577 }
8578
8579 if (pid == 0) {
8580 char * argv[5] = { "wget", "-O", "/dev/null",
8581 (char *) url, NULL };
8582
8583 execv("/usr/bin/wget", argv);
8584 perror("execv");
8585 exit(0);
8586 return -1;
8587 }
8588
8589 if (waitpid(pid, &status, 0) < 0) {
8590 perror("waitpid");
8591 return -1;
8592 }
8593
8594 if (WIFEXITED(status)) {
8595 const char *errmsg;
8596
8597 if (WEXITSTATUS(status) == 0)
8598 return 1;
8599 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
8600 WEXITSTATUS(status));
8601 switch (WEXITSTATUS(status)) {
8602 case 4:
8603 errmsg = "errmsg,Network failure";
8604 break;
8605 case 8:
8606 errmsg = "errmsg,Server issued an error response";
8607 break;
8608 default:
8609 errmsg = "errmsg,Unknown failure from wget";
8610 break;
8611 }
8612 send_resp(dut, conn, SIGMA_ERROR, errmsg);
8613 return 0;
8614 }
8615
8616 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
8617 return 0;
8618}
8619
8620
Jouni Malinenf7222712019-06-13 01:50:21 +03008621static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
8622 struct sigma_conn *conn,
8623 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008624{
8625 const char *program = get_param(cmd, "Prog");
8626
Jouni Malinen82905202018-04-29 17:20:10 +03008627 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008628 return -1;
8629#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03008630 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008631 return nan_cmd_sta_exec_action(dut, conn, cmd);
8632#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03008633
8634 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07008635 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03008636
8637 if (get_param(cmd, "url"))
8638 return sta_exec_action_url(dut, conn, cmd);
8639
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008640 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8641 return 0;
8642}
8643
8644
Jouni Malinenf7222712019-06-13 01:50:21 +03008645static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
8646 struct sigma_conn *conn,
8647 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008648{
8649 const char *intf = get_param(cmd, "Interface");
8650 const char *val, *mcs32, *rate;
8651
8652 val = get_param(cmd, "GREENFIELD");
8653 if (val) {
8654 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
8655 /* Enable GD */
8656 send_resp(dut, conn, SIGMA_ERROR,
8657 "ErrorCode,GF not supported");
8658 return 0;
8659 }
8660 }
8661
8662 val = get_param(cmd, "SGI20");
8663 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008664 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008665 case DRIVER_ATHEROS:
8666 ath_sta_set_sgi(dut, intf, val);
8667 break;
8668 default:
8669 send_resp(dut, conn, SIGMA_ERROR,
8670 "ErrorCode,SGI20 not supported");
8671 return 0;
8672 }
8673 }
8674
8675 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
8676 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
8677 if (mcs32 && rate) {
8678 /* TODO */
8679 send_resp(dut, conn, SIGMA_ERROR,
8680 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
8681 return 0;
8682 } else if (mcs32 && !rate) {
8683 /* TODO */
8684 send_resp(dut, conn, SIGMA_ERROR,
8685 "ErrorCode,MCS32 not supported");
8686 return 0;
8687 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008688 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008689 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008690 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008691 ath_sta_set_11nrates(dut, intf, rate);
8692 break;
8693 default:
8694 send_resp(dut, conn, SIGMA_ERROR,
8695 "ErrorCode,MCS32_FIXEDRATE not supported");
8696 return 0;
8697 }
8698 }
8699
8700 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8701}
8702
8703
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008704static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8705 int mcs_config)
8706{
8707#ifdef NL80211_SUPPORT
8708 int ret;
8709
8710 switch (mcs_config) {
8711 case HE_80_MCS0_7:
8712 case HE_80_MCS0_9:
8713 case HE_80_MCS0_11:
8714 ret = sta_set_he_mcs(dut, intf, mcs_config);
8715 if (ret) {
8716 sigma_dut_print(dut, DUT_MSG_ERROR,
8717 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8718 mcs_config, ret);
8719 }
8720 break;
8721 default:
8722 sigma_dut_print(dut, DUT_MSG_ERROR,
8723 "cmd_set_max_he_mcs: Invalid mcs %d",
8724 mcs_config);
8725 break;
8726 }
8727#else /* NL80211_SUPPORT */
8728 sigma_dut_print(dut, DUT_MSG_ERROR,
8729 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8730#endif /* NL80211_SUPPORT */
8731}
8732
8733
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008734#define TWT_REQUEST_CMD 0
8735#define TWT_SUGGEST_CMD 1
8736#define TWT_DEMAND_CMD 2
8737
Arif Hussain480d5f42019-03-12 14:40:42 -07008738static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8739 struct sigma_cmd *cmd)
8740{
8741#ifdef NL80211_SUPPORT
8742 struct nlattr *params;
8743 struct nlattr *attr;
8744 struct nlattr *attr1;
8745 struct nl_msg *msg;
8746 int ifindex, ret;
8747 const char *val;
8748 const char *intf = get_param(cmd, "Interface");
8749 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8750 wake_interval_mantissa = 512;
8751 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008752 protection = 0, cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
Arif Hussain480d5f42019-03-12 14:40:42 -07008753
8754 ifindex = if_nametoindex(intf);
8755 if (ifindex == 0) {
8756 sigma_dut_print(dut, DUT_MSG_ERROR,
8757 "%s: Index for interface %s failed",
8758 __func__, intf);
8759 return -1;
8760 }
8761
8762 val = get_param(cmd, "FlowType");
8763 if (val) {
8764 flow_type = atoi(val);
8765 if (flow_type != 0 && flow_type != 1) {
8766 sigma_dut_print(dut, DUT_MSG_ERROR,
8767 "TWT: Invalid FlowType %d", flow_type);
8768 return -1;
8769 }
8770 }
8771
8772 val = get_param(cmd, "TWT_Trigger");
8773 if (val) {
8774 twt_trigger = atoi(val);
8775 if (twt_trigger != 0 && twt_trigger != 1) {
8776 sigma_dut_print(dut, DUT_MSG_ERROR,
8777 "TWT: Invalid TWT_Trigger %d",
8778 twt_trigger);
8779 return -1;
8780 }
8781 }
8782
8783 val = get_param(cmd, "Protection");
8784 if (val) {
8785 protection = atoi(val);
8786 if (protection != 0 && protection != 1) {
8787 sigma_dut_print(dut, DUT_MSG_ERROR,
8788 "TWT: Invalid Protection %d",
8789 protection);
8790 return -1;
8791 }
8792 }
8793
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008794 val = get_param(cmd, "SetupCommand");
8795 if (val) {
8796 cmd_type = atoi(val);
8797 if (cmd_type == TWT_REQUEST_CMD)
8798 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_REQUEST;
8799 else if (cmd_type == TWT_SUGGEST_CMD)
8800 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
8801 else if (cmd_type == TWT_DEMAND_CMD)
8802 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_DEMAND;
8803 else
8804 sigma_dut_print(dut, DUT_MSG_ERROR,
8805 "Default suggest is used for cmd %d",
8806 cmd_type);
8807 }
8808
Arif Hussain480d5f42019-03-12 14:40:42 -07008809 val = get_param(cmd, "TargetWakeTime");
8810 if (val)
8811 target_wake_time = atoi(val);
8812
8813 val = get_param(cmd, "WakeIntervalMantissa");
8814 if (val)
8815 wake_interval_mantissa = atoi(val);
8816
8817 val = get_param(cmd, "WakeIntervalExp");
8818 if (val)
8819 wake_interval_exp = atoi(val);
8820
8821 val = get_param(cmd, "NominalMinWakeDur");
8822 if (val)
8823 nominal_min_wake_dur = atoi(val);
8824
8825 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8826 NL80211_CMD_VENDOR)) ||
8827 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8828 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8829 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8830 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8831 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8832 !(params = nla_nest_start(
8833 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
8834 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8835 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8836 wake_interval_exp) ||
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008837 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, cmd_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008838 (twt_trigger &&
8839 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008840 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8841 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008842 (protection &&
8843 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008844 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8845 target_wake_time) ||
8846 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8847 nominal_min_wake_dur) ||
8848 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8849 wake_interval_mantissa)) {
8850 sigma_dut_print(dut, DUT_MSG_ERROR,
8851 "%s: err in adding vendor_cmd and vendor_data",
8852 __func__);
8853 nlmsg_free(msg);
8854 return -1;
8855 }
8856 nla_nest_end(msg, attr1);
8857 nla_nest_end(msg, params);
8858 nla_nest_end(msg, attr);
8859
8860 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8861 if (ret) {
8862 sigma_dut_print(dut, DUT_MSG_ERROR,
8863 "%s: err in send_and_recv_msgs, ret=%d",
8864 __func__, ret);
8865 }
8866
8867 return ret;
8868#else /* NL80211_SUPPORT */
8869 sigma_dut_print(dut, DUT_MSG_ERROR,
8870 "TWT request cannot be done without NL80211_SUPPORT defined");
8871 return -1;
8872#endif /* NL80211_SUPPORT */
8873}
8874
8875
8876static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8877 struct sigma_cmd *cmd)
8878{
8879 #ifdef NL80211_SUPPORT
8880 struct nlattr *params;
8881 struct nlattr *attr;
8882 struct nlattr *attr1;
8883 int ifindex, ret;
8884 struct nl_msg *msg;
8885 const char *intf = get_param(cmd, "Interface");
8886
8887 ifindex = if_nametoindex(intf);
8888 if (ifindex == 0) {
8889 sigma_dut_print(dut, DUT_MSG_ERROR,
8890 "%s: Index for interface %s failed",
8891 __func__, intf);
8892 return -1;
8893 }
8894
8895 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8896 NL80211_CMD_VENDOR)) ||
8897 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8898 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8899 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8900 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8901 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8902 !(params = nla_nest_start(
8903 msg,
8904 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8905 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8906 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8907 sigma_dut_print(dut, DUT_MSG_ERROR,
8908 "%s: err in adding vendor_cmd and vendor_data",
8909 __func__);
8910 nlmsg_free(msg);
8911 return -1;
8912 }
8913 nla_nest_end(msg, attr1);
8914 nla_nest_end(msg, params);
8915 nla_nest_end(msg, attr);
8916
8917 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8918 if (ret) {
8919 sigma_dut_print(dut, DUT_MSG_ERROR,
8920 "%s: err in send_and_recv_msgs, ret=%d",
8921 __func__, ret);
8922 }
8923
8924 return ret;
8925#else /* NL80211_SUPPORT */
8926 sigma_dut_print(dut, DUT_MSG_ERROR,
8927 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8928 return -1;
8929#endif /* NL80211_SUPPORT */
8930}
8931
8932
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008933static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8934 struct sigma_cmd *cmd)
8935{
8936#ifdef NL80211_SUPPORT
8937 struct nlattr *params;
8938 struct nlattr *attr;
8939 struct nlattr *attr1;
8940 struct nl_msg *msg;
8941 int ifindex, ret;
8942 const char *val;
8943 const char *intf = get_param(cmd, "Interface");
8944 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8945 ulmu_data_dis = 0;
8946
8947 ifindex = if_nametoindex(intf);
8948 if (ifindex == 0) {
8949 sigma_dut_print(dut, DUT_MSG_ERROR,
8950 "%s: Index for interface %s failed",
8951 __func__, intf);
8952 return -1;
8953 }
8954 val = get_param(cmd, "OMCtrl_RxNSS");
8955 if (val)
8956 rx_nss = atoi(val);
8957
8958 val = get_param(cmd, "OMCtrl_ChnlWidth");
8959 if (val)
8960 ch_bw = atoi(val);
8961
8962 val = get_param(cmd, "OMCtrl_ULMUDisable");
8963 if (val)
8964 ulmu_dis = atoi(val);
8965
8966 val = get_param(cmd, "OMCtrl_TxNSTS");
8967 if (val)
8968 tx_nsts = atoi(val);
8969
8970 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8971 if (val)
8972 ulmu_data_dis = atoi(val);
8973
8974 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8975 NL80211_CMD_VENDOR)) ||
8976 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8977 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8978 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8979 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8980 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8981 !(params = nla_nest_start(
8982 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8983 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8984 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8985 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8986 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8987 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8988 ulmu_data_dis) ||
8989 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8990 ulmu_dis)) {
8991 sigma_dut_print(dut, DUT_MSG_ERROR,
8992 "%s: err in adding vendor_cmd and vendor_data",
8993 __func__);
8994 nlmsg_free(msg);
8995 return -1;
8996 }
8997 nla_nest_end(msg, attr1);
8998 nla_nest_end(msg, params);
8999 nla_nest_end(msg, attr);
9000
9001 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9002 if (ret) {
9003 sigma_dut_print(dut, DUT_MSG_ERROR,
9004 "%s: err in send_and_recv_msgs, ret=%d",
9005 __func__, ret);
9006 }
9007
9008 return ret;
9009#else /* NL80211_SUPPORT */
9010 sigma_dut_print(dut, DUT_MSG_ERROR,
9011 "OMI TX cannot be processed without NL80211_SUPPORT defined");
9012 return -1;
9013#endif /* NL80211_SUPPORT */
9014}
9015
9016
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009017static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
9018 struct sigma_conn *conn,
9019 struct sigma_cmd *cmd)
9020{
9021 const char *intf = get_param(cmd, "Interface");
9022 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07009023 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009024 int tkip = -1;
9025 int wep = -1;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309026 int iwpriv_status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009027
Arif Hussaina37e9552018-06-20 17:05:59 -07009028 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009029 val = get_param(cmd, "SGI80");
9030 if (val) {
9031 int sgi80;
9032
9033 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009034 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009035 }
9036
9037 val = get_param(cmd, "TxBF");
9038 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009039 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009040 case DRIVER_WCN:
9041 if (sta_set_tx_beamformee(dut, intf, 1)) {
9042 send_resp(dut, conn, SIGMA_ERROR,
9043 "ErrorCode,Failed to set TX beamformee enable");
9044 return 0;
9045 }
9046 break;
9047 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009048 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009049 send_resp(dut, conn, SIGMA_ERROR,
9050 "ErrorCode,Setting vhtsubfee failed");
9051 return 0;
9052 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009053 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009054 send_resp(dut, conn, SIGMA_ERROR,
9055 "ErrorCode,Setting vhtsubfer failed");
9056 return 0;
9057 }
9058 break;
9059 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009060 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009061 "Unsupported driver type");
9062 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009063 }
9064 }
9065
9066 val = get_param(cmd, "MU_TxBF");
9067 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009068 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009069 case DRIVER_ATHEROS:
9070 ath_sta_set_txsp_stream(dut, intf, "1SS");
9071 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009072 run_iwpriv(dut, intf, "vhtmubfee 1");
9073 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05309074 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009075 case DRIVER_WCN:
9076 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
9077 send_resp(dut, conn, SIGMA_ERROR,
9078 "ErrorCode,Failed to set RX/TXSP_STREAM");
9079 return 0;
9080 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05309081 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009082 default:
9083 sigma_dut_print(dut, DUT_MSG_ERROR,
9084 "Setting SP_STREAM not supported");
9085 break;
9086 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009087 }
9088
9089 val = get_param(cmd, "LDPC");
9090 if (val) {
9091 int ldpc;
9092
9093 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309094 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", ldpc);
9095 if (iwpriv_status)
9096 sta_config_params(dut, intf, STA_SET_LDPC, ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009097 }
9098
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08009099 val = get_param(cmd, "BCC");
9100 if (val) {
9101 int bcc;
9102
9103 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9104 /* use LDPC iwpriv itself to set bcc coding, bcc coding
9105 * is mutually exclusive to bcc */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309106 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", !bcc);
9107 if (iwpriv_status)
9108 sta_config_params(dut, intf, STA_SET_LDPC, !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08009109 }
9110
Arif Hussain7b47d2d2018-05-09 10:44:02 -07009111 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
9112 if (val && dut->sta_nss == 1)
9113 cmd_set_max_he_mcs(dut, intf, atoi(val));
9114
9115 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
9116 if (val && dut->sta_nss == 2)
9117 cmd_set_max_he_mcs(dut, intf, atoi(val));
9118
Arif Hussainac6c5112018-05-25 17:34:00 -07009119 val = get_param(cmd, "MCS_FixedRate");
9120 if (val) {
9121#ifdef NL80211_SUPPORT
9122 int mcs, ratecode = 0;
9123 enum he_mcs_config mcs_config;
9124 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03009125 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07009126
9127 ratecode = (0x07 & dut->sta_nss) << 5;
9128 mcs = atoi(val);
9129 /* Add the MCS to the ratecode */
9130 if (mcs >= 0 && mcs <= 11) {
9131 ratecode += mcs;
9132 if (dut->device_type == STA_testbed &&
9133 mcs > 7 && mcs <= 11) {
9134 if (mcs <= 9)
9135 mcs_config = HE_80_MCS0_9;
9136 else
9137 mcs_config = HE_80_MCS0_11;
9138 ret = sta_set_he_mcs(dut, intf, mcs_config);
9139 if (ret) {
9140 sigma_dut_print(dut, DUT_MSG_ERROR,
9141 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
9142 mcs, mcs_config, ret);
9143 }
9144 }
9145 snprintf(buf, sizeof(buf),
9146 "iwpriv %s set_11ax_rate 0x%03x",
9147 intf, ratecode);
9148 if (system(buf) != 0) {
9149 sigma_dut_print(dut, DUT_MSG_ERROR,
9150 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
9151 ratecode);
9152 }
9153 } else {
9154 sigma_dut_print(dut, DUT_MSG_ERROR,
9155 "MCS_FixedRate: HE MCS %d not supported",
9156 mcs);
9157 }
9158#else /* NL80211_SUPPORT */
9159 sigma_dut_print(dut, DUT_MSG_ERROR,
9160 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
9161#endif /* NL80211_SUPPORT */
9162 }
9163
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009164 val = get_param(cmd, "opt_md_notif_ie");
9165 if (val) {
9166 char *result = NULL;
9167 char delim[] = ";";
9168 char token[30];
9169 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309170 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009171
Peng Xub8fc5cc2017-05-10 17:27:28 -07009172 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309173 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009174
9175 /* Extract the NSS information */
9176 if (result) {
9177 value = atoi(result);
9178 switch (value) {
9179 case 1:
9180 config_val = 1;
9181 break;
9182 case 2:
9183 config_val = 3;
9184 break;
9185 case 3:
9186 config_val = 7;
9187 break;
9188 case 4:
9189 config_val = 15;
9190 break;
9191 default:
9192 config_val = 3;
9193 break;
9194 }
9195
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009196 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
9197 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009198
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009199 }
9200
9201 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309202 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009203 if (result) {
9204 value = atoi(result);
9205 switch (value) {
9206 case 20:
9207 config_val = 0;
9208 break;
9209 case 40:
9210 config_val = 1;
9211 break;
9212 case 80:
9213 config_val = 2;
9214 break;
9215 case 160:
9216 config_val = 3;
9217 break;
9218 default:
9219 config_val = 2;
9220 break;
9221 }
9222
9223 dut->chwidth = config_val;
9224
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009225 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009226 }
9227
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009228 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009229 }
9230
9231 val = get_param(cmd, "nss_mcs_cap");
9232 if (val) {
9233 int nss, mcs;
9234 char token[20];
9235 char *result = NULL;
9236 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309237 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009238
Peng Xub8fc5cc2017-05-10 17:27:28 -07009239 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309240 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309241 if (!result) {
9242 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009243 "NSS not specified");
9244 send_resp(dut, conn, SIGMA_ERROR,
9245 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309246 return 0;
9247 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009248 nss = atoi(result);
9249
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009250 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07009251 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009252
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309253 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009254 if (result == NULL) {
9255 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009256 "MCS not specified");
9257 send_resp(dut, conn, SIGMA_ERROR,
9258 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009259 return 0;
9260 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309261 result = strtok_r(result, "-", &saveptr);
9262 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309263 if (!result) {
9264 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009265 "MCS not specified");
9266 send_resp(dut, conn, SIGMA_ERROR,
9267 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309268 return 0;
9269 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009270 mcs = atoi(result);
9271
Arif Hussaina37e9552018-06-20 17:05:59 -07009272 if (program && strcasecmp(program, "HE") == 0) {
9273#ifdef NL80211_SUPPORT
9274 enum he_mcs_config mcs_config;
9275 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009276
Arif Hussaina37e9552018-06-20 17:05:59 -07009277 if (mcs >= 0 && mcs <= 7) {
9278 mcs_config = HE_80_MCS0_7;
9279 } else if (mcs > 7 && mcs <= 9) {
9280 mcs_config = HE_80_MCS0_9;
9281 } else if (mcs > 9 && mcs <= 11) {
9282 mcs_config = HE_80_MCS0_11;
9283 } else {
9284 sigma_dut_print(dut, DUT_MSG_ERROR,
9285 "nss_mcs_cap: HE: Invalid mcs: %d",
9286 mcs);
9287 send_resp(dut, conn, SIGMA_ERROR,
9288 "errorCode,Invalid MCS");
9289 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009290 }
Arif Hussaina37e9552018-06-20 17:05:59 -07009291
9292 ret = sta_set_he_mcs(dut, intf, mcs_config);
9293 if (ret) {
9294 sigma_dut_print(dut, DUT_MSG_ERROR,
9295 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
9296 mcs_config, ret);
9297 send_resp(dut, conn, SIGMA_ERROR,
9298 "errorCode,Failed to set MCS");
9299 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009300 }
Arif Hussaina37e9552018-06-20 17:05:59 -07009301#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009302 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009303 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
9304#endif /* NL80211_SUPPORT */
9305 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009306 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07009307
9308 switch (nss) {
9309 case 1:
9310 switch (mcs) {
9311 case 7:
9312 vht_mcsmap = 0xfffc;
9313 break;
9314 case 8:
9315 vht_mcsmap = 0xfffd;
9316 break;
9317 case 9:
9318 vht_mcsmap = 0xfffe;
9319 break;
9320 default:
9321 vht_mcsmap = 0xfffe;
9322 break;
9323 }
9324 break;
9325 case 2:
9326 switch (mcs) {
9327 case 7:
9328 vht_mcsmap = 0xfff0;
9329 break;
9330 case 8:
9331 vht_mcsmap = 0xfff5;
9332 break;
9333 case 9:
9334 vht_mcsmap = 0xfffa;
9335 break;
9336 default:
9337 vht_mcsmap = 0xfffa;
9338 break;
9339 }
9340 break;
9341 case 3:
9342 switch (mcs) {
9343 case 7:
9344 vht_mcsmap = 0xffc0;
9345 break;
9346 case 8:
9347 vht_mcsmap = 0xffd5;
9348 break;
9349 case 9:
9350 vht_mcsmap = 0xffea;
9351 break;
9352 default:
9353 vht_mcsmap = 0xffea;
9354 break;
9355 }
9356 break;
9357 default:
9358 vht_mcsmap = 0xffea;
9359 break;
9360 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009361 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009362 }
9363 }
9364
9365 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
9366
9367 val = get_param(cmd, "Vht_tkip");
9368 if (val)
9369 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9370
9371 val = get_param(cmd, "Vht_wep");
9372 if (val)
9373 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9374
9375 if (tkip != -1 || wep != -1) {
9376 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009377 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009378 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009379 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009380 } else {
9381 sigma_dut_print(dut, DUT_MSG_ERROR,
9382 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
9383 return 0;
9384 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009385 }
9386
Arif Hussain55f00da2018-07-03 08:28:26 -07009387 val = get_param(cmd, "txBandwidth");
9388 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009389 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07009390 case DRIVER_WCN:
9391 if (wcn_sta_set_width(dut, intf, val) < 0) {
9392 send_resp(dut, conn, SIGMA_ERROR,
9393 "ErrorCode,Failed to set txBandwidth");
9394 return 0;
9395 }
9396 break;
9397 case DRIVER_ATHEROS:
9398 if (ath_set_width(dut, conn, intf, val) < 0) {
9399 send_resp(dut, conn, SIGMA_ERROR,
9400 "ErrorCode,Failed to set txBandwidth");
9401 return 0;
9402 }
9403 break;
9404 default:
9405 sigma_dut_print(dut, DUT_MSG_ERROR,
9406 "Setting txBandwidth not supported");
9407 break;
9408 }
9409 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009410
Arif Hussain9765f7d2018-07-03 08:28:26 -07009411 val = get_param(cmd, "BeamformeeSTS");
9412 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07009413 if (sta_set_tx_beamformee(dut, intf, 1)) {
9414 send_resp(dut, conn, SIGMA_ERROR,
9415 "ErrorCode,Failed to set TX beamformee enable");
9416 return 0;
9417 }
9418
Arif Hussain9765f7d2018-07-03 08:28:26 -07009419 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
9420 send_resp(dut, conn, SIGMA_ERROR,
9421 "ErrorCode,Failed to set BeamformeeSTS");
9422 return 0;
9423 }
9424 }
9425
Arif Hussain68d23f52018-07-11 13:39:08 -07009426 val = get_param(cmd, "Trig_MAC_Padding_Dur");
9427 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07009428#ifdef NL80211_SUPPORT
9429 enum qca_wlan_he_mac_padding_dur set_val;
9430
9431 switch (atoi(val)) {
9432 case 16:
9433 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
9434 break;
9435 case 8:
9436 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
9437 break;
9438 default:
9439 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
9440 break;
9441 }
9442 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07009443 send_resp(dut, conn, SIGMA_ERROR,
9444 "ErrorCode,Failed to set MAC padding duration");
9445 return 0;
9446 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07009447#else /* NL80211_SUPPORT */
9448 sigma_dut_print(dut, DUT_MSG_ERROR,
9449 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
9450#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07009451 }
9452
Arif Hussain480d5f42019-03-12 14:40:42 -07009453 val = get_param(cmd, "TWT_ReqSupport");
9454 if (val) {
9455 int set_val;
9456
9457 if (strcasecmp(val, "Enable") == 0) {
9458 set_val = 1;
9459 } else if (strcasecmp(val, "Disable") == 0) {
9460 set_val = 0;
9461 } else {
9462 send_resp(dut, conn, SIGMA_ERROR,
9463 "ErrorCode,Invalid TWT_ReqSupport");
9464 return STATUS_SENT;
9465 }
9466
9467 if (sta_set_twt_req_support(dut, intf, set_val)) {
9468 sigma_dut_print(dut, DUT_MSG_ERROR,
9469 "Failed to set TWT req support %d",
9470 set_val);
9471 send_resp(dut, conn, SIGMA_ERROR,
9472 "ErrorCode,Failed to set TWT_ReqSupport");
9473 return STATUS_SENT;
9474 }
9475 }
9476
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07009477 val = get_param(cmd, "MU_EDCA");
9478 if (val && (strcasecmp(val, "Override") == 0)) {
9479 if (sta_set_mu_edca_override(dut, intf, 1)) {
9480 send_resp(dut, conn, SIGMA_ERROR,
9481 "ErrorCode,Failed to set MU EDCA override");
9482 return 0;
9483 }
9484 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009485
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07009486 val = get_param(cmd, "OMControl");
9487 if (val) {
9488 int set_val = 1;
9489
9490 if (strcasecmp(val, "Enable") == 0)
9491 set_val = 1;
9492 else if (strcasecmp(val, "Disable") == 0)
9493 set_val = 0;
9494
9495 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
9496 send_resp(dut, conn, SIGMA_ERROR,
9497 "ErrorCode,Failed to set OM ctrl supp");
9498 return 0;
9499 }
9500 }
9501
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009502 val = get_param(cmd, "ADDBAResp_BufSize");
9503 if (val) {
9504 int buf_size;
9505
9506 if (strcasecmp(val, "gt64") == 0)
9507 buf_size = 256;
9508 else
9509 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009510 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009511 sta_set_addba_buf_size(dut, intf, buf_size)) {
9512 send_resp(dut, conn, SIGMA_ERROR,
9513 "ErrorCode,set addbaresp_buff_size failed");
9514 return 0;
9515 }
9516 }
9517
9518 val = get_param(cmd, "ADDBAReq_BufSize");
9519 if (val) {
9520 int buf_size;
9521
9522 if (strcasecmp(val, "gt64") == 0)
9523 buf_size = 256;
9524 else
9525 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009526 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009527 sta_set_addba_buf_size(dut, intf, buf_size)) {
9528 send_resp(dut, conn, SIGMA_ERROR,
9529 "ErrorCode,set addbareq_buff_size failed");
9530 return 0;
9531 }
9532 }
9533
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009534 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9535}
9536
9537
9538static int sta_set_wireless_60g(struct sigma_dut *dut,
9539 struct sigma_conn *conn,
9540 struct sigma_cmd *cmd)
9541{
9542 const char *dev_role = get_param(cmd, "DevRole");
9543
9544 if (!dev_role) {
9545 send_resp(dut, conn, SIGMA_INVALID,
9546 "ErrorCode,DevRole not specified");
9547 return 0;
9548 }
9549
9550 if (strcasecmp(dev_role, "PCP") == 0)
9551 return sta_set_60g_pcp(dut, conn, cmd);
9552 if (strcasecmp(dev_role, "STA") == 0)
9553 return sta_set_60g_sta(dut, conn, cmd);
9554 send_resp(dut, conn, SIGMA_INVALID,
9555 "ErrorCode,DevRole not supported");
9556 return 0;
9557}
9558
9559
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309560static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
9561 struct sigma_cmd *cmd)
9562{
9563 int status;
9564 const char *intf = get_param(cmd, "Interface");
9565 const char *val = get_param(cmd, "DevRole");
9566
9567 if (val && strcasecmp(val, "STA-CFON") == 0) {
9568 status = sta_cfon_set_wireless(dut, conn, cmd);
9569 if (status)
9570 return status;
9571 }
9572 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9573}
9574
9575
Jouni Malinen67433fc2020-06-26 22:50:33 +03009576static enum sigma_cmd_result
9577sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
9578 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309579{
9580 const char *intf = get_param(cmd, "Interface");
9581 const char *val;
9582
9583 val = get_param(cmd, "ocvc");
9584 if (val)
9585 dut->ocvc = atoi(val);
9586
Jouni Malinen67433fc2020-06-26 22:50:33 +03009587 val = get_param(cmd, "ClientPrivacy");
9588 if (val) {
9589 dut->client_privacy = atoi(val);
9590 if (dut->client_privacy &&
9591 (wpa_command(intf, "SET mac_addr 1") < 0 ||
9592 wpa_command(intf, "SET rand_addr_lifetime 1") < 0 ||
9593 wpa_command(intf, "SET preassoc_mac_addr 1") < 0 ||
9594 wpa_command(intf, "SET gas_rand_mac_addr 1") < 0 ||
9595 wpa_command(intf, "SET gas_rand_addr_lifetime 1") < 0)) {
9596 send_resp(dut, conn, SIGMA_ERROR,
9597 "errorCode,Failed to enable random MAC address use");
9598 return STATUS_SENT_ERROR;
9599 }
9600 }
9601
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309602 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9603}
9604
9605
Jouni Malinenf7222712019-06-13 01:50:21 +03009606static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
9607 struct sigma_conn *conn,
9608 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009609{
9610 const char *val;
9611
9612 val = get_param(cmd, "Program");
9613 if (val) {
9614 if (strcasecmp(val, "11n") == 0)
9615 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08009616 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009617 return cmd_sta_set_wireless_vht(dut, conn, cmd);
9618 if (strcasecmp(val, "60ghz") == 0)
9619 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309620 if (strcasecmp(val, "OCE") == 0)
9621 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02009622 /* sta_set_wireless in WPS program is only used for 60G */
9623 if (is_60g_sigma_dut(dut))
9624 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309625 if (strcasecmp(val, "WPA3") == 0)
9626 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009627 send_resp(dut, conn, SIGMA_ERROR,
9628 "ErrorCode,Program value not supported");
9629 } else {
9630 send_resp(dut, conn, SIGMA_ERROR,
9631 "ErrorCode,Program argument not available");
9632 }
9633
9634 return 0;
9635}
9636
9637
9638static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
9639 int tid)
9640{
9641 char buf[100];
9642 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
9643
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05309644 if (tid < 0 ||
9645 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
9646 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
9647 return;
9648 }
9649
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009650 /*
9651 * Two ways to ensure that addba request with a
9652 * non zero TID could be sent out. EV 117296
9653 */
9654 snprintf(buf, sizeof(buf),
9655 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
9656 tid);
9657 if (system(buf) != 0) {
9658 sigma_dut_print(dut, DUT_MSG_ERROR,
9659 "Ping did not send out");
9660 }
9661
9662 snprintf(buf, sizeof(buf),
9663 "iwconfig %s | grep Access | awk '{print $6}' > %s",
9664 intf, VI_QOS_TMP_FILE);
9665 if (system(buf) != 0)
9666 return;
9667
9668 snprintf(buf, sizeof(buf),
9669 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
9670 intf, VI_QOS_TMP_FILE);
9671 if (system(buf) != 0)
9672 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
9673
9674 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
9675 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
9676 if (system(buf) != 0) {
9677 sigma_dut_print(dut, DUT_MSG_ERROR,
9678 "VI_QOS_TEMP_FILE generation error failed");
9679 }
9680 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9681 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9682 if (system(buf) != 0) {
9683 sigma_dut_print(dut, DUT_MSG_ERROR,
9684 "VI_QOS_FILE generation failed");
9685 }
9686
9687 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9688 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9689 if (system(buf) != 0) {
9690 sigma_dut_print(dut, DUT_MSG_ERROR,
9691 "VI_QOS_FILE generation failed");
9692 }
9693
9694 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
9695 if (system(buf) != 0) {
9696 }
9697}
9698
9699
9700static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9701 struct sigma_cmd *cmd)
9702{
9703 const char *intf = get_param(cmd, "Interface");
9704 const char *val;
9705 int tid = 0;
9706 char buf[100];
9707
9708 val = get_param(cmd, "TID");
9709 if (val) {
9710 tid = atoi(val);
9711 if (tid)
9712 ath_sta_inject_frame(dut, intf, tid);
9713 }
9714
9715 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009716 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009717
9718 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
9719 if (system(buf) != 0) {
9720 sigma_dut_print(dut, DUT_MSG_ERROR,
9721 "wifitool senddelba failed");
9722 }
9723
9724 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
9725 if (system(buf) != 0) {
9726 sigma_dut_print(dut, DUT_MSG_ERROR,
9727 "wifitool sendaddba failed");
9728 }
9729
9730 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9731
9732 return 1;
9733}
9734
9735
Lior David9981b512017-01-20 13:16:40 +02009736#ifdef __linux__
9737
9738static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
9739 int agg_size)
9740{
9741 char dir[128], buf[128];
9742 FILE *f;
9743 regex_t re;
9744 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03009745 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02009746
9747 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
9748 sigma_dut_print(dut, DUT_MSG_ERROR,
9749 "failed to get wil6210 debugfs dir");
9750 return -1;
9751 }
9752
Jouni Malinen3aa72862019-05-29 23:14:51 +03009753 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
9754 if (res < 0 || res >= sizeof(buf))
9755 return -1;
Lior David9981b512017-01-20 13:16:40 +02009756 f = fopen(buf, "r");
9757 if (!f) {
9758 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009759 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009760 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9761 if (res < 0 || res >= sizeof(buf))
9762 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009763 f = fopen(buf, "r");
9764 if (!f) {
9765 sigma_dut_print(dut, DUT_MSG_ERROR,
9766 "failed to open: %s", buf);
9767 return -1;
9768 }
Lior David9981b512017-01-20 13:16:40 +02009769 }
9770
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009771 /* can be either VRING tx... or RING... */
9772 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009773 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9774 goto out;
9775 }
9776
9777 /* find TX VRING for the mac address */
9778 found = 0;
9779 while (fgets(buf, sizeof(buf), f)) {
9780 if (strcasestr(buf, dest_mac)) {
9781 found = 1;
9782 break;
9783 }
9784 }
9785
9786 if (!found) {
9787 sigma_dut_print(dut, DUT_MSG_ERROR,
9788 "no TX VRING for %s", dest_mac);
9789 goto out;
9790 }
9791
9792 /* extract VRING ID, "VRING tx_<id> = {" */
9793 if (!fgets(buf, sizeof(buf), f)) {
9794 sigma_dut_print(dut, DUT_MSG_ERROR,
9795 "no VRING start line for %s", dest_mac);
9796 goto out;
9797 }
9798
9799 rc = regexec(&re, buf, 2, m, 0);
9800 regfree(&re);
9801 if (rc || m[1].rm_so < 0) {
9802 sigma_dut_print(dut, DUT_MSG_ERROR,
9803 "no VRING TX ID for %s", dest_mac);
9804 goto out;
9805 }
9806 buf[m[1].rm_eo] = 0;
9807 vring_id = atoi(&buf[m[1].rm_so]);
9808
9809 /* send the addba command */
9810 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009811 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9812 if (res < 0 || res >= sizeof(buf))
9813 return -1;
Lior David9981b512017-01-20 13:16:40 +02009814 f = fopen(buf, "w");
9815 if (!f) {
9816 sigma_dut_print(dut, DUT_MSG_ERROR,
9817 "failed to open: %s", buf);
9818 return -1;
9819 }
9820
9821 fprintf(f, "add %d %d\n", vring_id, agg_size);
9822
9823 ret = 0;
9824
9825out:
9826 fclose(f);
9827
9828 return ret;
9829}
9830
9831
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009832int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9833 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009834{
9835 const char *val;
9836 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009837
9838 val = get_param(cmd, "TID");
9839 if (val) {
9840 tid = atoi(val);
9841 if (tid != 0) {
9842 sigma_dut_print(dut, DUT_MSG_ERROR,
9843 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9844 tid);
9845 }
9846 }
9847
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009848 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009849 if (!val) {
9850 sigma_dut_print(dut, DUT_MSG_ERROR,
9851 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009852 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009853 }
9854
Lior David9981b512017-01-20 13:16:40 +02009855 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009856 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009857
9858 return 1;
9859}
9860
Lior David9981b512017-01-20 13:16:40 +02009861#endif /* __linux__ */
9862
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009863
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009864static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9865 struct sigma_cmd *cmd)
9866{
9867#ifdef NL80211_SUPPORT
9868 const char *intf = get_param(cmd, "Interface");
9869 const char *val;
9870 int tid = -1;
9871 int bufsize = 64;
9872 struct nl_msg *msg;
9873 int ret = 0;
9874 struct nlattr *params;
9875 int ifindex;
9876
9877 val = get_param(cmd, "TID");
9878 if (val)
9879 tid = atoi(val);
9880
9881 if (tid == -1) {
9882 send_resp(dut, conn, SIGMA_ERROR,
9883 "ErrorCode,sta_send_addba tid invalid");
9884 return 0;
9885 }
9886
9887 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9888
9889 ifindex = if_nametoindex(intf);
9890 if (ifindex == 0) {
9891 sigma_dut_print(dut, DUT_MSG_ERROR,
9892 "%s: Index for interface %s failed",
9893 __func__, intf);
9894 send_resp(dut, conn, SIGMA_ERROR,
9895 "ErrorCode,sta_send_addba interface invalid");
9896 return 0;
9897 }
9898
9899 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9900 NL80211_CMD_VENDOR)) ||
9901 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9902 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9903 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9904 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9905 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9906 nla_put_u8(msg,
9907 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9908 QCA_WLAN_ADD_BA) ||
9909 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9910 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009911 nla_put_u16(msg,
9912 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9913 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009914 sigma_dut_print(dut, DUT_MSG_ERROR,
9915 "%s: err in adding vendor_cmd and vendor_data",
9916 __func__);
9917 nlmsg_free(msg);
9918 send_resp(dut, conn, SIGMA_ERROR,
9919 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9920 return 0;
9921 }
9922 nla_nest_end(msg, params);
9923
9924 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9925 if (ret) {
9926 sigma_dut_print(dut, DUT_MSG_ERROR,
9927 "%s: err in send_and_recv_msgs, ret=%d",
9928 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309929 if (ret == -EOPNOTSUPP)
9930 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009931 send_resp(dut, conn, SIGMA_ERROR,
9932 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9933 return 0;
9934 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009935#else /* NL80211_SUPPORT */
9936 sigma_dut_print(dut, DUT_MSG_ERROR,
9937 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009938#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309939
9940 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009941}
9942
9943
Jouni Malinenf7222712019-06-13 01:50:21 +03009944static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9945 struct sigma_conn *conn,
9946 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009947{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009948 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009949 case DRIVER_ATHEROS:
9950 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009951 case DRIVER_WCN:
9952 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009953#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009954 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009955 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009956#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009957 default:
9958 /*
9959 * There is no driver specific implementation for other drivers.
9960 * Ignore the command and report COMPLETE since the following
9961 * throughput test operation will end up sending ADDBA anyway.
9962 */
9963 return 1;
9964 }
9965}
9966
9967
9968int inject_eth_frame(int s, const void *data, size_t len,
9969 unsigned short ethtype, char *dst, char *src)
9970{
9971 struct iovec iov[4] = {
9972 {
9973 .iov_base = dst,
9974 .iov_len = ETH_ALEN,
9975 },
9976 {
9977 .iov_base = src,
9978 .iov_len = ETH_ALEN,
9979 },
9980 {
9981 .iov_base = &ethtype,
9982 .iov_len = sizeof(unsigned short),
9983 },
9984 {
9985 .iov_base = (void *) data,
9986 .iov_len = len,
9987 }
9988 };
9989 struct msghdr msg = {
9990 .msg_name = NULL,
9991 .msg_namelen = 0,
9992 .msg_iov = iov,
9993 .msg_iovlen = 4,
9994 .msg_control = NULL,
9995 .msg_controllen = 0,
9996 .msg_flags = 0,
9997 };
9998
9999 return sendmsg(s, &msg, 0);
10000}
10001
10002#if defined(__linux__) || defined(__QNXNTO__)
10003
10004int inject_frame(int s, const void *data, size_t len, int encrypt)
10005{
10006#define IEEE80211_RADIOTAP_F_WEP 0x04
10007#define IEEE80211_RADIOTAP_F_FRAG 0x08
10008 unsigned char rtap_hdr[] = {
10009 0x00, 0x00, /* radiotap version */
10010 0x0e, 0x00, /* radiotap length */
10011 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
10012 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
10013 0x00, /* padding */
10014 0x00, 0x00, /* RX and TX flags to indicate that */
10015 0x00, 0x00, /* this is the injected frame directly */
10016 };
10017 struct iovec iov[2] = {
10018 {
10019 .iov_base = &rtap_hdr,
10020 .iov_len = sizeof(rtap_hdr),
10021 },
10022 {
10023 .iov_base = (void *) data,
10024 .iov_len = len,
10025 }
10026 };
10027 struct msghdr msg = {
10028 .msg_name = NULL,
10029 .msg_namelen = 0,
10030 .msg_iov = iov,
10031 .msg_iovlen = 2,
10032 .msg_control = NULL,
10033 .msg_controllen = 0,
10034 .msg_flags = 0,
10035 };
10036
10037 if (encrypt)
10038 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
10039
10040 return sendmsg(s, &msg, 0);
10041}
10042
10043
10044int open_monitor(const char *ifname)
10045{
10046#ifdef __QNXNTO__
10047 struct sockaddr_dl ll;
10048 int s;
10049
10050 memset(&ll, 0, sizeof(ll));
10051 ll.sdl_family = AF_LINK;
10052 ll.sdl_index = if_nametoindex(ifname);
10053 if (ll.sdl_index == 0) {
10054 perror("if_nametoindex");
10055 return -1;
10056 }
10057 s = socket(PF_INET, SOCK_RAW, 0);
10058#else /* __QNXNTO__ */
10059 struct sockaddr_ll ll;
10060 int s;
10061
10062 memset(&ll, 0, sizeof(ll));
10063 ll.sll_family = AF_PACKET;
10064 ll.sll_ifindex = if_nametoindex(ifname);
10065 if (ll.sll_ifindex == 0) {
10066 perror("if_nametoindex");
10067 return -1;
10068 }
10069 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
10070#endif /* __QNXNTO__ */
10071 if (s < 0) {
10072 perror("socket[PF_PACKET,SOCK_RAW]");
10073 return -1;
10074 }
10075
10076 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
10077 perror("monitor socket bind");
10078 close(s);
10079 return -1;
10080 }
10081
10082 return s;
10083}
10084
10085
10086static int hex2num(char c)
10087{
10088 if (c >= '0' && c <= '9')
10089 return c - '0';
10090 if (c >= 'a' && c <= 'f')
10091 return c - 'a' + 10;
10092 if (c >= 'A' && c <= 'F')
10093 return c - 'A' + 10;
10094 return -1;
10095}
10096
10097
10098int hwaddr_aton(const char *txt, unsigned char *addr)
10099{
10100 int i;
10101
10102 for (i = 0; i < 6; i++) {
10103 int a, b;
10104
10105 a = hex2num(*txt++);
10106 if (a < 0)
10107 return -1;
10108 b = hex2num(*txt++);
10109 if (b < 0)
10110 return -1;
10111 *addr++ = (a << 4) | b;
10112 if (i < 5 && *txt++ != ':')
10113 return -1;
10114 }
10115
10116 return 0;
10117}
10118
10119#endif /* defined(__linux__) || defined(__QNXNTO__) */
10120
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010121
10122#ifdef NL80211_SUPPORT
10123static int nl80211_send_frame_cmd(struct sigma_dut *dut, const char *intf,
10124 const u8 *data, size_t data_len, int freq)
10125{
10126 struct nl_msg *msg;
10127 int ret = 0;
10128 int ifindex;
10129
10130 ifindex = if_nametoindex(intf);
10131 if (ifindex == 0) {
10132 sigma_dut_print(dut, DUT_MSG_ERROR,
10133 "%s: Index for interface %s failed",
10134 __func__, intf);
10135 return -1;
10136 }
10137
10138 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10139 NL80211_CMD_FRAME)) ||
10140 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10141 nla_put(msg, NL80211_ATTR_FRAME, data_len, data)) {
10142 sigma_dut_print(dut, DUT_MSG_ERROR,
10143 "%s: Error in adding NL80211_CMD_FRAME",
10144 __func__);
10145 nlmsg_free(msg);
10146 return -1;
10147 }
10148
10149 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
10150 if (ret) {
10151 sigma_dut_print(dut, DUT_MSG_ERROR,
10152 "nl80211: Frame command failed: ret=%d (%s) req=%u",
10153 ret, strerror(-ret), freq);
10154 return -1;
10155 }
10156
10157 return 0;
10158}
10159#endif /* NL80211_SUPPORT */
10160
10161
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010162enum send_frame_type {
10163 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
10164};
10165enum send_frame_protection {
10166 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
10167};
10168
10169
10170static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010171 const char *intf, enum send_frame_type frame,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010172 enum send_frame_protection protected,
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010173 const char *dest, int use_monitor)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010174{
10175#ifdef __linux__
10176 unsigned char buf[1000], *pos;
10177 int s, res;
10178 char bssid[20], addr[20];
10179 char result[32], ssid[100];
10180 size_t ssid_len;
10181
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010182 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010183 sizeof(result)) < 0 ||
10184 strncmp(result, "COMPLETED", 9) != 0) {
10185 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
10186 return 0;
10187 }
10188
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010189 if (get_wpa_status(get_station_ifname(dut), "bssid",
10190 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010191 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
10192 "current BSSID");
10193 return 0;
10194 }
10195
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010196 if (get_wpa_status(get_station_ifname(dut), "address",
10197 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010198 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
10199 "own MAC address");
10200 return 0;
10201 }
10202
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010203 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010204 < 0) {
10205 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
10206 "current SSID");
10207 return 0;
10208 }
10209 ssid_len = strlen(ssid);
10210
10211 pos = buf;
10212
10213 /* Frame Control */
10214 switch (frame) {
10215 case DISASSOC:
10216 *pos++ = 0xa0;
10217 break;
10218 case DEAUTH:
10219 *pos++ = 0xc0;
10220 break;
10221 case SAQUERY:
10222 *pos++ = 0xd0;
10223 break;
10224 case AUTH:
10225 *pos++ = 0xb0;
10226 break;
10227 case ASSOCREQ:
10228 *pos++ = 0x00;
10229 break;
10230 case REASSOCREQ:
10231 *pos++ = 0x20;
10232 break;
10233 case DLS_REQ:
10234 *pos++ = 0xd0;
10235 break;
10236 }
10237
10238 if (protected == INCORRECT_KEY)
10239 *pos++ = 0x40; /* Set Protected field to 1 */
10240 else
10241 *pos++ = 0x00;
10242
10243 /* Duration */
10244 *pos++ = 0x00;
10245 *pos++ = 0x00;
10246
10247 /* addr1 = DA (current AP) */
10248 hwaddr_aton(bssid, pos);
10249 pos += 6;
10250 /* addr2 = SA (own address) */
10251 hwaddr_aton(addr, pos);
10252 pos += 6;
10253 /* addr3 = BSSID (current AP) */
10254 hwaddr_aton(bssid, pos);
10255 pos += 6;
10256
10257 /* Seq# (to be filled by driver/mac80211) */
10258 *pos++ = 0x00;
10259 *pos++ = 0x00;
10260
10261 if (protected == INCORRECT_KEY) {
10262 /* CCMP parameters */
10263 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
10264 pos += 8;
10265 }
10266
10267 if (protected == INCORRECT_KEY) {
10268 switch (frame) {
10269 case DEAUTH:
10270 /* Reason code (encrypted) */
10271 memcpy(pos, "\xa7\x39", 2);
10272 pos += 2;
10273 break;
10274 case DISASSOC:
10275 /* Reason code (encrypted) */
10276 memcpy(pos, "\xa7\x39", 2);
10277 pos += 2;
10278 break;
10279 case SAQUERY:
10280 /* Category|Action|TransID (encrypted) */
10281 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
10282 pos += 4;
10283 break;
10284 default:
10285 return -1;
10286 }
10287
10288 /* CCMP MIC */
10289 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
10290 pos += 8;
10291 } else {
10292 switch (frame) {
10293 case DEAUTH:
10294 /* reason code = 8 */
10295 *pos++ = 0x08;
10296 *pos++ = 0x00;
10297 break;
10298 case DISASSOC:
10299 /* reason code = 8 */
10300 *pos++ = 0x08;
10301 *pos++ = 0x00;
10302 break;
10303 case SAQUERY:
10304 /* Category - SA Query */
10305 *pos++ = 0x08;
10306 /* SA query Action - Request */
10307 *pos++ = 0x00;
10308 /* Transaction ID */
10309 *pos++ = 0x12;
10310 *pos++ = 0x34;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053010311 if (dut->saquery_oci_freq) {
10312 /* OCI IE - Extended ID */
10313 *pos++ = 0xFF;
10314 *pos++ = 0x04;
10315 *pos++ = 0x36;
10316 /* Operating Class */
10317 *pos++ = 0x74;
10318 /* Primary Channel */
10319 *pos++ = freq_to_channel(dut->saquery_oci_freq);
10320 /* Frequency Segment 1 Channel Number */
10321 *pos++ = 0x00;
10322 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010323 break;
10324 case AUTH:
10325 /* Auth Alg (Open) */
10326 *pos++ = 0x00;
10327 *pos++ = 0x00;
10328 /* Seq# */
10329 *pos++ = 0x01;
10330 *pos++ = 0x00;
10331 /* Status code */
10332 *pos++ = 0x00;
10333 *pos++ = 0x00;
10334 break;
10335 case ASSOCREQ:
10336 /* Capability Information */
10337 *pos++ = 0x31;
10338 *pos++ = 0x04;
10339 /* Listen Interval */
10340 *pos++ = 0x0a;
10341 *pos++ = 0x00;
10342 /* SSID */
10343 *pos++ = 0x00;
10344 *pos++ = ssid_len;
10345 memcpy(pos, ssid, ssid_len);
10346 pos += ssid_len;
10347 /* Supported Rates */
10348 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
10349 10);
10350 pos += 10;
10351 /* Extended Supported Rates */
10352 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
10353 pos += 6;
10354 /* RSN */
10355 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
10356 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
10357 "\x00\x00\x00\x00\x0f\xac\x06", 28);
10358 pos += 28;
10359 break;
10360 case REASSOCREQ:
10361 /* Capability Information */
10362 *pos++ = 0x31;
10363 *pos++ = 0x04;
10364 /* Listen Interval */
10365 *pos++ = 0x0a;
10366 *pos++ = 0x00;
10367 /* Current AP */
10368 hwaddr_aton(bssid, pos);
10369 pos += 6;
10370 /* SSID */
10371 *pos++ = 0x00;
10372 *pos++ = ssid_len;
10373 memcpy(pos, ssid, ssid_len);
10374 pos += ssid_len;
10375 /* Supported Rates */
10376 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
10377 10);
10378 pos += 10;
10379 /* Extended Supported Rates */
10380 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
10381 pos += 6;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053010382 /* RSNE - Group and Pairwise ciphers */
10383 memcpy(pos,
10384 "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04",
10385 14);
10386 pos += 14;
10387 /* RSNE - AKM Suite count */
10388 *pos++ = 0x01;
10389 *pos++ = 0x00;
10390 /* RSNE - AKM Suites */
10391 if (dut->program == PROGRAM_WPA3)
10392 memcpy(pos, "\x00\x0f\xac\x08", 4);
10393 else
10394 memcpy(pos, "\x00\x0f\xac\x02", 4);
10395 pos += 4;
10396 /* RSNE - Capabilities */
10397 *pos++ = 0xc0;
10398 if (dut->ocvc)
10399 *pos++ = 0x40;
10400 else
10401 *pos++ = 0x00;
10402 /* RSNE - PMKID list and Group Management Ciphers */
10403 memcpy(pos, "\x00\x00\x00\x0f\xac\x06", 6);
10404 pos += 6;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010405 break;
10406 case DLS_REQ:
10407 /* Category - DLS */
10408 *pos++ = 0x02;
10409 /* DLS Action - Request */
10410 *pos++ = 0x00;
10411 /* Destination MACAddress */
10412 if (dest)
10413 hwaddr_aton(dest, pos);
10414 else
10415 memset(pos, 0, 6);
10416 pos += 6;
10417 /* Source MACAddress */
10418 hwaddr_aton(addr, pos);
10419 pos += 6;
10420 /* Capability Information */
10421 *pos++ = 0x10; /* Privacy */
10422 *pos++ = 0x06; /* QoS */
10423 /* DLS Timeout Value */
10424 *pos++ = 0x00;
10425 *pos++ = 0x01;
10426 /* Supported rates */
10427 *pos++ = 0x01;
10428 *pos++ = 0x08;
10429 *pos++ = 0x0c; /* 6 Mbps */
10430 *pos++ = 0x12; /* 9 Mbps */
10431 *pos++ = 0x18; /* 12 Mbps */
10432 *pos++ = 0x24; /* 18 Mbps */
10433 *pos++ = 0x30; /* 24 Mbps */
10434 *pos++ = 0x48; /* 36 Mbps */
10435 *pos++ = 0x60; /* 48 Mbps */
10436 *pos++ = 0x6c; /* 54 Mbps */
10437 /* TODO: Extended Supported Rates */
10438 /* TODO: HT Capabilities */
10439 break;
10440 }
10441 }
10442
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010443 if (use_monitor) {
10444 s = open_monitor("sigmadut");
10445 if (s < 0) {
10446 send_resp(dut, conn, SIGMA_ERROR,
10447 "errorCode,Failed to open monitor socket");
10448 return 0;
10449 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010450
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010451 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
10452 if (res < 0) {
10453 send_resp(dut, conn, SIGMA_ERROR,
10454 "errorCode,Failed to inject frame");
10455 close(s);
10456 return 0;
10457 }
10458 if (res < pos - buf) {
10459 send_resp(dut, conn, SIGMA_ERROR,
10460 "errorCode,Only partial frame sent");
10461 close(s);
10462 return 0;
10463 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010464
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010465 close(s);
10466 } else {
10467#ifdef NL80211_SUPPORT
10468 int freq;
10469 char freq_str[10];
10470
10471 if (get_wpa_status(get_station_ifname(dut), "freq",
10472 freq_str, sizeof(freq_str)) < 0) {
10473 send_resp(dut, conn, SIGMA_ERROR,
10474 "errorCode,Could not get current operating frequency");
10475 return 0;
10476 }
10477 freq = atoi(freq_str);
10478
10479 if (nl80211_send_frame_cmd(dut, intf, buf, pos - buf, freq)) {
10480 send_resp(dut, conn, SIGMA_ERROR,
10481 "errorCode,Failed to inject frame");
10482 return 0;
10483 }
10484#else /* NL80211_SUPPORT */
10485 send_resp(dut, conn, SIGMA_ERROR,
10486 "errorCode,Failed to inject frame (no NL80211_SUPPORT)");
10487 return 0;
10488#endif /* NL80211_SUPPORT */
10489 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010490
10491 return 1;
10492#else /* __linux__ */
10493 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
10494 "yet supported");
10495 return 0;
10496#endif /* __linux__ */
10497}
10498
10499
10500static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
10501 struct sigma_conn *conn,
10502 struct sigma_cmd *cmd)
10503{
10504 const char *intf = get_param(cmd, "Interface");
10505 const char *sta, *val;
10506 unsigned char addr[ETH_ALEN];
10507 char buf[100];
10508
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010509 if (!intf)
10510 return -1;
10511
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010512 sta = get_param(cmd, "peer");
10513 if (sta == NULL)
10514 sta = get_param(cmd, "station");
10515 if (sta == NULL) {
10516 send_resp(dut, conn, SIGMA_ERROR,
10517 "ErrorCode,Missing peer address");
10518 return 0;
10519 }
10520 if (hwaddr_aton(sta, addr) < 0) {
10521 send_resp(dut, conn, SIGMA_ERROR,
10522 "ErrorCode,Invalid peer address");
10523 return 0;
10524 }
10525
10526 val = get_param(cmd, "type");
10527 if (val == NULL)
10528 return -1;
10529
10530 if (strcasecmp(val, "DISCOVERY") == 0) {
10531 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
10532 if (wpa_command(intf, buf) < 0) {
10533 send_resp(dut, conn, SIGMA_ERROR,
10534 "ErrorCode,Failed to send TDLS discovery");
10535 return 0;
10536 }
10537 return 1;
10538 }
10539
10540 if (strcasecmp(val, "SETUP") == 0) {
10541 int status = 0, timeout = 0;
10542
10543 val = get_param(cmd, "Status");
10544 if (val)
10545 status = atoi(val);
10546
10547 val = get_param(cmd, "Timeout");
10548 if (val)
10549 timeout = atoi(val);
10550
10551 if (status != 0 && status != 37) {
10552 send_resp(dut, conn, SIGMA_ERROR,
10553 "ErrorCode,Unsupported status value");
10554 return 0;
10555 }
10556
10557 if (timeout != 0 && timeout != 301) {
10558 send_resp(dut, conn, SIGMA_ERROR,
10559 "ErrorCode,Unsupported timeout value");
10560 return 0;
10561 }
10562
10563 if (status && timeout) {
10564 send_resp(dut, conn, SIGMA_ERROR,
10565 "ErrorCode,Unsupported timeout+status "
10566 "combination");
10567 return 0;
10568 }
10569
10570 if (status == 37 &&
10571 wpa_command(intf, "SET tdls_testing 0x200")) {
10572 send_resp(dut, conn, SIGMA_ERROR,
10573 "ErrorCode,Failed to enable "
10574 "decline setup response test mode");
10575 return 0;
10576 }
10577
10578 if (timeout == 301) {
10579 int res;
10580 if (dut->no_tpk_expiration)
10581 res = wpa_command(intf,
10582 "SET tdls_testing 0x108");
10583 else
10584 res = wpa_command(intf,
10585 "SET tdls_testing 0x8");
10586 if (res) {
10587 send_resp(dut, conn, SIGMA_ERROR,
10588 "ErrorCode,Failed to set short TPK "
10589 "lifetime");
10590 return 0;
10591 }
10592 }
10593
10594 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
10595 if (wpa_command(intf, buf) < 0) {
10596 send_resp(dut, conn, SIGMA_ERROR,
10597 "ErrorCode,Failed to send TDLS setup");
10598 return 0;
10599 }
10600 return 1;
10601 }
10602
10603 if (strcasecmp(val, "TEARDOWN") == 0) {
10604 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
10605 if (wpa_command(intf, buf) < 0) {
10606 send_resp(dut, conn, SIGMA_ERROR,
10607 "ErrorCode,Failed to send TDLS teardown");
10608 return 0;
10609 }
10610 return 1;
10611 }
10612
10613 send_resp(dut, conn, SIGMA_ERROR,
10614 "ErrorCode,Unsupported TDLS frame");
10615 return 0;
10616}
10617
10618
10619static int sta_ap_known(const char *ifname, const char *bssid)
10620{
10621 char buf[4096];
10622
Jouni Malinendd32f192018-09-15 02:55:19 +030010623 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010624 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
10625 return 0;
10626 if (strncmp(buf, "id=", 3) != 0)
10627 return 0;
10628 return 1;
10629}
10630
10631
10632static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
10633 const char *bssid)
10634{
10635 int res;
10636 struct wpa_ctrl *ctrl;
10637 char buf[256];
10638
10639 if (sta_ap_known(ifname, bssid))
10640 return 0;
10641 sigma_dut_print(dut, DUT_MSG_DEBUG,
10642 "AP not in BSS table - start scan");
10643
10644 ctrl = open_wpa_mon(ifname);
10645 if (ctrl == NULL) {
10646 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10647 "wpa_supplicant monitor connection");
10648 return -1;
10649 }
10650
10651 if (wpa_command(ifname, "SCAN") < 0) {
10652 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
10653 wpa_ctrl_detach(ctrl);
10654 wpa_ctrl_close(ctrl);
10655 return -1;
10656 }
10657
10658 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
10659 buf, sizeof(buf));
10660
10661 wpa_ctrl_detach(ctrl);
10662 wpa_ctrl_close(ctrl);
10663
10664 if (res < 0) {
10665 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
10666 return -1;
10667 }
10668
10669 if (sta_ap_known(ifname, bssid))
10670 return 0;
10671 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
10672 return -1;
10673}
10674
10675
10676static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
10677 struct sigma_conn *conn,
10678 struct sigma_cmd *cmd,
10679 const char *intf)
10680{
10681 char buf[200];
10682
10683 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
10684 if (system(buf) != 0) {
10685 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
10686 "ndsend");
10687 return 0;
10688 }
10689
10690 return 1;
10691}
10692
10693
10694static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
10695 struct sigma_conn *conn,
10696 struct sigma_cmd *cmd,
10697 const char *intf)
10698{
10699 char buf[200];
10700 const char *ip = get_param(cmd, "SenderIP");
10701
Peng Xu26b356d2017-10-04 17:58:16 -070010702 if (!ip)
10703 return 0;
10704
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010705 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
10706 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10707 if (system(buf) == 0) {
10708 sigma_dut_print(dut, DUT_MSG_INFO,
10709 "Neighbor Solicitation got a response "
10710 "for %s@%s", ip, intf);
10711 }
10712
10713 return 1;
10714}
10715
10716
10717static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
10718 struct sigma_conn *conn,
10719 struct sigma_cmd *cmd,
10720 const char *ifname)
10721{
10722 char buf[200];
10723 const char *ip = get_param(cmd, "SenderIP");
10724
10725 if (ip == NULL) {
10726 send_resp(dut, conn, SIGMA_ERROR,
10727 "ErrorCode,Missing SenderIP parameter");
10728 return 0;
10729 }
10730 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
10731 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10732 if (system(buf) != 0) {
10733 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
10734 "for %s@%s", ip, ifname);
10735 }
10736
10737 return 1;
10738}
10739
10740
10741static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
10742 struct sigma_conn *conn,
10743 struct sigma_cmd *cmd,
10744 const char *ifname)
10745{
10746 char buf[200];
10747 char ip[16];
10748 int s;
Peng Xub3756882017-10-04 14:39:09 -070010749 struct ifreq ifr;
10750 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010751
10752 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070010753 if (s < 0) {
10754 perror("socket");
10755 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010756 }
10757
Peng Xub3756882017-10-04 14:39:09 -070010758 memset(&ifr, 0, sizeof(ifr));
10759 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
10760 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
10761 sigma_dut_print(dut, DUT_MSG_INFO,
10762 "Failed to get %s IP address: %s",
10763 ifname, strerror(errno));
10764 close(s);
10765 return -1;
10766 }
10767 close(s);
10768
10769 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
10770 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
10771
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010772 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
10773 ip);
10774 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10775 if (system(buf) != 0) {
10776 }
10777
10778 return 1;
10779}
10780
10781
10782static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
10783 struct sigma_conn *conn,
10784 struct sigma_cmd *cmd,
10785 const char *ifname)
10786{
10787 char buf[200], addr[20];
10788 char dst[ETH_ALEN], src[ETH_ALEN];
10789 short ethtype = htons(ETH_P_ARP);
10790 char *pos;
10791 int s, res;
10792 const char *val;
10793 struct sockaddr_in taddr;
10794
10795 val = get_param(cmd, "dest");
10796 if (val)
10797 hwaddr_aton(val, (unsigned char *) dst);
10798
10799 val = get_param(cmd, "DestIP");
10800 if (val)
10801 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070010802 else
10803 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010804
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010805 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010806 sizeof(addr)) < 0)
10807 return -2;
10808 hwaddr_aton(addr, (unsigned char *) src);
10809
10810 pos = buf;
10811 *pos++ = 0x00;
10812 *pos++ = 0x01;
10813 *pos++ = 0x08;
10814 *pos++ = 0x00;
10815 *pos++ = 0x06;
10816 *pos++ = 0x04;
10817 *pos++ = 0x00;
10818 *pos++ = 0x02;
10819 memcpy(pos, src, ETH_ALEN);
10820 pos += ETH_ALEN;
10821 memcpy(pos, &taddr.sin_addr, 4);
10822 pos += 4;
10823 memcpy(pos, dst, ETH_ALEN);
10824 pos += ETH_ALEN;
10825 memcpy(pos, &taddr.sin_addr, 4);
10826 pos += 4;
10827
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010828 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010829 if (s < 0) {
10830 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
10831 "monitor socket");
10832 return 0;
10833 }
10834
10835 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
10836 if (res < 0) {
10837 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
10838 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053010839 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010840 return 0;
10841 }
10842
10843 close(s);
10844
10845 return 1;
10846}
10847
10848
10849static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
10850 struct sigma_conn *conn,
10851 struct sigma_cmd *cmd,
10852 const char *intf, const char *dest)
10853{
10854 char buf[100];
10855
10856 if (if_nametoindex("sigmadut") == 0) {
10857 snprintf(buf, sizeof(buf),
10858 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010859 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010860 if (system(buf) != 0 ||
10861 if_nametoindex("sigmadut") == 0) {
10862 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10863 "monitor interface with '%s'", buf);
10864 return -2;
10865 }
10866 }
10867
10868 if (system("ifconfig sigmadut up") != 0) {
10869 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10870 "monitor interface up");
10871 return -2;
10872 }
10873
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010874 return sta_inject_frame(dut, conn, intf, DLS_REQ, UNPROTECTED, dest, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010875}
10876
10877
10878static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10879 struct sigma_conn *conn,
10880 struct sigma_cmd *cmd)
10881{
10882 const char *intf = get_param(cmd, "Interface");
10883 const char *dest = get_param(cmd, "Dest");
10884 const char *type = get_param(cmd, "FrameName");
10885 const char *val;
10886 char buf[200], *pos, *end;
10887 int count, count2;
10888
10889 if (type == NULL)
10890 type = get_param(cmd, "Type");
10891
10892 if (intf == NULL || dest == NULL || type == NULL)
10893 return -1;
10894
10895 if (strcasecmp(type, "NeighAdv") == 0)
10896 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10897
10898 if (strcasecmp(type, "NeighSolicitReq") == 0)
10899 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10900
10901 if (strcasecmp(type, "ARPProbe") == 0)
10902 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10903
10904 if (strcasecmp(type, "ARPAnnounce") == 0)
10905 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10906
10907 if (strcasecmp(type, "ARPReply") == 0)
10908 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10909
10910 if (strcasecmp(type, "DLS-request") == 0 ||
10911 strcasecmp(type, "DLSrequest") == 0)
10912 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10913 dest);
10914
10915 if (strcasecmp(type, "ANQPQuery") != 0 &&
10916 strcasecmp(type, "Query") != 0) {
10917 send_resp(dut, conn, SIGMA_ERROR,
10918 "ErrorCode,Unsupported HS 2.0 send frame type");
10919 return 0;
10920 }
10921
10922 if (sta_scan_ap(dut, intf, dest) < 0) {
10923 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10924 "the requested AP");
10925 return 0;
10926 }
10927
10928 pos = buf;
10929 end = buf + sizeof(buf);
10930 count = 0;
10931 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10932
10933 val = get_param(cmd, "ANQP_CAP_LIST");
10934 if (val && atoi(val)) {
10935 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10936 count++;
10937 }
10938
10939 val = get_param(cmd, "VENUE_NAME");
10940 if (val && atoi(val)) {
10941 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10942 count++;
10943 }
10944
10945 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10946 if (val && atoi(val)) {
10947 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10948 count++;
10949 }
10950
10951 val = get_param(cmd, "ROAMING_CONS");
10952 if (val && atoi(val)) {
10953 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10954 count++;
10955 }
10956
10957 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10958 if (val && atoi(val)) {
10959 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10960 count++;
10961 }
10962
10963 val = get_param(cmd, "NAI_REALM_LIST");
10964 if (val && atoi(val)) {
10965 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10966 count++;
10967 }
10968
10969 val = get_param(cmd, "3GPP_INFO");
10970 if (val && atoi(val)) {
10971 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10972 count++;
10973 }
10974
10975 val = get_param(cmd, "DOMAIN_LIST");
10976 if (val && atoi(val)) {
10977 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10978 count++;
10979 }
10980
Jouni Malinen34cf9532018-04-29 19:26:33 +030010981 val = get_param(cmd, "Venue_URL");
10982 if (val && atoi(val)) {
10983 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10984 count++;
10985 }
10986
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010987 val = get_param(cmd, "Advice_Of_Charge");
10988 if (val && atoi(val)) {
10989 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10990 count++;
10991 }
10992
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010993 if (count && wpa_command(intf, buf)) {
10994 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10995 return 0;
10996 }
10997
10998 pos = buf;
10999 end = buf + sizeof(buf);
11000 count2 = 0;
11001 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
11002
11003 val = get_param(cmd, "HS_CAP_LIST");
11004 if (val && atoi(val)) {
11005 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
11006 count2++;
11007 }
11008
11009 val = get_param(cmd, "OPER_NAME");
11010 if (val && atoi(val)) {
11011 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
11012 count2++;
11013 }
11014
11015 val = get_param(cmd, "WAN_METRICS");
11016 if (!val)
11017 val = get_param(cmd, "WAN_MAT");
11018 if (!val)
11019 val = get_param(cmd, "WAN_MET");
11020 if (val && atoi(val)) {
11021 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
11022 count2++;
11023 }
11024
11025 val = get_param(cmd, "CONNECTION_CAPABILITY");
11026 if (val && atoi(val)) {
11027 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
11028 count2++;
11029 }
11030
11031 val = get_param(cmd, "OP_CLASS");
11032 if (val && atoi(val)) {
11033 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
11034 count2++;
11035 }
11036
11037 val = get_param(cmd, "OSU_PROVIDER_LIST");
11038 if (val && atoi(val)) {
11039 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
11040 count2++;
11041 }
11042
Jouni Malinenf67afec2018-04-29 19:24:58 +030011043 val = get_param(cmd, "OPER_ICON_METADATA");
11044 if (!val)
11045 val = get_param(cmd, "OPERATOR_ICON_METADATA");
11046 if (val && atoi(val)) {
11047 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
11048 count2++;
11049 }
11050
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011051 if (count && count2) {
11052 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
11053 "second query");
11054 sleep(1);
11055 }
11056
11057 if (count2 && wpa_command(intf, buf)) {
11058 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
11059 "failed");
11060 return 0;
11061 }
11062
11063 val = get_param(cmd, "NAI_HOME_REALM_LIST");
11064 if (val) {
11065 if (count || count2) {
11066 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
11067 "sending out second query");
11068 sleep(1);
11069 }
11070
11071 if (strcmp(val, "1") == 0)
11072 val = "mail.example.com";
11073 snprintf(buf, end - pos,
11074 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
11075 dest, val);
11076 if (wpa_command(intf, buf)) {
11077 send_resp(dut, conn, SIGMA_ERROR,
11078 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
11079 "failed");
11080 return 0;
11081 }
11082 }
11083
11084 val = get_param(cmd, "ICON_REQUEST");
11085 if (val) {
11086 if (count || count2) {
11087 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
11088 "sending out second query");
11089 sleep(1);
11090 }
11091
11092 snprintf(buf, end - pos,
11093 "HS20_ICON_REQUEST %s %s", dest, val);
11094 if (wpa_command(intf, buf)) {
11095 send_resp(dut, conn, SIGMA_ERROR,
11096 "ErrorCode,HS20_ICON_REQUEST failed");
11097 return 0;
11098 }
11099 }
11100
11101 return 1;
11102}
11103
11104
11105static int ath_sta_send_frame_vht(struct sigma_dut *dut,
11106 struct sigma_conn *conn,
11107 struct sigma_cmd *cmd)
11108{
11109 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011110 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011111 int chwidth, nss;
11112
11113 val = get_param(cmd, "framename");
11114 if (!val)
11115 return -1;
11116 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
11117
11118 /* Command sequence to generate Op mode notification */
11119 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011120 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011121
11122 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011123 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011124
11125 /* Extract Channel width */
11126 val = get_param(cmd, "Channel_width");
11127 if (val) {
11128 switch (atoi(val)) {
11129 case 20:
11130 chwidth = 0;
11131 break;
11132 case 40:
11133 chwidth = 1;
11134 break;
11135 case 80:
11136 chwidth = 2;
11137 break;
11138 case 160:
11139 chwidth = 3;
11140 break;
11141 default:
11142 chwidth = 2;
11143 break;
11144 }
11145
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011146 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011147 }
11148
11149 /* Extract NSS */
11150 val = get_param(cmd, "NSS");
11151 if (val) {
11152 switch (atoi(val)) {
11153 case 1:
11154 nss = 1;
11155 break;
11156 case 2:
11157 nss = 3;
11158 break;
11159 case 3:
11160 nss = 7;
11161 break;
11162 default:
11163 /* We do not support NSS > 3 */
11164 nss = 3;
11165 break;
11166 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011167 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011168 }
11169
11170 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011171 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011172 }
11173
11174 return 1;
11175}
11176
11177
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011178static int wcn_sta_set_pmf_config(struct sigma_dut *dut, const char *intf,
11179 enum send_frame_protection protected)
11180{
11181#ifdef NL80211_SUPPORT
11182 struct nl_msg *msg;
11183 int ret = 0;
11184 struct nlattr *params;
11185 int ifindex;
11186
11187 ifindex = if_nametoindex(intf);
11188 if (ifindex == 0) {
11189 sigma_dut_print(dut, DUT_MSG_ERROR,
11190 "%s: Index for interface %s failed",
11191 __func__, intf);
11192 return -1;
11193 }
11194
11195 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
11196 NL80211_CMD_VENDOR)) ||
11197 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
11198 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
11199 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
11200 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
11201 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
11202 nla_put_u8(msg,
11203 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PMF_PROTECTION,
11204 protected)) {
11205 sigma_dut_print(dut, DUT_MSG_ERROR,
11206 "%s: err in adding vendor_cmd and vendor_data",
11207 __func__);
11208 nlmsg_free(msg);
11209 return -1;
11210 }
11211 nla_nest_end(msg, params);
11212
11213 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
11214 if (ret) {
11215 sigma_dut_print(dut, DUT_MSG_ERROR,
11216 "%s: err in send_and_recv_msgs, ret=%d",
11217 __func__, ret);
11218 }
11219 return ret;
11220#else /* NL80211_SUPPORT */
11221 sigma_dut_print(dut, DUT_MSG_ERROR,
11222 "PMF config cannot be set without NL80211_SUPPORT defined");
11223 return -1;
11224#endif /* NL80211_SUPPORT */
11225}
11226
11227
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011228static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
11229 struct sigma_conn *conn,
11230 struct sigma_cmd *cmd)
11231{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011232 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011233 case DRIVER_ATHEROS:
11234 return ath_sta_send_frame_vht(dut, conn, cmd);
11235 default:
11236 send_resp(dut, conn, SIGMA_ERROR,
11237 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
11238 return 0;
11239 }
11240}
11241
11242
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011243static int wcn_sta_send_disassoc(struct sigma_dut *dut, const char *intf)
11244{
11245#ifdef NL80211_SUPPORT
11246 struct nl_msg *msg;
11247 int ret = 0;
11248 struct nlattr *params;
11249 int ifindex;
11250
11251 ifindex = if_nametoindex(intf);
11252 if (ifindex == 0) {
11253 sigma_dut_print(dut, DUT_MSG_ERROR,
11254 "%s: Index for interface %s failed",
11255 __func__, intf);
11256 return -1;
11257 }
11258
11259 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
11260 NL80211_CMD_VENDOR)) ||
11261 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
11262 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
11263 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
11264 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
11265 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
11266 nla_put_flag(msg,
11267 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISASSOC_TX)) {
11268 sigma_dut_print(dut, DUT_MSG_ERROR,
11269 "%s: err in adding vendor_cmd and vendor_data",
11270 __func__);
11271 nlmsg_free(msg);
11272 return -1;
11273 }
11274 nla_nest_end(msg, params);
11275
11276 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
11277 if (ret) {
11278 sigma_dut_print(dut, DUT_MSG_ERROR,
11279 "%s: err in send_and_recv_msgs, ret=%d",
11280 __func__, ret);
11281 }
11282 return ret;
11283#else /* NL80211_SUPPORT */
11284 sigma_dut_print(dut, DUT_MSG_ERROR,
11285 "Disassoc Tx cannot be done without NL80211_SUPPORT defined");
11286 return -1;
11287#endif /* NL80211_SUPPORT */
11288}
11289
11290
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011291static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
11292 struct sigma_cmd *cmd)
11293{
11294 const char *val;
11295 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011296 enum send_frame_protection protected;
11297 const char *pmf;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011298
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011299 if (!intf)
11300 return -1;
11301
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011302 val = get_param(cmd, "framename");
11303 if (!val)
11304 return -1;
11305 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
11306
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011307 pmf = get_param(cmd, "PMFProtected");
11308 if (!pmf)
11309 pmf = get_param(cmd, "Protected");
11310 if (pmf) {
11311 if (strcasecmp(pmf, "Correct-key") == 0 ||
11312 strcasecmp(pmf, "CorrectKey") == 0) {
11313 protected = CORRECT_KEY;
11314 } else if (strcasecmp(pmf, "IncorrectKey") == 0) {
11315 protected = INCORRECT_KEY;
11316 } else if (strcasecmp(pmf, "Unprotected") == 0) {
11317 protected = UNPROTECTED;
11318 } else {
11319 send_resp(dut, conn, SIGMA_ERROR,
11320 "errorCode,Unsupported PMFProtected");
11321 return STATUS_SENT_ERROR;
11322 }
11323 sigma_dut_print(dut, DUT_MSG_DEBUG, "Config PMF protection %d",
11324 protected);
11325 wcn_sta_set_pmf_config(dut, intf, protected);
11326 }
11327
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011328 /* Command sequence to generate Op mode notification */
11329 if (val && strcasecmp(val, "action") == 0) {
11330 val = get_param(cmd, "PPDUTxType");
11331 if (val && strcasecmp(val, "TB") == 0) {
11332 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
11333 sigma_dut_print(dut, DUT_MSG_ERROR,
11334 "failed to send TB PPDU Tx cfg");
11335 send_resp(dut, conn, SIGMA_ERROR,
11336 "ErrorCode,set TB PPDU Tx cfg failed");
11337 return 0;
11338 }
11339 return 1;
11340 }
11341
11342 sigma_dut_print(dut, DUT_MSG_ERROR,
11343 "Action Tx type is not defined");
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011344
11345 return SUCCESS_SEND_STATUS;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011346 }
11347
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011348 if (strcasecmp(val, "disassoc") == 0)
11349 wcn_sta_send_disassoc(dut, intf);
11350
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011351 return 1;
11352}
11353
11354
11355static int cmd_sta_send_frame_he(struct sigma_dut *dut,
11356 struct sigma_conn *conn,
11357 struct sigma_cmd *cmd)
11358{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011359 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011360 case DRIVER_WCN:
11361 return wcn_sta_send_frame_he(dut, conn, cmd);
11362 default:
11363 send_resp(dut, conn, SIGMA_ERROR,
11364 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
11365 return 0;
11366 }
11367}
11368
11369
Lior David0fe101e2017-03-09 16:09:50 +020011370#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011371
11372static int
11373wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
11374 const char *frame_name, const char *dest_mac)
11375{
11376 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
11377 const char *ssid = get_param(cmd, "ssid");
11378 const char *countstr = get_param(cmd, "count");
11379 const char *channelstr = get_param(cmd, "channel");
11380 const char *group_id = get_param(cmd, "groupid");
11381 const char *client_id = get_param(cmd, "clientmac");
11382 int count, channel, freq, i;
11383 const char *fname;
11384 char frame[1024], src_mac[20], group_id_attr[25],
11385 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
11386 const char *group_ssid;
11387 const int group_ssid_prefix_len = 9;
11388 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
11389 size_t framelen = sizeof(frame);
11390 struct template_frame_tag tags[2];
11391 size_t tags_total = ARRAY_SIZE(tags);
11392 int tag_index, len, dst_len;
11393
11394 if (!countstr || !channelstr) {
11395 sigma_dut_print(dut, DUT_MSG_ERROR,
11396 "Missing argument: count, channel");
11397 return -1;
11398 }
11399 if (isprobereq && !ssid) {
11400 sigma_dut_print(dut, DUT_MSG_ERROR,
11401 "Missing argument: ssid");
11402 return -1;
11403 }
11404 if (!isprobereq && (!group_id || !client_id)) {
11405 sigma_dut_print(dut, DUT_MSG_ERROR,
11406 "Missing argument: group_id, client_id");
11407 return -1;
11408 }
11409
11410 count = atoi(countstr);
11411 channel = atoi(channelstr);
11412 freq = channel_to_freq(dut, channel);
11413
11414 if (!freq) {
11415 sigma_dut_print(dut, DUT_MSG_ERROR,
11416 "invalid channel: %s", channelstr);
11417 return -1;
11418 }
11419
11420 if (isprobereq) {
11421 if (strcasecmp(ssid, "wildcard") == 0) {
11422 fname = "probe_req_wildcard.txt";
11423 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
11424 fname = "probe_req_P2P_Wildcard.txt";
11425 } else {
11426 sigma_dut_print(dut, DUT_MSG_ERROR,
11427 "invalid probe request type");
11428 return -1;
11429 }
11430 } else {
11431 fname = "P2P_device_discovery_req.txt";
11432 }
11433
11434 if (parse_template_frame_file(dut, fname, frame, &framelen,
11435 tags, &tags_total)) {
11436 sigma_dut_print(dut, DUT_MSG_ERROR,
11437 "invalid frame template: %s", fname);
11438 return -1;
11439 }
11440
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011441 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011442 src_mac, sizeof(src_mac)) < 0 ||
11443 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
11444 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
11445 return -1;
11446 /* Use wildcard BSSID, since we are in PBSS */
11447 memset(&hdr->addr3, 0xFF, ETH_ALEN);
11448
11449 if (!isprobereq) {
11450 tag_index = find_template_frame_tag(tags, tags_total, 1);
11451 if (tag_index < 0) {
11452 sigma_dut_print(dut, DUT_MSG_ERROR,
11453 "can't find device id attribute");
11454 return -1;
11455 }
11456 if (parse_mac_address(dut, client_id,
11457 (unsigned char *) client_mac)) {
11458 sigma_dut_print(dut, DUT_MSG_ERROR,
11459 "invalid client_id: %s", client_id);
11460 return -1;
11461 }
11462 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11463 framelen - tags[tag_index].offset,
11464 IEEE80211_P2P_ATTR_DEVICE_ID,
11465 client_mac, ETH_ALEN)) {
11466 sigma_dut_print(dut, DUT_MSG_ERROR,
11467 "fail to replace device id attribute");
11468 return -1;
11469 }
11470
11471 /*
11472 * group_id arg contains device MAC address followed by
11473 * space and SSID (DIRECT-somessid).
11474 * group id attribute contains device address (6 bytes)
11475 * followed by SSID prefix DIRECT-XX (9 bytes)
11476 */
11477 if (strlen(group_id) < sizeof(device_macstr)) {
11478 sigma_dut_print(dut, DUT_MSG_ERROR,
11479 "group_id arg too short");
11480 return -1;
11481 }
11482 memcpy(device_macstr, group_id, sizeof(device_macstr));
11483 device_macstr[sizeof(device_macstr) - 1] = '\0';
11484 if (parse_mac_address(dut, device_macstr,
11485 (unsigned char *) group_id_attr)) {
11486 sigma_dut_print(dut, DUT_MSG_ERROR,
11487 "fail to parse device address from group_id");
11488 return -1;
11489 }
11490 group_ssid = strchr(group_id, ' ');
11491 if (!group_ssid) {
11492 sigma_dut_print(dut, DUT_MSG_ERROR,
11493 "invalid group_id arg, no ssid");
11494 return -1;
11495 }
11496 group_ssid++;
11497 len = strlen(group_ssid);
11498 if (len < group_ssid_prefix_len) {
11499 sigma_dut_print(dut, DUT_MSG_ERROR,
11500 "group_id SSID too short");
11501 return -1;
11502 }
11503 dst_len = sizeof(group_id_attr) - ETH_ALEN;
11504 if (len > dst_len) {
11505 sigma_dut_print(dut, DUT_MSG_ERROR,
11506 "group_id SSID (%s) too long",
11507 group_ssid);
11508 return -1;
11509 }
11510
11511 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
11512 tag_index = find_template_frame_tag(tags, tags_total, 2);
11513 if (tag_index < 0) {
11514 sigma_dut_print(dut, DUT_MSG_ERROR,
11515 "can't find group id attribute");
11516 return -1;
11517 }
11518 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11519 framelen - tags[tag_index].offset,
11520 IEEE80211_P2P_ATTR_GROUP_ID,
11521 group_id_attr,
11522 sizeof(group_id_attr))) {
11523 sigma_dut_print(dut, DUT_MSG_ERROR,
11524 "fail to replace group id attribute");
11525 return -1;
11526 }
11527 }
11528
11529 for (i = 0; i < count; i++) {
11530 if (wil6210_transmit_frame(dut, freq,
11531 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
11532 frame, framelen)) {
11533 sigma_dut_print(dut, DUT_MSG_ERROR,
11534 "fail to transmit probe request frame");
11535 return -1;
11536 }
11537 }
11538
11539 return 0;
11540}
11541
11542
Lior David0fe101e2017-03-09 16:09:50 +020011543int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
11544 struct sigma_cmd *cmd)
11545{
11546 const char *frame_name = get_param(cmd, "framename");
11547 const char *mac = get_param(cmd, "dest_mac");
11548
11549 if (!frame_name || !mac) {
11550 sigma_dut_print(dut, DUT_MSG_ERROR,
11551 "framename and dest_mac must be provided");
11552 return -1;
11553 }
11554
11555 if (strcasecmp(frame_name, "brp") == 0) {
11556 const char *l_rx = get_param(cmd, "L-RX");
11557 int l_rx_i;
11558
11559 if (!l_rx) {
11560 sigma_dut_print(dut, DUT_MSG_ERROR,
11561 "L-RX must be provided");
11562 return -1;
11563 }
11564 l_rx_i = atoi(l_rx);
11565
11566 sigma_dut_print(dut, DUT_MSG_INFO,
11567 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
11568 mac, l_rx);
11569 if (l_rx_i != 16) {
11570 sigma_dut_print(dut, DUT_MSG_ERROR,
11571 "unsupported L-RX: %s", l_rx);
11572 return -1;
11573 }
11574
11575 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
11576 return -1;
11577 } else if (strcasecmp(frame_name, "ssw") == 0) {
11578 sigma_dut_print(dut, DUT_MSG_INFO,
11579 "dev_send_frame: SLS, dest_mac %s", mac);
11580 if (wil6210_send_sls(dut, mac))
11581 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011582 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
11583 (strcasecmp(frame_name, "devdiscreq") == 0)) {
11584 sigma_dut_print(dut, DUT_MSG_INFO,
11585 "dev_send_frame: %s, dest_mac %s", frame_name,
11586 mac);
11587 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
11588 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020011589 } else {
11590 sigma_dut_print(dut, DUT_MSG_ERROR,
11591 "unsupported frame type: %s", frame_name);
11592 return -1;
11593 }
11594
11595 return 1;
11596}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011597
Lior David0fe101e2017-03-09 16:09:50 +020011598#endif /* __linux__ */
11599
11600
11601static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
11602 struct sigma_conn *conn,
11603 struct sigma_cmd *cmd)
11604{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011605 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020011606#ifdef __linux__
11607 case DRIVER_WIL6210:
11608 return wil6210_send_frame_60g(dut, conn, cmd);
11609#endif /* __linux__ */
11610 default:
11611 send_resp(dut, conn, SIGMA_ERROR,
11612 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
11613 return 0;
11614 }
11615}
11616
11617
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011618static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
11619 const char *intf, struct sigma_cmd *cmd)
11620{
11621 const char *val, *addr;
11622 char buf[100];
11623
11624 addr = get_param(cmd, "DestMac");
11625 if (!addr) {
11626 send_resp(dut, conn, SIGMA_INVALID,
11627 "ErrorCode,AP MAC address is missing");
11628 return 0;
11629 }
11630
11631 val = get_param(cmd, "ANQPQuery_ID");
11632 if (!val) {
11633 send_resp(dut, conn, SIGMA_INVALID,
11634 "ErrorCode,Missing ANQPQuery_ID");
11635 return 0;
11636 }
11637
11638 if (strcasecmp(val, "NeighborReportReq") == 0) {
11639 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
11640 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
11641 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
11642 } else {
11643 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
11644 val);
11645 send_resp(dut, conn, SIGMA_INVALID,
11646 "ErrorCode,Invalid ANQPQuery_ID");
11647 return 0;
11648 }
11649
Ashwini Patild174f2c2017-04-13 16:49:46 +053011650 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
11651 * (Address3 = Wildcard BSSID when sent to not-associated AP;
11652 * if associated, AP BSSID).
11653 */
11654 if (wpa_command(intf, "SET gas_address3 1") < 0) {
11655 send_resp(dut, conn, SIGMA_ERROR,
11656 "ErrorCode,Failed to set gas_address3");
11657 return 0;
11658 }
11659
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011660 if (wpa_command(intf, buf) < 0) {
11661 send_resp(dut, conn, SIGMA_ERROR,
11662 "ErrorCode,Failed to send ANQP query");
11663 return 0;
11664 }
11665
11666 return 1;
11667}
11668
11669
11670static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
11671 struct sigma_conn *conn,
11672 const char *intf,
11673 struct sigma_cmd *cmd)
11674{
11675 const char *val = get_param(cmd, "FrameName");
11676
11677 if (val && strcasecmp(val, "ANQPQuery") == 0)
11678 return mbo_send_anqp_query(dut, conn, intf, cmd);
11679
11680 return 2;
11681}
11682
11683
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011684static enum sigma_cmd_result cmd_sta_send_frame_wpa3(struct sigma_dut *dut,
11685 struct sigma_conn *conn,
11686 const char *intf,
11687 struct sigma_cmd *cmd)
11688{
11689 const char *val = get_param(cmd, "framename");
11690
11691 if (!val)
11692 return INVALID_SEND_STATUS;
11693
11694 if (strcasecmp(val, "SAQueryReq") == 0) {
11695 val = get_param(cmd, "OCIChannel");
11696
11697 if (!val) {
11698 send_resp(dut, conn, SIGMA_ERROR,
11699 "errorCode,OCIChannel not present");
11700 return STATUS_SENT_ERROR;
11701 }
11702
11703 dut->saquery_oci_freq = channel_to_freq(dut, atoi(val));
11704 if (!dut->saquery_oci_freq) {
11705 send_resp(dut, conn, SIGMA_ERROR,
11706 "errorCode,Invalid OCIChannel number");
11707 return STATUS_SENT_ERROR;
11708 }
11709
11710 return sta_inject_frame(dut, conn, intf, SAQUERY, CORRECT_KEY,
11711 NULL, 0);
11712 }
11713
11714 if (strcasecmp(val, "reassocreq") == 0)
11715 return sta_inject_frame(dut, conn, intf, REASSOCREQ,
11716 CORRECT_KEY, NULL, 0);
11717
Veerendranath9f81dfb2020-08-10 01:21:29 -070011718 if (strcasecmp(val, "ANQPQuery") == 0) {
11719 char buf[50];
11720 const char *dest = get_param(cmd, "DestMac");
11721 const char *chan = get_param(cmd, "channel");
11722 int len, freq;
11723
11724 freq = chan ? channel_to_freq(dut, atoi(chan)) : 0;
11725 if (!dest || !freq)
11726 return INVALID_SEND_STATUS;
11727
11728 len = snprintf(buf, sizeof(buf), "ANQP_GET %s freq=%d 257",
11729 dest, freq);
11730 if (len < 0 || len >= sizeof(buf)) {
11731 sigma_dut_print(dut, DUT_MSG_ERROR,
11732 "Failed to allocate buf");
11733 return ERROR_SEND_STATUS;
11734 }
11735
11736 if (wpa_command(intf, buf) != 0) {
11737 send_resp(dut, conn, SIGMA_ERROR,
11738 "ErrorCode,Failed to send ANQP Query frame");
11739 return STATUS_SENT_ERROR;
11740 }
11741
11742 sigma_dut_print(dut, DUT_MSG_DEBUG,
11743 "ANQP Query sent: %s", buf);
11744
11745 return SUCCESS_SEND_STATUS;
11746 }
11747
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011748 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported framename");
11749 return STATUS_SENT_ERROR;
11750}
11751
11752
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011753static enum sigma_cmd_result
11754cmd_sta_send_frame_mscs(struct sigma_dut *dut, struct sigma_conn *conn,
11755 const char *intf, struct sigma_cmd *cmd)
11756{
11757 char buf[128], *pos;
11758 const char *val, *classifier_type = "04", *type;
11759 int len, rem_len;
11760 u8 up_bitmap;
11761
11762 val = get_param(cmd, "FrameName");
11763 type = get_param(cmd, "Request_Type");
11764 if (!val || !type || strcasecmp(val, "MSCSReq") != 0) {
11765 sigma_dut_print(dut, DUT_MSG_ERROR,
11766 "%s: frame name or type not valid", __func__);
11767 return INVALID_SEND_STATUS;
11768 }
11769
11770 rem_len = sizeof(buf);
11771 pos = buf;
11772 if (strcasecmp(type, "add") == 0) {
11773 len = snprintf(pos, rem_len, "MSCS add");
11774 } else if (strcasecmp(type, "update") == 0) {
11775 len = snprintf(pos, rem_len, "MSCS change");
11776 } else if (strcasecmp(type, "remove") == 0) {
11777 if (wpa_command(intf, "MSCS remove") != 0) {
11778 send_resp(dut, conn, SIGMA_ERROR,
11779 "ErrorCode,Failed to send MSCS frame req");
11780 return STATUS_SENT_ERROR;
11781 }
11782 return SUCCESS_SEND_STATUS;
11783 } else {
11784 sigma_dut_print(dut, DUT_MSG_ERROR,
11785 "%s: request type invalid", __func__);
11786 return INVALID_SEND_STATUS;
11787 }
11788
11789 if (len < 0 || len >= rem_len)
11790 goto fail;
11791
11792 pos += len;
11793 rem_len -= len;
11794
11795 val = get_param(cmd, "User_Priority_Bitmap");
11796 if (!val) {
11797 sigma_dut_print(dut, DUT_MSG_ERROR,
11798 "%s: user priority bitmap empty", __func__);
11799 return INVALID_SEND_STATUS;
11800 }
11801
11802 switch (atoi(val)) {
11803 case 0:
11804 up_bitmap = 0x00;
11805 break;
11806 case 1:
11807 up_bitmap = 0xF0;
11808 break;
11809 case 2:
11810 up_bitmap = 0xF6;
11811 break;
11812 default:
11813 sigma_dut_print(dut, DUT_MSG_ERROR,
11814 "%s: Unknown User_Priority_Bitmap value %d",
11815 __func__, atoi(val));
11816 return INVALID_SEND_STATUS;
11817 }
11818
11819 len = snprintf(pos, rem_len, " up_bitmap=%02x", up_bitmap);
11820 if (len < 0 || len >= rem_len)
11821 goto fail;
11822
11823 pos += len;
11824 rem_len -= len;
11825
11826 val = get_param(cmd, "User_Priority_Limit");
11827 if (!val) {
11828 sigma_dut_print(dut, DUT_MSG_ERROR,
11829 "%s: invalid user priority limit", __func__);
11830 return INVALID_SEND_STATUS;
11831 }
11832
11833 len = snprintf(pos, rem_len, " up_limit=%s", val);
11834 if (len < 0 || len >= rem_len)
11835 goto fail;
11836
11837 pos += len;
11838 rem_len -= len;
11839
11840 val = get_param(cmd, "Stream_Timeout");
11841 if (!val)
11842 val = get_param(cmd, "Stream_Timtout");
11843 if (!val) {
11844 sigma_dut_print(dut, DUT_MSG_ERROR,
11845 "%s: invalid stream timeout", __func__);
11846 return INVALID_SEND_STATUS;
11847 }
11848
11849 len = snprintf(pos, rem_len, " stream_timeout=%s", val);
11850 if (len < 0 || len >= rem_len)
11851 goto fail;
11852
11853 pos += len;
11854 rem_len -= len;
11855
11856 val = get_param(cmd, "TCLAS_Mask");
11857 if (!val) {
11858 sigma_dut_print(dut, DUT_MSG_ERROR,
11859 "%s: invalid tclas mask", __func__);
11860 return INVALID_SEND_STATUS;
11861 }
11862
11863 len = snprintf(pos, rem_len, " frame_classifier=%s%lx%032x",
11864 classifier_type, strtol(val, NULL, 2), 0);
11865 if (len < 0 || len >= rem_len)
11866 goto fail;
11867
11868 if (wpa_command(intf, buf) != 0) {
11869 send_resp(dut, conn, SIGMA_ERROR,
11870 "ErrorCode,Failed to send MSCS frame req");
11871 return STATUS_SENT_ERROR;
11872 }
11873
11874 sigma_dut_print(dut, DUT_MSG_DEBUG,
11875 "MSCS frame request sent: %s", buf);
11876
11877 return SUCCESS_SEND_STATUS;
11878fail:
11879 sigma_dut_print(dut, DUT_MSG_ERROR,
11880 "Failed to create MSCS frame req");
11881 return ERROR_SEND_STATUS;
11882}
11883
11884
Jouni Malinenf7222712019-06-13 01:50:21 +030011885enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
11886 struct sigma_conn *conn,
11887 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011888{
11889 const char *intf = get_param(cmd, "Interface");
11890 const char *val;
11891 enum send_frame_type frame;
11892 enum send_frame_protection protected;
11893 char buf[100];
11894 unsigned char addr[ETH_ALEN];
11895 int res;
11896
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011897 if (!intf)
11898 return -1;
11899
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011900 val = get_param(cmd, "program");
11901 if (val == NULL)
11902 val = get_param(cmd, "frame");
11903 if (val && strcasecmp(val, "TDLS") == 0)
11904 return cmd_sta_send_frame_tdls(dut, conn, cmd);
11905 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011906 strcasecmp(val, "HS2-R2") == 0 ||
11907 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011908 return cmd_sta_send_frame_hs2(dut, conn, cmd);
11909 if (val && strcasecmp(val, "VHT") == 0)
11910 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011911 if (val && strcasecmp(val, "HE") == 0)
11912 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070011913 if (val && strcasecmp(val, "LOC") == 0)
11914 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020011915 if (val && strcasecmp(val, "60GHz") == 0)
11916 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011917 if (val && strcasecmp(val, "MBO") == 0) {
11918 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
11919 if (res != 2)
11920 return res;
11921 }
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011922 if (val && strcasecmp(val, "WPA3") == 0)
11923 return cmd_sta_send_frame_wpa3(dut, conn, intf, cmd);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011924 if (val && strcasecmp(val, "QM") == 0)
11925 return cmd_sta_send_frame_mscs(dut, conn, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011926
11927 val = get_param(cmd, "TD_DISC");
11928 if (val) {
11929 if (hwaddr_aton(val, addr) < 0)
11930 return -1;
11931 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
11932 if (wpa_command(intf, buf) < 0) {
11933 send_resp(dut, conn, SIGMA_ERROR,
11934 "ErrorCode,Failed to send TDLS discovery");
11935 return 0;
11936 }
11937 return 1;
11938 }
11939
11940 val = get_param(cmd, "TD_Setup");
11941 if (val) {
11942 if (hwaddr_aton(val, addr) < 0)
11943 return -1;
11944 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
11945 if (wpa_command(intf, buf) < 0) {
11946 send_resp(dut, conn, SIGMA_ERROR,
11947 "ErrorCode,Failed to start TDLS setup");
11948 return 0;
11949 }
11950 return 1;
11951 }
11952
11953 val = get_param(cmd, "TD_TearDown");
11954 if (val) {
11955 if (hwaddr_aton(val, addr) < 0)
11956 return -1;
11957 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
11958 if (wpa_command(intf, buf) < 0) {
11959 send_resp(dut, conn, SIGMA_ERROR,
11960 "ErrorCode,Failed to tear down TDLS link");
11961 return 0;
11962 }
11963 return 1;
11964 }
11965
11966 val = get_param(cmd, "TD_ChannelSwitch");
11967 if (val) {
11968 /* TODO */
11969 send_resp(dut, conn, SIGMA_ERROR,
11970 "ErrorCode,TD_ChannelSwitch not yet supported");
11971 return 0;
11972 }
11973
11974 val = get_param(cmd, "TD_NF");
11975 if (val) {
11976 /* TODO */
11977 send_resp(dut, conn, SIGMA_ERROR,
11978 "ErrorCode,TD_NF not yet supported");
11979 return 0;
11980 }
11981
11982 val = get_param(cmd, "PMFFrameType");
11983 if (val == NULL)
11984 val = get_param(cmd, "FrameName");
11985 if (val == NULL)
11986 val = get_param(cmd, "Type");
11987 if (val == NULL)
11988 return -1;
11989 if (strcasecmp(val, "disassoc") == 0)
11990 frame = DISASSOC;
11991 else if (strcasecmp(val, "deauth") == 0)
11992 frame = DEAUTH;
11993 else if (strcasecmp(val, "saquery") == 0)
11994 frame = SAQUERY;
11995 else if (strcasecmp(val, "auth") == 0)
11996 frame = AUTH;
11997 else if (strcasecmp(val, "assocreq") == 0)
11998 frame = ASSOCREQ;
11999 else if (strcasecmp(val, "reassocreq") == 0)
12000 frame = REASSOCREQ;
12001 else if (strcasecmp(val, "neigreq") == 0) {
12002 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
12003
12004 val = get_param(cmd, "ssid");
12005 if (val == NULL)
12006 return -1;
12007
12008 res = send_neighbor_request(dut, intf, val);
12009 if (res) {
12010 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
12011 "Failed to send neighbor report request");
12012 return 0;
12013 }
12014
12015 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053012016 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
12017 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012018 sigma_dut_print(dut, DUT_MSG_DEBUG,
12019 "Got Transition Management Query");
12020
Ashwini Patil5acd7382017-04-13 15:55:04 +053012021 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012022 if (res) {
12023 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
12024 "Failed to send Transition Management Query");
12025 return 0;
12026 }
12027
12028 return 1;
12029 } else {
12030 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12031 "PMFFrameType");
12032 return 0;
12033 }
12034
12035 val = get_param(cmd, "PMFProtected");
12036 if (val == NULL)
12037 val = get_param(cmd, "Protected");
12038 if (val == NULL)
12039 return -1;
12040 if (strcasecmp(val, "Correct-key") == 0 ||
12041 strcasecmp(val, "CorrectKey") == 0)
12042 protected = CORRECT_KEY;
12043 else if (strcasecmp(val, "IncorrectKey") == 0)
12044 protected = INCORRECT_KEY;
12045 else if (strcasecmp(val, "Unprotected") == 0)
12046 protected = UNPROTECTED;
12047 else {
12048 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12049 "PMFProtected");
12050 return 0;
12051 }
12052
12053 if (protected != UNPROTECTED &&
12054 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
12055 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
12056 "PMFProtected for auth/assocreq/reassocreq");
12057 return 0;
12058 }
12059
12060 if (if_nametoindex("sigmadut") == 0) {
12061 snprintf(buf, sizeof(buf),
12062 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012063 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012064 if (system(buf) != 0 ||
12065 if_nametoindex("sigmadut") == 0) {
12066 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
12067 "monitor interface with '%s'", buf);
12068 return -2;
12069 }
12070 }
12071
12072 if (system("ifconfig sigmadut up") != 0) {
12073 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
12074 "monitor interface up");
12075 return -2;
12076 }
12077
Veerendranath Jakkam49774122020-07-05 09:52:18 +053012078 return sta_inject_frame(dut, conn, intf, frame, protected, NULL, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012079}
12080
12081
12082static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
12083 struct sigma_conn *conn,
12084 struct sigma_cmd *cmd,
12085 const char *ifname)
12086{
12087 char buf[200];
12088 const char *val;
12089
12090 val = get_param(cmd, "ClearARP");
12091 if (val && atoi(val) == 1) {
12092 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
12093 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12094 if (system(buf) != 0) {
12095 send_resp(dut, conn, SIGMA_ERROR,
12096 "errorCode,Failed to clear ARP cache");
12097 return 0;
12098 }
12099 }
12100
12101 return 1;
12102}
12103
12104
12105int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
12106 struct sigma_cmd *cmd)
12107{
12108 const char *intf = get_param(cmd, "Interface");
12109 const char *val;
12110
12111 if (intf == NULL)
12112 return -1;
12113
12114 val = get_param(cmd, "program");
12115 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030012116 strcasecmp(val, "HS2-R2") == 0 ||
12117 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012118 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
12119
12120 return -1;
12121}
12122
12123
Jouni Malinenf7222712019-06-13 01:50:21 +030012124static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
12125 struct sigma_conn *conn,
12126 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012127{
12128 const char *intf = get_param(cmd, "Interface");
12129 const char *mac = get_param(cmd, "MAC");
12130
12131 if (intf == NULL || mac == NULL)
12132 return -1;
12133
12134 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
12135 "interface %s to %s", intf, mac);
12136
12137 if (dut->set_macaddr) {
12138 char buf[128];
12139 int res;
12140 if (strcasecmp(mac, "default") == 0) {
12141 res = snprintf(buf, sizeof(buf), "%s",
12142 dut->set_macaddr);
12143 dut->tmp_mac_addr = 0;
12144 } else {
12145 res = snprintf(buf, sizeof(buf), "%s %s",
12146 dut->set_macaddr, mac);
12147 dut->tmp_mac_addr = 1;
12148 }
12149 if (res < 0 || res >= (int) sizeof(buf))
12150 return -1;
12151 if (system(buf) != 0) {
12152 send_resp(dut, conn, SIGMA_ERROR,
12153 "errorCode,Failed to set MAC "
12154 "address");
12155 return 0;
12156 }
12157 return 1;
12158 }
12159
12160 if (strcasecmp(mac, "default") == 0)
12161 return 1;
12162
12163 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12164 "command");
12165 return 0;
12166}
12167
12168
12169static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
12170 struct sigma_conn *conn, const char *intf,
12171 int val)
12172{
12173 char buf[200];
12174 int res;
12175
12176 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
12177 intf, val);
12178 if (res < 0 || res >= (int) sizeof(buf))
12179 return -1;
12180 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12181 if (system(buf) != 0) {
12182 send_resp(dut, conn, SIGMA_ERROR,
12183 "errorCode,Failed to configure offchannel mode");
12184 return 0;
12185 }
12186
12187 return 1;
12188}
12189
12190
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012191static int off_chan_val(enum sec_ch_offset off)
12192{
12193 switch (off) {
12194 case SEC_CH_NO:
12195 return 0;
12196 case SEC_CH_40ABOVE:
12197 return 40;
12198 case SEC_CH_40BELOW:
12199 return -40;
12200 }
12201
12202 return 0;
12203}
12204
12205
12206static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
12207 const char *intf, int off_ch_num,
12208 enum sec_ch_offset sec)
12209{
12210 char buf[200];
12211 int res;
12212
12213 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
12214 intf, off_ch_num);
12215 if (res < 0 || res >= (int) sizeof(buf))
12216 return -1;
12217 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12218 if (system(buf) != 0) {
12219 send_resp(dut, conn, SIGMA_ERROR,
12220 "errorCode,Failed to set offchan");
12221 return 0;
12222 }
12223
12224 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
12225 intf, off_chan_val(sec));
12226 if (res < 0 || res >= (int) sizeof(buf))
12227 return -1;
12228 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12229 if (system(buf) != 0) {
12230 send_resp(dut, conn, SIGMA_ERROR,
12231 "errorCode,Failed to set sec chan offset");
12232 return 0;
12233 }
12234
12235 return 1;
12236}
12237
12238
12239static int tdls_set_offchannel_offset(struct sigma_dut *dut,
12240 struct sigma_conn *conn,
12241 const char *intf, int off_ch_num,
12242 enum sec_ch_offset sec)
12243{
12244 char buf[200];
12245 int res;
12246
12247 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
12248 off_ch_num);
12249 if (res < 0 || res >= (int) sizeof(buf))
12250 return -1;
12251 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12252
12253 if (wpa_command(intf, buf) < 0) {
12254 send_resp(dut, conn, SIGMA_ERROR,
12255 "ErrorCode,Failed to set offchan");
12256 return 0;
12257 }
12258 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
12259 off_chan_val(sec));
12260 if (res < 0 || res >= (int) sizeof(buf))
12261 return -1;
12262
12263 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12264
12265 if (wpa_command(intf, buf) < 0) {
12266 send_resp(dut, conn, SIGMA_ERROR,
12267 "ErrorCode,Failed to set sec chan offset");
12268 return 0;
12269 }
12270
12271 return 1;
12272}
12273
12274
12275static int tdls_set_offchannel_mode(struct sigma_dut *dut,
12276 struct sigma_conn *conn,
12277 const char *intf, int val)
12278{
12279 char buf[200];
12280 int res;
12281
12282 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
12283 val);
12284 if (res < 0 || res >= (int) sizeof(buf))
12285 return -1;
12286 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12287
12288 if (wpa_command(intf, buf) < 0) {
12289 send_resp(dut, conn, SIGMA_ERROR,
12290 "ErrorCode,Failed to configure offchannel mode");
12291 return 0;
12292 }
12293
12294 return 1;
12295}
12296
12297
12298static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
12299 struct sigma_conn *conn,
12300 struct sigma_cmd *cmd)
12301{
12302 const char *val;
12303 enum {
12304 CHSM_NOT_SET,
12305 CHSM_ENABLE,
12306 CHSM_DISABLE,
12307 CHSM_REJREQ,
12308 CHSM_UNSOLRESP
12309 } chsm = CHSM_NOT_SET;
12310 int off_ch_num = -1;
12311 enum sec_ch_offset sec_ch = SEC_CH_NO;
12312 int res;
12313
12314 val = get_param(cmd, "Uapsd");
12315 if (val) {
12316 char buf[100];
12317 if (strcasecmp(val, "Enable") == 0)
12318 snprintf(buf, sizeof(buf), "SET ps 99");
12319 else if (strcasecmp(val, "Disable") == 0)
12320 snprintf(buf, sizeof(buf), "SET ps 98");
12321 else {
12322 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
12323 "Unsupported uapsd parameter value");
12324 return 0;
12325 }
12326 if (wpa_command(intf, buf)) {
12327 send_resp(dut, conn, SIGMA_ERROR,
12328 "ErrorCode,Failed to change U-APSD "
12329 "powersave mode");
12330 return 0;
12331 }
12332 }
12333
12334 val = get_param(cmd, "TPKTIMER");
12335 if (val && strcasecmp(val, "DISABLE") == 0) {
12336 if (wpa_command(intf, "SET tdls_testing 0x100")) {
12337 send_resp(dut, conn, SIGMA_ERROR,
12338 "ErrorCode,Failed to enable no TPK "
12339 "expiration test mode");
12340 return 0;
12341 }
12342 dut->no_tpk_expiration = 1;
12343 }
12344
12345 val = get_param(cmd, "ChSwitchMode");
12346 if (val) {
12347 if (strcasecmp(val, "Enable") == 0 ||
12348 strcasecmp(val, "Initiate") == 0)
12349 chsm = CHSM_ENABLE;
12350 else if (strcasecmp(val, "Disable") == 0 ||
12351 strcasecmp(val, "passive") == 0)
12352 chsm = CHSM_DISABLE;
12353 else if (strcasecmp(val, "RejReq") == 0)
12354 chsm = CHSM_REJREQ;
12355 else if (strcasecmp(val, "UnSolResp") == 0)
12356 chsm = CHSM_UNSOLRESP;
12357 else {
12358 send_resp(dut, conn, SIGMA_ERROR,
12359 "ErrorCode,Unknown ChSwitchMode value");
12360 return 0;
12361 }
12362 }
12363
12364 val = get_param(cmd, "OffChNum");
12365 if (val) {
12366 off_ch_num = atoi(val);
12367 if (off_ch_num == 0) {
12368 send_resp(dut, conn, SIGMA_ERROR,
12369 "ErrorCode,Invalid OffChNum");
12370 return 0;
12371 }
12372 }
12373
12374 val = get_param(cmd, "SecChOffset");
12375 if (val) {
12376 if (strcmp(val, "20") == 0)
12377 sec_ch = SEC_CH_NO;
12378 else if (strcasecmp(val, "40above") == 0)
12379 sec_ch = SEC_CH_40ABOVE;
12380 else if (strcasecmp(val, "40below") == 0)
12381 sec_ch = SEC_CH_40BELOW;
12382 else {
12383 send_resp(dut, conn, SIGMA_ERROR,
12384 "ErrorCode,Unknown SecChOffset value");
12385 return 0;
12386 }
12387 }
12388
12389 if (chsm == CHSM_NOT_SET) {
12390 /* no offchannel changes requested */
12391 return 1;
12392 }
12393
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012394 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
12395 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012396 send_resp(dut, conn, SIGMA_ERROR,
12397 "ErrorCode,Unknown interface");
12398 return 0;
12399 }
12400
12401 switch (chsm) {
12402 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030012403 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012404 break;
12405 case CHSM_ENABLE:
12406 if (off_ch_num < 0) {
12407 send_resp(dut, conn, SIGMA_ERROR,
12408 "ErrorCode,Missing OffChNum argument");
12409 return 0;
12410 }
12411 if (wifi_chip_type == DRIVER_WCN) {
12412 res = tdls_set_offchannel_offset(dut, conn, intf,
12413 off_ch_num, sec_ch);
12414 } else {
12415 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
12416 sec_ch);
12417 }
12418 if (res != 1)
12419 return res;
12420 if (wifi_chip_type == DRIVER_WCN)
12421 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
12422 else
12423 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
12424 break;
12425 case CHSM_DISABLE:
12426 if (wifi_chip_type == DRIVER_WCN)
12427 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
12428 else
12429 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
12430 break;
12431 case CHSM_REJREQ:
12432 if (wifi_chip_type == DRIVER_WCN)
12433 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
12434 else
12435 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
12436 break;
12437 case CHSM_UNSOLRESP:
12438 if (off_ch_num < 0) {
12439 send_resp(dut, conn, SIGMA_ERROR,
12440 "ErrorCode,Missing OffChNum argument");
12441 return 0;
12442 }
12443 if (wifi_chip_type == DRIVER_WCN) {
12444 res = tdls_set_offchannel_offset(dut, conn, intf,
12445 off_ch_num, sec_ch);
12446 } else {
12447 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
12448 sec_ch);
12449 }
12450 if (res != 1)
12451 return res;
12452 if (wifi_chip_type == DRIVER_WCN)
12453 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
12454 else
12455 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
12456 break;
12457 }
12458
12459 return res;
12460}
12461
12462
12463static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
12464 struct sigma_conn *conn,
12465 struct sigma_cmd *cmd)
12466{
12467 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053012468 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012469
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070012470 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080012471
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012472 val = get_param(cmd, "nss_mcs_opt");
12473 if (val) {
12474 /* String (nss_operating_mode; mcs_operating_mode) */
12475 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012476 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012477
12478 token = strdup(val);
12479 if (!token)
12480 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012481 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053012482 if (!result) {
12483 sigma_dut_print(dut, DUT_MSG_ERROR,
12484 "VHT NSS not specified");
12485 goto failed;
12486 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012487 if (strcasecmp(result, "def") != 0) {
12488 nss = atoi(result);
12489 if (nss == 4)
12490 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012491 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012492 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012493
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012494 }
12495
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012496 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053012497 if (!result) {
12498 sigma_dut_print(dut, DUT_MSG_ERROR,
12499 "VHT MCS not specified");
12500 goto failed;
12501 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012502 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012503 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012504 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012505 } else {
12506 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012507 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012508 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012509 }
12510 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012511 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012512 }
12513
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053012514 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012515 return 1;
12516failed:
12517 free(token);
12518 return 0;
12519}
12520
12521
12522static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
12523 struct sigma_conn *conn,
12524 struct sigma_cmd *cmd)
12525{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012526 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012527 case DRIVER_ATHEROS:
12528 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
12529 default:
12530 send_resp(dut, conn, SIGMA_ERROR,
12531 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
12532 return 0;
12533 }
12534}
12535
12536
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012537static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12538 struct sigma_conn *conn,
12539 struct sigma_cmd *cmd)
12540{
12541 const char *val;
12542 char *token = NULL, *result;
12543 char buf[60];
12544
12545 val = get_param(cmd, "nss_mcs_opt");
12546 if (val) {
12547 /* String (nss_operating_mode; mcs_operating_mode) */
12548 int nss, mcs, ratecode;
12549 char *saveptr;
12550
12551 token = strdup(val);
12552 if (!token)
12553 return -2;
12554
12555 result = strtok_r(token, ";", &saveptr);
12556 if (!result) {
12557 sigma_dut_print(dut, DUT_MSG_ERROR,
12558 "HE NSS not specified");
12559 goto failed;
12560 }
12561 nss = 1;
12562 if (strcasecmp(result, "def") != 0)
12563 nss = atoi(result);
12564
12565 result = strtok_r(NULL, ";", &saveptr);
12566 if (!result) {
12567 sigma_dut_print(dut, DUT_MSG_ERROR,
12568 "HE MCS not specified");
12569 goto failed;
12570 }
12571 mcs = 7;
12572 if (strcasecmp(result, "def") != 0)
12573 mcs = atoi(result);
12574
Arif Hussain557bf412018-05-25 17:29:36 -070012575 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012576 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070012577 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012578 } else if (nss > 2) {
12579 sigma_dut_print(dut, DUT_MSG_ERROR,
12580 "HE NSS %d not supported", nss);
12581 goto failed;
12582 }
12583
Arif Hussain557bf412018-05-25 17:29:36 -070012584 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
12585 if (system(buf) != 0) {
12586 sigma_dut_print(dut, DUT_MSG_ERROR,
12587 "nss_mcs_opt: iwpriv %s nss %d failed",
12588 intf, nss);
12589 goto failed;
12590 }
Arif Hussainac6c5112018-05-25 17:34:00 -070012591 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070012592
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012593 /* Add the MCS to the ratecode */
12594 if (mcs >= 0 && mcs <= 11) {
12595 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070012596#ifdef NL80211_SUPPORT
12597 if (dut->device_type == STA_testbed) {
12598 enum he_mcs_config mcs_config;
12599 int ret;
12600
12601 if (mcs <= 7)
12602 mcs_config = HE_80_MCS0_7;
12603 else if (mcs <= 9)
12604 mcs_config = HE_80_MCS0_9;
12605 else
12606 mcs_config = HE_80_MCS0_11;
12607 ret = sta_set_he_mcs(dut, intf, mcs_config);
12608 if (ret) {
12609 sigma_dut_print(dut, DUT_MSG_ERROR,
12610 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
12611 mcs, mcs_config, ret);
12612 goto failed;
12613 }
12614 }
12615#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012616 } else {
12617 sigma_dut_print(dut, DUT_MSG_ERROR,
12618 "HE MCS %d not supported", mcs);
12619 goto failed;
12620 }
12621 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
12622 intf, ratecode);
12623 if (system(buf) != 0) {
12624 sigma_dut_print(dut, DUT_MSG_ERROR,
12625 "iwpriv setting of 11ax rates failed");
12626 goto failed;
12627 }
12628 free(token);
12629 }
12630
12631 val = get_param(cmd, "GI");
12632 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012633 int fix_rate_sgi;
12634
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012635 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012636 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012637 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012638 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012639 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
12640 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012641 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012642 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012643 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
12644 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012645 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012646 } else {
12647 send_resp(dut, conn, SIGMA_ERROR,
12648 "errorCode,GI value not supported");
12649 return 0;
12650 }
12651 if (system(buf) != 0) {
12652 send_resp(dut, conn, SIGMA_ERROR,
12653 "errorCode,Failed to set shortgi");
12654 return 0;
12655 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012656 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
12657 intf, fix_rate_sgi);
12658 if (system(buf) != 0) {
12659 send_resp(dut, conn, SIGMA_ERROR,
12660 "errorCode,Failed to set fix rate shortgi");
12661 return STATUS_SENT;
12662 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012663 }
12664
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012665 val = get_param(cmd, "LTF");
12666 if (val) {
12667#ifdef NL80211_SUPPORT
12668 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012669 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012670 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012671 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012672 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012673 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012674 } else {
12675 send_resp(dut, conn, SIGMA_ERROR,
12676 "errorCode, LTF value not supported");
12677 return 0;
12678 }
12679#else /* NL80211_SUPPORT */
12680 sigma_dut_print(dut, DUT_MSG_ERROR,
12681 "LTF cannot be set without NL80211_SUPPORT defined");
12682 return -2;
12683#endif /* NL80211_SUPPORT */
12684 }
12685
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070012686 val = get_param(cmd, "TxSUPPDU");
12687 if (val) {
12688 int set_val = 1;
12689
12690 if (strcasecmp(val, "Enable") == 0)
12691 set_val = 1;
12692 else if (strcasecmp(val, "Disable") == 0)
12693 set_val = 0;
12694
12695 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
12696 send_resp(dut, conn, SIGMA_ERROR,
12697 "ErrorCode,Failed to set Tx SU PPDU config");
12698 return 0;
12699 }
12700 }
12701
Arif Hussain480d5f42019-03-12 14:40:42 -070012702 val = get_param(cmd, "TWT_Setup");
12703 if (val) {
12704 if (strcasecmp(val, "Request") == 0) {
12705 if (sta_twt_request(dut, conn, cmd)) {
12706 send_resp(dut, conn, SIGMA_ERROR,
12707 "ErrorCode,sta_twt_request failed");
12708 return STATUS_SENT;
12709 }
12710 } else if (strcasecmp(val, "Teardown") == 0) {
12711 if (sta_twt_teardown(dut, conn, cmd)) {
12712 send_resp(dut, conn, SIGMA_ERROR,
12713 "ErrorCode,sta_twt_teardown failed");
12714 return STATUS_SENT;
12715 }
12716 }
12717 }
12718
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080012719 val = get_param(cmd, "transmitOMI");
12720 if (val && sta_transmit_omi(dut, conn, cmd)) {
12721 send_resp(dut, conn, SIGMA_ERROR,
12722 "ErrorCode,sta_transmit_omi failed");
12723 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070012724 }
12725
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012726 val = get_param(cmd, "Powersave");
12727 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012728 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012729
12730 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012731 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012732 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012733 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012734 } else {
12735 sigma_dut_print(dut, DUT_MSG_ERROR,
12736 "Unsupported Powersave value '%s'",
12737 val);
12738 return -1;
12739 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012740 if (set_power_save_wcn(dut, intf, ps) < 0)
12741 return 0;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012742 }
12743
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080012744 val = get_param(cmd, "MU_EDCA");
12745 if (val) {
12746 if (strcasecmp(val, "Override") == 0) {
12747 if (sta_set_mu_edca_override(dut, intf, 1)) {
12748 send_resp(dut, conn, SIGMA_ERROR,
12749 "errorCode,MU EDCA override set failed");
12750 return STATUS_SENT;
12751 }
12752 } else if (strcasecmp(val, "Disable") == 0) {
12753 if (sta_set_mu_edca_override(dut, intf, 0)) {
12754 send_resp(dut, conn, SIGMA_ERROR,
12755 "errorCode,MU EDCA override disable failed");
12756 return STATUS_SENT;
12757 }
12758 }
12759 }
12760
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -070012761 val = get_param(cmd, "Ch_Pref");
12762 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12763 return STATUS_SENT;
12764
12765 val = get_param(cmd, "Cellular_Data_Cap");
12766 if (val && mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12767 return STATUS_SENT;
12768
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012769 return 1;
12770
12771failed:
12772 free(token);
12773 return -2;
12774}
12775
12776
12777static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12778 struct sigma_conn *conn,
12779 struct sigma_cmd *cmd)
12780{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012781 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012782 case DRIVER_WCN:
12783 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
12784 default:
12785 send_resp(dut, conn, SIGMA_ERROR,
12786 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
12787 return 0;
12788 }
12789}
12790
12791
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012792static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
12793 struct sigma_conn *conn,
12794 struct sigma_cmd *cmd)
12795{
12796 const char *val;
12797
12798 val = get_param(cmd, "powersave");
12799 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012800 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012801
12802 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012803 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012804 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012805 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012806 } else {
12807 sigma_dut_print(dut, DUT_MSG_ERROR,
12808 "Unsupported power save config");
12809 return -1;
12810 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012811 if (set_power_save_wcn(dut, intf, ps) < 0)
12812 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012813 return 1;
12814 }
12815
12816 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
12817
12818 return 0;
12819}
12820
12821
Ashwini Patil5acd7382017-04-13 15:55:04 +053012822static int btm_query_candidate_list(struct sigma_dut *dut,
12823 struct sigma_conn *conn,
12824 struct sigma_cmd *cmd)
12825{
12826 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
12827 int len, ret;
12828 char buf[10];
12829
12830 /*
12831 * Neighbor Report elements format:
12832 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
12833 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
12834 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
12835 */
12836
12837 bssid = get_param(cmd, "Nebor_BSSID");
12838 if (!bssid) {
12839 send_resp(dut, conn, SIGMA_INVALID,
12840 "errorCode,Nebor_BSSID is missing");
12841 return 0;
12842 }
12843
12844 info = get_param(cmd, "Nebor_Bssid_Info");
12845 if (!info) {
12846 sigma_dut_print(dut, DUT_MSG_INFO,
12847 "Using default value for Nebor_Bssid_Info: %s",
12848 DEFAULT_NEIGHBOR_BSSID_INFO);
12849 info = DEFAULT_NEIGHBOR_BSSID_INFO;
12850 }
12851
12852 op_class = get_param(cmd, "Nebor_Op_Class");
12853 if (!op_class) {
12854 send_resp(dut, conn, SIGMA_INVALID,
12855 "errorCode,Nebor_Op_Class is missing");
12856 return 0;
12857 }
12858
12859 ch = get_param(cmd, "Nebor_Op_Ch");
12860 if (!ch) {
12861 send_resp(dut, conn, SIGMA_INVALID,
12862 "errorCode,Nebor_Op_Ch is missing");
12863 return 0;
12864 }
12865
12866 phy_type = get_param(cmd, "Nebor_Phy_Type");
12867 if (!phy_type) {
12868 sigma_dut_print(dut, DUT_MSG_INFO,
12869 "Using default value for Nebor_Phy_Type: %s",
12870 DEFAULT_NEIGHBOR_PHY_TYPE);
12871 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
12872 }
12873
12874 /* Parse optional subelements */
12875 buf[0] = '\0';
12876 pref = get_param(cmd, "Nebor_Pref");
12877 if (pref) {
12878 /* hexdump for preferrence subelement */
12879 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
12880 if (ret < 0 || ret >= (int) sizeof(buf)) {
12881 sigma_dut_print(dut, DUT_MSG_ERROR,
12882 "snprintf failed for optional subelement ret: %d",
12883 ret);
12884 send_resp(dut, conn, SIGMA_ERROR,
12885 "errorCode,snprintf failed for subelement");
12886 return 0;
12887 }
12888 }
12889
12890 if (!dut->btm_query_cand_list) {
12891 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
12892 if (!dut->btm_query_cand_list) {
12893 send_resp(dut, conn, SIGMA_ERROR,
12894 "errorCode,Failed to allocate memory for btm_query_cand_list");
12895 return 0;
12896 }
12897 }
12898
12899 len = strlen(dut->btm_query_cand_list);
12900 ret = snprintf(dut->btm_query_cand_list + len,
12901 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
12902 bssid, info, op_class, ch, phy_type, buf);
12903 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
12904 sigma_dut_print(dut, DUT_MSG_ERROR,
12905 "snprintf failed for neighbor report list ret: %d",
12906 ret);
12907 send_resp(dut, conn, SIGMA_ERROR,
12908 "errorCode,snprintf failed for neighbor report");
12909 free(dut->btm_query_cand_list);
12910 dut->btm_query_cand_list = NULL;
12911 return 0;
12912 }
12913
12914 return 1;
12915}
12916
12917
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012918int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
12919 struct sigma_ese_alloc *allocs, int *allocs_size)
12920{
12921 int max_count = *allocs_size;
12922 int count = 0, i;
12923 const char *val;
12924
12925 do {
12926 val = get_param_indexed(cmd, "AllocID", count);
12927 if (val)
12928 count++;
12929 } while (val);
12930
12931 if (count == 0 || count > max_count) {
12932 sigma_dut_print(dut, DUT_MSG_ERROR,
12933 "Invalid number of allocations(%d)", count);
12934 return -1;
12935 }
12936
12937 for (i = 0; i < count; i++) {
12938 val = get_param_indexed(cmd, "PercentBI", i);
12939 if (!val) {
12940 sigma_dut_print(dut, DUT_MSG_ERROR,
12941 "Missing PercentBI parameter at index %d",
12942 i);
12943 return -1;
12944 }
12945 allocs[i].percent_bi = atoi(val);
12946
12947 val = get_param_indexed(cmd, "SrcAID", i);
12948 if (val)
12949 allocs[i].src_aid = strtol(val, NULL, 0);
12950 else
12951 allocs[i].src_aid = ESE_BCAST_AID;
12952
12953 val = get_param_indexed(cmd, "DestAID", i);
12954 if (val)
12955 allocs[i].dst_aid = strtol(val, NULL, 0);
12956 else
12957 allocs[i].dst_aid = ESE_BCAST_AID;
12958
12959 allocs[i].type = ESE_CBAP;
12960 sigma_dut_print(dut, DUT_MSG_INFO,
12961 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
12962 i, allocs[i].percent_bi, allocs[i].src_aid,
12963 allocs[i].dst_aid);
12964 }
12965
12966 *allocs_size = count;
12967 return 0;
12968}
12969
12970
12971static int sta_set_60g_ese(struct sigma_dut *dut, int count,
12972 struct sigma_ese_alloc *allocs)
12973{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012974 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012975#ifdef __linux__
12976 case DRIVER_WIL6210:
12977 if (wil6210_set_ese(dut, count, allocs))
12978 return -1;
12979 return 1;
12980#endif /* __linux__ */
12981 default:
12982 sigma_dut_print(dut, DUT_MSG_ERROR,
12983 "Unsupported sta_set_60g_ese with the current driver");
12984 return -1;
12985 }
12986}
12987
12988
12989static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
12990 struct sigma_conn *conn,
12991 struct sigma_cmd *cmd)
12992{
12993 const char *val;
12994
12995 val = get_param(cmd, "ExtSchIE");
12996 if (val && !strcasecmp(val, "Enable")) {
12997 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
12998 int count = MAX_ESE_ALLOCS;
12999
13000 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
13001 return -1;
13002 return sta_set_60g_ese(dut, count, allocs);
13003 }
13004
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020013005 val = get_param(cmd, "MCS_FixedRate");
13006 if (val) {
13007 int sta_mcs = atoi(val);
13008
13009 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
13010 sta_mcs);
13011 wil6210_set_force_mcs(dut, 1, sta_mcs);
13012
Jouni Malinen0e29cf22019-02-19 01:13:21 +020013013 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020013014 }
13015
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020013016 send_resp(dut, conn, SIGMA_ERROR,
13017 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020013018 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020013019}
13020
13021
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053013022static int wcn_sta_override_oci(struct sigma_dut *dut, const char *intf,
13023 const char *oci_frametype, uint32_t oci_freq)
13024{
13025#ifdef NL80211_SUPPORT
13026 struct nl_msg *msg;
13027 int ret = 0;
13028 struct nlattr *params;
13029 struct nlattr *attr;
13030 int ifindex;
13031 u8 frame_type;
13032
13033 ifindex = if_nametoindex(intf);
13034 if (ifindex == 0) {
13035 sigma_dut_print(dut, DUT_MSG_ERROR,
13036 "%s: Index for interface %s failed",
13037 __func__, intf);
13038 return -1;
13039 }
13040
13041 if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
13042 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_REQ;
13043 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
13044 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_RESP;
13045 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
13046 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_FT_REASSOC_REQ;
13047 } else {
13048 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: Unknown frametype %s",
13049 __func__, oci_frametype);
13050 return -1;
13051 }
13052
13053
13054 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
13055 NL80211_CMD_VENDOR)) ||
13056 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
13057 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
13058 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
13059 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
13060 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
13061 !(params = nla_nest_start(
13062 msg,
13063 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OCI_OVERRIDE)) ||
13064 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FRAME_TYPE,
13065 frame_type) ||
13066 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FREQUENCY,
13067 oci_freq)) {
13068 sigma_dut_print(dut, DUT_MSG_ERROR,
13069 "%s: err in adding vendor_cmd and vendor_data",
13070 __func__);
13071 nlmsg_free(msg);
13072 return -1;
13073 }
13074 nla_nest_end(msg, params);
13075 nla_nest_end(msg, attr);
13076
13077 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
13078 if (ret) {
13079 sigma_dut_print(dut, DUT_MSG_ERROR,
13080 "%s: err in send_and_recv_msgs, ret=%d",
13081 __func__, ret);
13082 }
13083 return ret;
13084#else /* NL80211_SUPPORT */
13085 sigma_dut_print(dut, DUT_MSG_ERROR,
13086 "OCI override not possible without NL80211_SUPPORT defined");
13087 return -1;
13088#endif /* NL80211_SUPPORT */
13089}
13090
13091
Jouni Malinen6250cb02020-04-15 13:54:45 +030013092static enum sigma_cmd_result
13093cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
13094 struct sigma_conn *conn,
13095 struct sigma_cmd *cmd)
13096{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053013097 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030013098
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053013099 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030013100 if (val && atoi(val) == 1) {
13101 if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
13102 send_resp(dut, conn, SIGMA_ERROR,
13103 "errorCode,Failed to set ft_rsnxe_used");
13104 return STATUS_SENT_ERROR;
13105 }
13106 return SUCCESS_SEND_STATUS;
13107 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053013108
13109 oci_chan = get_param(cmd, "OCIChannel");
13110 oci_frametype = get_param(cmd, "OCIFrameType");
13111 if (oci_chan && oci_frametype) {
13112 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
13113 char buf[100];
13114
13115 if (!oci_freq) {
13116 send_resp(dut, conn, SIGMA_ERROR,
13117 "errorCode,Invalid OCIChannel number");
13118 return STATUS_SENT_ERROR;
13119 }
13120
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053013121 if (wifi_chip_type == DRIVER_WCN &&
13122 (strcasecmp(oci_frametype, "SAQueryReq") == 0 ||
13123 strcasecmp(oci_frametype, "SAQueryResp") == 0 ||
13124 strcasecmp(oci_frametype, "Reassocreq") == 0)) {
13125 if (wcn_sta_override_oci(dut, intf, oci_frametype,
13126 oci_freq)) {
13127 send_resp(dut, conn, SIGMA_ERROR,
13128 "errorCode,Failed to override OCI");
13129 return STATUS_SENT_ERROR;
13130 }
13131 return SUCCESS_SEND_STATUS;
13132 }
13133
Vamsi Krishnad29bc762020-05-08 23:23:30 +053013134 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
13135 snprintf(buf, sizeof(buf),
13136 "SET oci_freq_override_eapol %d", oci_freq);
13137 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
13138 snprintf(buf, sizeof(buf),
13139 "SET oci_freq_override_saquery_req %d",
13140 oci_freq);
13141 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
13142 snprintf(buf, sizeof(buf),
13143 "SET oci_freq_override_saquery_resp %d",
13144 oci_freq);
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053013145 } else if (strcasecmp(oci_frametype, "GrpKeyM2") == 0) {
13146 snprintf(buf, sizeof(buf),
13147 "SET oci_freq_override_eapol_g2 %d",
13148 oci_freq);
13149 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
13150 snprintf(buf, sizeof(buf),
13151 "SET oci_freq_override_ft_assoc %d",
13152 oci_freq);
Vamsi Krishnad29bc762020-05-08 23:23:30 +053013153 } else {
13154 send_resp(dut, conn, SIGMA_ERROR,
13155 "errorCode,Unsupported OCIFrameType");
13156 return STATUS_SENT_ERROR;
13157 }
13158 if (wpa_command(intf, buf) < 0) {
13159 send_resp(dut, conn, SIGMA_ERROR,
13160 "errorCode,Failed to set oci_freq_override");
13161 return STATUS_SENT_ERROR;
13162 }
13163 return SUCCESS_SEND_STATUS;
13164 }
13165
Jouni Malinen6250cb02020-04-15 13:54:45 +030013166 send_resp(dut, conn, SIGMA_ERROR,
13167 "errorCode,Unsupported WPA3 rfeature");
13168 return STATUS_SENT_ERROR;
13169}
13170
13171
Jouni Malinenf7222712019-06-13 01:50:21 +030013172static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
13173 struct sigma_conn *conn,
13174 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013175{
13176 const char *intf = get_param(cmd, "Interface");
13177 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053013178 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013179
13180 if (intf == NULL || prog == NULL)
13181 return -1;
13182
Ashwini Patil5acd7382017-04-13 15:55:04 +053013183 /* BSS Transition candidate list for BTM query */
13184 val = get_param(cmd, "Nebor_BSSID");
13185 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
13186 return 0;
13187
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013188 if (strcasecmp(prog, "TDLS") == 0)
13189 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
13190
13191 if (strcasecmp(prog, "VHT") == 0)
13192 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
13193
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013194 if (strcasecmp(prog, "HE") == 0)
13195 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
13196
Ashwini Patil68d02cd2017-01-10 15:39:16 +053013197 if (strcasecmp(prog, "MBO") == 0) {
13198 val = get_param(cmd, "Cellular_Data_Cap");
13199 if (val &&
13200 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
13201 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053013202
13203 val = get_param(cmd, "Ch_Pref");
13204 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
13205 return 0;
13206
Ashwini Patil68d02cd2017-01-10 15:39:16 +053013207 return 1;
13208 }
13209
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020013210 if (strcasecmp(prog, "60GHz") == 0)
13211 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
13212
Jouni Malinen6250cb02020-04-15 13:54:45 +030013213 if (strcasecmp(prog, "WPA3") == 0)
13214 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
13215
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013216 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
13217 return 0;
13218}
13219
13220
Jouni Malinenf7222712019-06-13 01:50:21 +030013221static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
13222 struct sigma_conn *conn,
13223 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013224{
13225 const char *intf = get_param(cmd, "Interface");
13226 const char *mode = get_param(cmd, "Mode");
13227 int res;
13228
13229 if (intf == NULL || mode == NULL)
13230 return -1;
13231
13232 if (strcasecmp(mode, "On") == 0)
13233 res = wpa_command(intf, "SET radio_disabled 0");
13234 else if (strcasecmp(mode, "Off") == 0)
13235 res = wpa_command(intf, "SET radio_disabled 1");
13236 else
13237 return -1;
13238
13239 if (res) {
13240 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
13241 "radio mode");
13242 return 0;
13243 }
13244
13245 return 1;
13246}
13247
13248
Jouni Malinenf7222712019-06-13 01:50:21 +030013249static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
13250 struct sigma_conn *conn,
13251 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013252{
13253 const char *intf = get_param(cmd, "Interface");
13254 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013255 const char *prog = get_param(cmd, "program");
13256 const char *powersave = get_param(cmd, "powersave");
13257 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013258
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013259 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013260 return -1;
13261
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013262 if (prog && strcasecmp(prog, "60GHz") == 0) {
13263 /*
13264 * The CAPI mode parameter does not exist in 60G
13265 * unscheduled PS.
13266 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080013267 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013268 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013269 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020013270 strcasecmp(prog, "HE") == 0) {
13271 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013272 } else {
13273 if (mode == NULL)
13274 return -1;
13275
13276 if (strcasecmp(mode, "On") == 0)
13277 res = set_ps(intf, dut, 1);
13278 else if (strcasecmp(mode, "Off") == 0)
13279 res = set_ps(intf, dut, 0);
13280 else
13281 return -1;
13282 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013283
13284 if (res) {
13285 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
13286 "power save mode");
13287 return 0;
13288 }
13289
13290 return 1;
13291}
13292
13293
Jouni Malinenf7222712019-06-13 01:50:21 +030013294static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
13295 struct sigma_conn *conn,
13296 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013297{
13298 const char *intf = get_param(cmd, "Interface");
13299 const char *val, *bssid;
13300 int res;
13301 char *buf;
13302 size_t buf_len;
13303
13304 val = get_param(cmd, "BSSID_FILTER");
13305 if (val == NULL)
13306 return -1;
13307
13308 bssid = get_param(cmd, "BSSID_List");
13309 if (atoi(val) == 0 || bssid == NULL) {
13310 /* Disable BSSID filter */
13311 if (wpa_command(intf, "SET bssid_filter ")) {
13312 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
13313 "to disable BSSID filter");
13314 return 0;
13315 }
13316
13317 return 1;
13318 }
13319
13320 buf_len = 100 + strlen(bssid);
13321 buf = malloc(buf_len);
13322 if (buf == NULL)
13323 return -1;
13324
13325 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
13326 res = wpa_command(intf, buf);
13327 free(buf);
13328 if (res) {
13329 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
13330 "BSSID filter");
13331 return 0;
13332 }
13333
13334 return 1;
13335}
13336
13337
Jouni Malinenf7222712019-06-13 01:50:21 +030013338static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
13339 struct sigma_conn *conn,
13340 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013341{
13342 const char *intf = get_param(cmd, "Interface");
13343 const char *val;
13344
13345 /* TODO: ARP */
13346
13347 val = get_param(cmd, "HS2_CACHE_PROFILE");
13348 if (val && strcasecmp(val, "All") == 0)
13349 hs2_clear_credentials(intf);
13350
13351 return 1;
13352}
13353
13354
Jouni Malinenf7222712019-06-13 01:50:21 +030013355static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
13356 struct sigma_conn *conn,
13357 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013358{
13359 const char *intf = get_param(cmd, "Interface");
13360 const char *key_type = get_param(cmd, "KeyType");
13361 char buf[100], resp[200];
13362
13363 if (key_type == NULL)
13364 return -1;
13365
13366 if (strcasecmp(key_type, "GTK") == 0) {
13367 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
13368 strncmp(buf, "FAIL", 4) == 0) {
13369 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13370 "not fetch current GTK");
13371 return 0;
13372 }
13373 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
13374 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13375 return 0;
13376 } else {
13377 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13378 "KeyType");
13379 return 0;
13380 }
13381
13382 return 1;
13383}
13384
13385
13386static int hs2_set_policy(struct sigma_dut *dut)
13387{
13388#ifdef ANDROID
13389 system("ip rule del prio 23000");
13390 if (system("ip rule add from all lookup main prio 23000") != 0) {
13391 sigma_dut_print(dut, DUT_MSG_ERROR,
13392 "Failed to run:ip rule add from all lookup main prio");
13393 return -1;
13394 }
13395 if (system("ip route flush cache") != 0) {
13396 sigma_dut_print(dut, DUT_MSG_ERROR,
13397 "Failed to run ip route flush cache");
13398 return -1;
13399 }
13400 return 1;
13401#else /* ANDROID */
13402 return 0;
13403#endif /* ANDROID */
13404}
13405
13406
Jouni Malinenf7222712019-06-13 01:50:21 +030013407static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
13408 struct sigma_conn *conn,
13409 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013410{
13411 const char *intf = get_param(cmd, "Interface");
13412 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030013413 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013414 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030013415 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013416 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
13417 int tries = 0;
13418 int ignore_blacklist = 0;
13419 const char *events[] = {
13420 "CTRL-EVENT-CONNECTED",
13421 "INTERWORKING-BLACKLISTED",
13422 "INTERWORKING-NO-MATCH",
13423 NULL
13424 };
13425
13426 start_sta_mode(dut);
13427
Jouni Malinen439352d2018-09-13 03:42:23 +030013428 if (band) {
13429 if (strcmp(band, "2.4") == 0) {
13430 wpa_command(intf, "SET setband 2G");
13431 } else if (strcmp(band, "5") == 0) {
13432 wpa_command(intf, "SET setband 5G");
13433 } else {
13434 send_resp(dut, conn, SIGMA_ERROR,
13435 "errorCode,Unsupported band");
13436 return 0;
13437 }
13438 }
13439
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013440 blacklisted[0] = '\0';
13441 if (val && atoi(val))
13442 ignore_blacklist = 1;
13443
13444try_again:
13445 ctrl = open_wpa_mon(intf);
13446 if (ctrl == NULL) {
13447 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13448 "wpa_supplicant monitor connection");
13449 return -2;
13450 }
13451
13452 tries++;
13453 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
13454 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
13455 "Interworking connection");
13456 wpa_ctrl_detach(ctrl);
13457 wpa_ctrl_close(ctrl);
13458 return 0;
13459 }
13460
13461 buf[0] = '\0';
13462 while (1) {
13463 char *pos;
13464 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13465 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
13466 if (!pos)
13467 break;
13468 pos += 25;
13469 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
13470 pos);
13471 if (!blacklisted[0])
13472 memcpy(blacklisted, pos, strlen(pos) + 1);
13473 }
13474
13475 if (ignore_blacklist && blacklisted[0]) {
13476 char *end;
13477 end = strchr(blacklisted, ' ');
13478 if (end)
13479 *end = '\0';
13480 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
13481 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030013482 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
13483 blacklisted);
13484 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013485 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
13486 wpa_ctrl_detach(ctrl);
13487 wpa_ctrl_close(ctrl);
13488 return 0;
13489 }
13490 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13491 buf, sizeof(buf));
13492 }
13493
13494 wpa_ctrl_detach(ctrl);
13495 wpa_ctrl_close(ctrl);
13496
13497 if (res < 0) {
13498 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
13499 "connect");
13500 return 0;
13501 }
13502
13503 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
13504 strstr(buf, "INTERWORKING-BLACKLISTED")) {
13505 if (tries < 2) {
13506 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
13507 goto try_again;
13508 }
13509 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
13510 "matching credentials found");
13511 return 0;
13512 }
13513
13514 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13515 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13516 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
13517 "get current BSSID/SSID");
13518 return 0;
13519 }
13520
13521 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
13522 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13523 hs2_set_policy(dut);
13524 return 0;
13525}
13526
13527
Jouni Malinenf7222712019-06-13 01:50:21 +030013528static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
13529 struct sigma_conn *conn,
13530 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013531{
13532 const char *intf = get_param(cmd, "Interface");
13533 const char *display = get_param(cmd, "Display");
13534 struct wpa_ctrl *ctrl;
13535 char buf[300], params[400], *pos;
13536 char bssid[20];
13537 int info_avail = 0;
13538 unsigned int old_timeout;
13539 int res;
13540
13541 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
13542 send_resp(dut, conn, SIGMA_ERROR,
13543 "ErrorCode,Could not get current BSSID");
13544 return 0;
13545 }
13546 ctrl = open_wpa_mon(intf);
13547 if (!ctrl) {
13548 sigma_dut_print(dut, DUT_MSG_ERROR,
13549 "Failed to open wpa_supplicant monitor connection");
13550 return -2;
13551 }
13552
13553 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
13554 wpa_command(intf, buf);
13555
13556 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
13557 if (res < 0) {
13558 send_resp(dut, conn, SIGMA_ERROR,
13559 "ErrorCode,Could not complete GAS query");
13560 goto fail;
13561 }
13562
13563 old_timeout = dut->default_timeout;
13564 dut->default_timeout = 2;
13565 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
13566 dut->default_timeout = old_timeout;
13567 if (res < 0)
13568 goto done;
13569 pos = strchr(buf, ' ');
13570 if (!pos)
13571 goto done;
13572 pos++;
13573 pos = strchr(pos, ' ');
13574 if (!pos)
13575 goto done;
13576 pos++;
13577 info_avail = 1;
13578 snprintf(params, sizeof(params), "browser %s", pos);
13579
13580 if (display && strcasecmp(display, "Yes") == 0) {
13581 pid_t pid;
13582
13583 pid = fork();
13584 if (pid < 0) {
13585 perror("fork");
13586 return -1;
13587 }
13588
13589 if (pid == 0) {
13590 run_hs20_osu(dut, params);
13591 exit(0);
13592 }
13593 }
13594
13595done:
13596 snprintf(buf, sizeof(buf), "Info_available,%s",
13597 info_avail ? "Yes" : "No");
13598 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13599fail:
13600 wpa_ctrl_detach(ctrl);
13601 wpa_ctrl_close(ctrl);
13602 return 0;
13603}
13604
13605
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013606static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
13607 struct sigma_conn *conn,
13608 const char *ifname,
13609 struct sigma_cmd *cmd)
13610{
13611 const char *val;
13612 int id;
13613
13614 id = add_cred(ifname);
13615 if (id < 0)
13616 return -2;
13617 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13618
13619 val = get_param(cmd, "prefer");
13620 if (val && atoi(val) > 0)
13621 set_cred(ifname, id, "priority", "1");
13622
13623 val = get_param(cmd, "REALM");
13624 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13625 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13626 "realm");
13627 return 0;
13628 }
13629
13630 val = get_param(cmd, "HOME_FQDN");
13631 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13632 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13633 "home_fqdn");
13634 return 0;
13635 }
13636
13637 val = get_param(cmd, "Username");
13638 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13639 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13640 "username");
13641 return 0;
13642 }
13643
13644 val = get_param(cmd, "Password");
13645 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
13646 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13647 "password");
13648 return 0;
13649 }
13650
13651 val = get_param(cmd, "ROOT_CA");
13652 if (val) {
13653 char fname[200];
13654 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13655#ifdef __linux__
13656 if (!file_exists(fname)) {
13657 char msg[300];
13658 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13659 "file (%s) not found", fname);
13660 send_resp(dut, conn, SIGMA_ERROR, msg);
13661 return 0;
13662 }
13663#endif /* __linux__ */
13664 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13665 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13666 "not set root CA");
13667 return 0;
13668 }
13669 }
13670
13671 return 1;
13672}
13673
13674
13675static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
13676{
13677 FILE *in, *out;
13678 char buf[500];
13679 int found = 0;
13680
13681 in = fopen("devdetail.xml", "r");
13682 if (in == NULL)
13683 return -1;
13684 out = fopen("devdetail.xml.tmp", "w");
13685 if (out == NULL) {
13686 fclose(in);
13687 return -1;
13688 }
13689
13690 while (fgets(buf, sizeof(buf), in)) {
13691 char *pos = strstr(buf, "<IMSI>");
13692 if (pos) {
13693 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
13694 imsi);
13695 pos += 6;
13696 *pos = '\0';
13697 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
13698 found++;
13699 } else {
13700 fprintf(out, "%s", buf);
13701 }
13702 }
13703
13704 fclose(out);
13705 fclose(in);
13706 if (found)
13707 rename("devdetail.xml.tmp", "devdetail.xml");
13708 else
13709 unlink("devdetail.xml.tmp");
13710
13711 return 0;
13712}
13713
13714
13715static int sta_add_credential_sim(struct sigma_dut *dut,
13716 struct sigma_conn *conn,
13717 const char *ifname, struct sigma_cmd *cmd)
13718{
13719 const char *val, *imsi = NULL;
13720 int id;
13721 char buf[200];
13722 int res;
13723 const char *pos;
13724 size_t mnc_len;
13725 char plmn_mcc[4];
13726 char plmn_mnc[4];
13727
13728 id = add_cred(ifname);
13729 if (id < 0)
13730 return -2;
13731 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13732
13733 val = get_param(cmd, "prefer");
13734 if (val && atoi(val) > 0)
13735 set_cred(ifname, id, "priority", "1");
13736
13737 val = get_param(cmd, "PLMN_MCC");
13738 if (val == NULL) {
13739 send_resp(dut, conn, SIGMA_ERROR,
13740 "errorCode,Missing PLMN_MCC");
13741 return 0;
13742 }
13743 if (strlen(val) != 3) {
13744 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
13745 return 0;
13746 }
13747 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
13748
13749 val = get_param(cmd, "PLMN_MNC");
13750 if (val == NULL) {
13751 send_resp(dut, conn, SIGMA_ERROR,
13752 "errorCode,Missing PLMN_MNC");
13753 return 0;
13754 }
13755 if (strlen(val) != 2 && strlen(val) != 3) {
13756 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
13757 return 0;
13758 }
13759 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
13760
13761 val = get_param(cmd, "IMSI");
13762 if (val == NULL) {
13763 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
13764 "IMSI");
13765 return 0;
13766 }
13767
13768 imsi = pos = val;
13769
13770 if (strncmp(plmn_mcc, pos, 3) != 0) {
13771 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
13772 return 0;
13773 }
13774 pos += 3;
13775
13776 mnc_len = strlen(plmn_mnc);
13777 if (mnc_len < 2) {
13778 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
13779 return 0;
13780 }
13781
13782 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
13783 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
13784 return 0;
13785 }
13786 pos += mnc_len;
13787
13788 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
13789 if (res < 0 || res >= (int) sizeof(buf))
13790 return -1;
13791 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
13792 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13793 "not set IMSI");
13794 return 0;
13795 }
13796
13797 val = get_param(cmd, "Password");
13798 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
13799 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13800 "not set password");
13801 return 0;
13802 }
13803
Jouni Malinenba630452018-06-22 11:49:59 +030013804 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013805 /*
13806 * Set provisioning_sp for the test cases where SIM/USIM
13807 * provisioning is used.
13808 */
13809 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
13810 "wi-fi.org") < 0) {
13811 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13812 "not set provisioning_sp");
13813 return 0;
13814 }
13815
13816 update_devdetail_imsi(dut, imsi);
13817 }
13818
13819 return 1;
13820}
13821
13822
13823static int sta_add_credential_cert(struct sigma_dut *dut,
13824 struct sigma_conn *conn,
13825 const char *ifname,
13826 struct sigma_cmd *cmd)
13827{
13828 const char *val;
13829 int id;
13830
13831 id = add_cred(ifname);
13832 if (id < 0)
13833 return -2;
13834 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13835
13836 val = get_param(cmd, "prefer");
13837 if (val && atoi(val) > 0)
13838 set_cred(ifname, id, "priority", "1");
13839
13840 val = get_param(cmd, "REALM");
13841 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13842 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13843 "realm");
13844 return 0;
13845 }
13846
13847 val = get_param(cmd, "HOME_FQDN");
13848 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13849 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13850 "home_fqdn");
13851 return 0;
13852 }
13853
13854 val = get_param(cmd, "Username");
13855 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13856 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13857 "username");
13858 return 0;
13859 }
13860
13861 val = get_param(cmd, "clientCertificate");
13862 if (val) {
13863 char fname[200];
13864 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13865#ifdef __linux__
13866 if (!file_exists(fname)) {
13867 char msg[300];
13868 snprintf(msg, sizeof(msg),
13869 "ErrorCode,clientCertificate "
13870 "file (%s) not found", fname);
13871 send_resp(dut, conn, SIGMA_ERROR, msg);
13872 return 0;
13873 }
13874#endif /* __linux__ */
13875 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
13876 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13877 "not set client_cert");
13878 return 0;
13879 }
13880 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
13881 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13882 "not set private_key");
13883 return 0;
13884 }
13885 }
13886
13887 val = get_param(cmd, "ROOT_CA");
13888 if (val) {
13889 char fname[200];
13890 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13891#ifdef __linux__
13892 if (!file_exists(fname)) {
13893 char msg[300];
13894 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13895 "file (%s) not found", fname);
13896 send_resp(dut, conn, SIGMA_ERROR, msg);
13897 return 0;
13898 }
13899#endif /* __linux__ */
13900 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13901 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13902 "not set root CA");
13903 return 0;
13904 }
13905 }
13906
13907 return 1;
13908}
13909
13910
Jouni Malinenf7222712019-06-13 01:50:21 +030013911static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
13912 struct sigma_conn *conn,
13913 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013914{
13915 const char *intf = get_param(cmd, "Interface");
13916 const char *type;
13917
13918 start_sta_mode(dut);
13919
13920 type = get_param(cmd, "Type");
13921 if (!type)
13922 return -1;
13923
13924 if (strcasecmp(type, "uname_pwd") == 0)
13925 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
13926
13927 if (strcasecmp(type, "sim") == 0)
13928 return sta_add_credential_sim(dut, conn, intf, cmd);
13929
13930 if (strcasecmp(type, "cert") == 0)
13931 return sta_add_credential_cert(dut, conn, intf, cmd);
13932
13933 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
13934 "type");
13935 return 0;
13936}
13937
13938
Jouni Malinenf7222712019-06-13 01:50:21 +030013939static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
13940 struct sigma_conn *conn,
13941 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013942{
13943 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013944 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Veerendranathdc581b52020-08-10 03:29:08 -070013945 char buf[4096], scan_res[20];
vamsi krishna89ad8c62017-09-19 12:51:18 +053013946 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013947 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013948 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013949 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013950 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013951
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020013952 start_sta_mode(dut);
13953
Arif Hussain66a4af02019-02-07 15:04:51 -080013954 val = get_param(cmd, "GetParameter");
13955 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013956 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080013957 buf, sizeof(buf)) < 0) {
13958 sigma_dut_print(dut, DUT_MSG_ERROR,
13959 "Could not get ssid bssid");
13960 return ERROR_SEND_STATUS;
13961 }
13962
13963 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
13964 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13965 return STATUS_SENT;
13966 }
13967
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013968 val = get_param(cmd, "HESSID");
13969 if (val) {
13970 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
13971 if (res < 0 || res >= (int) sizeof(buf))
13972 return -1;
13973 wpa_command(intf, buf);
13974 }
13975
13976 val = get_param(cmd, "ACCS_NET_TYPE");
13977 if (val) {
13978 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
13979 val);
13980 if (res < 0 || res >= (int) sizeof(buf))
13981 return -1;
13982 wpa_command(intf, buf);
13983 }
13984
vamsi krishna89ad8c62017-09-19 12:51:18 +053013985 bssid = get_param(cmd, "Bssid");
13986 ssid = get_param(cmd, "Ssid");
13987
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013988 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
13989 dut->device_type == STA_testbed) {
13990 ssid = NULL;
13991 wildcard_ssid = 1;
13992 }
13993
vamsi krishna89ad8c62017-09-19 12:51:18 +053013994 if (ssid) {
13995 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
13996 send_resp(dut, conn, SIGMA_ERROR,
13997 "ErrorCode,Too long SSID");
13998 return 0;
13999 }
14000 ascii2hexstr(ssid, ssid_hex);
14001 }
14002
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014003 short_ssid = get_param(cmd, "ShortSSID");
14004 if (short_ssid) {
14005 uint32_t short_ssid_hex;
14006
14007 short_ssid_hex = strtoul(short_ssid, NULL, 16);
14008 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
14009 (((short_ssid_hex >> 8) & 0xFF) << 16) |
14010 (((short_ssid_hex >> 16) & 0xFF) << 8) |
14011 ((short_ssid_hex >> 24) & 0xFF);
14012
14013 res = snprintf(buf, sizeof(buf),
14014 "VENDOR_ELEM_ADD 14 ff053a%08x",
14015 short_ssid_hex);
14016 if (res < 0 || res >= (int) sizeof(buf) ||
14017 wpa_command(intf, buf)) {
14018 send_resp(dut, conn, SIGMA_ERROR,
14019 "errorCode,Failed to add short SSID");
14020 return STATUS_SENT_ERROR;
14021 }
14022 }
14023
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080014024 scan_freq = get_param(cmd, "ChnlFreq");
Veerendranath Jakkam132c4b42020-08-10 00:29:03 +053014025 if (scan_freq) {
14026 if (strcasecmp(scan_freq, "2G") == 0)
14027 scan_freq = "2412-2462";
14028 else if (strcasecmp(scan_freq, "5G") == 0)
14029 scan_freq = "5180-5925";
14030 }
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080014031
Jouni Malinen228a2fc2020-06-22 23:37:45 +030014032 val = get_param(cmd, "WaitCompletion");
14033 if (val && atoi(val) == 1) {
14034 ctrl = open_wpa_mon(intf);
14035 if (!ctrl) {
14036 send_resp(dut, conn, SIGMA_ERROR,
14037 "errorCode,Failed to open monitor socket");
14038 return STATUS_SENT_ERROR;
14039 }
14040 }
14041
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080014042 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053014043 bssid ? " bssid=": "",
14044 bssid ? bssid : "",
14045 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080014046 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080014047 wildcard_ssid ? " wildcard_ssid=1" : "",
14048 scan_freq ? " freq=" : "",
14049 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014050 if (res < 0 || res >= (int) sizeof(buf)) {
14051 send_resp(dut, conn, SIGMA_ERROR,
14052 "errorCode,Could not build scan command");
14053 status = STATUS_SENT_ERROR;
14054 goto remove_s_ssid;
14055 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053014056
Veerendranathdc581b52020-08-10 03:29:08 -070014057 res = wpa_command_resp(intf, buf, scan_res, sizeof(scan_res));
14058 if (strncmp(scan_res, "FAIL-BUSY", 9) == 0) {
14059 sigma_dut_print(dut, DUT_MSG_DEBUG,
14060 "Scan request rejected with busy status, abort ongoing scan and try again");
14061 wpa_command(intf, "ABORT_SCAN");
14062 res = wpa_command(intf, buf);
14063 }
14064
14065 if (res < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014066 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
14067 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014068 status = STATUS_SENT_ERROR;
14069 } else {
14070 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014071 }
14072
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014073remove_s_ssid:
14074 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
14075 sigma_dut_print(dut, DUT_MSG_ERROR,
14076 "Failed to delete vendor element");
14077
Jouni Malinen228a2fc2020-06-22 23:37:45 +030014078 if (ctrl) {
14079 if (status == SUCCESS_SEND_STATUS) {
14080 res = get_wpa_cli_event(dut, ctrl,
14081 "CTRL-EVENT-SCAN-RESULTS",
14082 buf, sizeof(buf));
14083 if (res < 0) {
14084 send_resp(dut, conn, SIGMA_ERROR,
14085 "ErrorCode,scan did not complete");
14086 status = STATUS_SENT_ERROR;
14087 }
14088 }
14089
14090 wpa_ctrl_detach(ctrl);
14091 wpa_ctrl_close(ctrl);
14092 }
14093
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014094 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014095}
14096
14097
Jouni Malinenf7222712019-06-13 01:50:21 +030014098static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
14099 struct sigma_conn *conn,
14100 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020014101{
14102 const char *intf = get_param(cmd, "Interface");
14103 const char *bssid;
14104 char buf[4096], *pos;
14105 int freq, chan;
14106 char *ssid;
14107 char resp[100];
14108 int res;
14109 struct wpa_ctrl *ctrl;
14110
14111 bssid = get_param(cmd, "BSSID");
14112 if (!bssid) {
14113 send_resp(dut, conn, SIGMA_INVALID,
14114 "errorCode,BSSID argument is missing");
14115 return 0;
14116 }
14117
14118 ctrl = open_wpa_mon(intf);
14119 if (!ctrl) {
14120 sigma_dut_print(dut, DUT_MSG_ERROR,
14121 "Failed to open wpa_supplicant monitor connection");
14122 return -1;
14123 }
14124
14125 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
14126 send_resp(dut, conn, SIGMA_ERROR,
14127 "errorCode,Could not start scan");
14128 wpa_ctrl_detach(ctrl);
14129 wpa_ctrl_close(ctrl);
14130 return 0;
14131 }
14132
14133 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
14134 buf, sizeof(buf));
14135
14136 wpa_ctrl_detach(ctrl);
14137 wpa_ctrl_close(ctrl);
14138
14139 if (res < 0) {
14140 send_resp(dut, conn, SIGMA_ERROR,
14141 "errorCode,Scan did not complete");
14142 return 0;
14143 }
14144
14145 snprintf(buf, sizeof(buf), "BSS %s", bssid);
14146 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
14147 strncmp(buf, "id=", 3) != 0) {
14148 send_resp(dut, conn, SIGMA_ERROR,
14149 "errorCode,Specified BSSID not found");
14150 return 0;
14151 }
14152
14153 pos = strstr(buf, "\nfreq=");
14154 if (!pos) {
14155 send_resp(dut, conn, SIGMA_ERROR,
14156 "errorCode,Channel not found");
14157 return 0;
14158 }
14159 freq = atoi(pos + 6);
14160 chan = freq_to_channel(freq);
14161
14162 pos = strstr(buf, "\nssid=");
14163 if (!pos) {
14164 send_resp(dut, conn, SIGMA_ERROR,
14165 "errorCode,SSID not found");
14166 return 0;
14167 }
14168 ssid = pos + 6;
14169 pos = strchr(ssid, '\n');
14170 if (pos)
14171 *pos = '\0';
14172 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
14173 send_resp(dut, conn, SIGMA_COMPLETE, resp);
14174 return 0;
14175}
14176
14177
Jouni Malinenf7222712019-06-13 01:50:21 +030014178static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
14179 struct sigma_conn *conn,
14180 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014181{
14182#ifdef __linux__
14183 struct timeval tv;
14184 struct tm tm;
14185 time_t t;
14186 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053014187 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014188
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014189 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014190
14191 memset(&tm, 0, sizeof(tm));
14192 val = get_param(cmd, "seconds");
14193 if (val)
14194 tm.tm_sec = atoi(val);
14195 val = get_param(cmd, "minutes");
14196 if (val)
14197 tm.tm_min = atoi(val);
14198 val = get_param(cmd, "hours");
14199 if (val)
14200 tm.tm_hour = atoi(val);
14201 val = get_param(cmd, "date");
14202 if (val)
14203 tm.tm_mday = atoi(val);
14204 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053014205 if (val) {
14206 v = atoi(val);
14207 if (v < 1 || v > 12) {
14208 send_resp(dut, conn, SIGMA_INVALID,
14209 "errorCode,Invalid month");
14210 return 0;
14211 }
14212 tm.tm_mon = v - 1;
14213 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014214 val = get_param(cmd, "year");
14215 if (val) {
14216 int year = atoi(val);
14217#ifdef ANDROID
14218 if (year > 2035)
14219 year = 2035; /* years beyond 2035 not supported */
14220#endif /* ANDROID */
14221 tm.tm_year = year - 1900;
14222 }
14223 t = mktime(&tm);
14224 if (t == (time_t) -1) {
14225 send_resp(dut, conn, SIGMA_ERROR,
14226 "errorCode,Invalid date or time");
14227 return 0;
14228 }
14229
14230 memset(&tv, 0, sizeof(tv));
14231 tv.tv_sec = t;
14232
14233 if (settimeofday(&tv, NULL) < 0) {
14234 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
14235 strerror(errno));
14236 send_resp(dut, conn, SIGMA_ERROR,
14237 "errorCode,Failed to set time");
14238 return 0;
14239 }
14240
14241 return 1;
14242#endif /* __linux__ */
14243
14244 return -1;
14245}
14246
14247
Jouni Malinenf7222712019-06-13 01:50:21 +030014248static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
14249 struct sigma_conn *conn,
14250 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014251{
14252 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014253 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014254 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014255 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014256 int res;
14257 struct wpa_ctrl *ctrl;
14258
14259 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014260 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014261
14262 val = get_param(cmd, "ProdESSAssoc");
14263 if (val)
14264 prod_ess_assoc = atoi(val);
14265
14266 kill_dhcp_client(dut, intf);
14267 if (start_dhcp_client(dut, intf) < 0)
14268 return -2;
14269
14270 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
14271 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
14272 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014273 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014274 prod_ess_assoc ? "" : "-N",
14275 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014276 name ? "'" : "",
14277 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
14278 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014279
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053014280 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014281 if (run_hs20_osu(dut, buf) < 0) {
14282 FILE *f;
14283
14284 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
14285
14286 f = fopen("hs20-osu-client.res", "r");
14287 if (f) {
14288 char resp[400], res[300], *pos;
14289 if (!fgets(res, sizeof(res), f))
14290 res[0] = '\0';
14291 pos = strchr(res, '\n');
14292 if (pos)
14293 *pos = '\0';
14294 fclose(f);
14295 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
14296 res);
14297 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
14298 if (system(resp) != 0) {
14299 }
14300 snprintf(resp, sizeof(resp),
14301 "SSID,,BSSID,,failureReason,%s", res);
14302 send_resp(dut, conn, SIGMA_COMPLETE, resp);
14303 return 0;
14304 }
14305
14306 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
14307 return 0;
14308 }
14309
14310 if (!prod_ess_assoc)
14311 goto report;
14312
14313 ctrl = open_wpa_mon(intf);
14314 if (ctrl == NULL) {
14315 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14316 "wpa_supplicant monitor connection");
14317 return -1;
14318 }
14319
14320 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
14321 buf, sizeof(buf));
14322
14323 wpa_ctrl_detach(ctrl);
14324 wpa_ctrl_close(ctrl);
14325
14326 if (res < 0) {
14327 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
14328 "network after OSU");
14329 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
14330 return 0;
14331 }
14332
14333report:
14334 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
14335 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
14336 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
14337 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
14338 return 0;
14339 }
14340
14341 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
14342 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014343 return 0;
14344}
14345
14346
Jouni Malinenf7222712019-06-13 01:50:21 +030014347static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
14348 struct sigma_conn *conn,
14349 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014350{
14351 const char *val;
14352 int timeout = 120;
14353
14354 val = get_param(cmd, "PolicyUpdate");
14355 if (val == NULL || atoi(val) == 0)
14356 return 1; /* No operation requested */
14357
14358 val = get_param(cmd, "Timeout");
14359 if (val)
14360 timeout = atoi(val);
14361
14362 if (timeout) {
14363 /* TODO: time out the command and return
14364 * PolicyUpdateStatus,TIMEOUT if needed. */
14365 }
14366
14367 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
14368 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
14369 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
14370 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
14371 return 0;
14372 }
14373
14374 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
14375 return 0;
14376}
14377
14378
Jouni Malinenf7222712019-06-13 01:50:21 +030014379static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
14380 struct sigma_conn *conn,
14381 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014382{
14383 struct wpa_ctrl *ctrl;
14384 const char *intf = get_param(cmd, "Interface");
14385 const char *bssid = get_param(cmd, "Bssid");
14386 const char *ssid = get_param(cmd, "SSID");
14387 const char *security = get_param(cmd, "Security");
14388 const char *passphrase = get_param(cmd, "Passphrase");
14389 const char *pin = get_param(cmd, "PIN");
14390 char buf[1000];
14391 char ssid_hex[200], passphrase_hex[200];
14392 const char *keymgmt, *cipher;
14393
14394 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014395 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014396
14397 if (!bssid) {
14398 send_resp(dut, conn, SIGMA_ERROR,
14399 "ErrorCode,Missing Bssid argument");
14400 return 0;
14401 }
14402
14403 if (!ssid) {
14404 send_resp(dut, conn, SIGMA_ERROR,
14405 "ErrorCode,Missing SSID argument");
14406 return 0;
14407 }
14408
14409 if (!security) {
14410 send_resp(dut, conn, SIGMA_ERROR,
14411 "ErrorCode,Missing Security argument");
14412 return 0;
14413 }
14414
14415 if (!passphrase) {
14416 send_resp(dut, conn, SIGMA_ERROR,
14417 "ErrorCode,Missing Passphrase argument");
14418 return 0;
14419 }
14420
14421 if (!pin) {
14422 send_resp(dut, conn, SIGMA_ERROR,
14423 "ErrorCode,Missing PIN argument");
14424 return 0;
14425 }
14426
vamsi krishna8c9c1562017-05-12 15:51:46 +053014427 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
14428 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014429 send_resp(dut, conn, SIGMA_ERROR,
14430 "ErrorCode,Too long SSID/passphrase");
14431 return 0;
14432 }
14433
14434 ctrl = open_wpa_mon(intf);
14435 if (ctrl == NULL) {
14436 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14437 "wpa_supplicant monitor connection");
14438 return -2;
14439 }
14440
14441 if (strcasecmp(security, "wpa2-psk") == 0) {
14442 keymgmt = "WPA2PSK";
14443 cipher = "CCMP";
14444 } else {
14445 wpa_ctrl_detach(ctrl);
14446 wpa_ctrl_close(ctrl);
14447 send_resp(dut, conn, SIGMA_ERROR,
14448 "ErrorCode,Unsupported Security value");
14449 return 0;
14450 }
14451
14452 ascii2hexstr(ssid, ssid_hex);
14453 ascii2hexstr(passphrase, passphrase_hex);
14454 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
14455 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
14456
14457 if (wpa_command(intf, buf) < 0) {
14458 wpa_ctrl_detach(ctrl);
14459 wpa_ctrl_close(ctrl);
14460 send_resp(dut, conn, SIGMA_ERROR,
14461 "ErrorCode,Failed to start registrar");
14462 return 0;
14463 }
14464
14465 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
14466 dut->er_oper_performed = 1;
14467
14468 return wps_connection_event(dut, conn, ctrl, intf, 0);
14469}
14470
14471
Jouni Malinenf7222712019-06-13 01:50:21 +030014472static enum sigma_cmd_result
14473cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
14474 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014475{
14476 struct wpa_ctrl *ctrl;
14477 const char *intf = get_param(cmd, "Interface");
14478 const char *bssid = get_param(cmd, "Bssid");
14479 char buf[100];
14480
14481 if (!bssid) {
14482 send_resp(dut, conn, SIGMA_ERROR,
14483 "ErrorCode,Missing Bssid argument");
14484 return 0;
14485 }
14486
14487 ctrl = open_wpa_mon(intf);
14488 if (ctrl == NULL) {
14489 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14490 "wpa_supplicant monitor connection");
14491 return -2;
14492 }
14493
14494 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
14495
14496 if (wpa_command(intf, buf) < 0) {
14497 wpa_ctrl_detach(ctrl);
14498 wpa_ctrl_close(ctrl);
14499 send_resp(dut, conn, SIGMA_ERROR,
14500 "ErrorCode,Failed to start registrar");
14501 return 0;
14502 }
14503
14504 return wps_connection_event(dut, conn, ctrl, intf, 0);
14505}
14506
14507
Jouni Malinenf7222712019-06-13 01:50:21 +030014508static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
14509 struct sigma_conn *conn,
14510 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053014511{
14512 struct wpa_ctrl *ctrl;
14513 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014514 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014515 const char *config_method = get_param(cmd, "WPSConfigMethod");
14516 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053014517 int res;
14518 char buf[256];
14519 const char *events[] = {
14520 "CTRL-EVENT-CONNECTED",
14521 "WPS-OVERLAP-DETECTED",
14522 "WPS-TIMEOUT",
14523 "WPS-FAIL",
14524 NULL
14525 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014526 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053014527
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014528 /* 60G WPS tests do not pass Interface parameter */
14529 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014530 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014531
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014532 if (dut->mode == SIGMA_MODE_AP)
14533 return ap_wps_registration(dut, conn, cmd);
14534
14535 if (config_method) {
14536 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
14537 * sta_wps_enter_pin before calling start_wps_registration. */
14538 if (strcasecmp(config_method, "PBC") == 0)
14539 dut->wps_method = WFA_CS_WPS_PBC;
14540 }
14541 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
14542 send_resp(dut, conn, SIGMA_ERROR,
14543 "ErrorCode,WPS parameters not yet set");
14544 return STATUS_SENT;
14545 }
14546
14547 /* Make sure WPS is enabled (also for STA mode) */
14548 dut->wps_disable = 0;
14549
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014550 if (dut->band == WPS_BAND_60G && network_mode &&
14551 strcasecmp(network_mode, "PBSS") == 0) {
14552 sigma_dut_print(dut, DUT_MSG_DEBUG,
14553 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014554 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014555 return -2;
14556 }
14557
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020014558 if (dut->force_rsn_ie) {
14559 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
14560 dut->force_rsn_ie);
14561 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
14562 sigma_dut_print(dut, DUT_MSG_INFO,
14563 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014564 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020014565 }
14566 }
14567
vamsi krishna9b144002017-09-20 13:28:13 +053014568 ctrl = open_wpa_mon(intf);
14569 if (!ctrl) {
14570 sigma_dut_print(dut, DUT_MSG_ERROR,
14571 "Failed to open wpa_supplicant monitor connection");
14572 return -2;
14573 }
14574
14575 role = get_param(cmd, "WpsRole");
14576 if (!role) {
14577 send_resp(dut, conn, SIGMA_INVALID,
14578 "ErrorCode,WpsRole not provided");
14579 goto fail;
14580 }
14581
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014582 if (strcasecmp(role, "Enrollee") != 0) {
14583 /* Registrar role for STA not supported */
14584 send_resp(dut, conn, SIGMA_ERROR,
14585 "ErrorCode,Unsupported WpsRole value");
14586 goto fail;
14587 }
14588
14589 if (is_60g_sigma_dut(dut)) {
14590 if (dut->wps_method == WFA_CS_WPS_PBC)
14591 snprintf(buf, sizeof(buf), "WPS_PBC");
14592 else /* WFA_CS_WPS_PIN_KEYPAD */
14593 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
14594 dut->wps_pin);
14595 if (wpa_command(intf, buf) < 0) {
14596 send_resp(dut, conn, SIGMA_ERROR,
14597 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053014598 goto fail;
14599 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014600 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
14601 if (res < 0) {
14602 send_resp(dut, conn, SIGMA_ERROR,
14603 "ErrorCode,WPS connection did not complete");
14604 goto fail;
14605 }
14606 if (strstr(buf, "WPS-TIMEOUT")) {
14607 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
14608 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
14609 send_resp(dut, conn, SIGMA_COMPLETE,
14610 "WpsState,OverlapSession");
14611 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
14612 send_resp(dut, conn, SIGMA_COMPLETE,
14613 "WpsState,Successful");
14614 } else {
14615 send_resp(dut, conn, SIGMA_COMPLETE,
14616 "WpsState,Failure");
14617 }
14618 } else {
14619 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053014620 if (wpa_command(intf, "WPS_PBC") < 0) {
14621 send_resp(dut, conn, SIGMA_ERROR,
14622 "ErrorCode,Failed to enable PBC");
14623 goto fail;
14624 }
14625 } else {
14626 /* TODO: PIN method */
14627 send_resp(dut, conn, SIGMA_ERROR,
14628 "ErrorCode,Unsupported WpsConfigMethod value");
14629 goto fail;
14630 }
14631 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
14632 if (res < 0) {
14633 send_resp(dut, conn, SIGMA_ERROR,
14634 "ErrorCode,WPS connection did not complete");
14635 goto fail;
14636 }
14637 if (strstr(buf, "WPS-TIMEOUT")) {
14638 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
14639 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
14640 send_resp(dut, conn, SIGMA_ERROR,
14641 "ErrorCode,OverlapSession");
14642 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
14643 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
14644 } else {
14645 send_resp(dut, conn, SIGMA_ERROR,
14646 "ErrorCode,WPS operation failed");
14647 }
vamsi krishna9b144002017-09-20 13:28:13 +053014648 }
14649
14650fail:
14651 wpa_ctrl_detach(ctrl);
14652 wpa_ctrl_close(ctrl);
14653 return 0;
14654}
14655
14656
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014657static int req_intf(struct sigma_cmd *cmd)
14658{
14659 return get_param(cmd, "interface") == NULL ? -1 : 0;
14660}
14661
14662
14663void sta_register_cmds(void)
14664{
14665 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
14666 cmd_sta_get_ip_config);
14667 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
14668 cmd_sta_set_ip_config);
14669 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
14670 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
14671 cmd_sta_get_mac_address);
14672 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
14673 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
14674 cmd_sta_verify_ip_connection);
14675 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
14676 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
14677 cmd_sta_set_encryption);
14678 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
14679 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
14680 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
14681 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
14682 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
14683 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
14684 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
14685 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
14686 cmd_sta_set_eapakaprime);
14687 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
14688 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
14689 /* TODO: sta_set_ibss */
14690 /* TODO: sta_set_mode */
14691 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
14692 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
14693 /* TODO: sta_up_load */
14694 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
14695 cmd_sta_preset_testparameters);
14696 /* TODO: sta_set_system */
14697 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
14698 /* TODO: sta_set_rifs_test */
14699 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
14700 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
14701 /* TODO: sta_send_coexist_mgmt */
14702 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
14703 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
14704 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
14705 sigma_dut_reg_cmd("sta_reset_default", req_intf,
14706 cmd_sta_reset_default);
14707 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
14708 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
14709 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
14710 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
14711 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014712 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014713 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
14714 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
14715 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
14716 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
14717 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030014718 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
14719 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014720 sigma_dut_reg_cmd("sta_add_credential", req_intf,
14721 cmd_sta_add_credential);
14722 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020014723 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014724 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
14725 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
14726 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
14727 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
14728 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
14729 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030014730 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014731 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
14732 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014733 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053014734 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014735}