blob: 5d489d3ce2eea16d18b45d2d86f5c1fdb2ce961c [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
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002309 if (dut->program == PROGRAM_60GHZ && network_mode &&
2310 strcasecmp(network_mode, "PBSS") == 0 &&
2311 set_network(ifname, id, "pbss", "1") < 0)
2312 return -2;
2313
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002314 return 1;
2315}
2316
2317
Jouni Malinen8ac93452019-08-14 15:19:13 +03002318static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2319 struct sigma_conn *conn,
2320 const char *ifname, int id)
2321{
2322 char buf[200];
2323
2324 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2325 if (!file_exists(buf))
2326 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2327 if (!file_exists(buf))
2328 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2329 if (!file_exists(buf)) {
2330 char msg[300];
2331
2332 snprintf(msg, sizeof(msg),
2333 "ErrorCode,trustedRootCA system store (%s) not found",
2334 buf);
2335 send_resp(dut, conn, SIGMA_ERROR, msg);
2336 return STATUS_SENT_ERROR;
2337 }
2338
2339 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2340 return ERROR_SEND_STATUS;
2341
2342 return SUCCESS_SEND_STATUS;
2343}
2344
2345
2346static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2347 struct sigma_conn *conn,
2348 const char *ifname, int id,
2349 const char *val)
2350{
2351 char buf[200];
2352#ifdef ANDROID
2353 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2354 int length;
2355#endif /* ANDROID */
2356
2357 if (strcmp(val, "DEFAULT") == 0)
2358 return set_trust_root_system(dut, conn, ifname, id);
2359
2360#ifdef ANDROID
2361 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2362 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2363 if (length > 0) {
2364 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2365 buf);
2366 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2367 goto ca_cert_selected;
2368 }
2369#endif /* ANDROID */
2370
2371 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2372#ifdef __linux__
2373 if (!file_exists(buf)) {
2374 char msg[300];
2375
2376 snprintf(msg, sizeof(msg),
2377 "ErrorCode,trustedRootCA file (%s) not found", buf);
2378 send_resp(dut, conn, SIGMA_ERROR, msg);
2379 return STATUS_SENT_ERROR;
2380 }
2381#endif /* __linux__ */
2382#ifdef ANDROID
2383ca_cert_selected:
2384#endif /* ANDROID */
2385 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2386 return ERROR_SEND_STATUS;
2387
2388 return SUCCESS_SEND_STATUS;
2389}
2390
2391
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002392static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302393 const char *ifname, int username_identity,
2394 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002395{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002396 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002397 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002398 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002399 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002400 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002401
2402 id = set_wpa_common(dut, conn, ifname, cmd);
2403 if (id < 0)
2404 return id;
2405
2406 val = get_param(cmd, "keyMgmtType");
2407 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302408 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002409 trust_root = get_param(cmd, "trustedRootCA");
2410 domain = get_param(cmd, "Domain");
2411 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002412
Jouni Malinenad395a22017-09-01 21:13:46 +03002413 if (val && strcasecmp(val, "SuiteB") == 0) {
2414 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2415 0)
2416 return -2;
2417 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002418 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2419 return -2;
2420 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2421 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2422 return -2;
2423 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2424 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2425 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002426 } else if (!akm &&
2427 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2428 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002429 if (set_network(ifname, id, "key_mgmt",
2430 "WPA-EAP WPA-EAP-SHA256") < 0)
2431 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302432 } else if (akm && atoi(akm) == 14) {
2433 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2434 dut->sta_pmf == STA_PMF_REQUIRED) {
2435 if (set_network(ifname, id, "key_mgmt",
2436 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2437 return -2;
2438 } else {
2439 if (set_network(ifname, id, "key_mgmt",
2440 "WPA-EAP FILS-SHA256") < 0)
2441 return -2;
2442 }
2443
Jouni Malinen8179fee2019-03-28 03:19:47 +02002444 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302445 } else if (akm && atoi(akm) == 15) {
2446 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2447 dut->sta_pmf == STA_PMF_REQUIRED) {
2448 if (set_network(ifname, id, "key_mgmt",
2449 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2450 return -2;
2451 } else {
2452 if (set_network(ifname, id, "key_mgmt",
2453 "WPA-EAP FILS-SHA384") < 0)
2454 return -2;
2455 }
2456
Jouni Malinen8179fee2019-03-28 03:19:47 +02002457 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002458 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002459 if (set_network(ifname, id, "key_mgmt",
2460 "WPA-EAP WPA-EAP-SHA256") < 0)
2461 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002462 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002463 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2464 return -2;
2465 }
2466
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002467 if (trust_root) {
2468 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2469 !domain_suffix) {
2470 send_resp(dut, conn, SIGMA_ERROR,
2471 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2472 return STATUS_SENT_ERROR;
2473 }
2474 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002475 if (res != SUCCESS_SEND_STATUS)
2476 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002477 }
2478
Jouni Malinen53264f62019-05-03 13:04:40 +03002479 val = get_param(cmd, "ServerCert");
2480 if (val) {
2481 FILE *f;
2482 char *result = NULL, *pos;
2483
2484 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2485 val);
2486 f = fopen(buf, "r");
2487 if (f) {
2488 result = fgets(buf, sizeof(buf), f);
2489 fclose(f);
2490 }
2491 if (!result) {
2492 snprintf(buf2, sizeof(buf2),
2493 "ErrorCode,ServerCert hash could not be read from %s",
2494 buf);
2495 send_resp(dut, conn, SIGMA_ERROR, buf2);
2496 return STATUS_SENT_ERROR;
2497 }
2498 pos = strchr(buf, '\n');
2499 if (pos)
2500 *pos = '\0';
2501 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2502 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2503 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002504
2505 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2506 if (file_exists(buf)) {
2507 sigma_dut_print(dut, DUT_MSG_DEBUG,
2508 "TOD policy enabled for the configured ServerCert hash");
2509 dut->sta_tod_policy = 1;
2510 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002511 }
2512
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002513 if (domain &&
2514 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002515 return ERROR_SEND_STATUS;
2516
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002517 if (domain_suffix &&
2518 set_network_quoted(ifname, id, "domain_suffix_match",
2519 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002520 return ERROR_SEND_STATUS;
2521
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302522 if (username_identity) {
2523 val = get_param(cmd, "username");
2524 if (val) {
2525 if (set_network_quoted(ifname, id, "identity", val) < 0)
2526 return -2;
2527 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002528
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302529 val = get_param(cmd, "password");
2530 if (val) {
2531 if (set_network_quoted(ifname, id, "password", val) < 0)
2532 return -2;
2533 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002534 }
2535
Jouni Malinen8179fee2019-03-28 03:19:47 +02002536 if (dut->akm_values &
2537 ((1 << AKM_FILS_SHA256) |
2538 (1 << AKM_FILS_SHA384) |
2539 (1 << AKM_FT_FILS_SHA256) |
2540 (1 << AKM_FT_FILS_SHA384)))
2541 erp = 1;
2542 if (erp && set_network(ifname, id, "erp", "1") < 0)
2543 return ERROR_SEND_STATUS;
2544
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002545 dut->sta_associate_wait_connect = 1;
2546
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002547 return id;
2548}
2549
2550
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002551static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2552{
2553 const char *val;
2554
2555 if (!cipher)
2556 return 0;
2557
2558 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2559 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2560 else if (strcasecmp(cipher,
2561 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2562 val = "ECDHE-RSA-AES256-GCM-SHA384";
2563 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2564 val = "DHE-RSA-AES256-GCM-SHA384";
2565 else if (strcasecmp(cipher,
2566 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2567 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2568 else
2569 return -1;
2570
2571 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2572 set_network_quoted(ifname, id, "phase1", "");
2573
2574 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2575}
2576
2577
Jouni Malinenf7222712019-06-13 01:50:21 +03002578static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2579 struct sigma_conn *conn,
2580 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002581{
2582 const char *intf = get_param(cmd, "Interface");
2583 const char *ifname, *val;
2584 int id;
2585 char buf[200];
2586#ifdef ANDROID
2587 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2588 int length;
2589 int jb_or_newer = 0;
2590 char prop[PROPERTY_VALUE_MAX];
2591#endif /* ANDROID */
2592
2593 if (intf == NULL)
2594 return -1;
2595
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002596 if (strcmp(intf, get_main_ifname(dut)) == 0)
2597 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002598 else
2599 ifname = intf;
2600
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302601 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002602 if (id < 0)
2603 return id;
2604
2605 if (set_network(ifname, id, "eap", "TLS") < 0)
2606 return -2;
2607
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302608 if (!get_param(cmd, "username") &&
2609 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002610 "wifi-user@wifilabs.local") < 0)
2611 return -2;
2612
2613 val = get_param(cmd, "clientCertificate");
2614 if (val == NULL)
2615 return -1;
2616#ifdef ANDROID
2617 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2618 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2619 if (length < 0) {
2620 /*
2621 * JB started reporting keystore type mismatches, so retry with
2622 * the GET_PUBKEY command if the generic GET fails.
2623 */
2624 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2625 buf, kvalue);
2626 }
2627
2628 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2629 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2630 if (strncmp(prop, "4.0", 3) != 0)
2631 jb_or_newer = 1;
2632 } else
2633 jb_or_newer = 1; /* assume newer */
2634
2635 if (jb_or_newer && length > 0) {
2636 sigma_dut_print(dut, DUT_MSG_INFO,
2637 "Use Android keystore [%s]", buf);
2638 if (set_network(ifname, id, "engine", "1") < 0)
2639 return -2;
2640 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2641 return -2;
2642 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2643 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2644 return -2;
2645 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2646 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2647 return -2;
2648 return 1;
2649 } else if (length > 0) {
2650 sigma_dut_print(dut, DUT_MSG_INFO,
2651 "Use Android keystore [%s]", buf);
2652 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2653 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2654 return -2;
2655 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2656 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2657 return -2;
2658 return 1;
2659 }
2660#endif /* ANDROID */
2661
2662 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2663#ifdef __linux__
2664 if (!file_exists(buf)) {
2665 char msg[300];
2666 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2667 "(%s) not found", buf);
2668 send_resp(dut, conn, SIGMA_ERROR, msg);
2669 return -3;
2670 }
2671#endif /* __linux__ */
2672 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2673 return -2;
2674 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2675 return -2;
2676
2677 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2678 return -2;
2679
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002680 val = get_param(cmd, "keyMgmtType");
2681 if (val && strcasecmp(val, "SuiteB") == 0) {
2682 val = get_param(cmd, "CertType");
2683 if (val && strcasecmp(val, "RSA") == 0) {
2684 if (set_network_quoted(ifname, id, "phase1",
2685 "tls_suiteb=1") < 0)
2686 return -2;
2687 } else {
2688 if (set_network_quoted(ifname, id, "openssl_ciphers",
2689 "SUITEB192") < 0)
2690 return -2;
2691 }
2692
2693 val = get_param(cmd, "TLSCipher");
2694 if (set_tls_cipher(ifname, id, val) < 0) {
2695 send_resp(dut, conn, SIGMA_ERROR,
2696 "ErrorCode,Unsupported TLSCipher value");
2697 return -3;
2698 }
2699 }
2700
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002701 return 1;
2702}
2703
2704
Jouni Malinenf7222712019-06-13 01:50:21 +03002705static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2706 struct sigma_conn *conn,
2707 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002708{
2709 const char *intf = get_param(cmd, "Interface");
2710 const char *ifname;
2711 int id;
2712
2713 if (intf == NULL)
2714 return -1;
2715
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002716 if (strcmp(intf, get_main_ifname(dut)) == 0)
2717 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002718 else
2719 ifname = intf;
2720
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302721 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002722 if (id < 0)
2723 return id;
2724
2725 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2726 send_resp(dut, conn, SIGMA_ERROR,
2727 "errorCode,Failed to set TTLS method");
2728 return 0;
2729 }
2730
2731 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2732 send_resp(dut, conn, SIGMA_ERROR,
2733 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2734 return 0;
2735 }
2736
2737 return 1;
2738}
2739
2740
Jouni Malinenf7222712019-06-13 01:50:21 +03002741static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2742 struct sigma_conn *conn,
2743 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002744{
2745 const char *intf = get_param(cmd, "Interface");
2746 const char *ifname;
2747 int id;
2748
2749 if (intf == NULL)
2750 return -1;
2751
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002752 if (strcmp(intf, get_main_ifname(dut)) == 0)
2753 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002754 else
2755 ifname = intf;
2756
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302757 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002758 if (id < 0)
2759 return id;
2760
2761 if (set_network(ifname, id, "eap", "SIM") < 0)
2762 return -2;
2763
2764 return 1;
2765}
2766
2767
Jouni Malinenf7222712019-06-13 01:50:21 +03002768static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2769 struct sigma_conn *conn,
2770 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002771{
2772 const char *intf = get_param(cmd, "Interface");
2773 const char *ifname, *val;
2774 int id;
2775 char buf[100];
2776
2777 if (intf == NULL)
2778 return -1;
2779
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002780 if (strcmp(intf, get_main_ifname(dut)) == 0)
2781 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002782 else
2783 ifname = intf;
2784
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302785 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002786 if (id < 0)
2787 return id;
2788
2789 if (set_network(ifname, id, "eap", "PEAP") < 0)
2790 return -2;
2791
2792 val = get_param(cmd, "innerEAP");
2793 if (val) {
2794 if (strcasecmp(val, "MSCHAPv2") == 0) {
2795 if (set_network_quoted(ifname, id, "phase2",
2796 "auth=MSCHAPV2") < 0)
2797 return -2;
2798 } else if (strcasecmp(val, "GTC") == 0) {
2799 if (set_network_quoted(ifname, id, "phase2",
2800 "auth=GTC") < 0)
2801 return -2;
2802 } else
2803 return -1;
2804 }
2805
2806 val = get_param(cmd, "peapVersion");
2807 if (val) {
2808 int ver = atoi(val);
2809 if (ver < 0 || ver > 1)
2810 return -1;
2811 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2812 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2813 return -2;
2814 }
2815
2816 return 1;
2817}
2818
2819
Jouni Malinenf7222712019-06-13 01:50:21 +03002820static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2821 struct sigma_conn *conn,
2822 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002823{
2824 const char *intf = get_param(cmd, "Interface");
2825 const char *ifname, *val;
2826 int id;
2827 char buf[100];
2828
2829 if (intf == NULL)
2830 return -1;
2831
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002832 if (strcmp(intf, get_main_ifname(dut)) == 0)
2833 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002834 else
2835 ifname = intf;
2836
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302837 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002838 if (id < 0)
2839 return id;
2840
2841 if (set_network(ifname, id, "eap", "FAST") < 0)
2842 return -2;
2843
2844 val = get_param(cmd, "innerEAP");
2845 if (val) {
2846 if (strcasecmp(val, "MSCHAPV2") == 0) {
2847 if (set_network_quoted(ifname, id, "phase2",
2848 "auth=MSCHAPV2") < 0)
2849 return -2;
2850 } else if (strcasecmp(val, "GTC") == 0) {
2851 if (set_network_quoted(ifname, id, "phase2",
2852 "auth=GTC") < 0)
2853 return -2;
2854 } else
2855 return -1;
2856 }
2857
2858 val = get_param(cmd, "validateServer");
2859 if (val) {
2860 /* TODO */
2861 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2862 "validateServer=%s", val);
2863 }
2864
2865 val = get_param(cmd, "pacFile");
2866 if (val) {
2867 snprintf(buf, sizeof(buf), "blob://%s", val);
2868 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2869 return -2;
2870 }
2871
2872 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2873 0)
2874 return -2;
2875
2876 return 1;
2877}
2878
2879
Jouni Malinenf7222712019-06-13 01:50:21 +03002880static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2881 struct sigma_conn *conn,
2882 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002883{
2884 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302885 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002886 const char *ifname;
2887 int id;
2888
2889 if (intf == NULL)
2890 return -1;
2891
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002892 if (strcmp(intf, get_main_ifname(dut)) == 0)
2893 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002894 else
2895 ifname = intf;
2896
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302897 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002898 if (id < 0)
2899 return id;
2900
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302901 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2902 * hexadecimal).
2903 */
2904 if (username && username[0] == '6') {
2905 if (set_network(ifname, id, "eap", "AKA'") < 0)
2906 return -2;
2907 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002908 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302909 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002910
2911 return 1;
2912}
2913
2914
Jouni Malinenf7222712019-06-13 01:50:21 +03002915static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2916 struct sigma_conn *conn,
2917 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002918{
2919 const char *intf = get_param(cmd, "Interface");
2920 const char *ifname;
2921 int id;
2922
2923 if (intf == NULL)
2924 return -1;
2925
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002926 if (strcmp(intf, get_main_ifname(dut)) == 0)
2927 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002928 else
2929 ifname = intf;
2930
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302931 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002932 if (id < 0)
2933 return id;
2934
2935 if (set_network(ifname, id, "eap", "AKA'") < 0)
2936 return -2;
2937
2938 return 1;
2939}
2940
2941
2942static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2943 struct sigma_cmd *cmd)
2944{
2945 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002946 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002947 const char *ifname;
2948 int id;
2949
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002950 if (strcmp(intf, get_main_ifname(dut)) == 0)
2951 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002952 else
2953 ifname = intf;
2954
2955 id = add_network_common(dut, conn, ifname, cmd);
2956 if (id < 0)
2957 return id;
2958
2959 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2960 return -2;
2961
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002962 if (dut->program == PROGRAM_60GHZ && network_mode &&
2963 strcasecmp(network_mode, "PBSS") == 0 &&
2964 set_network(ifname, id, "pbss", "1") < 0)
2965 return -2;
2966
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002967 return 1;
2968}
2969
2970
Jouni Malinen47dcc952017-10-09 16:43:24 +03002971static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2972 struct sigma_cmd *cmd)
2973{
2974 const char *intf = get_param(cmd, "Interface");
2975 const char *ifname, *val;
2976 int id;
2977
2978 if (intf == NULL)
2979 return -1;
2980
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002981 if (strcmp(intf, get_main_ifname(dut)) == 0)
2982 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002983 else
2984 ifname = intf;
2985
2986 id = set_wpa_common(dut, conn, ifname, cmd);
2987 if (id < 0)
2988 return id;
2989
2990 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
2991 return -2;
2992
2993 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03002994 if (val && strcmp(val, "0") == 0) {
2995 if (wpa_command(ifname,
2996 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
2997 sigma_dut_print(dut, DUT_MSG_ERROR,
2998 "Failed to set OWE DH Param element override");
2999 return -2;
3000 }
Hu Wang6010ce72020-03-05 19:33:53 +08003001 } else if (val &&
3002 (set_network(ifname, id, "owe_group", val) < 0 ||
3003 (dut->owe_ptk_workaround &&
3004 set_network(ifname, id, "owe_ptk_workaround", "1") < 0))) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003005 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003006 "Failed to set owe_group");
Jouni Malinen47dcc952017-10-09 16:43:24 +03003007 return -2;
3008 }
3009
3010 return 1;
3011}
3012
3013
Jouni Malinenf7222712019-06-13 01:50:21 +03003014static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3015 struct sigma_conn *conn,
3016 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003017{
3018 const char *type = get_param(cmd, "Type");
3019
3020 if (type == NULL) {
3021 send_resp(dut, conn, SIGMA_ERROR,
3022 "ErrorCode,Missing Type argument");
3023 return 0;
3024 }
3025
3026 if (strcasecmp(type, "OPEN") == 0)
3027 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003028 if (strcasecmp(type, "OWE") == 0)
3029 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003030 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003031 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003032 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003033 return cmd_sta_set_psk(dut, conn, cmd);
3034 if (strcasecmp(type, "EAPTLS") == 0)
3035 return cmd_sta_set_eaptls(dut, conn, cmd);
3036 if (strcasecmp(type, "EAPTTLS") == 0)
3037 return cmd_sta_set_eapttls(dut, conn, cmd);
3038 if (strcasecmp(type, "EAPPEAP") == 0)
3039 return cmd_sta_set_peap(dut, conn, cmd);
3040 if (strcasecmp(type, "EAPSIM") == 0)
3041 return cmd_sta_set_eapsim(dut, conn, cmd);
3042 if (strcasecmp(type, "EAPFAST") == 0)
3043 return cmd_sta_set_eapfast(dut, conn, cmd);
3044 if (strcasecmp(type, "EAPAKA") == 0)
3045 return cmd_sta_set_eapaka(dut, conn, cmd);
3046 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3047 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003048 if (strcasecmp(type, "wep") == 0)
3049 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003050
3051 send_resp(dut, conn, SIGMA_ERROR,
3052 "ErrorCode,Unsupported Type value");
3053 return 0;
3054}
3055
3056
3057int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3058{
3059#ifdef __linux__
3060 /* special handling for ath6kl */
3061 char path[128], fname[128], *pos;
3062 ssize_t res;
3063 FILE *f;
3064
Jouni Malinene39cd562019-05-29 23:39:56 +03003065 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3066 intf);
3067 if (res < 0 || res >= sizeof(fname))
3068 return 0;
3069 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003070 if (res < 0)
3071 return 0; /* not ath6kl */
3072
3073 if (res >= (int) sizeof(path))
3074 res = sizeof(path) - 1;
3075 path[res] = '\0';
3076 pos = strrchr(path, '/');
3077 if (pos == NULL)
3078 pos = path;
3079 else
3080 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003081 res = snprintf(fname, sizeof(fname),
3082 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3083 "create_qos", pos);
3084 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003085 return 0; /* not ath6kl */
3086
3087 if (uapsd) {
3088 f = fopen(fname, "w");
3089 if (f == NULL)
3090 return -1;
3091
3092 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3093 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3094 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3095 "20000 0\n");
3096 fclose(f);
3097 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003098 res = snprintf(fname, sizeof(fname),
3099 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3100 "delete_qos", pos);
3101 if (res < 0 || res >= sizeof(fname))
3102 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003103
3104 f = fopen(fname, "w");
3105 if (f == NULL)
3106 return -1;
3107
3108 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3109 fprintf(f, "2 4\n");
3110 fclose(f);
3111 }
3112#endif /* __linux__ */
3113
3114 return 0;
3115}
3116
3117
Jouni Malinenf7222712019-06-13 01:50:21 +03003118static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3119 struct sigma_conn *conn,
3120 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003121{
3122 const char *intf = get_param(cmd, "Interface");
3123 /* const char *ssid = get_param(cmd, "ssid"); */
3124 const char *val;
3125 int max_sp_len = 4;
3126 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3127 char buf[100];
3128 int ret1, ret2;
3129
3130 val = get_param(cmd, "maxSPLength");
3131 if (val) {
3132 max_sp_len = atoi(val);
3133 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3134 max_sp_len != 4)
3135 return -1;
3136 }
3137
3138 val = get_param(cmd, "acBE");
3139 if (val)
3140 ac_be = atoi(val);
3141
3142 val = get_param(cmd, "acBK");
3143 if (val)
3144 ac_bk = atoi(val);
3145
3146 val = get_param(cmd, "acVI");
3147 if (val)
3148 ac_vi = atoi(val);
3149
3150 val = get_param(cmd, "acVO");
3151 if (val)
3152 ac_vo = atoi(val);
3153
3154 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3155
3156 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3157 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3158 ret1 = wpa_command(intf, buf);
3159
3160 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3161 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3162 ret2 = wpa_command(intf, buf);
3163
3164 if (ret1 && ret2) {
3165 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3166 "UAPSD parameters.");
3167 return -2;
3168 }
3169
3170 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3171 send_resp(dut, conn, SIGMA_ERROR,
3172 "ErrorCode,Failed to set ath6kl QoS parameters");
3173 return 0;
3174 }
3175
3176 return 1;
3177}
3178
3179
Jouni Malinenf7222712019-06-13 01:50:21 +03003180static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3181 struct sigma_conn *conn,
3182 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003183{
3184 char buf[1000];
3185 const char *intf = get_param(cmd, "Interface");
3186 const char *grp = get_param(cmd, "Group");
3187 const char *act = get_param(cmd, "Action");
3188 const char *tid = get_param(cmd, "Tid");
3189 const char *dir = get_param(cmd, "Direction");
3190 const char *psb = get_param(cmd, "Psb");
3191 const char *up = get_param(cmd, "Up");
3192 const char *fixed = get_param(cmd, "Fixed");
3193 const char *size = get_param(cmd, "Size");
3194 const char *msize = get_param(cmd, "Maxsize");
3195 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3196 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3197 const char *inact = get_param(cmd, "Inactivity");
3198 const char *sus = get_param(cmd, "Suspension");
3199 const char *mindr = get_param(cmd, "Mindatarate");
3200 const char *meandr = get_param(cmd, "Meandatarate");
3201 const char *peakdr = get_param(cmd, "Peakdatarate");
3202 const char *phyrate = get_param(cmd, "Phyrate");
3203 const char *burstsize = get_param(cmd, "Burstsize");
3204 const char *sba = get_param(cmd, "Sba");
3205 int direction;
3206 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003207 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003208 int fixed_int;
3209 int psb_ts;
3210
3211 if (intf == NULL || grp == NULL || act == NULL )
3212 return -1;
3213
3214 if (strcasecmp(act, "addts") == 0) {
3215 if (tid == NULL || dir == NULL || psb == NULL ||
3216 up == NULL || fixed == NULL || size == NULL)
3217 return -1;
3218
3219 /*
3220 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3221 * possible values, but WMM-AC and V-E test scripts use "UP,
3222 * "DOWN", and "BIDI".
3223 */
3224 if (strcasecmp(dir, "uplink") == 0 ||
3225 strcasecmp(dir, "up") == 0) {
3226 direction = 0;
3227 } else if (strcasecmp(dir, "downlink") == 0 ||
3228 strcasecmp(dir, "down") == 0) {
3229 direction = 1;
3230 } else if (strcasecmp(dir, "bidi") == 0) {
3231 direction = 2;
3232 } else {
3233 sigma_dut_print(dut, DUT_MSG_ERROR,
3234 "Direction %s not supported", dir);
3235 return -1;
3236 }
3237
3238 if (strcasecmp(psb, "legacy") == 0) {
3239 psb_ts = 0;
3240 } else if (strcasecmp(psb, "uapsd") == 0) {
3241 psb_ts = 1;
3242 } else {
3243 sigma_dut_print(dut, DUT_MSG_ERROR,
3244 "PSB %s not supported", psb);
3245 return -1;
3246 }
3247
3248 if (atoi(tid) < 0 || atoi(tid) > 7) {
3249 sigma_dut_print(dut, DUT_MSG_ERROR,
3250 "TID %s not supported", tid);
3251 return -1;
3252 }
3253
3254 if (strcasecmp(fixed, "true") == 0) {
3255 fixed_int = 1;
3256 } else {
3257 fixed_int = 0;
3258 }
3259
Peng Xu93319622017-10-04 17:58:16 -07003260 if (sba)
3261 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003262
3263 dut->dialog_token++;
3264 handle = 7000 + dut->dialog_token;
3265
3266 /*
3267 * size: convert to hex
3268 * maxsi: convert to hex
3269 * mindr: convert to hex
3270 * meandr: convert to hex
3271 * peakdr: convert to hex
3272 * burstsize: convert to hex
3273 * phyrate: convert to hex
3274 * sba: convert to hex with modification
3275 * minsi: convert to integer
3276 * sus: convert to integer
3277 * inact: convert to integer
3278 * maxsi: convert to integer
3279 */
3280
3281 /*
3282 * The Nominal MSDU Size field is 2 octets long and contains an
3283 * unsigned integer that specifies the nominal size, in octets,
3284 * of MSDUs belonging to the traffic under this traffic
3285 * specification and is defined in Figure 16. If the Fixed
3286 * subfield is set to 1, then the size of the MSDU is fixed and
3287 * is indicated by the Size Subfield. If the Fixed subfield is
3288 * set to 0, then the size of the MSDU might not be fixed and
3289 * the Size indicates the nominal MSDU size.
3290 *
3291 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3292 * and specifies the excess allocation of time (and bandwidth)
3293 * over and above the stated rates required to transport an MSDU
3294 * belonging to the traffic in this TSPEC. This field is
3295 * represented as an unsigned binary number with an implicit
3296 * binary point after the leftmost 3 bits. For example, an SBA
3297 * of 1.75 is represented as 0x3800. This field is included to
3298 * account for retransmissions. As such, the value of this field
3299 * must be greater than unity.
3300 */
3301
3302 snprintf(buf, sizeof(buf),
3303 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3304 " 0x%X 0x%X 0x%X"
3305 " 0x%X 0x%X 0x%X"
3306 " 0x%X %d %d %d %d"
3307 " %d %d",
3308 intf, handle, tid, direction, psb_ts, up,
3309 (unsigned int) ((fixed_int << 15) | atoi(size)),
3310 msize ? atoi(msize) : 0,
3311 mindr ? atoi(mindr) : 0,
3312 meandr ? atoi(meandr) : 0,
3313 peakdr ? atoi(peakdr) : 0,
3314 burstsize ? atoi(burstsize) : 0,
3315 phyrate ? atoi(phyrate) : 0,
3316 sba ? ((unsigned int) (((int) sba_fv << 13) |
3317 (int)((sba_fv - (int) sba_fv) *
3318 8192))) : 0,
3319 minsi ? atoi(minsi) : 0,
3320 sus ? atoi(sus) : 0,
3321 0, 0,
3322 inact ? atoi(inact) : 0,
3323 maxsi ? atoi(maxsi) : 0);
3324
3325 if (system(buf) != 0) {
3326 sigma_dut_print(dut, DUT_MSG_ERROR,
3327 "iwpriv addtspec request failed");
3328 send_resp(dut, conn, SIGMA_ERROR,
3329 "errorCode,Failed to execute addTspec command");
3330 return 0;
3331 }
3332
3333 sigma_dut_print(dut, DUT_MSG_INFO,
3334 "iwpriv addtspec request send");
3335
3336 /* Mapping handle to a TID */
3337 dut->tid_to_handle[atoi(tid)] = handle;
3338 } else if (strcasecmp(act, "delts") == 0) {
3339 if (tid == NULL)
3340 return -1;
3341
3342 if (atoi(tid) < 0 || atoi(tid) > 7) {
3343 sigma_dut_print(dut, DUT_MSG_ERROR,
3344 "TID %s not supported", tid);
3345 send_resp(dut, conn, SIGMA_ERROR,
3346 "errorCode,Unsupported TID");
3347 return 0;
3348 }
3349
3350 handle = dut->tid_to_handle[atoi(tid)];
3351
3352 if (handle < 7000 || handle > 7255) {
3353 /* Invalid handle ie no mapping for that TID */
3354 sigma_dut_print(dut, DUT_MSG_ERROR,
3355 "handle-> %d not found", handle);
3356 }
3357
3358 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3359 intf, handle);
3360
3361 if (system(buf) != 0) {
3362 sigma_dut_print(dut, DUT_MSG_ERROR,
3363 "iwpriv deltspec request failed");
3364 send_resp(dut, conn, SIGMA_ERROR,
3365 "errorCode,Failed to execute delTspec command");
3366 return 0;
3367 }
3368
3369 sigma_dut_print(dut, DUT_MSG_INFO,
3370 "iwpriv deltspec request send");
3371
3372 dut->tid_to_handle[atoi(tid)] = 0;
3373 } else {
3374 sigma_dut_print(dut, DUT_MSG_ERROR,
3375 "Action type %s not supported", act);
3376 send_resp(dut, conn, SIGMA_ERROR,
3377 "errorCode,Unsupported Action");
3378 return 0;
3379 }
3380
3381 return 1;
3382}
3383
3384
vamsi krishna52e16f92017-08-29 12:37:34 +05303385static int find_network(struct sigma_dut *dut, const char *ssid)
3386{
3387 char list[4096];
3388 char *pos;
3389
3390 sigma_dut_print(dut, DUT_MSG_DEBUG,
3391 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003392 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303393 list, sizeof(list)) < 0)
3394 return -1;
3395 pos = strstr(list, ssid);
3396 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3397 return -1;
3398
3399 while (pos > list && pos[-1] != '\n')
3400 pos--;
3401 dut->infra_network_id = atoi(pos);
3402 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3403 return 0;
3404}
3405
3406
Sunil Dutt44595082018-02-12 19:41:45 +05303407#ifdef NL80211_SUPPORT
3408static int sta_config_rsnie(struct sigma_dut *dut, int val)
3409{
3410 struct nl_msg *msg;
3411 int ret;
3412 struct nlattr *params;
3413 int ifindex;
3414
3415 ifindex = if_nametoindex("wlan0");
3416 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3417 NL80211_CMD_VENDOR)) ||
3418 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3419 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3420 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3421 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
3422 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3423 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) {
3424 sigma_dut_print(dut, DUT_MSG_ERROR,
3425 "%s: err in adding vendor_cmd and vendor_data",
3426 __func__);
3427 nlmsg_free(msg);
3428 return -1;
3429 }
3430 nla_nest_end(msg, params);
3431
3432 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3433 if (ret) {
3434 sigma_dut_print(dut, DUT_MSG_ERROR,
3435 "%s: err in send_and_recv_msgs, ret=%d",
3436 __func__, ret);
3437 return ret;
3438 }
3439
3440 return 0;
3441}
3442#endif /* NL80211_SUPPORT */
3443
3444
Jouni Malinenf7222712019-06-13 01:50:21 +03003445static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3446 struct sigma_conn *conn,
3447 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003448{
3449 /* const char *intf = get_param(cmd, "Interface"); */
3450 const char *ssid = get_param(cmd, "ssid");
3451 const char *wps_param = get_param(cmd, "WPS");
3452 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003453 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003454 const char *network_mode = get_param(cmd, "network_mode");
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303455 const char *ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003456 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003457 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003458 int e;
3459 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3460 struct wpa_ctrl *ctrl = NULL;
3461 int num_network_not_found = 0;
3462 int num_disconnected = 0;
3463 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003464
3465 if (ssid == NULL)
3466 return -1;
3467
Jouni Malinen37d5c692019-08-19 16:56:55 +03003468 dut->server_cert_tod = 0;
3469
Jouni Malinen3c367e82017-06-23 17:01:47 +03003470 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303471#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003472 if (get_driver_type(dut) == DRIVER_WCN) {
Sunil Dutt44595082018-02-12 19:41:45 +05303473 sta_config_rsnie(dut, 1);
3474 dut->config_rsnie = 1;
3475 }
3476#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003477 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3478 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003479 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03003480 send_resp(dut, conn, SIGMA_ERROR,
3481 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3482 return 0;
3483 }
3484 }
3485
Jouni Malinen68143132017-09-02 02:34:08 +03003486 if (dut->sae_commit_override) {
3487 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3488 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003489 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03003490 send_resp(dut, conn, SIGMA_ERROR,
3491 "ErrorCode,Failed to set SAE commit override");
3492 return 0;
3493 }
3494 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303495#ifdef ANDROID
3496 if (dut->fils_hlp)
3497 process_fils_hlp(dut);
3498#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003499
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003500 if (wps_param &&
3501 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3502 wps = 1;
3503
Vamsi Krishnac1633d22020-05-06 18:31:21 +05303504 if (dut->ocvc &&
3505 set_network(get_station_ifname(dut), dut->infra_network_id,
3506 "ocv", "1") < 0)
3507 return ERROR_SEND_STATUS;
3508
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003509 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003510 if (dut->program == PROGRAM_60GHZ && network_mode &&
3511 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003512 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003513 "pbss", "1") < 0)
3514 return -2;
3515
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003516 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3517 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3518 "parameters not yet set");
3519 return 0;
3520 }
3521 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003522 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003523 return -2;
3524 } else {
3525 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3526 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003527 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003528 return -2;
3529 }
3530 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303531 if (strcmp(ssid, dut->infra_ssid) == 0) {
3532 sigma_dut_print(dut, DUT_MSG_DEBUG,
3533 "sta_associate for the most recently added network");
3534 } else if (find_network(dut, ssid) < 0) {
3535 sigma_dut_print(dut, DUT_MSG_DEBUG,
3536 "sta_associate for a previously stored network profile");
3537 send_resp(dut, conn, SIGMA_ERROR,
3538 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003539 return 0;
3540 }
3541
3542 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003543 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003544 "bssid", bssid) < 0) {
3545 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3546 "Invalid bssid argument");
3547 return 0;
3548 }
3549
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303550 if ((dut->program == PROGRAM_WPA3 &&
3551 dut->sta_associate_wait_connect) ||
3552 dut->program == PROGRAM_QM) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003553 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003554 if (!ctrl)
3555 return ERROR_SEND_STATUS;
3556 }
3557
Jouni Malinen46a19b62017-06-23 14:31:27 +03003558 extra[0] = '\0';
3559 if (chan)
3560 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003561 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003562 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3563 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003564 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003565 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3566 "network id %d on %s",
3567 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003568 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003569 ret = ERROR_SEND_STATUS;
3570 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003571 }
3572 }
3573
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003574 if (!ctrl)
3575 return SUCCESS_SEND_STATUS;
3576
3577 /* Wait for connection result to be able to store server certificate
3578 * hash for trust root override testing
3579 * (dev_exec_action,ServerCertTrust). */
3580
3581 for (e = 0; e < 20; e++) {
3582 const char *events[] = {
3583 "CTRL-EVENT-EAP-PEER-CERT",
3584 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3585 "CTRL-EVENT-DISCONNECTED",
3586 "CTRL-EVENT-CONNECTED",
3587 "CTRL-EVENT-NETWORK-NOT-FOUND",
3588 NULL
3589 };
3590 char buf[1024];
3591 int res;
3592
3593 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3594 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02003595 send_resp(dut, conn, SIGMA_COMPLETE,
3596 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003597 ret = STATUS_SENT_ERROR;
3598 break;
3599 }
3600 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3601 buf);
3602
3603 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3604 strstr(buf, " depth=0")) {
3605 char *pos = strstr(buf, " hash=");
3606
3607 if (pos) {
3608 char *end;
3609
Jouni Malinen34b19cb2019-08-16 16:37:17 +03003610 if (strstr(buf, " tod=1"))
3611 tod = 1;
3612 else if (strstr(buf, " tod=2"))
3613 tod = 2;
3614 else
3615 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003616 sigma_dut_print(dut, DUT_MSG_DEBUG,
3617 "Server certificate TOD policy: %d",
3618 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03003619 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003620
3621 pos += 6;
3622 end = strchr(pos, ' ');
3623 if (end)
3624 *end = '\0';
3625 strlcpy(dut->server_cert_hash, pos,
3626 sizeof(dut->server_cert_hash));
3627 sigma_dut_print(dut, DUT_MSG_DEBUG,
3628 "Server certificate hash: %s",
3629 dut->server_cert_hash);
3630 }
3631 }
3632
3633 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3634 send_resp(dut, conn, SIGMA_COMPLETE,
3635 "Result,TLS server certificate validation failed");
3636 ret = STATUS_SENT_ERROR;
3637 break;
3638 }
3639
3640 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3641 num_network_not_found++;
3642
3643 if (num_network_not_found > 2) {
3644 send_resp(dut, conn, SIGMA_COMPLETE,
3645 "Result,Network not found");
3646 ret = STATUS_SENT_ERROR;
3647 break;
3648 }
3649 }
3650
3651 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3652 num_disconnected++;
3653
3654 if (num_disconnected > 2) {
3655 send_resp(dut, conn, SIGMA_COMPLETE,
3656 "Result,Connection failed");
3657 ret = STATUS_SENT_ERROR;
3658 break;
3659 }
3660 }
3661
3662 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3663 if (tod >= 0) {
3664 sigma_dut_print(dut, DUT_MSG_DEBUG,
3665 "Network profile TOD policy update: %d -> %d",
3666 dut->sta_tod_policy, tod);
3667 dut->sta_tod_policy = tod;
3668 }
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303669 if (dut->program == PROGRAM_QM) {
3670 unsigned char iface_mac_addr[ETH_ALEN];
3671 char ipv6[100];
3672
3673 if (get_hwaddr(ifname, iface_mac_addr) < 0) {
3674 sigma_dut_print(dut, DUT_MSG_ERROR,
3675 "%s: get_hwaddr %s failed",
3676 __func__, ifname);
3677 ret = ERROR_SEND_STATUS;
3678 break;
3679 }
3680
3681 convert_mac_addr_to_ipv6_lladdr(iface_mac_addr,
3682 ipv6,
3683 sizeof(ipv6));
3684
3685 if (set_ipv6_addr(dut, ipv6, "64", ifname) !=
3686 0) {
3687 ret = ERROR_SEND_STATUS;
3688 break;
3689 }
3690 }
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003691 break;
3692 }
3693 }
3694done:
3695 if (ctrl) {
3696 wpa_ctrl_detach(ctrl);
3697 wpa_ctrl_close(ctrl);
3698 }
3699 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003700}
3701
3702
3703static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3704{
3705 char buf[500], cmd[200];
3706 int res;
3707
3708 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3709 * default path */
3710 res = snprintf(cmd, sizeof(cmd),
3711 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3712 file_exists("./hs20-osu-client") ?
3713 "./hs20-osu-client" : "hs20-osu-client",
3714 sigma_wpas_ctrl,
3715 dut->summary_log ? "-s " : "",
3716 dut->summary_log ? dut->summary_log : "");
3717 if (res < 0 || res >= (int) sizeof(cmd))
3718 return -1;
3719
3720 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3721 if (res < 0 || res >= (int) sizeof(buf))
3722 return -1;
3723 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3724
3725 if (system(buf) != 0) {
3726 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3727 return -1;
3728 }
3729 sigma_dut_print(dut, DUT_MSG_DEBUG,
3730 "Completed hs20-osu-client operation");
3731
3732 return 0;
3733}
3734
3735
3736static int download_ppsmo(struct sigma_dut *dut,
3737 struct sigma_conn *conn,
3738 const char *intf,
3739 struct sigma_cmd *cmd)
3740{
3741 const char *name, *path, *val;
3742 char url[500], buf[600], fbuf[100];
3743 char *fqdn = NULL;
3744
3745 name = get_param(cmd, "FileName");
3746 path = get_param(cmd, "FilePath");
3747 if (name == NULL || path == NULL)
3748 return -1;
3749
3750 if (strcasecmp(path, "VendorSpecific") == 0) {
3751 snprintf(url, sizeof(url), "PPS/%s", name);
3752 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3753 "from the device (%s)", url);
3754 if (!file_exists(url)) {
3755 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3756 "PPS MO file does not exist");
3757 return 0;
3758 }
3759 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3760 if (system(buf) != 0) {
3761 send_resp(dut, conn, SIGMA_ERROR,
3762 "errorCode,Failed to copy PPS MO");
3763 return 0;
3764 }
3765 } else if (strncasecmp(path, "http:", 5) != 0 &&
3766 strncasecmp(path, "https:", 6) != 0) {
3767 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3768 "Unsupported FilePath value");
3769 return 0;
3770 } else {
3771 snprintf(url, sizeof(url), "%s/%s", path, name);
3772 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3773 url);
3774 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3775 remove("pps-tnds.xml");
3776 if (system(buf) != 0) {
3777 send_resp(dut, conn, SIGMA_ERROR,
3778 "errorCode,Failed to download PPS MO");
3779 return 0;
3780 }
3781 }
3782
3783 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3784 send_resp(dut, conn, SIGMA_ERROR,
3785 "errorCode,Failed to parse downloaded PPSMO");
3786 return 0;
3787 }
3788 unlink("pps-tnds.xml");
3789
3790 val = get_param(cmd, "managementTreeURI");
3791 if (val) {
3792 const char *pos, *end;
3793 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3794 val);
3795 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3796 send_resp(dut, conn, SIGMA_ERROR,
3797 "errorCode,Invalid managementTreeURI prefix");
3798 return 0;
3799 }
3800 pos = val + 8;
3801 end = strchr(pos, '/');
3802 if (end == NULL ||
3803 strcmp(end, "/PerProviderSubscription") != 0) {
3804 send_resp(dut, conn, SIGMA_ERROR,
3805 "errorCode,Invalid managementTreeURI postfix");
3806 return 0;
3807 }
3808 if (end - pos >= (int) sizeof(fbuf)) {
3809 send_resp(dut, conn, SIGMA_ERROR,
3810 "errorCode,Too long FQDN in managementTreeURI");
3811 return 0;
3812 }
3813 memcpy(fbuf, pos, end - pos);
3814 fbuf[end - pos] = '\0';
3815 fqdn = fbuf;
3816 sigma_dut_print(dut, DUT_MSG_INFO,
3817 "FQDN from managementTreeURI: %s", fqdn);
3818 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3819 FILE *f = fopen("pps-fqdn", "r");
3820 if (f) {
3821 if (fgets(fbuf, sizeof(fbuf), f)) {
3822 fbuf[sizeof(fbuf) - 1] = '\0';
3823 fqdn = fbuf;
3824 sigma_dut_print(dut, DUT_MSG_DEBUG,
3825 "Use FQDN %s", fqdn);
3826 }
3827 fclose(f);
3828 }
3829 }
3830
3831 if (fqdn == NULL) {
3832 send_resp(dut, conn, SIGMA_ERROR,
3833 "errorCode,No FQDN specified");
3834 return 0;
3835 }
3836
3837 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3838 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3839 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3840
3841 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3842 if (rename("pps.xml", buf) < 0) {
3843 send_resp(dut, conn, SIGMA_ERROR,
3844 "errorCode,Could not move PPS MO");
3845 return 0;
3846 }
3847
3848 if (strcasecmp(path, "VendorSpecific") == 0) {
3849 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3850 fqdn);
3851 if (system(buf)) {
3852 send_resp(dut, conn, SIGMA_ERROR,
3853 "errorCode,Failed to copy OSU CA cert");
3854 return 0;
3855 }
3856
3857 snprintf(buf, sizeof(buf),
3858 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3859 fqdn);
3860 if (system(buf)) {
3861 send_resp(dut, conn, SIGMA_ERROR,
3862 "errorCode,Failed to copy AAA CA cert");
3863 return 0;
3864 }
3865 } else {
3866 snprintf(buf, sizeof(buf),
3867 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3868 fqdn, fqdn);
3869 if (run_hs20_osu(dut, buf) < 0) {
3870 send_resp(dut, conn, SIGMA_ERROR,
3871 "errorCode,Failed to download OSU CA cert");
3872 return 0;
3873 }
3874
3875 snprintf(buf, sizeof(buf),
3876 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3877 fqdn, fqdn);
3878 if (run_hs20_osu(dut, buf) < 0) {
3879 sigma_dut_print(dut, DUT_MSG_INFO,
3880 "Failed to download AAA CA cert");
3881 }
3882 }
3883
3884 if (file_exists("next-client-cert.pem")) {
3885 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3886 if (rename("next-client-cert.pem", buf) < 0) {
3887 send_resp(dut, conn, SIGMA_ERROR,
3888 "errorCode,Could not move client certificate");
3889 return 0;
3890 }
3891 }
3892
3893 if (file_exists("next-client-key.pem")) {
3894 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3895 if (rename("next-client-key.pem", buf) < 0) {
3896 send_resp(dut, conn, SIGMA_ERROR,
3897 "errorCode,Could not move client key");
3898 return 0;
3899 }
3900 }
3901
3902 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3903 if (run_hs20_osu(dut, buf) < 0) {
3904 send_resp(dut, conn, SIGMA_ERROR,
3905 "errorCode,Failed to configure credential from "
3906 "PPSMO");
3907 return 0;
3908 }
3909
3910 return 1;
3911}
3912
3913
3914static int download_cert(struct sigma_dut *dut,
3915 struct sigma_conn *conn,
3916 const char *intf,
3917 struct sigma_cmd *cmd)
3918{
3919 const char *name, *path;
3920 char url[500], buf[600];
3921
3922 name = get_param(cmd, "FileName");
3923 path = get_param(cmd, "FilePath");
3924 if (name == NULL || path == NULL)
3925 return -1;
3926
3927 if (strcasecmp(path, "VendorSpecific") == 0) {
3928 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
3929 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3930 "certificate from the device (%s)", url);
3931 if (!file_exists(url)) {
3932 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3933 "certificate file does not exist");
3934 return 0;
3935 }
3936 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
3937 if (system(buf) != 0) {
3938 send_resp(dut, conn, SIGMA_ERROR,
3939 "errorCode,Failed to copy client "
3940 "certificate");
3941 return 0;
3942 }
3943
3944 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
3945 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3946 "private key from the device (%s)", url);
3947 if (!file_exists(url)) {
3948 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3949 "private key file does not exist");
3950 return 0;
3951 }
3952 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
3953 if (system(buf) != 0) {
3954 send_resp(dut, conn, SIGMA_ERROR,
3955 "errorCode,Failed to copy client key");
3956 return 0;
3957 }
3958 } else if (strncasecmp(path, "http:", 5) != 0 &&
3959 strncasecmp(path, "https:", 6) != 0) {
3960 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3961 "Unsupported FilePath value");
3962 return 0;
3963 } else {
3964 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
3965 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
3966 "certificate/key from %s", url);
3967 snprintf(buf, sizeof(buf),
3968 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
3969 if (system(buf) != 0) {
3970 send_resp(dut, conn, SIGMA_ERROR,
3971 "errorCode,Failed to download client "
3972 "certificate");
3973 return 0;
3974 }
3975
3976 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
3977 {
3978 send_resp(dut, conn, SIGMA_ERROR,
3979 "errorCode,Failed to copy client key");
3980 return 0;
3981 }
3982 }
3983
3984 return 1;
3985}
3986
3987
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003988static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
3989 struct sigma_conn *conn,
3990 struct sigma_cmd *cmd)
3991{
3992 const char *val;
3993 const char *intf = get_param(cmd, "interface");
3994
3995 if (!intf)
3996 return -1;
3997
3998 val = get_param(cmd, "WscIEFragment");
3999 if (val && strcasecmp(val, "enable") == 0) {
4000 sigma_dut_print(dut, DUT_MSG_DEBUG,
4001 "Enable WSC IE fragmentation");
4002
4003 dut->wsc_fragment = 1;
4004 /* set long attributes to force fragmentation */
4005 if (wpa_command(intf, "SET device_name "
4006 WPS_LONG_DEVICE_NAME) < 0)
4007 return -2;
4008 if (wpa_command(intf, "SET manufacturer "
4009 WPS_LONG_MANUFACTURER) < 0)
4010 return -2;
4011 if (wpa_command(intf, "SET model_name "
4012 WPS_LONG_MODEL_NAME) < 0)
4013 return -2;
4014 if (wpa_command(intf, "SET model_number "
4015 WPS_LONG_MODEL_NUMBER) < 0)
4016 return -2;
4017 if (wpa_command(intf, "SET serial_number "
4018 WPS_LONG_SERIAL_NUMBER) < 0)
4019 return -2;
4020 }
4021
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02004022 val = get_param(cmd, "RSN_IE");
4023 if (val) {
4024 if (strcasecmp(val, "disable") == 0)
4025 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
4026 else if (strcasecmp(val, "enable") == 0)
4027 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
4028 }
4029
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004030 val = get_param(cmd, "WpsVersion");
4031 if (val)
4032 dut->wps_forced_version = get_wps_forced_version(dut, val);
4033
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004034 val = get_param(cmd, "WscEAPFragment");
4035 if (val && strcasecmp(val, "enable") == 0)
4036 dut->eap_fragment = 1;
4037
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004038 return 1;
4039}
4040
4041
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004042static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4043 struct sigma_conn *conn,
4044 const char *intf,
4045 struct sigma_cmd *cmd)
4046{
4047 const char *val;
4048
4049 val = get_param(cmd, "FileType");
4050 if (val && strcasecmp(val, "PPSMO") == 0)
4051 return download_ppsmo(dut, conn, intf, cmd);
4052 if (val && strcasecmp(val, "CERT") == 0)
4053 return download_cert(dut, conn, intf, cmd);
4054 if (val) {
4055 send_resp(dut, conn, SIGMA_ERROR,
4056 "ErrorCode,Unsupported FileType");
4057 return 0;
4058 }
4059
4060 return 1;
4061}
4062
4063
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304064static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4065 struct sigma_conn *conn,
4066 const char *intf,
4067 struct sigma_cmd *cmd)
4068{
4069 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304070 char buf[1000];
4071 char text[20];
4072 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304073
4074 val = get_param(cmd, "OCESupport");
4075 if (val && strcasecmp(val, "Disable") == 0) {
4076 if (wpa_command(intf, "SET oce 0") < 0) {
4077 send_resp(dut, conn, SIGMA_ERROR,
4078 "ErrorCode,Failed to disable OCE");
4079 return 0;
4080 }
4081 } else if (val && strcasecmp(val, "Enable") == 0) {
4082 if (wpa_command(intf, "SET oce 1") < 0) {
4083 send_resp(dut, conn, SIGMA_ERROR,
4084 "ErrorCode,Failed to enable OCE");
4085 return 0;
4086 }
4087 }
4088
vamsi krishnaa2799492017-12-05 14:28:01 +05304089 val = get_param(cmd, "FILScap");
4090 if (val && (atoi(val) == 1)) {
4091 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4092 send_resp(dut, conn, SIGMA_ERROR,
4093 "ErrorCode,Failed to enable FILS");
4094 return 0;
4095 }
4096 } else if (val && (atoi(val) == 0)) {
4097 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4098 send_resp(dut, conn, SIGMA_ERROR,
4099 "ErrorCode,Failed to disable FILS");
4100 return 0;
4101 }
4102 }
4103
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304104 val = get_param(cmd, "FILSHLP");
4105 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004106 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304107 sizeof(text)) < 0)
4108 return -2;
4109 hwaddr_aton(text, addr);
4110 snprintf(buf, sizeof(buf),
4111 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4112 "080045100140000040004011399e00000000ffffffff00440043"
4113 "012cb30001010600fd4f46410000000000000000000000000000"
4114 "000000000000"
4115 "%02x%02x%02x%02x%02x%02x"
4116 "0000000000000000000000000000000000000000000000000000"
4117 "0000000000000000000000000000000000000000000000000000"
4118 "0000000000000000000000000000000000000000000000000000"
4119 "0000000000000000000000000000000000000000000000000000"
4120 "0000000000000000000000000000000000000000000000000000"
4121 "0000000000000000000000000000000000000000000000000000"
4122 "0000000000000000000000000000000000000000000000000000"
4123 "0000000000000000000000000000000000000000638253633501"
4124 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4125 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4126 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4127 if (wpa_command(intf, buf)) {
4128 send_resp(dut, conn, SIGMA_ERROR,
4129 "ErrorCode,Failed to add HLP");
4130 return 0;
4131 }
4132 dut->fils_hlp = 1;
4133 }
4134
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304135 return 1;
4136}
4137
4138
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004139static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4140 const char *val)
4141{
4142 int counter = 0;
4143 char token[50];
4144 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304145 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004146
Peng Xub8fc5cc2017-05-10 17:27:28 -07004147 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004148 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304149 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004150 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004151 if (strcmp(result, "disable") == 0)
4152 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4153 else
4154 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304155 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004156 counter++;
4157 }
4158}
4159
4160
4161static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4162 const char *val)
4163{
4164 char buf[100];
4165
4166 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4167 if (system(buf) != 0) {
4168 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4169 }
4170}
4171
4172
4173static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4174 const char *val)
4175{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004176 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004177 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004178 }
4179}
4180
4181
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004182static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4183 const char *val)
4184{
4185#ifdef NL80211_SUPPORT
4186 struct nl_msg *msg;
4187 int ret = 0;
4188 struct nlattr *params;
4189 int ifindex;
4190 int wmmenable = 1;
4191
4192 if (val &&
4193 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4194 wmmenable = 0;
4195
4196 ifindex = if_nametoindex(intf);
4197 if (ifindex == 0) {
4198 sigma_dut_print(dut, DUT_MSG_ERROR,
4199 "%s: Index for interface %s failed",
4200 __func__, intf);
4201 return -1;
4202 }
4203
4204 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4205 NL80211_CMD_VENDOR)) ||
4206 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4207 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4208 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4209 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4210 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4211 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4212 wmmenable)) {
4213 sigma_dut_print(dut, DUT_MSG_ERROR,
4214 "%s: err in adding vendor_cmd and vendor_data",
4215 __func__);
4216 nlmsg_free(msg);
4217 return -1;
4218 }
4219 nla_nest_end(msg, params);
4220
4221 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4222 if (ret) {
4223 sigma_dut_print(dut, DUT_MSG_ERROR,
4224 "%s: err in send_and_recv_msgs, ret=%d",
4225 __func__, ret);
4226 }
4227 return ret;
4228#else /* NL80211_SUPPORT */
4229 sigma_dut_print(dut, DUT_MSG_ERROR,
4230 "WMM cannot be changed without NL80211_SUPPORT defined");
4231 return -1;
4232#endif /* NL80211_SUPPORT */
4233}
4234
4235
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004236static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4237 const char *val)
4238{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004239 int sgi20;
4240
4241 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4242
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004243 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004244}
4245
4246
4247static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4248 const char *val)
4249{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304250 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004251
4252 /* Disable Tx Beam forming when using a fixed rate */
4253 ath_disable_txbf(dut, intf);
4254
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304255 v = atoi(val);
4256 if (v < 0 || v > 32) {
4257 sigma_dut_print(dut, DUT_MSG_ERROR,
4258 "Invalid Fixed MCS rate: %d", v);
4259 return;
4260 }
4261 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004262
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004263 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004264
4265 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004266 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004267}
4268
4269
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004270static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4271 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004272{
4273 char buf[60];
4274
4275 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4276 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4277 else
4278 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4279
4280 if (system(buf) != 0)
4281 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4282}
4283
4284
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004285static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4286 int ampdu)
4287{
4288 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004289 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004290
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004291 if (ampdu)
4292 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004293 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4294 if (system(buf) != 0) {
4295 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4296 return -1;
4297 }
4298
4299 return 0;
4300}
4301
4302
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004303static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4304 const char *val)
4305{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004306 run_iwpriv(dut, intf, "tx_stbc %s", val);
4307 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004308}
4309
4310
4311static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4312 const char *val)
4313{
4314 char buf[60];
4315
Peng Xucc317ed2017-05-18 16:44:37 -07004316 if (strcmp(val, "160") == 0) {
4317 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4318 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004319 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4320 } else if (strcmp(val, "40") == 0) {
4321 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4322 } else if (strcmp(val, "20") == 0) {
4323 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4324 } else if (strcasecmp(val, "Auto") == 0) {
4325 buf[0] = '\0';
4326 } else {
4327 sigma_dut_print(dut, DUT_MSG_ERROR,
4328 "WIDTH/CTS_WIDTH value not supported");
4329 return -1;
4330 }
4331
4332 if (buf[0] != '\0' && system(buf) != 0) {
4333 sigma_dut_print(dut, DUT_MSG_ERROR,
4334 "Failed to set WIDTH/CTS_WIDTH");
4335 return -1;
4336 }
4337
4338 return 0;
4339}
4340
4341
4342int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4343 const char *intf, const char *val)
4344{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004345 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004346 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004347 dut->chwidth = 0;
4348 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004349 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004350 dut->chwidth = 0;
4351 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004352 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004353 dut->chwidth = 1;
4354 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004355 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004356 dut->chwidth = 2;
4357 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004358 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004359 dut->chwidth = 3;
4360 } else {
4361 send_resp(dut, conn, SIGMA_ERROR,
4362 "ErrorCode,WIDTH not supported");
4363 return -1;
4364 }
4365
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004366 return 0;
4367}
4368
4369
4370static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4371 const char *val)
4372{
4373 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004374 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004375
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004376 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004377 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004378 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004379 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004380 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004381 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004382 } else {
4383 sigma_dut_print(dut, DUT_MSG_ERROR,
4384 "SP_STREAM value not supported");
4385 return -1;
4386 }
4387
4388 if (system(buf) != 0) {
4389 sigma_dut_print(dut, DUT_MSG_ERROR,
4390 "Failed to set SP_STREAM");
4391 return -1;
4392 }
4393
Arif Hussainac6c5112018-05-25 17:34:00 -07004394 dut->sta_nss = sta_nss;
4395
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004396 return 0;
4397}
4398
4399
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304400static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4401 const char *val)
4402{
4403 char buf[60];
4404
4405 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
4406 if (system(buf) != 0)
4407 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4408
4409 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
4410 if (system(buf) != 0)
4411 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4412}
4413
4414
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304415static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4416 struct sigma_conn *conn,
4417 const char *intf, int capa)
4418{
4419 char buf[32];
4420
4421 if (capa > 0 && capa < 4) {
4422 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4423 if (wpa_command(intf, buf) < 0) {
4424 send_resp(dut, conn, SIGMA_ERROR,
4425 "ErrorCode, Failed to set cellular data capability");
4426 return 0;
4427 }
4428 return 1;
4429 }
4430
4431 sigma_dut_print(dut, DUT_MSG_ERROR,
4432 "Invalid Cellular data capability: %d", capa);
4433 send_resp(dut, conn, SIGMA_INVALID,
4434 "ErrorCode,Invalid cellular data capability");
4435 return 0;
4436}
4437
4438
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304439static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4440 const char *intf, const char *val)
4441{
4442 if (strcasecmp(val, "Disable") == 0) {
4443 if (wpa_command(intf, "SET roaming 0") < 0) {
4444 send_resp(dut, conn, SIGMA_ERROR,
4445 "ErrorCode,Failed to disable roaming");
4446 return 0;
4447 }
4448 return 1;
4449 }
4450
4451 if (strcasecmp(val, "Enable") == 0) {
4452 if (wpa_command(intf, "SET roaming 1") < 0) {
4453 send_resp(dut, conn, SIGMA_ERROR,
4454 "ErrorCode,Failed to enable roaming");
4455 return 0;
4456 }
4457 return 1;
4458 }
4459
4460 sigma_dut_print(dut, DUT_MSG_ERROR,
4461 "Invalid value provided for roaming: %s", val);
4462 send_resp(dut, conn, SIGMA_INVALID,
4463 "ErrorCode,Unknown value provided for Roaming");
4464 return 0;
4465}
4466
4467
Ashwini Patila75de5a2017-04-13 16:35:05 +05304468static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4469 struct sigma_conn *conn,
4470 const char *intf, const char *val)
4471{
4472 if (strcasecmp(val, "Disable") == 0) {
4473 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4474 send_resp(dut, conn, SIGMA_ERROR,
4475 "ErrorCode,Failed to disable Assoc_disallow");
4476 return 0;
4477 }
4478 return 1;
4479 }
4480
4481 if (strcasecmp(val, "Enable") == 0) {
4482 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4483 send_resp(dut, conn, SIGMA_ERROR,
4484 "ErrorCode,Failed to enable Assoc_disallow");
4485 return 0;
4486 }
4487 return 1;
4488 }
4489
4490 sigma_dut_print(dut, DUT_MSG_ERROR,
4491 "Invalid value provided for Assoc_disallow: %s", val);
4492 send_resp(dut, conn, SIGMA_INVALID,
4493 "ErrorCode,Unknown value provided for Assoc_disallow");
4494 return 0;
4495}
4496
4497
Ashwini Patilc63161e2017-04-13 16:30:23 +05304498static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4499 const char *intf, const char *val)
4500{
4501 if (strcasecmp(val, "Reject") == 0) {
4502 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4503 send_resp(dut, conn, SIGMA_ERROR,
4504 "ErrorCode,Failed to Reject BTM Request");
4505 return 0;
4506 }
4507 return 1;
4508 }
4509
4510 if (strcasecmp(val, "Accept") == 0) {
4511 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4512 send_resp(dut, conn, SIGMA_ERROR,
4513 "ErrorCode,Failed to Accept BTM Request");
4514 return 0;
4515 }
4516 return 1;
4517 }
4518
4519 sigma_dut_print(dut, DUT_MSG_ERROR,
4520 "Invalid value provided for BSS_Transition: %s", val);
4521 send_resp(dut, conn, SIGMA_INVALID,
4522 "ErrorCode,Unknown value provided for BSS_Transition");
4523 return 0;
4524}
4525
4526
Ashwini Patil00402582017-04-13 12:29:39 +05304527static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4528 struct sigma_conn *conn,
4529 const char *intf,
4530 struct sigma_cmd *cmd)
4531{
4532 const char *ch, *pref, *op_class, *reason;
4533 char buf[120];
4534 int len, ret;
4535
4536 pref = get_param(cmd, "Ch_Pref");
4537 if (!pref)
4538 return 1;
4539
4540 if (strcasecmp(pref, "clear") == 0) {
4541 free(dut->non_pref_ch_list);
4542 dut->non_pref_ch_list = NULL;
4543 } else {
4544 op_class = get_param(cmd, "Ch_Op_Class");
4545 if (!op_class) {
4546 send_resp(dut, conn, SIGMA_INVALID,
4547 "ErrorCode,Ch_Op_Class not provided");
4548 return 0;
4549 }
4550
4551 ch = get_param(cmd, "Ch_Pref_Num");
4552 if (!ch) {
4553 send_resp(dut, conn, SIGMA_INVALID,
4554 "ErrorCode,Ch_Pref_Num not provided");
4555 return 0;
4556 }
4557
4558 reason = get_param(cmd, "Ch_Reason_Code");
4559 if (!reason) {
4560 send_resp(dut, conn, SIGMA_INVALID,
4561 "ErrorCode,Ch_Reason_Code not provided");
4562 return 0;
4563 }
4564
4565 if (!dut->non_pref_ch_list) {
4566 dut->non_pref_ch_list =
4567 calloc(1, NON_PREF_CH_LIST_SIZE);
4568 if (!dut->non_pref_ch_list) {
4569 send_resp(dut, conn, SIGMA_ERROR,
4570 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4571 return 0;
4572 }
4573 }
4574 len = strlen(dut->non_pref_ch_list);
4575 ret = snprintf(dut->non_pref_ch_list + len,
4576 NON_PREF_CH_LIST_SIZE - len,
4577 " %s:%s:%s:%s", op_class, ch, pref, reason);
4578 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4579 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4580 dut->non_pref_ch_list);
4581 } else {
4582 sigma_dut_print(dut, DUT_MSG_ERROR,
4583 "snprintf failed for non_pref_list, ret = %d",
4584 ret);
4585 send_resp(dut, conn, SIGMA_ERROR,
4586 "ErrorCode,snprintf failed");
4587 free(dut->non_pref_ch_list);
4588 dut->non_pref_ch_list = NULL;
4589 return 0;
4590 }
4591 }
4592
4593 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4594 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4595 if (ret < 0 || ret >= (int) sizeof(buf)) {
4596 sigma_dut_print(dut, DUT_MSG_DEBUG,
4597 "snprintf failed for set non_pref_chan, ret: %d",
4598 ret);
4599 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4600 return 0;
4601 }
4602
4603 if (wpa_command(intf, buf) < 0) {
4604 send_resp(dut, conn, SIGMA_ERROR,
4605 "ErrorCode,Failed to set non-preferred channel list");
4606 return 0;
4607 }
4608
4609 return 1;
4610}
4611
4612
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004613#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004614
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004615static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4616 uint8_t cfg)
4617{
4618 struct nl_msg *msg;
4619 int ret = 0;
4620 struct nlattr *params;
4621 int ifindex;
4622
4623 ifindex = if_nametoindex(intf);
4624 if (ifindex == 0) {
4625 sigma_dut_print(dut, DUT_MSG_ERROR,
4626 "%s: Index for interface %s failed",
4627 __func__, intf);
4628 return -1;
4629 }
4630
4631 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4632 NL80211_CMD_VENDOR)) ||
4633 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4634 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4635 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4636 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4637 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4638 nla_put_u8(msg,
4639 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4640 cfg)) {
4641 sigma_dut_print(dut, DUT_MSG_ERROR,
4642 "%s: err in adding vendor_cmd and vendor_data",
4643 __func__);
4644 nlmsg_free(msg);
4645 return -1;
4646 }
4647 nla_nest_end(msg, params);
4648
4649 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4650 if (ret) {
4651 sigma_dut_print(dut, DUT_MSG_ERROR,
4652 "%s: err in send_and_recv_msgs, ret=%d",
4653 __func__, ret);
4654 }
4655 return ret;
4656}
4657
4658
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004659static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4660 enum he_fragmentation_val frag)
4661{
4662 struct nl_msg *msg;
4663 int ret = 0;
4664 struct nlattr *params;
4665 int ifindex;
4666
4667 ifindex = if_nametoindex(intf);
4668 if (ifindex == 0) {
4669 sigma_dut_print(dut, DUT_MSG_ERROR,
4670 "%s: Index for interface %s failed",
4671 __func__, intf);
4672 return -1;
4673 }
4674
4675 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4676 NL80211_CMD_VENDOR)) ||
4677 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4678 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4679 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4680 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4681 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4682 nla_put_u8(msg,
4683 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
4684 frag)) {
4685 sigma_dut_print(dut, DUT_MSG_ERROR,
4686 "%s: err in adding vendor_cmd and vendor_data",
4687 __func__);
4688 nlmsg_free(msg);
4689 return -1;
4690 }
4691 nla_nest_end(msg, params);
4692
4693 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4694 if (ret) {
4695 sigma_dut_print(dut, DUT_MSG_ERROR,
4696 "%s: err in send_and_recv_msgs, ret=%d",
4697 __func__, ret);
4698 }
4699 return ret;
4700}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004701
4702
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08004703int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
4704 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004705{
4706 struct nl_msg *msg;
4707 int ret = 0;
4708 struct nlattr *params;
4709 int ifindex;
4710
4711 ifindex = if_nametoindex(intf);
4712 if (ifindex == 0) {
4713 sigma_dut_print(dut, DUT_MSG_ERROR,
4714 "%s: Index for interface %s failed",
4715 __func__, intf);
4716 return -1;
4717 }
4718
4719 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4720 NL80211_CMD_VENDOR)) ||
4721 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4722 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4723 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4724 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4725 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4726 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
4727 ltf)) {
4728 sigma_dut_print(dut, DUT_MSG_ERROR,
4729 "%s: err in adding vendor_cmd and vendor_data",
4730 __func__);
4731 nlmsg_free(msg);
4732 return -1;
4733 }
4734 nla_nest_end(msg, params);
4735
4736 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4737 if (ret) {
4738 sigma_dut_print(dut, DUT_MSG_ERROR,
4739 "%s: err in send_and_recv_msgs, ret=%d",
4740 __func__, ret);
4741 }
4742 return ret;
4743}
4744
4745
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004746static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4747 int noack, enum qca_wlan_ac_type ac)
4748{
4749 struct nl_msg *msg;
4750 int ret = 0;
4751 struct nlattr *params;
4752 int ifindex;
4753
4754 ifindex = if_nametoindex(intf);
4755 if (ifindex == 0) {
4756 sigma_dut_print(dut, DUT_MSG_ERROR,
4757 "%s: Index for interface %s failed",
4758 __func__, intf);
4759 return -1;
4760 }
4761
4762 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4763 NL80211_CMD_VENDOR)) ||
4764 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4765 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4766 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4767 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4768 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4769 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4770 noack) ||
4771 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4772 ac)) {
4773 sigma_dut_print(dut, DUT_MSG_ERROR,
4774 "%s: err in adding vendor_cmd and vendor_data",
4775 __func__);
4776 nlmsg_free(msg);
4777 return -1;
4778 }
4779 nla_nest_end(msg, params);
4780
4781 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4782 if (ret) {
4783 sigma_dut_print(dut, DUT_MSG_ERROR,
4784 "%s: err in send_and_recv_msgs, ret=%d",
4785 __func__, ret);
4786 }
4787 return ret;
4788}
4789
4790
4791static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4792 const char *val)
4793{
4794 int noack, ret;
4795 char token[100];
4796 char *result;
4797 char *saveptr;
4798 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4799
4800 strlcpy(token, val, sizeof(token));
4801 token[sizeof(token) - 1] = '\0';
4802 result = strtok_r(token, ":", &saveptr);
4803 while (result) {
4804 noack = strcasecmp(result, "Disable") != 0;
4805 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4806 if (ret) {
4807 sigma_dut_print(dut, DUT_MSG_ERROR,
4808 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4809 ac, ret);
4810 }
4811 result = strtok_r(NULL, ":", &saveptr);
4812 ac++;
4813 }
4814}
4815
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004816#endif /* NL80211_SUPPORT */
4817
4818
Jouni Malinenf7222712019-06-13 01:50:21 +03004819static enum sigma_cmd_result
4820cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
4821 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004822{
4823 const char *intf = get_param(cmd, "Interface");
4824 const char *val;
4825
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03004826 val = get_param(cmd, "FT_DS");
4827 if (val) {
4828 if (strcasecmp(val, "Enable") == 0) {
4829 dut->sta_ft_ds = 1;
4830 } else if (strcasecmp(val, "Disable") == 0) {
4831 dut->sta_ft_ds = 0;
4832 } else {
4833 send_resp(dut, conn, SIGMA_ERROR,
4834 "errorCode,Unsupported value for FT_DS");
4835 return STATUS_SENT_ERROR;
4836 }
4837 }
4838
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004839 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03004840 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
4841 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004842 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
4843 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004844
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004845 if (val && strcasecmp(val, "LOC") == 0)
4846 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02004847 if (val && strcasecmp(val, "60GHZ") == 0) {
4848 val = get_param(cmd, "WPS");
4849 if (val && strcasecmp(val, "disable") == 0) {
4850 dut->wps_disable = 1;
4851 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
4852 } else {
4853 /* wps_disable can have other value from the previous
4854 * test, so make sure it has the correct value.
4855 */
4856 dut->wps_disable = 0;
4857 }
4858
4859 val = get_param(cmd, "P2P");
4860 if (val && strcasecmp(val, "disable") == 0)
4861 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
4862 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004863
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004864 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
4865 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
4866
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004867#ifdef ANDROID_NAN
4868 if (val && strcasecmp(val, "NAN") == 0)
4869 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
4870#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004871#ifdef MIRACAST
4872 if (val && (strcasecmp(val, "WFD") == 0 ||
4873 strcasecmp(val, "DisplayR2") == 0))
4874 return miracast_preset_testparameters(dut, conn, cmd);
4875#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004876
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304877 if (val && strcasecmp(val, "MBO") == 0) {
4878 val = get_param(cmd, "Cellular_Data_Cap");
4879 if (val &&
4880 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
4881 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05304882
4883 val = get_param(cmd, "Ch_Pref");
4884 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
4885 return 0;
4886
Ashwini Patilc63161e2017-04-13 16:30:23 +05304887 val = get_param(cmd, "BSS_Transition");
4888 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
4889 return 0;
4890
Ashwini Patila75de5a2017-04-13 16:35:05 +05304891 val = get_param(cmd, "Assoc_Disallow");
4892 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
4893 return 0;
4894
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304895 val = get_param(cmd, "Roaming");
4896 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
4897 return 0;
4898
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304899 return 1;
4900 }
4901
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304902 if (val && strcasecmp(val, "OCE") == 0)
4903 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
4904
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004905#if 0
4906 val = get_param(cmd, "Supplicant");
4907 if (val && strcasecmp(val, "Default") != 0) {
4908 send_resp(dut, conn, SIGMA_ERROR,
4909 "ErrorCode,Only default(Vendor) supplicant "
4910 "supported");
4911 return 0;
4912 }
4913#endif
4914
4915 val = get_param(cmd, "RTS");
4916 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004917 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004918 case DRIVER_ATHEROS:
4919 ath_sta_set_rts(dut, intf, val);
4920 break;
4921 default:
4922#if 0
4923 send_resp(dut, conn, SIGMA_ERROR,
4924 "ErrorCode,Setting RTS not supported");
4925 return 0;
4926#else
4927 sigma_dut_print(dut, DUT_MSG_DEBUG,
4928 "Setting RTS not supported");
4929 break;
4930#endif
4931 }
4932 }
4933
4934#if 0
4935 val = get_param(cmd, "FRGMNT");
4936 if (val) {
4937 /* TODO */
4938 send_resp(dut, conn, SIGMA_ERROR,
4939 "ErrorCode,Setting FRGMNT not supported");
4940 return 0;
4941 }
4942#endif
4943
4944#if 0
4945 val = get_param(cmd, "Preamble");
4946 if (val) {
4947 /* TODO: Long/Short */
4948 send_resp(dut, conn, SIGMA_ERROR,
4949 "ErrorCode,Setting Preamble not supported");
4950 return 0;
4951 }
4952#endif
4953
4954 val = get_param(cmd, "Mode");
4955 if (val) {
4956 if (strcmp(val, "11b") == 0 ||
4957 strcmp(val, "11g") == 0 ||
4958 strcmp(val, "11a") == 0 ||
4959 strcmp(val, "11n") == 0 ||
4960 strcmp(val, "11ng") == 0 ||
4961 strcmp(val, "11nl") == 0 ||
4962 strcmp(val, "11nl(nabg)") == 0 ||
4963 strcmp(val, "AC") == 0 ||
4964 strcmp(val, "11AC") == 0 ||
4965 strcmp(val, "11ac") == 0 ||
4966 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08004967 strcmp(val, "11an") == 0 ||
4968 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004969 /* STA supports all modes by default */
4970 } else {
4971 send_resp(dut, conn, SIGMA_ERROR,
4972 "ErrorCode,Setting Mode not supported");
4973 return 0;
4974 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004975
4976 /* Change the mode only in case of testbed for HE program
4977 * and for 11a and 11g modes only. */
4978 if (dut->program == PROGRAM_HE &&
4979 dut->device_type == STA_testbed) {
4980 int phymode;
4981 char buf[60];
4982
4983 if (strcmp(val, "11a") == 0) {
Amarnath Hullur Subramanyam94dfaf02018-03-02 19:26:57 -08004984 phymode = 1; /* IEEE80211_MODE_11A */
4985 } else if (strcmp(val, "11g") == 0) {
4986 phymode = 3; /* IEEE80211_MODE_11G */
4987 } else if (strcmp(val, "11b") == 0) {
4988 phymode = 2; /* IEEE80211_MODE_11B */
4989 } else if (strcmp(val, "11n") == 0 ||
4990 strcmp(val, "11nl") == 0 ||
4991 strcmp(val, "11nl(nabg)") == 0) {
4992 phymode = 22; /* IEEE80211_MODE_11AGN */
4993 } else if (strcmp(val, "11ng") == 0) {
4994 phymode = 13; /* IEEE80211_MODE_11NG_HT40 */
4995 } else if (strcmp(val, "AC") == 0 ||
4996 strcasecmp(val, "11AC") == 0) {
4997 phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */
4998 } else if (strcmp(val, "11na") == 0 ||
4999 strcasecmp(val, "11an") == 0) {
5000 phymode = 14; /* IEEE80211_MODE_11NA_HT40 */
5001 } else if (strcmp(val, "11ax") == 0) {
5002 phymode = 0; /* IEEE80211_MODE_AUTO */
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005003 } else {
5004 sigma_dut_print(dut, DUT_MSG_DEBUG,
5005 "Ignoring mode change for mode: %s",
5006 val);
5007 phymode = -1;
5008 }
5009 if (phymode != -1) {
5010 snprintf(buf, sizeof(buf),
5011 "iwpriv %s setphymode %d",
5012 intf, phymode);
5013 if (system(buf) != 0) {
5014 sigma_dut_print(dut, DUT_MSG_ERROR,
5015 "iwpriv setting of phymode failed");
5016 }
5017 }
5018 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005019 }
5020
5021 val = get_param(cmd, "wmm");
5022 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005023 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005024 case DRIVER_ATHEROS:
5025 ath_sta_set_wmm(dut, intf, val);
5026 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005027 case DRIVER_WCN:
5028 wcn_sta_set_wmm(dut, intf, val);
5029 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005030 default:
5031 sigma_dut_print(dut, DUT_MSG_DEBUG,
5032 "Setting wmm not supported");
5033 break;
5034 }
5035 }
5036
5037 val = get_param(cmd, "Powersave");
5038 if (val) {
5039 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005040 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305041 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005042 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005043 }
5044
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005045 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005046 "P2P_SET ps 0") < 0)
5047 return -2;
5048 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005049 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5050 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005051 } else if (strcmp(val, "1") == 0 ||
5052 strcasecmp(val, "PSPoll") == 0 ||
5053 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005054 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305055 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005056 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005057 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005058 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005059 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005060 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005061 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005062 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005063 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005064 "P2P_SET ps 99") < 0)
5065 return -2;
5066 } else if (strcmp(val, "2") == 0 ||
5067 strcasecmp(val, "Fast") == 0) {
5068 /* TODO */
5069 send_resp(dut, conn, SIGMA_ERROR,
5070 "ErrorCode,Powersave=Fast not supported");
5071 return 0;
5072 } else if (strcmp(val, "3") == 0 ||
5073 strcasecmp(val, "PSNonPoll") == 0) {
5074 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005075 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5076 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005077
5078 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005079 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005080 "P2P_SET ps 1") < 0)
5081 return -2;
5082 } else
5083 return -1;
5084 }
5085
5086 val = get_param(cmd, "NoAck");
5087 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005088 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005089 case DRIVER_ATHEROS:
5090 ath_sta_set_noack(dut, intf, val);
5091 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005092#ifdef NL80211_SUPPORT
5093 case DRIVER_WCN:
5094 wcn_sta_set_noack(dut, intf, val);
5095 break;
5096#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005097 default:
5098 send_resp(dut, conn, SIGMA_ERROR,
5099 "ErrorCode,Setting NoAck not supported");
5100 return 0;
5101 }
5102 }
5103
5104 val = get_param(cmd, "IgnoreChswitchProhibit");
5105 if (val) {
5106 /* TODO: Enabled/disabled */
5107 if (strcasecmp(val, "Enabled") == 0) {
5108 send_resp(dut, conn, SIGMA_ERROR,
5109 "ErrorCode,Enabling IgnoreChswitchProhibit "
5110 "not supported");
5111 return 0;
5112 }
5113 }
5114
5115 val = get_param(cmd, "TDLS");
5116 if (val) {
5117 if (strcasecmp(val, "Disabled") == 0) {
5118 if (wpa_command(intf, "SET tdls_disabled 1")) {
5119 send_resp(dut, conn, SIGMA_ERROR,
5120 "ErrorCode,Failed to disable TDLS");
5121 return 0;
5122 }
5123 } else if (strcasecmp(val, "Enabled") == 0) {
5124 if (wpa_command(intf, "SET tdls_disabled 0")) {
5125 send_resp(dut, conn, SIGMA_ERROR,
5126 "ErrorCode,Failed to enable TDLS");
5127 return 0;
5128 }
5129 } else {
5130 send_resp(dut, conn, SIGMA_ERROR,
5131 "ErrorCode,Unsupported TDLS value");
5132 return 0;
5133 }
5134 }
5135
5136 val = get_param(cmd, "TDLSmode");
5137 if (val) {
5138 if (strcasecmp(val, "Default") == 0) {
5139 wpa_command(intf, "SET tdls_testing 0");
5140 } else if (strcasecmp(val, "APProhibit") == 0) {
5141 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5142 send_resp(dut, conn, SIGMA_ERROR,
5143 "ErrorCode,Failed to enable ignore "
5144 "APProhibit TDLS mode");
5145 return 0;
5146 }
5147 } else if (strcasecmp(val, "HiLoMac") == 0) {
5148 /* STA should respond with TDLS setup req for a TDLS
5149 * setup req */
5150 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5151 send_resp(dut, conn, SIGMA_ERROR,
5152 "ErrorCode,Failed to enable HiLoMac "
5153 "TDLS mode");
5154 return 0;
5155 }
5156 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5157 /*
5158 * Since all security modes are enabled by default when
5159 * Sigma control is used, there is no need to do
5160 * anything here.
5161 */
5162 } else if (strcasecmp(val, "ExistLink") == 0) {
5163 /*
5164 * Since we allow new TDLS Setup Request even if there
5165 * is an existing link, nothing needs to be done for
5166 * this.
5167 */
5168 } else {
5169 /* TODO:
5170 * ExistLink: STA should send TDLS setup req even if
5171 * direct link already exists
5172 */
5173 send_resp(dut, conn, SIGMA_ERROR,
5174 "ErrorCode,Unsupported TDLSmode value");
5175 return 0;
5176 }
5177 }
5178
5179 val = get_param(cmd, "FakePubKey");
5180 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5181 send_resp(dut, conn, SIGMA_ERROR,
5182 "ErrorCode,Failed to enable FakePubKey");
5183 return 0;
5184 }
5185
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005186#ifdef NL80211_SUPPORT
5187 val = get_param(cmd, "FrgmntSupport");
5188 if (val) {
5189 if (strcasecmp(val, "Enable") == 0) {
5190 if (sta_set_he_fragmentation(dut, intf,
5191 HE_FRAG_LEVEL1)) {
5192 send_resp(dut, conn, SIGMA_ERROR,
5193 "ErrorCode,Failed to enable HE Fragmentation");
5194 return 0;
5195 }
5196 } else if (strcasecmp(val, "Disable") == 0) {
5197 if (sta_set_he_fragmentation(dut, intf,
5198 HE_FRAG_DISABLE)) {
5199 send_resp(dut, conn, SIGMA_ERROR,
5200 "ErrorCode,Failed to disable HE Fragmentation");
5201 return 0;
5202 }
5203 }
5204 }
5205#endif /* NL80211_SUPPORT */
5206
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005207 return 1;
5208}
5209
5210
5211static const char * ath_get_radio_name(const char *radio_name)
5212{
5213 if (radio_name == NULL)
5214 return "wifi0";
5215 if (strcmp(radio_name, "wifi1") == 0)
5216 return "wifi1";
5217 if (strcmp(radio_name, "wifi2") == 0)
5218 return "wifi2";
5219 return "wifi0";
5220}
5221
5222
5223static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5224 const char *val)
5225{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005226 unsigned int vht_mcsmap = 0;
5227 int txchainmask = 0;
5228 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5229
5230 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5231 if (dut->testbed_flag_txsp == 1) {
5232 vht_mcsmap = 0xfffc;
5233 dut->testbed_flag_txsp = 0;
5234 } else {
5235 vht_mcsmap = 0xfffe;
5236 }
5237 txchainmask = 1;
5238 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5239 if (dut->testbed_flag_txsp == 1) {
5240 vht_mcsmap = 0xfff0;
5241 dut->testbed_flag_txsp = 0;
5242 } else {
5243 vht_mcsmap = 0xfffa;
5244 }
5245 txchainmask = 3;
5246 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5247 if (dut->testbed_flag_txsp == 1) {
5248 vht_mcsmap = 0xffc0;
5249 dut->testbed_flag_txsp = 0;
5250 } else {
5251 vht_mcsmap = 0xffea;
5252 }
5253 txchainmask = 7;
5254 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5255 if (dut->testbed_flag_txsp == 1) {
5256 vht_mcsmap = 0xff00;
5257 dut->testbed_flag_txsp = 0;
5258 } else {
5259 vht_mcsmap = 0xffaa;
5260 }
5261 txchainmask = 15;
5262 } else {
5263 if (dut->testbed_flag_txsp == 1) {
5264 vht_mcsmap = 0xffc0;
5265 dut->testbed_flag_txsp = 0;
5266 } else {
5267 vht_mcsmap = 0xffea;
5268 }
5269 }
5270
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005271 if (txchainmask)
5272 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005273
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005274 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005275}
5276
5277
5278static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5279 const char *val)
5280{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005281 unsigned int vht_mcsmap = 0;
5282 int rxchainmask = 0;
5283 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5284
5285 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5286 if (dut->testbed_flag_rxsp == 1) {
5287 vht_mcsmap = 0xfffc;
5288 dut->testbed_flag_rxsp = 0;
5289 } else {
5290 vht_mcsmap = 0xfffe;
5291 }
5292 rxchainmask = 1;
5293 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5294 if (dut->testbed_flag_rxsp == 1) {
5295 vht_mcsmap = 0xfff0;
5296 dut->testbed_flag_rxsp = 0;
5297 } else {
5298 vht_mcsmap = 0xfffa;
5299 }
5300 rxchainmask = 3;
5301 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5302 if (dut->testbed_flag_rxsp == 1) {
5303 vht_mcsmap = 0xffc0;
5304 dut->testbed_flag_rxsp = 0;
5305 } else {
5306 vht_mcsmap = 0xffea;
5307 }
5308 rxchainmask = 7;
5309 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5310 if (dut->testbed_flag_rxsp == 1) {
5311 vht_mcsmap = 0xff00;
5312 dut->testbed_flag_rxsp = 0;
5313 } else {
5314 vht_mcsmap = 0xffaa;
5315 }
5316 rxchainmask = 15;
5317 } else {
5318 if (dut->testbed_flag_rxsp == 1) {
5319 vht_mcsmap = 0xffc0;
5320 dut->testbed_flag_rxsp = 0;
5321 } else {
5322 vht_mcsmap = 0xffea;
5323 }
5324 }
5325
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005326 if (rxchainmask)
5327 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005328
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005329 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005330}
5331
5332
5333void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5334{
5335 if (strcasecmp(val, "enable") == 0) {
5336 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5337 != 0) {
5338 sigma_dut_print(dut, DUT_MSG_ERROR,
5339 "Disable BB_VHTSIGB_CRC_CALC failed");
5340 }
5341
5342 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5343 != 0) {
5344 sigma_dut_print(dut, DUT_MSG_ERROR,
5345 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5346 }
5347 } else {
5348 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5349 != 0) {
5350 sigma_dut_print(dut, DUT_MSG_ERROR,
5351 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5352 }
5353
5354 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5355 != 0) {
5356 sigma_dut_print(dut, DUT_MSG_ERROR,
5357 "Enable BB_VHTSIGB_CRC_CALC failed");
5358 }
5359 }
5360}
5361
5362
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005363static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5364 const char *val)
5365{
5366 char buf[60];
5367
5368 if (strcmp(val, "20") == 0) {
5369 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5370 dut->chwidth = 0;
5371 } else if (strcmp(val, "40") == 0) {
5372 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5373 dut->chwidth = 1;
5374 } else if (strcmp(val, "80") == 0) {
5375 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5376 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305377 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005378 buf[0] = '\0';
5379 } else {
5380 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5381 val);
5382 return -1;
5383 }
5384
5385 if (buf[0] != '\0' && system(buf) != 0) {
5386 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5387 return -1;
5388 }
5389
5390 return 0;
5391}
5392
5393
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005394static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5395 const char *intf, int addbareject)
5396{
5397#ifdef NL80211_SUPPORT
5398 struct nl_msg *msg;
5399 int ret = 0;
5400 struct nlattr *params;
5401 int ifindex;
5402
5403 ifindex = if_nametoindex(intf);
5404 if (ifindex == 0) {
5405 sigma_dut_print(dut, DUT_MSG_ERROR,
5406 "%s: Index for interface %s failed",
5407 __func__, intf);
5408 return -1;
5409 }
5410
5411 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5412 NL80211_CMD_VENDOR)) ||
5413 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5414 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5415 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5416 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5417 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5418 nla_put_u8(msg,
5419 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5420 !addbareject)) {
5421 sigma_dut_print(dut, DUT_MSG_ERROR,
5422 "%s: err in adding vendor_cmd and vendor_data",
5423 __func__);
5424 nlmsg_free(msg);
5425 return -1;
5426 }
5427 nla_nest_end(msg, params);
5428
5429 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5430 if (ret) {
5431 sigma_dut_print(dut, DUT_MSG_ERROR,
5432 "%s: err in send_and_recv_msgs, ret=%d",
5433 __func__, ret);
5434 }
5435 return ret;
5436#else /* NL80211_SUPPORT */
5437 sigma_dut_print(dut, DUT_MSG_ERROR,
5438 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5439 return -1;
5440#endif /* NL80211_SUPPORT */
5441}
5442
5443
5444static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5445 int addbareject)
5446{
5447 int ret;
5448
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005449 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005450 case DRIVER_WCN:
5451 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5452 if (ret) {
5453 sigma_dut_print(dut, DUT_MSG_ERROR,
5454 "nlvendor_sta_set_addba_reject failed, ret:%d",
5455 ret);
5456 return ret;
5457 }
5458 break;
5459 default:
5460 sigma_dut_print(dut, DUT_MSG_ERROR,
5461 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5462 ret = -1;
5463 break;
5464 }
5465
5466 return ret;
5467}
5468
5469
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005470static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5471 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005472{
5473#ifdef NL80211_SUPPORT
5474 struct nl_msg *msg;
5475 int ret = 0;
5476 struct nlattr *params;
5477 int ifindex;
5478
5479 ifindex = if_nametoindex(intf);
5480 if (ifindex == 0) {
5481 sigma_dut_print(dut, DUT_MSG_ERROR,
5482 "%s: Index for interface %s failed",
5483 __func__, intf);
5484 return -1;
5485 }
5486
5487 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5488 NL80211_CMD_VENDOR)) ||
5489 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5490 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5491 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5492 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5493 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5494 nla_put_u8(msg,
5495 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005496 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005497 sigma_dut_print(dut, DUT_MSG_ERROR,
5498 "%s: err in adding vendor_cmd and vendor_data",
5499 __func__);
5500 nlmsg_free(msg);
5501 return -1;
5502 }
5503 nla_nest_end(msg, params);
5504
5505 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5506 if (ret) {
5507 sigma_dut_print(dut, DUT_MSG_ERROR,
5508 "%s: err in send_and_recv_msgs, ret=%d",
5509 __func__, ret);
5510 }
5511 return ret;
5512#else /* NL80211_SUPPORT */
5513 sigma_dut_print(dut, DUT_MSG_ERROR,
5514 "Disable addba not possible without NL80211_SUPPORT defined");
5515 return -1;
5516#endif /* NL80211_SUPPORT */
5517}
5518
5519
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305520#ifdef NL80211_SUPPORT
5521static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5522{
5523 struct nl_msg *msg;
5524 int ret = 0;
5525 int ifindex;
5526
5527 ifindex = if_nametoindex(intf);
5528 if (ifindex == 0) {
5529 sigma_dut_print(dut, DUT_MSG_ERROR,
5530 "%s: Index for interface %s failed",
5531 __func__, intf);
5532 return -1;
5533 }
5534
5535 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5536 NL80211_CMD_SET_WIPHY)) ||
5537 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5538 sigma_dut_print(dut, DUT_MSG_ERROR,
5539 "%s: err in adding RTS threshold",
5540 __func__);
5541 nlmsg_free(msg);
5542 return -1;
5543 }
5544
5545 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5546 if (ret) {
5547 sigma_dut_print(dut, DUT_MSG_ERROR,
5548 "%s: err in send_and_recv_msgs, ret=%d",
5549 __func__, ret);
5550 }
5551 return ret;
5552}
5553#endif /* NL80211_SUPPORT */
5554
5555
5556static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5557{
5558 char buf[100];
5559
5560#ifdef NL80211_SUPPORT
5561 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5562 return 0;
5563 sigma_dut_print(dut, DUT_MSG_DEBUG,
5564 "Fall back to using iwconfig for setting RTS threshold");
5565#endif /* NL80211_SUPPORT */
5566
5567 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5568 if (system(buf) != 0) {
5569 sigma_dut_print(dut, DUT_MSG_ERROR,
5570 "Failed to set RTS threshold %d", val);
5571 return -1;
5572 }
5573 return 0;
5574}
5575
5576
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005577static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5578 struct sigma_conn *conn,
5579 struct sigma_cmd *cmd)
5580{
5581 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005582 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005583 char buf[128];
5584 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005585
5586 val = get_param(cmd, "40_INTOLERANT");
5587 if (val) {
5588 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5589 /* TODO: iwpriv ht40intol through wpa_supplicant */
5590 send_resp(dut, conn, SIGMA_ERROR,
5591 "ErrorCode,40_INTOLERANT not supported");
5592 return 0;
5593 }
5594 }
5595
5596 val = get_param(cmd, "ADDBA_REJECT");
5597 if (val) {
5598 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5599 /* reject any ADDBA with status "decline" */
5600 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005601 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005602 } else {
5603 /* accept ADDBA */
5604 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005605 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005606 }
5607 }
5608
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005609 if (addbareject >= 0 &&
5610 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5611 send_resp(dut, conn, SIGMA_ERROR,
5612 "ErrorCode,set addba_reject failed");
5613 return 0;
5614 }
5615
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005616 val = get_param(cmd, "AMPDU");
5617 if (val) {
5618 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5619 /* enable AMPDU Aggregation */
5620 if (ampdu == 0) {
5621 send_resp(dut, conn, SIGMA_ERROR,
5622 "ErrorCode,Mismatch in "
5623 "addba_reject/ampdu - "
5624 "not supported");
5625 return 0;
5626 }
5627 ampdu = 1;
5628 } else {
5629 /* disable AMPDU Aggregation */
5630 if (ampdu == 1) {
5631 send_resp(dut, conn, SIGMA_ERROR,
5632 "ErrorCode,Mismatch in "
5633 "addba_reject/ampdu - "
5634 "not supported");
5635 return 0;
5636 }
5637 ampdu = 0;
5638 }
5639 }
5640
5641 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005642 int ret;
5643
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005644 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5645 ampdu ? "Enabling" : "Disabling");
5646 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005647 if (wpa_command(intf, buf) < 0 &&
5648 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005649 send_resp(dut, conn, SIGMA_ERROR,
5650 "ErrorCode,set aggr failed");
5651 return 0;
5652 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005653
5654 if (ampdu == 0) {
5655 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005656 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005657 if (ret) {
5658 sigma_dut_print(dut, DUT_MSG_ERROR,
5659 "Failed to disable addba, ret:%d",
5660 ret);
5661 }
5662 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005663 }
5664
5665 val = get_param(cmd, "AMSDU");
5666 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005667 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005668 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005669 case DRIVER_WCN:
5670 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005671 break;
5672 default:
5673 if (strcmp(val, "1") == 0 ||
5674 strcasecmp(val, "Enable") == 0) {
5675 /* Enable AMSDU Aggregation */
5676 send_resp(dut, conn, SIGMA_ERROR,
5677 "ErrorCode,AMSDU aggregation not supported");
5678 return 0;
5679 }
5680 break;
5681 }
5682 }
5683
5684 val = get_param(cmd, "STBC_RX");
5685 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005686 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005687 case DRIVER_ATHEROS:
5688 ath_sta_set_stbc(dut, intf, val);
5689 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305690 case DRIVER_WCN:
5691 wcn_sta_set_stbc(dut, intf, val);
5692 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005693 default:
5694 send_resp(dut, conn, SIGMA_ERROR,
5695 "ErrorCode,STBC_RX not supported");
5696 return 0;
5697 }
5698 }
5699
5700 val = get_param(cmd, "WIDTH");
5701 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005702 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005703 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005704 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005705 send_resp(dut, conn, SIGMA_ERROR,
5706 "ErrorCode,Failed to set WIDTH");
5707 return 0;
5708 }
5709 break;
5710 case DRIVER_ATHEROS:
5711 if (ath_set_width(dut, conn, intf, val) < 0)
5712 return 0;
5713 break;
5714 default:
5715 sigma_dut_print(dut, DUT_MSG_ERROR,
5716 "Setting WIDTH not supported");
5717 break;
5718 }
5719 }
5720
5721 val = get_param(cmd, "SMPS");
5722 if (val) {
5723 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5724 send_resp(dut, conn, SIGMA_ERROR,
5725 "ErrorCode,SMPS not supported");
5726 return 0;
5727 }
5728
5729 val = get_param(cmd, "TXSP_STREAM");
5730 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005731 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005732 case DRIVER_WCN:
5733 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5734 send_resp(dut, conn, SIGMA_ERROR,
5735 "ErrorCode,Failed to set TXSP_STREAM");
5736 return 0;
5737 }
5738 break;
5739 case DRIVER_ATHEROS:
5740 ath_sta_set_txsp_stream(dut, intf, val);
5741 break;
5742 default:
5743 sigma_dut_print(dut, DUT_MSG_ERROR,
5744 "Setting TXSP_STREAM not supported");
5745 break;
5746 }
5747 }
5748
5749 val = get_param(cmd, "RXSP_STREAM");
5750 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005751 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005752 case DRIVER_WCN:
5753 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5754 send_resp(dut, conn, SIGMA_ERROR,
5755 "ErrorCode,Failed to set RXSP_STREAM");
5756 return 0;
5757 }
5758 break;
5759 case DRIVER_ATHEROS:
5760 ath_sta_set_rxsp_stream(dut, intf, val);
5761 break;
5762 default:
5763 sigma_dut_print(dut, DUT_MSG_ERROR,
5764 "Setting RXSP_STREAM not supported");
5765 break;
5766 }
5767 }
5768
5769 val = get_param(cmd, "DYN_BW_SGNL");
5770 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005771 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005772 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08005773 if (strcasecmp(val, "enable") == 0) {
5774 snprintf(buf, sizeof(buf),
5775 "iwpriv %s cwmenable 1", intf);
5776 if (system(buf) != 0) {
5777 sigma_dut_print(dut, DUT_MSG_ERROR,
5778 "iwpriv cwmenable 1 failed");
5779 return 0;
5780 }
5781 } else if (strcasecmp(val, "disable") == 0) {
5782 snprintf(buf, sizeof(buf),
5783 "iwpriv %s cwmenable 0", intf);
5784 if (system(buf) != 0) {
5785 sigma_dut_print(dut, DUT_MSG_ERROR,
5786 "iwpriv cwmenable 0 failed");
5787 return 0;
5788 }
5789 } else {
5790 sigma_dut_print(dut, DUT_MSG_ERROR,
5791 "Unsupported DYN_BW_SGL");
5792 }
5793
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005794 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5795 if (system(buf) != 0) {
5796 sigma_dut_print(dut, DUT_MSG_ERROR,
5797 "Failed to set cts_cbw in DYN_BW_SGNL");
5798 return 0;
5799 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005800 break;
5801 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005802 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005803 ath_config_dyn_bw_sig(dut, intf, val);
5804 break;
5805 default:
5806 sigma_dut_print(dut, DUT_MSG_ERROR,
5807 "Failed to set DYN_BW_SGNL");
5808 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005809 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005810 }
5811
5812 val = get_param(cmd, "RTS_FORCE");
5813 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005814 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005815 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305816 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005817 sigma_dut_print(dut, DUT_MSG_ERROR,
5818 "Failed to set RTS_FORCE 64");
5819 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03005820 res = snprintf(buf, sizeof(buf),
5821 "wifitool %s beeliner_fw_test 100 1",
5822 intf);
5823 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08005824 sigma_dut_print(dut, DUT_MSG_ERROR,
5825 "wifitool beeliner_fw_test 100 1 failed");
5826 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005827 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305828 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005829 sigma_dut_print(dut, DUT_MSG_ERROR,
5830 "Failed to set RTS_FORCE 2347");
5831 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005832 } else {
5833 send_resp(dut, conn, SIGMA_ERROR,
5834 "ErrorCode,RTS_FORCE value not supported");
5835 return 0;
5836 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005837 }
5838
5839 val = get_param(cmd, "CTS_WIDTH");
5840 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005841 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005842 case DRIVER_WCN:
5843 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
5844 send_resp(dut, conn, SIGMA_ERROR,
5845 "ErrorCode,Failed to set CTS_WIDTH");
5846 return 0;
5847 }
5848 break;
5849 case DRIVER_ATHEROS:
5850 ath_set_cts_width(dut, intf, val);
5851 break;
5852 default:
5853 sigma_dut_print(dut, DUT_MSG_ERROR,
5854 "Setting CTS_WIDTH not supported");
5855 break;
5856 }
5857 }
5858
5859 val = get_param(cmd, "BW_SGNL");
5860 if (val) {
5861 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005862 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005863 } else if (strcasecmp(val, "Disable") == 0) {
5864 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005865 } else {
5866 send_resp(dut, conn, SIGMA_ERROR,
5867 "ErrorCode,BW_SGNL value not supported");
5868 return 0;
5869 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005870 }
5871
5872 val = get_param(cmd, "Band");
5873 if (val) {
5874 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
5875 /* STA supports all bands by default */
5876 } else {
5877 send_resp(dut, conn, SIGMA_ERROR,
5878 "ErrorCode,Unsupported Band");
5879 return 0;
5880 }
5881 }
5882
5883 val = get_param(cmd, "zero_crc");
5884 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005885 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005886 case DRIVER_ATHEROS:
5887 ath_set_zero_crc(dut, val);
5888 break;
5889 default:
5890 break;
5891 }
5892 }
5893
5894 return 1;
5895}
5896
5897
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005898static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
5899{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005900 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005901#ifdef __linux__
5902 case DRIVER_WIL6210:
5903 return wil6210_set_force_mcs(dut, force, mcs);
5904#endif /* __linux__ */
5905 default:
5906 sigma_dut_print(dut, DUT_MSG_ERROR,
5907 "Unsupported sta_set_force_mcs with the current driver");
5908 return -1;
5909 }
5910}
5911
5912
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005913static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
5914{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005915 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005916#ifdef __linux__
5917 case DRIVER_WIL6210:
5918 return wil6210_force_rsn_ie(dut, state);
5919#endif /* __linux__ */
5920 default:
5921 sigma_dut_print(dut, DUT_MSG_ERROR,
5922 "Unsupported sta_60g_force_rsn_ie with the current driver");
5923 return -1;
5924 }
5925}
5926
5927
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005928static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
5929 struct sigma_cmd *cmd)
5930{
5931 const char *val;
5932 char buf[100];
5933
5934 val = get_param(cmd, "MSDUSize");
5935 if (val) {
5936 int mtu;
5937
5938 dut->amsdu_size = atoi(val);
5939 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
5940 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
5941 sigma_dut_print(dut, DUT_MSG_ERROR,
5942 "MSDUSize %d is above max %d or below min %d",
5943 dut->amsdu_size,
5944 IEEE80211_MAX_DATA_LEN_DMG,
5945 IEEE80211_SNAP_LEN_DMG);
5946 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005947 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005948 }
5949
5950 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
5951 sigma_dut_print(dut, DUT_MSG_DEBUG,
5952 "Setting amsdu_size to %d", mtu);
5953 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005954 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005955
5956 if (system(buf) != 0) {
5957 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
5958 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005959 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005960 }
5961 }
5962
5963 val = get_param(cmd, "BAckRcvBuf");
5964 if (val) {
5965 dut->back_rcv_buf = atoi(val);
5966 if (dut->back_rcv_buf == 0) {
5967 sigma_dut_print(dut, DUT_MSG_ERROR,
5968 "Failed to convert %s or value is 0",
5969 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005970 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005971 }
5972
5973 sigma_dut_print(dut, DUT_MSG_DEBUG,
5974 "Setting BAckRcvBuf to %s", val);
5975 }
5976
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005977 val = get_param(cmd, "MCS_FixedRate");
5978 if (val) {
5979 if (sta_set_force_mcs(dut, 1, atoi(val))) {
5980 sigma_dut_print(dut, DUT_MSG_ERROR,
5981 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005982 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005983 }
5984 }
5985
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005986 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005987}
5988
5989
5990static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
5991 struct sigma_cmd *cmd)
5992{
5993 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005994 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005995 const char *val;
5996 char buf[100];
5997
5998 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005999 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006000 if (wpa_command(ifname, "PING") != 0) {
6001 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006002 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006003 }
6004
6005 wpa_command(ifname, "FLUSH");
6006 net_id = add_network_common(dut, conn, ifname, cmd);
6007 if (net_id < 0) {
6008 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
6009 return net_id;
6010 }
6011
6012 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
6013 if (set_network(ifname, net_id, "mode", "2") < 0) {
6014 sigma_dut_print(dut, DUT_MSG_ERROR,
6015 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006016 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006017 }
6018
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006019 if (set_network(ifname, net_id, "pbss", "1") < 0)
6020 return -2;
6021
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006022 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006023 "Supplicant set network with mode 2. network_id %d",
6024 net_id);
6025
6026 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6027 sigma_dut_print(dut, DUT_MSG_INFO,
6028 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006029 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006030 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006031
6032 val = get_param(cmd, "Security");
6033 if (val && strcasecmp(val, "OPEN") == 0) {
6034 dut->ap_key_mgmt = AP_OPEN;
6035 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6036 sigma_dut_print(dut, DUT_MSG_ERROR,
6037 "Failed to set supplicant to %s security",
6038 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006039 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006040 }
6041 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6042 dut->ap_key_mgmt = AP_WPA2_PSK;
6043 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6044 sigma_dut_print(dut, DUT_MSG_ERROR,
6045 "Failed to set supplicant to %s security",
6046 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006047 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006048 }
6049
6050 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6051 sigma_dut_print(dut, DUT_MSG_ERROR,
6052 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006053 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006054 }
6055 } else if (val) {
6056 sigma_dut_print(dut, DUT_MSG_ERROR,
6057 "Requested Security %s is not supported on 60GHz",
6058 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006059 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006060 }
6061
6062 val = get_param(cmd, "Encrypt");
6063 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6064 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6065 sigma_dut_print(dut, DUT_MSG_ERROR,
6066 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006067 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006068 }
6069 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6070 sigma_dut_print(dut, DUT_MSG_ERROR,
6071 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006072 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006073 }
6074 } else if (val) {
6075 sigma_dut_print(dut, DUT_MSG_ERROR,
6076 "Requested Encrypt %s is not supported on 60 GHz",
6077 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006078 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006079 }
6080
6081 val = get_param(cmd, "PSK");
6082 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6083 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6084 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006085 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006086 }
6087
6088 /* Convert 60G channel to freq */
6089 switch (dut->ap_channel) {
6090 case 1:
6091 val = "58320";
6092 break;
6093 case 2:
6094 val = "60480";
6095 break;
6096 case 3:
6097 val = "62640";
6098 break;
6099 default:
6100 sigma_dut_print(dut, DUT_MSG_ERROR,
6101 "Failed to configure channel %d. Not supported",
6102 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006103 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006104 }
6105
6106 if (set_network(ifname, net_id, "frequency", val) < 0) {
6107 sigma_dut_print(dut, DUT_MSG_ERROR,
6108 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006109 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006110 }
6111
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006112 if (dut->eap_fragment) {
6113 sigma_dut_print(dut, DUT_MSG_DEBUG,
6114 "Set EAP fragment size to 128 bytes.");
6115 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6116 return ERROR_SEND_STATUS;
6117 }
6118
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006119 sigma_dut_print(dut, DUT_MSG_DEBUG,
6120 "Supplicant set network with frequency");
6121
6122 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6123 if (wpa_command(ifname, buf) < 0) {
6124 sigma_dut_print(dut, DUT_MSG_INFO,
6125 "Failed to select network id %d on %s",
6126 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006127 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006128 }
6129
6130 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6131
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006132 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006133}
6134
6135
Lior David67543f52017-01-03 19:04:22 +02006136static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6137{
6138 char buf[128], fname[128];
6139 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006140 int res;
Lior David67543f52017-01-03 19:04:22 +02006141
6142 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6143 sigma_dut_print(dut, DUT_MSG_ERROR,
6144 "failed to get wil6210 debugfs dir");
6145 return -1;
6146 }
6147
Jouni Malinen3aa72862019-05-29 23:14:51 +03006148 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6149 if (res < 0 || res >= sizeof(fname))
6150 return -1;
Lior David67543f52017-01-03 19:04:22 +02006151 f = fopen(fname, "w");
6152 if (!f) {
6153 sigma_dut_print(dut, DUT_MSG_ERROR,
6154 "failed to open: %s", fname);
6155 return -1;
6156 }
6157
6158 fprintf(f, "%d\n", abft_len);
6159 fclose(f);
6160
6161 return 0;
6162}
6163
6164
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006165int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6166 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006167{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006168 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006169 case DRIVER_WIL6210:
6170 return wil6210_set_abft_len(dut, abft_len);
6171 default:
6172 sigma_dut_print(dut, DUT_MSG_ERROR,
6173 "set abft_len not supported");
6174 return -1;
6175 }
6176}
6177
6178
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006179static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6180 struct sigma_cmd *cmd)
6181{
6182 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006183 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006184
6185 if (dut->dev_role != DEVROLE_PCP) {
6186 send_resp(dut, conn, SIGMA_INVALID,
6187 "ErrorCode,Invalid DevRole");
6188 return 0;
6189 }
6190
6191 val = get_param(cmd, "SSID");
6192 if (val) {
6193 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6194 send_resp(dut, conn, SIGMA_INVALID,
6195 "ErrorCode,Invalid SSID");
6196 return -1;
6197 }
6198
Peng Xub8fc5cc2017-05-10 17:27:28 -07006199 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006200 }
6201
6202 val = get_param(cmd, "CHANNEL");
6203 if (val) {
6204 const char *pos;
6205
6206 dut->ap_channel = atoi(val);
6207 pos = strchr(val, ';');
6208 if (pos) {
6209 pos++;
6210 dut->ap_channel_1 = atoi(pos);
6211 }
6212 }
6213
6214 switch (dut->ap_channel) {
6215 case 1:
6216 case 2:
6217 case 3:
6218 break;
6219 default:
6220 sigma_dut_print(dut, DUT_MSG_ERROR,
6221 "Channel %d is not supported", dut->ap_channel);
6222 send_resp(dut, conn, SIGMA_ERROR,
6223 "Requested channel is not supported");
6224 return -1;
6225 }
6226
6227 val = get_param(cmd, "BCNINT");
6228 if (val)
6229 dut->ap_bcnint = atoi(val);
6230
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006231 val = get_param(cmd, "AllocType");
6232 if (val) {
6233 send_resp(dut, conn, SIGMA_ERROR,
6234 "ErrorCode,AllocType is not supported yet");
6235 return -1;
6236 }
6237
6238 val = get_param(cmd, "PercentBI");
6239 if (val) {
6240 send_resp(dut, conn, SIGMA_ERROR,
6241 "ErrorCode,PercentBI is not supported yet");
6242 return -1;
6243 }
6244
6245 val = get_param(cmd, "CBAPOnly");
6246 if (val) {
6247 send_resp(dut, conn, SIGMA_ERROR,
6248 "ErrorCode,CBAPOnly is not supported yet");
6249 return -1;
6250 }
6251
6252 val = get_param(cmd, "AMPDU");
6253 if (val) {
6254 if (strcasecmp(val, "Enable") == 0)
6255 dut->ap_ampdu = 1;
6256 else if (strcasecmp(val, "Disable") == 0)
6257 dut->ap_ampdu = 2;
6258 else {
6259 send_resp(dut, conn, SIGMA_ERROR,
6260 "ErrorCode,AMPDU value is not Enable nor Disabled");
6261 return -1;
6262 }
6263 }
6264
6265 val = get_param(cmd, "AMSDU");
6266 if (val) {
6267 if (strcasecmp(val, "Enable") == 0)
6268 dut->ap_amsdu = 1;
6269 else if (strcasecmp(val, "Disable") == 0)
6270 dut->ap_amsdu = 2;
6271 }
6272
6273 val = get_param(cmd, "NumMSDU");
6274 if (val) {
6275 send_resp(dut, conn, SIGMA_ERROR,
6276 "ErrorCode, NumMSDU is not supported yet");
6277 return -1;
6278 }
6279
6280 val = get_param(cmd, "ABFTLRang");
6281 if (val) {
6282 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006283 "ABFTLRang parameter %s", val);
6284 if (strcmp(val, "Gt1") == 0)
6285 abft_len = 2; /* 2 slots in this case */
6286 }
6287
6288 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6289 send_resp(dut, conn, SIGMA_ERROR,
6290 "ErrorCode, Can't set ABFT length");
6291 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006292 }
6293
6294 if (sta_pcp_start(dut, conn, cmd) < 0) {
6295 send_resp(dut, conn, SIGMA_ERROR,
6296 "ErrorCode, Can't start PCP role");
6297 return -1;
6298 }
6299
6300 return sta_set_60g_common(dut, conn, cmd);
6301}
6302
6303
6304static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6305 struct sigma_cmd *cmd)
6306{
6307 const char *val = get_param(cmd, "DiscoveryMode");
6308
6309 if (dut->dev_role != DEVROLE_STA) {
6310 send_resp(dut, conn, SIGMA_INVALID,
6311 "ErrorCode,Invalid DevRole");
6312 return 0;
6313 }
6314
6315 if (val) {
6316 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6317 /* Ignore Discovery mode till Driver expose API. */
6318#if 0
6319 if (strcasecmp(val, "1") == 0) {
6320 send_resp(dut, conn, SIGMA_INVALID,
6321 "ErrorCode,DiscoveryMode 1 not supported");
6322 return 0;
6323 }
6324
6325 if (strcasecmp(val, "0") == 0) {
6326 /* OK */
6327 } else {
6328 send_resp(dut, conn, SIGMA_INVALID,
6329 "ErrorCode,DiscoveryMode not supported");
6330 return 0;
6331 }
6332#endif
6333 }
6334
6335 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006336 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006337 return sta_set_60g_common(dut, conn, cmd);
6338}
6339
6340
Jouni Malinenf7222712019-06-13 01:50:21 +03006341static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6342 struct sigma_conn *conn,
6343 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006344{
6345 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006346 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306347
Jouni Malinened77e672018-01-10 16:45:13 +02006348 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006349 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006350 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306351 wpa_command(intf, "DISCONNECT");
6352 return 1;
6353 }
6354
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006355 disconnect_station(dut);
6356 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6357 * due to cached results. */
6358 wpa_command(intf, "SET ignore_old_scan_res 1");
6359 wpa_command(intf, "BSS_FLUSH");
6360 return 1;
6361}
6362
6363
Jouni Malinenf7222712019-06-13 01:50:21 +03006364static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6365 struct sigma_conn *conn,
6366 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006367{
6368 const char *intf = get_param(cmd, "Interface");
6369 const char *bssid = get_param(cmd, "bssid");
6370 const char *val = get_param(cmd, "CHANNEL");
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006371 const char *freq_val = get_param(cmd, "ChnlFreq");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006372 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306373 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306374 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006375 int res;
6376 int chan = 0;
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006377 int freq = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006378 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306379 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006380 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006381
6382 if (bssid == NULL) {
6383 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6384 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006385 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006386 }
6387
6388 if (val)
6389 chan = atoi(val);
6390
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006391 if (freq_val)
6392 freq = atoi(freq_val);
6393
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006394 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6395 /* The current network may be from sta_associate or
6396 * sta_hs2_associate
6397 */
6398 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6399 0 ||
6400 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006401 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006402 }
6403
6404 ctrl = open_wpa_mon(intf);
6405 if (ctrl == NULL) {
6406 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6407 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006408 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006409 }
6410
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006411 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05306412 sizeof(result)) < 0 ||
6413 strncmp(result, "COMPLETED", 9) != 0) {
6414 sigma_dut_print(dut, DUT_MSG_DEBUG,
6415 "sta_reassoc: Not connected");
6416 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006417 } else if (dut->sta_ft_ds) {
6418 sigma_dut_print(dut, DUT_MSG_DEBUG,
6419 "sta_reassoc: Use FT-over-DS");
6420 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306421 }
6422
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306423 if (dut->rsne_override) {
6424#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006425 if (get_driver_type(dut) == DRIVER_WCN &&
6426 dut->config_rsnie == 0) {
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306427 sta_config_rsnie(dut, 1);
6428 dut->config_rsnie = 1;
6429 }
6430#endif /* NL80211_SUPPORT */
6431 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6432 dut->rsne_override);
6433 if (wpa_command(intf, buf) < 0) {
6434 send_resp(dut, conn, SIGMA_ERROR,
6435 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6436 return 0;
6437 }
6438 }
6439
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006440 if (ft_ds) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006441 if (chan || freq) {
6442 if (!freq)
6443 freq = channel_to_freq(dut, chan);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006444 if (!freq) {
6445 sigma_dut_print(dut, DUT_MSG_ERROR,
6446 "Invalid channel number provided: %d",
6447 chan);
6448 send_resp(dut, conn, SIGMA_INVALID,
6449 "ErrorCode,Invalid channel number");
6450 goto close_mon_conn;
6451 }
6452 res = snprintf(buf, sizeof(buf),
6453 "SCAN TYPE=ONLY freq=%d", freq);
6454 } else {
6455 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6456 }
6457 if (res < 0 || res >= (int) sizeof(buf)) {
6458 send_resp(dut, conn, SIGMA_ERROR,
6459 "ErrorCode,snprintf failed");
6460 goto close_mon_conn;
6461 }
6462 if (wpa_command(intf, buf) < 0) {
6463 sigma_dut_print(dut, DUT_MSG_INFO,
6464 "Failed to start scan");
6465 send_resp(dut, conn, SIGMA_ERROR,
6466 "ErrorCode,scan failed");
6467 goto close_mon_conn;
6468 }
6469
6470 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6471 buf, sizeof(buf));
6472 if (res < 0) {
6473 sigma_dut_print(dut, DUT_MSG_INFO,
6474 "Scan did not complete");
6475 send_resp(dut, conn, SIGMA_ERROR,
6476 "ErrorCode,scan did not complete");
6477 goto close_mon_conn;
6478 }
6479
6480 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6481 if (res > 0 && res < (int) sizeof(buf))
6482 res = wpa_command(intf, buf);
6483
6484 if (res < 0 || res >= (int) sizeof(buf)) {
6485 send_resp(dut, conn, SIGMA_ERROR,
6486 "errorCode,FT_DS command failed");
6487 status = STATUS_SENT_ERROR;
6488 goto close_mon_conn;
6489 }
6490 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006491 if (chan || freq) {
6492 if (!freq)
6493 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306494 if (!freq) {
6495 sigma_dut_print(dut, DUT_MSG_ERROR,
6496 "Invalid channel number provided: %d",
6497 chan);
6498 send_resp(dut, conn, SIGMA_INVALID,
6499 "ErrorCode,Invalid channel number");
6500 goto close_mon_conn;
6501 }
6502 res = snprintf(buf, sizeof(buf),
6503 "SCAN TYPE=ONLY freq=%d", freq);
6504 } else {
6505 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6506 }
6507 if (res < 0 || res >= (int) sizeof(buf)) {
6508 send_resp(dut, conn, SIGMA_ERROR,
6509 "ErrorCode,snprintf failed");
6510 goto close_mon_conn;
6511 }
6512 if (wpa_command(intf, buf) < 0) {
6513 sigma_dut_print(dut, DUT_MSG_INFO,
6514 "Failed to start scan");
6515 send_resp(dut, conn, SIGMA_ERROR,
6516 "ErrorCode,scan failed");
6517 goto close_mon_conn;
6518 }
6519
6520 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6521 buf, sizeof(buf));
6522 if (res < 0) {
6523 sigma_dut_print(dut, DUT_MSG_INFO,
6524 "Scan did not complete");
6525 send_resp(dut, conn, SIGMA_ERROR,
6526 "ErrorCode,scan did not complete");
6527 goto close_mon_conn;
6528 }
6529
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006530 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6531 < 0) {
6532 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6533 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006534 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306535 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006536 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306537 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006538 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306539 if (res < 0 || res >= (int) sizeof(buf) ||
6540 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006541 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306542 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306543 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006544 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006545 sigma_dut_print(dut, DUT_MSG_INFO,
6546 "sta_reassoc: Run %s successful", buf);
6547 } else if (wpa_command(intf, "REASSOCIATE")) {
6548 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6549 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306550 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006551 }
6552
6553 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6554 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306555 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006556 send_resp(dut, conn, SIGMA_ERROR,
6557 "errorCode,Connection did not complete");
6558 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306559 goto close_mon_conn;
6560 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006561 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006562
Ashwini Patil467efef2017-05-25 12:18:27 +05306563close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006564 wpa_ctrl_detach(ctrl);
6565 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306566 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006567}
6568
6569
6570static void hs2_clear_credentials(const char *intf)
6571{
6572 wpa_command(intf, "REMOVE_CRED all");
6573}
6574
6575
Lior Davidcc88b562017-01-03 18:52:09 +02006576#ifdef __linux__
6577static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6578 unsigned int *aid)
6579{
Lior David0fe101e2017-03-09 16:09:50 +02006580 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006581
Lior David0fe101e2017-03-09 16:09:50 +02006582 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006583}
6584#endif /* __linux__ */
6585
6586
6587static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6588 unsigned int *aid)
6589{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006590 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02006591#ifdef __linux__
6592 case DRIVER_WIL6210:
6593 return wil6210_get_aid(dut, bssid, aid);
6594#endif /* __linux__ */
6595 default:
6596 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6597 return -1;
6598 }
6599}
6600
6601
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006602static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6603 struct sigma_cmd *cmd)
6604{
6605 char buf[MAX_CMD_LEN];
6606 char bss_list[MAX_CMD_LEN];
6607 const char *parameter = get_param(cmd, "Parameter");
6608
6609 if (parameter == NULL)
6610 return -1;
6611
Lior Davidcc88b562017-01-03 18:52:09 +02006612 if (strcasecmp(parameter, "AID") == 0) {
6613 unsigned int aid = 0;
6614 char bssid[20];
6615
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006616 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02006617 bssid, sizeof(bssid)) < 0) {
6618 sigma_dut_print(dut, DUT_MSG_ERROR,
6619 "could not get bssid");
6620 return -2;
6621 }
6622
6623 if (sta_get_aid_60g(dut, bssid, &aid))
6624 return -2;
6625
6626 snprintf(buf, sizeof(buf), "aid,%d", aid);
6627 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6628 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6629 return 0;
6630 }
6631
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006632 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6633 char *bss_line;
6634 char *bss_id = NULL;
6635 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306636 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006637
6638 if (ifname == NULL) {
6639 sigma_dut_print(dut, DUT_MSG_INFO,
6640 "For get DiscoveredDevList need Interface name.");
6641 return -1;
6642 }
6643
6644 /*
6645 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6646 * of BSSIDs in "bssid=<BSSID>\n"
6647 */
6648 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6649 bss_list,
6650 sizeof(bss_list)) < 0) {
6651 sigma_dut_print(dut, DUT_MSG_ERROR,
6652 "Failed to get bss list");
6653 return -1;
6654 }
6655
6656 sigma_dut_print(dut, DUT_MSG_DEBUG,
6657 "bss list for ifname:%s is:%s",
6658 ifname, bss_list);
6659
6660 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306661 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006662 while (bss_line) {
6663 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6664 bss_id) {
6665 int len;
6666
6667 len = snprintf(buf + strlen(buf),
6668 sizeof(buf) - strlen(buf),
6669 ",%s", bss_id);
6670 free(bss_id);
6671 bss_id = NULL;
6672 if (len < 0) {
6673 sigma_dut_print(dut,
6674 DUT_MSG_ERROR,
6675 "Failed to read BSSID");
6676 send_resp(dut, conn, SIGMA_ERROR,
6677 "ErrorCode,Failed to read BSS ID");
6678 return 0;
6679 }
6680
6681 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6682 sigma_dut_print(dut,
6683 DUT_MSG_ERROR,
6684 "Response buf too small for list");
6685 send_resp(dut, conn,
6686 SIGMA_ERROR,
6687 "ErrorCode,Response buf too small for list");
6688 return 0;
6689 }
6690 }
6691
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306692 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006693 }
6694
6695 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6696 buf);
6697 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6698 return 0;
6699 }
6700
6701 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6702 return 0;
6703}
6704
6705
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006706static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6707 struct sigma_cmd *cmd)
6708{
6709 char buf[MAX_CMD_LEN];
6710 const char *parameter = get_param(cmd, "Parameter");
6711
6712 if (!parameter)
6713 return -1;
6714
6715 if (strcasecmp(parameter, "RSSI") == 0) {
6716 char rssi[10];
6717
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006718 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006719 rssi, sizeof(rssi)) < 0) {
6720 sigma_dut_print(dut, DUT_MSG_ERROR,
6721 "Could not get RSSI");
6722 return -2;
6723 }
6724
6725 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6726 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6727 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6728 return 0;
6729 }
6730
6731 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6732 return 0;
6733}
6734
6735
Jouni Malinenca0abd32020-02-09 20:18:10 +02006736static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
6737 struct sigma_conn *conn,
6738 struct sigma_cmd *cmd)
6739{
6740 const char *intf = get_param(cmd, "Interface");
6741 char buf[4096], bssid[20], resp[200], *pos, *tmp;
6742
6743 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
6744 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
6745 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
6746 send_resp(dut, conn, SIGMA_ERROR,
6747 "ErrorCode,PMKSA_GET not supported");
6748 return STATUS_SENT_ERROR;
6749 }
6750
6751 if (strncmp(buf, "FAIL", 4) == 0 ||
6752 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
6753 send_resp(dut, conn, SIGMA_ERROR,
6754 "ErrorCode,Could not find current network");
6755 return STATUS_SENT_ERROR;
6756 }
6757
6758 pos = buf;
6759 while (pos) {
6760 if (strncmp(pos, bssid, 17) == 0) {
6761 pos = strchr(pos, ' ');
6762 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05306763 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02006764 pos++;
6765 pos = strchr(pos, ' ');
6766 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05306767 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02006768 pos++;
6769 tmp = strchr(pos, ' ');
6770 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05306771 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02006772 *tmp = '\0';
6773 break;
6774 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02006775 pos = strchr(pos, '\n');
6776 if (pos)
6777 pos++;
6778 }
6779
6780 if (!pos) {
6781 send_resp(dut, conn, SIGMA_ERROR,
6782 "ErrorCode,PMK not available");
6783 return STATUS_SENT_ERROR;
6784 }
6785
6786 snprintf(resp, sizeof(resp), "PMK,%s", pos);
6787 send_resp(dut, conn, SIGMA_COMPLETE, resp);
6788 return STATUS_SENT;
6789}
6790
6791
Jouni Malinenf7222712019-06-13 01:50:21 +03006792static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
6793 struct sigma_conn *conn,
6794 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006795{
6796 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02006797 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006798
Jouni Malinenca0abd32020-02-09 20:18:10 +02006799 if (!parameter)
6800 return INVALID_SEND_STATUS;
6801
6802 if (strcasecmp(parameter, "PMK") == 0)
6803 return sta_get_pmk(dut, conn, cmd);
6804
6805 if (!program)
6806 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006807
6808 if (strcasecmp(program, "P2PNFC") == 0)
6809 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
6810
6811 if (strcasecmp(program, "60ghz") == 0)
6812 return sta_get_parameter_60g(dut, conn, cmd);
6813
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006814 if (strcasecmp(program, "he") == 0)
6815 return sta_get_parameter_he(dut, conn, cmd);
6816
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006817#ifdef ANDROID_NAN
6818 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07006819 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006820#endif /* ANDROID_NAN */
6821
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006822#ifdef MIRACAST
6823 if (strcasecmp(program, "WFD") == 0 ||
6824 strcasecmp(program, "DisplayR2") == 0)
6825 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
6826#endif /* MIRACAST */
6827
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006828 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6829 return 0;
6830}
6831
6832
6833static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
6834 const char *type)
6835{
6836 char buf[100];
6837
6838 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006839 run_iwpriv(dut, intf, "chwidth 2");
6840 run_iwpriv(dut, intf, "mode 11ACVHT80");
6841 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006842 }
6843
6844 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006845 run_iwpriv(dut, intf, "chwidth 0");
6846 run_iwpriv(dut, intf, "mode 11naht40");
6847 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006848 }
6849
6850 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006851 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006852
6853 /* Reset CTS width */
6854 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
6855 intf);
6856 if (system(buf) != 0) {
6857 sigma_dut_print(dut, DUT_MSG_ERROR,
6858 "wifitool %s beeliner_fw_test 54 0 failed",
6859 intf);
6860 }
6861
6862 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006863 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006864
6865 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
6866 if (system(buf) != 0) {
6867 sigma_dut_print(dut, DUT_MSG_ERROR,
6868 "iwpriv rts failed");
6869 }
6870 }
6871
6872 if (type && strcasecmp(type, "Testbed") == 0) {
6873 dut->testbed_flag_txsp = 1;
6874 dut->testbed_flag_rxsp = 1;
6875 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006876 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006877
6878 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006879 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006880
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006881 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006882
6883 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006884 run_iwpriv(dut, intf, "tx_stbc 0");
6885 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006886
6887 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006888 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006889 }
6890
6891 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006892 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07006893 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006894
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006895 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006896 }
6897}
6898
6899
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006900#ifdef NL80211_SUPPORT
6901static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
6902 enum he_mcs_config mcs)
6903{
6904 struct nl_msg *msg;
6905 int ret = 0;
6906 struct nlattr *params;
6907 int ifindex;
6908
6909 ifindex = if_nametoindex(intf);
6910 if (ifindex == 0) {
6911 sigma_dut_print(dut, DUT_MSG_ERROR,
6912 "%s: Index for interface %s failed",
6913 __func__, intf);
6914 return -1;
6915 }
6916
6917 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6918 NL80211_CMD_VENDOR)) ||
6919 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6920 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6921 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6922 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6923 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6924 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
6925 mcs)) {
6926 sigma_dut_print(dut, DUT_MSG_ERROR,
6927 "%s: err in adding vendor_cmd and vendor_data",
6928 __func__);
6929 nlmsg_free(msg);
6930 return -1;
6931 }
6932 nla_nest_end(msg, params);
6933
6934 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6935 if (ret) {
6936 sigma_dut_print(dut, DUT_MSG_ERROR,
6937 "%s: err in send_and_recv_msgs, ret=%d",
6938 __func__, ret);
6939 }
6940 return ret;
6941}
6942#endif /* NL80211_SUPPORT */
6943
6944
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07006945static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
6946 const char *intf, int enable)
6947{
6948#ifdef NL80211_SUPPORT
6949 struct nl_msg *msg;
6950 int ret = 0;
6951 struct nlattr *params;
6952 int ifindex;
6953
6954 ifindex = if_nametoindex(intf);
6955 if (ifindex == 0) {
6956 sigma_dut_print(dut, DUT_MSG_ERROR,
6957 "%s: Index for interface %s failed",
6958 __func__, intf);
6959 return -1;
6960 }
6961
6962 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6963 NL80211_CMD_VENDOR)) ||
6964 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6965 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6966 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6967 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6968 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6969 nla_put_u8(msg,
6970 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
6971 enable)) {
6972 sigma_dut_print(dut, DUT_MSG_ERROR,
6973 "%s: err in adding vendor_cmd and vendor_data",
6974 __func__);
6975 nlmsg_free(msg);
6976 return -1;
6977 }
6978 nla_nest_end(msg, params);
6979
6980 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6981 if (ret) {
6982 sigma_dut_print(dut, DUT_MSG_ERROR,
6983 "%s: err in send_and_recv_msgs, ret=%d",
6984 __func__, ret);
6985 }
6986 return ret;
6987#else /* NL80211_SUPPORT */
6988 sigma_dut_print(dut, DUT_MSG_ERROR,
6989 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
6990 return -1;
6991#endif /* NL80211_SUPPORT */
6992}
6993
6994
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08006995static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
6996 const char *intf, int enable)
6997{
6998#ifdef NL80211_SUPPORT
6999 struct nl_msg *msg;
7000 int ret = 0;
7001 struct nlattr *params;
7002 int ifindex;
7003
7004 ifindex = if_nametoindex(intf);
7005 if (ifindex == 0) {
7006 sigma_dut_print(dut, DUT_MSG_ERROR,
7007 "%s: Index for interface %s failed",
7008 __func__, intf);
7009 return -1;
7010 }
7011
7012 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7013 NL80211_CMD_VENDOR)) ||
7014 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7015 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7016 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7017 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7018 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7019 nla_put_u8(msg,
7020 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7021 enable)) {
7022 sigma_dut_print(dut, DUT_MSG_ERROR,
7023 "%s: err in adding vendor_cmd and vendor_data",
7024 __func__);
7025 nlmsg_free(msg);
7026 return -1;
7027 }
7028 nla_nest_end(msg, params);
7029
7030 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7031 if (ret) {
7032 sigma_dut_print(dut, DUT_MSG_ERROR,
7033 "%s: err in send_and_recv_msgs, ret=%d",
7034 __func__, ret);
7035 }
7036 return ret;
7037#else /* NL80211_SUPPORT */
7038 sigma_dut_print(dut, DUT_MSG_ERROR,
7039 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7040 return -1;
7041#endif /* NL80211_SUPPORT */
7042}
7043
7044
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007045#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007046
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007047static int sta_set_he_testbed_def(struct sigma_dut *dut,
7048 const char *intf, int cfg)
7049{
7050 struct nl_msg *msg;
7051 int ret = 0;
7052 struct nlattr *params;
7053 int ifindex;
7054
7055 ifindex = if_nametoindex(intf);
7056 if (ifindex == 0) {
7057 sigma_dut_print(dut, DUT_MSG_ERROR,
7058 "%s: Index for interface %s failed",
7059 __func__, intf);
7060 return -1;
7061 }
7062
7063 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7064 NL80211_CMD_VENDOR)) ||
7065 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7066 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7067 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7068 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7069 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7070 nla_put_u8(msg,
7071 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7072 cfg)) {
7073 sigma_dut_print(dut, DUT_MSG_ERROR,
7074 "%s: err in adding vendor_cmd and vendor_data",
7075 __func__);
7076 nlmsg_free(msg);
7077 return -1;
7078 }
7079 nla_nest_end(msg, params);
7080
7081 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7082 if (ret) {
7083 sigma_dut_print(dut, DUT_MSG_ERROR,
7084 "%s: err in send_and_recv_msgs, ret=%d",
7085 __func__, ret);
7086 }
7087 return ret;
7088}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007089
7090
7091static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7092{
7093 struct nl_msg *msg;
7094 int ret = 0;
7095 struct nlattr *params;
7096 int ifindex;
7097
7098 ifindex = if_nametoindex(intf);
7099 if (ifindex == 0) {
7100 sigma_dut_print(dut, DUT_MSG_ERROR,
7101 "%s: Index for interface %s failed",
7102 __func__, intf);
7103 return -1;
7104 }
7105
7106 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7107 NL80211_CMD_VENDOR)) ||
7108 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7109 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7110 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7111 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7112 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7113 nla_put_u8(msg,
7114 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7115 cfg)) {
7116 sigma_dut_print(dut, DUT_MSG_ERROR,
7117 "%s: err in adding vendor_cmd and vendor_data",
7118 __func__);
7119 nlmsg_free(msg);
7120 return -1;
7121 }
7122 nla_nest_end(msg, params);
7123
7124 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7125 if (ret) {
7126 sigma_dut_print(dut, DUT_MSG_ERROR,
7127 "%s: err in send_and_recv_msgs, ret=%d",
7128 __func__, ret);
7129 }
7130 return ret;
7131}
7132
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007133#endif /* NL80211_SUPPORT */
7134
7135
Qiwei Caib6806972020-01-15 13:52:11 +08007136int sta_set_addba_buf_size(struct sigma_dut *dut,
7137 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007138{
7139#ifdef NL80211_SUPPORT
7140 struct nl_msg *msg;
7141 int ret = 0;
7142 struct nlattr *params;
7143 int ifindex;
7144
7145 ifindex = if_nametoindex(intf);
7146 if (ifindex == 0) {
7147 sigma_dut_print(dut, DUT_MSG_ERROR,
7148 "%s: Index for interface %s failed",
7149 __func__, intf);
7150 return -1;
7151 }
7152
7153 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7154 NL80211_CMD_VENDOR)) ||
7155 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7156 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7157 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7158 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7159 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07007160 nla_put_u16(msg,
7161 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
7162 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007163 sigma_dut_print(dut, DUT_MSG_ERROR,
7164 "%s: err in adding vendor_cmd and vendor_data",
7165 __func__);
7166 nlmsg_free(msg);
7167 return -1;
7168 }
7169 nla_nest_end(msg, params);
7170
7171 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7172 if (ret) {
7173 sigma_dut_print(dut, DUT_MSG_ERROR,
7174 "%s: err in send_and_recv_msgs, ret=%d",
7175 __func__, ret);
7176 }
7177 return ret;
7178#else /* NL80211_SUPPORT */
7179 sigma_dut_print(dut, DUT_MSG_ERROR,
7180 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7181 return -1;
7182#endif /* NL80211_SUPPORT */
7183}
7184
7185
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007186static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
7187 int enable)
7188{
7189#ifdef NL80211_SUPPORT
7190 struct nl_msg *msg;
7191 int ret = 0;
7192 struct nlattr *params;
7193 int ifindex;
7194
7195 ifindex = if_nametoindex(intf);
7196 if (ifindex == 0) {
7197 sigma_dut_print(dut, DUT_MSG_ERROR,
7198 "%s: Index for interface %s failed",
7199 __func__, intf);
7200 return -1;
7201 }
7202
7203 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7204 NL80211_CMD_VENDOR)) ||
7205 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7206 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7207 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7208 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7209 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7210 nla_put_u8(msg,
7211 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7212 enable)) {
7213 sigma_dut_print(dut, DUT_MSG_ERROR,
7214 "%s: err in adding vendor_cmd and vendor_data",
7215 __func__);
7216 nlmsg_free(msg);
7217 return -1;
7218 }
7219 nla_nest_end(msg, params);
7220
7221 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7222 if (ret) {
7223 sigma_dut_print(dut, DUT_MSG_ERROR,
7224 "%s: err in send_and_recv_msgs, ret=%d",
7225 __func__, ret);
7226 }
7227 return ret;
7228#else /* NL80211_SUPPORT */
7229 sigma_dut_print(dut, DUT_MSG_ERROR,
7230 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7231 return -1;
7232#endif /* NL80211_SUPPORT */
7233}
7234
7235
Arif Hussain9765f7d2018-07-03 08:28:26 -07007236static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7237 int val)
7238{
7239#ifdef NL80211_SUPPORT
7240 struct nl_msg *msg;
7241 int ret = 0;
7242 struct nlattr *params;
7243 int ifindex;
7244
7245 ifindex = if_nametoindex(intf);
7246 if (ifindex == 0) {
7247 sigma_dut_print(dut, DUT_MSG_ERROR,
7248 "%s: Index for interface %s failed, val:%d",
7249 __func__, intf, val);
7250 return -1;
7251 }
7252
7253 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7254 NL80211_CMD_VENDOR)) ||
7255 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7256 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7257 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7258 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7259 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7260 nla_put_u8(msg,
7261 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7262 val)) {
7263 sigma_dut_print(dut, DUT_MSG_ERROR,
7264 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7265 __func__, val);
7266 nlmsg_free(msg);
7267 return -1;
7268 }
7269 nla_nest_end(msg, params);
7270
7271 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7272 if (ret) {
7273 sigma_dut_print(dut, DUT_MSG_ERROR,
7274 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7275 __func__, ret, val);
7276 }
7277 return ret;
7278#else /* NL80211_SUPPORT */
7279 sigma_dut_print(dut, DUT_MSG_ERROR,
7280 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7281 return -1;
7282#endif /* NL80211_SUPPORT */
7283}
7284
7285
Arif Hussain68d23f52018-07-11 13:39:08 -07007286#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007287static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7288 enum qca_wlan_he_mac_padding_dur val)
7289{
Arif Hussain68d23f52018-07-11 13:39:08 -07007290 struct nl_msg *msg;
7291 int ret = 0;
7292 struct nlattr *params;
7293 int ifindex;
7294
7295 ifindex = if_nametoindex(intf);
7296 if (ifindex == 0) {
7297 sigma_dut_print(dut, DUT_MSG_ERROR,
7298 "%s: Index for interface %s failed, val:%d",
7299 __func__, intf, val);
7300 return -1;
7301 }
7302
7303 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7304 NL80211_CMD_VENDOR)) ||
7305 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7306 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7307 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7308 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7309 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7310 nla_put_u8(msg,
7311 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
7312 val)) {
7313 sigma_dut_print(dut, DUT_MSG_ERROR,
7314 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7315 __func__, val);
7316 nlmsg_free(msg);
7317 return -1;
7318 }
7319 nla_nest_end(msg, params);
7320
7321 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7322 if (ret) {
7323 sigma_dut_print(dut, DUT_MSG_ERROR,
7324 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7325 __func__, ret, val);
7326 }
7327 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07007328}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007329#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007330
7331
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007332static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7333 int val)
7334{
7335#ifdef NL80211_SUPPORT
7336 struct nl_msg *msg;
7337 int ret = 0;
7338 struct nlattr *params;
7339 int ifindex;
7340
7341 ifindex = if_nametoindex(intf);
7342 if (ifindex == 0) {
7343 sigma_dut_print(dut, DUT_MSG_ERROR,
7344 "%s: Index for interface %s failed, val:%d",
7345 __func__, intf, val);
7346 return -1;
7347 }
7348
7349 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7350 NL80211_CMD_VENDOR)) ||
7351 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7352 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7353 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7354 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7355 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7356 nla_put_u8(msg,
7357 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7358 val)) {
7359 sigma_dut_print(dut, DUT_MSG_ERROR,
7360 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7361 __func__, val);
7362 nlmsg_free(msg);
7363 return -1;
7364 }
7365 nla_nest_end(msg, params);
7366
7367 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7368 if (ret) {
7369 sigma_dut_print(dut, DUT_MSG_ERROR,
7370 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7371 __func__, ret, val);
7372 }
7373 return ret;
7374#else /* NL80211_SUPPORT */
7375 sigma_dut_print(dut, DUT_MSG_ERROR,
7376 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7377 return -1;
7378#endif /* NL80211_SUPPORT */
7379}
7380
7381
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007382#ifdef NL80211_SUPPORT
7383static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7384{
7385 struct nl_msg *msg;
7386 int ret = 0;
7387 struct nlattr *params;
7388 int ifindex;
7389
7390 ifindex = if_nametoindex(intf);
7391 if (ifindex == 0) {
7392 sigma_dut_print(dut, DUT_MSG_ERROR,
7393 "%s: Index for interface %s failed",
7394 __func__, intf);
7395 return -1;
7396 }
7397
7398 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7399 NL80211_CMD_VENDOR)) ||
7400 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7401 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7402 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7403 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7404 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7405 nla_put_flag(msg,
7406 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
7407 sigma_dut_print(dut, DUT_MSG_ERROR,
7408 "%s: err in adding vendor_cmd and vendor_data",
7409 __func__);
7410 nlmsg_free(msg);
7411 return -1;
7412 }
7413 nla_nest_end(msg, params);
7414
7415 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7416 if (ret) {
7417 sigma_dut_print(dut, DUT_MSG_ERROR,
7418 "%s: err in send_and_recv_msgs, ret=%d",
7419 __func__, ret);
7420 }
7421 return ret;
7422}
7423#endif /* NL80211_SUPPORT */
7424
7425
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007426static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7427 int val)
7428{
7429#ifdef NL80211_SUPPORT
7430 struct nl_msg *msg;
7431 int ret = 0;
7432 struct nlattr *params;
7433 int ifindex;
7434
7435 ifindex = if_nametoindex(intf);
7436 if (ifindex == 0) {
7437 sigma_dut_print(dut, DUT_MSG_ERROR,
7438 "%s: Index for interface %s failed, val:%d",
7439 __func__, intf, val);
7440 return -1;
7441 }
7442
7443 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7444 NL80211_CMD_VENDOR)) ||
7445 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7446 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7447 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7448 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7449 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7450 nla_put_u8(msg,
7451 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
7452 val)) {
7453 sigma_dut_print(dut, DUT_MSG_ERROR,
7454 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7455 __func__, val);
7456 nlmsg_free(msg);
7457 return -1;
7458 }
7459 nla_nest_end(msg, params);
7460
7461 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7462 if (ret) {
7463 sigma_dut_print(dut, DUT_MSG_ERROR,
7464 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7465 __func__, ret, val);
7466 }
7467 return ret;
7468#else /* NL80211_SUPPORT */
7469 sigma_dut_print(dut, DUT_MSG_ERROR,
7470 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7471 return -1;
7472#endif /* NL80211_SUPPORT */
7473}
7474
7475
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007476static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7477 int val)
7478{
7479#ifdef NL80211_SUPPORT
7480 struct nl_msg *msg;
7481 int ret = 0;
7482 struct nlattr *params;
7483 int ifindex;
7484
7485 ifindex = if_nametoindex(intf);
7486 if (ifindex == 0) {
7487 sigma_dut_print(dut, DUT_MSG_ERROR,
7488 "%s: Index for interface %s failed, val:%d",
7489 __func__, intf, val);
7490 return -1;
7491 }
7492
7493 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7494 NL80211_CMD_VENDOR)) ||
7495 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7496 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7497 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7498 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7499 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7500 nla_put_u8(msg,
7501 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
7502 val)) {
7503 sigma_dut_print(dut, DUT_MSG_ERROR,
7504 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7505 __func__, val);
7506 nlmsg_free(msg);
7507 return -1;
7508 }
7509 nla_nest_end(msg, params);
7510
7511 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7512 if (ret) {
7513 sigma_dut_print(dut, DUT_MSG_ERROR,
7514 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7515 __func__, ret, val);
7516 }
7517 return ret;
7518#else /* NL80211_SUPPORT */
7519 sigma_dut_print(dut, DUT_MSG_ERROR,
7520 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7521 return -1;
7522#endif /* NL80211_SUPPORT */
7523}
7524
7525
Arif Hussain480d5f42019-03-12 14:40:42 -07007526static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7527 int val)
7528{
7529#ifdef NL80211_SUPPORT
7530 struct nl_msg *msg;
7531 int ret;
7532 struct nlattr *params;
7533 int ifindex;
7534
7535 ifindex = if_nametoindex(intf);
7536 if (ifindex == 0) {
7537 sigma_dut_print(dut, DUT_MSG_ERROR,
7538 "%s: Index for interface %s failed, val:%d",
7539 __func__, intf, val);
7540 return -1;
7541 }
7542
7543 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7544 NL80211_CMD_VENDOR)) ||
7545 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7546 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7547 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7548 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7549 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7550 nla_put_u8(msg,
7551 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT,
7552 val)) {
7553 sigma_dut_print(dut, DUT_MSG_ERROR,
7554 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7555 __func__, val);
7556 nlmsg_free(msg);
7557 return -1;
7558 }
7559 nla_nest_end(msg, params);
7560
7561 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7562 if (ret) {
7563 sigma_dut_print(dut, DUT_MSG_ERROR,
7564 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7565 __func__, ret, val);
7566 }
7567 return ret;
7568#else /* NL80211_SUPPORT */
7569 sigma_dut_print(dut, DUT_MSG_ERROR,
7570 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7571 return -1;
7572#endif /* NL80211_SUPPORT */
7573}
7574
7575
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007576static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7577 const char *type)
7578{
7579 char buf[60];
7580
7581 if (dut->program == PROGRAM_HE) {
7582 /* resetting phymode to auto in case of HE program */
7583 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
7584 if (system(buf) != 0) {
7585 sigma_dut_print(dut, DUT_MSG_ERROR,
7586 "iwpriv %s setphymode failed", intf);
7587 }
7588
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007589 /* reset the rate to Auto rate */
7590 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7591 intf);
7592 if (system(buf) != 0) {
7593 sigma_dut_print(dut, DUT_MSG_ERROR,
7594 "iwpriv %s set_11ax_rate 0xff failed",
7595 intf);
7596 }
7597
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007598 /* reset the LDPC setting */
7599 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7600 if (system(buf) != 0) {
7601 sigma_dut_print(dut, DUT_MSG_ERROR,
7602 "iwpriv %s ldpc 1 failed", intf);
7603 }
7604
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007605 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05307606 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007607
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007608 /* remove all network profiles */
7609 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007610
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007611 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7612 sta_set_addba_buf_size(dut, intf, 64);
7613
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007614#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007615 /* Reset the device HE capabilities to its default supported
7616 * configuration. */
7617 sta_set_he_testbed_def(dut, intf, 0);
7618
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007619 /* Disable noackpolicy for all AC */
7620 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7621 sigma_dut_print(dut, DUT_MSG_ERROR,
7622 "Disable of noackpolicy for all AC failed");
7623 }
7624#endif /* NL80211_SUPPORT */
7625
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007626 /* Enable WMM by default */
7627 if (wcn_sta_set_wmm(dut, intf, "on")) {
7628 sigma_dut_print(dut, DUT_MSG_ERROR,
7629 "Enable of WMM in sta_reset_default_wcn failed");
7630 }
7631
7632 /* Disable ADDBA_REJECT by default */
7633 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7634 sigma_dut_print(dut, DUT_MSG_ERROR,
7635 "Disable of addba_reject in sta_reset_default_wcn failed");
7636 }
7637
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007638 /* Enable sending of ADDBA by default */
7639 if (nlvendor_config_send_addba(dut, intf, 1)) {
7640 sigma_dut_print(dut, DUT_MSG_ERROR,
7641 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7642 }
7643
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007644 /* Enable AMPDU by default */
7645 iwpriv_sta_set_ampdu(dut, intf, 1);
7646
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007647#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08007648 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007649 sigma_dut_print(dut, DUT_MSG_ERROR,
7650 "Set LTF config to default in sta_reset_default_wcn failed");
7651 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007652
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007653 /* set the beamformee NSTS(maximum number of
7654 * space-time streams) to default DUT config
7655 */
7656 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007657 sigma_dut_print(dut, DUT_MSG_ERROR,
7658 "Failed to set BeamformeeSTS");
7659 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007660
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007661 if (sta_set_mac_padding_duration(
7662 dut, intf,
7663 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007664 sigma_dut_print(dut, DUT_MSG_ERROR,
7665 "Failed to set MAC padding duration");
7666 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007667
7668 if (sta_set_mu_edca_override(dut, intf, 0)) {
7669 sigma_dut_print(dut, DUT_MSG_ERROR,
7670 "ErrorCode,Failed to set MU EDCA override disable");
7671 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007672
7673 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7674 sigma_dut_print(dut, DUT_MSG_ERROR,
7675 "Failed to set OM ctrl supp");
7676 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007677
7678 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7679 sigma_dut_print(dut, DUT_MSG_ERROR,
7680 "Failed to set Tx SU PPDU enable");
7681 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007682
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007683 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7684 sigma_dut_print(dut, DUT_MSG_ERROR,
7685 "failed to send TB PPDU Tx cfg");
7686 }
7687
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007688 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7689 sigma_dut_print(dut, DUT_MSG_ERROR,
7690 "Failed to set OM ctrl reset");
7691 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007692
7693 /* +HTC-HE support default on */
7694 if (sta_set_he_htc_supp(dut, intf, 1)) {
7695 sigma_dut_print(dut, DUT_MSG_ERROR,
7696 "Setting of +HTC-HE support failed");
7697 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007698#endif /* NL80211_SUPPORT */
7699
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007700 if (sta_set_tx_beamformee(dut, intf, 1)) {
7701 sigma_dut_print(dut, DUT_MSG_ERROR,
7702 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7703 }
7704
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007705 wpa_command(intf, "SET oce 1");
7706
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007707 /* Set nss to 1 and MCS 0-7 in case of testbed */
7708 if (type && strcasecmp(type, "Testbed") == 0) {
7709#ifdef NL80211_SUPPORT
7710 int ret;
7711#endif /* NL80211_SUPPORT */
7712
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007713 wpa_command(intf, "SET oce 0");
7714
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007715 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7716 if (system(buf) != 0) {
7717 sigma_dut_print(dut, DUT_MSG_ERROR,
7718 "iwpriv %s nss failed", intf);
7719 }
7720
7721#ifdef NL80211_SUPPORT
7722 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7723 if (ret) {
7724 sigma_dut_print(dut, DUT_MSG_ERROR,
7725 "Setting of MCS failed, ret:%d",
7726 ret);
7727 }
7728#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007729
7730 /* Disable STBC as default */
7731 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007732
7733 /* Disable AMSDU as default */
7734 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007735
7736#ifdef NL80211_SUPPORT
7737 /* HE fragmentation default off */
7738 if (sta_set_he_fragmentation(dut, intf,
7739 HE_FRAG_DISABLE)) {
7740 sigma_dut_print(dut, DUT_MSG_ERROR,
7741 "Setting of HE fragmentation failed");
7742 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007743
7744 /* set the beamformee NSTS(maximum number of
7745 * space-time streams) to default testbed config
7746 */
7747 if (sta_set_beamformee_sts(dut, intf, 3)) {
7748 sigma_dut_print(dut, DUT_MSG_ERROR,
7749 "Failed to set BeamformeeSTS");
7750 }
7751
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007752 /* +HTC-HE support default off */
7753 if (sta_set_he_htc_supp(dut, intf, 0)) {
7754 sigma_dut_print(dut, DUT_MSG_ERROR,
7755 "Setting of +HTC-HE support failed");
7756 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007757
7758 /* Set device HE capabilities to testbed default
7759 * configuration. */
7760 if (sta_set_he_testbed_def(dut, intf, 1)) {
7761 sigma_dut_print(dut, DUT_MSG_DEBUG,
7762 "Failed to set HE defaults");
7763 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007764
7765 /* Disable VHT support in 2.4 GHz for testbed */
7766 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007767#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007768
7769 /* Enable WEP/TKIP with HE capability in testbed */
7770 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
7771 sigma_dut_print(dut, DUT_MSG_ERROR,
7772 "Enabling HE config with WEP/TKIP failed");
7773 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007774 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007775
7776 /* Defaults in case of DUT */
7777 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07007778 /* Enable STBC by default */
7779 wcn_sta_set_stbc(dut, intf, "1");
7780
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007781 /* set nss to 2 */
7782 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
7783 if (system(buf) != 0) {
7784 sigma_dut_print(dut, DUT_MSG_ERROR,
7785 "iwpriv %s nss 2 failed", intf);
7786 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007787 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007788
7789#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07007790 /* Set HE_MCS to 0-11 */
7791 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007792 sigma_dut_print(dut, DUT_MSG_ERROR,
7793 "Setting of MCS failed");
7794 }
7795#endif /* NL80211_SUPPORT */
7796
7797 /* Disable WEP/TKIP with HE capability in DUT */
7798 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
7799 sigma_dut_print(dut, DUT_MSG_ERROR,
7800 "Enabling HE config with WEP/TKIP failed");
7801 }
7802 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007803 }
7804}
7805
7806
Jouni Malinenf7222712019-06-13 01:50:21 +03007807static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
7808 struct sigma_conn *conn,
7809 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007810{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007811 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007812 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007813 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007814 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307815 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007816
Jouni Malinenb21f0542019-11-04 17:53:38 +02007817 if (dut->station_ifname_2g &&
7818 strcmp(dut->station_ifname_2g, intf) == 0)
7819 dut->use_5g = 0;
7820 else if (dut->station_ifname_5g &&
7821 strcmp(dut->station_ifname_5g, intf) == 0)
7822 dut->use_5g = 1;
7823
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007824 if (!program)
7825 program = get_param(cmd, "prog");
7826 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007827 dut->device_type = STA_unknown;
7828 type = get_param(cmd, "type");
7829 if (type && strcasecmp(type, "Testbed") == 0)
7830 dut->device_type = STA_testbed;
7831 if (type && strcasecmp(type, "DUT") == 0)
7832 dut->device_type = STA_dut;
7833
7834 if (dut->program == PROGRAM_TDLS) {
7835 /* Clear TDLS testing mode */
7836 wpa_command(intf, "SET tdls_disabled 0");
7837 wpa_command(intf, "SET tdls_testing 0");
7838 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007839 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05307840 /* Enable the WCN driver in TDLS Explicit trigger mode
7841 */
7842 wpa_command(intf, "SET tdls_external_control 0");
7843 wpa_command(intf, "SET tdls_trigger_control 0");
7844 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007845 }
7846
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007847#ifdef MIRACAST
7848 if (dut->program == PROGRAM_WFD ||
7849 dut->program == PROGRAM_DISPLAYR2)
7850 miracast_sta_reset_default(dut, conn, cmd);
7851#endif /* MIRACAST */
7852
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007853 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007854 case DRIVER_ATHEROS:
7855 sta_reset_default_ath(dut, intf, type);
7856 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007857 case DRIVER_WCN:
7858 sta_reset_default_wcn(dut, intf, type);
7859 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007860 default:
7861 break;
7862 }
7863
7864#ifdef ANDROID_NAN
7865 if (dut->program == PROGRAM_NAN)
7866 nan_cmd_sta_reset_default(dut, conn, cmd);
7867#endif /* ANDROID_NAN */
7868
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05307869 if (dut->program == PROGRAM_LOC &&
7870 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
7871 return ERROR_SEND_STATUS;
7872
Jouni Malinenba630452018-06-22 11:49:59 +03007873 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007874 unlink("SP/wi-fi.org/pps.xml");
7875 if (system("rm -r SP/*") != 0) {
7876 }
7877 unlink("next-client-cert.pem");
7878 unlink("next-client-key.pem");
7879 }
7880
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007881 /* For WPS program of the 60 GHz band the band type needs to be saved */
7882 if (dut->program == PROGRAM_WPS) {
7883 if (band && strcasecmp(band, "60GHz") == 0) {
7884 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007885 /* For 60 GHz enable WPS for WPS TCs */
7886 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007887 } else {
7888 dut->band = WPS_BAND_NON_60G;
7889 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007890 } else if (dut->program == PROGRAM_60GHZ) {
7891 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
7892 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007893 }
7894
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02007895 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007896 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007897 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007898
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007899 sigma_dut_print(dut, DUT_MSG_INFO,
7900 "WPS 60 GHz program, wps_disable = %d",
7901 dut->wps_disable);
7902
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007903 if (!dev_role) {
7904 send_resp(dut, conn, SIGMA_ERROR,
7905 "errorCode,Missing DevRole argument");
7906 return 0;
7907 }
7908
7909 if (strcasecmp(dev_role, "STA") == 0)
7910 dut->dev_role = DEVROLE_STA;
7911 else if (strcasecmp(dev_role, "PCP") == 0)
7912 dut->dev_role = DEVROLE_PCP;
7913 else {
7914 send_resp(dut, conn, SIGMA_ERROR,
7915 "errorCode,Unknown DevRole");
7916 return 0;
7917 }
7918
7919 if (dut->device_type == STA_unknown) {
7920 sigma_dut_print(dut, DUT_MSG_ERROR,
7921 "Device type is not STA testbed or DUT");
7922 send_resp(dut, conn, SIGMA_ERROR,
7923 "errorCode,Unknown device type");
7924 return 0;
7925 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007926
7927 sigma_dut_print(dut, DUT_MSG_DEBUG,
7928 "Setting msdu_size to MAX: 7912");
7929 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007930 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007931
7932 if (system(buf) != 0) {
7933 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
7934 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007935 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007936 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007937
7938 if (sta_set_force_mcs(dut, 0, 1)) {
7939 sigma_dut_print(dut, DUT_MSG_ERROR,
7940 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007941 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007942 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007943 }
7944
7945 wpa_command(intf, "WPS_ER_STOP");
7946 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05307947 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007948 wpa_command(intf, "SET radio_disabled 0");
7949
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007950 dut->wps_forced_version = 0;
7951
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007952 if (dut->wsc_fragment) {
7953 dut->wsc_fragment = 0;
7954 wpa_command(intf, "SET device_name Test client");
7955 wpa_command(intf, "SET manufacturer ");
7956 wpa_command(intf, "SET model_name ");
7957 wpa_command(intf, "SET model_number ");
7958 wpa_command(intf, "SET serial_number ");
7959 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02007960 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
7961 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
7962 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
7963 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007964
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007965 if (dut->tmp_mac_addr && dut->set_macaddr) {
7966 dut->tmp_mac_addr = 0;
7967 if (system(dut->set_macaddr) != 0) {
7968 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
7969 "temporary MAC address");
7970 }
7971 }
7972
7973 set_ps(intf, dut, 0);
7974
Jouni Malinenba630452018-06-22 11:49:59 +03007975 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
7976 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007977 wpa_command(intf, "SET interworking 1");
7978 wpa_command(intf, "SET hs20 1");
7979 }
7980
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007981 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007982 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007983 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007984 wpa_command(intf, "SET pmf 1");
7985 } else {
7986 wpa_command(intf, "SET pmf 0");
7987 }
7988
7989 hs2_clear_credentials(intf);
7990 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
7991 wpa_command(intf, "SET access_network_type 15");
7992
7993 static_ip_file(0, NULL, NULL, NULL);
7994 kill_dhcp_client(dut, intf);
7995 clear_ip_addr(dut, intf);
7996
7997 dut->er_oper_performed = 0;
7998 dut->er_oper_bssid[0] = '\0';
7999
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008000 if (dut->program == PROGRAM_LOC) {
8001 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008002 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008003 }
8004
Ashwini Patil00402582017-04-13 12:29:39 +05308005 if (dut->program == PROGRAM_MBO) {
8006 free(dut->non_pref_ch_list);
8007 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05308008 free(dut->btm_query_cand_list);
8009 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05308010 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05308011 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05308012 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05308013 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05308014 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05308015 }
8016
Jouni Malinen3c367e82017-06-23 17:01:47 +03008017 free(dut->rsne_override);
8018 dut->rsne_override = NULL;
8019
Jouni Malinen68143132017-09-02 02:34:08 +03008020 free(dut->sae_commit_override);
8021 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03008022 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02008023 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03008024
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008025 dut->sta_associate_wait_connect = 0;
8026 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03008027 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008028 dut->sta_tod_policy = 0;
8029
Jouni Malinend86e5822017-08-29 03:55:32 +03008030 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02008031 free(dut->dpp_peer_uri);
8032 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02008033 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02008034 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03008035 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03008036
Jouni Malinenfac9cad2017-10-10 18:35:55 +03008037 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
8038
vamsi krishnaa2799492017-12-05 14:28:01 +05308039 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308040 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05308041 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05308042 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
8043 dut->fils_hlp = 0;
8044#ifdef ANDROID
8045 hlp_thread_cleanup(dut);
8046#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05308047 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308048
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308049 if (dut->program == PROGRAM_QM)
8050 wpa_command(intf, "SET interworking 1");
8051
Jouni Malinen8179fee2019-03-28 03:19:47 +02008052 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03008053 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02008054
Sunil Dutt076081f2018-02-05 19:45:50 +05308055#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008056 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05308057 dut->config_rsnie == 1) {
8058 dut->config_rsnie = 0;
8059 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05308060 }
8061#endif /* NL80211_SUPPORT */
8062
Sunil Duttfebf8a82018-02-09 18:50:13 +05308063 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
8064 dut->dev_role = DEVROLE_STA_CFON;
8065 return sta_cfon_reset_default(dut, conn, cmd);
8066 }
8067
Jouni Malinen439352d2018-09-13 03:42:23 +03008068 wpa_command(intf, "SET setband AUTO");
8069
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308070 dut->ocvc = 0;
Jouni Malinen67433fc2020-06-26 22:50:33 +03008071 dut->client_privacy = 0;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05308072 dut->saquery_oci_freq = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308073
Sunil Duttfebf8a82018-02-09 18:50:13 +05308074 if (dut->program != PROGRAM_VHT)
8075 return cmd_sta_p2p_reset(dut, conn, cmd);
8076
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08008077 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008078}
8079
8080
Jouni Malinenf7222712019-06-13 01:50:21 +03008081static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
8082 struct sigma_conn *conn,
8083 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008084{
8085 const char *program = get_param(cmd, "Program");
8086
8087 if (program == NULL)
8088 return -1;
8089#ifdef ANDROID_NAN
8090 if (strcasecmp(program, "NAN") == 0)
8091 return nan_cmd_sta_get_events(dut, conn, cmd);
8092#endif /* ANDROID_NAN */
8093 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8094 return 0;
8095}
8096
8097
Jouni Malinen82905202018-04-29 17:20:10 +03008098static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
8099 struct sigma_cmd *cmd)
8100{
8101 const char *url = get_param(cmd, "url");
8102 const char *method = get_param(cmd, "method");
8103 pid_t pid;
8104 int status;
8105
8106 if (!url || !method)
8107 return -1;
8108
8109 /* TODO: Add support for method,post */
8110 if (strcasecmp(method, "get") != 0) {
8111 send_resp(dut, conn, SIGMA_ERROR,
8112 "ErrorCode,Unsupported method");
8113 return 0;
8114 }
8115
8116 pid = fork();
8117 if (pid < 0) {
8118 perror("fork");
8119 return -1;
8120 }
8121
8122 if (pid == 0) {
8123 char * argv[5] = { "wget", "-O", "/dev/null",
8124 (char *) url, NULL };
8125
8126 execv("/usr/bin/wget", argv);
8127 perror("execv");
8128 exit(0);
8129 return -1;
8130 }
8131
8132 if (waitpid(pid, &status, 0) < 0) {
8133 perror("waitpid");
8134 return -1;
8135 }
8136
8137 if (WIFEXITED(status)) {
8138 const char *errmsg;
8139
8140 if (WEXITSTATUS(status) == 0)
8141 return 1;
8142 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
8143 WEXITSTATUS(status));
8144 switch (WEXITSTATUS(status)) {
8145 case 4:
8146 errmsg = "errmsg,Network failure";
8147 break;
8148 case 8:
8149 errmsg = "errmsg,Server issued an error response";
8150 break;
8151 default:
8152 errmsg = "errmsg,Unknown failure from wget";
8153 break;
8154 }
8155 send_resp(dut, conn, SIGMA_ERROR, errmsg);
8156 return 0;
8157 }
8158
8159 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
8160 return 0;
8161}
8162
8163
Jouni Malinenf7222712019-06-13 01:50:21 +03008164static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
8165 struct sigma_conn *conn,
8166 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008167{
8168 const char *program = get_param(cmd, "Prog");
8169
Jouni Malinen82905202018-04-29 17:20:10 +03008170 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008171 return -1;
8172#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03008173 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008174 return nan_cmd_sta_exec_action(dut, conn, cmd);
8175#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03008176
8177 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07008178 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03008179
8180 if (get_param(cmd, "url"))
8181 return sta_exec_action_url(dut, conn, cmd);
8182
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008183 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8184 return 0;
8185}
8186
8187
Jouni Malinenf7222712019-06-13 01:50:21 +03008188static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
8189 struct sigma_conn *conn,
8190 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008191{
8192 const char *intf = get_param(cmd, "Interface");
8193 const char *val, *mcs32, *rate;
8194
8195 val = get_param(cmd, "GREENFIELD");
8196 if (val) {
8197 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
8198 /* Enable GD */
8199 send_resp(dut, conn, SIGMA_ERROR,
8200 "ErrorCode,GF not supported");
8201 return 0;
8202 }
8203 }
8204
8205 val = get_param(cmd, "SGI20");
8206 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008207 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008208 case DRIVER_ATHEROS:
8209 ath_sta_set_sgi(dut, intf, val);
8210 break;
8211 default:
8212 send_resp(dut, conn, SIGMA_ERROR,
8213 "ErrorCode,SGI20 not supported");
8214 return 0;
8215 }
8216 }
8217
8218 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
8219 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
8220 if (mcs32 && rate) {
8221 /* TODO */
8222 send_resp(dut, conn, SIGMA_ERROR,
8223 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
8224 return 0;
8225 } else if (mcs32 && !rate) {
8226 /* TODO */
8227 send_resp(dut, conn, SIGMA_ERROR,
8228 "ErrorCode,MCS32 not supported");
8229 return 0;
8230 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008231 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008232 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008233 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008234 ath_sta_set_11nrates(dut, intf, rate);
8235 break;
8236 default:
8237 send_resp(dut, conn, SIGMA_ERROR,
8238 "ErrorCode,MCS32_FIXEDRATE not supported");
8239 return 0;
8240 }
8241 }
8242
8243 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8244}
8245
8246
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008247static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8248 int mcs_config)
8249{
8250#ifdef NL80211_SUPPORT
8251 int ret;
8252
8253 switch (mcs_config) {
8254 case HE_80_MCS0_7:
8255 case HE_80_MCS0_9:
8256 case HE_80_MCS0_11:
8257 ret = sta_set_he_mcs(dut, intf, mcs_config);
8258 if (ret) {
8259 sigma_dut_print(dut, DUT_MSG_ERROR,
8260 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8261 mcs_config, ret);
8262 }
8263 break;
8264 default:
8265 sigma_dut_print(dut, DUT_MSG_ERROR,
8266 "cmd_set_max_he_mcs: Invalid mcs %d",
8267 mcs_config);
8268 break;
8269 }
8270#else /* NL80211_SUPPORT */
8271 sigma_dut_print(dut, DUT_MSG_ERROR,
8272 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8273#endif /* NL80211_SUPPORT */
8274}
8275
8276
Arif Hussain480d5f42019-03-12 14:40:42 -07008277static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8278 struct sigma_cmd *cmd)
8279{
8280#ifdef NL80211_SUPPORT
8281 struct nlattr *params;
8282 struct nlattr *attr;
8283 struct nlattr *attr1;
8284 struct nl_msg *msg;
8285 int ifindex, ret;
8286 const char *val;
8287 const char *intf = get_param(cmd, "Interface");
8288 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8289 wake_interval_mantissa = 512;
8290 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
8291 protection = 0;
8292
8293 ifindex = if_nametoindex(intf);
8294 if (ifindex == 0) {
8295 sigma_dut_print(dut, DUT_MSG_ERROR,
8296 "%s: Index for interface %s failed",
8297 __func__, intf);
8298 return -1;
8299 }
8300
8301 val = get_param(cmd, "FlowType");
8302 if (val) {
8303 flow_type = atoi(val);
8304 if (flow_type != 0 && flow_type != 1) {
8305 sigma_dut_print(dut, DUT_MSG_ERROR,
8306 "TWT: Invalid FlowType %d", flow_type);
8307 return -1;
8308 }
8309 }
8310
8311 val = get_param(cmd, "TWT_Trigger");
8312 if (val) {
8313 twt_trigger = atoi(val);
8314 if (twt_trigger != 0 && twt_trigger != 1) {
8315 sigma_dut_print(dut, DUT_MSG_ERROR,
8316 "TWT: Invalid TWT_Trigger %d",
8317 twt_trigger);
8318 return -1;
8319 }
8320 }
8321
8322 val = get_param(cmd, "Protection");
8323 if (val) {
8324 protection = atoi(val);
8325 if (protection != 0 && protection != 1) {
8326 sigma_dut_print(dut, DUT_MSG_ERROR,
8327 "TWT: Invalid Protection %d",
8328 protection);
8329 return -1;
8330 }
8331 }
8332
8333 val = get_param(cmd, "TargetWakeTime");
8334 if (val)
8335 target_wake_time = atoi(val);
8336
8337 val = get_param(cmd, "WakeIntervalMantissa");
8338 if (val)
8339 wake_interval_mantissa = atoi(val);
8340
8341 val = get_param(cmd, "WakeIntervalExp");
8342 if (val)
8343 wake_interval_exp = atoi(val);
8344
8345 val = get_param(cmd, "NominalMinWakeDur");
8346 if (val)
8347 nominal_min_wake_dur = atoi(val);
8348
8349 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8350 NL80211_CMD_VENDOR)) ||
8351 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8352 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8353 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8354 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8355 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8356 !(params = nla_nest_start(
8357 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
8358 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8359 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8360 wake_interval_exp) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008361 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, 1) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008362 (twt_trigger &&
8363 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008364 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8365 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008366 (protection &&
8367 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008368 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8369 target_wake_time) ||
8370 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8371 nominal_min_wake_dur) ||
8372 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8373 wake_interval_mantissa)) {
8374 sigma_dut_print(dut, DUT_MSG_ERROR,
8375 "%s: err in adding vendor_cmd and vendor_data",
8376 __func__);
8377 nlmsg_free(msg);
8378 return -1;
8379 }
8380 nla_nest_end(msg, attr1);
8381 nla_nest_end(msg, params);
8382 nla_nest_end(msg, attr);
8383
8384 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8385 if (ret) {
8386 sigma_dut_print(dut, DUT_MSG_ERROR,
8387 "%s: err in send_and_recv_msgs, ret=%d",
8388 __func__, ret);
8389 }
8390
8391 return ret;
8392#else /* NL80211_SUPPORT */
8393 sigma_dut_print(dut, DUT_MSG_ERROR,
8394 "TWT request cannot be done without NL80211_SUPPORT defined");
8395 return -1;
8396#endif /* NL80211_SUPPORT */
8397}
8398
8399
8400static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8401 struct sigma_cmd *cmd)
8402{
8403 #ifdef NL80211_SUPPORT
8404 struct nlattr *params;
8405 struct nlattr *attr;
8406 struct nlattr *attr1;
8407 int ifindex, ret;
8408 struct nl_msg *msg;
8409 const char *intf = get_param(cmd, "Interface");
8410
8411 ifindex = if_nametoindex(intf);
8412 if (ifindex == 0) {
8413 sigma_dut_print(dut, DUT_MSG_ERROR,
8414 "%s: Index for interface %s failed",
8415 __func__, intf);
8416 return -1;
8417 }
8418
8419 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8420 NL80211_CMD_VENDOR)) ||
8421 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8422 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8423 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8424 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8425 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8426 !(params = nla_nest_start(
8427 msg,
8428 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8429 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8430 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8431 sigma_dut_print(dut, DUT_MSG_ERROR,
8432 "%s: err in adding vendor_cmd and vendor_data",
8433 __func__);
8434 nlmsg_free(msg);
8435 return -1;
8436 }
8437 nla_nest_end(msg, attr1);
8438 nla_nest_end(msg, params);
8439 nla_nest_end(msg, attr);
8440
8441 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8442 if (ret) {
8443 sigma_dut_print(dut, DUT_MSG_ERROR,
8444 "%s: err in send_and_recv_msgs, ret=%d",
8445 __func__, ret);
8446 }
8447
8448 return ret;
8449#else /* NL80211_SUPPORT */
8450 sigma_dut_print(dut, DUT_MSG_ERROR,
8451 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8452 return -1;
8453#endif /* NL80211_SUPPORT */
8454}
8455
8456
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008457static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8458 struct sigma_cmd *cmd)
8459{
8460#ifdef NL80211_SUPPORT
8461 struct nlattr *params;
8462 struct nlattr *attr;
8463 struct nlattr *attr1;
8464 struct nl_msg *msg;
8465 int ifindex, ret;
8466 const char *val;
8467 const char *intf = get_param(cmd, "Interface");
8468 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8469 ulmu_data_dis = 0;
8470
8471 ifindex = if_nametoindex(intf);
8472 if (ifindex == 0) {
8473 sigma_dut_print(dut, DUT_MSG_ERROR,
8474 "%s: Index for interface %s failed",
8475 __func__, intf);
8476 return -1;
8477 }
8478 val = get_param(cmd, "OMCtrl_RxNSS");
8479 if (val)
8480 rx_nss = atoi(val);
8481
8482 val = get_param(cmd, "OMCtrl_ChnlWidth");
8483 if (val)
8484 ch_bw = atoi(val);
8485
8486 val = get_param(cmd, "OMCtrl_ULMUDisable");
8487 if (val)
8488 ulmu_dis = atoi(val);
8489
8490 val = get_param(cmd, "OMCtrl_TxNSTS");
8491 if (val)
8492 tx_nsts = atoi(val);
8493
8494 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8495 if (val)
8496 ulmu_data_dis = atoi(val);
8497
8498 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8499 NL80211_CMD_VENDOR)) ||
8500 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8501 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8502 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8503 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8504 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8505 !(params = nla_nest_start(
8506 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8507 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8508 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8509 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8510 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8511 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8512 ulmu_data_dis) ||
8513 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8514 ulmu_dis)) {
8515 sigma_dut_print(dut, DUT_MSG_ERROR,
8516 "%s: err in adding vendor_cmd and vendor_data",
8517 __func__);
8518 nlmsg_free(msg);
8519 return -1;
8520 }
8521 nla_nest_end(msg, attr1);
8522 nla_nest_end(msg, params);
8523 nla_nest_end(msg, attr);
8524
8525 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8526 if (ret) {
8527 sigma_dut_print(dut, DUT_MSG_ERROR,
8528 "%s: err in send_and_recv_msgs, ret=%d",
8529 __func__, ret);
8530 }
8531
8532 return ret;
8533#else /* NL80211_SUPPORT */
8534 sigma_dut_print(dut, DUT_MSG_ERROR,
8535 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8536 return -1;
8537#endif /* NL80211_SUPPORT */
8538}
8539
8540
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008541static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8542 struct sigma_conn *conn,
8543 struct sigma_cmd *cmd)
8544{
8545 const char *intf = get_param(cmd, "Interface");
8546 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008547 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008548 int tkip = -1;
8549 int wep = -1;
8550
Arif Hussaina37e9552018-06-20 17:05:59 -07008551 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008552 val = get_param(cmd, "SGI80");
8553 if (val) {
8554 int sgi80;
8555
8556 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008557 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008558 }
8559
8560 val = get_param(cmd, "TxBF");
8561 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008562 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008563 case DRIVER_WCN:
8564 if (sta_set_tx_beamformee(dut, intf, 1)) {
8565 send_resp(dut, conn, SIGMA_ERROR,
8566 "ErrorCode,Failed to set TX beamformee enable");
8567 return 0;
8568 }
8569 break;
8570 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008571 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008572 send_resp(dut, conn, SIGMA_ERROR,
8573 "ErrorCode,Setting vhtsubfee failed");
8574 return 0;
8575 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008576 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008577 send_resp(dut, conn, SIGMA_ERROR,
8578 "ErrorCode,Setting vhtsubfer failed");
8579 return 0;
8580 }
8581 break;
8582 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008583 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008584 "Unsupported driver type");
8585 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008586 }
8587 }
8588
8589 val = get_param(cmd, "MU_TxBF");
8590 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008591 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008592 case DRIVER_ATHEROS:
8593 ath_sta_set_txsp_stream(dut, intf, "1SS");
8594 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008595 run_iwpriv(dut, intf, "vhtmubfee 1");
8596 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308597 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008598 case DRIVER_WCN:
8599 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8600 send_resp(dut, conn, SIGMA_ERROR,
8601 "ErrorCode,Failed to set RX/TXSP_STREAM");
8602 return 0;
8603 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308604 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008605 default:
8606 sigma_dut_print(dut, DUT_MSG_ERROR,
8607 "Setting SP_STREAM not supported");
8608 break;
8609 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008610 }
8611
8612 val = get_param(cmd, "LDPC");
8613 if (val) {
8614 int ldpc;
8615
8616 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008617 run_iwpriv(dut, intf, "ldpc %d", ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008618 }
8619
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008620 val = get_param(cmd, "BCC");
8621 if (val) {
8622 int bcc;
8623
8624 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8625 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8626 * is mutually exclusive to bcc */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008627 run_iwpriv(dut, intf, "ldpc %d", !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008628 }
8629
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008630 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8631 if (val && dut->sta_nss == 1)
8632 cmd_set_max_he_mcs(dut, intf, atoi(val));
8633
8634 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8635 if (val && dut->sta_nss == 2)
8636 cmd_set_max_he_mcs(dut, intf, atoi(val));
8637
Arif Hussainac6c5112018-05-25 17:34:00 -07008638 val = get_param(cmd, "MCS_FixedRate");
8639 if (val) {
8640#ifdef NL80211_SUPPORT
8641 int mcs, ratecode = 0;
8642 enum he_mcs_config mcs_config;
8643 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008644 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008645
8646 ratecode = (0x07 & dut->sta_nss) << 5;
8647 mcs = atoi(val);
8648 /* Add the MCS to the ratecode */
8649 if (mcs >= 0 && mcs <= 11) {
8650 ratecode += mcs;
8651 if (dut->device_type == STA_testbed &&
8652 mcs > 7 && mcs <= 11) {
8653 if (mcs <= 9)
8654 mcs_config = HE_80_MCS0_9;
8655 else
8656 mcs_config = HE_80_MCS0_11;
8657 ret = sta_set_he_mcs(dut, intf, mcs_config);
8658 if (ret) {
8659 sigma_dut_print(dut, DUT_MSG_ERROR,
8660 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8661 mcs, mcs_config, ret);
8662 }
8663 }
8664 snprintf(buf, sizeof(buf),
8665 "iwpriv %s set_11ax_rate 0x%03x",
8666 intf, ratecode);
8667 if (system(buf) != 0) {
8668 sigma_dut_print(dut, DUT_MSG_ERROR,
8669 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8670 ratecode);
8671 }
8672 } else {
8673 sigma_dut_print(dut, DUT_MSG_ERROR,
8674 "MCS_FixedRate: HE MCS %d not supported",
8675 mcs);
8676 }
8677#else /* NL80211_SUPPORT */
8678 sigma_dut_print(dut, DUT_MSG_ERROR,
8679 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8680#endif /* NL80211_SUPPORT */
8681 }
8682
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008683 val = get_param(cmd, "opt_md_notif_ie");
8684 if (val) {
8685 char *result = NULL;
8686 char delim[] = ";";
8687 char token[30];
8688 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308689 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008690
Peng Xub8fc5cc2017-05-10 17:27:28 -07008691 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308692 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008693
8694 /* Extract the NSS information */
8695 if (result) {
8696 value = atoi(result);
8697 switch (value) {
8698 case 1:
8699 config_val = 1;
8700 break;
8701 case 2:
8702 config_val = 3;
8703 break;
8704 case 3:
8705 config_val = 7;
8706 break;
8707 case 4:
8708 config_val = 15;
8709 break;
8710 default:
8711 config_val = 3;
8712 break;
8713 }
8714
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008715 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8716 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008717
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008718 }
8719
8720 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308721 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008722 if (result) {
8723 value = atoi(result);
8724 switch (value) {
8725 case 20:
8726 config_val = 0;
8727 break;
8728 case 40:
8729 config_val = 1;
8730 break;
8731 case 80:
8732 config_val = 2;
8733 break;
8734 case 160:
8735 config_val = 3;
8736 break;
8737 default:
8738 config_val = 2;
8739 break;
8740 }
8741
8742 dut->chwidth = config_val;
8743
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008744 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008745 }
8746
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008747 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008748 }
8749
8750 val = get_param(cmd, "nss_mcs_cap");
8751 if (val) {
8752 int nss, mcs;
8753 char token[20];
8754 char *result = NULL;
8755 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308756 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008757
Peng Xub8fc5cc2017-05-10 17:27:28 -07008758 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308759 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308760 if (!result) {
8761 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008762 "NSS not specified");
8763 send_resp(dut, conn, SIGMA_ERROR,
8764 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308765 return 0;
8766 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008767 nss = atoi(result);
8768
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008769 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07008770 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008771
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308772 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008773 if (result == NULL) {
8774 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008775 "MCS not specified");
8776 send_resp(dut, conn, SIGMA_ERROR,
8777 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008778 return 0;
8779 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308780 result = strtok_r(result, "-", &saveptr);
8781 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308782 if (!result) {
8783 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008784 "MCS not specified");
8785 send_resp(dut, conn, SIGMA_ERROR,
8786 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308787 return 0;
8788 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008789 mcs = atoi(result);
8790
Arif Hussaina37e9552018-06-20 17:05:59 -07008791 if (program && strcasecmp(program, "HE") == 0) {
8792#ifdef NL80211_SUPPORT
8793 enum he_mcs_config mcs_config;
8794 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008795
Arif Hussaina37e9552018-06-20 17:05:59 -07008796 if (mcs >= 0 && mcs <= 7) {
8797 mcs_config = HE_80_MCS0_7;
8798 } else if (mcs > 7 && mcs <= 9) {
8799 mcs_config = HE_80_MCS0_9;
8800 } else if (mcs > 9 && mcs <= 11) {
8801 mcs_config = HE_80_MCS0_11;
8802 } else {
8803 sigma_dut_print(dut, DUT_MSG_ERROR,
8804 "nss_mcs_cap: HE: Invalid mcs: %d",
8805 mcs);
8806 send_resp(dut, conn, SIGMA_ERROR,
8807 "errorCode,Invalid MCS");
8808 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008809 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008810
8811 ret = sta_set_he_mcs(dut, intf, mcs_config);
8812 if (ret) {
8813 sigma_dut_print(dut, DUT_MSG_ERROR,
8814 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
8815 mcs_config, ret);
8816 send_resp(dut, conn, SIGMA_ERROR,
8817 "errorCode,Failed to set MCS");
8818 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008819 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008820#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008821 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008822 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
8823#endif /* NL80211_SUPPORT */
8824 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008825 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07008826
8827 switch (nss) {
8828 case 1:
8829 switch (mcs) {
8830 case 7:
8831 vht_mcsmap = 0xfffc;
8832 break;
8833 case 8:
8834 vht_mcsmap = 0xfffd;
8835 break;
8836 case 9:
8837 vht_mcsmap = 0xfffe;
8838 break;
8839 default:
8840 vht_mcsmap = 0xfffe;
8841 break;
8842 }
8843 break;
8844 case 2:
8845 switch (mcs) {
8846 case 7:
8847 vht_mcsmap = 0xfff0;
8848 break;
8849 case 8:
8850 vht_mcsmap = 0xfff5;
8851 break;
8852 case 9:
8853 vht_mcsmap = 0xfffa;
8854 break;
8855 default:
8856 vht_mcsmap = 0xfffa;
8857 break;
8858 }
8859 break;
8860 case 3:
8861 switch (mcs) {
8862 case 7:
8863 vht_mcsmap = 0xffc0;
8864 break;
8865 case 8:
8866 vht_mcsmap = 0xffd5;
8867 break;
8868 case 9:
8869 vht_mcsmap = 0xffea;
8870 break;
8871 default:
8872 vht_mcsmap = 0xffea;
8873 break;
8874 }
8875 break;
8876 default:
8877 vht_mcsmap = 0xffea;
8878 break;
8879 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008880 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008881 }
8882 }
8883
8884 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
8885
8886 val = get_param(cmd, "Vht_tkip");
8887 if (val)
8888 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8889
8890 val = get_param(cmd, "Vht_wep");
8891 if (val)
8892 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8893
8894 if (tkip != -1 || wep != -1) {
8895 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008896 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008897 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008898 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008899 } else {
8900 sigma_dut_print(dut, DUT_MSG_ERROR,
8901 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
8902 return 0;
8903 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008904 }
8905
Arif Hussain55f00da2018-07-03 08:28:26 -07008906 val = get_param(cmd, "txBandwidth");
8907 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008908 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07008909 case DRIVER_WCN:
8910 if (wcn_sta_set_width(dut, intf, val) < 0) {
8911 send_resp(dut, conn, SIGMA_ERROR,
8912 "ErrorCode,Failed to set txBandwidth");
8913 return 0;
8914 }
8915 break;
8916 case DRIVER_ATHEROS:
8917 if (ath_set_width(dut, conn, intf, val) < 0) {
8918 send_resp(dut, conn, SIGMA_ERROR,
8919 "ErrorCode,Failed to set txBandwidth");
8920 return 0;
8921 }
8922 break;
8923 default:
8924 sigma_dut_print(dut, DUT_MSG_ERROR,
8925 "Setting txBandwidth not supported");
8926 break;
8927 }
8928 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008929
Arif Hussain9765f7d2018-07-03 08:28:26 -07008930 val = get_param(cmd, "BeamformeeSTS");
8931 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07008932 if (sta_set_tx_beamformee(dut, intf, 1)) {
8933 send_resp(dut, conn, SIGMA_ERROR,
8934 "ErrorCode,Failed to set TX beamformee enable");
8935 return 0;
8936 }
8937
Arif Hussain9765f7d2018-07-03 08:28:26 -07008938 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
8939 send_resp(dut, conn, SIGMA_ERROR,
8940 "ErrorCode,Failed to set BeamformeeSTS");
8941 return 0;
8942 }
8943 }
8944
Arif Hussain68d23f52018-07-11 13:39:08 -07008945 val = get_param(cmd, "Trig_MAC_Padding_Dur");
8946 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008947#ifdef NL80211_SUPPORT
8948 enum qca_wlan_he_mac_padding_dur set_val;
8949
8950 switch (atoi(val)) {
8951 case 16:
8952 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
8953 break;
8954 case 8:
8955 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
8956 break;
8957 default:
8958 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
8959 break;
8960 }
8961 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008962 send_resp(dut, conn, SIGMA_ERROR,
8963 "ErrorCode,Failed to set MAC padding duration");
8964 return 0;
8965 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008966#else /* NL80211_SUPPORT */
8967 sigma_dut_print(dut, DUT_MSG_ERROR,
8968 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
8969#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008970 }
8971
Arif Hussain480d5f42019-03-12 14:40:42 -07008972 val = get_param(cmd, "TWT_ReqSupport");
8973 if (val) {
8974 int set_val;
8975
8976 if (strcasecmp(val, "Enable") == 0) {
8977 set_val = 1;
8978 } else if (strcasecmp(val, "Disable") == 0) {
8979 set_val = 0;
8980 } else {
8981 send_resp(dut, conn, SIGMA_ERROR,
8982 "ErrorCode,Invalid TWT_ReqSupport");
8983 return STATUS_SENT;
8984 }
8985
8986 if (sta_set_twt_req_support(dut, intf, set_val)) {
8987 sigma_dut_print(dut, DUT_MSG_ERROR,
8988 "Failed to set TWT req support %d",
8989 set_val);
8990 send_resp(dut, conn, SIGMA_ERROR,
8991 "ErrorCode,Failed to set TWT_ReqSupport");
8992 return STATUS_SENT;
8993 }
8994 }
8995
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008996 val = get_param(cmd, "MU_EDCA");
8997 if (val && (strcasecmp(val, "Override") == 0)) {
8998 if (sta_set_mu_edca_override(dut, intf, 1)) {
8999 send_resp(dut, conn, SIGMA_ERROR,
9000 "ErrorCode,Failed to set MU EDCA override");
9001 return 0;
9002 }
9003 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009004
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07009005 val = get_param(cmd, "OMControl");
9006 if (val) {
9007 int set_val = 1;
9008
9009 if (strcasecmp(val, "Enable") == 0)
9010 set_val = 1;
9011 else if (strcasecmp(val, "Disable") == 0)
9012 set_val = 0;
9013
9014 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
9015 send_resp(dut, conn, SIGMA_ERROR,
9016 "ErrorCode,Failed to set OM ctrl supp");
9017 return 0;
9018 }
9019 }
9020
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009021 val = get_param(cmd, "ADDBAResp_BufSize");
9022 if (val) {
9023 int buf_size;
9024
9025 if (strcasecmp(val, "gt64") == 0)
9026 buf_size = 256;
9027 else
9028 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009029 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009030 sta_set_addba_buf_size(dut, intf, buf_size)) {
9031 send_resp(dut, conn, SIGMA_ERROR,
9032 "ErrorCode,set addbaresp_buff_size failed");
9033 return 0;
9034 }
9035 }
9036
9037 val = get_param(cmd, "ADDBAReq_BufSize");
9038 if (val) {
9039 int buf_size;
9040
9041 if (strcasecmp(val, "gt64") == 0)
9042 buf_size = 256;
9043 else
9044 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009045 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009046 sta_set_addba_buf_size(dut, intf, buf_size)) {
9047 send_resp(dut, conn, SIGMA_ERROR,
9048 "ErrorCode,set addbareq_buff_size failed");
9049 return 0;
9050 }
9051 }
9052
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009053 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9054}
9055
9056
9057static int sta_set_wireless_60g(struct sigma_dut *dut,
9058 struct sigma_conn *conn,
9059 struct sigma_cmd *cmd)
9060{
9061 const char *dev_role = get_param(cmd, "DevRole");
9062
9063 if (!dev_role) {
9064 send_resp(dut, conn, SIGMA_INVALID,
9065 "ErrorCode,DevRole not specified");
9066 return 0;
9067 }
9068
9069 if (strcasecmp(dev_role, "PCP") == 0)
9070 return sta_set_60g_pcp(dut, conn, cmd);
9071 if (strcasecmp(dev_role, "STA") == 0)
9072 return sta_set_60g_sta(dut, conn, cmd);
9073 send_resp(dut, conn, SIGMA_INVALID,
9074 "ErrorCode,DevRole not supported");
9075 return 0;
9076}
9077
9078
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309079static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
9080 struct sigma_cmd *cmd)
9081{
9082 int status;
9083 const char *intf = get_param(cmd, "Interface");
9084 const char *val = get_param(cmd, "DevRole");
9085
9086 if (val && strcasecmp(val, "STA-CFON") == 0) {
9087 status = sta_cfon_set_wireless(dut, conn, cmd);
9088 if (status)
9089 return status;
9090 }
9091 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9092}
9093
9094
Jouni Malinen67433fc2020-06-26 22:50:33 +03009095static enum sigma_cmd_result
9096sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
9097 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309098{
9099 const char *intf = get_param(cmd, "Interface");
9100 const char *val;
9101
9102 val = get_param(cmd, "ocvc");
9103 if (val)
9104 dut->ocvc = atoi(val);
9105
Jouni Malinen67433fc2020-06-26 22:50:33 +03009106 val = get_param(cmd, "ClientPrivacy");
9107 if (val) {
9108 dut->client_privacy = atoi(val);
9109 if (dut->client_privacy &&
9110 (wpa_command(intf, "SET mac_addr 1") < 0 ||
9111 wpa_command(intf, "SET rand_addr_lifetime 1") < 0 ||
9112 wpa_command(intf, "SET preassoc_mac_addr 1") < 0 ||
9113 wpa_command(intf, "SET gas_rand_mac_addr 1") < 0 ||
9114 wpa_command(intf, "SET gas_rand_addr_lifetime 1") < 0)) {
9115 send_resp(dut, conn, SIGMA_ERROR,
9116 "errorCode,Failed to enable random MAC address use");
9117 return STATUS_SENT_ERROR;
9118 }
9119 }
9120
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309121 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9122}
9123
9124
Jouni Malinenf7222712019-06-13 01:50:21 +03009125static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
9126 struct sigma_conn *conn,
9127 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009128{
9129 const char *val;
9130
9131 val = get_param(cmd, "Program");
9132 if (val) {
9133 if (strcasecmp(val, "11n") == 0)
9134 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08009135 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009136 return cmd_sta_set_wireless_vht(dut, conn, cmd);
9137 if (strcasecmp(val, "60ghz") == 0)
9138 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309139 if (strcasecmp(val, "OCE") == 0)
9140 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02009141 /* sta_set_wireless in WPS program is only used for 60G */
9142 if (is_60g_sigma_dut(dut))
9143 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309144 if (strcasecmp(val, "WPA3") == 0)
9145 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009146 send_resp(dut, conn, SIGMA_ERROR,
9147 "ErrorCode,Program value not supported");
9148 } else {
9149 send_resp(dut, conn, SIGMA_ERROR,
9150 "ErrorCode,Program argument not available");
9151 }
9152
9153 return 0;
9154}
9155
9156
9157static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
9158 int tid)
9159{
9160 char buf[100];
9161 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
9162
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05309163 if (tid < 0 ||
9164 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
9165 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
9166 return;
9167 }
9168
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009169 /*
9170 * Two ways to ensure that addba request with a
9171 * non zero TID could be sent out. EV 117296
9172 */
9173 snprintf(buf, sizeof(buf),
9174 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
9175 tid);
9176 if (system(buf) != 0) {
9177 sigma_dut_print(dut, DUT_MSG_ERROR,
9178 "Ping did not send out");
9179 }
9180
9181 snprintf(buf, sizeof(buf),
9182 "iwconfig %s | grep Access | awk '{print $6}' > %s",
9183 intf, VI_QOS_TMP_FILE);
9184 if (system(buf) != 0)
9185 return;
9186
9187 snprintf(buf, sizeof(buf),
9188 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
9189 intf, VI_QOS_TMP_FILE);
9190 if (system(buf) != 0)
9191 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
9192
9193 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
9194 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
9195 if (system(buf) != 0) {
9196 sigma_dut_print(dut, DUT_MSG_ERROR,
9197 "VI_QOS_TEMP_FILE generation error failed");
9198 }
9199 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9200 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9201 if (system(buf) != 0) {
9202 sigma_dut_print(dut, DUT_MSG_ERROR,
9203 "VI_QOS_FILE generation failed");
9204 }
9205
9206 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9207 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9208 if (system(buf) != 0) {
9209 sigma_dut_print(dut, DUT_MSG_ERROR,
9210 "VI_QOS_FILE generation failed");
9211 }
9212
9213 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
9214 if (system(buf) != 0) {
9215 }
9216}
9217
9218
9219static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9220 struct sigma_cmd *cmd)
9221{
9222 const char *intf = get_param(cmd, "Interface");
9223 const char *val;
9224 int tid = 0;
9225 char buf[100];
9226
9227 val = get_param(cmd, "TID");
9228 if (val) {
9229 tid = atoi(val);
9230 if (tid)
9231 ath_sta_inject_frame(dut, intf, tid);
9232 }
9233
9234 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009235 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009236
9237 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
9238 if (system(buf) != 0) {
9239 sigma_dut_print(dut, DUT_MSG_ERROR,
9240 "wifitool senddelba failed");
9241 }
9242
9243 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
9244 if (system(buf) != 0) {
9245 sigma_dut_print(dut, DUT_MSG_ERROR,
9246 "wifitool sendaddba failed");
9247 }
9248
9249 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9250
9251 return 1;
9252}
9253
9254
Lior David9981b512017-01-20 13:16:40 +02009255#ifdef __linux__
9256
9257static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
9258 int agg_size)
9259{
9260 char dir[128], buf[128];
9261 FILE *f;
9262 regex_t re;
9263 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03009264 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02009265
9266 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
9267 sigma_dut_print(dut, DUT_MSG_ERROR,
9268 "failed to get wil6210 debugfs dir");
9269 return -1;
9270 }
9271
Jouni Malinen3aa72862019-05-29 23:14:51 +03009272 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
9273 if (res < 0 || res >= sizeof(buf))
9274 return -1;
Lior David9981b512017-01-20 13:16:40 +02009275 f = fopen(buf, "r");
9276 if (!f) {
9277 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009278 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009279 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9280 if (res < 0 || res >= sizeof(buf))
9281 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009282 f = fopen(buf, "r");
9283 if (!f) {
9284 sigma_dut_print(dut, DUT_MSG_ERROR,
9285 "failed to open: %s", buf);
9286 return -1;
9287 }
Lior David9981b512017-01-20 13:16:40 +02009288 }
9289
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009290 /* can be either VRING tx... or RING... */
9291 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009292 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9293 goto out;
9294 }
9295
9296 /* find TX VRING for the mac address */
9297 found = 0;
9298 while (fgets(buf, sizeof(buf), f)) {
9299 if (strcasestr(buf, dest_mac)) {
9300 found = 1;
9301 break;
9302 }
9303 }
9304
9305 if (!found) {
9306 sigma_dut_print(dut, DUT_MSG_ERROR,
9307 "no TX VRING for %s", dest_mac);
9308 goto out;
9309 }
9310
9311 /* extract VRING ID, "VRING tx_<id> = {" */
9312 if (!fgets(buf, sizeof(buf), f)) {
9313 sigma_dut_print(dut, DUT_MSG_ERROR,
9314 "no VRING start line for %s", dest_mac);
9315 goto out;
9316 }
9317
9318 rc = regexec(&re, buf, 2, m, 0);
9319 regfree(&re);
9320 if (rc || m[1].rm_so < 0) {
9321 sigma_dut_print(dut, DUT_MSG_ERROR,
9322 "no VRING TX ID for %s", dest_mac);
9323 goto out;
9324 }
9325 buf[m[1].rm_eo] = 0;
9326 vring_id = atoi(&buf[m[1].rm_so]);
9327
9328 /* send the addba command */
9329 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009330 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9331 if (res < 0 || res >= sizeof(buf))
9332 return -1;
Lior David9981b512017-01-20 13:16:40 +02009333 f = fopen(buf, "w");
9334 if (!f) {
9335 sigma_dut_print(dut, DUT_MSG_ERROR,
9336 "failed to open: %s", buf);
9337 return -1;
9338 }
9339
9340 fprintf(f, "add %d %d\n", vring_id, agg_size);
9341
9342 ret = 0;
9343
9344out:
9345 fclose(f);
9346
9347 return ret;
9348}
9349
9350
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009351int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9352 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009353{
9354 const char *val;
9355 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009356
9357 val = get_param(cmd, "TID");
9358 if (val) {
9359 tid = atoi(val);
9360 if (tid != 0) {
9361 sigma_dut_print(dut, DUT_MSG_ERROR,
9362 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9363 tid);
9364 }
9365 }
9366
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009367 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009368 if (!val) {
9369 sigma_dut_print(dut, DUT_MSG_ERROR,
9370 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009371 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009372 }
9373
Lior David9981b512017-01-20 13:16:40 +02009374 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009375 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009376
9377 return 1;
9378}
9379
Lior David9981b512017-01-20 13:16:40 +02009380#endif /* __linux__ */
9381
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009382
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009383static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9384 struct sigma_cmd *cmd)
9385{
9386#ifdef NL80211_SUPPORT
9387 const char *intf = get_param(cmd, "Interface");
9388 const char *val;
9389 int tid = -1;
9390 int bufsize = 64;
9391 struct nl_msg *msg;
9392 int ret = 0;
9393 struct nlattr *params;
9394 int ifindex;
9395
9396 val = get_param(cmd, "TID");
9397 if (val)
9398 tid = atoi(val);
9399
9400 if (tid == -1) {
9401 send_resp(dut, conn, SIGMA_ERROR,
9402 "ErrorCode,sta_send_addba tid invalid");
9403 return 0;
9404 }
9405
9406 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9407
9408 ifindex = if_nametoindex(intf);
9409 if (ifindex == 0) {
9410 sigma_dut_print(dut, DUT_MSG_ERROR,
9411 "%s: Index for interface %s failed",
9412 __func__, intf);
9413 send_resp(dut, conn, SIGMA_ERROR,
9414 "ErrorCode,sta_send_addba interface invalid");
9415 return 0;
9416 }
9417
9418 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9419 NL80211_CMD_VENDOR)) ||
9420 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9421 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9422 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9423 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9424 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9425 nla_put_u8(msg,
9426 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9427 QCA_WLAN_ADD_BA) ||
9428 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9429 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009430 nla_put_u16(msg,
9431 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9432 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009433 sigma_dut_print(dut, DUT_MSG_ERROR,
9434 "%s: err in adding vendor_cmd and vendor_data",
9435 __func__);
9436 nlmsg_free(msg);
9437 send_resp(dut, conn, SIGMA_ERROR,
9438 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9439 return 0;
9440 }
9441 nla_nest_end(msg, params);
9442
9443 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9444 if (ret) {
9445 sigma_dut_print(dut, DUT_MSG_ERROR,
9446 "%s: err in send_and_recv_msgs, ret=%d",
9447 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309448 if (ret == -EOPNOTSUPP)
9449 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009450 send_resp(dut, conn, SIGMA_ERROR,
9451 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9452 return 0;
9453 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009454#else /* NL80211_SUPPORT */
9455 sigma_dut_print(dut, DUT_MSG_ERROR,
9456 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009457#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309458
9459 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009460}
9461
9462
Jouni Malinenf7222712019-06-13 01:50:21 +03009463static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9464 struct sigma_conn *conn,
9465 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009466{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009467 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009468 case DRIVER_ATHEROS:
9469 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009470 case DRIVER_WCN:
9471 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009472#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009473 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009474 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009475#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009476 default:
9477 /*
9478 * There is no driver specific implementation for other drivers.
9479 * Ignore the command and report COMPLETE since the following
9480 * throughput test operation will end up sending ADDBA anyway.
9481 */
9482 return 1;
9483 }
9484}
9485
9486
9487int inject_eth_frame(int s, const void *data, size_t len,
9488 unsigned short ethtype, char *dst, char *src)
9489{
9490 struct iovec iov[4] = {
9491 {
9492 .iov_base = dst,
9493 .iov_len = ETH_ALEN,
9494 },
9495 {
9496 .iov_base = src,
9497 .iov_len = ETH_ALEN,
9498 },
9499 {
9500 .iov_base = &ethtype,
9501 .iov_len = sizeof(unsigned short),
9502 },
9503 {
9504 .iov_base = (void *) data,
9505 .iov_len = len,
9506 }
9507 };
9508 struct msghdr msg = {
9509 .msg_name = NULL,
9510 .msg_namelen = 0,
9511 .msg_iov = iov,
9512 .msg_iovlen = 4,
9513 .msg_control = NULL,
9514 .msg_controllen = 0,
9515 .msg_flags = 0,
9516 };
9517
9518 return sendmsg(s, &msg, 0);
9519}
9520
9521#if defined(__linux__) || defined(__QNXNTO__)
9522
9523int inject_frame(int s, const void *data, size_t len, int encrypt)
9524{
9525#define IEEE80211_RADIOTAP_F_WEP 0x04
9526#define IEEE80211_RADIOTAP_F_FRAG 0x08
9527 unsigned char rtap_hdr[] = {
9528 0x00, 0x00, /* radiotap version */
9529 0x0e, 0x00, /* radiotap length */
9530 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9531 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9532 0x00, /* padding */
9533 0x00, 0x00, /* RX and TX flags to indicate that */
9534 0x00, 0x00, /* this is the injected frame directly */
9535 };
9536 struct iovec iov[2] = {
9537 {
9538 .iov_base = &rtap_hdr,
9539 .iov_len = sizeof(rtap_hdr),
9540 },
9541 {
9542 .iov_base = (void *) data,
9543 .iov_len = len,
9544 }
9545 };
9546 struct msghdr msg = {
9547 .msg_name = NULL,
9548 .msg_namelen = 0,
9549 .msg_iov = iov,
9550 .msg_iovlen = 2,
9551 .msg_control = NULL,
9552 .msg_controllen = 0,
9553 .msg_flags = 0,
9554 };
9555
9556 if (encrypt)
9557 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9558
9559 return sendmsg(s, &msg, 0);
9560}
9561
9562
9563int open_monitor(const char *ifname)
9564{
9565#ifdef __QNXNTO__
9566 struct sockaddr_dl ll;
9567 int s;
9568
9569 memset(&ll, 0, sizeof(ll));
9570 ll.sdl_family = AF_LINK;
9571 ll.sdl_index = if_nametoindex(ifname);
9572 if (ll.sdl_index == 0) {
9573 perror("if_nametoindex");
9574 return -1;
9575 }
9576 s = socket(PF_INET, SOCK_RAW, 0);
9577#else /* __QNXNTO__ */
9578 struct sockaddr_ll ll;
9579 int s;
9580
9581 memset(&ll, 0, sizeof(ll));
9582 ll.sll_family = AF_PACKET;
9583 ll.sll_ifindex = if_nametoindex(ifname);
9584 if (ll.sll_ifindex == 0) {
9585 perror("if_nametoindex");
9586 return -1;
9587 }
9588 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9589#endif /* __QNXNTO__ */
9590 if (s < 0) {
9591 perror("socket[PF_PACKET,SOCK_RAW]");
9592 return -1;
9593 }
9594
9595 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9596 perror("monitor socket bind");
9597 close(s);
9598 return -1;
9599 }
9600
9601 return s;
9602}
9603
9604
9605static int hex2num(char c)
9606{
9607 if (c >= '0' && c <= '9')
9608 return c - '0';
9609 if (c >= 'a' && c <= 'f')
9610 return c - 'a' + 10;
9611 if (c >= 'A' && c <= 'F')
9612 return c - 'A' + 10;
9613 return -1;
9614}
9615
9616
9617int hwaddr_aton(const char *txt, unsigned char *addr)
9618{
9619 int i;
9620
9621 for (i = 0; i < 6; i++) {
9622 int a, b;
9623
9624 a = hex2num(*txt++);
9625 if (a < 0)
9626 return -1;
9627 b = hex2num(*txt++);
9628 if (b < 0)
9629 return -1;
9630 *addr++ = (a << 4) | b;
9631 if (i < 5 && *txt++ != ':')
9632 return -1;
9633 }
9634
9635 return 0;
9636}
9637
9638#endif /* defined(__linux__) || defined(__QNXNTO__) */
9639
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309640
9641#ifdef NL80211_SUPPORT
9642static int nl80211_send_frame_cmd(struct sigma_dut *dut, const char *intf,
9643 const u8 *data, size_t data_len, int freq)
9644{
9645 struct nl_msg *msg;
9646 int ret = 0;
9647 int ifindex;
9648
9649 ifindex = if_nametoindex(intf);
9650 if (ifindex == 0) {
9651 sigma_dut_print(dut, DUT_MSG_ERROR,
9652 "%s: Index for interface %s failed",
9653 __func__, intf);
9654 return -1;
9655 }
9656
9657 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9658 NL80211_CMD_FRAME)) ||
9659 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
9660 nla_put(msg, NL80211_ATTR_FRAME, data_len, data)) {
9661 sigma_dut_print(dut, DUT_MSG_ERROR,
9662 "%s: Error in adding NL80211_CMD_FRAME",
9663 __func__);
9664 nlmsg_free(msg);
9665 return -1;
9666 }
9667
9668 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9669 if (ret) {
9670 sigma_dut_print(dut, DUT_MSG_ERROR,
9671 "nl80211: Frame command failed: ret=%d (%s) req=%u",
9672 ret, strerror(-ret), freq);
9673 return -1;
9674 }
9675
9676 return 0;
9677}
9678#endif /* NL80211_SUPPORT */
9679
9680
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009681enum send_frame_type {
9682 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9683};
9684enum send_frame_protection {
9685 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9686};
9687
9688
9689static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309690 const char *intf, enum send_frame_type frame,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009691 enum send_frame_protection protected,
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309692 const char *dest, int use_monitor)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009693{
9694#ifdef __linux__
9695 unsigned char buf[1000], *pos;
9696 int s, res;
9697 char bssid[20], addr[20];
9698 char result[32], ssid[100];
9699 size_t ssid_len;
9700
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009701 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009702 sizeof(result)) < 0 ||
9703 strncmp(result, "COMPLETED", 9) != 0) {
9704 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9705 return 0;
9706 }
9707
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009708 if (get_wpa_status(get_station_ifname(dut), "bssid",
9709 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009710 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9711 "current BSSID");
9712 return 0;
9713 }
9714
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009715 if (get_wpa_status(get_station_ifname(dut), "address",
9716 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009717 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9718 "own MAC address");
9719 return 0;
9720 }
9721
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009722 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009723 < 0) {
9724 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9725 "current SSID");
9726 return 0;
9727 }
9728 ssid_len = strlen(ssid);
9729
9730 pos = buf;
9731
9732 /* Frame Control */
9733 switch (frame) {
9734 case DISASSOC:
9735 *pos++ = 0xa0;
9736 break;
9737 case DEAUTH:
9738 *pos++ = 0xc0;
9739 break;
9740 case SAQUERY:
9741 *pos++ = 0xd0;
9742 break;
9743 case AUTH:
9744 *pos++ = 0xb0;
9745 break;
9746 case ASSOCREQ:
9747 *pos++ = 0x00;
9748 break;
9749 case REASSOCREQ:
9750 *pos++ = 0x20;
9751 break;
9752 case DLS_REQ:
9753 *pos++ = 0xd0;
9754 break;
9755 }
9756
9757 if (protected == INCORRECT_KEY)
9758 *pos++ = 0x40; /* Set Protected field to 1 */
9759 else
9760 *pos++ = 0x00;
9761
9762 /* Duration */
9763 *pos++ = 0x00;
9764 *pos++ = 0x00;
9765
9766 /* addr1 = DA (current AP) */
9767 hwaddr_aton(bssid, pos);
9768 pos += 6;
9769 /* addr2 = SA (own address) */
9770 hwaddr_aton(addr, pos);
9771 pos += 6;
9772 /* addr3 = BSSID (current AP) */
9773 hwaddr_aton(bssid, pos);
9774 pos += 6;
9775
9776 /* Seq# (to be filled by driver/mac80211) */
9777 *pos++ = 0x00;
9778 *pos++ = 0x00;
9779
9780 if (protected == INCORRECT_KEY) {
9781 /* CCMP parameters */
9782 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9783 pos += 8;
9784 }
9785
9786 if (protected == INCORRECT_KEY) {
9787 switch (frame) {
9788 case DEAUTH:
9789 /* Reason code (encrypted) */
9790 memcpy(pos, "\xa7\x39", 2);
9791 pos += 2;
9792 break;
9793 case DISASSOC:
9794 /* Reason code (encrypted) */
9795 memcpy(pos, "\xa7\x39", 2);
9796 pos += 2;
9797 break;
9798 case SAQUERY:
9799 /* Category|Action|TransID (encrypted) */
9800 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9801 pos += 4;
9802 break;
9803 default:
9804 return -1;
9805 }
9806
9807 /* CCMP MIC */
9808 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9809 pos += 8;
9810 } else {
9811 switch (frame) {
9812 case DEAUTH:
9813 /* reason code = 8 */
9814 *pos++ = 0x08;
9815 *pos++ = 0x00;
9816 break;
9817 case DISASSOC:
9818 /* reason code = 8 */
9819 *pos++ = 0x08;
9820 *pos++ = 0x00;
9821 break;
9822 case SAQUERY:
9823 /* Category - SA Query */
9824 *pos++ = 0x08;
9825 /* SA query Action - Request */
9826 *pos++ = 0x00;
9827 /* Transaction ID */
9828 *pos++ = 0x12;
9829 *pos++ = 0x34;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05309830 if (dut->saquery_oci_freq) {
9831 /* OCI IE - Extended ID */
9832 *pos++ = 0xFF;
9833 *pos++ = 0x04;
9834 *pos++ = 0x36;
9835 /* Operating Class */
9836 *pos++ = 0x74;
9837 /* Primary Channel */
9838 *pos++ = freq_to_channel(dut->saquery_oci_freq);
9839 /* Frequency Segment 1 Channel Number */
9840 *pos++ = 0x00;
9841 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009842 break;
9843 case AUTH:
9844 /* Auth Alg (Open) */
9845 *pos++ = 0x00;
9846 *pos++ = 0x00;
9847 /* Seq# */
9848 *pos++ = 0x01;
9849 *pos++ = 0x00;
9850 /* Status code */
9851 *pos++ = 0x00;
9852 *pos++ = 0x00;
9853 break;
9854 case ASSOCREQ:
9855 /* Capability Information */
9856 *pos++ = 0x31;
9857 *pos++ = 0x04;
9858 /* Listen Interval */
9859 *pos++ = 0x0a;
9860 *pos++ = 0x00;
9861 /* SSID */
9862 *pos++ = 0x00;
9863 *pos++ = ssid_len;
9864 memcpy(pos, ssid, ssid_len);
9865 pos += ssid_len;
9866 /* Supported Rates */
9867 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9868 10);
9869 pos += 10;
9870 /* Extended Supported Rates */
9871 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9872 pos += 6;
9873 /* RSN */
9874 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9875 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9876 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9877 pos += 28;
9878 break;
9879 case REASSOCREQ:
9880 /* Capability Information */
9881 *pos++ = 0x31;
9882 *pos++ = 0x04;
9883 /* Listen Interval */
9884 *pos++ = 0x0a;
9885 *pos++ = 0x00;
9886 /* Current AP */
9887 hwaddr_aton(bssid, pos);
9888 pos += 6;
9889 /* SSID */
9890 *pos++ = 0x00;
9891 *pos++ = ssid_len;
9892 memcpy(pos, ssid, ssid_len);
9893 pos += ssid_len;
9894 /* Supported Rates */
9895 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9896 10);
9897 pos += 10;
9898 /* Extended Supported Rates */
9899 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9900 pos += 6;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05309901 /* RSNE - Group and Pairwise ciphers */
9902 memcpy(pos,
9903 "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04",
9904 14);
9905 pos += 14;
9906 /* RSNE - AKM Suite count */
9907 *pos++ = 0x01;
9908 *pos++ = 0x00;
9909 /* RSNE - AKM Suites */
9910 if (dut->program == PROGRAM_WPA3)
9911 memcpy(pos, "\x00\x0f\xac\x08", 4);
9912 else
9913 memcpy(pos, "\x00\x0f\xac\x02", 4);
9914 pos += 4;
9915 /* RSNE - Capabilities */
9916 *pos++ = 0xc0;
9917 if (dut->ocvc)
9918 *pos++ = 0x40;
9919 else
9920 *pos++ = 0x00;
9921 /* RSNE - PMKID list and Group Management Ciphers */
9922 memcpy(pos, "\x00\x00\x00\x0f\xac\x06", 6);
9923 pos += 6;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009924 break;
9925 case DLS_REQ:
9926 /* Category - DLS */
9927 *pos++ = 0x02;
9928 /* DLS Action - Request */
9929 *pos++ = 0x00;
9930 /* Destination MACAddress */
9931 if (dest)
9932 hwaddr_aton(dest, pos);
9933 else
9934 memset(pos, 0, 6);
9935 pos += 6;
9936 /* Source MACAddress */
9937 hwaddr_aton(addr, pos);
9938 pos += 6;
9939 /* Capability Information */
9940 *pos++ = 0x10; /* Privacy */
9941 *pos++ = 0x06; /* QoS */
9942 /* DLS Timeout Value */
9943 *pos++ = 0x00;
9944 *pos++ = 0x01;
9945 /* Supported rates */
9946 *pos++ = 0x01;
9947 *pos++ = 0x08;
9948 *pos++ = 0x0c; /* 6 Mbps */
9949 *pos++ = 0x12; /* 9 Mbps */
9950 *pos++ = 0x18; /* 12 Mbps */
9951 *pos++ = 0x24; /* 18 Mbps */
9952 *pos++ = 0x30; /* 24 Mbps */
9953 *pos++ = 0x48; /* 36 Mbps */
9954 *pos++ = 0x60; /* 48 Mbps */
9955 *pos++ = 0x6c; /* 54 Mbps */
9956 /* TODO: Extended Supported Rates */
9957 /* TODO: HT Capabilities */
9958 break;
9959 }
9960 }
9961
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309962 if (use_monitor) {
9963 s = open_monitor("sigmadut");
9964 if (s < 0) {
9965 send_resp(dut, conn, SIGMA_ERROR,
9966 "errorCode,Failed to open monitor socket");
9967 return 0;
9968 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009969
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309970 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
9971 if (res < 0) {
9972 send_resp(dut, conn, SIGMA_ERROR,
9973 "errorCode,Failed to inject frame");
9974 close(s);
9975 return 0;
9976 }
9977 if (res < pos - buf) {
9978 send_resp(dut, conn, SIGMA_ERROR,
9979 "errorCode,Only partial frame sent");
9980 close(s);
9981 return 0;
9982 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009983
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309984 close(s);
9985 } else {
9986#ifdef NL80211_SUPPORT
9987 int freq;
9988 char freq_str[10];
9989
9990 if (get_wpa_status(get_station_ifname(dut), "freq",
9991 freq_str, sizeof(freq_str)) < 0) {
9992 send_resp(dut, conn, SIGMA_ERROR,
9993 "errorCode,Could not get current operating frequency");
9994 return 0;
9995 }
9996 freq = atoi(freq_str);
9997
9998 if (nl80211_send_frame_cmd(dut, intf, buf, pos - buf, freq)) {
9999 send_resp(dut, conn, SIGMA_ERROR,
10000 "errorCode,Failed to inject frame");
10001 return 0;
10002 }
10003#else /* NL80211_SUPPORT */
10004 send_resp(dut, conn, SIGMA_ERROR,
10005 "errorCode,Failed to inject frame (no NL80211_SUPPORT)");
10006 return 0;
10007#endif /* NL80211_SUPPORT */
10008 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010009
10010 return 1;
10011#else /* __linux__ */
10012 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
10013 "yet supported");
10014 return 0;
10015#endif /* __linux__ */
10016}
10017
10018
10019static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
10020 struct sigma_conn *conn,
10021 struct sigma_cmd *cmd)
10022{
10023 const char *intf = get_param(cmd, "Interface");
10024 const char *sta, *val;
10025 unsigned char addr[ETH_ALEN];
10026 char buf[100];
10027
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010028 if (!intf)
10029 return -1;
10030
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010031 sta = get_param(cmd, "peer");
10032 if (sta == NULL)
10033 sta = get_param(cmd, "station");
10034 if (sta == NULL) {
10035 send_resp(dut, conn, SIGMA_ERROR,
10036 "ErrorCode,Missing peer address");
10037 return 0;
10038 }
10039 if (hwaddr_aton(sta, addr) < 0) {
10040 send_resp(dut, conn, SIGMA_ERROR,
10041 "ErrorCode,Invalid peer address");
10042 return 0;
10043 }
10044
10045 val = get_param(cmd, "type");
10046 if (val == NULL)
10047 return -1;
10048
10049 if (strcasecmp(val, "DISCOVERY") == 0) {
10050 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
10051 if (wpa_command(intf, buf) < 0) {
10052 send_resp(dut, conn, SIGMA_ERROR,
10053 "ErrorCode,Failed to send TDLS discovery");
10054 return 0;
10055 }
10056 return 1;
10057 }
10058
10059 if (strcasecmp(val, "SETUP") == 0) {
10060 int status = 0, timeout = 0;
10061
10062 val = get_param(cmd, "Status");
10063 if (val)
10064 status = atoi(val);
10065
10066 val = get_param(cmd, "Timeout");
10067 if (val)
10068 timeout = atoi(val);
10069
10070 if (status != 0 && status != 37) {
10071 send_resp(dut, conn, SIGMA_ERROR,
10072 "ErrorCode,Unsupported status value");
10073 return 0;
10074 }
10075
10076 if (timeout != 0 && timeout != 301) {
10077 send_resp(dut, conn, SIGMA_ERROR,
10078 "ErrorCode,Unsupported timeout value");
10079 return 0;
10080 }
10081
10082 if (status && timeout) {
10083 send_resp(dut, conn, SIGMA_ERROR,
10084 "ErrorCode,Unsupported timeout+status "
10085 "combination");
10086 return 0;
10087 }
10088
10089 if (status == 37 &&
10090 wpa_command(intf, "SET tdls_testing 0x200")) {
10091 send_resp(dut, conn, SIGMA_ERROR,
10092 "ErrorCode,Failed to enable "
10093 "decline setup response test mode");
10094 return 0;
10095 }
10096
10097 if (timeout == 301) {
10098 int res;
10099 if (dut->no_tpk_expiration)
10100 res = wpa_command(intf,
10101 "SET tdls_testing 0x108");
10102 else
10103 res = wpa_command(intf,
10104 "SET tdls_testing 0x8");
10105 if (res) {
10106 send_resp(dut, conn, SIGMA_ERROR,
10107 "ErrorCode,Failed to set short TPK "
10108 "lifetime");
10109 return 0;
10110 }
10111 }
10112
10113 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
10114 if (wpa_command(intf, buf) < 0) {
10115 send_resp(dut, conn, SIGMA_ERROR,
10116 "ErrorCode,Failed to send TDLS setup");
10117 return 0;
10118 }
10119 return 1;
10120 }
10121
10122 if (strcasecmp(val, "TEARDOWN") == 0) {
10123 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
10124 if (wpa_command(intf, buf) < 0) {
10125 send_resp(dut, conn, SIGMA_ERROR,
10126 "ErrorCode,Failed to send TDLS teardown");
10127 return 0;
10128 }
10129 return 1;
10130 }
10131
10132 send_resp(dut, conn, SIGMA_ERROR,
10133 "ErrorCode,Unsupported TDLS frame");
10134 return 0;
10135}
10136
10137
10138static int sta_ap_known(const char *ifname, const char *bssid)
10139{
10140 char buf[4096];
10141
Jouni Malinendd32f192018-09-15 02:55:19 +030010142 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010143 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
10144 return 0;
10145 if (strncmp(buf, "id=", 3) != 0)
10146 return 0;
10147 return 1;
10148}
10149
10150
10151static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
10152 const char *bssid)
10153{
10154 int res;
10155 struct wpa_ctrl *ctrl;
10156 char buf[256];
10157
10158 if (sta_ap_known(ifname, bssid))
10159 return 0;
10160 sigma_dut_print(dut, DUT_MSG_DEBUG,
10161 "AP not in BSS table - start scan");
10162
10163 ctrl = open_wpa_mon(ifname);
10164 if (ctrl == NULL) {
10165 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10166 "wpa_supplicant monitor connection");
10167 return -1;
10168 }
10169
10170 if (wpa_command(ifname, "SCAN") < 0) {
10171 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
10172 wpa_ctrl_detach(ctrl);
10173 wpa_ctrl_close(ctrl);
10174 return -1;
10175 }
10176
10177 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
10178 buf, sizeof(buf));
10179
10180 wpa_ctrl_detach(ctrl);
10181 wpa_ctrl_close(ctrl);
10182
10183 if (res < 0) {
10184 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
10185 return -1;
10186 }
10187
10188 if (sta_ap_known(ifname, bssid))
10189 return 0;
10190 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
10191 return -1;
10192}
10193
10194
10195static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
10196 struct sigma_conn *conn,
10197 struct sigma_cmd *cmd,
10198 const char *intf)
10199{
10200 char buf[200];
10201
10202 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
10203 if (system(buf) != 0) {
10204 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
10205 "ndsend");
10206 return 0;
10207 }
10208
10209 return 1;
10210}
10211
10212
10213static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
10214 struct sigma_conn *conn,
10215 struct sigma_cmd *cmd,
10216 const char *intf)
10217{
10218 char buf[200];
10219 const char *ip = get_param(cmd, "SenderIP");
10220
Peng Xu26b356d2017-10-04 17:58:16 -070010221 if (!ip)
10222 return 0;
10223
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010224 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
10225 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10226 if (system(buf) == 0) {
10227 sigma_dut_print(dut, DUT_MSG_INFO,
10228 "Neighbor Solicitation got a response "
10229 "for %s@%s", ip, intf);
10230 }
10231
10232 return 1;
10233}
10234
10235
10236static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
10237 struct sigma_conn *conn,
10238 struct sigma_cmd *cmd,
10239 const char *ifname)
10240{
10241 char buf[200];
10242 const char *ip = get_param(cmd, "SenderIP");
10243
10244 if (ip == NULL) {
10245 send_resp(dut, conn, SIGMA_ERROR,
10246 "ErrorCode,Missing SenderIP parameter");
10247 return 0;
10248 }
10249 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
10250 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10251 if (system(buf) != 0) {
10252 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
10253 "for %s@%s", ip, ifname);
10254 }
10255
10256 return 1;
10257}
10258
10259
10260static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
10261 struct sigma_conn *conn,
10262 struct sigma_cmd *cmd,
10263 const char *ifname)
10264{
10265 char buf[200];
10266 char ip[16];
10267 int s;
Peng Xub3756882017-10-04 14:39:09 -070010268 struct ifreq ifr;
10269 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010270
10271 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070010272 if (s < 0) {
10273 perror("socket");
10274 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010275 }
10276
Peng Xub3756882017-10-04 14:39:09 -070010277 memset(&ifr, 0, sizeof(ifr));
10278 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
10279 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
10280 sigma_dut_print(dut, DUT_MSG_INFO,
10281 "Failed to get %s IP address: %s",
10282 ifname, strerror(errno));
10283 close(s);
10284 return -1;
10285 }
10286 close(s);
10287
10288 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
10289 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
10290
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010291 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
10292 ip);
10293 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10294 if (system(buf) != 0) {
10295 }
10296
10297 return 1;
10298}
10299
10300
10301static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
10302 struct sigma_conn *conn,
10303 struct sigma_cmd *cmd,
10304 const char *ifname)
10305{
10306 char buf[200], addr[20];
10307 char dst[ETH_ALEN], src[ETH_ALEN];
10308 short ethtype = htons(ETH_P_ARP);
10309 char *pos;
10310 int s, res;
10311 const char *val;
10312 struct sockaddr_in taddr;
10313
10314 val = get_param(cmd, "dest");
10315 if (val)
10316 hwaddr_aton(val, (unsigned char *) dst);
10317
10318 val = get_param(cmd, "DestIP");
10319 if (val)
10320 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070010321 else
10322 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010323
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010324 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010325 sizeof(addr)) < 0)
10326 return -2;
10327 hwaddr_aton(addr, (unsigned char *) src);
10328
10329 pos = buf;
10330 *pos++ = 0x00;
10331 *pos++ = 0x01;
10332 *pos++ = 0x08;
10333 *pos++ = 0x00;
10334 *pos++ = 0x06;
10335 *pos++ = 0x04;
10336 *pos++ = 0x00;
10337 *pos++ = 0x02;
10338 memcpy(pos, src, ETH_ALEN);
10339 pos += ETH_ALEN;
10340 memcpy(pos, &taddr.sin_addr, 4);
10341 pos += 4;
10342 memcpy(pos, dst, ETH_ALEN);
10343 pos += ETH_ALEN;
10344 memcpy(pos, &taddr.sin_addr, 4);
10345 pos += 4;
10346
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010347 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010348 if (s < 0) {
10349 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
10350 "monitor socket");
10351 return 0;
10352 }
10353
10354 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
10355 if (res < 0) {
10356 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
10357 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053010358 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010359 return 0;
10360 }
10361
10362 close(s);
10363
10364 return 1;
10365}
10366
10367
10368static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
10369 struct sigma_conn *conn,
10370 struct sigma_cmd *cmd,
10371 const char *intf, const char *dest)
10372{
10373 char buf[100];
10374
10375 if (if_nametoindex("sigmadut") == 0) {
10376 snprintf(buf, sizeof(buf),
10377 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010378 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010379 if (system(buf) != 0 ||
10380 if_nametoindex("sigmadut") == 0) {
10381 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10382 "monitor interface with '%s'", buf);
10383 return -2;
10384 }
10385 }
10386
10387 if (system("ifconfig sigmadut up") != 0) {
10388 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10389 "monitor interface up");
10390 return -2;
10391 }
10392
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010393 return sta_inject_frame(dut, conn, intf, DLS_REQ, UNPROTECTED, dest, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010394}
10395
10396
10397static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10398 struct sigma_conn *conn,
10399 struct sigma_cmd *cmd)
10400{
10401 const char *intf = get_param(cmd, "Interface");
10402 const char *dest = get_param(cmd, "Dest");
10403 const char *type = get_param(cmd, "FrameName");
10404 const char *val;
10405 char buf[200], *pos, *end;
10406 int count, count2;
10407
10408 if (type == NULL)
10409 type = get_param(cmd, "Type");
10410
10411 if (intf == NULL || dest == NULL || type == NULL)
10412 return -1;
10413
10414 if (strcasecmp(type, "NeighAdv") == 0)
10415 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10416
10417 if (strcasecmp(type, "NeighSolicitReq") == 0)
10418 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10419
10420 if (strcasecmp(type, "ARPProbe") == 0)
10421 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10422
10423 if (strcasecmp(type, "ARPAnnounce") == 0)
10424 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10425
10426 if (strcasecmp(type, "ARPReply") == 0)
10427 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10428
10429 if (strcasecmp(type, "DLS-request") == 0 ||
10430 strcasecmp(type, "DLSrequest") == 0)
10431 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10432 dest);
10433
10434 if (strcasecmp(type, "ANQPQuery") != 0 &&
10435 strcasecmp(type, "Query") != 0) {
10436 send_resp(dut, conn, SIGMA_ERROR,
10437 "ErrorCode,Unsupported HS 2.0 send frame type");
10438 return 0;
10439 }
10440
10441 if (sta_scan_ap(dut, intf, dest) < 0) {
10442 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10443 "the requested AP");
10444 return 0;
10445 }
10446
10447 pos = buf;
10448 end = buf + sizeof(buf);
10449 count = 0;
10450 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10451
10452 val = get_param(cmd, "ANQP_CAP_LIST");
10453 if (val && atoi(val)) {
10454 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10455 count++;
10456 }
10457
10458 val = get_param(cmd, "VENUE_NAME");
10459 if (val && atoi(val)) {
10460 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10461 count++;
10462 }
10463
10464 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10465 if (val && atoi(val)) {
10466 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10467 count++;
10468 }
10469
10470 val = get_param(cmd, "ROAMING_CONS");
10471 if (val && atoi(val)) {
10472 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10473 count++;
10474 }
10475
10476 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10477 if (val && atoi(val)) {
10478 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10479 count++;
10480 }
10481
10482 val = get_param(cmd, "NAI_REALM_LIST");
10483 if (val && atoi(val)) {
10484 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10485 count++;
10486 }
10487
10488 val = get_param(cmd, "3GPP_INFO");
10489 if (val && atoi(val)) {
10490 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10491 count++;
10492 }
10493
10494 val = get_param(cmd, "DOMAIN_LIST");
10495 if (val && atoi(val)) {
10496 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10497 count++;
10498 }
10499
Jouni Malinen34cf9532018-04-29 19:26:33 +030010500 val = get_param(cmd, "Venue_URL");
10501 if (val && atoi(val)) {
10502 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10503 count++;
10504 }
10505
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010506 val = get_param(cmd, "Advice_Of_Charge");
10507 if (val && atoi(val)) {
10508 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10509 count++;
10510 }
10511
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010512 if (count && wpa_command(intf, buf)) {
10513 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10514 return 0;
10515 }
10516
10517 pos = buf;
10518 end = buf + sizeof(buf);
10519 count2 = 0;
10520 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
10521
10522 val = get_param(cmd, "HS_CAP_LIST");
10523 if (val && atoi(val)) {
10524 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
10525 count2++;
10526 }
10527
10528 val = get_param(cmd, "OPER_NAME");
10529 if (val && atoi(val)) {
10530 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
10531 count2++;
10532 }
10533
10534 val = get_param(cmd, "WAN_METRICS");
10535 if (!val)
10536 val = get_param(cmd, "WAN_MAT");
10537 if (!val)
10538 val = get_param(cmd, "WAN_MET");
10539 if (val && atoi(val)) {
10540 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10541 count2++;
10542 }
10543
10544 val = get_param(cmd, "CONNECTION_CAPABILITY");
10545 if (val && atoi(val)) {
10546 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10547 count2++;
10548 }
10549
10550 val = get_param(cmd, "OP_CLASS");
10551 if (val && atoi(val)) {
10552 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10553 count2++;
10554 }
10555
10556 val = get_param(cmd, "OSU_PROVIDER_LIST");
10557 if (val && atoi(val)) {
10558 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10559 count2++;
10560 }
10561
Jouni Malinenf67afec2018-04-29 19:24:58 +030010562 val = get_param(cmd, "OPER_ICON_METADATA");
10563 if (!val)
10564 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10565 if (val && atoi(val)) {
10566 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10567 count2++;
10568 }
10569
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010570 if (count && count2) {
10571 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10572 "second query");
10573 sleep(1);
10574 }
10575
10576 if (count2 && wpa_command(intf, buf)) {
10577 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10578 "failed");
10579 return 0;
10580 }
10581
10582 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10583 if (val) {
10584 if (count || count2) {
10585 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10586 "sending out second query");
10587 sleep(1);
10588 }
10589
10590 if (strcmp(val, "1") == 0)
10591 val = "mail.example.com";
10592 snprintf(buf, end - pos,
10593 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10594 dest, val);
10595 if (wpa_command(intf, buf)) {
10596 send_resp(dut, conn, SIGMA_ERROR,
10597 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10598 "failed");
10599 return 0;
10600 }
10601 }
10602
10603 val = get_param(cmd, "ICON_REQUEST");
10604 if (val) {
10605 if (count || count2) {
10606 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10607 "sending out second query");
10608 sleep(1);
10609 }
10610
10611 snprintf(buf, end - pos,
10612 "HS20_ICON_REQUEST %s %s", dest, val);
10613 if (wpa_command(intf, buf)) {
10614 send_resp(dut, conn, SIGMA_ERROR,
10615 "ErrorCode,HS20_ICON_REQUEST failed");
10616 return 0;
10617 }
10618 }
10619
10620 return 1;
10621}
10622
10623
10624static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10625 struct sigma_conn *conn,
10626 struct sigma_cmd *cmd)
10627{
10628 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010629 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010630 int chwidth, nss;
10631
10632 val = get_param(cmd, "framename");
10633 if (!val)
10634 return -1;
10635 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10636
10637 /* Command sequence to generate Op mode notification */
10638 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010639 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010640
10641 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010642 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010643
10644 /* Extract Channel width */
10645 val = get_param(cmd, "Channel_width");
10646 if (val) {
10647 switch (atoi(val)) {
10648 case 20:
10649 chwidth = 0;
10650 break;
10651 case 40:
10652 chwidth = 1;
10653 break;
10654 case 80:
10655 chwidth = 2;
10656 break;
10657 case 160:
10658 chwidth = 3;
10659 break;
10660 default:
10661 chwidth = 2;
10662 break;
10663 }
10664
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010665 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010666 }
10667
10668 /* Extract NSS */
10669 val = get_param(cmd, "NSS");
10670 if (val) {
10671 switch (atoi(val)) {
10672 case 1:
10673 nss = 1;
10674 break;
10675 case 2:
10676 nss = 3;
10677 break;
10678 case 3:
10679 nss = 7;
10680 break;
10681 default:
10682 /* We do not support NSS > 3 */
10683 nss = 3;
10684 break;
10685 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010686 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010687 }
10688
10689 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010690 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010691 }
10692
10693 return 1;
10694}
10695
10696
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010697static int wcn_sta_set_pmf_config(struct sigma_dut *dut, const char *intf,
10698 enum send_frame_protection protected)
10699{
10700#ifdef NL80211_SUPPORT
10701 struct nl_msg *msg;
10702 int ret = 0;
10703 struct nlattr *params;
10704 int ifindex;
10705
10706 ifindex = if_nametoindex(intf);
10707 if (ifindex == 0) {
10708 sigma_dut_print(dut, DUT_MSG_ERROR,
10709 "%s: Index for interface %s failed",
10710 __func__, intf);
10711 return -1;
10712 }
10713
10714 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10715 NL80211_CMD_VENDOR)) ||
10716 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
10717 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10718 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10719 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
10720 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10721 nla_put_u8(msg,
10722 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PMF_PROTECTION,
10723 protected)) {
10724 sigma_dut_print(dut, DUT_MSG_ERROR,
10725 "%s: err in adding vendor_cmd and vendor_data",
10726 __func__);
10727 nlmsg_free(msg);
10728 return -1;
10729 }
10730 nla_nest_end(msg, params);
10731
10732 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
10733 if (ret) {
10734 sigma_dut_print(dut, DUT_MSG_ERROR,
10735 "%s: err in send_and_recv_msgs, ret=%d",
10736 __func__, ret);
10737 }
10738 return ret;
10739#else /* NL80211_SUPPORT */
10740 sigma_dut_print(dut, DUT_MSG_ERROR,
10741 "PMF config cannot be set without NL80211_SUPPORT defined");
10742 return -1;
10743#endif /* NL80211_SUPPORT */
10744}
10745
10746
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010747static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
10748 struct sigma_conn *conn,
10749 struct sigma_cmd *cmd)
10750{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010751 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010752 case DRIVER_ATHEROS:
10753 return ath_sta_send_frame_vht(dut, conn, cmd);
10754 default:
10755 send_resp(dut, conn, SIGMA_ERROR,
10756 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
10757 return 0;
10758 }
10759}
10760
10761
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010762static int wcn_sta_send_disassoc(struct sigma_dut *dut, const char *intf)
10763{
10764#ifdef NL80211_SUPPORT
10765 struct nl_msg *msg;
10766 int ret = 0;
10767 struct nlattr *params;
10768 int ifindex;
10769
10770 ifindex = if_nametoindex(intf);
10771 if (ifindex == 0) {
10772 sigma_dut_print(dut, DUT_MSG_ERROR,
10773 "%s: Index for interface %s failed",
10774 __func__, intf);
10775 return -1;
10776 }
10777
10778 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10779 NL80211_CMD_VENDOR)) ||
10780 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
10781 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10782 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10783 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
10784 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10785 nla_put_flag(msg,
10786 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISASSOC_TX)) {
10787 sigma_dut_print(dut, DUT_MSG_ERROR,
10788 "%s: err in adding vendor_cmd and vendor_data",
10789 __func__);
10790 nlmsg_free(msg);
10791 return -1;
10792 }
10793 nla_nest_end(msg, params);
10794
10795 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
10796 if (ret) {
10797 sigma_dut_print(dut, DUT_MSG_ERROR,
10798 "%s: err in send_and_recv_msgs, ret=%d",
10799 __func__, ret);
10800 }
10801 return ret;
10802#else /* NL80211_SUPPORT */
10803 sigma_dut_print(dut, DUT_MSG_ERROR,
10804 "Disassoc Tx cannot be done without NL80211_SUPPORT defined");
10805 return -1;
10806#endif /* NL80211_SUPPORT */
10807}
10808
10809
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010810static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
10811 struct sigma_cmd *cmd)
10812{
10813 const char *val;
10814 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010815 enum send_frame_protection protected;
10816 const char *pmf;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010817
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010818 if (!intf)
10819 return -1;
10820
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010821 val = get_param(cmd, "framename");
10822 if (!val)
10823 return -1;
10824 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10825
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010826 pmf = get_param(cmd, "PMFProtected");
10827 if (!pmf)
10828 pmf = get_param(cmd, "Protected");
10829 if (pmf) {
10830 if (strcasecmp(pmf, "Correct-key") == 0 ||
10831 strcasecmp(pmf, "CorrectKey") == 0) {
10832 protected = CORRECT_KEY;
10833 } else if (strcasecmp(pmf, "IncorrectKey") == 0) {
10834 protected = INCORRECT_KEY;
10835 } else if (strcasecmp(pmf, "Unprotected") == 0) {
10836 protected = UNPROTECTED;
10837 } else {
10838 send_resp(dut, conn, SIGMA_ERROR,
10839 "errorCode,Unsupported PMFProtected");
10840 return STATUS_SENT_ERROR;
10841 }
10842 sigma_dut_print(dut, DUT_MSG_DEBUG, "Config PMF protection %d",
10843 protected);
10844 wcn_sta_set_pmf_config(dut, intf, protected);
10845 }
10846
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010847 /* Command sequence to generate Op mode notification */
10848 if (val && strcasecmp(val, "action") == 0) {
10849 val = get_param(cmd, "PPDUTxType");
10850 if (val && strcasecmp(val, "TB") == 0) {
10851 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
10852 sigma_dut_print(dut, DUT_MSG_ERROR,
10853 "failed to send TB PPDU Tx cfg");
10854 send_resp(dut, conn, SIGMA_ERROR,
10855 "ErrorCode,set TB PPDU Tx cfg failed");
10856 return 0;
10857 }
10858 return 1;
10859 }
10860
10861 sigma_dut_print(dut, DUT_MSG_ERROR,
10862 "Action Tx type is not defined");
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010863
10864 return SUCCESS_SEND_STATUS;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010865 }
10866
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010867 if (strcasecmp(val, "disassoc") == 0)
10868 wcn_sta_send_disassoc(dut, intf);
10869
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010870 return 1;
10871}
10872
10873
10874static int cmd_sta_send_frame_he(struct sigma_dut *dut,
10875 struct sigma_conn *conn,
10876 struct sigma_cmd *cmd)
10877{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010878 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010879 case DRIVER_WCN:
10880 return wcn_sta_send_frame_he(dut, conn, cmd);
10881 default:
10882 send_resp(dut, conn, SIGMA_ERROR,
10883 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
10884 return 0;
10885 }
10886}
10887
10888
Lior David0fe101e2017-03-09 16:09:50 +020010889#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010890
10891static int
10892wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
10893 const char *frame_name, const char *dest_mac)
10894{
10895 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
10896 const char *ssid = get_param(cmd, "ssid");
10897 const char *countstr = get_param(cmd, "count");
10898 const char *channelstr = get_param(cmd, "channel");
10899 const char *group_id = get_param(cmd, "groupid");
10900 const char *client_id = get_param(cmd, "clientmac");
10901 int count, channel, freq, i;
10902 const char *fname;
10903 char frame[1024], src_mac[20], group_id_attr[25],
10904 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
10905 const char *group_ssid;
10906 const int group_ssid_prefix_len = 9;
10907 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
10908 size_t framelen = sizeof(frame);
10909 struct template_frame_tag tags[2];
10910 size_t tags_total = ARRAY_SIZE(tags);
10911 int tag_index, len, dst_len;
10912
10913 if (!countstr || !channelstr) {
10914 sigma_dut_print(dut, DUT_MSG_ERROR,
10915 "Missing argument: count, channel");
10916 return -1;
10917 }
10918 if (isprobereq && !ssid) {
10919 sigma_dut_print(dut, DUT_MSG_ERROR,
10920 "Missing argument: ssid");
10921 return -1;
10922 }
10923 if (!isprobereq && (!group_id || !client_id)) {
10924 sigma_dut_print(dut, DUT_MSG_ERROR,
10925 "Missing argument: group_id, client_id");
10926 return -1;
10927 }
10928
10929 count = atoi(countstr);
10930 channel = atoi(channelstr);
10931 freq = channel_to_freq(dut, channel);
10932
10933 if (!freq) {
10934 sigma_dut_print(dut, DUT_MSG_ERROR,
10935 "invalid channel: %s", channelstr);
10936 return -1;
10937 }
10938
10939 if (isprobereq) {
10940 if (strcasecmp(ssid, "wildcard") == 0) {
10941 fname = "probe_req_wildcard.txt";
10942 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
10943 fname = "probe_req_P2P_Wildcard.txt";
10944 } else {
10945 sigma_dut_print(dut, DUT_MSG_ERROR,
10946 "invalid probe request type");
10947 return -1;
10948 }
10949 } else {
10950 fname = "P2P_device_discovery_req.txt";
10951 }
10952
10953 if (parse_template_frame_file(dut, fname, frame, &framelen,
10954 tags, &tags_total)) {
10955 sigma_dut_print(dut, DUT_MSG_ERROR,
10956 "invalid frame template: %s", fname);
10957 return -1;
10958 }
10959
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010960 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010961 src_mac, sizeof(src_mac)) < 0 ||
10962 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
10963 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
10964 return -1;
10965 /* Use wildcard BSSID, since we are in PBSS */
10966 memset(&hdr->addr3, 0xFF, ETH_ALEN);
10967
10968 if (!isprobereq) {
10969 tag_index = find_template_frame_tag(tags, tags_total, 1);
10970 if (tag_index < 0) {
10971 sigma_dut_print(dut, DUT_MSG_ERROR,
10972 "can't find device id attribute");
10973 return -1;
10974 }
10975 if (parse_mac_address(dut, client_id,
10976 (unsigned char *) client_mac)) {
10977 sigma_dut_print(dut, DUT_MSG_ERROR,
10978 "invalid client_id: %s", client_id);
10979 return -1;
10980 }
10981 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10982 framelen - tags[tag_index].offset,
10983 IEEE80211_P2P_ATTR_DEVICE_ID,
10984 client_mac, ETH_ALEN)) {
10985 sigma_dut_print(dut, DUT_MSG_ERROR,
10986 "fail to replace device id attribute");
10987 return -1;
10988 }
10989
10990 /*
10991 * group_id arg contains device MAC address followed by
10992 * space and SSID (DIRECT-somessid).
10993 * group id attribute contains device address (6 bytes)
10994 * followed by SSID prefix DIRECT-XX (9 bytes)
10995 */
10996 if (strlen(group_id) < sizeof(device_macstr)) {
10997 sigma_dut_print(dut, DUT_MSG_ERROR,
10998 "group_id arg too short");
10999 return -1;
11000 }
11001 memcpy(device_macstr, group_id, sizeof(device_macstr));
11002 device_macstr[sizeof(device_macstr) - 1] = '\0';
11003 if (parse_mac_address(dut, device_macstr,
11004 (unsigned char *) group_id_attr)) {
11005 sigma_dut_print(dut, DUT_MSG_ERROR,
11006 "fail to parse device address from group_id");
11007 return -1;
11008 }
11009 group_ssid = strchr(group_id, ' ');
11010 if (!group_ssid) {
11011 sigma_dut_print(dut, DUT_MSG_ERROR,
11012 "invalid group_id arg, no ssid");
11013 return -1;
11014 }
11015 group_ssid++;
11016 len = strlen(group_ssid);
11017 if (len < group_ssid_prefix_len) {
11018 sigma_dut_print(dut, DUT_MSG_ERROR,
11019 "group_id SSID too short");
11020 return -1;
11021 }
11022 dst_len = sizeof(group_id_attr) - ETH_ALEN;
11023 if (len > dst_len) {
11024 sigma_dut_print(dut, DUT_MSG_ERROR,
11025 "group_id SSID (%s) too long",
11026 group_ssid);
11027 return -1;
11028 }
11029
11030 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
11031 tag_index = find_template_frame_tag(tags, tags_total, 2);
11032 if (tag_index < 0) {
11033 sigma_dut_print(dut, DUT_MSG_ERROR,
11034 "can't find group id attribute");
11035 return -1;
11036 }
11037 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11038 framelen - tags[tag_index].offset,
11039 IEEE80211_P2P_ATTR_GROUP_ID,
11040 group_id_attr,
11041 sizeof(group_id_attr))) {
11042 sigma_dut_print(dut, DUT_MSG_ERROR,
11043 "fail to replace group id attribute");
11044 return -1;
11045 }
11046 }
11047
11048 for (i = 0; i < count; i++) {
11049 if (wil6210_transmit_frame(dut, freq,
11050 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
11051 frame, framelen)) {
11052 sigma_dut_print(dut, DUT_MSG_ERROR,
11053 "fail to transmit probe request frame");
11054 return -1;
11055 }
11056 }
11057
11058 return 0;
11059}
11060
11061
Lior David0fe101e2017-03-09 16:09:50 +020011062int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
11063 struct sigma_cmd *cmd)
11064{
11065 const char *frame_name = get_param(cmd, "framename");
11066 const char *mac = get_param(cmd, "dest_mac");
11067
11068 if (!frame_name || !mac) {
11069 sigma_dut_print(dut, DUT_MSG_ERROR,
11070 "framename and dest_mac must be provided");
11071 return -1;
11072 }
11073
11074 if (strcasecmp(frame_name, "brp") == 0) {
11075 const char *l_rx = get_param(cmd, "L-RX");
11076 int l_rx_i;
11077
11078 if (!l_rx) {
11079 sigma_dut_print(dut, DUT_MSG_ERROR,
11080 "L-RX must be provided");
11081 return -1;
11082 }
11083 l_rx_i = atoi(l_rx);
11084
11085 sigma_dut_print(dut, DUT_MSG_INFO,
11086 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
11087 mac, l_rx);
11088 if (l_rx_i != 16) {
11089 sigma_dut_print(dut, DUT_MSG_ERROR,
11090 "unsupported L-RX: %s", l_rx);
11091 return -1;
11092 }
11093
11094 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
11095 return -1;
11096 } else if (strcasecmp(frame_name, "ssw") == 0) {
11097 sigma_dut_print(dut, DUT_MSG_INFO,
11098 "dev_send_frame: SLS, dest_mac %s", mac);
11099 if (wil6210_send_sls(dut, mac))
11100 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011101 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
11102 (strcasecmp(frame_name, "devdiscreq") == 0)) {
11103 sigma_dut_print(dut, DUT_MSG_INFO,
11104 "dev_send_frame: %s, dest_mac %s", frame_name,
11105 mac);
11106 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
11107 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020011108 } else {
11109 sigma_dut_print(dut, DUT_MSG_ERROR,
11110 "unsupported frame type: %s", frame_name);
11111 return -1;
11112 }
11113
11114 return 1;
11115}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011116
Lior David0fe101e2017-03-09 16:09:50 +020011117#endif /* __linux__ */
11118
11119
11120static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
11121 struct sigma_conn *conn,
11122 struct sigma_cmd *cmd)
11123{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011124 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020011125#ifdef __linux__
11126 case DRIVER_WIL6210:
11127 return wil6210_send_frame_60g(dut, conn, cmd);
11128#endif /* __linux__ */
11129 default:
11130 send_resp(dut, conn, SIGMA_ERROR,
11131 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
11132 return 0;
11133 }
11134}
11135
11136
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011137static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
11138 const char *intf, struct sigma_cmd *cmd)
11139{
11140 const char *val, *addr;
11141 char buf[100];
11142
11143 addr = get_param(cmd, "DestMac");
11144 if (!addr) {
11145 send_resp(dut, conn, SIGMA_INVALID,
11146 "ErrorCode,AP MAC address is missing");
11147 return 0;
11148 }
11149
11150 val = get_param(cmd, "ANQPQuery_ID");
11151 if (!val) {
11152 send_resp(dut, conn, SIGMA_INVALID,
11153 "ErrorCode,Missing ANQPQuery_ID");
11154 return 0;
11155 }
11156
11157 if (strcasecmp(val, "NeighborReportReq") == 0) {
11158 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
11159 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
11160 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
11161 } else {
11162 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
11163 val);
11164 send_resp(dut, conn, SIGMA_INVALID,
11165 "ErrorCode,Invalid ANQPQuery_ID");
11166 return 0;
11167 }
11168
Ashwini Patild174f2c2017-04-13 16:49:46 +053011169 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
11170 * (Address3 = Wildcard BSSID when sent to not-associated AP;
11171 * if associated, AP BSSID).
11172 */
11173 if (wpa_command(intf, "SET gas_address3 1") < 0) {
11174 send_resp(dut, conn, SIGMA_ERROR,
11175 "ErrorCode,Failed to set gas_address3");
11176 return 0;
11177 }
11178
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011179 if (wpa_command(intf, buf) < 0) {
11180 send_resp(dut, conn, SIGMA_ERROR,
11181 "ErrorCode,Failed to send ANQP query");
11182 return 0;
11183 }
11184
11185 return 1;
11186}
11187
11188
11189static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
11190 struct sigma_conn *conn,
11191 const char *intf,
11192 struct sigma_cmd *cmd)
11193{
11194 const char *val = get_param(cmd, "FrameName");
11195
11196 if (val && strcasecmp(val, "ANQPQuery") == 0)
11197 return mbo_send_anqp_query(dut, conn, intf, cmd);
11198
11199 return 2;
11200}
11201
11202
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011203static enum sigma_cmd_result cmd_sta_send_frame_wpa3(struct sigma_dut *dut,
11204 struct sigma_conn *conn,
11205 const char *intf,
11206 struct sigma_cmd *cmd)
11207{
11208 const char *val = get_param(cmd, "framename");
11209
11210 if (!val)
11211 return INVALID_SEND_STATUS;
11212
11213 if (strcasecmp(val, "SAQueryReq") == 0) {
11214 val = get_param(cmd, "OCIChannel");
11215
11216 if (!val) {
11217 send_resp(dut, conn, SIGMA_ERROR,
11218 "errorCode,OCIChannel not present");
11219 return STATUS_SENT_ERROR;
11220 }
11221
11222 dut->saquery_oci_freq = channel_to_freq(dut, atoi(val));
11223 if (!dut->saquery_oci_freq) {
11224 send_resp(dut, conn, SIGMA_ERROR,
11225 "errorCode,Invalid OCIChannel number");
11226 return STATUS_SENT_ERROR;
11227 }
11228
11229 return sta_inject_frame(dut, conn, intf, SAQUERY, CORRECT_KEY,
11230 NULL, 0);
11231 }
11232
11233 if (strcasecmp(val, "reassocreq") == 0)
11234 return sta_inject_frame(dut, conn, intf, REASSOCREQ,
11235 CORRECT_KEY, NULL, 0);
11236
11237 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported framename");
11238 return STATUS_SENT_ERROR;
11239}
11240
11241
Jouni Malinenf7222712019-06-13 01:50:21 +030011242enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
11243 struct sigma_conn *conn,
11244 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011245{
11246 const char *intf = get_param(cmd, "Interface");
11247 const char *val;
11248 enum send_frame_type frame;
11249 enum send_frame_protection protected;
11250 char buf[100];
11251 unsigned char addr[ETH_ALEN];
11252 int res;
11253
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011254 if (!intf)
11255 return -1;
11256
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011257 val = get_param(cmd, "program");
11258 if (val == NULL)
11259 val = get_param(cmd, "frame");
11260 if (val && strcasecmp(val, "TDLS") == 0)
11261 return cmd_sta_send_frame_tdls(dut, conn, cmd);
11262 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011263 strcasecmp(val, "HS2-R2") == 0 ||
11264 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011265 return cmd_sta_send_frame_hs2(dut, conn, cmd);
11266 if (val && strcasecmp(val, "VHT") == 0)
11267 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011268 if (val && strcasecmp(val, "HE") == 0)
11269 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070011270 if (val && strcasecmp(val, "LOC") == 0)
11271 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020011272 if (val && strcasecmp(val, "60GHz") == 0)
11273 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011274 if (val && strcasecmp(val, "MBO") == 0) {
11275 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
11276 if (res != 2)
11277 return res;
11278 }
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011279 if (val && strcasecmp(val, "WPA3") == 0)
11280 return cmd_sta_send_frame_wpa3(dut, conn, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011281
11282 val = get_param(cmd, "TD_DISC");
11283 if (val) {
11284 if (hwaddr_aton(val, addr) < 0)
11285 return -1;
11286 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
11287 if (wpa_command(intf, buf) < 0) {
11288 send_resp(dut, conn, SIGMA_ERROR,
11289 "ErrorCode,Failed to send TDLS discovery");
11290 return 0;
11291 }
11292 return 1;
11293 }
11294
11295 val = get_param(cmd, "TD_Setup");
11296 if (val) {
11297 if (hwaddr_aton(val, addr) < 0)
11298 return -1;
11299 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
11300 if (wpa_command(intf, buf) < 0) {
11301 send_resp(dut, conn, SIGMA_ERROR,
11302 "ErrorCode,Failed to start TDLS setup");
11303 return 0;
11304 }
11305 return 1;
11306 }
11307
11308 val = get_param(cmd, "TD_TearDown");
11309 if (val) {
11310 if (hwaddr_aton(val, addr) < 0)
11311 return -1;
11312 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
11313 if (wpa_command(intf, buf) < 0) {
11314 send_resp(dut, conn, SIGMA_ERROR,
11315 "ErrorCode,Failed to tear down TDLS link");
11316 return 0;
11317 }
11318 return 1;
11319 }
11320
11321 val = get_param(cmd, "TD_ChannelSwitch");
11322 if (val) {
11323 /* TODO */
11324 send_resp(dut, conn, SIGMA_ERROR,
11325 "ErrorCode,TD_ChannelSwitch not yet supported");
11326 return 0;
11327 }
11328
11329 val = get_param(cmd, "TD_NF");
11330 if (val) {
11331 /* TODO */
11332 send_resp(dut, conn, SIGMA_ERROR,
11333 "ErrorCode,TD_NF not yet supported");
11334 return 0;
11335 }
11336
11337 val = get_param(cmd, "PMFFrameType");
11338 if (val == NULL)
11339 val = get_param(cmd, "FrameName");
11340 if (val == NULL)
11341 val = get_param(cmd, "Type");
11342 if (val == NULL)
11343 return -1;
11344 if (strcasecmp(val, "disassoc") == 0)
11345 frame = DISASSOC;
11346 else if (strcasecmp(val, "deauth") == 0)
11347 frame = DEAUTH;
11348 else if (strcasecmp(val, "saquery") == 0)
11349 frame = SAQUERY;
11350 else if (strcasecmp(val, "auth") == 0)
11351 frame = AUTH;
11352 else if (strcasecmp(val, "assocreq") == 0)
11353 frame = ASSOCREQ;
11354 else if (strcasecmp(val, "reassocreq") == 0)
11355 frame = REASSOCREQ;
11356 else if (strcasecmp(val, "neigreq") == 0) {
11357 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
11358
11359 val = get_param(cmd, "ssid");
11360 if (val == NULL)
11361 return -1;
11362
11363 res = send_neighbor_request(dut, intf, val);
11364 if (res) {
11365 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11366 "Failed to send neighbor report request");
11367 return 0;
11368 }
11369
11370 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053011371 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
11372 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011373 sigma_dut_print(dut, DUT_MSG_DEBUG,
11374 "Got Transition Management Query");
11375
Ashwini Patil5acd7382017-04-13 15:55:04 +053011376 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011377 if (res) {
11378 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11379 "Failed to send Transition Management Query");
11380 return 0;
11381 }
11382
11383 return 1;
11384 } else {
11385 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11386 "PMFFrameType");
11387 return 0;
11388 }
11389
11390 val = get_param(cmd, "PMFProtected");
11391 if (val == NULL)
11392 val = get_param(cmd, "Protected");
11393 if (val == NULL)
11394 return -1;
11395 if (strcasecmp(val, "Correct-key") == 0 ||
11396 strcasecmp(val, "CorrectKey") == 0)
11397 protected = CORRECT_KEY;
11398 else if (strcasecmp(val, "IncorrectKey") == 0)
11399 protected = INCORRECT_KEY;
11400 else if (strcasecmp(val, "Unprotected") == 0)
11401 protected = UNPROTECTED;
11402 else {
11403 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11404 "PMFProtected");
11405 return 0;
11406 }
11407
11408 if (protected != UNPROTECTED &&
11409 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
11410 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
11411 "PMFProtected for auth/assocreq/reassocreq");
11412 return 0;
11413 }
11414
11415 if (if_nametoindex("sigmadut") == 0) {
11416 snprintf(buf, sizeof(buf),
11417 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011418 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011419 if (system(buf) != 0 ||
11420 if_nametoindex("sigmadut") == 0) {
11421 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11422 "monitor interface with '%s'", buf);
11423 return -2;
11424 }
11425 }
11426
11427 if (system("ifconfig sigmadut up") != 0) {
11428 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11429 "monitor interface up");
11430 return -2;
11431 }
11432
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011433 return sta_inject_frame(dut, conn, intf, frame, protected, NULL, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011434}
11435
11436
11437static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
11438 struct sigma_conn *conn,
11439 struct sigma_cmd *cmd,
11440 const char *ifname)
11441{
11442 char buf[200];
11443 const char *val;
11444
11445 val = get_param(cmd, "ClearARP");
11446 if (val && atoi(val) == 1) {
11447 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
11448 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11449 if (system(buf) != 0) {
11450 send_resp(dut, conn, SIGMA_ERROR,
11451 "errorCode,Failed to clear ARP cache");
11452 return 0;
11453 }
11454 }
11455
11456 return 1;
11457}
11458
11459
11460int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
11461 struct sigma_cmd *cmd)
11462{
11463 const char *intf = get_param(cmd, "Interface");
11464 const char *val;
11465
11466 if (intf == NULL)
11467 return -1;
11468
11469 val = get_param(cmd, "program");
11470 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011471 strcasecmp(val, "HS2-R2") == 0 ||
11472 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011473 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
11474
11475 return -1;
11476}
11477
11478
Jouni Malinenf7222712019-06-13 01:50:21 +030011479static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
11480 struct sigma_conn *conn,
11481 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011482{
11483 const char *intf = get_param(cmd, "Interface");
11484 const char *mac = get_param(cmd, "MAC");
11485
11486 if (intf == NULL || mac == NULL)
11487 return -1;
11488
11489 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
11490 "interface %s to %s", intf, mac);
11491
11492 if (dut->set_macaddr) {
11493 char buf[128];
11494 int res;
11495 if (strcasecmp(mac, "default") == 0) {
11496 res = snprintf(buf, sizeof(buf), "%s",
11497 dut->set_macaddr);
11498 dut->tmp_mac_addr = 0;
11499 } else {
11500 res = snprintf(buf, sizeof(buf), "%s %s",
11501 dut->set_macaddr, mac);
11502 dut->tmp_mac_addr = 1;
11503 }
11504 if (res < 0 || res >= (int) sizeof(buf))
11505 return -1;
11506 if (system(buf) != 0) {
11507 send_resp(dut, conn, SIGMA_ERROR,
11508 "errorCode,Failed to set MAC "
11509 "address");
11510 return 0;
11511 }
11512 return 1;
11513 }
11514
11515 if (strcasecmp(mac, "default") == 0)
11516 return 1;
11517
11518 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11519 "command");
11520 return 0;
11521}
11522
11523
11524static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
11525 struct sigma_conn *conn, const char *intf,
11526 int val)
11527{
11528 char buf[200];
11529 int res;
11530
11531 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
11532 intf, val);
11533 if (res < 0 || res >= (int) sizeof(buf))
11534 return -1;
11535 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11536 if (system(buf) != 0) {
11537 send_resp(dut, conn, SIGMA_ERROR,
11538 "errorCode,Failed to configure offchannel mode");
11539 return 0;
11540 }
11541
11542 return 1;
11543}
11544
11545
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011546static int off_chan_val(enum sec_ch_offset off)
11547{
11548 switch (off) {
11549 case SEC_CH_NO:
11550 return 0;
11551 case SEC_CH_40ABOVE:
11552 return 40;
11553 case SEC_CH_40BELOW:
11554 return -40;
11555 }
11556
11557 return 0;
11558}
11559
11560
11561static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
11562 const char *intf, int off_ch_num,
11563 enum sec_ch_offset sec)
11564{
11565 char buf[200];
11566 int res;
11567
11568 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
11569 intf, off_ch_num);
11570 if (res < 0 || res >= (int) sizeof(buf))
11571 return -1;
11572 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11573 if (system(buf) != 0) {
11574 send_resp(dut, conn, SIGMA_ERROR,
11575 "errorCode,Failed to set offchan");
11576 return 0;
11577 }
11578
11579 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
11580 intf, off_chan_val(sec));
11581 if (res < 0 || res >= (int) sizeof(buf))
11582 return -1;
11583 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11584 if (system(buf) != 0) {
11585 send_resp(dut, conn, SIGMA_ERROR,
11586 "errorCode,Failed to set sec chan offset");
11587 return 0;
11588 }
11589
11590 return 1;
11591}
11592
11593
11594static int tdls_set_offchannel_offset(struct sigma_dut *dut,
11595 struct sigma_conn *conn,
11596 const char *intf, int off_ch_num,
11597 enum sec_ch_offset sec)
11598{
11599 char buf[200];
11600 int res;
11601
11602 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
11603 off_ch_num);
11604 if (res < 0 || res >= (int) sizeof(buf))
11605 return -1;
11606 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11607
11608 if (wpa_command(intf, buf) < 0) {
11609 send_resp(dut, conn, SIGMA_ERROR,
11610 "ErrorCode,Failed to set offchan");
11611 return 0;
11612 }
11613 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
11614 off_chan_val(sec));
11615 if (res < 0 || res >= (int) sizeof(buf))
11616 return -1;
11617
11618 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11619
11620 if (wpa_command(intf, buf) < 0) {
11621 send_resp(dut, conn, SIGMA_ERROR,
11622 "ErrorCode,Failed to set sec chan offset");
11623 return 0;
11624 }
11625
11626 return 1;
11627}
11628
11629
11630static int tdls_set_offchannel_mode(struct sigma_dut *dut,
11631 struct sigma_conn *conn,
11632 const char *intf, int val)
11633{
11634 char buf[200];
11635 int res;
11636
11637 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
11638 val);
11639 if (res < 0 || res >= (int) sizeof(buf))
11640 return -1;
11641 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11642
11643 if (wpa_command(intf, buf) < 0) {
11644 send_resp(dut, conn, SIGMA_ERROR,
11645 "ErrorCode,Failed to configure offchannel mode");
11646 return 0;
11647 }
11648
11649 return 1;
11650}
11651
11652
11653static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
11654 struct sigma_conn *conn,
11655 struct sigma_cmd *cmd)
11656{
11657 const char *val;
11658 enum {
11659 CHSM_NOT_SET,
11660 CHSM_ENABLE,
11661 CHSM_DISABLE,
11662 CHSM_REJREQ,
11663 CHSM_UNSOLRESP
11664 } chsm = CHSM_NOT_SET;
11665 int off_ch_num = -1;
11666 enum sec_ch_offset sec_ch = SEC_CH_NO;
11667 int res;
11668
11669 val = get_param(cmd, "Uapsd");
11670 if (val) {
11671 char buf[100];
11672 if (strcasecmp(val, "Enable") == 0)
11673 snprintf(buf, sizeof(buf), "SET ps 99");
11674 else if (strcasecmp(val, "Disable") == 0)
11675 snprintf(buf, sizeof(buf), "SET ps 98");
11676 else {
11677 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11678 "Unsupported uapsd parameter value");
11679 return 0;
11680 }
11681 if (wpa_command(intf, buf)) {
11682 send_resp(dut, conn, SIGMA_ERROR,
11683 "ErrorCode,Failed to change U-APSD "
11684 "powersave mode");
11685 return 0;
11686 }
11687 }
11688
11689 val = get_param(cmd, "TPKTIMER");
11690 if (val && strcasecmp(val, "DISABLE") == 0) {
11691 if (wpa_command(intf, "SET tdls_testing 0x100")) {
11692 send_resp(dut, conn, SIGMA_ERROR,
11693 "ErrorCode,Failed to enable no TPK "
11694 "expiration test mode");
11695 return 0;
11696 }
11697 dut->no_tpk_expiration = 1;
11698 }
11699
11700 val = get_param(cmd, "ChSwitchMode");
11701 if (val) {
11702 if (strcasecmp(val, "Enable") == 0 ||
11703 strcasecmp(val, "Initiate") == 0)
11704 chsm = CHSM_ENABLE;
11705 else if (strcasecmp(val, "Disable") == 0 ||
11706 strcasecmp(val, "passive") == 0)
11707 chsm = CHSM_DISABLE;
11708 else if (strcasecmp(val, "RejReq") == 0)
11709 chsm = CHSM_REJREQ;
11710 else if (strcasecmp(val, "UnSolResp") == 0)
11711 chsm = CHSM_UNSOLRESP;
11712 else {
11713 send_resp(dut, conn, SIGMA_ERROR,
11714 "ErrorCode,Unknown ChSwitchMode value");
11715 return 0;
11716 }
11717 }
11718
11719 val = get_param(cmd, "OffChNum");
11720 if (val) {
11721 off_ch_num = atoi(val);
11722 if (off_ch_num == 0) {
11723 send_resp(dut, conn, SIGMA_ERROR,
11724 "ErrorCode,Invalid OffChNum");
11725 return 0;
11726 }
11727 }
11728
11729 val = get_param(cmd, "SecChOffset");
11730 if (val) {
11731 if (strcmp(val, "20") == 0)
11732 sec_ch = SEC_CH_NO;
11733 else if (strcasecmp(val, "40above") == 0)
11734 sec_ch = SEC_CH_40ABOVE;
11735 else if (strcasecmp(val, "40below") == 0)
11736 sec_ch = SEC_CH_40BELOW;
11737 else {
11738 send_resp(dut, conn, SIGMA_ERROR,
11739 "ErrorCode,Unknown SecChOffset value");
11740 return 0;
11741 }
11742 }
11743
11744 if (chsm == CHSM_NOT_SET) {
11745 /* no offchannel changes requested */
11746 return 1;
11747 }
11748
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011749 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
11750 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011751 send_resp(dut, conn, SIGMA_ERROR,
11752 "ErrorCode,Unknown interface");
11753 return 0;
11754 }
11755
11756 switch (chsm) {
11757 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030011758 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011759 break;
11760 case CHSM_ENABLE:
11761 if (off_ch_num < 0) {
11762 send_resp(dut, conn, SIGMA_ERROR,
11763 "ErrorCode,Missing OffChNum argument");
11764 return 0;
11765 }
11766 if (wifi_chip_type == DRIVER_WCN) {
11767 res = tdls_set_offchannel_offset(dut, conn, intf,
11768 off_ch_num, sec_ch);
11769 } else {
11770 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11771 sec_ch);
11772 }
11773 if (res != 1)
11774 return res;
11775 if (wifi_chip_type == DRIVER_WCN)
11776 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
11777 else
11778 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
11779 break;
11780 case CHSM_DISABLE:
11781 if (wifi_chip_type == DRIVER_WCN)
11782 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
11783 else
11784 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
11785 break;
11786 case CHSM_REJREQ:
11787 if (wifi_chip_type == DRIVER_WCN)
11788 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
11789 else
11790 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
11791 break;
11792 case CHSM_UNSOLRESP:
11793 if (off_ch_num < 0) {
11794 send_resp(dut, conn, SIGMA_ERROR,
11795 "ErrorCode,Missing OffChNum argument");
11796 return 0;
11797 }
11798 if (wifi_chip_type == DRIVER_WCN) {
11799 res = tdls_set_offchannel_offset(dut, conn, intf,
11800 off_ch_num, sec_ch);
11801 } else {
11802 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11803 sec_ch);
11804 }
11805 if (res != 1)
11806 return res;
11807 if (wifi_chip_type == DRIVER_WCN)
11808 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
11809 else
11810 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
11811 break;
11812 }
11813
11814 return res;
11815}
11816
11817
11818static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11819 struct sigma_conn *conn,
11820 struct sigma_cmd *cmd)
11821{
11822 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011823 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011824
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011825 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080011826
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011827 val = get_param(cmd, "nss_mcs_opt");
11828 if (val) {
11829 /* String (nss_operating_mode; mcs_operating_mode) */
11830 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011831 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011832
11833 token = strdup(val);
11834 if (!token)
11835 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011836 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011837 if (!result) {
11838 sigma_dut_print(dut, DUT_MSG_ERROR,
11839 "VHT NSS not specified");
11840 goto failed;
11841 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011842 if (strcasecmp(result, "def") != 0) {
11843 nss = atoi(result);
11844 if (nss == 4)
11845 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011846 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011847 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011848
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011849 }
11850
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011851 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011852 if (!result) {
11853 sigma_dut_print(dut, DUT_MSG_ERROR,
11854 "VHT MCS not specified");
11855 goto failed;
11856 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011857 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011858 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011859 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011860 } else {
11861 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011862 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011863 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011864 }
11865 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011866 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011867 }
11868
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011869 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011870 return 1;
11871failed:
11872 free(token);
11873 return 0;
11874}
11875
11876
11877static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11878 struct sigma_conn *conn,
11879 struct sigma_cmd *cmd)
11880{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011881 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011882 case DRIVER_ATHEROS:
11883 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
11884 default:
11885 send_resp(dut, conn, SIGMA_ERROR,
11886 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
11887 return 0;
11888 }
11889}
11890
11891
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011892static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11893 struct sigma_conn *conn,
11894 struct sigma_cmd *cmd)
11895{
11896 const char *val;
11897 char *token = NULL, *result;
11898 char buf[60];
11899
11900 val = get_param(cmd, "nss_mcs_opt");
11901 if (val) {
11902 /* String (nss_operating_mode; mcs_operating_mode) */
11903 int nss, mcs, ratecode;
11904 char *saveptr;
11905
11906 token = strdup(val);
11907 if (!token)
11908 return -2;
11909
11910 result = strtok_r(token, ";", &saveptr);
11911 if (!result) {
11912 sigma_dut_print(dut, DUT_MSG_ERROR,
11913 "HE NSS not specified");
11914 goto failed;
11915 }
11916 nss = 1;
11917 if (strcasecmp(result, "def") != 0)
11918 nss = atoi(result);
11919
11920 result = strtok_r(NULL, ";", &saveptr);
11921 if (!result) {
11922 sigma_dut_print(dut, DUT_MSG_ERROR,
11923 "HE MCS not specified");
11924 goto failed;
11925 }
11926 mcs = 7;
11927 if (strcasecmp(result, "def") != 0)
11928 mcs = atoi(result);
11929
Arif Hussain557bf412018-05-25 17:29:36 -070011930 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011931 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070011932 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011933 } else if (nss > 2) {
11934 sigma_dut_print(dut, DUT_MSG_ERROR,
11935 "HE NSS %d not supported", nss);
11936 goto failed;
11937 }
11938
Arif Hussain557bf412018-05-25 17:29:36 -070011939 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
11940 if (system(buf) != 0) {
11941 sigma_dut_print(dut, DUT_MSG_ERROR,
11942 "nss_mcs_opt: iwpriv %s nss %d failed",
11943 intf, nss);
11944 goto failed;
11945 }
Arif Hussainac6c5112018-05-25 17:34:00 -070011946 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070011947
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011948 /* Add the MCS to the ratecode */
11949 if (mcs >= 0 && mcs <= 11) {
11950 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070011951#ifdef NL80211_SUPPORT
11952 if (dut->device_type == STA_testbed) {
11953 enum he_mcs_config mcs_config;
11954 int ret;
11955
11956 if (mcs <= 7)
11957 mcs_config = HE_80_MCS0_7;
11958 else if (mcs <= 9)
11959 mcs_config = HE_80_MCS0_9;
11960 else
11961 mcs_config = HE_80_MCS0_11;
11962 ret = sta_set_he_mcs(dut, intf, mcs_config);
11963 if (ret) {
11964 sigma_dut_print(dut, DUT_MSG_ERROR,
11965 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
11966 mcs, mcs_config, ret);
11967 goto failed;
11968 }
11969 }
11970#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011971 } else {
11972 sigma_dut_print(dut, DUT_MSG_ERROR,
11973 "HE MCS %d not supported", mcs);
11974 goto failed;
11975 }
11976 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
11977 intf, ratecode);
11978 if (system(buf) != 0) {
11979 sigma_dut_print(dut, DUT_MSG_ERROR,
11980 "iwpriv setting of 11ax rates failed");
11981 goto failed;
11982 }
11983 free(token);
11984 }
11985
11986 val = get_param(cmd, "GI");
11987 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011988 int fix_rate_sgi;
11989
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011990 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011991 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011992 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011993 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011994 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
11995 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011996 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011997 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011998 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
11999 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012000 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012001 } else {
12002 send_resp(dut, conn, SIGMA_ERROR,
12003 "errorCode,GI value not supported");
12004 return 0;
12005 }
12006 if (system(buf) != 0) {
12007 send_resp(dut, conn, SIGMA_ERROR,
12008 "errorCode,Failed to set shortgi");
12009 return 0;
12010 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012011 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
12012 intf, fix_rate_sgi);
12013 if (system(buf) != 0) {
12014 send_resp(dut, conn, SIGMA_ERROR,
12015 "errorCode,Failed to set fix rate shortgi");
12016 return STATUS_SENT;
12017 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012018 }
12019
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012020 val = get_param(cmd, "LTF");
12021 if (val) {
12022#ifdef NL80211_SUPPORT
12023 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012024 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012025 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012026 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012027 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012028 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012029 } else {
12030 send_resp(dut, conn, SIGMA_ERROR,
12031 "errorCode, LTF value not supported");
12032 return 0;
12033 }
12034#else /* NL80211_SUPPORT */
12035 sigma_dut_print(dut, DUT_MSG_ERROR,
12036 "LTF cannot be set without NL80211_SUPPORT defined");
12037 return -2;
12038#endif /* NL80211_SUPPORT */
12039 }
12040
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070012041 val = get_param(cmd, "TxSUPPDU");
12042 if (val) {
12043 int set_val = 1;
12044
12045 if (strcasecmp(val, "Enable") == 0)
12046 set_val = 1;
12047 else if (strcasecmp(val, "Disable") == 0)
12048 set_val = 0;
12049
12050 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
12051 send_resp(dut, conn, SIGMA_ERROR,
12052 "ErrorCode,Failed to set Tx SU PPDU config");
12053 return 0;
12054 }
12055 }
12056
Arif Hussain480d5f42019-03-12 14:40:42 -070012057 val = get_param(cmd, "TWT_Setup");
12058 if (val) {
12059 if (strcasecmp(val, "Request") == 0) {
12060 if (sta_twt_request(dut, conn, cmd)) {
12061 send_resp(dut, conn, SIGMA_ERROR,
12062 "ErrorCode,sta_twt_request failed");
12063 return STATUS_SENT;
12064 }
12065 } else if (strcasecmp(val, "Teardown") == 0) {
12066 if (sta_twt_teardown(dut, conn, cmd)) {
12067 send_resp(dut, conn, SIGMA_ERROR,
12068 "ErrorCode,sta_twt_teardown failed");
12069 return STATUS_SENT;
12070 }
12071 }
12072 }
12073
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080012074 val = get_param(cmd, "transmitOMI");
12075 if (val && sta_transmit_omi(dut, conn, cmd)) {
12076 send_resp(dut, conn, SIGMA_ERROR,
12077 "ErrorCode,sta_transmit_omi failed");
12078 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070012079 }
12080
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012081 val = get_param(cmd, "Powersave");
12082 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012083 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012084
12085 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012086 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012087 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012088 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012089 } else {
12090 sigma_dut_print(dut, DUT_MSG_ERROR,
12091 "Unsupported Powersave value '%s'",
12092 val);
12093 return -1;
12094 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012095 if (set_power_save_wcn(dut, intf, ps) < 0)
12096 return 0;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012097 }
12098
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080012099 val = get_param(cmd, "MU_EDCA");
12100 if (val) {
12101 if (strcasecmp(val, "Override") == 0) {
12102 if (sta_set_mu_edca_override(dut, intf, 1)) {
12103 send_resp(dut, conn, SIGMA_ERROR,
12104 "errorCode,MU EDCA override set failed");
12105 return STATUS_SENT;
12106 }
12107 } else if (strcasecmp(val, "Disable") == 0) {
12108 if (sta_set_mu_edca_override(dut, intf, 0)) {
12109 send_resp(dut, conn, SIGMA_ERROR,
12110 "errorCode,MU EDCA override disable failed");
12111 return STATUS_SENT;
12112 }
12113 }
12114 }
12115
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012116 return 1;
12117
12118failed:
12119 free(token);
12120 return -2;
12121}
12122
12123
12124static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12125 struct sigma_conn *conn,
12126 struct sigma_cmd *cmd)
12127{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012128 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012129 case DRIVER_WCN:
12130 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
12131 default:
12132 send_resp(dut, conn, SIGMA_ERROR,
12133 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
12134 return 0;
12135 }
12136}
12137
12138
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012139static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
12140 struct sigma_conn *conn,
12141 struct sigma_cmd *cmd)
12142{
12143 const char *val;
12144
12145 val = get_param(cmd, "powersave");
12146 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012147 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012148
12149 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012150 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012151 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012152 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012153 } else {
12154 sigma_dut_print(dut, DUT_MSG_ERROR,
12155 "Unsupported power save config");
12156 return -1;
12157 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012158 if (set_power_save_wcn(dut, intf, ps) < 0)
12159 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012160 return 1;
12161 }
12162
12163 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
12164
12165 return 0;
12166}
12167
12168
Ashwini Patil5acd7382017-04-13 15:55:04 +053012169static int btm_query_candidate_list(struct sigma_dut *dut,
12170 struct sigma_conn *conn,
12171 struct sigma_cmd *cmd)
12172{
12173 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
12174 int len, ret;
12175 char buf[10];
12176
12177 /*
12178 * Neighbor Report elements format:
12179 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
12180 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
12181 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
12182 */
12183
12184 bssid = get_param(cmd, "Nebor_BSSID");
12185 if (!bssid) {
12186 send_resp(dut, conn, SIGMA_INVALID,
12187 "errorCode,Nebor_BSSID is missing");
12188 return 0;
12189 }
12190
12191 info = get_param(cmd, "Nebor_Bssid_Info");
12192 if (!info) {
12193 sigma_dut_print(dut, DUT_MSG_INFO,
12194 "Using default value for Nebor_Bssid_Info: %s",
12195 DEFAULT_NEIGHBOR_BSSID_INFO);
12196 info = DEFAULT_NEIGHBOR_BSSID_INFO;
12197 }
12198
12199 op_class = get_param(cmd, "Nebor_Op_Class");
12200 if (!op_class) {
12201 send_resp(dut, conn, SIGMA_INVALID,
12202 "errorCode,Nebor_Op_Class is missing");
12203 return 0;
12204 }
12205
12206 ch = get_param(cmd, "Nebor_Op_Ch");
12207 if (!ch) {
12208 send_resp(dut, conn, SIGMA_INVALID,
12209 "errorCode,Nebor_Op_Ch is missing");
12210 return 0;
12211 }
12212
12213 phy_type = get_param(cmd, "Nebor_Phy_Type");
12214 if (!phy_type) {
12215 sigma_dut_print(dut, DUT_MSG_INFO,
12216 "Using default value for Nebor_Phy_Type: %s",
12217 DEFAULT_NEIGHBOR_PHY_TYPE);
12218 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
12219 }
12220
12221 /* Parse optional subelements */
12222 buf[0] = '\0';
12223 pref = get_param(cmd, "Nebor_Pref");
12224 if (pref) {
12225 /* hexdump for preferrence subelement */
12226 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
12227 if (ret < 0 || ret >= (int) sizeof(buf)) {
12228 sigma_dut_print(dut, DUT_MSG_ERROR,
12229 "snprintf failed for optional subelement ret: %d",
12230 ret);
12231 send_resp(dut, conn, SIGMA_ERROR,
12232 "errorCode,snprintf failed for subelement");
12233 return 0;
12234 }
12235 }
12236
12237 if (!dut->btm_query_cand_list) {
12238 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
12239 if (!dut->btm_query_cand_list) {
12240 send_resp(dut, conn, SIGMA_ERROR,
12241 "errorCode,Failed to allocate memory for btm_query_cand_list");
12242 return 0;
12243 }
12244 }
12245
12246 len = strlen(dut->btm_query_cand_list);
12247 ret = snprintf(dut->btm_query_cand_list + len,
12248 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
12249 bssid, info, op_class, ch, phy_type, buf);
12250 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
12251 sigma_dut_print(dut, DUT_MSG_ERROR,
12252 "snprintf failed for neighbor report list ret: %d",
12253 ret);
12254 send_resp(dut, conn, SIGMA_ERROR,
12255 "errorCode,snprintf failed for neighbor report");
12256 free(dut->btm_query_cand_list);
12257 dut->btm_query_cand_list = NULL;
12258 return 0;
12259 }
12260
12261 return 1;
12262}
12263
12264
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012265int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
12266 struct sigma_ese_alloc *allocs, int *allocs_size)
12267{
12268 int max_count = *allocs_size;
12269 int count = 0, i;
12270 const char *val;
12271
12272 do {
12273 val = get_param_indexed(cmd, "AllocID", count);
12274 if (val)
12275 count++;
12276 } while (val);
12277
12278 if (count == 0 || count > max_count) {
12279 sigma_dut_print(dut, DUT_MSG_ERROR,
12280 "Invalid number of allocations(%d)", count);
12281 return -1;
12282 }
12283
12284 for (i = 0; i < count; i++) {
12285 val = get_param_indexed(cmd, "PercentBI", i);
12286 if (!val) {
12287 sigma_dut_print(dut, DUT_MSG_ERROR,
12288 "Missing PercentBI parameter at index %d",
12289 i);
12290 return -1;
12291 }
12292 allocs[i].percent_bi = atoi(val);
12293
12294 val = get_param_indexed(cmd, "SrcAID", i);
12295 if (val)
12296 allocs[i].src_aid = strtol(val, NULL, 0);
12297 else
12298 allocs[i].src_aid = ESE_BCAST_AID;
12299
12300 val = get_param_indexed(cmd, "DestAID", i);
12301 if (val)
12302 allocs[i].dst_aid = strtol(val, NULL, 0);
12303 else
12304 allocs[i].dst_aid = ESE_BCAST_AID;
12305
12306 allocs[i].type = ESE_CBAP;
12307 sigma_dut_print(dut, DUT_MSG_INFO,
12308 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
12309 i, allocs[i].percent_bi, allocs[i].src_aid,
12310 allocs[i].dst_aid);
12311 }
12312
12313 *allocs_size = count;
12314 return 0;
12315}
12316
12317
12318static int sta_set_60g_ese(struct sigma_dut *dut, int count,
12319 struct sigma_ese_alloc *allocs)
12320{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012321 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012322#ifdef __linux__
12323 case DRIVER_WIL6210:
12324 if (wil6210_set_ese(dut, count, allocs))
12325 return -1;
12326 return 1;
12327#endif /* __linux__ */
12328 default:
12329 sigma_dut_print(dut, DUT_MSG_ERROR,
12330 "Unsupported sta_set_60g_ese with the current driver");
12331 return -1;
12332 }
12333}
12334
12335
12336static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
12337 struct sigma_conn *conn,
12338 struct sigma_cmd *cmd)
12339{
12340 const char *val;
12341
12342 val = get_param(cmd, "ExtSchIE");
12343 if (val && !strcasecmp(val, "Enable")) {
12344 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
12345 int count = MAX_ESE_ALLOCS;
12346
12347 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
12348 return -1;
12349 return sta_set_60g_ese(dut, count, allocs);
12350 }
12351
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012352 val = get_param(cmd, "MCS_FixedRate");
12353 if (val) {
12354 int sta_mcs = atoi(val);
12355
12356 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
12357 sta_mcs);
12358 wil6210_set_force_mcs(dut, 1, sta_mcs);
12359
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012360 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012361 }
12362
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012363 send_resp(dut, conn, SIGMA_ERROR,
12364 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012365 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012366}
12367
12368
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012369static int wcn_sta_override_oci(struct sigma_dut *dut, const char *intf,
12370 const char *oci_frametype, uint32_t oci_freq)
12371{
12372#ifdef NL80211_SUPPORT
12373 struct nl_msg *msg;
12374 int ret = 0;
12375 struct nlattr *params;
12376 struct nlattr *attr;
12377 int ifindex;
12378 u8 frame_type;
12379
12380 ifindex = if_nametoindex(intf);
12381 if (ifindex == 0) {
12382 sigma_dut_print(dut, DUT_MSG_ERROR,
12383 "%s: Index for interface %s failed",
12384 __func__, intf);
12385 return -1;
12386 }
12387
12388 if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12389 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_REQ;
12390 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12391 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_RESP;
12392 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
12393 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_FT_REASSOC_REQ;
12394 } else {
12395 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: Unknown frametype %s",
12396 __func__, oci_frametype);
12397 return -1;
12398 }
12399
12400
12401 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
12402 NL80211_CMD_VENDOR)) ||
12403 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
12404 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
12405 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
12406 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
12407 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
12408 !(params = nla_nest_start(
12409 msg,
12410 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OCI_OVERRIDE)) ||
12411 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FRAME_TYPE,
12412 frame_type) ||
12413 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FREQUENCY,
12414 oci_freq)) {
12415 sigma_dut_print(dut, DUT_MSG_ERROR,
12416 "%s: err in adding vendor_cmd and vendor_data",
12417 __func__);
12418 nlmsg_free(msg);
12419 return -1;
12420 }
12421 nla_nest_end(msg, params);
12422 nla_nest_end(msg, attr);
12423
12424 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
12425 if (ret) {
12426 sigma_dut_print(dut, DUT_MSG_ERROR,
12427 "%s: err in send_and_recv_msgs, ret=%d",
12428 __func__, ret);
12429 }
12430 return ret;
12431#else /* NL80211_SUPPORT */
12432 sigma_dut_print(dut, DUT_MSG_ERROR,
12433 "OCI override not possible without NL80211_SUPPORT defined");
12434 return -1;
12435#endif /* NL80211_SUPPORT */
12436}
12437
12438
Jouni Malinen6250cb02020-04-15 13:54:45 +030012439static enum sigma_cmd_result
12440cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
12441 struct sigma_conn *conn,
12442 struct sigma_cmd *cmd)
12443{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012444 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030012445
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053012446 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030012447 if (val && atoi(val) == 1) {
12448 if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
12449 send_resp(dut, conn, SIGMA_ERROR,
12450 "errorCode,Failed to set ft_rsnxe_used");
12451 return STATUS_SENT_ERROR;
12452 }
12453 return SUCCESS_SEND_STATUS;
12454 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012455
12456 oci_chan = get_param(cmd, "OCIChannel");
12457 oci_frametype = get_param(cmd, "OCIFrameType");
12458 if (oci_chan && oci_frametype) {
12459 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
12460 char buf[100];
12461
12462 if (!oci_freq) {
12463 send_resp(dut, conn, SIGMA_ERROR,
12464 "errorCode,Invalid OCIChannel number");
12465 return STATUS_SENT_ERROR;
12466 }
12467
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012468 if (wifi_chip_type == DRIVER_WCN &&
12469 (strcasecmp(oci_frametype, "SAQueryReq") == 0 ||
12470 strcasecmp(oci_frametype, "SAQueryResp") == 0 ||
12471 strcasecmp(oci_frametype, "Reassocreq") == 0)) {
12472 if (wcn_sta_override_oci(dut, intf, oci_frametype,
12473 oci_freq)) {
12474 send_resp(dut, conn, SIGMA_ERROR,
12475 "errorCode,Failed to override OCI");
12476 return STATUS_SENT_ERROR;
12477 }
12478 return SUCCESS_SEND_STATUS;
12479 }
12480
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012481 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
12482 snprintf(buf, sizeof(buf),
12483 "SET oci_freq_override_eapol %d", oci_freq);
12484 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12485 snprintf(buf, sizeof(buf),
12486 "SET oci_freq_override_saquery_req %d",
12487 oci_freq);
12488 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12489 snprintf(buf, sizeof(buf),
12490 "SET oci_freq_override_saquery_resp %d",
12491 oci_freq);
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012492 } else if (strcasecmp(oci_frametype, "GrpKeyM2") == 0) {
12493 snprintf(buf, sizeof(buf),
12494 "SET oci_freq_override_eapol_g2 %d",
12495 oci_freq);
12496 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
12497 snprintf(buf, sizeof(buf),
12498 "SET oci_freq_override_ft_assoc %d",
12499 oci_freq);
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012500 } else {
12501 send_resp(dut, conn, SIGMA_ERROR,
12502 "errorCode,Unsupported OCIFrameType");
12503 return STATUS_SENT_ERROR;
12504 }
12505 if (wpa_command(intf, buf) < 0) {
12506 send_resp(dut, conn, SIGMA_ERROR,
12507 "errorCode,Failed to set oci_freq_override");
12508 return STATUS_SENT_ERROR;
12509 }
12510 return SUCCESS_SEND_STATUS;
12511 }
12512
Jouni Malinen6250cb02020-04-15 13:54:45 +030012513 send_resp(dut, conn, SIGMA_ERROR,
12514 "errorCode,Unsupported WPA3 rfeature");
12515 return STATUS_SENT_ERROR;
12516}
12517
12518
Jouni Malinenf7222712019-06-13 01:50:21 +030012519static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
12520 struct sigma_conn *conn,
12521 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012522{
12523 const char *intf = get_param(cmd, "Interface");
12524 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012525 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012526
12527 if (intf == NULL || prog == NULL)
12528 return -1;
12529
Ashwini Patil5acd7382017-04-13 15:55:04 +053012530 /* BSS Transition candidate list for BTM query */
12531 val = get_param(cmd, "Nebor_BSSID");
12532 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
12533 return 0;
12534
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012535 if (strcasecmp(prog, "TDLS") == 0)
12536 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
12537
12538 if (strcasecmp(prog, "VHT") == 0)
12539 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
12540
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012541 if (strcasecmp(prog, "HE") == 0)
12542 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
12543
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012544 if (strcasecmp(prog, "MBO") == 0) {
12545 val = get_param(cmd, "Cellular_Data_Cap");
12546 if (val &&
12547 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12548 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053012549
12550 val = get_param(cmd, "Ch_Pref");
12551 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12552 return 0;
12553
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012554 return 1;
12555 }
12556
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012557 if (strcasecmp(prog, "60GHz") == 0)
12558 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
12559
Jouni Malinen6250cb02020-04-15 13:54:45 +030012560 if (strcasecmp(prog, "WPA3") == 0)
12561 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
12562
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012563 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
12564 return 0;
12565}
12566
12567
Jouni Malinenf7222712019-06-13 01:50:21 +030012568static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
12569 struct sigma_conn *conn,
12570 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012571{
12572 const char *intf = get_param(cmd, "Interface");
12573 const char *mode = get_param(cmd, "Mode");
12574 int res;
12575
12576 if (intf == NULL || mode == NULL)
12577 return -1;
12578
12579 if (strcasecmp(mode, "On") == 0)
12580 res = wpa_command(intf, "SET radio_disabled 0");
12581 else if (strcasecmp(mode, "Off") == 0)
12582 res = wpa_command(intf, "SET radio_disabled 1");
12583 else
12584 return -1;
12585
12586 if (res) {
12587 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12588 "radio mode");
12589 return 0;
12590 }
12591
12592 return 1;
12593}
12594
12595
Jouni Malinenf7222712019-06-13 01:50:21 +030012596static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
12597 struct sigma_conn *conn,
12598 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012599{
12600 const char *intf = get_param(cmd, "Interface");
12601 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012602 const char *prog = get_param(cmd, "program");
12603 const char *powersave = get_param(cmd, "powersave");
12604 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012605
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012606 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012607 return -1;
12608
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012609 if (prog && strcasecmp(prog, "60GHz") == 0) {
12610 /*
12611 * The CAPI mode parameter does not exist in 60G
12612 * unscheduled PS.
12613 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080012614 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012615 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012616 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020012617 strcasecmp(prog, "HE") == 0) {
12618 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012619 } else {
12620 if (mode == NULL)
12621 return -1;
12622
12623 if (strcasecmp(mode, "On") == 0)
12624 res = set_ps(intf, dut, 1);
12625 else if (strcasecmp(mode, "Off") == 0)
12626 res = set_ps(intf, dut, 0);
12627 else
12628 return -1;
12629 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012630
12631 if (res) {
12632 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12633 "power save mode");
12634 return 0;
12635 }
12636
12637 return 1;
12638}
12639
12640
Jouni Malinenf7222712019-06-13 01:50:21 +030012641static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
12642 struct sigma_conn *conn,
12643 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012644{
12645 const char *intf = get_param(cmd, "Interface");
12646 const char *val, *bssid;
12647 int res;
12648 char *buf;
12649 size_t buf_len;
12650
12651 val = get_param(cmd, "BSSID_FILTER");
12652 if (val == NULL)
12653 return -1;
12654
12655 bssid = get_param(cmd, "BSSID_List");
12656 if (atoi(val) == 0 || bssid == NULL) {
12657 /* Disable BSSID filter */
12658 if (wpa_command(intf, "SET bssid_filter ")) {
12659 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
12660 "to disable BSSID filter");
12661 return 0;
12662 }
12663
12664 return 1;
12665 }
12666
12667 buf_len = 100 + strlen(bssid);
12668 buf = malloc(buf_len);
12669 if (buf == NULL)
12670 return -1;
12671
12672 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
12673 res = wpa_command(intf, buf);
12674 free(buf);
12675 if (res) {
12676 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
12677 "BSSID filter");
12678 return 0;
12679 }
12680
12681 return 1;
12682}
12683
12684
Jouni Malinenf7222712019-06-13 01:50:21 +030012685static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
12686 struct sigma_conn *conn,
12687 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012688{
12689 const char *intf = get_param(cmd, "Interface");
12690 const char *val;
12691
12692 /* TODO: ARP */
12693
12694 val = get_param(cmd, "HS2_CACHE_PROFILE");
12695 if (val && strcasecmp(val, "All") == 0)
12696 hs2_clear_credentials(intf);
12697
12698 return 1;
12699}
12700
12701
Jouni Malinenf7222712019-06-13 01:50:21 +030012702static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
12703 struct sigma_conn *conn,
12704 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012705{
12706 const char *intf = get_param(cmd, "Interface");
12707 const char *key_type = get_param(cmd, "KeyType");
12708 char buf[100], resp[200];
12709
12710 if (key_type == NULL)
12711 return -1;
12712
12713 if (strcasecmp(key_type, "GTK") == 0) {
12714 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
12715 strncmp(buf, "FAIL", 4) == 0) {
12716 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12717 "not fetch current GTK");
12718 return 0;
12719 }
12720 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
12721 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12722 return 0;
12723 } else {
12724 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12725 "KeyType");
12726 return 0;
12727 }
12728
12729 return 1;
12730}
12731
12732
12733static int hs2_set_policy(struct sigma_dut *dut)
12734{
12735#ifdef ANDROID
12736 system("ip rule del prio 23000");
12737 if (system("ip rule add from all lookup main prio 23000") != 0) {
12738 sigma_dut_print(dut, DUT_MSG_ERROR,
12739 "Failed to run:ip rule add from all lookup main prio");
12740 return -1;
12741 }
12742 if (system("ip route flush cache") != 0) {
12743 sigma_dut_print(dut, DUT_MSG_ERROR,
12744 "Failed to run ip route flush cache");
12745 return -1;
12746 }
12747 return 1;
12748#else /* ANDROID */
12749 return 0;
12750#endif /* ANDROID */
12751}
12752
12753
Jouni Malinenf7222712019-06-13 01:50:21 +030012754static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
12755 struct sigma_conn *conn,
12756 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012757{
12758 const char *intf = get_param(cmd, "Interface");
12759 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030012760 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012761 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030012762 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012763 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
12764 int tries = 0;
12765 int ignore_blacklist = 0;
12766 const char *events[] = {
12767 "CTRL-EVENT-CONNECTED",
12768 "INTERWORKING-BLACKLISTED",
12769 "INTERWORKING-NO-MATCH",
12770 NULL
12771 };
12772
12773 start_sta_mode(dut);
12774
Jouni Malinen439352d2018-09-13 03:42:23 +030012775 if (band) {
12776 if (strcmp(band, "2.4") == 0) {
12777 wpa_command(intf, "SET setband 2G");
12778 } else if (strcmp(band, "5") == 0) {
12779 wpa_command(intf, "SET setband 5G");
12780 } else {
12781 send_resp(dut, conn, SIGMA_ERROR,
12782 "errorCode,Unsupported band");
12783 return 0;
12784 }
12785 }
12786
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012787 blacklisted[0] = '\0';
12788 if (val && atoi(val))
12789 ignore_blacklist = 1;
12790
12791try_again:
12792 ctrl = open_wpa_mon(intf);
12793 if (ctrl == NULL) {
12794 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12795 "wpa_supplicant monitor connection");
12796 return -2;
12797 }
12798
12799 tries++;
12800 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
12801 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
12802 "Interworking connection");
12803 wpa_ctrl_detach(ctrl);
12804 wpa_ctrl_close(ctrl);
12805 return 0;
12806 }
12807
12808 buf[0] = '\0';
12809 while (1) {
12810 char *pos;
12811 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
12812 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
12813 if (!pos)
12814 break;
12815 pos += 25;
12816 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
12817 pos);
12818 if (!blacklisted[0])
12819 memcpy(blacklisted, pos, strlen(pos) + 1);
12820 }
12821
12822 if (ignore_blacklist && blacklisted[0]) {
12823 char *end;
12824 end = strchr(blacklisted, ' ');
12825 if (end)
12826 *end = '\0';
12827 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
12828 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030012829 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
12830 blacklisted);
12831 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012832 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
12833 wpa_ctrl_detach(ctrl);
12834 wpa_ctrl_close(ctrl);
12835 return 0;
12836 }
12837 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
12838 buf, sizeof(buf));
12839 }
12840
12841 wpa_ctrl_detach(ctrl);
12842 wpa_ctrl_close(ctrl);
12843
12844 if (res < 0) {
12845 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12846 "connect");
12847 return 0;
12848 }
12849
12850 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
12851 strstr(buf, "INTERWORKING-BLACKLISTED")) {
12852 if (tries < 2) {
12853 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
12854 goto try_again;
12855 }
12856 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
12857 "matching credentials found");
12858 return 0;
12859 }
12860
12861 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12862 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12863 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12864 "get current BSSID/SSID");
12865 return 0;
12866 }
12867
12868 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
12869 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12870 hs2_set_policy(dut);
12871 return 0;
12872}
12873
12874
Jouni Malinenf7222712019-06-13 01:50:21 +030012875static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
12876 struct sigma_conn *conn,
12877 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030012878{
12879 const char *intf = get_param(cmd, "Interface");
12880 const char *display = get_param(cmd, "Display");
12881 struct wpa_ctrl *ctrl;
12882 char buf[300], params[400], *pos;
12883 char bssid[20];
12884 int info_avail = 0;
12885 unsigned int old_timeout;
12886 int res;
12887
12888 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
12889 send_resp(dut, conn, SIGMA_ERROR,
12890 "ErrorCode,Could not get current BSSID");
12891 return 0;
12892 }
12893 ctrl = open_wpa_mon(intf);
12894 if (!ctrl) {
12895 sigma_dut_print(dut, DUT_MSG_ERROR,
12896 "Failed to open wpa_supplicant monitor connection");
12897 return -2;
12898 }
12899
12900 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
12901 wpa_command(intf, buf);
12902
12903 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
12904 if (res < 0) {
12905 send_resp(dut, conn, SIGMA_ERROR,
12906 "ErrorCode,Could not complete GAS query");
12907 goto fail;
12908 }
12909
12910 old_timeout = dut->default_timeout;
12911 dut->default_timeout = 2;
12912 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
12913 dut->default_timeout = old_timeout;
12914 if (res < 0)
12915 goto done;
12916 pos = strchr(buf, ' ');
12917 if (!pos)
12918 goto done;
12919 pos++;
12920 pos = strchr(pos, ' ');
12921 if (!pos)
12922 goto done;
12923 pos++;
12924 info_avail = 1;
12925 snprintf(params, sizeof(params), "browser %s", pos);
12926
12927 if (display && strcasecmp(display, "Yes") == 0) {
12928 pid_t pid;
12929
12930 pid = fork();
12931 if (pid < 0) {
12932 perror("fork");
12933 return -1;
12934 }
12935
12936 if (pid == 0) {
12937 run_hs20_osu(dut, params);
12938 exit(0);
12939 }
12940 }
12941
12942done:
12943 snprintf(buf, sizeof(buf), "Info_available,%s",
12944 info_avail ? "Yes" : "No");
12945 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12946fail:
12947 wpa_ctrl_detach(ctrl);
12948 wpa_ctrl_close(ctrl);
12949 return 0;
12950}
12951
12952
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012953static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
12954 struct sigma_conn *conn,
12955 const char *ifname,
12956 struct sigma_cmd *cmd)
12957{
12958 const char *val;
12959 int id;
12960
12961 id = add_cred(ifname);
12962 if (id < 0)
12963 return -2;
12964 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12965
12966 val = get_param(cmd, "prefer");
12967 if (val && atoi(val) > 0)
12968 set_cred(ifname, id, "priority", "1");
12969
12970 val = get_param(cmd, "REALM");
12971 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12972 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12973 "realm");
12974 return 0;
12975 }
12976
12977 val = get_param(cmd, "HOME_FQDN");
12978 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12979 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12980 "home_fqdn");
12981 return 0;
12982 }
12983
12984 val = get_param(cmd, "Username");
12985 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12986 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12987 "username");
12988 return 0;
12989 }
12990
12991 val = get_param(cmd, "Password");
12992 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
12993 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12994 "password");
12995 return 0;
12996 }
12997
12998 val = get_param(cmd, "ROOT_CA");
12999 if (val) {
13000 char fname[200];
13001 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13002#ifdef __linux__
13003 if (!file_exists(fname)) {
13004 char msg[300];
13005 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13006 "file (%s) not found", fname);
13007 send_resp(dut, conn, SIGMA_ERROR, msg);
13008 return 0;
13009 }
13010#endif /* __linux__ */
13011 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13012 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13013 "not set root CA");
13014 return 0;
13015 }
13016 }
13017
13018 return 1;
13019}
13020
13021
13022static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
13023{
13024 FILE *in, *out;
13025 char buf[500];
13026 int found = 0;
13027
13028 in = fopen("devdetail.xml", "r");
13029 if (in == NULL)
13030 return -1;
13031 out = fopen("devdetail.xml.tmp", "w");
13032 if (out == NULL) {
13033 fclose(in);
13034 return -1;
13035 }
13036
13037 while (fgets(buf, sizeof(buf), in)) {
13038 char *pos = strstr(buf, "<IMSI>");
13039 if (pos) {
13040 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
13041 imsi);
13042 pos += 6;
13043 *pos = '\0';
13044 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
13045 found++;
13046 } else {
13047 fprintf(out, "%s", buf);
13048 }
13049 }
13050
13051 fclose(out);
13052 fclose(in);
13053 if (found)
13054 rename("devdetail.xml.tmp", "devdetail.xml");
13055 else
13056 unlink("devdetail.xml.tmp");
13057
13058 return 0;
13059}
13060
13061
13062static int sta_add_credential_sim(struct sigma_dut *dut,
13063 struct sigma_conn *conn,
13064 const char *ifname, struct sigma_cmd *cmd)
13065{
13066 const char *val, *imsi = NULL;
13067 int id;
13068 char buf[200];
13069 int res;
13070 const char *pos;
13071 size_t mnc_len;
13072 char plmn_mcc[4];
13073 char plmn_mnc[4];
13074
13075 id = add_cred(ifname);
13076 if (id < 0)
13077 return -2;
13078 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13079
13080 val = get_param(cmd, "prefer");
13081 if (val && atoi(val) > 0)
13082 set_cred(ifname, id, "priority", "1");
13083
13084 val = get_param(cmd, "PLMN_MCC");
13085 if (val == NULL) {
13086 send_resp(dut, conn, SIGMA_ERROR,
13087 "errorCode,Missing PLMN_MCC");
13088 return 0;
13089 }
13090 if (strlen(val) != 3) {
13091 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
13092 return 0;
13093 }
13094 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
13095
13096 val = get_param(cmd, "PLMN_MNC");
13097 if (val == NULL) {
13098 send_resp(dut, conn, SIGMA_ERROR,
13099 "errorCode,Missing PLMN_MNC");
13100 return 0;
13101 }
13102 if (strlen(val) != 2 && strlen(val) != 3) {
13103 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
13104 return 0;
13105 }
13106 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
13107
13108 val = get_param(cmd, "IMSI");
13109 if (val == NULL) {
13110 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
13111 "IMSI");
13112 return 0;
13113 }
13114
13115 imsi = pos = val;
13116
13117 if (strncmp(plmn_mcc, pos, 3) != 0) {
13118 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
13119 return 0;
13120 }
13121 pos += 3;
13122
13123 mnc_len = strlen(plmn_mnc);
13124 if (mnc_len < 2) {
13125 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
13126 return 0;
13127 }
13128
13129 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
13130 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
13131 return 0;
13132 }
13133 pos += mnc_len;
13134
13135 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
13136 if (res < 0 || res >= (int) sizeof(buf))
13137 return -1;
13138 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
13139 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13140 "not set IMSI");
13141 return 0;
13142 }
13143
13144 val = get_param(cmd, "Password");
13145 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
13146 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13147 "not set password");
13148 return 0;
13149 }
13150
Jouni Malinenba630452018-06-22 11:49:59 +030013151 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013152 /*
13153 * Set provisioning_sp for the test cases where SIM/USIM
13154 * provisioning is used.
13155 */
13156 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
13157 "wi-fi.org") < 0) {
13158 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13159 "not set provisioning_sp");
13160 return 0;
13161 }
13162
13163 update_devdetail_imsi(dut, imsi);
13164 }
13165
13166 return 1;
13167}
13168
13169
13170static int sta_add_credential_cert(struct sigma_dut *dut,
13171 struct sigma_conn *conn,
13172 const char *ifname,
13173 struct sigma_cmd *cmd)
13174{
13175 const char *val;
13176 int id;
13177
13178 id = add_cred(ifname);
13179 if (id < 0)
13180 return -2;
13181 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13182
13183 val = get_param(cmd, "prefer");
13184 if (val && atoi(val) > 0)
13185 set_cred(ifname, id, "priority", "1");
13186
13187 val = get_param(cmd, "REALM");
13188 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13189 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13190 "realm");
13191 return 0;
13192 }
13193
13194 val = get_param(cmd, "HOME_FQDN");
13195 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13196 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13197 "home_fqdn");
13198 return 0;
13199 }
13200
13201 val = get_param(cmd, "Username");
13202 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13203 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13204 "username");
13205 return 0;
13206 }
13207
13208 val = get_param(cmd, "clientCertificate");
13209 if (val) {
13210 char fname[200];
13211 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13212#ifdef __linux__
13213 if (!file_exists(fname)) {
13214 char msg[300];
13215 snprintf(msg, sizeof(msg),
13216 "ErrorCode,clientCertificate "
13217 "file (%s) not found", fname);
13218 send_resp(dut, conn, SIGMA_ERROR, msg);
13219 return 0;
13220 }
13221#endif /* __linux__ */
13222 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
13223 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13224 "not set client_cert");
13225 return 0;
13226 }
13227 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
13228 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13229 "not set private_key");
13230 return 0;
13231 }
13232 }
13233
13234 val = get_param(cmd, "ROOT_CA");
13235 if (val) {
13236 char fname[200];
13237 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13238#ifdef __linux__
13239 if (!file_exists(fname)) {
13240 char msg[300];
13241 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13242 "file (%s) not found", fname);
13243 send_resp(dut, conn, SIGMA_ERROR, msg);
13244 return 0;
13245 }
13246#endif /* __linux__ */
13247 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13248 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13249 "not set root CA");
13250 return 0;
13251 }
13252 }
13253
13254 return 1;
13255}
13256
13257
Jouni Malinenf7222712019-06-13 01:50:21 +030013258static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
13259 struct sigma_conn *conn,
13260 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013261{
13262 const char *intf = get_param(cmd, "Interface");
13263 const char *type;
13264
13265 start_sta_mode(dut);
13266
13267 type = get_param(cmd, "Type");
13268 if (!type)
13269 return -1;
13270
13271 if (strcasecmp(type, "uname_pwd") == 0)
13272 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
13273
13274 if (strcasecmp(type, "sim") == 0)
13275 return sta_add_credential_sim(dut, conn, intf, cmd);
13276
13277 if (strcasecmp(type, "cert") == 0)
13278 return sta_add_credential_cert(dut, conn, intf, cmd);
13279
13280 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
13281 "type");
13282 return 0;
13283}
13284
13285
Jouni Malinenf7222712019-06-13 01:50:21 +030013286static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
13287 struct sigma_conn *conn,
13288 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013289{
13290 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013291 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Arif Hussain66a4af02019-02-07 15:04:51 -080013292 char buf[4096];
vamsi krishna89ad8c62017-09-19 12:51:18 +053013293 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013294 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013295 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013296 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013297 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013298
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020013299 start_sta_mode(dut);
13300
Arif Hussain66a4af02019-02-07 15:04:51 -080013301 val = get_param(cmd, "GetParameter");
13302 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013303 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080013304 buf, sizeof(buf)) < 0) {
13305 sigma_dut_print(dut, DUT_MSG_ERROR,
13306 "Could not get ssid bssid");
13307 return ERROR_SEND_STATUS;
13308 }
13309
13310 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
13311 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13312 return STATUS_SENT;
13313 }
13314
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013315 val = get_param(cmd, "HESSID");
13316 if (val) {
13317 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
13318 if (res < 0 || res >= (int) sizeof(buf))
13319 return -1;
13320 wpa_command(intf, buf);
13321 }
13322
13323 val = get_param(cmd, "ACCS_NET_TYPE");
13324 if (val) {
13325 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
13326 val);
13327 if (res < 0 || res >= (int) sizeof(buf))
13328 return -1;
13329 wpa_command(intf, buf);
13330 }
13331
vamsi krishna89ad8c62017-09-19 12:51:18 +053013332 bssid = get_param(cmd, "Bssid");
13333 ssid = get_param(cmd, "Ssid");
13334
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013335 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
13336 dut->device_type == STA_testbed) {
13337 ssid = NULL;
13338 wildcard_ssid = 1;
13339 }
13340
vamsi krishna89ad8c62017-09-19 12:51:18 +053013341 if (ssid) {
13342 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
13343 send_resp(dut, conn, SIGMA_ERROR,
13344 "ErrorCode,Too long SSID");
13345 return 0;
13346 }
13347 ascii2hexstr(ssid, ssid_hex);
13348 }
13349
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013350 short_ssid = get_param(cmd, "ShortSSID");
13351 if (short_ssid) {
13352 uint32_t short_ssid_hex;
13353
13354 short_ssid_hex = strtoul(short_ssid, NULL, 16);
13355 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
13356 (((short_ssid_hex >> 8) & 0xFF) << 16) |
13357 (((short_ssid_hex >> 16) & 0xFF) << 8) |
13358 ((short_ssid_hex >> 24) & 0xFF);
13359
13360 res = snprintf(buf, sizeof(buf),
13361 "VENDOR_ELEM_ADD 14 ff053a%08x",
13362 short_ssid_hex);
13363 if (res < 0 || res >= (int) sizeof(buf) ||
13364 wpa_command(intf, buf)) {
13365 send_resp(dut, conn, SIGMA_ERROR,
13366 "errorCode,Failed to add short SSID");
13367 return STATUS_SENT_ERROR;
13368 }
13369 }
13370
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013371 scan_freq = get_param(cmd, "ChnlFreq");
13372
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013373 val = get_param(cmd, "WaitCompletion");
13374 if (val && atoi(val) == 1) {
13375 ctrl = open_wpa_mon(intf);
13376 if (!ctrl) {
13377 send_resp(dut, conn, SIGMA_ERROR,
13378 "errorCode,Failed to open monitor socket");
13379 return STATUS_SENT_ERROR;
13380 }
13381 }
13382
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013383 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053013384 bssid ? " bssid=": "",
13385 bssid ? bssid : "",
13386 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013387 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013388 wildcard_ssid ? " wildcard_ssid=1" : "",
13389 scan_freq ? " freq=" : "",
13390 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013391 if (res < 0 || res >= (int) sizeof(buf)) {
13392 send_resp(dut, conn, SIGMA_ERROR,
13393 "errorCode,Could not build scan command");
13394 status = STATUS_SENT_ERROR;
13395 goto remove_s_ssid;
13396 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053013397
13398 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013399 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
13400 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013401 status = STATUS_SENT_ERROR;
13402 } else {
13403 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013404 }
13405
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013406remove_s_ssid:
13407 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
13408 sigma_dut_print(dut, DUT_MSG_ERROR,
13409 "Failed to delete vendor element");
13410
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013411 if (ctrl) {
13412 if (status == SUCCESS_SEND_STATUS) {
13413 res = get_wpa_cli_event(dut, ctrl,
13414 "CTRL-EVENT-SCAN-RESULTS",
13415 buf, sizeof(buf));
13416 if (res < 0) {
13417 send_resp(dut, conn, SIGMA_ERROR,
13418 "ErrorCode,scan did not complete");
13419 status = STATUS_SENT_ERROR;
13420 }
13421 }
13422
13423 wpa_ctrl_detach(ctrl);
13424 wpa_ctrl_close(ctrl);
13425 }
13426
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013427 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013428}
13429
13430
Jouni Malinenf7222712019-06-13 01:50:21 +030013431static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
13432 struct sigma_conn *conn,
13433 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013434{
13435 const char *intf = get_param(cmd, "Interface");
13436 const char *bssid;
13437 char buf[4096], *pos;
13438 int freq, chan;
13439 char *ssid;
13440 char resp[100];
13441 int res;
13442 struct wpa_ctrl *ctrl;
13443
13444 bssid = get_param(cmd, "BSSID");
13445 if (!bssid) {
13446 send_resp(dut, conn, SIGMA_INVALID,
13447 "errorCode,BSSID argument is missing");
13448 return 0;
13449 }
13450
13451 ctrl = open_wpa_mon(intf);
13452 if (!ctrl) {
13453 sigma_dut_print(dut, DUT_MSG_ERROR,
13454 "Failed to open wpa_supplicant monitor connection");
13455 return -1;
13456 }
13457
13458 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
13459 send_resp(dut, conn, SIGMA_ERROR,
13460 "errorCode,Could not start scan");
13461 wpa_ctrl_detach(ctrl);
13462 wpa_ctrl_close(ctrl);
13463 return 0;
13464 }
13465
13466 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
13467 buf, sizeof(buf));
13468
13469 wpa_ctrl_detach(ctrl);
13470 wpa_ctrl_close(ctrl);
13471
13472 if (res < 0) {
13473 send_resp(dut, conn, SIGMA_ERROR,
13474 "errorCode,Scan did not complete");
13475 return 0;
13476 }
13477
13478 snprintf(buf, sizeof(buf), "BSS %s", bssid);
13479 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
13480 strncmp(buf, "id=", 3) != 0) {
13481 send_resp(dut, conn, SIGMA_ERROR,
13482 "errorCode,Specified BSSID not found");
13483 return 0;
13484 }
13485
13486 pos = strstr(buf, "\nfreq=");
13487 if (!pos) {
13488 send_resp(dut, conn, SIGMA_ERROR,
13489 "errorCode,Channel not found");
13490 return 0;
13491 }
13492 freq = atoi(pos + 6);
13493 chan = freq_to_channel(freq);
13494
13495 pos = strstr(buf, "\nssid=");
13496 if (!pos) {
13497 send_resp(dut, conn, SIGMA_ERROR,
13498 "errorCode,SSID not found");
13499 return 0;
13500 }
13501 ssid = pos + 6;
13502 pos = strchr(ssid, '\n');
13503 if (pos)
13504 *pos = '\0';
13505 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
13506 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13507 return 0;
13508}
13509
13510
Jouni Malinenf7222712019-06-13 01:50:21 +030013511static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
13512 struct sigma_conn *conn,
13513 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013514{
13515#ifdef __linux__
13516 struct timeval tv;
13517 struct tm tm;
13518 time_t t;
13519 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013520 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013521
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013522 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013523
13524 memset(&tm, 0, sizeof(tm));
13525 val = get_param(cmd, "seconds");
13526 if (val)
13527 tm.tm_sec = atoi(val);
13528 val = get_param(cmd, "minutes");
13529 if (val)
13530 tm.tm_min = atoi(val);
13531 val = get_param(cmd, "hours");
13532 if (val)
13533 tm.tm_hour = atoi(val);
13534 val = get_param(cmd, "date");
13535 if (val)
13536 tm.tm_mday = atoi(val);
13537 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013538 if (val) {
13539 v = atoi(val);
13540 if (v < 1 || v > 12) {
13541 send_resp(dut, conn, SIGMA_INVALID,
13542 "errorCode,Invalid month");
13543 return 0;
13544 }
13545 tm.tm_mon = v - 1;
13546 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013547 val = get_param(cmd, "year");
13548 if (val) {
13549 int year = atoi(val);
13550#ifdef ANDROID
13551 if (year > 2035)
13552 year = 2035; /* years beyond 2035 not supported */
13553#endif /* ANDROID */
13554 tm.tm_year = year - 1900;
13555 }
13556 t = mktime(&tm);
13557 if (t == (time_t) -1) {
13558 send_resp(dut, conn, SIGMA_ERROR,
13559 "errorCode,Invalid date or time");
13560 return 0;
13561 }
13562
13563 memset(&tv, 0, sizeof(tv));
13564 tv.tv_sec = t;
13565
13566 if (settimeofday(&tv, NULL) < 0) {
13567 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
13568 strerror(errno));
13569 send_resp(dut, conn, SIGMA_ERROR,
13570 "errorCode,Failed to set time");
13571 return 0;
13572 }
13573
13574 return 1;
13575#endif /* __linux__ */
13576
13577 return -1;
13578}
13579
13580
Jouni Malinenf7222712019-06-13 01:50:21 +030013581static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
13582 struct sigma_conn *conn,
13583 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013584{
13585 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013586 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013587 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013588 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013589 int res;
13590 struct wpa_ctrl *ctrl;
13591
13592 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013593 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013594
13595 val = get_param(cmd, "ProdESSAssoc");
13596 if (val)
13597 prod_ess_assoc = atoi(val);
13598
13599 kill_dhcp_client(dut, intf);
13600 if (start_dhcp_client(dut, intf) < 0)
13601 return -2;
13602
13603 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
13604 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13605 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013606 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013607 prod_ess_assoc ? "" : "-N",
13608 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013609 name ? "'" : "",
13610 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
13611 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013612
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053013613 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013614 if (run_hs20_osu(dut, buf) < 0) {
13615 FILE *f;
13616
13617 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
13618
13619 f = fopen("hs20-osu-client.res", "r");
13620 if (f) {
13621 char resp[400], res[300], *pos;
13622 if (!fgets(res, sizeof(res), f))
13623 res[0] = '\0';
13624 pos = strchr(res, '\n');
13625 if (pos)
13626 *pos = '\0';
13627 fclose(f);
13628 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
13629 res);
13630 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
13631 if (system(resp) != 0) {
13632 }
13633 snprintf(resp, sizeof(resp),
13634 "SSID,,BSSID,,failureReason,%s", res);
13635 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13636 return 0;
13637 }
13638
13639 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13640 return 0;
13641 }
13642
13643 if (!prod_ess_assoc)
13644 goto report;
13645
13646 ctrl = open_wpa_mon(intf);
13647 if (ctrl == NULL) {
13648 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13649 "wpa_supplicant monitor connection");
13650 return -1;
13651 }
13652
13653 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13654 buf, sizeof(buf));
13655
13656 wpa_ctrl_detach(ctrl);
13657 wpa_ctrl_close(ctrl);
13658
13659 if (res < 0) {
13660 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
13661 "network after OSU");
13662 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13663 return 0;
13664 }
13665
13666report:
13667 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13668 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13669 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
13670 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13671 return 0;
13672 }
13673
13674 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
13675 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013676 return 0;
13677}
13678
13679
Jouni Malinenf7222712019-06-13 01:50:21 +030013680static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
13681 struct sigma_conn *conn,
13682 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013683{
13684 const char *val;
13685 int timeout = 120;
13686
13687 val = get_param(cmd, "PolicyUpdate");
13688 if (val == NULL || atoi(val) == 0)
13689 return 1; /* No operation requested */
13690
13691 val = get_param(cmd, "Timeout");
13692 if (val)
13693 timeout = atoi(val);
13694
13695 if (timeout) {
13696 /* TODO: time out the command and return
13697 * PolicyUpdateStatus,TIMEOUT if needed. */
13698 }
13699
13700 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
13701 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13702 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
13703 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
13704 return 0;
13705 }
13706
13707 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
13708 return 0;
13709}
13710
13711
Jouni Malinenf7222712019-06-13 01:50:21 +030013712static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
13713 struct sigma_conn *conn,
13714 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013715{
13716 struct wpa_ctrl *ctrl;
13717 const char *intf = get_param(cmd, "Interface");
13718 const char *bssid = get_param(cmd, "Bssid");
13719 const char *ssid = get_param(cmd, "SSID");
13720 const char *security = get_param(cmd, "Security");
13721 const char *passphrase = get_param(cmd, "Passphrase");
13722 const char *pin = get_param(cmd, "PIN");
13723 char buf[1000];
13724 char ssid_hex[200], passphrase_hex[200];
13725 const char *keymgmt, *cipher;
13726
13727 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013728 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013729
13730 if (!bssid) {
13731 send_resp(dut, conn, SIGMA_ERROR,
13732 "ErrorCode,Missing Bssid argument");
13733 return 0;
13734 }
13735
13736 if (!ssid) {
13737 send_resp(dut, conn, SIGMA_ERROR,
13738 "ErrorCode,Missing SSID argument");
13739 return 0;
13740 }
13741
13742 if (!security) {
13743 send_resp(dut, conn, SIGMA_ERROR,
13744 "ErrorCode,Missing Security argument");
13745 return 0;
13746 }
13747
13748 if (!passphrase) {
13749 send_resp(dut, conn, SIGMA_ERROR,
13750 "ErrorCode,Missing Passphrase argument");
13751 return 0;
13752 }
13753
13754 if (!pin) {
13755 send_resp(dut, conn, SIGMA_ERROR,
13756 "ErrorCode,Missing PIN argument");
13757 return 0;
13758 }
13759
vamsi krishna8c9c1562017-05-12 15:51:46 +053013760 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
13761 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013762 send_resp(dut, conn, SIGMA_ERROR,
13763 "ErrorCode,Too long SSID/passphrase");
13764 return 0;
13765 }
13766
13767 ctrl = open_wpa_mon(intf);
13768 if (ctrl == NULL) {
13769 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13770 "wpa_supplicant monitor connection");
13771 return -2;
13772 }
13773
13774 if (strcasecmp(security, "wpa2-psk") == 0) {
13775 keymgmt = "WPA2PSK";
13776 cipher = "CCMP";
13777 } else {
13778 wpa_ctrl_detach(ctrl);
13779 wpa_ctrl_close(ctrl);
13780 send_resp(dut, conn, SIGMA_ERROR,
13781 "ErrorCode,Unsupported Security value");
13782 return 0;
13783 }
13784
13785 ascii2hexstr(ssid, ssid_hex);
13786 ascii2hexstr(passphrase, passphrase_hex);
13787 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
13788 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
13789
13790 if (wpa_command(intf, buf) < 0) {
13791 wpa_ctrl_detach(ctrl);
13792 wpa_ctrl_close(ctrl);
13793 send_resp(dut, conn, SIGMA_ERROR,
13794 "ErrorCode,Failed to start registrar");
13795 return 0;
13796 }
13797
13798 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
13799 dut->er_oper_performed = 1;
13800
13801 return wps_connection_event(dut, conn, ctrl, intf, 0);
13802}
13803
13804
Jouni Malinenf7222712019-06-13 01:50:21 +030013805static enum sigma_cmd_result
13806cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
13807 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013808{
13809 struct wpa_ctrl *ctrl;
13810 const char *intf = get_param(cmd, "Interface");
13811 const char *bssid = get_param(cmd, "Bssid");
13812 char buf[100];
13813
13814 if (!bssid) {
13815 send_resp(dut, conn, SIGMA_ERROR,
13816 "ErrorCode,Missing Bssid argument");
13817 return 0;
13818 }
13819
13820 ctrl = open_wpa_mon(intf);
13821 if (ctrl == NULL) {
13822 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13823 "wpa_supplicant monitor connection");
13824 return -2;
13825 }
13826
13827 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
13828
13829 if (wpa_command(intf, buf) < 0) {
13830 wpa_ctrl_detach(ctrl);
13831 wpa_ctrl_close(ctrl);
13832 send_resp(dut, conn, SIGMA_ERROR,
13833 "ErrorCode,Failed to start registrar");
13834 return 0;
13835 }
13836
13837 return wps_connection_event(dut, conn, ctrl, intf, 0);
13838}
13839
13840
Jouni Malinenf7222712019-06-13 01:50:21 +030013841static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
13842 struct sigma_conn *conn,
13843 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053013844{
13845 struct wpa_ctrl *ctrl;
13846 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013847 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013848 const char *config_method = get_param(cmd, "WPSConfigMethod");
13849 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053013850 int res;
13851 char buf[256];
13852 const char *events[] = {
13853 "CTRL-EVENT-CONNECTED",
13854 "WPS-OVERLAP-DETECTED",
13855 "WPS-TIMEOUT",
13856 "WPS-FAIL",
13857 NULL
13858 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013859 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053013860
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013861 /* 60G WPS tests do not pass Interface parameter */
13862 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013863 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013864
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013865 if (dut->mode == SIGMA_MODE_AP)
13866 return ap_wps_registration(dut, conn, cmd);
13867
13868 if (config_method) {
13869 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
13870 * sta_wps_enter_pin before calling start_wps_registration. */
13871 if (strcasecmp(config_method, "PBC") == 0)
13872 dut->wps_method = WFA_CS_WPS_PBC;
13873 }
13874 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
13875 send_resp(dut, conn, SIGMA_ERROR,
13876 "ErrorCode,WPS parameters not yet set");
13877 return STATUS_SENT;
13878 }
13879
13880 /* Make sure WPS is enabled (also for STA mode) */
13881 dut->wps_disable = 0;
13882
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013883 if (dut->band == WPS_BAND_60G && network_mode &&
13884 strcasecmp(network_mode, "PBSS") == 0) {
13885 sigma_dut_print(dut, DUT_MSG_DEBUG,
13886 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013887 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013888 return -2;
13889 }
13890
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013891 if (dut->force_rsn_ie) {
13892 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
13893 dut->force_rsn_ie);
13894 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
13895 sigma_dut_print(dut, DUT_MSG_INFO,
13896 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020013897 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013898 }
13899 }
13900
vamsi krishna9b144002017-09-20 13:28:13 +053013901 ctrl = open_wpa_mon(intf);
13902 if (!ctrl) {
13903 sigma_dut_print(dut, DUT_MSG_ERROR,
13904 "Failed to open wpa_supplicant monitor connection");
13905 return -2;
13906 }
13907
13908 role = get_param(cmd, "WpsRole");
13909 if (!role) {
13910 send_resp(dut, conn, SIGMA_INVALID,
13911 "ErrorCode,WpsRole not provided");
13912 goto fail;
13913 }
13914
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013915 if (strcasecmp(role, "Enrollee") != 0) {
13916 /* Registrar role for STA not supported */
13917 send_resp(dut, conn, SIGMA_ERROR,
13918 "ErrorCode,Unsupported WpsRole value");
13919 goto fail;
13920 }
13921
13922 if (is_60g_sigma_dut(dut)) {
13923 if (dut->wps_method == WFA_CS_WPS_PBC)
13924 snprintf(buf, sizeof(buf), "WPS_PBC");
13925 else /* WFA_CS_WPS_PIN_KEYPAD */
13926 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
13927 dut->wps_pin);
13928 if (wpa_command(intf, buf) < 0) {
13929 send_resp(dut, conn, SIGMA_ERROR,
13930 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053013931 goto fail;
13932 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013933 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13934 if (res < 0) {
13935 send_resp(dut, conn, SIGMA_ERROR,
13936 "ErrorCode,WPS connection did not complete");
13937 goto fail;
13938 }
13939 if (strstr(buf, "WPS-TIMEOUT")) {
13940 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
13941 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13942 send_resp(dut, conn, SIGMA_COMPLETE,
13943 "WpsState,OverlapSession");
13944 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13945 send_resp(dut, conn, SIGMA_COMPLETE,
13946 "WpsState,Successful");
13947 } else {
13948 send_resp(dut, conn, SIGMA_COMPLETE,
13949 "WpsState,Failure");
13950 }
13951 } else {
13952 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053013953 if (wpa_command(intf, "WPS_PBC") < 0) {
13954 send_resp(dut, conn, SIGMA_ERROR,
13955 "ErrorCode,Failed to enable PBC");
13956 goto fail;
13957 }
13958 } else {
13959 /* TODO: PIN method */
13960 send_resp(dut, conn, SIGMA_ERROR,
13961 "ErrorCode,Unsupported WpsConfigMethod value");
13962 goto fail;
13963 }
13964 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13965 if (res < 0) {
13966 send_resp(dut, conn, SIGMA_ERROR,
13967 "ErrorCode,WPS connection did not complete");
13968 goto fail;
13969 }
13970 if (strstr(buf, "WPS-TIMEOUT")) {
13971 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
13972 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13973 send_resp(dut, conn, SIGMA_ERROR,
13974 "ErrorCode,OverlapSession");
13975 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13976 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
13977 } else {
13978 send_resp(dut, conn, SIGMA_ERROR,
13979 "ErrorCode,WPS operation failed");
13980 }
vamsi krishna9b144002017-09-20 13:28:13 +053013981 }
13982
13983fail:
13984 wpa_ctrl_detach(ctrl);
13985 wpa_ctrl_close(ctrl);
13986 return 0;
13987}
13988
13989
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013990static int req_intf(struct sigma_cmd *cmd)
13991{
13992 return get_param(cmd, "interface") == NULL ? -1 : 0;
13993}
13994
13995
13996void sta_register_cmds(void)
13997{
13998 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
13999 cmd_sta_get_ip_config);
14000 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
14001 cmd_sta_set_ip_config);
14002 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
14003 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
14004 cmd_sta_get_mac_address);
14005 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
14006 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
14007 cmd_sta_verify_ip_connection);
14008 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
14009 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
14010 cmd_sta_set_encryption);
14011 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
14012 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
14013 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
14014 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
14015 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
14016 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
14017 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
14018 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
14019 cmd_sta_set_eapakaprime);
14020 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
14021 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
14022 /* TODO: sta_set_ibss */
14023 /* TODO: sta_set_mode */
14024 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
14025 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
14026 /* TODO: sta_up_load */
14027 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
14028 cmd_sta_preset_testparameters);
14029 /* TODO: sta_set_system */
14030 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
14031 /* TODO: sta_set_rifs_test */
14032 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
14033 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
14034 /* TODO: sta_send_coexist_mgmt */
14035 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
14036 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
14037 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
14038 sigma_dut_reg_cmd("sta_reset_default", req_intf,
14039 cmd_sta_reset_default);
14040 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
14041 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
14042 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
14043 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
14044 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014045 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014046 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
14047 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
14048 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
14049 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
14050 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030014051 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
14052 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014053 sigma_dut_reg_cmd("sta_add_credential", req_intf,
14054 cmd_sta_add_credential);
14055 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020014056 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014057 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
14058 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
14059 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
14060 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
14061 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
14062 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030014063 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014064 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
14065 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014066 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053014067 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014068}