blob: f256785c46a5706a599b4a697acaf2ab00b1153f [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");
2289 return ERROR_SEND_STATUS;
2290 }
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
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002304 if (dut->program == PROGRAM_60GHZ && network_mode &&
2305 strcasecmp(network_mode, "PBSS") == 0 &&
2306 set_network(ifname, id, "pbss", "1") < 0)
2307 return -2;
2308
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002309 return 1;
2310}
2311
2312
Jouni Malinen8ac93452019-08-14 15:19:13 +03002313static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2314 struct sigma_conn *conn,
2315 const char *ifname, int id)
2316{
2317 char buf[200];
2318
2319 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2320 if (!file_exists(buf))
2321 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2322 if (!file_exists(buf))
2323 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2324 if (!file_exists(buf)) {
2325 char msg[300];
2326
2327 snprintf(msg, sizeof(msg),
2328 "ErrorCode,trustedRootCA system store (%s) not found",
2329 buf);
2330 send_resp(dut, conn, SIGMA_ERROR, msg);
2331 return STATUS_SENT_ERROR;
2332 }
2333
2334 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2335 return ERROR_SEND_STATUS;
2336
2337 return SUCCESS_SEND_STATUS;
2338}
2339
2340
2341static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2342 struct sigma_conn *conn,
2343 const char *ifname, int id,
2344 const char *val)
2345{
2346 char buf[200];
2347#ifdef ANDROID
2348 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2349 int length;
2350#endif /* ANDROID */
2351
2352 if (strcmp(val, "DEFAULT") == 0)
2353 return set_trust_root_system(dut, conn, ifname, id);
2354
2355#ifdef ANDROID
2356 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2357 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2358 if (length > 0) {
2359 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2360 buf);
2361 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2362 goto ca_cert_selected;
2363 }
2364#endif /* ANDROID */
2365
2366 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2367#ifdef __linux__
2368 if (!file_exists(buf)) {
2369 char msg[300];
2370
2371 snprintf(msg, sizeof(msg),
2372 "ErrorCode,trustedRootCA file (%s) not found", buf);
2373 send_resp(dut, conn, SIGMA_ERROR, msg);
2374 return STATUS_SENT_ERROR;
2375 }
2376#endif /* __linux__ */
2377#ifdef ANDROID
2378ca_cert_selected:
2379#endif /* ANDROID */
2380 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2381 return ERROR_SEND_STATUS;
2382
2383 return SUCCESS_SEND_STATUS;
2384}
2385
2386
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002387static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302388 const char *ifname, int username_identity,
2389 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002390{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002391 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002392 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002393 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002394 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002395 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002396
2397 id = set_wpa_common(dut, conn, ifname, cmd);
2398 if (id < 0)
2399 return id;
2400
2401 val = get_param(cmd, "keyMgmtType");
2402 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302403 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002404 trust_root = get_param(cmd, "trustedRootCA");
2405 domain = get_param(cmd, "Domain");
2406 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002407
Jouni Malinenad395a22017-09-01 21:13:46 +03002408 if (val && strcasecmp(val, "SuiteB") == 0) {
2409 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2410 0)
2411 return -2;
2412 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002413 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2414 return -2;
2415 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2416 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2417 return -2;
2418 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2419 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2420 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002421 } else if (!akm &&
2422 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2423 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002424 if (set_network(ifname, id, "key_mgmt",
2425 "WPA-EAP WPA-EAP-SHA256") < 0)
2426 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302427 } else if (akm && atoi(akm) == 14) {
2428 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2429 dut->sta_pmf == STA_PMF_REQUIRED) {
2430 if (set_network(ifname, id, "key_mgmt",
2431 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2432 return -2;
2433 } else {
2434 if (set_network(ifname, id, "key_mgmt",
2435 "WPA-EAP FILS-SHA256") < 0)
2436 return -2;
2437 }
2438
Jouni Malinen8179fee2019-03-28 03:19:47 +02002439 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302440 } else if (akm && atoi(akm) == 15) {
2441 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2442 dut->sta_pmf == STA_PMF_REQUIRED) {
2443 if (set_network(ifname, id, "key_mgmt",
2444 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2445 return -2;
2446 } else {
2447 if (set_network(ifname, id, "key_mgmt",
2448 "WPA-EAP FILS-SHA384") < 0)
2449 return -2;
2450 }
2451
Jouni Malinen8179fee2019-03-28 03:19:47 +02002452 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002453 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002454 if (set_network(ifname, id, "key_mgmt",
2455 "WPA-EAP WPA-EAP-SHA256") < 0)
2456 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002457 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002458 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2459 return -2;
2460 }
2461
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002462 if (trust_root) {
2463 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2464 !domain_suffix) {
2465 send_resp(dut, conn, SIGMA_ERROR,
2466 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2467 return STATUS_SENT_ERROR;
2468 }
2469 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002470 if (res != SUCCESS_SEND_STATUS)
2471 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002472 }
2473
Jouni Malinen53264f62019-05-03 13:04:40 +03002474 val = get_param(cmd, "ServerCert");
2475 if (val) {
2476 FILE *f;
2477 char *result = NULL, *pos;
2478
2479 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2480 val);
2481 f = fopen(buf, "r");
2482 if (f) {
2483 result = fgets(buf, sizeof(buf), f);
2484 fclose(f);
2485 }
2486 if (!result) {
2487 snprintf(buf2, sizeof(buf2),
2488 "ErrorCode,ServerCert hash could not be read from %s",
2489 buf);
2490 send_resp(dut, conn, SIGMA_ERROR, buf2);
2491 return STATUS_SENT_ERROR;
2492 }
2493 pos = strchr(buf, '\n');
2494 if (pos)
2495 *pos = '\0';
2496 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2497 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2498 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002499
2500 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2501 if (file_exists(buf)) {
2502 sigma_dut_print(dut, DUT_MSG_DEBUG,
2503 "TOD policy enabled for the configured ServerCert hash");
2504 dut->sta_tod_policy = 1;
2505 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002506 }
2507
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002508 if (domain &&
2509 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002510 return ERROR_SEND_STATUS;
2511
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002512 if (domain_suffix &&
2513 set_network_quoted(ifname, id, "domain_suffix_match",
2514 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002515 return ERROR_SEND_STATUS;
2516
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302517 if (username_identity) {
2518 val = get_param(cmd, "username");
2519 if (val) {
2520 if (set_network_quoted(ifname, id, "identity", val) < 0)
2521 return -2;
2522 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002523
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302524 val = get_param(cmd, "password");
2525 if (val) {
2526 if (set_network_quoted(ifname, id, "password", val) < 0)
2527 return -2;
2528 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002529 }
2530
Jouni Malinen8179fee2019-03-28 03:19:47 +02002531 if (dut->akm_values &
2532 ((1 << AKM_FILS_SHA256) |
2533 (1 << AKM_FILS_SHA384) |
2534 (1 << AKM_FT_FILS_SHA256) |
2535 (1 << AKM_FT_FILS_SHA384)))
2536 erp = 1;
2537 if (erp && set_network(ifname, id, "erp", "1") < 0)
2538 return ERROR_SEND_STATUS;
2539
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002540 dut->sta_associate_wait_connect = 1;
2541
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002542 return id;
2543}
2544
2545
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002546static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2547{
2548 const char *val;
2549
2550 if (!cipher)
2551 return 0;
2552
2553 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2554 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2555 else if (strcasecmp(cipher,
2556 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2557 val = "ECDHE-RSA-AES256-GCM-SHA384";
2558 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2559 val = "DHE-RSA-AES256-GCM-SHA384";
2560 else if (strcasecmp(cipher,
2561 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2562 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2563 else
2564 return -1;
2565
2566 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2567 set_network_quoted(ifname, id, "phase1", "");
2568
2569 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2570}
2571
2572
Jouni Malinenf7222712019-06-13 01:50:21 +03002573static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2574 struct sigma_conn *conn,
2575 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002576{
2577 const char *intf = get_param(cmd, "Interface");
2578 const char *ifname, *val;
2579 int id;
2580 char buf[200];
2581#ifdef ANDROID
2582 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2583 int length;
2584 int jb_or_newer = 0;
2585 char prop[PROPERTY_VALUE_MAX];
2586#endif /* ANDROID */
2587
2588 if (intf == NULL)
2589 return -1;
2590
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002591 if (strcmp(intf, get_main_ifname(dut)) == 0)
2592 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002593 else
2594 ifname = intf;
2595
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302596 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002597 if (id < 0)
2598 return id;
2599
2600 if (set_network(ifname, id, "eap", "TLS") < 0)
2601 return -2;
2602
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302603 if (!get_param(cmd, "username") &&
2604 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002605 "wifi-user@wifilabs.local") < 0)
2606 return -2;
2607
2608 val = get_param(cmd, "clientCertificate");
2609 if (val == NULL)
2610 return -1;
2611#ifdef ANDROID
2612 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2613 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2614 if (length < 0) {
2615 /*
2616 * JB started reporting keystore type mismatches, so retry with
2617 * the GET_PUBKEY command if the generic GET fails.
2618 */
2619 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2620 buf, kvalue);
2621 }
2622
2623 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2624 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2625 if (strncmp(prop, "4.0", 3) != 0)
2626 jb_or_newer = 1;
2627 } else
2628 jb_or_newer = 1; /* assume newer */
2629
2630 if (jb_or_newer && length > 0) {
2631 sigma_dut_print(dut, DUT_MSG_INFO,
2632 "Use Android keystore [%s]", buf);
2633 if (set_network(ifname, id, "engine", "1") < 0)
2634 return -2;
2635 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2636 return -2;
2637 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2638 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2639 return -2;
2640 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2641 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2642 return -2;
2643 return 1;
2644 } else if (length > 0) {
2645 sigma_dut_print(dut, DUT_MSG_INFO,
2646 "Use Android keystore [%s]", buf);
2647 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2648 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2649 return -2;
2650 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2651 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2652 return -2;
2653 return 1;
2654 }
2655#endif /* ANDROID */
2656
2657 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2658#ifdef __linux__
2659 if (!file_exists(buf)) {
2660 char msg[300];
2661 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2662 "(%s) not found", buf);
2663 send_resp(dut, conn, SIGMA_ERROR, msg);
2664 return -3;
2665 }
2666#endif /* __linux__ */
2667 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2668 return -2;
2669 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2670 return -2;
2671
2672 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2673 return -2;
2674
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002675 val = get_param(cmd, "keyMgmtType");
2676 if (val && strcasecmp(val, "SuiteB") == 0) {
2677 val = get_param(cmd, "CertType");
2678 if (val && strcasecmp(val, "RSA") == 0) {
2679 if (set_network_quoted(ifname, id, "phase1",
2680 "tls_suiteb=1") < 0)
2681 return -2;
2682 } else {
2683 if (set_network_quoted(ifname, id, "openssl_ciphers",
2684 "SUITEB192") < 0)
2685 return -2;
2686 }
2687
2688 val = get_param(cmd, "TLSCipher");
2689 if (set_tls_cipher(ifname, id, val) < 0) {
2690 send_resp(dut, conn, SIGMA_ERROR,
2691 "ErrorCode,Unsupported TLSCipher value");
2692 return -3;
2693 }
2694 }
2695
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002696 return 1;
2697}
2698
2699
Jouni Malinenf7222712019-06-13 01:50:21 +03002700static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2701 struct sigma_conn *conn,
2702 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002703{
2704 const char *intf = get_param(cmd, "Interface");
2705 const char *ifname;
2706 int id;
2707
2708 if (intf == NULL)
2709 return -1;
2710
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002711 if (strcmp(intf, get_main_ifname(dut)) == 0)
2712 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002713 else
2714 ifname = intf;
2715
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302716 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002717 if (id < 0)
2718 return id;
2719
2720 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2721 send_resp(dut, conn, SIGMA_ERROR,
2722 "errorCode,Failed to set TTLS method");
2723 return 0;
2724 }
2725
2726 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2727 send_resp(dut, conn, SIGMA_ERROR,
2728 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2729 return 0;
2730 }
2731
2732 return 1;
2733}
2734
2735
Jouni Malinenf7222712019-06-13 01:50:21 +03002736static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2737 struct sigma_conn *conn,
2738 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002739{
2740 const char *intf = get_param(cmd, "Interface");
2741 const char *ifname;
2742 int id;
2743
2744 if (intf == NULL)
2745 return -1;
2746
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002747 if (strcmp(intf, get_main_ifname(dut)) == 0)
2748 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002749 else
2750 ifname = intf;
2751
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302752 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002753 if (id < 0)
2754 return id;
2755
2756 if (set_network(ifname, id, "eap", "SIM") < 0)
2757 return -2;
2758
2759 return 1;
2760}
2761
2762
Jouni Malinenf7222712019-06-13 01:50:21 +03002763static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2764 struct sigma_conn *conn,
2765 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002766{
2767 const char *intf = get_param(cmd, "Interface");
2768 const char *ifname, *val;
2769 int id;
2770 char buf[100];
2771
2772 if (intf == NULL)
2773 return -1;
2774
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002775 if (strcmp(intf, get_main_ifname(dut)) == 0)
2776 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002777 else
2778 ifname = intf;
2779
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302780 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002781 if (id < 0)
2782 return id;
2783
2784 if (set_network(ifname, id, "eap", "PEAP") < 0)
2785 return -2;
2786
2787 val = get_param(cmd, "innerEAP");
2788 if (val) {
2789 if (strcasecmp(val, "MSCHAPv2") == 0) {
2790 if (set_network_quoted(ifname, id, "phase2",
2791 "auth=MSCHAPV2") < 0)
2792 return -2;
2793 } else if (strcasecmp(val, "GTC") == 0) {
2794 if (set_network_quoted(ifname, id, "phase2",
2795 "auth=GTC") < 0)
2796 return -2;
2797 } else
2798 return -1;
2799 }
2800
2801 val = get_param(cmd, "peapVersion");
2802 if (val) {
2803 int ver = atoi(val);
2804 if (ver < 0 || ver > 1)
2805 return -1;
2806 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2807 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2808 return -2;
2809 }
2810
2811 return 1;
2812}
2813
2814
Jouni Malinenf7222712019-06-13 01:50:21 +03002815static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2816 struct sigma_conn *conn,
2817 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002818{
2819 const char *intf = get_param(cmd, "Interface");
2820 const char *ifname, *val;
2821 int id;
2822 char buf[100];
2823
2824 if (intf == NULL)
2825 return -1;
2826
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002827 if (strcmp(intf, get_main_ifname(dut)) == 0)
2828 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002829 else
2830 ifname = intf;
2831
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302832 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002833 if (id < 0)
2834 return id;
2835
2836 if (set_network(ifname, id, "eap", "FAST") < 0)
2837 return -2;
2838
2839 val = get_param(cmd, "innerEAP");
2840 if (val) {
2841 if (strcasecmp(val, "MSCHAPV2") == 0) {
2842 if (set_network_quoted(ifname, id, "phase2",
2843 "auth=MSCHAPV2") < 0)
2844 return -2;
2845 } else if (strcasecmp(val, "GTC") == 0) {
2846 if (set_network_quoted(ifname, id, "phase2",
2847 "auth=GTC") < 0)
2848 return -2;
2849 } else
2850 return -1;
2851 }
2852
2853 val = get_param(cmd, "validateServer");
2854 if (val) {
2855 /* TODO */
2856 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2857 "validateServer=%s", val);
2858 }
2859
2860 val = get_param(cmd, "pacFile");
2861 if (val) {
2862 snprintf(buf, sizeof(buf), "blob://%s", val);
2863 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2864 return -2;
2865 }
2866
2867 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2868 0)
2869 return -2;
2870
2871 return 1;
2872}
2873
2874
Jouni Malinenf7222712019-06-13 01:50:21 +03002875static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2876 struct sigma_conn *conn,
2877 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002878{
2879 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302880 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002881 const char *ifname;
2882 int id;
2883
2884 if (intf == NULL)
2885 return -1;
2886
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002887 if (strcmp(intf, get_main_ifname(dut)) == 0)
2888 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002889 else
2890 ifname = intf;
2891
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302892 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002893 if (id < 0)
2894 return id;
2895
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302896 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2897 * hexadecimal).
2898 */
2899 if (username && username[0] == '6') {
2900 if (set_network(ifname, id, "eap", "AKA'") < 0)
2901 return -2;
2902 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002903 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302904 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002905
2906 return 1;
2907}
2908
2909
Jouni Malinenf7222712019-06-13 01:50:21 +03002910static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2911 struct sigma_conn *conn,
2912 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002913{
2914 const char *intf = get_param(cmd, "Interface");
2915 const char *ifname;
2916 int id;
2917
2918 if (intf == NULL)
2919 return -1;
2920
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002921 if (strcmp(intf, get_main_ifname(dut)) == 0)
2922 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002923 else
2924 ifname = intf;
2925
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302926 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002927 if (id < 0)
2928 return id;
2929
2930 if (set_network(ifname, id, "eap", "AKA'") < 0)
2931 return -2;
2932
2933 return 1;
2934}
2935
2936
2937static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2938 struct sigma_cmd *cmd)
2939{
2940 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002941 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002942 const char *ifname;
2943 int id;
2944
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002945 if (strcmp(intf, get_main_ifname(dut)) == 0)
2946 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002947 else
2948 ifname = intf;
2949
2950 id = add_network_common(dut, conn, ifname, cmd);
2951 if (id < 0)
2952 return id;
2953
2954 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2955 return -2;
2956
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002957 if (dut->program == PROGRAM_60GHZ && network_mode &&
2958 strcasecmp(network_mode, "PBSS") == 0 &&
2959 set_network(ifname, id, "pbss", "1") < 0)
2960 return -2;
2961
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002962 return 1;
2963}
2964
2965
Jouni Malinen47dcc952017-10-09 16:43:24 +03002966static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2967 struct sigma_cmd *cmd)
2968{
2969 const char *intf = get_param(cmd, "Interface");
2970 const char *ifname, *val;
2971 int id;
2972
2973 if (intf == NULL)
2974 return -1;
2975
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002976 if (strcmp(intf, get_main_ifname(dut)) == 0)
2977 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002978 else
2979 ifname = intf;
2980
2981 id = set_wpa_common(dut, conn, ifname, cmd);
2982 if (id < 0)
2983 return id;
2984
2985 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
2986 return -2;
2987
2988 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03002989 if (val && strcmp(val, "0") == 0) {
2990 if (wpa_command(ifname,
2991 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
2992 sigma_dut_print(dut, DUT_MSG_ERROR,
2993 "Failed to set OWE DH Param element override");
2994 return -2;
2995 }
Hu Wang6010ce72020-03-05 19:33:53 +08002996 } else if (val &&
2997 (set_network(ifname, id, "owe_group", val) < 0 ||
2998 (dut->owe_ptk_workaround &&
2999 set_network(ifname, id, "owe_ptk_workaround", "1") < 0))) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003000 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003001 "Failed to set owe_group");
Jouni Malinen47dcc952017-10-09 16:43:24 +03003002 return -2;
3003 }
3004
3005 return 1;
3006}
3007
3008
Jouni Malinenf7222712019-06-13 01:50:21 +03003009static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3010 struct sigma_conn *conn,
3011 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003012{
3013 const char *type = get_param(cmd, "Type");
3014
3015 if (type == NULL) {
3016 send_resp(dut, conn, SIGMA_ERROR,
3017 "ErrorCode,Missing Type argument");
3018 return 0;
3019 }
3020
3021 if (strcasecmp(type, "OPEN") == 0)
3022 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003023 if (strcasecmp(type, "OWE") == 0)
3024 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003025 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003026 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003027 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003028 return cmd_sta_set_psk(dut, conn, cmd);
3029 if (strcasecmp(type, "EAPTLS") == 0)
3030 return cmd_sta_set_eaptls(dut, conn, cmd);
3031 if (strcasecmp(type, "EAPTTLS") == 0)
3032 return cmd_sta_set_eapttls(dut, conn, cmd);
3033 if (strcasecmp(type, "EAPPEAP") == 0)
3034 return cmd_sta_set_peap(dut, conn, cmd);
3035 if (strcasecmp(type, "EAPSIM") == 0)
3036 return cmd_sta_set_eapsim(dut, conn, cmd);
3037 if (strcasecmp(type, "EAPFAST") == 0)
3038 return cmd_sta_set_eapfast(dut, conn, cmd);
3039 if (strcasecmp(type, "EAPAKA") == 0)
3040 return cmd_sta_set_eapaka(dut, conn, cmd);
3041 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3042 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003043 if (strcasecmp(type, "wep") == 0)
3044 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003045
3046 send_resp(dut, conn, SIGMA_ERROR,
3047 "ErrorCode,Unsupported Type value");
3048 return 0;
3049}
3050
3051
3052int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3053{
3054#ifdef __linux__
3055 /* special handling for ath6kl */
3056 char path[128], fname[128], *pos;
3057 ssize_t res;
3058 FILE *f;
3059
Jouni Malinene39cd562019-05-29 23:39:56 +03003060 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3061 intf);
3062 if (res < 0 || res >= sizeof(fname))
3063 return 0;
3064 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003065 if (res < 0)
3066 return 0; /* not ath6kl */
3067
3068 if (res >= (int) sizeof(path))
3069 res = sizeof(path) - 1;
3070 path[res] = '\0';
3071 pos = strrchr(path, '/');
3072 if (pos == NULL)
3073 pos = path;
3074 else
3075 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003076 res = snprintf(fname, sizeof(fname),
3077 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3078 "create_qos", pos);
3079 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003080 return 0; /* not ath6kl */
3081
3082 if (uapsd) {
3083 f = fopen(fname, "w");
3084 if (f == NULL)
3085 return -1;
3086
3087 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3088 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3089 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3090 "20000 0\n");
3091 fclose(f);
3092 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003093 res = snprintf(fname, sizeof(fname),
3094 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3095 "delete_qos", pos);
3096 if (res < 0 || res >= sizeof(fname))
3097 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003098
3099 f = fopen(fname, "w");
3100 if (f == NULL)
3101 return -1;
3102
3103 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3104 fprintf(f, "2 4\n");
3105 fclose(f);
3106 }
3107#endif /* __linux__ */
3108
3109 return 0;
3110}
3111
3112
Jouni Malinenf7222712019-06-13 01:50:21 +03003113static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3114 struct sigma_conn *conn,
3115 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003116{
3117 const char *intf = get_param(cmd, "Interface");
3118 /* const char *ssid = get_param(cmd, "ssid"); */
3119 const char *val;
3120 int max_sp_len = 4;
3121 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3122 char buf[100];
3123 int ret1, ret2;
3124
3125 val = get_param(cmd, "maxSPLength");
3126 if (val) {
3127 max_sp_len = atoi(val);
3128 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3129 max_sp_len != 4)
3130 return -1;
3131 }
3132
3133 val = get_param(cmd, "acBE");
3134 if (val)
3135 ac_be = atoi(val);
3136
3137 val = get_param(cmd, "acBK");
3138 if (val)
3139 ac_bk = atoi(val);
3140
3141 val = get_param(cmd, "acVI");
3142 if (val)
3143 ac_vi = atoi(val);
3144
3145 val = get_param(cmd, "acVO");
3146 if (val)
3147 ac_vo = atoi(val);
3148
3149 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3150
3151 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3152 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3153 ret1 = wpa_command(intf, buf);
3154
3155 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3156 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3157 ret2 = wpa_command(intf, buf);
3158
3159 if (ret1 && ret2) {
3160 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3161 "UAPSD parameters.");
3162 return -2;
3163 }
3164
3165 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3166 send_resp(dut, conn, SIGMA_ERROR,
3167 "ErrorCode,Failed to set ath6kl QoS parameters");
3168 return 0;
3169 }
3170
3171 return 1;
3172}
3173
3174
Jouni Malinenf7222712019-06-13 01:50:21 +03003175static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3176 struct sigma_conn *conn,
3177 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003178{
3179 char buf[1000];
3180 const char *intf = get_param(cmd, "Interface");
3181 const char *grp = get_param(cmd, "Group");
3182 const char *act = get_param(cmd, "Action");
3183 const char *tid = get_param(cmd, "Tid");
3184 const char *dir = get_param(cmd, "Direction");
3185 const char *psb = get_param(cmd, "Psb");
3186 const char *up = get_param(cmd, "Up");
3187 const char *fixed = get_param(cmd, "Fixed");
3188 const char *size = get_param(cmd, "Size");
3189 const char *msize = get_param(cmd, "Maxsize");
3190 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3191 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3192 const char *inact = get_param(cmd, "Inactivity");
3193 const char *sus = get_param(cmd, "Suspension");
3194 const char *mindr = get_param(cmd, "Mindatarate");
3195 const char *meandr = get_param(cmd, "Meandatarate");
3196 const char *peakdr = get_param(cmd, "Peakdatarate");
3197 const char *phyrate = get_param(cmd, "Phyrate");
3198 const char *burstsize = get_param(cmd, "Burstsize");
3199 const char *sba = get_param(cmd, "Sba");
3200 int direction;
3201 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003202 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003203 int fixed_int;
3204 int psb_ts;
3205
3206 if (intf == NULL || grp == NULL || act == NULL )
3207 return -1;
3208
3209 if (strcasecmp(act, "addts") == 0) {
3210 if (tid == NULL || dir == NULL || psb == NULL ||
3211 up == NULL || fixed == NULL || size == NULL)
3212 return -1;
3213
3214 /*
3215 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3216 * possible values, but WMM-AC and V-E test scripts use "UP,
3217 * "DOWN", and "BIDI".
3218 */
3219 if (strcasecmp(dir, "uplink") == 0 ||
3220 strcasecmp(dir, "up") == 0) {
3221 direction = 0;
3222 } else if (strcasecmp(dir, "downlink") == 0 ||
3223 strcasecmp(dir, "down") == 0) {
3224 direction = 1;
3225 } else if (strcasecmp(dir, "bidi") == 0) {
3226 direction = 2;
3227 } else {
3228 sigma_dut_print(dut, DUT_MSG_ERROR,
3229 "Direction %s not supported", dir);
3230 return -1;
3231 }
3232
3233 if (strcasecmp(psb, "legacy") == 0) {
3234 psb_ts = 0;
3235 } else if (strcasecmp(psb, "uapsd") == 0) {
3236 psb_ts = 1;
3237 } else {
3238 sigma_dut_print(dut, DUT_MSG_ERROR,
3239 "PSB %s not supported", psb);
3240 return -1;
3241 }
3242
3243 if (atoi(tid) < 0 || atoi(tid) > 7) {
3244 sigma_dut_print(dut, DUT_MSG_ERROR,
3245 "TID %s not supported", tid);
3246 return -1;
3247 }
3248
3249 if (strcasecmp(fixed, "true") == 0) {
3250 fixed_int = 1;
3251 } else {
3252 fixed_int = 0;
3253 }
3254
Peng Xu93319622017-10-04 17:58:16 -07003255 if (sba)
3256 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003257
3258 dut->dialog_token++;
3259 handle = 7000 + dut->dialog_token;
3260
3261 /*
3262 * size: convert to hex
3263 * maxsi: convert to hex
3264 * mindr: convert to hex
3265 * meandr: convert to hex
3266 * peakdr: convert to hex
3267 * burstsize: convert to hex
3268 * phyrate: convert to hex
3269 * sba: convert to hex with modification
3270 * minsi: convert to integer
3271 * sus: convert to integer
3272 * inact: convert to integer
3273 * maxsi: convert to integer
3274 */
3275
3276 /*
3277 * The Nominal MSDU Size field is 2 octets long and contains an
3278 * unsigned integer that specifies the nominal size, in octets,
3279 * of MSDUs belonging to the traffic under this traffic
3280 * specification and is defined in Figure 16. If the Fixed
3281 * subfield is set to 1, then the size of the MSDU is fixed and
3282 * is indicated by the Size Subfield. If the Fixed subfield is
3283 * set to 0, then the size of the MSDU might not be fixed and
3284 * the Size indicates the nominal MSDU size.
3285 *
3286 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3287 * and specifies the excess allocation of time (and bandwidth)
3288 * over and above the stated rates required to transport an MSDU
3289 * belonging to the traffic in this TSPEC. This field is
3290 * represented as an unsigned binary number with an implicit
3291 * binary point after the leftmost 3 bits. For example, an SBA
3292 * of 1.75 is represented as 0x3800. This field is included to
3293 * account for retransmissions. As such, the value of this field
3294 * must be greater than unity.
3295 */
3296
3297 snprintf(buf, sizeof(buf),
3298 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3299 " 0x%X 0x%X 0x%X"
3300 " 0x%X 0x%X 0x%X"
3301 " 0x%X %d %d %d %d"
3302 " %d %d",
3303 intf, handle, tid, direction, psb_ts, up,
3304 (unsigned int) ((fixed_int << 15) | atoi(size)),
3305 msize ? atoi(msize) : 0,
3306 mindr ? atoi(mindr) : 0,
3307 meandr ? atoi(meandr) : 0,
3308 peakdr ? atoi(peakdr) : 0,
3309 burstsize ? atoi(burstsize) : 0,
3310 phyrate ? atoi(phyrate) : 0,
3311 sba ? ((unsigned int) (((int) sba_fv << 13) |
3312 (int)((sba_fv - (int) sba_fv) *
3313 8192))) : 0,
3314 minsi ? atoi(minsi) : 0,
3315 sus ? atoi(sus) : 0,
3316 0, 0,
3317 inact ? atoi(inact) : 0,
3318 maxsi ? atoi(maxsi) : 0);
3319
3320 if (system(buf) != 0) {
3321 sigma_dut_print(dut, DUT_MSG_ERROR,
3322 "iwpriv addtspec request failed");
3323 send_resp(dut, conn, SIGMA_ERROR,
3324 "errorCode,Failed to execute addTspec command");
3325 return 0;
3326 }
3327
3328 sigma_dut_print(dut, DUT_MSG_INFO,
3329 "iwpriv addtspec request send");
3330
3331 /* Mapping handle to a TID */
3332 dut->tid_to_handle[atoi(tid)] = handle;
3333 } else if (strcasecmp(act, "delts") == 0) {
3334 if (tid == NULL)
3335 return -1;
3336
3337 if (atoi(tid) < 0 || atoi(tid) > 7) {
3338 sigma_dut_print(dut, DUT_MSG_ERROR,
3339 "TID %s not supported", tid);
3340 send_resp(dut, conn, SIGMA_ERROR,
3341 "errorCode,Unsupported TID");
3342 return 0;
3343 }
3344
3345 handle = dut->tid_to_handle[atoi(tid)];
3346
3347 if (handle < 7000 || handle > 7255) {
3348 /* Invalid handle ie no mapping for that TID */
3349 sigma_dut_print(dut, DUT_MSG_ERROR,
3350 "handle-> %d not found", handle);
3351 }
3352
3353 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3354 intf, handle);
3355
3356 if (system(buf) != 0) {
3357 sigma_dut_print(dut, DUT_MSG_ERROR,
3358 "iwpriv deltspec request failed");
3359 send_resp(dut, conn, SIGMA_ERROR,
3360 "errorCode,Failed to execute delTspec command");
3361 return 0;
3362 }
3363
3364 sigma_dut_print(dut, DUT_MSG_INFO,
3365 "iwpriv deltspec request send");
3366
3367 dut->tid_to_handle[atoi(tid)] = 0;
3368 } else {
3369 sigma_dut_print(dut, DUT_MSG_ERROR,
3370 "Action type %s not supported", act);
3371 send_resp(dut, conn, SIGMA_ERROR,
3372 "errorCode,Unsupported Action");
3373 return 0;
3374 }
3375
3376 return 1;
3377}
3378
3379
vamsi krishna52e16f92017-08-29 12:37:34 +05303380static int find_network(struct sigma_dut *dut, const char *ssid)
3381{
3382 char list[4096];
3383 char *pos;
3384
3385 sigma_dut_print(dut, DUT_MSG_DEBUG,
3386 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003387 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303388 list, sizeof(list)) < 0)
3389 return -1;
3390 pos = strstr(list, ssid);
3391 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3392 return -1;
3393
3394 while (pos > list && pos[-1] != '\n')
3395 pos--;
3396 dut->infra_network_id = atoi(pos);
3397 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3398 return 0;
3399}
3400
3401
Sunil Dutt44595082018-02-12 19:41:45 +05303402#ifdef NL80211_SUPPORT
3403static int sta_config_rsnie(struct sigma_dut *dut, int val)
3404{
3405 struct nl_msg *msg;
3406 int ret;
3407 struct nlattr *params;
3408 int ifindex;
3409
3410 ifindex = if_nametoindex("wlan0");
3411 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3412 NL80211_CMD_VENDOR)) ||
3413 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3414 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3415 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3416 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
3417 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3418 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) {
3419 sigma_dut_print(dut, DUT_MSG_ERROR,
3420 "%s: err in adding vendor_cmd and vendor_data",
3421 __func__);
3422 nlmsg_free(msg);
3423 return -1;
3424 }
3425 nla_nest_end(msg, params);
3426
3427 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3428 if (ret) {
3429 sigma_dut_print(dut, DUT_MSG_ERROR,
3430 "%s: err in send_and_recv_msgs, ret=%d",
3431 __func__, ret);
3432 return ret;
3433 }
3434
3435 return 0;
3436}
3437#endif /* NL80211_SUPPORT */
3438
3439
Jouni Malinenf7222712019-06-13 01:50:21 +03003440static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3441 struct sigma_conn *conn,
3442 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003443{
3444 /* const char *intf = get_param(cmd, "Interface"); */
3445 const char *ssid = get_param(cmd, "ssid");
3446 const char *wps_param = get_param(cmd, "WPS");
3447 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003448 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003449 const char *network_mode = get_param(cmd, "network_mode");
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303450 const char *ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003451 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003452 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003453 int e;
3454 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3455 struct wpa_ctrl *ctrl = NULL;
3456 int num_network_not_found = 0;
3457 int num_disconnected = 0;
3458 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003459
3460 if (ssid == NULL)
3461 return -1;
3462
Jouni Malinen37d5c692019-08-19 16:56:55 +03003463 dut->server_cert_tod = 0;
3464
Jouni Malinen3c367e82017-06-23 17:01:47 +03003465 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303466#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003467 if (get_driver_type(dut) == DRIVER_WCN) {
Sunil Dutt44595082018-02-12 19:41:45 +05303468 sta_config_rsnie(dut, 1);
3469 dut->config_rsnie = 1;
3470 }
3471#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003472 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3473 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003474 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03003475 send_resp(dut, conn, SIGMA_ERROR,
3476 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3477 return 0;
3478 }
3479 }
3480
Jouni Malinen68143132017-09-02 02:34:08 +03003481 if (dut->sae_commit_override) {
3482 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3483 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003484 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03003485 send_resp(dut, conn, SIGMA_ERROR,
3486 "ErrorCode,Failed to set SAE commit override");
3487 return 0;
3488 }
3489 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303490#ifdef ANDROID
3491 if (dut->fils_hlp)
3492 process_fils_hlp(dut);
3493#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003494
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003495 if (wps_param &&
3496 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3497 wps = 1;
3498
Vamsi Krishnac1633d22020-05-06 18:31:21 +05303499 if (dut->ocvc &&
3500 set_network(get_station_ifname(dut), dut->infra_network_id,
3501 "ocv", "1") < 0)
3502 return ERROR_SEND_STATUS;
3503
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003504 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003505 if (dut->program == PROGRAM_60GHZ && network_mode &&
3506 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003507 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003508 "pbss", "1") < 0)
3509 return -2;
3510
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003511 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3512 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3513 "parameters not yet set");
3514 return 0;
3515 }
3516 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003517 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003518 return -2;
3519 } else {
3520 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3521 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003522 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003523 return -2;
3524 }
3525 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303526 if (strcmp(ssid, dut->infra_ssid) == 0) {
3527 sigma_dut_print(dut, DUT_MSG_DEBUG,
3528 "sta_associate for the most recently added network");
3529 } else if (find_network(dut, ssid) < 0) {
3530 sigma_dut_print(dut, DUT_MSG_DEBUG,
3531 "sta_associate for a previously stored network profile");
3532 send_resp(dut, conn, SIGMA_ERROR,
3533 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003534 return 0;
3535 }
3536
3537 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003538 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003539 "bssid", bssid) < 0) {
3540 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3541 "Invalid bssid argument");
3542 return 0;
3543 }
3544
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303545 if ((dut->program == PROGRAM_WPA3 &&
3546 dut->sta_associate_wait_connect) ||
3547 dut->program == PROGRAM_QM) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003548 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003549 if (!ctrl)
3550 return ERROR_SEND_STATUS;
3551 }
3552
Jouni Malinen46a19b62017-06-23 14:31:27 +03003553 extra[0] = '\0';
3554 if (chan)
3555 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003556 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003557 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3558 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003559 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003560 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3561 "network id %d on %s",
3562 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003563 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003564 ret = ERROR_SEND_STATUS;
3565 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003566 }
3567 }
3568
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003569 if (!ctrl)
3570 return SUCCESS_SEND_STATUS;
3571
3572 /* Wait for connection result to be able to store server certificate
3573 * hash for trust root override testing
3574 * (dev_exec_action,ServerCertTrust). */
3575
3576 for (e = 0; e < 20; e++) {
3577 const char *events[] = {
3578 "CTRL-EVENT-EAP-PEER-CERT",
3579 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3580 "CTRL-EVENT-DISCONNECTED",
3581 "CTRL-EVENT-CONNECTED",
3582 "CTRL-EVENT-NETWORK-NOT-FOUND",
3583 NULL
3584 };
3585 char buf[1024];
3586 int res;
3587
3588 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3589 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02003590 send_resp(dut, conn, SIGMA_COMPLETE,
3591 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003592 ret = STATUS_SENT_ERROR;
3593 break;
3594 }
3595 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3596 buf);
3597
3598 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3599 strstr(buf, " depth=0")) {
3600 char *pos = strstr(buf, " hash=");
3601
3602 if (pos) {
3603 char *end;
3604
Jouni Malinen34b19cb2019-08-16 16:37:17 +03003605 if (strstr(buf, " tod=1"))
3606 tod = 1;
3607 else if (strstr(buf, " tod=2"))
3608 tod = 2;
3609 else
3610 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003611 sigma_dut_print(dut, DUT_MSG_DEBUG,
3612 "Server certificate TOD policy: %d",
3613 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03003614 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003615
3616 pos += 6;
3617 end = strchr(pos, ' ');
3618 if (end)
3619 *end = '\0';
3620 strlcpy(dut->server_cert_hash, pos,
3621 sizeof(dut->server_cert_hash));
3622 sigma_dut_print(dut, DUT_MSG_DEBUG,
3623 "Server certificate hash: %s",
3624 dut->server_cert_hash);
3625 }
3626 }
3627
3628 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3629 send_resp(dut, conn, SIGMA_COMPLETE,
3630 "Result,TLS server certificate validation failed");
3631 ret = STATUS_SENT_ERROR;
3632 break;
3633 }
3634
3635 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3636 num_network_not_found++;
3637
3638 if (num_network_not_found > 2) {
3639 send_resp(dut, conn, SIGMA_COMPLETE,
3640 "Result,Network not found");
3641 ret = STATUS_SENT_ERROR;
3642 break;
3643 }
3644 }
3645
3646 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3647 num_disconnected++;
3648
3649 if (num_disconnected > 2) {
3650 send_resp(dut, conn, SIGMA_COMPLETE,
3651 "Result,Connection failed");
3652 ret = STATUS_SENT_ERROR;
3653 break;
3654 }
3655 }
3656
3657 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3658 if (tod >= 0) {
3659 sigma_dut_print(dut, DUT_MSG_DEBUG,
3660 "Network profile TOD policy update: %d -> %d",
3661 dut->sta_tod_policy, tod);
3662 dut->sta_tod_policy = tod;
3663 }
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303664 if (dut->program == PROGRAM_QM) {
3665 unsigned char iface_mac_addr[ETH_ALEN];
3666 char ipv6[100];
3667
3668 if (get_hwaddr(ifname, iface_mac_addr) < 0) {
3669 sigma_dut_print(dut, DUT_MSG_ERROR,
3670 "%s: get_hwaddr %s failed",
3671 __func__, ifname);
3672 ret = ERROR_SEND_STATUS;
3673 break;
3674 }
3675
3676 convert_mac_addr_to_ipv6_lladdr(iface_mac_addr,
3677 ipv6,
3678 sizeof(ipv6));
3679
3680 if (set_ipv6_addr(dut, ipv6, "64", ifname) !=
3681 0) {
3682 ret = ERROR_SEND_STATUS;
3683 break;
3684 }
3685 }
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003686 break;
3687 }
3688 }
3689done:
3690 if (ctrl) {
3691 wpa_ctrl_detach(ctrl);
3692 wpa_ctrl_close(ctrl);
3693 }
3694 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003695}
3696
3697
3698static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3699{
3700 char buf[500], cmd[200];
3701 int res;
3702
3703 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3704 * default path */
3705 res = snprintf(cmd, sizeof(cmd),
3706 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3707 file_exists("./hs20-osu-client") ?
3708 "./hs20-osu-client" : "hs20-osu-client",
3709 sigma_wpas_ctrl,
3710 dut->summary_log ? "-s " : "",
3711 dut->summary_log ? dut->summary_log : "");
3712 if (res < 0 || res >= (int) sizeof(cmd))
3713 return -1;
3714
3715 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3716 if (res < 0 || res >= (int) sizeof(buf))
3717 return -1;
3718 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3719
3720 if (system(buf) != 0) {
3721 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3722 return -1;
3723 }
3724 sigma_dut_print(dut, DUT_MSG_DEBUG,
3725 "Completed hs20-osu-client operation");
3726
3727 return 0;
3728}
3729
3730
3731static int download_ppsmo(struct sigma_dut *dut,
3732 struct sigma_conn *conn,
3733 const char *intf,
3734 struct sigma_cmd *cmd)
3735{
3736 const char *name, *path, *val;
3737 char url[500], buf[600], fbuf[100];
3738 char *fqdn = NULL;
3739
3740 name = get_param(cmd, "FileName");
3741 path = get_param(cmd, "FilePath");
3742 if (name == NULL || path == NULL)
3743 return -1;
3744
3745 if (strcasecmp(path, "VendorSpecific") == 0) {
3746 snprintf(url, sizeof(url), "PPS/%s", name);
3747 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3748 "from the device (%s)", url);
3749 if (!file_exists(url)) {
3750 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3751 "PPS MO file does not exist");
3752 return 0;
3753 }
3754 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3755 if (system(buf) != 0) {
3756 send_resp(dut, conn, SIGMA_ERROR,
3757 "errorCode,Failed to copy PPS MO");
3758 return 0;
3759 }
3760 } else if (strncasecmp(path, "http:", 5) != 0 &&
3761 strncasecmp(path, "https:", 6) != 0) {
3762 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3763 "Unsupported FilePath value");
3764 return 0;
3765 } else {
3766 snprintf(url, sizeof(url), "%s/%s", path, name);
3767 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3768 url);
3769 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3770 remove("pps-tnds.xml");
3771 if (system(buf) != 0) {
3772 send_resp(dut, conn, SIGMA_ERROR,
3773 "errorCode,Failed to download PPS MO");
3774 return 0;
3775 }
3776 }
3777
3778 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3779 send_resp(dut, conn, SIGMA_ERROR,
3780 "errorCode,Failed to parse downloaded PPSMO");
3781 return 0;
3782 }
3783 unlink("pps-tnds.xml");
3784
3785 val = get_param(cmd, "managementTreeURI");
3786 if (val) {
3787 const char *pos, *end;
3788 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3789 val);
3790 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3791 send_resp(dut, conn, SIGMA_ERROR,
3792 "errorCode,Invalid managementTreeURI prefix");
3793 return 0;
3794 }
3795 pos = val + 8;
3796 end = strchr(pos, '/');
3797 if (end == NULL ||
3798 strcmp(end, "/PerProviderSubscription") != 0) {
3799 send_resp(dut, conn, SIGMA_ERROR,
3800 "errorCode,Invalid managementTreeURI postfix");
3801 return 0;
3802 }
3803 if (end - pos >= (int) sizeof(fbuf)) {
3804 send_resp(dut, conn, SIGMA_ERROR,
3805 "errorCode,Too long FQDN in managementTreeURI");
3806 return 0;
3807 }
3808 memcpy(fbuf, pos, end - pos);
3809 fbuf[end - pos] = '\0';
3810 fqdn = fbuf;
3811 sigma_dut_print(dut, DUT_MSG_INFO,
3812 "FQDN from managementTreeURI: %s", fqdn);
3813 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3814 FILE *f = fopen("pps-fqdn", "r");
3815 if (f) {
3816 if (fgets(fbuf, sizeof(fbuf), f)) {
3817 fbuf[sizeof(fbuf) - 1] = '\0';
3818 fqdn = fbuf;
3819 sigma_dut_print(dut, DUT_MSG_DEBUG,
3820 "Use FQDN %s", fqdn);
3821 }
3822 fclose(f);
3823 }
3824 }
3825
3826 if (fqdn == NULL) {
3827 send_resp(dut, conn, SIGMA_ERROR,
3828 "errorCode,No FQDN specified");
3829 return 0;
3830 }
3831
3832 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3833 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3834 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3835
3836 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3837 if (rename("pps.xml", buf) < 0) {
3838 send_resp(dut, conn, SIGMA_ERROR,
3839 "errorCode,Could not move PPS MO");
3840 return 0;
3841 }
3842
3843 if (strcasecmp(path, "VendorSpecific") == 0) {
3844 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3845 fqdn);
3846 if (system(buf)) {
3847 send_resp(dut, conn, SIGMA_ERROR,
3848 "errorCode,Failed to copy OSU CA cert");
3849 return 0;
3850 }
3851
3852 snprintf(buf, sizeof(buf),
3853 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3854 fqdn);
3855 if (system(buf)) {
3856 send_resp(dut, conn, SIGMA_ERROR,
3857 "errorCode,Failed to copy AAA CA cert");
3858 return 0;
3859 }
3860 } else {
3861 snprintf(buf, sizeof(buf),
3862 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3863 fqdn, fqdn);
3864 if (run_hs20_osu(dut, buf) < 0) {
3865 send_resp(dut, conn, SIGMA_ERROR,
3866 "errorCode,Failed to download OSU CA cert");
3867 return 0;
3868 }
3869
3870 snprintf(buf, sizeof(buf),
3871 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3872 fqdn, fqdn);
3873 if (run_hs20_osu(dut, buf) < 0) {
3874 sigma_dut_print(dut, DUT_MSG_INFO,
3875 "Failed to download AAA CA cert");
3876 }
3877 }
3878
3879 if (file_exists("next-client-cert.pem")) {
3880 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3881 if (rename("next-client-cert.pem", buf) < 0) {
3882 send_resp(dut, conn, SIGMA_ERROR,
3883 "errorCode,Could not move client certificate");
3884 return 0;
3885 }
3886 }
3887
3888 if (file_exists("next-client-key.pem")) {
3889 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3890 if (rename("next-client-key.pem", buf) < 0) {
3891 send_resp(dut, conn, SIGMA_ERROR,
3892 "errorCode,Could not move client key");
3893 return 0;
3894 }
3895 }
3896
3897 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3898 if (run_hs20_osu(dut, buf) < 0) {
3899 send_resp(dut, conn, SIGMA_ERROR,
3900 "errorCode,Failed to configure credential from "
3901 "PPSMO");
3902 return 0;
3903 }
3904
3905 return 1;
3906}
3907
3908
3909static int download_cert(struct sigma_dut *dut,
3910 struct sigma_conn *conn,
3911 const char *intf,
3912 struct sigma_cmd *cmd)
3913{
3914 const char *name, *path;
3915 char url[500], buf[600];
3916
3917 name = get_param(cmd, "FileName");
3918 path = get_param(cmd, "FilePath");
3919 if (name == NULL || path == NULL)
3920 return -1;
3921
3922 if (strcasecmp(path, "VendorSpecific") == 0) {
3923 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
3924 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3925 "certificate from the device (%s)", url);
3926 if (!file_exists(url)) {
3927 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3928 "certificate file does not exist");
3929 return 0;
3930 }
3931 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
3932 if (system(buf) != 0) {
3933 send_resp(dut, conn, SIGMA_ERROR,
3934 "errorCode,Failed to copy client "
3935 "certificate");
3936 return 0;
3937 }
3938
3939 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
3940 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3941 "private key from the device (%s)", url);
3942 if (!file_exists(url)) {
3943 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3944 "private key file does not exist");
3945 return 0;
3946 }
3947 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
3948 if (system(buf) != 0) {
3949 send_resp(dut, conn, SIGMA_ERROR,
3950 "errorCode,Failed to copy client key");
3951 return 0;
3952 }
3953 } else if (strncasecmp(path, "http:", 5) != 0 &&
3954 strncasecmp(path, "https:", 6) != 0) {
3955 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3956 "Unsupported FilePath value");
3957 return 0;
3958 } else {
3959 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
3960 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
3961 "certificate/key from %s", url);
3962 snprintf(buf, sizeof(buf),
3963 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
3964 if (system(buf) != 0) {
3965 send_resp(dut, conn, SIGMA_ERROR,
3966 "errorCode,Failed to download client "
3967 "certificate");
3968 return 0;
3969 }
3970
3971 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
3972 {
3973 send_resp(dut, conn, SIGMA_ERROR,
3974 "errorCode,Failed to copy client key");
3975 return 0;
3976 }
3977 }
3978
3979 return 1;
3980}
3981
3982
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003983static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
3984 struct sigma_conn *conn,
3985 struct sigma_cmd *cmd)
3986{
3987 const char *val;
3988 const char *intf = get_param(cmd, "interface");
3989
3990 if (!intf)
3991 return -1;
3992
3993 val = get_param(cmd, "WscIEFragment");
3994 if (val && strcasecmp(val, "enable") == 0) {
3995 sigma_dut_print(dut, DUT_MSG_DEBUG,
3996 "Enable WSC IE fragmentation");
3997
3998 dut->wsc_fragment = 1;
3999 /* set long attributes to force fragmentation */
4000 if (wpa_command(intf, "SET device_name "
4001 WPS_LONG_DEVICE_NAME) < 0)
4002 return -2;
4003 if (wpa_command(intf, "SET manufacturer "
4004 WPS_LONG_MANUFACTURER) < 0)
4005 return -2;
4006 if (wpa_command(intf, "SET model_name "
4007 WPS_LONG_MODEL_NAME) < 0)
4008 return -2;
4009 if (wpa_command(intf, "SET model_number "
4010 WPS_LONG_MODEL_NUMBER) < 0)
4011 return -2;
4012 if (wpa_command(intf, "SET serial_number "
4013 WPS_LONG_SERIAL_NUMBER) < 0)
4014 return -2;
4015 }
4016
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02004017 val = get_param(cmd, "RSN_IE");
4018 if (val) {
4019 if (strcasecmp(val, "disable") == 0)
4020 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
4021 else if (strcasecmp(val, "enable") == 0)
4022 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
4023 }
4024
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004025 val = get_param(cmd, "WpsVersion");
4026 if (val)
4027 dut->wps_forced_version = get_wps_forced_version(dut, val);
4028
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004029 val = get_param(cmd, "WscEAPFragment");
4030 if (val && strcasecmp(val, "enable") == 0)
4031 dut->eap_fragment = 1;
4032
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004033 return 1;
4034}
4035
4036
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004037static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4038 struct sigma_conn *conn,
4039 const char *intf,
4040 struct sigma_cmd *cmd)
4041{
4042 const char *val;
4043
4044 val = get_param(cmd, "FileType");
4045 if (val && strcasecmp(val, "PPSMO") == 0)
4046 return download_ppsmo(dut, conn, intf, cmd);
4047 if (val && strcasecmp(val, "CERT") == 0)
4048 return download_cert(dut, conn, intf, cmd);
4049 if (val) {
4050 send_resp(dut, conn, SIGMA_ERROR,
4051 "ErrorCode,Unsupported FileType");
4052 return 0;
4053 }
4054
4055 return 1;
4056}
4057
4058
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304059static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4060 struct sigma_conn *conn,
4061 const char *intf,
4062 struct sigma_cmd *cmd)
4063{
4064 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304065 char buf[1000];
4066 char text[20];
4067 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304068
4069 val = get_param(cmd, "OCESupport");
4070 if (val && strcasecmp(val, "Disable") == 0) {
4071 if (wpa_command(intf, "SET oce 0") < 0) {
4072 send_resp(dut, conn, SIGMA_ERROR,
4073 "ErrorCode,Failed to disable OCE");
4074 return 0;
4075 }
4076 } else if (val && strcasecmp(val, "Enable") == 0) {
4077 if (wpa_command(intf, "SET oce 1") < 0) {
4078 send_resp(dut, conn, SIGMA_ERROR,
4079 "ErrorCode,Failed to enable OCE");
4080 return 0;
4081 }
4082 }
4083
vamsi krishnaa2799492017-12-05 14:28:01 +05304084 val = get_param(cmd, "FILScap");
4085 if (val && (atoi(val) == 1)) {
4086 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4087 send_resp(dut, conn, SIGMA_ERROR,
4088 "ErrorCode,Failed to enable FILS");
4089 return 0;
4090 }
4091 } else if (val && (atoi(val) == 0)) {
4092 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4093 send_resp(dut, conn, SIGMA_ERROR,
4094 "ErrorCode,Failed to disable FILS");
4095 return 0;
4096 }
4097 }
4098
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304099 val = get_param(cmd, "FILSHLP");
4100 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004101 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304102 sizeof(text)) < 0)
4103 return -2;
4104 hwaddr_aton(text, addr);
4105 snprintf(buf, sizeof(buf),
4106 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4107 "080045100140000040004011399e00000000ffffffff00440043"
4108 "012cb30001010600fd4f46410000000000000000000000000000"
4109 "000000000000"
4110 "%02x%02x%02x%02x%02x%02x"
4111 "0000000000000000000000000000000000000000000000000000"
4112 "0000000000000000000000000000000000000000000000000000"
4113 "0000000000000000000000000000000000000000000000000000"
4114 "0000000000000000000000000000000000000000000000000000"
4115 "0000000000000000000000000000000000000000000000000000"
4116 "0000000000000000000000000000000000000000000000000000"
4117 "0000000000000000000000000000000000000000000000000000"
4118 "0000000000000000000000000000000000000000638253633501"
4119 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4120 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4121 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4122 if (wpa_command(intf, buf)) {
4123 send_resp(dut, conn, SIGMA_ERROR,
4124 "ErrorCode,Failed to add HLP");
4125 return 0;
4126 }
4127 dut->fils_hlp = 1;
4128 }
4129
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304130 return 1;
4131}
4132
4133
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004134static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4135 const char *val)
4136{
4137 int counter = 0;
4138 char token[50];
4139 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304140 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004141
Peng Xub8fc5cc2017-05-10 17:27:28 -07004142 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004143 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304144 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004145 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004146 if (strcmp(result, "disable") == 0)
4147 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4148 else
4149 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304150 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004151 counter++;
4152 }
4153}
4154
4155
4156static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4157 const char *val)
4158{
4159 char buf[100];
4160
4161 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4162 if (system(buf) != 0) {
4163 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4164 }
4165}
4166
4167
4168static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4169 const char *val)
4170{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004171 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004172 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004173 }
4174}
4175
4176
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004177static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4178 const char *val)
4179{
4180#ifdef NL80211_SUPPORT
4181 struct nl_msg *msg;
4182 int ret = 0;
4183 struct nlattr *params;
4184 int ifindex;
4185 int wmmenable = 1;
4186
4187 if (val &&
4188 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4189 wmmenable = 0;
4190
4191 ifindex = if_nametoindex(intf);
4192 if (ifindex == 0) {
4193 sigma_dut_print(dut, DUT_MSG_ERROR,
4194 "%s: Index for interface %s failed",
4195 __func__, intf);
4196 return -1;
4197 }
4198
4199 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4200 NL80211_CMD_VENDOR)) ||
4201 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4202 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4203 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4204 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4205 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4206 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4207 wmmenable)) {
4208 sigma_dut_print(dut, DUT_MSG_ERROR,
4209 "%s: err in adding vendor_cmd and vendor_data",
4210 __func__);
4211 nlmsg_free(msg);
4212 return -1;
4213 }
4214 nla_nest_end(msg, params);
4215
4216 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4217 if (ret) {
4218 sigma_dut_print(dut, DUT_MSG_ERROR,
4219 "%s: err in send_and_recv_msgs, ret=%d",
4220 __func__, ret);
4221 }
4222 return ret;
4223#else /* NL80211_SUPPORT */
4224 sigma_dut_print(dut, DUT_MSG_ERROR,
4225 "WMM cannot be changed without NL80211_SUPPORT defined");
4226 return -1;
4227#endif /* NL80211_SUPPORT */
4228}
4229
4230
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004231static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4232 const char *val)
4233{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004234 int sgi20;
4235
4236 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4237
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004238 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004239}
4240
4241
4242static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4243 const char *val)
4244{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304245 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004246
4247 /* Disable Tx Beam forming when using a fixed rate */
4248 ath_disable_txbf(dut, intf);
4249
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304250 v = atoi(val);
4251 if (v < 0 || v > 32) {
4252 sigma_dut_print(dut, DUT_MSG_ERROR,
4253 "Invalid Fixed MCS rate: %d", v);
4254 return;
4255 }
4256 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004257
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004258 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004259
4260 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004261 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004262}
4263
4264
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004265static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4266 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004267{
4268 char buf[60];
4269
4270 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4271 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4272 else
4273 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4274
4275 if (system(buf) != 0)
4276 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4277}
4278
4279
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004280static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4281 int ampdu)
4282{
4283 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004284 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004285
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004286 if (ampdu)
4287 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004288 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4289 if (system(buf) != 0) {
4290 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4291 return -1;
4292 }
4293
4294 return 0;
4295}
4296
4297
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004298static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4299 const char *val)
4300{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004301 run_iwpriv(dut, intf, "tx_stbc %s", val);
4302 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004303}
4304
4305
4306static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4307 const char *val)
4308{
4309 char buf[60];
4310
Peng Xucc317ed2017-05-18 16:44:37 -07004311 if (strcmp(val, "160") == 0) {
4312 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4313 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004314 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4315 } else if (strcmp(val, "40") == 0) {
4316 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4317 } else if (strcmp(val, "20") == 0) {
4318 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4319 } else if (strcasecmp(val, "Auto") == 0) {
4320 buf[0] = '\0';
4321 } else {
4322 sigma_dut_print(dut, DUT_MSG_ERROR,
4323 "WIDTH/CTS_WIDTH value not supported");
4324 return -1;
4325 }
4326
4327 if (buf[0] != '\0' && system(buf) != 0) {
4328 sigma_dut_print(dut, DUT_MSG_ERROR,
4329 "Failed to set WIDTH/CTS_WIDTH");
4330 return -1;
4331 }
4332
4333 return 0;
4334}
4335
4336
4337int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4338 const char *intf, const char *val)
4339{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004340 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004341 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004342 dut->chwidth = 0;
4343 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004344 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004345 dut->chwidth = 0;
4346 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004347 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004348 dut->chwidth = 1;
4349 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004350 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004351 dut->chwidth = 2;
4352 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004353 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004354 dut->chwidth = 3;
4355 } else {
4356 send_resp(dut, conn, SIGMA_ERROR,
4357 "ErrorCode,WIDTH not supported");
4358 return -1;
4359 }
4360
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004361 return 0;
4362}
4363
4364
4365static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4366 const char *val)
4367{
4368 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004369 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004370
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004371 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004372 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004373 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004374 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004375 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004376 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004377 } else {
4378 sigma_dut_print(dut, DUT_MSG_ERROR,
4379 "SP_STREAM value not supported");
4380 return -1;
4381 }
4382
4383 if (system(buf) != 0) {
4384 sigma_dut_print(dut, DUT_MSG_ERROR,
4385 "Failed to set SP_STREAM");
4386 return -1;
4387 }
4388
Arif Hussainac6c5112018-05-25 17:34:00 -07004389 dut->sta_nss = sta_nss;
4390
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004391 return 0;
4392}
4393
4394
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304395static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4396 const char *val)
4397{
4398 char buf[60];
4399
4400 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
4401 if (system(buf) != 0)
4402 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4403
4404 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
4405 if (system(buf) != 0)
4406 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4407}
4408
4409
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304410static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4411 struct sigma_conn *conn,
4412 const char *intf, int capa)
4413{
4414 char buf[32];
4415
4416 if (capa > 0 && capa < 4) {
4417 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4418 if (wpa_command(intf, buf) < 0) {
4419 send_resp(dut, conn, SIGMA_ERROR,
4420 "ErrorCode, Failed to set cellular data capability");
4421 return 0;
4422 }
4423 return 1;
4424 }
4425
4426 sigma_dut_print(dut, DUT_MSG_ERROR,
4427 "Invalid Cellular data capability: %d", capa);
4428 send_resp(dut, conn, SIGMA_INVALID,
4429 "ErrorCode,Invalid cellular data capability");
4430 return 0;
4431}
4432
4433
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304434static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4435 const char *intf, const char *val)
4436{
4437 if (strcasecmp(val, "Disable") == 0) {
4438 if (wpa_command(intf, "SET roaming 0") < 0) {
4439 send_resp(dut, conn, SIGMA_ERROR,
4440 "ErrorCode,Failed to disable roaming");
4441 return 0;
4442 }
4443 return 1;
4444 }
4445
4446 if (strcasecmp(val, "Enable") == 0) {
4447 if (wpa_command(intf, "SET roaming 1") < 0) {
4448 send_resp(dut, conn, SIGMA_ERROR,
4449 "ErrorCode,Failed to enable roaming");
4450 return 0;
4451 }
4452 return 1;
4453 }
4454
4455 sigma_dut_print(dut, DUT_MSG_ERROR,
4456 "Invalid value provided for roaming: %s", val);
4457 send_resp(dut, conn, SIGMA_INVALID,
4458 "ErrorCode,Unknown value provided for Roaming");
4459 return 0;
4460}
4461
4462
Ashwini Patila75de5a2017-04-13 16:35:05 +05304463static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4464 struct sigma_conn *conn,
4465 const char *intf, const char *val)
4466{
4467 if (strcasecmp(val, "Disable") == 0) {
4468 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4469 send_resp(dut, conn, SIGMA_ERROR,
4470 "ErrorCode,Failed to disable Assoc_disallow");
4471 return 0;
4472 }
4473 return 1;
4474 }
4475
4476 if (strcasecmp(val, "Enable") == 0) {
4477 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4478 send_resp(dut, conn, SIGMA_ERROR,
4479 "ErrorCode,Failed to enable Assoc_disallow");
4480 return 0;
4481 }
4482 return 1;
4483 }
4484
4485 sigma_dut_print(dut, DUT_MSG_ERROR,
4486 "Invalid value provided for Assoc_disallow: %s", val);
4487 send_resp(dut, conn, SIGMA_INVALID,
4488 "ErrorCode,Unknown value provided for Assoc_disallow");
4489 return 0;
4490}
4491
4492
Ashwini Patilc63161e2017-04-13 16:30:23 +05304493static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4494 const char *intf, const char *val)
4495{
4496 if (strcasecmp(val, "Reject") == 0) {
4497 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4498 send_resp(dut, conn, SIGMA_ERROR,
4499 "ErrorCode,Failed to Reject BTM Request");
4500 return 0;
4501 }
4502 return 1;
4503 }
4504
4505 if (strcasecmp(val, "Accept") == 0) {
4506 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4507 send_resp(dut, conn, SIGMA_ERROR,
4508 "ErrorCode,Failed to Accept BTM Request");
4509 return 0;
4510 }
4511 return 1;
4512 }
4513
4514 sigma_dut_print(dut, DUT_MSG_ERROR,
4515 "Invalid value provided for BSS_Transition: %s", val);
4516 send_resp(dut, conn, SIGMA_INVALID,
4517 "ErrorCode,Unknown value provided for BSS_Transition");
4518 return 0;
4519}
4520
4521
Ashwini Patil00402582017-04-13 12:29:39 +05304522static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4523 struct sigma_conn *conn,
4524 const char *intf,
4525 struct sigma_cmd *cmd)
4526{
4527 const char *ch, *pref, *op_class, *reason;
4528 char buf[120];
4529 int len, ret;
4530
4531 pref = get_param(cmd, "Ch_Pref");
4532 if (!pref)
4533 return 1;
4534
4535 if (strcasecmp(pref, "clear") == 0) {
4536 free(dut->non_pref_ch_list);
4537 dut->non_pref_ch_list = NULL;
4538 } else {
4539 op_class = get_param(cmd, "Ch_Op_Class");
4540 if (!op_class) {
4541 send_resp(dut, conn, SIGMA_INVALID,
4542 "ErrorCode,Ch_Op_Class not provided");
4543 return 0;
4544 }
4545
4546 ch = get_param(cmd, "Ch_Pref_Num");
4547 if (!ch) {
4548 send_resp(dut, conn, SIGMA_INVALID,
4549 "ErrorCode,Ch_Pref_Num not provided");
4550 return 0;
4551 }
4552
4553 reason = get_param(cmd, "Ch_Reason_Code");
4554 if (!reason) {
4555 send_resp(dut, conn, SIGMA_INVALID,
4556 "ErrorCode,Ch_Reason_Code not provided");
4557 return 0;
4558 }
4559
4560 if (!dut->non_pref_ch_list) {
4561 dut->non_pref_ch_list =
4562 calloc(1, NON_PREF_CH_LIST_SIZE);
4563 if (!dut->non_pref_ch_list) {
4564 send_resp(dut, conn, SIGMA_ERROR,
4565 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4566 return 0;
4567 }
4568 }
4569 len = strlen(dut->non_pref_ch_list);
4570 ret = snprintf(dut->non_pref_ch_list + len,
4571 NON_PREF_CH_LIST_SIZE - len,
4572 " %s:%s:%s:%s", op_class, ch, pref, reason);
4573 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4574 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4575 dut->non_pref_ch_list);
4576 } else {
4577 sigma_dut_print(dut, DUT_MSG_ERROR,
4578 "snprintf failed for non_pref_list, ret = %d",
4579 ret);
4580 send_resp(dut, conn, SIGMA_ERROR,
4581 "ErrorCode,snprintf failed");
4582 free(dut->non_pref_ch_list);
4583 dut->non_pref_ch_list = NULL;
4584 return 0;
4585 }
4586 }
4587
4588 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4589 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4590 if (ret < 0 || ret >= (int) sizeof(buf)) {
4591 sigma_dut_print(dut, DUT_MSG_DEBUG,
4592 "snprintf failed for set non_pref_chan, ret: %d",
4593 ret);
4594 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4595 return 0;
4596 }
4597
4598 if (wpa_command(intf, buf) < 0) {
4599 send_resp(dut, conn, SIGMA_ERROR,
4600 "ErrorCode,Failed to set non-preferred channel list");
4601 return 0;
4602 }
4603
4604 return 1;
4605}
4606
4607
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004608#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004609
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004610static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4611 uint8_t cfg)
4612{
4613 struct nl_msg *msg;
4614 int ret = 0;
4615 struct nlattr *params;
4616 int ifindex;
4617
4618 ifindex = if_nametoindex(intf);
4619 if (ifindex == 0) {
4620 sigma_dut_print(dut, DUT_MSG_ERROR,
4621 "%s: Index for interface %s failed",
4622 __func__, intf);
4623 return -1;
4624 }
4625
4626 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4627 NL80211_CMD_VENDOR)) ||
4628 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4629 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4630 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4631 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4632 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4633 nla_put_u8(msg,
4634 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4635 cfg)) {
4636 sigma_dut_print(dut, DUT_MSG_ERROR,
4637 "%s: err in adding vendor_cmd and vendor_data",
4638 __func__);
4639 nlmsg_free(msg);
4640 return -1;
4641 }
4642 nla_nest_end(msg, params);
4643
4644 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4645 if (ret) {
4646 sigma_dut_print(dut, DUT_MSG_ERROR,
4647 "%s: err in send_and_recv_msgs, ret=%d",
4648 __func__, ret);
4649 }
4650 return ret;
4651}
4652
4653
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004654static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4655 enum he_fragmentation_val frag)
4656{
4657 struct nl_msg *msg;
4658 int ret = 0;
4659 struct nlattr *params;
4660 int ifindex;
4661
4662 ifindex = if_nametoindex(intf);
4663 if (ifindex == 0) {
4664 sigma_dut_print(dut, DUT_MSG_ERROR,
4665 "%s: Index for interface %s failed",
4666 __func__, intf);
4667 return -1;
4668 }
4669
4670 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4671 NL80211_CMD_VENDOR)) ||
4672 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4673 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4674 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4675 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4676 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4677 nla_put_u8(msg,
4678 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
4679 frag)) {
4680 sigma_dut_print(dut, DUT_MSG_ERROR,
4681 "%s: err in adding vendor_cmd and vendor_data",
4682 __func__);
4683 nlmsg_free(msg);
4684 return -1;
4685 }
4686 nla_nest_end(msg, params);
4687
4688 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4689 if (ret) {
4690 sigma_dut_print(dut, DUT_MSG_ERROR,
4691 "%s: err in send_and_recv_msgs, ret=%d",
4692 __func__, ret);
4693 }
4694 return ret;
4695}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004696
4697
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08004698int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
4699 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004700{
4701 struct nl_msg *msg;
4702 int ret = 0;
4703 struct nlattr *params;
4704 int ifindex;
4705
4706 ifindex = if_nametoindex(intf);
4707 if (ifindex == 0) {
4708 sigma_dut_print(dut, DUT_MSG_ERROR,
4709 "%s: Index for interface %s failed",
4710 __func__, intf);
4711 return -1;
4712 }
4713
4714 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4715 NL80211_CMD_VENDOR)) ||
4716 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4717 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4718 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4719 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4720 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4721 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
4722 ltf)) {
4723 sigma_dut_print(dut, DUT_MSG_ERROR,
4724 "%s: err in adding vendor_cmd and vendor_data",
4725 __func__);
4726 nlmsg_free(msg);
4727 return -1;
4728 }
4729 nla_nest_end(msg, params);
4730
4731 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4732 if (ret) {
4733 sigma_dut_print(dut, DUT_MSG_ERROR,
4734 "%s: err in send_and_recv_msgs, ret=%d",
4735 __func__, ret);
4736 }
4737 return ret;
4738}
4739
4740
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004741static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4742 int noack, enum qca_wlan_ac_type ac)
4743{
4744 struct nl_msg *msg;
4745 int ret = 0;
4746 struct nlattr *params;
4747 int ifindex;
4748
4749 ifindex = if_nametoindex(intf);
4750 if (ifindex == 0) {
4751 sigma_dut_print(dut, DUT_MSG_ERROR,
4752 "%s: Index for interface %s failed",
4753 __func__, intf);
4754 return -1;
4755 }
4756
4757 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4758 NL80211_CMD_VENDOR)) ||
4759 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4760 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4761 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4762 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4763 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4764 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4765 noack) ||
4766 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4767 ac)) {
4768 sigma_dut_print(dut, DUT_MSG_ERROR,
4769 "%s: err in adding vendor_cmd and vendor_data",
4770 __func__);
4771 nlmsg_free(msg);
4772 return -1;
4773 }
4774 nla_nest_end(msg, params);
4775
4776 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4777 if (ret) {
4778 sigma_dut_print(dut, DUT_MSG_ERROR,
4779 "%s: err in send_and_recv_msgs, ret=%d",
4780 __func__, ret);
4781 }
4782 return ret;
4783}
4784
4785
4786static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4787 const char *val)
4788{
4789 int noack, ret;
4790 char token[100];
4791 char *result;
4792 char *saveptr;
4793 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4794
4795 strlcpy(token, val, sizeof(token));
4796 token[sizeof(token) - 1] = '\0';
4797 result = strtok_r(token, ":", &saveptr);
4798 while (result) {
4799 noack = strcasecmp(result, "Disable") != 0;
4800 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4801 if (ret) {
4802 sigma_dut_print(dut, DUT_MSG_ERROR,
4803 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4804 ac, ret);
4805 }
4806 result = strtok_r(NULL, ":", &saveptr);
4807 ac++;
4808 }
4809}
4810
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004811#endif /* NL80211_SUPPORT */
4812
4813
Jouni Malinenf7222712019-06-13 01:50:21 +03004814static enum sigma_cmd_result
4815cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
4816 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004817{
4818 const char *intf = get_param(cmd, "Interface");
4819 const char *val;
4820
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03004821 val = get_param(cmd, "FT_DS");
4822 if (val) {
4823 if (strcasecmp(val, "Enable") == 0) {
4824 dut->sta_ft_ds = 1;
4825 } else if (strcasecmp(val, "Disable") == 0) {
4826 dut->sta_ft_ds = 0;
4827 } else {
4828 send_resp(dut, conn, SIGMA_ERROR,
4829 "errorCode,Unsupported value for FT_DS");
4830 return STATUS_SENT_ERROR;
4831 }
4832 }
4833
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004834 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03004835 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
4836 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004837 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
4838 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004839
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004840 if (val && strcasecmp(val, "LOC") == 0)
4841 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02004842 if (val && strcasecmp(val, "60GHZ") == 0) {
4843 val = get_param(cmd, "WPS");
4844 if (val && strcasecmp(val, "disable") == 0) {
4845 dut->wps_disable = 1;
4846 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
4847 } else {
4848 /* wps_disable can have other value from the previous
4849 * test, so make sure it has the correct value.
4850 */
4851 dut->wps_disable = 0;
4852 }
4853
4854 val = get_param(cmd, "P2P");
4855 if (val && strcasecmp(val, "disable") == 0)
4856 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
4857 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004858
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004859 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
4860 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
4861
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004862#ifdef ANDROID_NAN
4863 if (val && strcasecmp(val, "NAN") == 0)
4864 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
4865#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004866#ifdef MIRACAST
4867 if (val && (strcasecmp(val, "WFD") == 0 ||
4868 strcasecmp(val, "DisplayR2") == 0))
4869 return miracast_preset_testparameters(dut, conn, cmd);
4870#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004871
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304872 if (val && strcasecmp(val, "MBO") == 0) {
4873 val = get_param(cmd, "Cellular_Data_Cap");
4874 if (val &&
4875 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
4876 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05304877
4878 val = get_param(cmd, "Ch_Pref");
4879 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
4880 return 0;
4881
Ashwini Patilc63161e2017-04-13 16:30:23 +05304882 val = get_param(cmd, "BSS_Transition");
4883 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
4884 return 0;
4885
Ashwini Patila75de5a2017-04-13 16:35:05 +05304886 val = get_param(cmd, "Assoc_Disallow");
4887 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
4888 return 0;
4889
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304890 val = get_param(cmd, "Roaming");
4891 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
4892 return 0;
4893
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304894 return 1;
4895 }
4896
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304897 if (val && strcasecmp(val, "OCE") == 0)
4898 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
4899
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004900#if 0
4901 val = get_param(cmd, "Supplicant");
4902 if (val && strcasecmp(val, "Default") != 0) {
4903 send_resp(dut, conn, SIGMA_ERROR,
4904 "ErrorCode,Only default(Vendor) supplicant "
4905 "supported");
4906 return 0;
4907 }
4908#endif
4909
4910 val = get_param(cmd, "RTS");
4911 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004912 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004913 case DRIVER_ATHEROS:
4914 ath_sta_set_rts(dut, intf, val);
4915 break;
4916 default:
4917#if 0
4918 send_resp(dut, conn, SIGMA_ERROR,
4919 "ErrorCode,Setting RTS not supported");
4920 return 0;
4921#else
4922 sigma_dut_print(dut, DUT_MSG_DEBUG,
4923 "Setting RTS not supported");
4924 break;
4925#endif
4926 }
4927 }
4928
4929#if 0
4930 val = get_param(cmd, "FRGMNT");
4931 if (val) {
4932 /* TODO */
4933 send_resp(dut, conn, SIGMA_ERROR,
4934 "ErrorCode,Setting FRGMNT not supported");
4935 return 0;
4936 }
4937#endif
4938
4939#if 0
4940 val = get_param(cmd, "Preamble");
4941 if (val) {
4942 /* TODO: Long/Short */
4943 send_resp(dut, conn, SIGMA_ERROR,
4944 "ErrorCode,Setting Preamble not supported");
4945 return 0;
4946 }
4947#endif
4948
4949 val = get_param(cmd, "Mode");
4950 if (val) {
4951 if (strcmp(val, "11b") == 0 ||
4952 strcmp(val, "11g") == 0 ||
4953 strcmp(val, "11a") == 0 ||
4954 strcmp(val, "11n") == 0 ||
4955 strcmp(val, "11ng") == 0 ||
4956 strcmp(val, "11nl") == 0 ||
4957 strcmp(val, "11nl(nabg)") == 0 ||
4958 strcmp(val, "AC") == 0 ||
4959 strcmp(val, "11AC") == 0 ||
4960 strcmp(val, "11ac") == 0 ||
4961 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08004962 strcmp(val, "11an") == 0 ||
4963 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004964 /* STA supports all modes by default */
4965 } else {
4966 send_resp(dut, conn, SIGMA_ERROR,
4967 "ErrorCode,Setting Mode not supported");
4968 return 0;
4969 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004970
4971 /* Change the mode only in case of testbed for HE program
4972 * and for 11a and 11g modes only. */
4973 if (dut->program == PROGRAM_HE &&
4974 dut->device_type == STA_testbed) {
4975 int phymode;
4976 char buf[60];
4977
4978 if (strcmp(val, "11a") == 0) {
Amarnath Hullur Subramanyam94dfaf02018-03-02 19:26:57 -08004979 phymode = 1; /* IEEE80211_MODE_11A */
4980 } else if (strcmp(val, "11g") == 0) {
4981 phymode = 3; /* IEEE80211_MODE_11G */
4982 } else if (strcmp(val, "11b") == 0) {
4983 phymode = 2; /* IEEE80211_MODE_11B */
4984 } else if (strcmp(val, "11n") == 0 ||
4985 strcmp(val, "11nl") == 0 ||
4986 strcmp(val, "11nl(nabg)") == 0) {
4987 phymode = 22; /* IEEE80211_MODE_11AGN */
4988 } else if (strcmp(val, "11ng") == 0) {
4989 phymode = 13; /* IEEE80211_MODE_11NG_HT40 */
4990 } else if (strcmp(val, "AC") == 0 ||
4991 strcasecmp(val, "11AC") == 0) {
4992 phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */
4993 } else if (strcmp(val, "11na") == 0 ||
4994 strcasecmp(val, "11an") == 0) {
4995 phymode = 14; /* IEEE80211_MODE_11NA_HT40 */
4996 } else if (strcmp(val, "11ax") == 0) {
4997 phymode = 0; /* IEEE80211_MODE_AUTO */
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004998 } else {
4999 sigma_dut_print(dut, DUT_MSG_DEBUG,
5000 "Ignoring mode change for mode: %s",
5001 val);
5002 phymode = -1;
5003 }
5004 if (phymode != -1) {
5005 snprintf(buf, sizeof(buf),
5006 "iwpriv %s setphymode %d",
5007 intf, phymode);
5008 if (system(buf) != 0) {
5009 sigma_dut_print(dut, DUT_MSG_ERROR,
5010 "iwpriv setting of phymode failed");
5011 }
5012 }
5013 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005014 }
5015
5016 val = get_param(cmd, "wmm");
5017 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005018 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005019 case DRIVER_ATHEROS:
5020 ath_sta_set_wmm(dut, intf, val);
5021 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005022 case DRIVER_WCN:
5023 wcn_sta_set_wmm(dut, intf, val);
5024 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005025 default:
5026 sigma_dut_print(dut, DUT_MSG_DEBUG,
5027 "Setting wmm not supported");
5028 break;
5029 }
5030 }
5031
5032 val = get_param(cmd, "Powersave");
5033 if (val) {
5034 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005035 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305036 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005037 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005038 }
5039
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005040 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005041 "P2P_SET ps 0") < 0)
5042 return -2;
5043 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005044 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5045 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005046 } else if (strcmp(val, "1") == 0 ||
5047 strcasecmp(val, "PSPoll") == 0 ||
5048 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005049 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305050 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005051 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005052 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005053 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005054 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005055 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005056 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005057 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005058 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005059 "P2P_SET ps 99") < 0)
5060 return -2;
5061 } else if (strcmp(val, "2") == 0 ||
5062 strcasecmp(val, "Fast") == 0) {
5063 /* TODO */
5064 send_resp(dut, conn, SIGMA_ERROR,
5065 "ErrorCode,Powersave=Fast not supported");
5066 return 0;
5067 } else if (strcmp(val, "3") == 0 ||
5068 strcasecmp(val, "PSNonPoll") == 0) {
5069 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005070 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5071 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005072
5073 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005074 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005075 "P2P_SET ps 1") < 0)
5076 return -2;
5077 } else
5078 return -1;
5079 }
5080
5081 val = get_param(cmd, "NoAck");
5082 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005083 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005084 case DRIVER_ATHEROS:
5085 ath_sta_set_noack(dut, intf, val);
5086 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005087#ifdef NL80211_SUPPORT
5088 case DRIVER_WCN:
5089 wcn_sta_set_noack(dut, intf, val);
5090 break;
5091#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005092 default:
5093 send_resp(dut, conn, SIGMA_ERROR,
5094 "ErrorCode,Setting NoAck not supported");
5095 return 0;
5096 }
5097 }
5098
5099 val = get_param(cmd, "IgnoreChswitchProhibit");
5100 if (val) {
5101 /* TODO: Enabled/disabled */
5102 if (strcasecmp(val, "Enabled") == 0) {
5103 send_resp(dut, conn, SIGMA_ERROR,
5104 "ErrorCode,Enabling IgnoreChswitchProhibit "
5105 "not supported");
5106 return 0;
5107 }
5108 }
5109
5110 val = get_param(cmd, "TDLS");
5111 if (val) {
5112 if (strcasecmp(val, "Disabled") == 0) {
5113 if (wpa_command(intf, "SET tdls_disabled 1")) {
5114 send_resp(dut, conn, SIGMA_ERROR,
5115 "ErrorCode,Failed to disable TDLS");
5116 return 0;
5117 }
5118 } else if (strcasecmp(val, "Enabled") == 0) {
5119 if (wpa_command(intf, "SET tdls_disabled 0")) {
5120 send_resp(dut, conn, SIGMA_ERROR,
5121 "ErrorCode,Failed to enable TDLS");
5122 return 0;
5123 }
5124 } else {
5125 send_resp(dut, conn, SIGMA_ERROR,
5126 "ErrorCode,Unsupported TDLS value");
5127 return 0;
5128 }
5129 }
5130
5131 val = get_param(cmd, "TDLSmode");
5132 if (val) {
5133 if (strcasecmp(val, "Default") == 0) {
5134 wpa_command(intf, "SET tdls_testing 0");
5135 } else if (strcasecmp(val, "APProhibit") == 0) {
5136 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5137 send_resp(dut, conn, SIGMA_ERROR,
5138 "ErrorCode,Failed to enable ignore "
5139 "APProhibit TDLS mode");
5140 return 0;
5141 }
5142 } else if (strcasecmp(val, "HiLoMac") == 0) {
5143 /* STA should respond with TDLS setup req for a TDLS
5144 * setup req */
5145 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5146 send_resp(dut, conn, SIGMA_ERROR,
5147 "ErrorCode,Failed to enable HiLoMac "
5148 "TDLS mode");
5149 return 0;
5150 }
5151 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5152 /*
5153 * Since all security modes are enabled by default when
5154 * Sigma control is used, there is no need to do
5155 * anything here.
5156 */
5157 } else if (strcasecmp(val, "ExistLink") == 0) {
5158 /*
5159 * Since we allow new TDLS Setup Request even if there
5160 * is an existing link, nothing needs to be done for
5161 * this.
5162 */
5163 } else {
5164 /* TODO:
5165 * ExistLink: STA should send TDLS setup req even if
5166 * direct link already exists
5167 */
5168 send_resp(dut, conn, SIGMA_ERROR,
5169 "ErrorCode,Unsupported TDLSmode value");
5170 return 0;
5171 }
5172 }
5173
5174 val = get_param(cmd, "FakePubKey");
5175 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5176 send_resp(dut, conn, SIGMA_ERROR,
5177 "ErrorCode,Failed to enable FakePubKey");
5178 return 0;
5179 }
5180
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005181#ifdef NL80211_SUPPORT
5182 val = get_param(cmd, "FrgmntSupport");
5183 if (val) {
5184 if (strcasecmp(val, "Enable") == 0) {
5185 if (sta_set_he_fragmentation(dut, intf,
5186 HE_FRAG_LEVEL1)) {
5187 send_resp(dut, conn, SIGMA_ERROR,
5188 "ErrorCode,Failed to enable HE Fragmentation");
5189 return 0;
5190 }
5191 } else if (strcasecmp(val, "Disable") == 0) {
5192 if (sta_set_he_fragmentation(dut, intf,
5193 HE_FRAG_DISABLE)) {
5194 send_resp(dut, conn, SIGMA_ERROR,
5195 "ErrorCode,Failed to disable HE Fragmentation");
5196 return 0;
5197 }
5198 }
5199 }
5200#endif /* NL80211_SUPPORT */
5201
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005202 return 1;
5203}
5204
5205
5206static const char * ath_get_radio_name(const char *radio_name)
5207{
5208 if (radio_name == NULL)
5209 return "wifi0";
5210 if (strcmp(radio_name, "wifi1") == 0)
5211 return "wifi1";
5212 if (strcmp(radio_name, "wifi2") == 0)
5213 return "wifi2";
5214 return "wifi0";
5215}
5216
5217
5218static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5219 const char *val)
5220{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005221 unsigned int vht_mcsmap = 0;
5222 int txchainmask = 0;
5223 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5224
5225 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5226 if (dut->testbed_flag_txsp == 1) {
5227 vht_mcsmap = 0xfffc;
5228 dut->testbed_flag_txsp = 0;
5229 } else {
5230 vht_mcsmap = 0xfffe;
5231 }
5232 txchainmask = 1;
5233 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5234 if (dut->testbed_flag_txsp == 1) {
5235 vht_mcsmap = 0xfff0;
5236 dut->testbed_flag_txsp = 0;
5237 } else {
5238 vht_mcsmap = 0xfffa;
5239 }
5240 txchainmask = 3;
5241 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5242 if (dut->testbed_flag_txsp == 1) {
5243 vht_mcsmap = 0xffc0;
5244 dut->testbed_flag_txsp = 0;
5245 } else {
5246 vht_mcsmap = 0xffea;
5247 }
5248 txchainmask = 7;
5249 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5250 if (dut->testbed_flag_txsp == 1) {
5251 vht_mcsmap = 0xff00;
5252 dut->testbed_flag_txsp = 0;
5253 } else {
5254 vht_mcsmap = 0xffaa;
5255 }
5256 txchainmask = 15;
5257 } else {
5258 if (dut->testbed_flag_txsp == 1) {
5259 vht_mcsmap = 0xffc0;
5260 dut->testbed_flag_txsp = 0;
5261 } else {
5262 vht_mcsmap = 0xffea;
5263 }
5264 }
5265
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005266 if (txchainmask)
5267 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005268
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005269 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005270}
5271
5272
5273static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5274 const char *val)
5275{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005276 unsigned int vht_mcsmap = 0;
5277 int rxchainmask = 0;
5278 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5279
5280 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5281 if (dut->testbed_flag_rxsp == 1) {
5282 vht_mcsmap = 0xfffc;
5283 dut->testbed_flag_rxsp = 0;
5284 } else {
5285 vht_mcsmap = 0xfffe;
5286 }
5287 rxchainmask = 1;
5288 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5289 if (dut->testbed_flag_rxsp == 1) {
5290 vht_mcsmap = 0xfff0;
5291 dut->testbed_flag_rxsp = 0;
5292 } else {
5293 vht_mcsmap = 0xfffa;
5294 }
5295 rxchainmask = 3;
5296 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5297 if (dut->testbed_flag_rxsp == 1) {
5298 vht_mcsmap = 0xffc0;
5299 dut->testbed_flag_rxsp = 0;
5300 } else {
5301 vht_mcsmap = 0xffea;
5302 }
5303 rxchainmask = 7;
5304 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5305 if (dut->testbed_flag_rxsp == 1) {
5306 vht_mcsmap = 0xff00;
5307 dut->testbed_flag_rxsp = 0;
5308 } else {
5309 vht_mcsmap = 0xffaa;
5310 }
5311 rxchainmask = 15;
5312 } else {
5313 if (dut->testbed_flag_rxsp == 1) {
5314 vht_mcsmap = 0xffc0;
5315 dut->testbed_flag_rxsp = 0;
5316 } else {
5317 vht_mcsmap = 0xffea;
5318 }
5319 }
5320
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005321 if (rxchainmask)
5322 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005323
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005324 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005325}
5326
5327
5328void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5329{
5330 if (strcasecmp(val, "enable") == 0) {
5331 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5332 != 0) {
5333 sigma_dut_print(dut, DUT_MSG_ERROR,
5334 "Disable BB_VHTSIGB_CRC_CALC failed");
5335 }
5336
5337 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5338 != 0) {
5339 sigma_dut_print(dut, DUT_MSG_ERROR,
5340 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5341 }
5342 } else {
5343 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5344 != 0) {
5345 sigma_dut_print(dut, DUT_MSG_ERROR,
5346 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5347 }
5348
5349 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5350 != 0) {
5351 sigma_dut_print(dut, DUT_MSG_ERROR,
5352 "Enable BB_VHTSIGB_CRC_CALC failed");
5353 }
5354 }
5355}
5356
5357
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005358static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5359 const char *val)
5360{
5361 char buf[60];
5362
5363 if (strcmp(val, "20") == 0) {
5364 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5365 dut->chwidth = 0;
5366 } else if (strcmp(val, "40") == 0) {
5367 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5368 dut->chwidth = 1;
5369 } else if (strcmp(val, "80") == 0) {
5370 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5371 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305372 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005373 buf[0] = '\0';
5374 } else {
5375 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5376 val);
5377 return -1;
5378 }
5379
5380 if (buf[0] != '\0' && system(buf) != 0) {
5381 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5382 return -1;
5383 }
5384
5385 return 0;
5386}
5387
5388
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005389static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5390 const char *intf, int addbareject)
5391{
5392#ifdef NL80211_SUPPORT
5393 struct nl_msg *msg;
5394 int ret = 0;
5395 struct nlattr *params;
5396 int ifindex;
5397
5398 ifindex = if_nametoindex(intf);
5399 if (ifindex == 0) {
5400 sigma_dut_print(dut, DUT_MSG_ERROR,
5401 "%s: Index for interface %s failed",
5402 __func__, intf);
5403 return -1;
5404 }
5405
5406 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5407 NL80211_CMD_VENDOR)) ||
5408 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5409 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5410 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5411 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5412 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5413 nla_put_u8(msg,
5414 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5415 !addbareject)) {
5416 sigma_dut_print(dut, DUT_MSG_ERROR,
5417 "%s: err in adding vendor_cmd and vendor_data",
5418 __func__);
5419 nlmsg_free(msg);
5420 return -1;
5421 }
5422 nla_nest_end(msg, params);
5423
5424 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5425 if (ret) {
5426 sigma_dut_print(dut, DUT_MSG_ERROR,
5427 "%s: err in send_and_recv_msgs, ret=%d",
5428 __func__, ret);
5429 }
5430 return ret;
5431#else /* NL80211_SUPPORT */
5432 sigma_dut_print(dut, DUT_MSG_ERROR,
5433 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5434 return -1;
5435#endif /* NL80211_SUPPORT */
5436}
5437
5438
5439static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5440 int addbareject)
5441{
5442 int ret;
5443
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005444 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005445 case DRIVER_WCN:
5446 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5447 if (ret) {
5448 sigma_dut_print(dut, DUT_MSG_ERROR,
5449 "nlvendor_sta_set_addba_reject failed, ret:%d",
5450 ret);
5451 return ret;
5452 }
5453 break;
5454 default:
5455 sigma_dut_print(dut, DUT_MSG_ERROR,
5456 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5457 ret = -1;
5458 break;
5459 }
5460
5461 return ret;
5462}
5463
5464
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005465static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5466 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005467{
5468#ifdef NL80211_SUPPORT
5469 struct nl_msg *msg;
5470 int ret = 0;
5471 struct nlattr *params;
5472 int ifindex;
5473
5474 ifindex = if_nametoindex(intf);
5475 if (ifindex == 0) {
5476 sigma_dut_print(dut, DUT_MSG_ERROR,
5477 "%s: Index for interface %s failed",
5478 __func__, intf);
5479 return -1;
5480 }
5481
5482 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5483 NL80211_CMD_VENDOR)) ||
5484 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5485 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5486 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5487 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5488 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5489 nla_put_u8(msg,
5490 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005491 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005492 sigma_dut_print(dut, DUT_MSG_ERROR,
5493 "%s: err in adding vendor_cmd and vendor_data",
5494 __func__);
5495 nlmsg_free(msg);
5496 return -1;
5497 }
5498 nla_nest_end(msg, params);
5499
5500 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5501 if (ret) {
5502 sigma_dut_print(dut, DUT_MSG_ERROR,
5503 "%s: err in send_and_recv_msgs, ret=%d",
5504 __func__, ret);
5505 }
5506 return ret;
5507#else /* NL80211_SUPPORT */
5508 sigma_dut_print(dut, DUT_MSG_ERROR,
5509 "Disable addba not possible without NL80211_SUPPORT defined");
5510 return -1;
5511#endif /* NL80211_SUPPORT */
5512}
5513
5514
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305515#ifdef NL80211_SUPPORT
5516static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5517{
5518 struct nl_msg *msg;
5519 int ret = 0;
5520 int ifindex;
5521
5522 ifindex = if_nametoindex(intf);
5523 if (ifindex == 0) {
5524 sigma_dut_print(dut, DUT_MSG_ERROR,
5525 "%s: Index for interface %s failed",
5526 __func__, intf);
5527 return -1;
5528 }
5529
5530 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5531 NL80211_CMD_SET_WIPHY)) ||
5532 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5533 sigma_dut_print(dut, DUT_MSG_ERROR,
5534 "%s: err in adding RTS threshold",
5535 __func__);
5536 nlmsg_free(msg);
5537 return -1;
5538 }
5539
5540 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5541 if (ret) {
5542 sigma_dut_print(dut, DUT_MSG_ERROR,
5543 "%s: err in send_and_recv_msgs, ret=%d",
5544 __func__, ret);
5545 }
5546 return ret;
5547}
5548#endif /* NL80211_SUPPORT */
5549
5550
5551static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5552{
5553 char buf[100];
5554
5555#ifdef NL80211_SUPPORT
5556 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5557 return 0;
5558 sigma_dut_print(dut, DUT_MSG_DEBUG,
5559 "Fall back to using iwconfig for setting RTS threshold");
5560#endif /* NL80211_SUPPORT */
5561
5562 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5563 if (system(buf) != 0) {
5564 sigma_dut_print(dut, DUT_MSG_ERROR,
5565 "Failed to set RTS threshold %d", val);
5566 return -1;
5567 }
5568 return 0;
5569}
5570
5571
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005572static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5573 struct sigma_conn *conn,
5574 struct sigma_cmd *cmd)
5575{
5576 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005577 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005578 char buf[128];
5579 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005580
5581 val = get_param(cmd, "40_INTOLERANT");
5582 if (val) {
5583 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5584 /* TODO: iwpriv ht40intol through wpa_supplicant */
5585 send_resp(dut, conn, SIGMA_ERROR,
5586 "ErrorCode,40_INTOLERANT not supported");
5587 return 0;
5588 }
5589 }
5590
5591 val = get_param(cmd, "ADDBA_REJECT");
5592 if (val) {
5593 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5594 /* reject any ADDBA with status "decline" */
5595 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005596 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005597 } else {
5598 /* accept ADDBA */
5599 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005600 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005601 }
5602 }
5603
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005604 if (addbareject >= 0 &&
5605 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5606 send_resp(dut, conn, SIGMA_ERROR,
5607 "ErrorCode,set addba_reject failed");
5608 return 0;
5609 }
5610
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005611 val = get_param(cmd, "AMPDU");
5612 if (val) {
5613 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5614 /* enable AMPDU Aggregation */
5615 if (ampdu == 0) {
5616 send_resp(dut, conn, SIGMA_ERROR,
5617 "ErrorCode,Mismatch in "
5618 "addba_reject/ampdu - "
5619 "not supported");
5620 return 0;
5621 }
5622 ampdu = 1;
5623 } else {
5624 /* disable AMPDU Aggregation */
5625 if (ampdu == 1) {
5626 send_resp(dut, conn, SIGMA_ERROR,
5627 "ErrorCode,Mismatch in "
5628 "addba_reject/ampdu - "
5629 "not supported");
5630 return 0;
5631 }
5632 ampdu = 0;
5633 }
5634 }
5635
5636 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005637 int ret;
5638
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005639 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5640 ampdu ? "Enabling" : "Disabling");
5641 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005642 if (wpa_command(intf, buf) < 0 &&
5643 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005644 send_resp(dut, conn, SIGMA_ERROR,
5645 "ErrorCode,set aggr failed");
5646 return 0;
5647 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005648
5649 if (ampdu == 0) {
5650 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005651 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005652 if (ret) {
5653 sigma_dut_print(dut, DUT_MSG_ERROR,
5654 "Failed to disable addba, ret:%d",
5655 ret);
5656 }
5657 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005658 }
5659
5660 val = get_param(cmd, "AMSDU");
5661 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005662 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005663 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005664 case DRIVER_WCN:
5665 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005666 break;
5667 default:
5668 if (strcmp(val, "1") == 0 ||
5669 strcasecmp(val, "Enable") == 0) {
5670 /* Enable AMSDU Aggregation */
5671 send_resp(dut, conn, SIGMA_ERROR,
5672 "ErrorCode,AMSDU aggregation not supported");
5673 return 0;
5674 }
5675 break;
5676 }
5677 }
5678
5679 val = get_param(cmd, "STBC_RX");
5680 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005681 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005682 case DRIVER_ATHEROS:
5683 ath_sta_set_stbc(dut, intf, val);
5684 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305685 case DRIVER_WCN:
5686 wcn_sta_set_stbc(dut, intf, val);
5687 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005688 default:
5689 send_resp(dut, conn, SIGMA_ERROR,
5690 "ErrorCode,STBC_RX not supported");
5691 return 0;
5692 }
5693 }
5694
5695 val = get_param(cmd, "WIDTH");
5696 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005697 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005698 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005699 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005700 send_resp(dut, conn, SIGMA_ERROR,
5701 "ErrorCode,Failed to set WIDTH");
5702 return 0;
5703 }
5704 break;
5705 case DRIVER_ATHEROS:
5706 if (ath_set_width(dut, conn, intf, val) < 0)
5707 return 0;
5708 break;
5709 default:
5710 sigma_dut_print(dut, DUT_MSG_ERROR,
5711 "Setting WIDTH not supported");
5712 break;
5713 }
5714 }
5715
5716 val = get_param(cmd, "SMPS");
5717 if (val) {
5718 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5719 send_resp(dut, conn, SIGMA_ERROR,
5720 "ErrorCode,SMPS not supported");
5721 return 0;
5722 }
5723
5724 val = get_param(cmd, "TXSP_STREAM");
5725 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005726 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005727 case DRIVER_WCN:
5728 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5729 send_resp(dut, conn, SIGMA_ERROR,
5730 "ErrorCode,Failed to set TXSP_STREAM");
5731 return 0;
5732 }
5733 break;
5734 case DRIVER_ATHEROS:
5735 ath_sta_set_txsp_stream(dut, intf, val);
5736 break;
5737 default:
5738 sigma_dut_print(dut, DUT_MSG_ERROR,
5739 "Setting TXSP_STREAM not supported");
5740 break;
5741 }
5742 }
5743
5744 val = get_param(cmd, "RXSP_STREAM");
5745 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005746 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005747 case DRIVER_WCN:
5748 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5749 send_resp(dut, conn, SIGMA_ERROR,
5750 "ErrorCode,Failed to set RXSP_STREAM");
5751 return 0;
5752 }
5753 break;
5754 case DRIVER_ATHEROS:
5755 ath_sta_set_rxsp_stream(dut, intf, val);
5756 break;
5757 default:
5758 sigma_dut_print(dut, DUT_MSG_ERROR,
5759 "Setting RXSP_STREAM not supported");
5760 break;
5761 }
5762 }
5763
5764 val = get_param(cmd, "DYN_BW_SGNL");
5765 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005766 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005767 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08005768 if (strcasecmp(val, "enable") == 0) {
5769 snprintf(buf, sizeof(buf),
5770 "iwpriv %s cwmenable 1", intf);
5771 if (system(buf) != 0) {
5772 sigma_dut_print(dut, DUT_MSG_ERROR,
5773 "iwpriv cwmenable 1 failed");
5774 return 0;
5775 }
5776 } else if (strcasecmp(val, "disable") == 0) {
5777 snprintf(buf, sizeof(buf),
5778 "iwpriv %s cwmenable 0", intf);
5779 if (system(buf) != 0) {
5780 sigma_dut_print(dut, DUT_MSG_ERROR,
5781 "iwpriv cwmenable 0 failed");
5782 return 0;
5783 }
5784 } else {
5785 sigma_dut_print(dut, DUT_MSG_ERROR,
5786 "Unsupported DYN_BW_SGL");
5787 }
5788
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005789 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5790 if (system(buf) != 0) {
5791 sigma_dut_print(dut, DUT_MSG_ERROR,
5792 "Failed to set cts_cbw in DYN_BW_SGNL");
5793 return 0;
5794 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005795 break;
5796 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005797 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005798 ath_config_dyn_bw_sig(dut, intf, val);
5799 break;
5800 default:
5801 sigma_dut_print(dut, DUT_MSG_ERROR,
5802 "Failed to set DYN_BW_SGNL");
5803 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005804 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005805 }
5806
5807 val = get_param(cmd, "RTS_FORCE");
5808 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005809 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005810 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305811 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005812 sigma_dut_print(dut, DUT_MSG_ERROR,
5813 "Failed to set RTS_FORCE 64");
5814 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03005815 res = snprintf(buf, sizeof(buf),
5816 "wifitool %s beeliner_fw_test 100 1",
5817 intf);
5818 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08005819 sigma_dut_print(dut, DUT_MSG_ERROR,
5820 "wifitool beeliner_fw_test 100 1 failed");
5821 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005822 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305823 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005824 sigma_dut_print(dut, DUT_MSG_ERROR,
5825 "Failed to set RTS_FORCE 2347");
5826 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005827 } else {
5828 send_resp(dut, conn, SIGMA_ERROR,
5829 "ErrorCode,RTS_FORCE value not supported");
5830 return 0;
5831 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005832 }
5833
5834 val = get_param(cmd, "CTS_WIDTH");
5835 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005836 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005837 case DRIVER_WCN:
5838 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
5839 send_resp(dut, conn, SIGMA_ERROR,
5840 "ErrorCode,Failed to set CTS_WIDTH");
5841 return 0;
5842 }
5843 break;
5844 case DRIVER_ATHEROS:
5845 ath_set_cts_width(dut, intf, val);
5846 break;
5847 default:
5848 sigma_dut_print(dut, DUT_MSG_ERROR,
5849 "Setting CTS_WIDTH not supported");
5850 break;
5851 }
5852 }
5853
5854 val = get_param(cmd, "BW_SGNL");
5855 if (val) {
5856 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005857 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005858 } else if (strcasecmp(val, "Disable") == 0) {
5859 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005860 } else {
5861 send_resp(dut, conn, SIGMA_ERROR,
5862 "ErrorCode,BW_SGNL value not supported");
5863 return 0;
5864 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005865 }
5866
5867 val = get_param(cmd, "Band");
5868 if (val) {
5869 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
5870 /* STA supports all bands by default */
5871 } else {
5872 send_resp(dut, conn, SIGMA_ERROR,
5873 "ErrorCode,Unsupported Band");
5874 return 0;
5875 }
5876 }
5877
5878 val = get_param(cmd, "zero_crc");
5879 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005880 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005881 case DRIVER_ATHEROS:
5882 ath_set_zero_crc(dut, val);
5883 break;
5884 default:
5885 break;
5886 }
5887 }
5888
5889 return 1;
5890}
5891
5892
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005893static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
5894{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005895 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005896#ifdef __linux__
5897 case DRIVER_WIL6210:
5898 return wil6210_set_force_mcs(dut, force, mcs);
5899#endif /* __linux__ */
5900 default:
5901 sigma_dut_print(dut, DUT_MSG_ERROR,
5902 "Unsupported sta_set_force_mcs with the current driver");
5903 return -1;
5904 }
5905}
5906
5907
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005908static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
5909{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005910 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005911#ifdef __linux__
5912 case DRIVER_WIL6210:
5913 return wil6210_force_rsn_ie(dut, state);
5914#endif /* __linux__ */
5915 default:
5916 sigma_dut_print(dut, DUT_MSG_ERROR,
5917 "Unsupported sta_60g_force_rsn_ie with the current driver");
5918 return -1;
5919 }
5920}
5921
5922
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005923static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
5924 struct sigma_cmd *cmd)
5925{
5926 const char *val;
5927 char buf[100];
5928
5929 val = get_param(cmd, "MSDUSize");
5930 if (val) {
5931 int mtu;
5932
5933 dut->amsdu_size = atoi(val);
5934 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
5935 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
5936 sigma_dut_print(dut, DUT_MSG_ERROR,
5937 "MSDUSize %d is above max %d or below min %d",
5938 dut->amsdu_size,
5939 IEEE80211_MAX_DATA_LEN_DMG,
5940 IEEE80211_SNAP_LEN_DMG);
5941 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005942 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005943 }
5944
5945 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
5946 sigma_dut_print(dut, DUT_MSG_DEBUG,
5947 "Setting amsdu_size to %d", mtu);
5948 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005949 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005950
5951 if (system(buf) != 0) {
5952 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
5953 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005954 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005955 }
5956 }
5957
5958 val = get_param(cmd, "BAckRcvBuf");
5959 if (val) {
5960 dut->back_rcv_buf = atoi(val);
5961 if (dut->back_rcv_buf == 0) {
5962 sigma_dut_print(dut, DUT_MSG_ERROR,
5963 "Failed to convert %s or value is 0",
5964 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005965 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005966 }
5967
5968 sigma_dut_print(dut, DUT_MSG_DEBUG,
5969 "Setting BAckRcvBuf to %s", val);
5970 }
5971
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005972 val = get_param(cmd, "MCS_FixedRate");
5973 if (val) {
5974 if (sta_set_force_mcs(dut, 1, atoi(val))) {
5975 sigma_dut_print(dut, DUT_MSG_ERROR,
5976 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005977 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005978 }
5979 }
5980
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005981 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005982}
5983
5984
5985static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
5986 struct sigma_cmd *cmd)
5987{
5988 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005989 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005990 const char *val;
5991 char buf[100];
5992
5993 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005994 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005995 if (wpa_command(ifname, "PING") != 0) {
5996 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005997 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005998 }
5999
6000 wpa_command(ifname, "FLUSH");
6001 net_id = add_network_common(dut, conn, ifname, cmd);
6002 if (net_id < 0) {
6003 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
6004 return net_id;
6005 }
6006
6007 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
6008 if (set_network(ifname, net_id, "mode", "2") < 0) {
6009 sigma_dut_print(dut, DUT_MSG_ERROR,
6010 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006011 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006012 }
6013
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006014 if (set_network(ifname, net_id, "pbss", "1") < 0)
6015 return -2;
6016
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006017 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006018 "Supplicant set network with mode 2. network_id %d",
6019 net_id);
6020
6021 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6022 sigma_dut_print(dut, DUT_MSG_INFO,
6023 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006024 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006025 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006026
6027 val = get_param(cmd, "Security");
6028 if (val && strcasecmp(val, "OPEN") == 0) {
6029 dut->ap_key_mgmt = AP_OPEN;
6030 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6031 sigma_dut_print(dut, DUT_MSG_ERROR,
6032 "Failed to set supplicant to %s security",
6033 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006034 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006035 }
6036 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6037 dut->ap_key_mgmt = AP_WPA2_PSK;
6038 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6039 sigma_dut_print(dut, DUT_MSG_ERROR,
6040 "Failed to set supplicant to %s security",
6041 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006042 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006043 }
6044
6045 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6046 sigma_dut_print(dut, DUT_MSG_ERROR,
6047 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006048 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006049 }
6050 } else if (val) {
6051 sigma_dut_print(dut, DUT_MSG_ERROR,
6052 "Requested Security %s is not supported on 60GHz",
6053 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006054 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006055 }
6056
6057 val = get_param(cmd, "Encrypt");
6058 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6059 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6060 sigma_dut_print(dut, DUT_MSG_ERROR,
6061 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006062 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006063 }
6064 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6065 sigma_dut_print(dut, DUT_MSG_ERROR,
6066 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006067 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006068 }
6069 } else if (val) {
6070 sigma_dut_print(dut, DUT_MSG_ERROR,
6071 "Requested Encrypt %s is not supported on 60 GHz",
6072 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006073 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006074 }
6075
6076 val = get_param(cmd, "PSK");
6077 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6078 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6079 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006080 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006081 }
6082
6083 /* Convert 60G channel to freq */
6084 switch (dut->ap_channel) {
6085 case 1:
6086 val = "58320";
6087 break;
6088 case 2:
6089 val = "60480";
6090 break;
6091 case 3:
6092 val = "62640";
6093 break;
6094 default:
6095 sigma_dut_print(dut, DUT_MSG_ERROR,
6096 "Failed to configure channel %d. Not supported",
6097 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006098 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006099 }
6100
6101 if (set_network(ifname, net_id, "frequency", val) < 0) {
6102 sigma_dut_print(dut, DUT_MSG_ERROR,
6103 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006104 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006105 }
6106
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006107 if (dut->eap_fragment) {
6108 sigma_dut_print(dut, DUT_MSG_DEBUG,
6109 "Set EAP fragment size to 128 bytes.");
6110 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6111 return ERROR_SEND_STATUS;
6112 }
6113
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006114 sigma_dut_print(dut, DUT_MSG_DEBUG,
6115 "Supplicant set network with frequency");
6116
6117 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6118 if (wpa_command(ifname, buf) < 0) {
6119 sigma_dut_print(dut, DUT_MSG_INFO,
6120 "Failed to select network id %d on %s",
6121 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006122 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006123 }
6124
6125 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6126
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006127 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006128}
6129
6130
Lior David67543f52017-01-03 19:04:22 +02006131static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6132{
6133 char buf[128], fname[128];
6134 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006135 int res;
Lior David67543f52017-01-03 19:04:22 +02006136
6137 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6138 sigma_dut_print(dut, DUT_MSG_ERROR,
6139 "failed to get wil6210 debugfs dir");
6140 return -1;
6141 }
6142
Jouni Malinen3aa72862019-05-29 23:14:51 +03006143 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6144 if (res < 0 || res >= sizeof(fname))
6145 return -1;
Lior David67543f52017-01-03 19:04:22 +02006146 f = fopen(fname, "w");
6147 if (!f) {
6148 sigma_dut_print(dut, DUT_MSG_ERROR,
6149 "failed to open: %s", fname);
6150 return -1;
6151 }
6152
6153 fprintf(f, "%d\n", abft_len);
6154 fclose(f);
6155
6156 return 0;
6157}
6158
6159
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006160int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6161 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006162{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006163 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006164 case DRIVER_WIL6210:
6165 return wil6210_set_abft_len(dut, abft_len);
6166 default:
6167 sigma_dut_print(dut, DUT_MSG_ERROR,
6168 "set abft_len not supported");
6169 return -1;
6170 }
6171}
6172
6173
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006174static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6175 struct sigma_cmd *cmd)
6176{
6177 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006178 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006179
6180 if (dut->dev_role != DEVROLE_PCP) {
6181 send_resp(dut, conn, SIGMA_INVALID,
6182 "ErrorCode,Invalid DevRole");
6183 return 0;
6184 }
6185
6186 val = get_param(cmd, "SSID");
6187 if (val) {
6188 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6189 send_resp(dut, conn, SIGMA_INVALID,
6190 "ErrorCode,Invalid SSID");
6191 return -1;
6192 }
6193
Peng Xub8fc5cc2017-05-10 17:27:28 -07006194 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006195 }
6196
6197 val = get_param(cmd, "CHANNEL");
6198 if (val) {
6199 const char *pos;
6200
6201 dut->ap_channel = atoi(val);
6202 pos = strchr(val, ';');
6203 if (pos) {
6204 pos++;
6205 dut->ap_channel_1 = atoi(pos);
6206 }
6207 }
6208
6209 switch (dut->ap_channel) {
6210 case 1:
6211 case 2:
6212 case 3:
6213 break;
6214 default:
6215 sigma_dut_print(dut, DUT_MSG_ERROR,
6216 "Channel %d is not supported", dut->ap_channel);
6217 send_resp(dut, conn, SIGMA_ERROR,
6218 "Requested channel is not supported");
6219 return -1;
6220 }
6221
6222 val = get_param(cmd, "BCNINT");
6223 if (val)
6224 dut->ap_bcnint = atoi(val);
6225
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006226 val = get_param(cmd, "AllocType");
6227 if (val) {
6228 send_resp(dut, conn, SIGMA_ERROR,
6229 "ErrorCode,AllocType is not supported yet");
6230 return -1;
6231 }
6232
6233 val = get_param(cmd, "PercentBI");
6234 if (val) {
6235 send_resp(dut, conn, SIGMA_ERROR,
6236 "ErrorCode,PercentBI is not supported yet");
6237 return -1;
6238 }
6239
6240 val = get_param(cmd, "CBAPOnly");
6241 if (val) {
6242 send_resp(dut, conn, SIGMA_ERROR,
6243 "ErrorCode,CBAPOnly is not supported yet");
6244 return -1;
6245 }
6246
6247 val = get_param(cmd, "AMPDU");
6248 if (val) {
6249 if (strcasecmp(val, "Enable") == 0)
6250 dut->ap_ampdu = 1;
6251 else if (strcasecmp(val, "Disable") == 0)
6252 dut->ap_ampdu = 2;
6253 else {
6254 send_resp(dut, conn, SIGMA_ERROR,
6255 "ErrorCode,AMPDU value is not Enable nor Disabled");
6256 return -1;
6257 }
6258 }
6259
6260 val = get_param(cmd, "AMSDU");
6261 if (val) {
6262 if (strcasecmp(val, "Enable") == 0)
6263 dut->ap_amsdu = 1;
6264 else if (strcasecmp(val, "Disable") == 0)
6265 dut->ap_amsdu = 2;
6266 }
6267
6268 val = get_param(cmd, "NumMSDU");
6269 if (val) {
6270 send_resp(dut, conn, SIGMA_ERROR,
6271 "ErrorCode, NumMSDU is not supported yet");
6272 return -1;
6273 }
6274
6275 val = get_param(cmd, "ABFTLRang");
6276 if (val) {
6277 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006278 "ABFTLRang parameter %s", val);
6279 if (strcmp(val, "Gt1") == 0)
6280 abft_len = 2; /* 2 slots in this case */
6281 }
6282
6283 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6284 send_resp(dut, conn, SIGMA_ERROR,
6285 "ErrorCode, Can't set ABFT length");
6286 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006287 }
6288
6289 if (sta_pcp_start(dut, conn, cmd) < 0) {
6290 send_resp(dut, conn, SIGMA_ERROR,
6291 "ErrorCode, Can't start PCP role");
6292 return -1;
6293 }
6294
6295 return sta_set_60g_common(dut, conn, cmd);
6296}
6297
6298
6299static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6300 struct sigma_cmd *cmd)
6301{
6302 const char *val = get_param(cmd, "DiscoveryMode");
6303
6304 if (dut->dev_role != DEVROLE_STA) {
6305 send_resp(dut, conn, SIGMA_INVALID,
6306 "ErrorCode,Invalid DevRole");
6307 return 0;
6308 }
6309
6310 if (val) {
6311 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6312 /* Ignore Discovery mode till Driver expose API. */
6313#if 0
6314 if (strcasecmp(val, "1") == 0) {
6315 send_resp(dut, conn, SIGMA_INVALID,
6316 "ErrorCode,DiscoveryMode 1 not supported");
6317 return 0;
6318 }
6319
6320 if (strcasecmp(val, "0") == 0) {
6321 /* OK */
6322 } else {
6323 send_resp(dut, conn, SIGMA_INVALID,
6324 "ErrorCode,DiscoveryMode not supported");
6325 return 0;
6326 }
6327#endif
6328 }
6329
6330 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006331 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006332 return sta_set_60g_common(dut, conn, cmd);
6333}
6334
6335
Jouni Malinenf7222712019-06-13 01:50:21 +03006336static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6337 struct sigma_conn *conn,
6338 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006339{
6340 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006341 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306342
Jouni Malinened77e672018-01-10 16:45:13 +02006343 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006344 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006345 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306346 wpa_command(intf, "DISCONNECT");
6347 return 1;
6348 }
6349
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006350 disconnect_station(dut);
6351 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6352 * due to cached results. */
6353 wpa_command(intf, "SET ignore_old_scan_res 1");
6354 wpa_command(intf, "BSS_FLUSH");
6355 return 1;
6356}
6357
6358
Jouni Malinenf7222712019-06-13 01:50:21 +03006359static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6360 struct sigma_conn *conn,
6361 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006362{
6363 const char *intf = get_param(cmd, "Interface");
6364 const char *bssid = get_param(cmd, "bssid");
6365 const char *val = get_param(cmd, "CHANNEL");
6366 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306367 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306368 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006369 int res;
6370 int chan = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006371 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306372 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006373 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006374
6375 if (bssid == NULL) {
6376 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6377 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006378 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006379 }
6380
6381 if (val)
6382 chan = atoi(val);
6383
6384 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6385 /* The current network may be from sta_associate or
6386 * sta_hs2_associate
6387 */
6388 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6389 0 ||
6390 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006391 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006392 }
6393
6394 ctrl = open_wpa_mon(intf);
6395 if (ctrl == NULL) {
6396 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6397 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006398 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006399 }
6400
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006401 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05306402 sizeof(result)) < 0 ||
6403 strncmp(result, "COMPLETED", 9) != 0) {
6404 sigma_dut_print(dut, DUT_MSG_DEBUG,
6405 "sta_reassoc: Not connected");
6406 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006407 } else if (dut->sta_ft_ds) {
6408 sigma_dut_print(dut, DUT_MSG_DEBUG,
6409 "sta_reassoc: Use FT-over-DS");
6410 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306411 }
6412
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306413 if (dut->rsne_override) {
6414#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006415 if (get_driver_type(dut) == DRIVER_WCN &&
6416 dut->config_rsnie == 0) {
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306417 sta_config_rsnie(dut, 1);
6418 dut->config_rsnie = 1;
6419 }
6420#endif /* NL80211_SUPPORT */
6421 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6422 dut->rsne_override);
6423 if (wpa_command(intf, buf) < 0) {
6424 send_resp(dut, conn, SIGMA_ERROR,
6425 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6426 return 0;
6427 }
6428 }
6429
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006430 if (ft_ds) {
6431 if (chan) {
6432 unsigned int freq;
6433
6434 freq = channel_to_freq(dut, chan);
6435 if (!freq) {
6436 sigma_dut_print(dut, DUT_MSG_ERROR,
6437 "Invalid channel number provided: %d",
6438 chan);
6439 send_resp(dut, conn, SIGMA_INVALID,
6440 "ErrorCode,Invalid channel number");
6441 goto close_mon_conn;
6442 }
6443 res = snprintf(buf, sizeof(buf),
6444 "SCAN TYPE=ONLY freq=%d", freq);
6445 } else {
6446 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6447 }
6448 if (res < 0 || res >= (int) sizeof(buf)) {
6449 send_resp(dut, conn, SIGMA_ERROR,
6450 "ErrorCode,snprintf failed");
6451 goto close_mon_conn;
6452 }
6453 if (wpa_command(intf, buf) < 0) {
6454 sigma_dut_print(dut, DUT_MSG_INFO,
6455 "Failed to start scan");
6456 send_resp(dut, conn, SIGMA_ERROR,
6457 "ErrorCode,scan failed");
6458 goto close_mon_conn;
6459 }
6460
6461 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6462 buf, sizeof(buf));
6463 if (res < 0) {
6464 sigma_dut_print(dut, DUT_MSG_INFO,
6465 "Scan did not complete");
6466 send_resp(dut, conn, SIGMA_ERROR,
6467 "ErrorCode,scan did not complete");
6468 goto close_mon_conn;
6469 }
6470
6471 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6472 if (res > 0 && res < (int) sizeof(buf))
6473 res = wpa_command(intf, buf);
6474
6475 if (res < 0 || res >= (int) sizeof(buf)) {
6476 send_resp(dut, conn, SIGMA_ERROR,
6477 "errorCode,FT_DS command failed");
6478 status = STATUS_SENT_ERROR;
6479 goto close_mon_conn;
6480 }
6481 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306482 if (chan) {
6483 unsigned int freq;
6484
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02006485 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306486 if (!freq) {
6487 sigma_dut_print(dut, DUT_MSG_ERROR,
6488 "Invalid channel number provided: %d",
6489 chan);
6490 send_resp(dut, conn, SIGMA_INVALID,
6491 "ErrorCode,Invalid channel number");
6492 goto close_mon_conn;
6493 }
6494 res = snprintf(buf, sizeof(buf),
6495 "SCAN TYPE=ONLY freq=%d", freq);
6496 } else {
6497 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6498 }
6499 if (res < 0 || res >= (int) sizeof(buf)) {
6500 send_resp(dut, conn, SIGMA_ERROR,
6501 "ErrorCode,snprintf failed");
6502 goto close_mon_conn;
6503 }
6504 if (wpa_command(intf, buf) < 0) {
6505 sigma_dut_print(dut, DUT_MSG_INFO,
6506 "Failed to start scan");
6507 send_resp(dut, conn, SIGMA_ERROR,
6508 "ErrorCode,scan failed");
6509 goto close_mon_conn;
6510 }
6511
6512 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6513 buf, sizeof(buf));
6514 if (res < 0) {
6515 sigma_dut_print(dut, DUT_MSG_INFO,
6516 "Scan did not complete");
6517 send_resp(dut, conn, SIGMA_ERROR,
6518 "ErrorCode,scan did not complete");
6519 goto close_mon_conn;
6520 }
6521
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006522 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6523 < 0) {
6524 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6525 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006526 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306527 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006528 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306529 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006530 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306531 if (res < 0 || res >= (int) sizeof(buf) ||
6532 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006533 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306534 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306535 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006536 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006537 sigma_dut_print(dut, DUT_MSG_INFO,
6538 "sta_reassoc: Run %s successful", buf);
6539 } else if (wpa_command(intf, "REASSOCIATE")) {
6540 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6541 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306542 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006543 }
6544
6545 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6546 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306547 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006548 send_resp(dut, conn, SIGMA_ERROR,
6549 "errorCode,Connection did not complete");
6550 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306551 goto close_mon_conn;
6552 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006553 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006554
Ashwini Patil467efef2017-05-25 12:18:27 +05306555close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006556 wpa_ctrl_detach(ctrl);
6557 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306558 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006559}
6560
6561
6562static void hs2_clear_credentials(const char *intf)
6563{
6564 wpa_command(intf, "REMOVE_CRED all");
6565}
6566
6567
Lior Davidcc88b562017-01-03 18:52:09 +02006568#ifdef __linux__
6569static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6570 unsigned int *aid)
6571{
Lior David0fe101e2017-03-09 16:09:50 +02006572 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006573
Lior David0fe101e2017-03-09 16:09:50 +02006574 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006575}
6576#endif /* __linux__ */
6577
6578
6579static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6580 unsigned int *aid)
6581{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006582 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02006583#ifdef __linux__
6584 case DRIVER_WIL6210:
6585 return wil6210_get_aid(dut, bssid, aid);
6586#endif /* __linux__ */
6587 default:
6588 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6589 return -1;
6590 }
6591}
6592
6593
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006594static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6595 struct sigma_cmd *cmd)
6596{
6597 char buf[MAX_CMD_LEN];
6598 char bss_list[MAX_CMD_LEN];
6599 const char *parameter = get_param(cmd, "Parameter");
6600
6601 if (parameter == NULL)
6602 return -1;
6603
Lior Davidcc88b562017-01-03 18:52:09 +02006604 if (strcasecmp(parameter, "AID") == 0) {
6605 unsigned int aid = 0;
6606 char bssid[20];
6607
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006608 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02006609 bssid, sizeof(bssid)) < 0) {
6610 sigma_dut_print(dut, DUT_MSG_ERROR,
6611 "could not get bssid");
6612 return -2;
6613 }
6614
6615 if (sta_get_aid_60g(dut, bssid, &aid))
6616 return -2;
6617
6618 snprintf(buf, sizeof(buf), "aid,%d", aid);
6619 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6620 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6621 return 0;
6622 }
6623
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006624 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6625 char *bss_line;
6626 char *bss_id = NULL;
6627 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306628 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006629
6630 if (ifname == NULL) {
6631 sigma_dut_print(dut, DUT_MSG_INFO,
6632 "For get DiscoveredDevList need Interface name.");
6633 return -1;
6634 }
6635
6636 /*
6637 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6638 * of BSSIDs in "bssid=<BSSID>\n"
6639 */
6640 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6641 bss_list,
6642 sizeof(bss_list)) < 0) {
6643 sigma_dut_print(dut, DUT_MSG_ERROR,
6644 "Failed to get bss list");
6645 return -1;
6646 }
6647
6648 sigma_dut_print(dut, DUT_MSG_DEBUG,
6649 "bss list for ifname:%s is:%s",
6650 ifname, bss_list);
6651
6652 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306653 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006654 while (bss_line) {
6655 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6656 bss_id) {
6657 int len;
6658
6659 len = snprintf(buf + strlen(buf),
6660 sizeof(buf) - strlen(buf),
6661 ",%s", bss_id);
6662 free(bss_id);
6663 bss_id = NULL;
6664 if (len < 0) {
6665 sigma_dut_print(dut,
6666 DUT_MSG_ERROR,
6667 "Failed to read BSSID");
6668 send_resp(dut, conn, SIGMA_ERROR,
6669 "ErrorCode,Failed to read BSS ID");
6670 return 0;
6671 }
6672
6673 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6674 sigma_dut_print(dut,
6675 DUT_MSG_ERROR,
6676 "Response buf too small for list");
6677 send_resp(dut, conn,
6678 SIGMA_ERROR,
6679 "ErrorCode,Response buf too small for list");
6680 return 0;
6681 }
6682 }
6683
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306684 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006685 }
6686
6687 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6688 buf);
6689 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6690 return 0;
6691 }
6692
6693 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6694 return 0;
6695}
6696
6697
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006698static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6699 struct sigma_cmd *cmd)
6700{
6701 char buf[MAX_CMD_LEN];
6702 const char *parameter = get_param(cmd, "Parameter");
6703
6704 if (!parameter)
6705 return -1;
6706
6707 if (strcasecmp(parameter, "RSSI") == 0) {
6708 char rssi[10];
6709
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006710 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006711 rssi, sizeof(rssi)) < 0) {
6712 sigma_dut_print(dut, DUT_MSG_ERROR,
6713 "Could not get RSSI");
6714 return -2;
6715 }
6716
6717 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6718 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6719 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6720 return 0;
6721 }
6722
6723 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6724 return 0;
6725}
6726
6727
Jouni Malinenca0abd32020-02-09 20:18:10 +02006728static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
6729 struct sigma_conn *conn,
6730 struct sigma_cmd *cmd)
6731{
6732 const char *intf = get_param(cmd, "Interface");
6733 char buf[4096], bssid[20], resp[200], *pos, *tmp;
6734
6735 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
6736 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
6737 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
6738 send_resp(dut, conn, SIGMA_ERROR,
6739 "ErrorCode,PMKSA_GET not supported");
6740 return STATUS_SENT_ERROR;
6741 }
6742
6743 if (strncmp(buf, "FAIL", 4) == 0 ||
6744 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
6745 send_resp(dut, conn, SIGMA_ERROR,
6746 "ErrorCode,Could not find current network");
6747 return STATUS_SENT_ERROR;
6748 }
6749
6750 pos = buf;
6751 while (pos) {
6752 if (strncmp(pos, bssid, 17) == 0) {
6753 pos = strchr(pos, ' ');
6754 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05306755 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02006756 pos++;
6757 pos = strchr(pos, ' ');
6758 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05306759 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02006760 pos++;
6761 tmp = strchr(pos, ' ');
6762 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05306763 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02006764 *tmp = '\0';
6765 break;
6766 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02006767 pos = strchr(pos, '\n');
6768 if (pos)
6769 pos++;
6770 }
6771
6772 if (!pos) {
6773 send_resp(dut, conn, SIGMA_ERROR,
6774 "ErrorCode,PMK not available");
6775 return STATUS_SENT_ERROR;
6776 }
6777
6778 snprintf(resp, sizeof(resp), "PMK,%s", pos);
6779 send_resp(dut, conn, SIGMA_COMPLETE, resp);
6780 return STATUS_SENT;
6781}
6782
6783
Jouni Malinenf7222712019-06-13 01:50:21 +03006784static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
6785 struct sigma_conn *conn,
6786 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006787{
6788 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02006789 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006790
Jouni Malinenca0abd32020-02-09 20:18:10 +02006791 if (!parameter)
6792 return INVALID_SEND_STATUS;
6793
6794 if (strcasecmp(parameter, "PMK") == 0)
6795 return sta_get_pmk(dut, conn, cmd);
6796
6797 if (!program)
6798 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006799
6800 if (strcasecmp(program, "P2PNFC") == 0)
6801 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
6802
6803 if (strcasecmp(program, "60ghz") == 0)
6804 return sta_get_parameter_60g(dut, conn, cmd);
6805
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006806 if (strcasecmp(program, "he") == 0)
6807 return sta_get_parameter_he(dut, conn, cmd);
6808
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006809#ifdef ANDROID_NAN
6810 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07006811 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006812#endif /* ANDROID_NAN */
6813
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006814#ifdef MIRACAST
6815 if (strcasecmp(program, "WFD") == 0 ||
6816 strcasecmp(program, "DisplayR2") == 0)
6817 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
6818#endif /* MIRACAST */
6819
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006820 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6821 return 0;
6822}
6823
6824
6825static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
6826 const char *type)
6827{
6828 char buf[100];
6829
6830 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006831 run_iwpriv(dut, intf, "chwidth 2");
6832 run_iwpriv(dut, intf, "mode 11ACVHT80");
6833 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006834 }
6835
6836 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006837 run_iwpriv(dut, intf, "chwidth 0");
6838 run_iwpriv(dut, intf, "mode 11naht40");
6839 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006840 }
6841
6842 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006843 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006844
6845 /* Reset CTS width */
6846 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
6847 intf);
6848 if (system(buf) != 0) {
6849 sigma_dut_print(dut, DUT_MSG_ERROR,
6850 "wifitool %s beeliner_fw_test 54 0 failed",
6851 intf);
6852 }
6853
6854 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006855 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006856
6857 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
6858 if (system(buf) != 0) {
6859 sigma_dut_print(dut, DUT_MSG_ERROR,
6860 "iwpriv rts failed");
6861 }
6862 }
6863
6864 if (type && strcasecmp(type, "Testbed") == 0) {
6865 dut->testbed_flag_txsp = 1;
6866 dut->testbed_flag_rxsp = 1;
6867 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006868 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006869
6870 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006871 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006872
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006873 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006874
6875 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006876 run_iwpriv(dut, intf, "tx_stbc 0");
6877 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006878
6879 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006880 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006881 }
6882
6883 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006884 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07006885 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006886
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006887 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006888 }
6889}
6890
6891
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006892#ifdef NL80211_SUPPORT
6893static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
6894 enum he_mcs_config mcs)
6895{
6896 struct nl_msg *msg;
6897 int ret = 0;
6898 struct nlattr *params;
6899 int ifindex;
6900
6901 ifindex = if_nametoindex(intf);
6902 if (ifindex == 0) {
6903 sigma_dut_print(dut, DUT_MSG_ERROR,
6904 "%s: Index for interface %s failed",
6905 __func__, intf);
6906 return -1;
6907 }
6908
6909 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6910 NL80211_CMD_VENDOR)) ||
6911 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6912 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6913 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6914 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6915 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6916 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
6917 mcs)) {
6918 sigma_dut_print(dut, DUT_MSG_ERROR,
6919 "%s: err in adding vendor_cmd and vendor_data",
6920 __func__);
6921 nlmsg_free(msg);
6922 return -1;
6923 }
6924 nla_nest_end(msg, params);
6925
6926 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6927 if (ret) {
6928 sigma_dut_print(dut, DUT_MSG_ERROR,
6929 "%s: err in send_and_recv_msgs, ret=%d",
6930 __func__, ret);
6931 }
6932 return ret;
6933}
6934#endif /* NL80211_SUPPORT */
6935
6936
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07006937static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
6938 const char *intf, int enable)
6939{
6940#ifdef NL80211_SUPPORT
6941 struct nl_msg *msg;
6942 int ret = 0;
6943 struct nlattr *params;
6944 int ifindex;
6945
6946 ifindex = if_nametoindex(intf);
6947 if (ifindex == 0) {
6948 sigma_dut_print(dut, DUT_MSG_ERROR,
6949 "%s: Index for interface %s failed",
6950 __func__, intf);
6951 return -1;
6952 }
6953
6954 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6955 NL80211_CMD_VENDOR)) ||
6956 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6957 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6958 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6959 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6960 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6961 nla_put_u8(msg,
6962 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
6963 enable)) {
6964 sigma_dut_print(dut, DUT_MSG_ERROR,
6965 "%s: err in adding vendor_cmd and vendor_data",
6966 __func__);
6967 nlmsg_free(msg);
6968 return -1;
6969 }
6970 nla_nest_end(msg, params);
6971
6972 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6973 if (ret) {
6974 sigma_dut_print(dut, DUT_MSG_ERROR,
6975 "%s: err in send_and_recv_msgs, ret=%d",
6976 __func__, ret);
6977 }
6978 return ret;
6979#else /* NL80211_SUPPORT */
6980 sigma_dut_print(dut, DUT_MSG_ERROR,
6981 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
6982 return -1;
6983#endif /* NL80211_SUPPORT */
6984}
6985
6986
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08006987static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
6988 const char *intf, int enable)
6989{
6990#ifdef NL80211_SUPPORT
6991 struct nl_msg *msg;
6992 int ret = 0;
6993 struct nlattr *params;
6994 int ifindex;
6995
6996 ifindex = if_nametoindex(intf);
6997 if (ifindex == 0) {
6998 sigma_dut_print(dut, DUT_MSG_ERROR,
6999 "%s: Index for interface %s failed",
7000 __func__, intf);
7001 return -1;
7002 }
7003
7004 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7005 NL80211_CMD_VENDOR)) ||
7006 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7007 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7008 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7009 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7010 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7011 nla_put_u8(msg,
7012 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7013 enable)) {
7014 sigma_dut_print(dut, DUT_MSG_ERROR,
7015 "%s: err in adding vendor_cmd and vendor_data",
7016 __func__);
7017 nlmsg_free(msg);
7018 return -1;
7019 }
7020 nla_nest_end(msg, params);
7021
7022 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7023 if (ret) {
7024 sigma_dut_print(dut, DUT_MSG_ERROR,
7025 "%s: err in send_and_recv_msgs, ret=%d",
7026 __func__, ret);
7027 }
7028 return ret;
7029#else /* NL80211_SUPPORT */
7030 sigma_dut_print(dut, DUT_MSG_ERROR,
7031 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7032 return -1;
7033#endif /* NL80211_SUPPORT */
7034}
7035
7036
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007037#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007038
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007039static int sta_set_he_testbed_def(struct sigma_dut *dut,
7040 const char *intf, int cfg)
7041{
7042 struct nl_msg *msg;
7043 int ret = 0;
7044 struct nlattr *params;
7045 int ifindex;
7046
7047 ifindex = if_nametoindex(intf);
7048 if (ifindex == 0) {
7049 sigma_dut_print(dut, DUT_MSG_ERROR,
7050 "%s: Index for interface %s failed",
7051 __func__, intf);
7052 return -1;
7053 }
7054
7055 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7056 NL80211_CMD_VENDOR)) ||
7057 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7058 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7059 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7060 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7061 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7062 nla_put_u8(msg,
7063 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7064 cfg)) {
7065 sigma_dut_print(dut, DUT_MSG_ERROR,
7066 "%s: err in adding vendor_cmd and vendor_data",
7067 __func__);
7068 nlmsg_free(msg);
7069 return -1;
7070 }
7071 nla_nest_end(msg, params);
7072
7073 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7074 if (ret) {
7075 sigma_dut_print(dut, DUT_MSG_ERROR,
7076 "%s: err in send_and_recv_msgs, ret=%d",
7077 __func__, ret);
7078 }
7079 return ret;
7080}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007081
7082
7083static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7084{
7085 struct nl_msg *msg;
7086 int ret = 0;
7087 struct nlattr *params;
7088 int ifindex;
7089
7090 ifindex = if_nametoindex(intf);
7091 if (ifindex == 0) {
7092 sigma_dut_print(dut, DUT_MSG_ERROR,
7093 "%s: Index for interface %s failed",
7094 __func__, intf);
7095 return -1;
7096 }
7097
7098 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7099 NL80211_CMD_VENDOR)) ||
7100 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7101 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7102 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7103 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7104 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7105 nla_put_u8(msg,
7106 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7107 cfg)) {
7108 sigma_dut_print(dut, DUT_MSG_ERROR,
7109 "%s: err in adding vendor_cmd and vendor_data",
7110 __func__);
7111 nlmsg_free(msg);
7112 return -1;
7113 }
7114 nla_nest_end(msg, params);
7115
7116 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7117 if (ret) {
7118 sigma_dut_print(dut, DUT_MSG_ERROR,
7119 "%s: err in send_and_recv_msgs, ret=%d",
7120 __func__, ret);
7121 }
7122 return ret;
7123}
7124
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007125#endif /* NL80211_SUPPORT */
7126
7127
Qiwei Caib6806972020-01-15 13:52:11 +08007128int sta_set_addba_buf_size(struct sigma_dut *dut,
7129 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007130{
7131#ifdef NL80211_SUPPORT
7132 struct nl_msg *msg;
7133 int ret = 0;
7134 struct nlattr *params;
7135 int ifindex;
7136
7137 ifindex = if_nametoindex(intf);
7138 if (ifindex == 0) {
7139 sigma_dut_print(dut, DUT_MSG_ERROR,
7140 "%s: Index for interface %s failed",
7141 __func__, intf);
7142 return -1;
7143 }
7144
7145 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7146 NL80211_CMD_VENDOR)) ||
7147 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7148 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7149 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7150 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7151 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07007152 nla_put_u16(msg,
7153 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
7154 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007155 sigma_dut_print(dut, DUT_MSG_ERROR,
7156 "%s: err in adding vendor_cmd and vendor_data",
7157 __func__);
7158 nlmsg_free(msg);
7159 return -1;
7160 }
7161 nla_nest_end(msg, params);
7162
7163 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7164 if (ret) {
7165 sigma_dut_print(dut, DUT_MSG_ERROR,
7166 "%s: err in send_and_recv_msgs, ret=%d",
7167 __func__, ret);
7168 }
7169 return ret;
7170#else /* NL80211_SUPPORT */
7171 sigma_dut_print(dut, DUT_MSG_ERROR,
7172 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7173 return -1;
7174#endif /* NL80211_SUPPORT */
7175}
7176
7177
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007178static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
7179 int enable)
7180{
7181#ifdef NL80211_SUPPORT
7182 struct nl_msg *msg;
7183 int ret = 0;
7184 struct nlattr *params;
7185 int ifindex;
7186
7187 ifindex = if_nametoindex(intf);
7188 if (ifindex == 0) {
7189 sigma_dut_print(dut, DUT_MSG_ERROR,
7190 "%s: Index for interface %s failed",
7191 __func__, intf);
7192 return -1;
7193 }
7194
7195 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7196 NL80211_CMD_VENDOR)) ||
7197 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7198 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7199 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7200 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7201 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7202 nla_put_u8(msg,
7203 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7204 enable)) {
7205 sigma_dut_print(dut, DUT_MSG_ERROR,
7206 "%s: err in adding vendor_cmd and vendor_data",
7207 __func__);
7208 nlmsg_free(msg);
7209 return -1;
7210 }
7211 nla_nest_end(msg, params);
7212
7213 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7214 if (ret) {
7215 sigma_dut_print(dut, DUT_MSG_ERROR,
7216 "%s: err in send_and_recv_msgs, ret=%d",
7217 __func__, ret);
7218 }
7219 return ret;
7220#else /* NL80211_SUPPORT */
7221 sigma_dut_print(dut, DUT_MSG_ERROR,
7222 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7223 return -1;
7224#endif /* NL80211_SUPPORT */
7225}
7226
7227
Arif Hussain9765f7d2018-07-03 08:28:26 -07007228static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7229 int val)
7230{
7231#ifdef NL80211_SUPPORT
7232 struct nl_msg *msg;
7233 int ret = 0;
7234 struct nlattr *params;
7235 int ifindex;
7236
7237 ifindex = if_nametoindex(intf);
7238 if (ifindex == 0) {
7239 sigma_dut_print(dut, DUT_MSG_ERROR,
7240 "%s: Index for interface %s failed, val:%d",
7241 __func__, intf, val);
7242 return -1;
7243 }
7244
7245 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7246 NL80211_CMD_VENDOR)) ||
7247 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7248 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7249 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7250 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7251 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7252 nla_put_u8(msg,
7253 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7254 val)) {
7255 sigma_dut_print(dut, DUT_MSG_ERROR,
7256 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7257 __func__, val);
7258 nlmsg_free(msg);
7259 return -1;
7260 }
7261 nla_nest_end(msg, params);
7262
7263 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7264 if (ret) {
7265 sigma_dut_print(dut, DUT_MSG_ERROR,
7266 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7267 __func__, ret, val);
7268 }
7269 return ret;
7270#else /* NL80211_SUPPORT */
7271 sigma_dut_print(dut, DUT_MSG_ERROR,
7272 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7273 return -1;
7274#endif /* NL80211_SUPPORT */
7275}
7276
7277
Arif Hussain68d23f52018-07-11 13:39:08 -07007278#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007279static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7280 enum qca_wlan_he_mac_padding_dur val)
7281{
Arif Hussain68d23f52018-07-11 13:39:08 -07007282 struct nl_msg *msg;
7283 int ret = 0;
7284 struct nlattr *params;
7285 int ifindex;
7286
7287 ifindex = if_nametoindex(intf);
7288 if (ifindex == 0) {
7289 sigma_dut_print(dut, DUT_MSG_ERROR,
7290 "%s: Index for interface %s failed, val:%d",
7291 __func__, intf, val);
7292 return -1;
7293 }
7294
7295 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7296 NL80211_CMD_VENDOR)) ||
7297 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7298 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7299 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7300 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7301 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7302 nla_put_u8(msg,
7303 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
7304 val)) {
7305 sigma_dut_print(dut, DUT_MSG_ERROR,
7306 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7307 __func__, val);
7308 nlmsg_free(msg);
7309 return -1;
7310 }
7311 nla_nest_end(msg, params);
7312
7313 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7314 if (ret) {
7315 sigma_dut_print(dut, DUT_MSG_ERROR,
7316 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7317 __func__, ret, val);
7318 }
7319 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07007320}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007321#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007322
7323
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007324static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7325 int val)
7326{
7327#ifdef NL80211_SUPPORT
7328 struct nl_msg *msg;
7329 int ret = 0;
7330 struct nlattr *params;
7331 int ifindex;
7332
7333 ifindex = if_nametoindex(intf);
7334 if (ifindex == 0) {
7335 sigma_dut_print(dut, DUT_MSG_ERROR,
7336 "%s: Index for interface %s failed, val:%d",
7337 __func__, intf, val);
7338 return -1;
7339 }
7340
7341 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7342 NL80211_CMD_VENDOR)) ||
7343 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7344 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7345 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7346 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7347 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7348 nla_put_u8(msg,
7349 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7350 val)) {
7351 sigma_dut_print(dut, DUT_MSG_ERROR,
7352 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7353 __func__, val);
7354 nlmsg_free(msg);
7355 return -1;
7356 }
7357 nla_nest_end(msg, params);
7358
7359 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7360 if (ret) {
7361 sigma_dut_print(dut, DUT_MSG_ERROR,
7362 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7363 __func__, ret, val);
7364 }
7365 return ret;
7366#else /* NL80211_SUPPORT */
7367 sigma_dut_print(dut, DUT_MSG_ERROR,
7368 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7369 return -1;
7370#endif /* NL80211_SUPPORT */
7371}
7372
7373
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007374#ifdef NL80211_SUPPORT
7375static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7376{
7377 struct nl_msg *msg;
7378 int ret = 0;
7379 struct nlattr *params;
7380 int ifindex;
7381
7382 ifindex = if_nametoindex(intf);
7383 if (ifindex == 0) {
7384 sigma_dut_print(dut, DUT_MSG_ERROR,
7385 "%s: Index for interface %s failed",
7386 __func__, intf);
7387 return -1;
7388 }
7389
7390 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7391 NL80211_CMD_VENDOR)) ||
7392 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7393 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7394 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7395 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7396 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7397 nla_put_flag(msg,
7398 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
7399 sigma_dut_print(dut, DUT_MSG_ERROR,
7400 "%s: err in adding vendor_cmd and vendor_data",
7401 __func__);
7402 nlmsg_free(msg);
7403 return -1;
7404 }
7405 nla_nest_end(msg, params);
7406
7407 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7408 if (ret) {
7409 sigma_dut_print(dut, DUT_MSG_ERROR,
7410 "%s: err in send_and_recv_msgs, ret=%d",
7411 __func__, ret);
7412 }
7413 return ret;
7414}
7415#endif /* NL80211_SUPPORT */
7416
7417
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007418static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7419 int val)
7420{
7421#ifdef NL80211_SUPPORT
7422 struct nl_msg *msg;
7423 int ret = 0;
7424 struct nlattr *params;
7425 int ifindex;
7426
7427 ifindex = if_nametoindex(intf);
7428 if (ifindex == 0) {
7429 sigma_dut_print(dut, DUT_MSG_ERROR,
7430 "%s: Index for interface %s failed, val:%d",
7431 __func__, intf, val);
7432 return -1;
7433 }
7434
7435 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7436 NL80211_CMD_VENDOR)) ||
7437 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7438 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7439 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7440 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7441 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7442 nla_put_u8(msg,
7443 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
7444 val)) {
7445 sigma_dut_print(dut, DUT_MSG_ERROR,
7446 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7447 __func__, val);
7448 nlmsg_free(msg);
7449 return -1;
7450 }
7451 nla_nest_end(msg, params);
7452
7453 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7454 if (ret) {
7455 sigma_dut_print(dut, DUT_MSG_ERROR,
7456 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7457 __func__, ret, val);
7458 }
7459 return ret;
7460#else /* NL80211_SUPPORT */
7461 sigma_dut_print(dut, DUT_MSG_ERROR,
7462 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7463 return -1;
7464#endif /* NL80211_SUPPORT */
7465}
7466
7467
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007468static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7469 int val)
7470{
7471#ifdef NL80211_SUPPORT
7472 struct nl_msg *msg;
7473 int ret = 0;
7474 struct nlattr *params;
7475 int ifindex;
7476
7477 ifindex = if_nametoindex(intf);
7478 if (ifindex == 0) {
7479 sigma_dut_print(dut, DUT_MSG_ERROR,
7480 "%s: Index for interface %s failed, val:%d",
7481 __func__, intf, val);
7482 return -1;
7483 }
7484
7485 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7486 NL80211_CMD_VENDOR)) ||
7487 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7488 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7489 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7490 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7491 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7492 nla_put_u8(msg,
7493 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
7494 val)) {
7495 sigma_dut_print(dut, DUT_MSG_ERROR,
7496 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7497 __func__, val);
7498 nlmsg_free(msg);
7499 return -1;
7500 }
7501 nla_nest_end(msg, params);
7502
7503 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7504 if (ret) {
7505 sigma_dut_print(dut, DUT_MSG_ERROR,
7506 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7507 __func__, ret, val);
7508 }
7509 return ret;
7510#else /* NL80211_SUPPORT */
7511 sigma_dut_print(dut, DUT_MSG_ERROR,
7512 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7513 return -1;
7514#endif /* NL80211_SUPPORT */
7515}
7516
7517
Arif Hussain480d5f42019-03-12 14:40:42 -07007518static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7519 int val)
7520{
7521#ifdef NL80211_SUPPORT
7522 struct nl_msg *msg;
7523 int ret;
7524 struct nlattr *params;
7525 int ifindex;
7526
7527 ifindex = if_nametoindex(intf);
7528 if (ifindex == 0) {
7529 sigma_dut_print(dut, DUT_MSG_ERROR,
7530 "%s: Index for interface %s failed, val:%d",
7531 __func__, intf, val);
7532 return -1;
7533 }
7534
7535 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7536 NL80211_CMD_VENDOR)) ||
7537 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7538 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7539 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7540 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7541 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7542 nla_put_u8(msg,
7543 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT,
7544 val)) {
7545 sigma_dut_print(dut, DUT_MSG_ERROR,
7546 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7547 __func__, val);
7548 nlmsg_free(msg);
7549 return -1;
7550 }
7551 nla_nest_end(msg, params);
7552
7553 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7554 if (ret) {
7555 sigma_dut_print(dut, DUT_MSG_ERROR,
7556 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7557 __func__, ret, val);
7558 }
7559 return ret;
7560#else /* NL80211_SUPPORT */
7561 sigma_dut_print(dut, DUT_MSG_ERROR,
7562 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7563 return -1;
7564#endif /* NL80211_SUPPORT */
7565}
7566
7567
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007568static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7569 const char *type)
7570{
7571 char buf[60];
7572
7573 if (dut->program == PROGRAM_HE) {
7574 /* resetting phymode to auto in case of HE program */
7575 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
7576 if (system(buf) != 0) {
7577 sigma_dut_print(dut, DUT_MSG_ERROR,
7578 "iwpriv %s setphymode failed", intf);
7579 }
7580
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007581 /* reset the rate to Auto rate */
7582 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7583 intf);
7584 if (system(buf) != 0) {
7585 sigma_dut_print(dut, DUT_MSG_ERROR,
7586 "iwpriv %s set_11ax_rate 0xff failed",
7587 intf);
7588 }
7589
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007590 /* reset the LDPC setting */
7591 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7592 if (system(buf) != 0) {
7593 sigma_dut_print(dut, DUT_MSG_ERROR,
7594 "iwpriv %s ldpc 1 failed", intf);
7595 }
7596
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007597 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05307598 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007599
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007600 /* remove all network profiles */
7601 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007602
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007603 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7604 sta_set_addba_buf_size(dut, intf, 64);
7605
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007606#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007607 /* Reset the device HE capabilities to its default supported
7608 * configuration. */
7609 sta_set_he_testbed_def(dut, intf, 0);
7610
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007611 /* Disable noackpolicy for all AC */
7612 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7613 sigma_dut_print(dut, DUT_MSG_ERROR,
7614 "Disable of noackpolicy for all AC failed");
7615 }
7616#endif /* NL80211_SUPPORT */
7617
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007618 /* Enable WMM by default */
7619 if (wcn_sta_set_wmm(dut, intf, "on")) {
7620 sigma_dut_print(dut, DUT_MSG_ERROR,
7621 "Enable of WMM in sta_reset_default_wcn failed");
7622 }
7623
7624 /* Disable ADDBA_REJECT by default */
7625 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7626 sigma_dut_print(dut, DUT_MSG_ERROR,
7627 "Disable of addba_reject in sta_reset_default_wcn failed");
7628 }
7629
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007630 /* Enable sending of ADDBA by default */
7631 if (nlvendor_config_send_addba(dut, intf, 1)) {
7632 sigma_dut_print(dut, DUT_MSG_ERROR,
7633 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7634 }
7635
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007636 /* Enable AMPDU by default */
7637 iwpriv_sta_set_ampdu(dut, intf, 1);
7638
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007639#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08007640 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007641 sigma_dut_print(dut, DUT_MSG_ERROR,
7642 "Set LTF config to default in sta_reset_default_wcn failed");
7643 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007644
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007645 /* set the beamformee NSTS(maximum number of
7646 * space-time streams) to default DUT config
7647 */
7648 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007649 sigma_dut_print(dut, DUT_MSG_ERROR,
7650 "Failed to set BeamformeeSTS");
7651 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007652
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007653 if (sta_set_mac_padding_duration(
7654 dut, intf,
7655 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007656 sigma_dut_print(dut, DUT_MSG_ERROR,
7657 "Failed to set MAC padding duration");
7658 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007659
7660 if (sta_set_mu_edca_override(dut, intf, 0)) {
7661 sigma_dut_print(dut, DUT_MSG_ERROR,
7662 "ErrorCode,Failed to set MU EDCA override disable");
7663 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007664
7665 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7666 sigma_dut_print(dut, DUT_MSG_ERROR,
7667 "Failed to set OM ctrl supp");
7668 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007669
7670 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7671 sigma_dut_print(dut, DUT_MSG_ERROR,
7672 "Failed to set Tx SU PPDU enable");
7673 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007674
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007675 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7676 sigma_dut_print(dut, DUT_MSG_ERROR,
7677 "failed to send TB PPDU Tx cfg");
7678 }
7679
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007680 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7681 sigma_dut_print(dut, DUT_MSG_ERROR,
7682 "Failed to set OM ctrl reset");
7683 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007684
7685 /* +HTC-HE support default on */
7686 if (sta_set_he_htc_supp(dut, intf, 1)) {
7687 sigma_dut_print(dut, DUT_MSG_ERROR,
7688 "Setting of +HTC-HE support failed");
7689 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007690#endif /* NL80211_SUPPORT */
7691
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007692 if (sta_set_tx_beamformee(dut, intf, 1)) {
7693 sigma_dut_print(dut, DUT_MSG_ERROR,
7694 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7695 }
7696
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007697 /* Set nss to 1 and MCS 0-7 in case of testbed */
7698 if (type && strcasecmp(type, "Testbed") == 0) {
7699#ifdef NL80211_SUPPORT
7700 int ret;
7701#endif /* NL80211_SUPPORT */
7702
7703 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7704 if (system(buf) != 0) {
7705 sigma_dut_print(dut, DUT_MSG_ERROR,
7706 "iwpriv %s nss failed", intf);
7707 }
7708
7709#ifdef NL80211_SUPPORT
7710 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7711 if (ret) {
7712 sigma_dut_print(dut, DUT_MSG_ERROR,
7713 "Setting of MCS failed, ret:%d",
7714 ret);
7715 }
7716#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007717
7718 /* Disable STBC as default */
7719 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007720
7721 /* Disable AMSDU as default */
7722 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007723
7724#ifdef NL80211_SUPPORT
7725 /* HE fragmentation default off */
7726 if (sta_set_he_fragmentation(dut, intf,
7727 HE_FRAG_DISABLE)) {
7728 sigma_dut_print(dut, DUT_MSG_ERROR,
7729 "Setting of HE fragmentation failed");
7730 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007731
7732 /* set the beamformee NSTS(maximum number of
7733 * space-time streams) to default testbed config
7734 */
7735 if (sta_set_beamformee_sts(dut, intf, 3)) {
7736 sigma_dut_print(dut, DUT_MSG_ERROR,
7737 "Failed to set BeamformeeSTS");
7738 }
7739
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007740 /* +HTC-HE support default off */
7741 if (sta_set_he_htc_supp(dut, intf, 0)) {
7742 sigma_dut_print(dut, DUT_MSG_ERROR,
7743 "Setting of +HTC-HE support failed");
7744 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007745
7746 /* Set device HE capabilities to testbed default
7747 * configuration. */
7748 if (sta_set_he_testbed_def(dut, intf, 1)) {
7749 sigma_dut_print(dut, DUT_MSG_DEBUG,
7750 "Failed to set HE defaults");
7751 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007752
7753 /* Disable VHT support in 2.4 GHz for testbed */
7754 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007755#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007756
7757 /* Enable WEP/TKIP with HE capability in testbed */
7758 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
7759 sigma_dut_print(dut, DUT_MSG_ERROR,
7760 "Enabling HE config with WEP/TKIP failed");
7761 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007762 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007763
7764 /* Defaults in case of DUT */
7765 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07007766 /* Enable STBC by default */
7767 wcn_sta_set_stbc(dut, intf, "1");
7768
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007769 /* set nss to 2 */
7770 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
7771 if (system(buf) != 0) {
7772 sigma_dut_print(dut, DUT_MSG_ERROR,
7773 "iwpriv %s nss 2 failed", intf);
7774 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007775 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007776
7777#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07007778 /* Set HE_MCS to 0-11 */
7779 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007780 sigma_dut_print(dut, DUT_MSG_ERROR,
7781 "Setting of MCS failed");
7782 }
7783#endif /* NL80211_SUPPORT */
7784
7785 /* Disable WEP/TKIP with HE capability in DUT */
7786 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
7787 sigma_dut_print(dut, DUT_MSG_ERROR,
7788 "Enabling HE config with WEP/TKIP failed");
7789 }
7790 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007791 }
7792}
7793
7794
Jouni Malinenf7222712019-06-13 01:50:21 +03007795static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
7796 struct sigma_conn *conn,
7797 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007798{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007799 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007800 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007801 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007802 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307803 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007804
Jouni Malinenb21f0542019-11-04 17:53:38 +02007805 if (dut->station_ifname_2g &&
7806 strcmp(dut->station_ifname_2g, intf) == 0)
7807 dut->use_5g = 0;
7808 else if (dut->station_ifname_5g &&
7809 strcmp(dut->station_ifname_5g, intf) == 0)
7810 dut->use_5g = 1;
7811
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007812 if (!program)
7813 program = get_param(cmd, "prog");
7814 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007815 dut->device_type = STA_unknown;
7816 type = get_param(cmd, "type");
7817 if (type && strcasecmp(type, "Testbed") == 0)
7818 dut->device_type = STA_testbed;
7819 if (type && strcasecmp(type, "DUT") == 0)
7820 dut->device_type = STA_dut;
7821
7822 if (dut->program == PROGRAM_TDLS) {
7823 /* Clear TDLS testing mode */
7824 wpa_command(intf, "SET tdls_disabled 0");
7825 wpa_command(intf, "SET tdls_testing 0");
7826 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007827 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05307828 /* Enable the WCN driver in TDLS Explicit trigger mode
7829 */
7830 wpa_command(intf, "SET tdls_external_control 0");
7831 wpa_command(intf, "SET tdls_trigger_control 0");
7832 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007833 }
7834
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007835#ifdef MIRACAST
7836 if (dut->program == PROGRAM_WFD ||
7837 dut->program == PROGRAM_DISPLAYR2)
7838 miracast_sta_reset_default(dut, conn, cmd);
7839#endif /* MIRACAST */
7840
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007841 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007842 case DRIVER_ATHEROS:
7843 sta_reset_default_ath(dut, intf, type);
7844 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007845 case DRIVER_WCN:
7846 sta_reset_default_wcn(dut, intf, type);
7847 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007848 default:
7849 break;
7850 }
7851
7852#ifdef ANDROID_NAN
7853 if (dut->program == PROGRAM_NAN)
7854 nan_cmd_sta_reset_default(dut, conn, cmd);
7855#endif /* ANDROID_NAN */
7856
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05307857 if (dut->program == PROGRAM_LOC &&
7858 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
7859 return ERROR_SEND_STATUS;
7860
Jouni Malinenba630452018-06-22 11:49:59 +03007861 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007862 unlink("SP/wi-fi.org/pps.xml");
7863 if (system("rm -r SP/*") != 0) {
7864 }
7865 unlink("next-client-cert.pem");
7866 unlink("next-client-key.pem");
7867 }
7868
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007869 /* For WPS program of the 60 GHz band the band type needs to be saved */
7870 if (dut->program == PROGRAM_WPS) {
7871 if (band && strcasecmp(band, "60GHz") == 0) {
7872 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007873 /* For 60 GHz enable WPS for WPS TCs */
7874 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007875 } else {
7876 dut->band = WPS_BAND_NON_60G;
7877 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007878 } else if (dut->program == PROGRAM_60GHZ) {
7879 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
7880 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007881 }
7882
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02007883 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007884 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007885 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007886
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007887 sigma_dut_print(dut, DUT_MSG_INFO,
7888 "WPS 60 GHz program, wps_disable = %d",
7889 dut->wps_disable);
7890
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007891 if (!dev_role) {
7892 send_resp(dut, conn, SIGMA_ERROR,
7893 "errorCode,Missing DevRole argument");
7894 return 0;
7895 }
7896
7897 if (strcasecmp(dev_role, "STA") == 0)
7898 dut->dev_role = DEVROLE_STA;
7899 else if (strcasecmp(dev_role, "PCP") == 0)
7900 dut->dev_role = DEVROLE_PCP;
7901 else {
7902 send_resp(dut, conn, SIGMA_ERROR,
7903 "errorCode,Unknown DevRole");
7904 return 0;
7905 }
7906
7907 if (dut->device_type == STA_unknown) {
7908 sigma_dut_print(dut, DUT_MSG_ERROR,
7909 "Device type is not STA testbed or DUT");
7910 send_resp(dut, conn, SIGMA_ERROR,
7911 "errorCode,Unknown device type");
7912 return 0;
7913 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007914
7915 sigma_dut_print(dut, DUT_MSG_DEBUG,
7916 "Setting msdu_size to MAX: 7912");
7917 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007918 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007919
7920 if (system(buf) != 0) {
7921 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
7922 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007923 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007924 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007925
7926 if (sta_set_force_mcs(dut, 0, 1)) {
7927 sigma_dut_print(dut, DUT_MSG_ERROR,
7928 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007929 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007930 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007931 }
7932
7933 wpa_command(intf, "WPS_ER_STOP");
7934 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05307935 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007936 wpa_command(intf, "SET radio_disabled 0");
7937
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007938 dut->wps_forced_version = 0;
7939
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007940 if (dut->wsc_fragment) {
7941 dut->wsc_fragment = 0;
7942 wpa_command(intf, "SET device_name Test client");
7943 wpa_command(intf, "SET manufacturer ");
7944 wpa_command(intf, "SET model_name ");
7945 wpa_command(intf, "SET model_number ");
7946 wpa_command(intf, "SET serial_number ");
7947 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02007948 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
7949 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
7950 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
7951 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007952
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007953 if (dut->tmp_mac_addr && dut->set_macaddr) {
7954 dut->tmp_mac_addr = 0;
7955 if (system(dut->set_macaddr) != 0) {
7956 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
7957 "temporary MAC address");
7958 }
7959 }
7960
7961 set_ps(intf, dut, 0);
7962
Jouni Malinenba630452018-06-22 11:49:59 +03007963 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
7964 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007965 wpa_command(intf, "SET interworking 1");
7966 wpa_command(intf, "SET hs20 1");
7967 }
7968
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007969 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007970 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007971 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007972 wpa_command(intf, "SET pmf 1");
7973 } else {
7974 wpa_command(intf, "SET pmf 0");
7975 }
7976
7977 hs2_clear_credentials(intf);
7978 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
7979 wpa_command(intf, "SET access_network_type 15");
7980
7981 static_ip_file(0, NULL, NULL, NULL);
7982 kill_dhcp_client(dut, intf);
7983 clear_ip_addr(dut, intf);
7984
7985 dut->er_oper_performed = 0;
7986 dut->er_oper_bssid[0] = '\0';
7987
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007988 if (dut->program == PROGRAM_LOC) {
7989 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007990 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007991 }
7992
Ashwini Patil00402582017-04-13 12:29:39 +05307993 if (dut->program == PROGRAM_MBO) {
7994 free(dut->non_pref_ch_list);
7995 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05307996 free(dut->btm_query_cand_list);
7997 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05307998 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05307999 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05308000 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05308001 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05308002 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05308003 }
8004
Jouni Malinen3c367e82017-06-23 17:01:47 +03008005 free(dut->rsne_override);
8006 dut->rsne_override = NULL;
8007
Jouni Malinen68143132017-09-02 02:34:08 +03008008 free(dut->sae_commit_override);
8009 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03008010 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02008011 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03008012
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008013 dut->sta_associate_wait_connect = 0;
8014 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03008015 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008016 dut->sta_tod_policy = 0;
8017
Jouni Malinend86e5822017-08-29 03:55:32 +03008018 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02008019 free(dut->dpp_peer_uri);
8020 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02008021 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02008022 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03008023 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03008024
Jouni Malinenfac9cad2017-10-10 18:35:55 +03008025 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
8026
vamsi krishnaa2799492017-12-05 14:28:01 +05308027 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308028 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05308029 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05308030 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
8031 dut->fils_hlp = 0;
8032#ifdef ANDROID
8033 hlp_thread_cleanup(dut);
8034#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05308035 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308036
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308037 if (dut->program == PROGRAM_QM)
8038 wpa_command(intf, "SET interworking 1");
8039
Jouni Malinen8179fee2019-03-28 03:19:47 +02008040 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03008041 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02008042
Sunil Dutt076081f2018-02-05 19:45:50 +05308043#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008044 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05308045 dut->config_rsnie == 1) {
8046 dut->config_rsnie = 0;
8047 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05308048 }
8049#endif /* NL80211_SUPPORT */
8050
Sunil Duttfebf8a82018-02-09 18:50:13 +05308051 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
8052 dut->dev_role = DEVROLE_STA_CFON;
8053 return sta_cfon_reset_default(dut, conn, cmd);
8054 }
8055
Jouni Malinen439352d2018-09-13 03:42:23 +03008056 wpa_command(intf, "SET setband AUTO");
8057
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308058 dut->ocvc = 0;
8059
Sunil Duttfebf8a82018-02-09 18:50:13 +05308060 if (dut->program != PROGRAM_VHT)
8061 return cmd_sta_p2p_reset(dut, conn, cmd);
8062
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08008063 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008064}
8065
8066
Jouni Malinenf7222712019-06-13 01:50:21 +03008067static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
8068 struct sigma_conn *conn,
8069 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008070{
8071 const char *program = get_param(cmd, "Program");
8072
8073 if (program == NULL)
8074 return -1;
8075#ifdef ANDROID_NAN
8076 if (strcasecmp(program, "NAN") == 0)
8077 return nan_cmd_sta_get_events(dut, conn, cmd);
8078#endif /* ANDROID_NAN */
8079 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8080 return 0;
8081}
8082
8083
Jouni Malinen82905202018-04-29 17:20:10 +03008084static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
8085 struct sigma_cmd *cmd)
8086{
8087 const char *url = get_param(cmd, "url");
8088 const char *method = get_param(cmd, "method");
8089 pid_t pid;
8090 int status;
8091
8092 if (!url || !method)
8093 return -1;
8094
8095 /* TODO: Add support for method,post */
8096 if (strcasecmp(method, "get") != 0) {
8097 send_resp(dut, conn, SIGMA_ERROR,
8098 "ErrorCode,Unsupported method");
8099 return 0;
8100 }
8101
8102 pid = fork();
8103 if (pid < 0) {
8104 perror("fork");
8105 return -1;
8106 }
8107
8108 if (pid == 0) {
8109 char * argv[5] = { "wget", "-O", "/dev/null",
8110 (char *) url, NULL };
8111
8112 execv("/usr/bin/wget", argv);
8113 perror("execv");
8114 exit(0);
8115 return -1;
8116 }
8117
8118 if (waitpid(pid, &status, 0) < 0) {
8119 perror("waitpid");
8120 return -1;
8121 }
8122
8123 if (WIFEXITED(status)) {
8124 const char *errmsg;
8125
8126 if (WEXITSTATUS(status) == 0)
8127 return 1;
8128 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
8129 WEXITSTATUS(status));
8130 switch (WEXITSTATUS(status)) {
8131 case 4:
8132 errmsg = "errmsg,Network failure";
8133 break;
8134 case 8:
8135 errmsg = "errmsg,Server issued an error response";
8136 break;
8137 default:
8138 errmsg = "errmsg,Unknown failure from wget";
8139 break;
8140 }
8141 send_resp(dut, conn, SIGMA_ERROR, errmsg);
8142 return 0;
8143 }
8144
8145 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
8146 return 0;
8147}
8148
8149
Jouni Malinenf7222712019-06-13 01:50:21 +03008150static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
8151 struct sigma_conn *conn,
8152 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008153{
8154 const char *program = get_param(cmd, "Prog");
8155
Jouni Malinen82905202018-04-29 17:20:10 +03008156 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008157 return -1;
8158#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03008159 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008160 return nan_cmd_sta_exec_action(dut, conn, cmd);
8161#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03008162
8163 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07008164 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03008165
8166 if (get_param(cmd, "url"))
8167 return sta_exec_action_url(dut, conn, cmd);
8168
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008169 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8170 return 0;
8171}
8172
8173
Jouni Malinenf7222712019-06-13 01:50:21 +03008174static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
8175 struct sigma_conn *conn,
8176 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008177{
8178 const char *intf = get_param(cmd, "Interface");
8179 const char *val, *mcs32, *rate;
8180
8181 val = get_param(cmd, "GREENFIELD");
8182 if (val) {
8183 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
8184 /* Enable GD */
8185 send_resp(dut, conn, SIGMA_ERROR,
8186 "ErrorCode,GF not supported");
8187 return 0;
8188 }
8189 }
8190
8191 val = get_param(cmd, "SGI20");
8192 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008193 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008194 case DRIVER_ATHEROS:
8195 ath_sta_set_sgi(dut, intf, val);
8196 break;
8197 default:
8198 send_resp(dut, conn, SIGMA_ERROR,
8199 "ErrorCode,SGI20 not supported");
8200 return 0;
8201 }
8202 }
8203
8204 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
8205 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
8206 if (mcs32 && rate) {
8207 /* TODO */
8208 send_resp(dut, conn, SIGMA_ERROR,
8209 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
8210 return 0;
8211 } else if (mcs32 && !rate) {
8212 /* TODO */
8213 send_resp(dut, conn, SIGMA_ERROR,
8214 "ErrorCode,MCS32 not supported");
8215 return 0;
8216 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008217 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008218 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008219 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008220 ath_sta_set_11nrates(dut, intf, rate);
8221 break;
8222 default:
8223 send_resp(dut, conn, SIGMA_ERROR,
8224 "ErrorCode,MCS32_FIXEDRATE not supported");
8225 return 0;
8226 }
8227 }
8228
8229 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8230}
8231
8232
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008233static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8234 int mcs_config)
8235{
8236#ifdef NL80211_SUPPORT
8237 int ret;
8238
8239 switch (mcs_config) {
8240 case HE_80_MCS0_7:
8241 case HE_80_MCS0_9:
8242 case HE_80_MCS0_11:
8243 ret = sta_set_he_mcs(dut, intf, mcs_config);
8244 if (ret) {
8245 sigma_dut_print(dut, DUT_MSG_ERROR,
8246 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8247 mcs_config, ret);
8248 }
8249 break;
8250 default:
8251 sigma_dut_print(dut, DUT_MSG_ERROR,
8252 "cmd_set_max_he_mcs: Invalid mcs %d",
8253 mcs_config);
8254 break;
8255 }
8256#else /* NL80211_SUPPORT */
8257 sigma_dut_print(dut, DUT_MSG_ERROR,
8258 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8259#endif /* NL80211_SUPPORT */
8260}
8261
8262
Arif Hussain480d5f42019-03-12 14:40:42 -07008263static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8264 struct sigma_cmd *cmd)
8265{
8266#ifdef NL80211_SUPPORT
8267 struct nlattr *params;
8268 struct nlattr *attr;
8269 struct nlattr *attr1;
8270 struct nl_msg *msg;
8271 int ifindex, ret;
8272 const char *val;
8273 const char *intf = get_param(cmd, "Interface");
8274 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8275 wake_interval_mantissa = 512;
8276 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
8277 protection = 0;
8278
8279 ifindex = if_nametoindex(intf);
8280 if (ifindex == 0) {
8281 sigma_dut_print(dut, DUT_MSG_ERROR,
8282 "%s: Index for interface %s failed",
8283 __func__, intf);
8284 return -1;
8285 }
8286
8287 val = get_param(cmd, "FlowType");
8288 if (val) {
8289 flow_type = atoi(val);
8290 if (flow_type != 0 && flow_type != 1) {
8291 sigma_dut_print(dut, DUT_MSG_ERROR,
8292 "TWT: Invalid FlowType %d", flow_type);
8293 return -1;
8294 }
8295 }
8296
8297 val = get_param(cmd, "TWT_Trigger");
8298 if (val) {
8299 twt_trigger = atoi(val);
8300 if (twt_trigger != 0 && twt_trigger != 1) {
8301 sigma_dut_print(dut, DUT_MSG_ERROR,
8302 "TWT: Invalid TWT_Trigger %d",
8303 twt_trigger);
8304 return -1;
8305 }
8306 }
8307
8308 val = get_param(cmd, "Protection");
8309 if (val) {
8310 protection = atoi(val);
8311 if (protection != 0 && protection != 1) {
8312 sigma_dut_print(dut, DUT_MSG_ERROR,
8313 "TWT: Invalid Protection %d",
8314 protection);
8315 return -1;
8316 }
8317 }
8318
8319 val = get_param(cmd, "TargetWakeTime");
8320 if (val)
8321 target_wake_time = atoi(val);
8322
8323 val = get_param(cmd, "WakeIntervalMantissa");
8324 if (val)
8325 wake_interval_mantissa = atoi(val);
8326
8327 val = get_param(cmd, "WakeIntervalExp");
8328 if (val)
8329 wake_interval_exp = atoi(val);
8330
8331 val = get_param(cmd, "NominalMinWakeDur");
8332 if (val)
8333 nominal_min_wake_dur = atoi(val);
8334
8335 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8336 NL80211_CMD_VENDOR)) ||
8337 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8338 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8339 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8340 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8341 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8342 !(params = nla_nest_start(
8343 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
8344 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8345 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8346 wake_interval_exp) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008347 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, 1) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008348 (twt_trigger &&
8349 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008350 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8351 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008352 (protection &&
8353 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008354 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8355 target_wake_time) ||
8356 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8357 nominal_min_wake_dur) ||
8358 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8359 wake_interval_mantissa)) {
8360 sigma_dut_print(dut, DUT_MSG_ERROR,
8361 "%s: err in adding vendor_cmd and vendor_data",
8362 __func__);
8363 nlmsg_free(msg);
8364 return -1;
8365 }
8366 nla_nest_end(msg, attr1);
8367 nla_nest_end(msg, params);
8368 nla_nest_end(msg, attr);
8369
8370 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8371 if (ret) {
8372 sigma_dut_print(dut, DUT_MSG_ERROR,
8373 "%s: err in send_and_recv_msgs, ret=%d",
8374 __func__, ret);
8375 }
8376
8377 return ret;
8378#else /* NL80211_SUPPORT */
8379 sigma_dut_print(dut, DUT_MSG_ERROR,
8380 "TWT request cannot be done without NL80211_SUPPORT defined");
8381 return -1;
8382#endif /* NL80211_SUPPORT */
8383}
8384
8385
8386static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8387 struct sigma_cmd *cmd)
8388{
8389 #ifdef NL80211_SUPPORT
8390 struct nlattr *params;
8391 struct nlattr *attr;
8392 struct nlattr *attr1;
8393 int ifindex, ret;
8394 struct nl_msg *msg;
8395 const char *intf = get_param(cmd, "Interface");
8396
8397 ifindex = if_nametoindex(intf);
8398 if (ifindex == 0) {
8399 sigma_dut_print(dut, DUT_MSG_ERROR,
8400 "%s: Index for interface %s failed",
8401 __func__, intf);
8402 return -1;
8403 }
8404
8405 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8406 NL80211_CMD_VENDOR)) ||
8407 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8408 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8409 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8410 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8411 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8412 !(params = nla_nest_start(
8413 msg,
8414 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8415 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8416 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8417 sigma_dut_print(dut, DUT_MSG_ERROR,
8418 "%s: err in adding vendor_cmd and vendor_data",
8419 __func__);
8420 nlmsg_free(msg);
8421 return -1;
8422 }
8423 nla_nest_end(msg, attr1);
8424 nla_nest_end(msg, params);
8425 nla_nest_end(msg, attr);
8426
8427 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8428 if (ret) {
8429 sigma_dut_print(dut, DUT_MSG_ERROR,
8430 "%s: err in send_and_recv_msgs, ret=%d",
8431 __func__, ret);
8432 }
8433
8434 return ret;
8435#else /* NL80211_SUPPORT */
8436 sigma_dut_print(dut, DUT_MSG_ERROR,
8437 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8438 return -1;
8439#endif /* NL80211_SUPPORT */
8440}
8441
8442
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008443static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8444 struct sigma_cmd *cmd)
8445{
8446#ifdef NL80211_SUPPORT
8447 struct nlattr *params;
8448 struct nlattr *attr;
8449 struct nlattr *attr1;
8450 struct nl_msg *msg;
8451 int ifindex, ret;
8452 const char *val;
8453 const char *intf = get_param(cmd, "Interface");
8454 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8455 ulmu_data_dis = 0;
8456
8457 ifindex = if_nametoindex(intf);
8458 if (ifindex == 0) {
8459 sigma_dut_print(dut, DUT_MSG_ERROR,
8460 "%s: Index for interface %s failed",
8461 __func__, intf);
8462 return -1;
8463 }
8464 val = get_param(cmd, "OMCtrl_RxNSS");
8465 if (val)
8466 rx_nss = atoi(val);
8467
8468 val = get_param(cmd, "OMCtrl_ChnlWidth");
8469 if (val)
8470 ch_bw = atoi(val);
8471
8472 val = get_param(cmd, "OMCtrl_ULMUDisable");
8473 if (val)
8474 ulmu_dis = atoi(val);
8475
8476 val = get_param(cmd, "OMCtrl_TxNSTS");
8477 if (val)
8478 tx_nsts = atoi(val);
8479
8480 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8481 if (val)
8482 ulmu_data_dis = atoi(val);
8483
8484 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8485 NL80211_CMD_VENDOR)) ||
8486 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8487 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8488 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8489 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8490 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8491 !(params = nla_nest_start(
8492 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8493 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8494 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8495 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8496 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8497 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8498 ulmu_data_dis) ||
8499 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8500 ulmu_dis)) {
8501 sigma_dut_print(dut, DUT_MSG_ERROR,
8502 "%s: err in adding vendor_cmd and vendor_data",
8503 __func__);
8504 nlmsg_free(msg);
8505 return -1;
8506 }
8507 nla_nest_end(msg, attr1);
8508 nla_nest_end(msg, params);
8509 nla_nest_end(msg, attr);
8510
8511 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8512 if (ret) {
8513 sigma_dut_print(dut, DUT_MSG_ERROR,
8514 "%s: err in send_and_recv_msgs, ret=%d",
8515 __func__, ret);
8516 }
8517
8518 return ret;
8519#else /* NL80211_SUPPORT */
8520 sigma_dut_print(dut, DUT_MSG_ERROR,
8521 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8522 return -1;
8523#endif /* NL80211_SUPPORT */
8524}
8525
8526
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008527static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8528 struct sigma_conn *conn,
8529 struct sigma_cmd *cmd)
8530{
8531 const char *intf = get_param(cmd, "Interface");
8532 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008533 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008534 int tkip = -1;
8535 int wep = -1;
8536
Arif Hussaina37e9552018-06-20 17:05:59 -07008537 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008538 val = get_param(cmd, "SGI80");
8539 if (val) {
8540 int sgi80;
8541
8542 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008543 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008544 }
8545
8546 val = get_param(cmd, "TxBF");
8547 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008548 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008549 case DRIVER_WCN:
8550 if (sta_set_tx_beamformee(dut, intf, 1)) {
8551 send_resp(dut, conn, SIGMA_ERROR,
8552 "ErrorCode,Failed to set TX beamformee enable");
8553 return 0;
8554 }
8555 break;
8556 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008557 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008558 send_resp(dut, conn, SIGMA_ERROR,
8559 "ErrorCode,Setting vhtsubfee failed");
8560 return 0;
8561 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008562 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008563 send_resp(dut, conn, SIGMA_ERROR,
8564 "ErrorCode,Setting vhtsubfer failed");
8565 return 0;
8566 }
8567 break;
8568 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008569 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008570 "Unsupported driver type");
8571 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008572 }
8573 }
8574
8575 val = get_param(cmd, "MU_TxBF");
8576 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008577 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008578 case DRIVER_ATHEROS:
8579 ath_sta_set_txsp_stream(dut, intf, "1SS");
8580 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008581 run_iwpriv(dut, intf, "vhtmubfee 1");
8582 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308583 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008584 case DRIVER_WCN:
8585 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8586 send_resp(dut, conn, SIGMA_ERROR,
8587 "ErrorCode,Failed to set RX/TXSP_STREAM");
8588 return 0;
8589 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308590 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008591 default:
8592 sigma_dut_print(dut, DUT_MSG_ERROR,
8593 "Setting SP_STREAM not supported");
8594 break;
8595 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008596 }
8597
8598 val = get_param(cmd, "LDPC");
8599 if (val) {
8600 int ldpc;
8601
8602 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008603 run_iwpriv(dut, intf, "ldpc %d", ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008604 }
8605
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008606 val = get_param(cmd, "BCC");
8607 if (val) {
8608 int bcc;
8609
8610 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8611 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8612 * is mutually exclusive to bcc */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008613 run_iwpriv(dut, intf, "ldpc %d", !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008614 }
8615
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008616 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8617 if (val && dut->sta_nss == 1)
8618 cmd_set_max_he_mcs(dut, intf, atoi(val));
8619
8620 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8621 if (val && dut->sta_nss == 2)
8622 cmd_set_max_he_mcs(dut, intf, atoi(val));
8623
Arif Hussainac6c5112018-05-25 17:34:00 -07008624 val = get_param(cmd, "MCS_FixedRate");
8625 if (val) {
8626#ifdef NL80211_SUPPORT
8627 int mcs, ratecode = 0;
8628 enum he_mcs_config mcs_config;
8629 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008630 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008631
8632 ratecode = (0x07 & dut->sta_nss) << 5;
8633 mcs = atoi(val);
8634 /* Add the MCS to the ratecode */
8635 if (mcs >= 0 && mcs <= 11) {
8636 ratecode += mcs;
8637 if (dut->device_type == STA_testbed &&
8638 mcs > 7 && mcs <= 11) {
8639 if (mcs <= 9)
8640 mcs_config = HE_80_MCS0_9;
8641 else
8642 mcs_config = HE_80_MCS0_11;
8643 ret = sta_set_he_mcs(dut, intf, mcs_config);
8644 if (ret) {
8645 sigma_dut_print(dut, DUT_MSG_ERROR,
8646 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8647 mcs, mcs_config, ret);
8648 }
8649 }
8650 snprintf(buf, sizeof(buf),
8651 "iwpriv %s set_11ax_rate 0x%03x",
8652 intf, ratecode);
8653 if (system(buf) != 0) {
8654 sigma_dut_print(dut, DUT_MSG_ERROR,
8655 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8656 ratecode);
8657 }
8658 } else {
8659 sigma_dut_print(dut, DUT_MSG_ERROR,
8660 "MCS_FixedRate: HE MCS %d not supported",
8661 mcs);
8662 }
8663#else /* NL80211_SUPPORT */
8664 sigma_dut_print(dut, DUT_MSG_ERROR,
8665 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8666#endif /* NL80211_SUPPORT */
8667 }
8668
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008669 val = get_param(cmd, "opt_md_notif_ie");
8670 if (val) {
8671 char *result = NULL;
8672 char delim[] = ";";
8673 char token[30];
8674 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308675 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008676
Peng Xub8fc5cc2017-05-10 17:27:28 -07008677 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308678 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008679
8680 /* Extract the NSS information */
8681 if (result) {
8682 value = atoi(result);
8683 switch (value) {
8684 case 1:
8685 config_val = 1;
8686 break;
8687 case 2:
8688 config_val = 3;
8689 break;
8690 case 3:
8691 config_val = 7;
8692 break;
8693 case 4:
8694 config_val = 15;
8695 break;
8696 default:
8697 config_val = 3;
8698 break;
8699 }
8700
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008701 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8702 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008703
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008704 }
8705
8706 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308707 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008708 if (result) {
8709 value = atoi(result);
8710 switch (value) {
8711 case 20:
8712 config_val = 0;
8713 break;
8714 case 40:
8715 config_val = 1;
8716 break;
8717 case 80:
8718 config_val = 2;
8719 break;
8720 case 160:
8721 config_val = 3;
8722 break;
8723 default:
8724 config_val = 2;
8725 break;
8726 }
8727
8728 dut->chwidth = config_val;
8729
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008730 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008731 }
8732
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008733 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008734 }
8735
8736 val = get_param(cmd, "nss_mcs_cap");
8737 if (val) {
8738 int nss, mcs;
8739 char token[20];
8740 char *result = NULL;
8741 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308742 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008743
Peng Xub8fc5cc2017-05-10 17:27:28 -07008744 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308745 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308746 if (!result) {
8747 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008748 "NSS not specified");
8749 send_resp(dut, conn, SIGMA_ERROR,
8750 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308751 return 0;
8752 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008753 nss = atoi(result);
8754
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008755 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07008756 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008757
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308758 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008759 if (result == NULL) {
8760 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008761 "MCS not specified");
8762 send_resp(dut, conn, SIGMA_ERROR,
8763 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008764 return 0;
8765 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308766 result = strtok_r(result, "-", &saveptr);
8767 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308768 if (!result) {
8769 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008770 "MCS not specified");
8771 send_resp(dut, conn, SIGMA_ERROR,
8772 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308773 return 0;
8774 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008775 mcs = atoi(result);
8776
Arif Hussaina37e9552018-06-20 17:05:59 -07008777 if (program && strcasecmp(program, "HE") == 0) {
8778#ifdef NL80211_SUPPORT
8779 enum he_mcs_config mcs_config;
8780 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008781
Arif Hussaina37e9552018-06-20 17:05:59 -07008782 if (mcs >= 0 && mcs <= 7) {
8783 mcs_config = HE_80_MCS0_7;
8784 } else if (mcs > 7 && mcs <= 9) {
8785 mcs_config = HE_80_MCS0_9;
8786 } else if (mcs > 9 && mcs <= 11) {
8787 mcs_config = HE_80_MCS0_11;
8788 } else {
8789 sigma_dut_print(dut, DUT_MSG_ERROR,
8790 "nss_mcs_cap: HE: Invalid mcs: %d",
8791 mcs);
8792 send_resp(dut, conn, SIGMA_ERROR,
8793 "errorCode,Invalid MCS");
8794 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008795 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008796
8797 ret = sta_set_he_mcs(dut, intf, mcs_config);
8798 if (ret) {
8799 sigma_dut_print(dut, DUT_MSG_ERROR,
8800 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
8801 mcs_config, ret);
8802 send_resp(dut, conn, SIGMA_ERROR,
8803 "errorCode,Failed to set MCS");
8804 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008805 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008806#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008807 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008808 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
8809#endif /* NL80211_SUPPORT */
8810 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008811 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07008812
8813 switch (nss) {
8814 case 1:
8815 switch (mcs) {
8816 case 7:
8817 vht_mcsmap = 0xfffc;
8818 break;
8819 case 8:
8820 vht_mcsmap = 0xfffd;
8821 break;
8822 case 9:
8823 vht_mcsmap = 0xfffe;
8824 break;
8825 default:
8826 vht_mcsmap = 0xfffe;
8827 break;
8828 }
8829 break;
8830 case 2:
8831 switch (mcs) {
8832 case 7:
8833 vht_mcsmap = 0xfff0;
8834 break;
8835 case 8:
8836 vht_mcsmap = 0xfff5;
8837 break;
8838 case 9:
8839 vht_mcsmap = 0xfffa;
8840 break;
8841 default:
8842 vht_mcsmap = 0xfffa;
8843 break;
8844 }
8845 break;
8846 case 3:
8847 switch (mcs) {
8848 case 7:
8849 vht_mcsmap = 0xffc0;
8850 break;
8851 case 8:
8852 vht_mcsmap = 0xffd5;
8853 break;
8854 case 9:
8855 vht_mcsmap = 0xffea;
8856 break;
8857 default:
8858 vht_mcsmap = 0xffea;
8859 break;
8860 }
8861 break;
8862 default:
8863 vht_mcsmap = 0xffea;
8864 break;
8865 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008866 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008867 }
8868 }
8869
8870 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
8871
8872 val = get_param(cmd, "Vht_tkip");
8873 if (val)
8874 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8875
8876 val = get_param(cmd, "Vht_wep");
8877 if (val)
8878 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8879
8880 if (tkip != -1 || wep != -1) {
8881 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008882 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008883 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008884 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008885 } else {
8886 sigma_dut_print(dut, DUT_MSG_ERROR,
8887 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
8888 return 0;
8889 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008890 }
8891
Arif Hussain55f00da2018-07-03 08:28:26 -07008892 val = get_param(cmd, "txBandwidth");
8893 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008894 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07008895 case DRIVER_WCN:
8896 if (wcn_sta_set_width(dut, intf, val) < 0) {
8897 send_resp(dut, conn, SIGMA_ERROR,
8898 "ErrorCode,Failed to set txBandwidth");
8899 return 0;
8900 }
8901 break;
8902 case DRIVER_ATHEROS:
8903 if (ath_set_width(dut, conn, intf, val) < 0) {
8904 send_resp(dut, conn, SIGMA_ERROR,
8905 "ErrorCode,Failed to set txBandwidth");
8906 return 0;
8907 }
8908 break;
8909 default:
8910 sigma_dut_print(dut, DUT_MSG_ERROR,
8911 "Setting txBandwidth not supported");
8912 break;
8913 }
8914 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008915
Arif Hussain9765f7d2018-07-03 08:28:26 -07008916 val = get_param(cmd, "BeamformeeSTS");
8917 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07008918 if (sta_set_tx_beamformee(dut, intf, 1)) {
8919 send_resp(dut, conn, SIGMA_ERROR,
8920 "ErrorCode,Failed to set TX beamformee enable");
8921 return 0;
8922 }
8923
Arif Hussain9765f7d2018-07-03 08:28:26 -07008924 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
8925 send_resp(dut, conn, SIGMA_ERROR,
8926 "ErrorCode,Failed to set BeamformeeSTS");
8927 return 0;
8928 }
8929 }
8930
Arif Hussain68d23f52018-07-11 13:39:08 -07008931 val = get_param(cmd, "Trig_MAC_Padding_Dur");
8932 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008933#ifdef NL80211_SUPPORT
8934 enum qca_wlan_he_mac_padding_dur set_val;
8935
8936 switch (atoi(val)) {
8937 case 16:
8938 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
8939 break;
8940 case 8:
8941 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
8942 break;
8943 default:
8944 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
8945 break;
8946 }
8947 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008948 send_resp(dut, conn, SIGMA_ERROR,
8949 "ErrorCode,Failed to set MAC padding duration");
8950 return 0;
8951 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008952#else /* NL80211_SUPPORT */
8953 sigma_dut_print(dut, DUT_MSG_ERROR,
8954 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
8955#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008956 }
8957
Arif Hussain480d5f42019-03-12 14:40:42 -07008958 val = get_param(cmd, "TWT_ReqSupport");
8959 if (val) {
8960 int set_val;
8961
8962 if (strcasecmp(val, "Enable") == 0) {
8963 set_val = 1;
8964 } else if (strcasecmp(val, "Disable") == 0) {
8965 set_val = 0;
8966 } else {
8967 send_resp(dut, conn, SIGMA_ERROR,
8968 "ErrorCode,Invalid TWT_ReqSupport");
8969 return STATUS_SENT;
8970 }
8971
8972 if (sta_set_twt_req_support(dut, intf, set_val)) {
8973 sigma_dut_print(dut, DUT_MSG_ERROR,
8974 "Failed to set TWT req support %d",
8975 set_val);
8976 send_resp(dut, conn, SIGMA_ERROR,
8977 "ErrorCode,Failed to set TWT_ReqSupport");
8978 return STATUS_SENT;
8979 }
8980 }
8981
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008982 val = get_param(cmd, "MU_EDCA");
8983 if (val && (strcasecmp(val, "Override") == 0)) {
8984 if (sta_set_mu_edca_override(dut, intf, 1)) {
8985 send_resp(dut, conn, SIGMA_ERROR,
8986 "ErrorCode,Failed to set MU EDCA override");
8987 return 0;
8988 }
8989 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008990
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008991 val = get_param(cmd, "OMControl");
8992 if (val) {
8993 int set_val = 1;
8994
8995 if (strcasecmp(val, "Enable") == 0)
8996 set_val = 1;
8997 else if (strcasecmp(val, "Disable") == 0)
8998 set_val = 0;
8999
9000 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
9001 send_resp(dut, conn, SIGMA_ERROR,
9002 "ErrorCode,Failed to set OM ctrl supp");
9003 return 0;
9004 }
9005 }
9006
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009007 val = get_param(cmd, "ADDBAResp_BufSize");
9008 if (val) {
9009 int buf_size;
9010
9011 if (strcasecmp(val, "gt64") == 0)
9012 buf_size = 256;
9013 else
9014 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009015 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009016 sta_set_addba_buf_size(dut, intf, buf_size)) {
9017 send_resp(dut, conn, SIGMA_ERROR,
9018 "ErrorCode,set addbaresp_buff_size failed");
9019 return 0;
9020 }
9021 }
9022
9023 val = get_param(cmd, "ADDBAReq_BufSize");
9024 if (val) {
9025 int buf_size;
9026
9027 if (strcasecmp(val, "gt64") == 0)
9028 buf_size = 256;
9029 else
9030 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009031 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009032 sta_set_addba_buf_size(dut, intf, buf_size)) {
9033 send_resp(dut, conn, SIGMA_ERROR,
9034 "ErrorCode,set addbareq_buff_size failed");
9035 return 0;
9036 }
9037 }
9038
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009039 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9040}
9041
9042
9043static int sta_set_wireless_60g(struct sigma_dut *dut,
9044 struct sigma_conn *conn,
9045 struct sigma_cmd *cmd)
9046{
9047 const char *dev_role = get_param(cmd, "DevRole");
9048
9049 if (!dev_role) {
9050 send_resp(dut, conn, SIGMA_INVALID,
9051 "ErrorCode,DevRole not specified");
9052 return 0;
9053 }
9054
9055 if (strcasecmp(dev_role, "PCP") == 0)
9056 return sta_set_60g_pcp(dut, conn, cmd);
9057 if (strcasecmp(dev_role, "STA") == 0)
9058 return sta_set_60g_sta(dut, conn, cmd);
9059 send_resp(dut, conn, SIGMA_INVALID,
9060 "ErrorCode,DevRole not supported");
9061 return 0;
9062}
9063
9064
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309065static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
9066 struct sigma_cmd *cmd)
9067{
9068 int status;
9069 const char *intf = get_param(cmd, "Interface");
9070 const char *val = get_param(cmd, "DevRole");
9071
9072 if (val && strcasecmp(val, "STA-CFON") == 0) {
9073 status = sta_cfon_set_wireless(dut, conn, cmd);
9074 if (status)
9075 return status;
9076 }
9077 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9078}
9079
9080
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309081static int sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
9082 struct sigma_cmd *cmd)
9083{
9084 const char *intf = get_param(cmd, "Interface");
9085 const char *val;
9086
9087 val = get_param(cmd, "ocvc");
9088 if (val)
9089 dut->ocvc = atoi(val);
9090
9091 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9092}
9093
9094
Jouni Malinenf7222712019-06-13 01:50:21 +03009095static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
9096 struct sigma_conn *conn,
9097 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009098{
9099 const char *val;
9100
9101 val = get_param(cmd, "Program");
9102 if (val) {
9103 if (strcasecmp(val, "11n") == 0)
9104 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08009105 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009106 return cmd_sta_set_wireless_vht(dut, conn, cmd);
9107 if (strcasecmp(val, "60ghz") == 0)
9108 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309109 if (strcasecmp(val, "OCE") == 0)
9110 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02009111 /* sta_set_wireless in WPS program is only used for 60G */
9112 if (is_60g_sigma_dut(dut))
9113 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309114 if (strcasecmp(val, "WPA3") == 0)
9115 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009116 send_resp(dut, conn, SIGMA_ERROR,
9117 "ErrorCode,Program value not supported");
9118 } else {
9119 send_resp(dut, conn, SIGMA_ERROR,
9120 "ErrorCode,Program argument not available");
9121 }
9122
9123 return 0;
9124}
9125
9126
9127static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
9128 int tid)
9129{
9130 char buf[100];
9131 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
9132
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05309133 if (tid < 0 ||
9134 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
9135 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
9136 return;
9137 }
9138
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009139 /*
9140 * Two ways to ensure that addba request with a
9141 * non zero TID could be sent out. EV 117296
9142 */
9143 snprintf(buf, sizeof(buf),
9144 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
9145 tid);
9146 if (system(buf) != 0) {
9147 sigma_dut_print(dut, DUT_MSG_ERROR,
9148 "Ping did not send out");
9149 }
9150
9151 snprintf(buf, sizeof(buf),
9152 "iwconfig %s | grep Access | awk '{print $6}' > %s",
9153 intf, VI_QOS_TMP_FILE);
9154 if (system(buf) != 0)
9155 return;
9156
9157 snprintf(buf, sizeof(buf),
9158 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
9159 intf, VI_QOS_TMP_FILE);
9160 if (system(buf) != 0)
9161 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
9162
9163 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
9164 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
9165 if (system(buf) != 0) {
9166 sigma_dut_print(dut, DUT_MSG_ERROR,
9167 "VI_QOS_TEMP_FILE generation error failed");
9168 }
9169 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9170 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9171 if (system(buf) != 0) {
9172 sigma_dut_print(dut, DUT_MSG_ERROR,
9173 "VI_QOS_FILE generation failed");
9174 }
9175
9176 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9177 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9178 if (system(buf) != 0) {
9179 sigma_dut_print(dut, DUT_MSG_ERROR,
9180 "VI_QOS_FILE generation failed");
9181 }
9182
9183 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
9184 if (system(buf) != 0) {
9185 }
9186}
9187
9188
9189static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9190 struct sigma_cmd *cmd)
9191{
9192 const char *intf = get_param(cmd, "Interface");
9193 const char *val;
9194 int tid = 0;
9195 char buf[100];
9196
9197 val = get_param(cmd, "TID");
9198 if (val) {
9199 tid = atoi(val);
9200 if (tid)
9201 ath_sta_inject_frame(dut, intf, tid);
9202 }
9203
9204 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009205 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009206
9207 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
9208 if (system(buf) != 0) {
9209 sigma_dut_print(dut, DUT_MSG_ERROR,
9210 "wifitool senddelba failed");
9211 }
9212
9213 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
9214 if (system(buf) != 0) {
9215 sigma_dut_print(dut, DUT_MSG_ERROR,
9216 "wifitool sendaddba failed");
9217 }
9218
9219 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9220
9221 return 1;
9222}
9223
9224
Lior David9981b512017-01-20 13:16:40 +02009225#ifdef __linux__
9226
9227static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
9228 int agg_size)
9229{
9230 char dir[128], buf[128];
9231 FILE *f;
9232 regex_t re;
9233 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03009234 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02009235
9236 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
9237 sigma_dut_print(dut, DUT_MSG_ERROR,
9238 "failed to get wil6210 debugfs dir");
9239 return -1;
9240 }
9241
Jouni Malinen3aa72862019-05-29 23:14:51 +03009242 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
9243 if (res < 0 || res >= sizeof(buf))
9244 return -1;
Lior David9981b512017-01-20 13:16:40 +02009245 f = fopen(buf, "r");
9246 if (!f) {
9247 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009248 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009249 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9250 if (res < 0 || res >= sizeof(buf))
9251 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009252 f = fopen(buf, "r");
9253 if (!f) {
9254 sigma_dut_print(dut, DUT_MSG_ERROR,
9255 "failed to open: %s", buf);
9256 return -1;
9257 }
Lior David9981b512017-01-20 13:16:40 +02009258 }
9259
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009260 /* can be either VRING tx... or RING... */
9261 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009262 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9263 goto out;
9264 }
9265
9266 /* find TX VRING for the mac address */
9267 found = 0;
9268 while (fgets(buf, sizeof(buf), f)) {
9269 if (strcasestr(buf, dest_mac)) {
9270 found = 1;
9271 break;
9272 }
9273 }
9274
9275 if (!found) {
9276 sigma_dut_print(dut, DUT_MSG_ERROR,
9277 "no TX VRING for %s", dest_mac);
9278 goto out;
9279 }
9280
9281 /* extract VRING ID, "VRING tx_<id> = {" */
9282 if (!fgets(buf, sizeof(buf), f)) {
9283 sigma_dut_print(dut, DUT_MSG_ERROR,
9284 "no VRING start line for %s", dest_mac);
9285 goto out;
9286 }
9287
9288 rc = regexec(&re, buf, 2, m, 0);
9289 regfree(&re);
9290 if (rc || m[1].rm_so < 0) {
9291 sigma_dut_print(dut, DUT_MSG_ERROR,
9292 "no VRING TX ID for %s", dest_mac);
9293 goto out;
9294 }
9295 buf[m[1].rm_eo] = 0;
9296 vring_id = atoi(&buf[m[1].rm_so]);
9297
9298 /* send the addba command */
9299 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009300 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9301 if (res < 0 || res >= sizeof(buf))
9302 return -1;
Lior David9981b512017-01-20 13:16:40 +02009303 f = fopen(buf, "w");
9304 if (!f) {
9305 sigma_dut_print(dut, DUT_MSG_ERROR,
9306 "failed to open: %s", buf);
9307 return -1;
9308 }
9309
9310 fprintf(f, "add %d %d\n", vring_id, agg_size);
9311
9312 ret = 0;
9313
9314out:
9315 fclose(f);
9316
9317 return ret;
9318}
9319
9320
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009321int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9322 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009323{
9324 const char *val;
9325 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009326
9327 val = get_param(cmd, "TID");
9328 if (val) {
9329 tid = atoi(val);
9330 if (tid != 0) {
9331 sigma_dut_print(dut, DUT_MSG_ERROR,
9332 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9333 tid);
9334 }
9335 }
9336
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009337 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009338 if (!val) {
9339 sigma_dut_print(dut, DUT_MSG_ERROR,
9340 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009341 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009342 }
9343
Lior David9981b512017-01-20 13:16:40 +02009344 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009345 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009346
9347 return 1;
9348}
9349
Lior David9981b512017-01-20 13:16:40 +02009350#endif /* __linux__ */
9351
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009352
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009353static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9354 struct sigma_cmd *cmd)
9355{
9356#ifdef NL80211_SUPPORT
9357 const char *intf = get_param(cmd, "Interface");
9358 const char *val;
9359 int tid = -1;
9360 int bufsize = 64;
9361 struct nl_msg *msg;
9362 int ret = 0;
9363 struct nlattr *params;
9364 int ifindex;
9365
9366 val = get_param(cmd, "TID");
9367 if (val)
9368 tid = atoi(val);
9369
9370 if (tid == -1) {
9371 send_resp(dut, conn, SIGMA_ERROR,
9372 "ErrorCode,sta_send_addba tid invalid");
9373 return 0;
9374 }
9375
9376 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9377
9378 ifindex = if_nametoindex(intf);
9379 if (ifindex == 0) {
9380 sigma_dut_print(dut, DUT_MSG_ERROR,
9381 "%s: Index for interface %s failed",
9382 __func__, intf);
9383 send_resp(dut, conn, SIGMA_ERROR,
9384 "ErrorCode,sta_send_addba interface invalid");
9385 return 0;
9386 }
9387
9388 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9389 NL80211_CMD_VENDOR)) ||
9390 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9391 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9392 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9393 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9394 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9395 nla_put_u8(msg,
9396 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9397 QCA_WLAN_ADD_BA) ||
9398 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9399 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009400 nla_put_u16(msg,
9401 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9402 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009403 sigma_dut_print(dut, DUT_MSG_ERROR,
9404 "%s: err in adding vendor_cmd and vendor_data",
9405 __func__);
9406 nlmsg_free(msg);
9407 send_resp(dut, conn, SIGMA_ERROR,
9408 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9409 return 0;
9410 }
9411 nla_nest_end(msg, params);
9412
9413 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9414 if (ret) {
9415 sigma_dut_print(dut, DUT_MSG_ERROR,
9416 "%s: err in send_and_recv_msgs, ret=%d",
9417 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309418 if (ret == -EOPNOTSUPP)
9419 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009420 send_resp(dut, conn, SIGMA_ERROR,
9421 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9422 return 0;
9423 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009424#else /* NL80211_SUPPORT */
9425 sigma_dut_print(dut, DUT_MSG_ERROR,
9426 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009427#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309428
9429 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009430}
9431
9432
Jouni Malinenf7222712019-06-13 01:50:21 +03009433static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9434 struct sigma_conn *conn,
9435 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009436{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009437 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009438 case DRIVER_ATHEROS:
9439 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009440 case DRIVER_WCN:
9441 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009442#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009443 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009444 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009445#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009446 default:
9447 /*
9448 * There is no driver specific implementation for other drivers.
9449 * Ignore the command and report COMPLETE since the following
9450 * throughput test operation will end up sending ADDBA anyway.
9451 */
9452 return 1;
9453 }
9454}
9455
9456
9457int inject_eth_frame(int s, const void *data, size_t len,
9458 unsigned short ethtype, char *dst, char *src)
9459{
9460 struct iovec iov[4] = {
9461 {
9462 .iov_base = dst,
9463 .iov_len = ETH_ALEN,
9464 },
9465 {
9466 .iov_base = src,
9467 .iov_len = ETH_ALEN,
9468 },
9469 {
9470 .iov_base = &ethtype,
9471 .iov_len = sizeof(unsigned short),
9472 },
9473 {
9474 .iov_base = (void *) data,
9475 .iov_len = len,
9476 }
9477 };
9478 struct msghdr msg = {
9479 .msg_name = NULL,
9480 .msg_namelen = 0,
9481 .msg_iov = iov,
9482 .msg_iovlen = 4,
9483 .msg_control = NULL,
9484 .msg_controllen = 0,
9485 .msg_flags = 0,
9486 };
9487
9488 return sendmsg(s, &msg, 0);
9489}
9490
9491#if defined(__linux__) || defined(__QNXNTO__)
9492
9493int inject_frame(int s, const void *data, size_t len, int encrypt)
9494{
9495#define IEEE80211_RADIOTAP_F_WEP 0x04
9496#define IEEE80211_RADIOTAP_F_FRAG 0x08
9497 unsigned char rtap_hdr[] = {
9498 0x00, 0x00, /* radiotap version */
9499 0x0e, 0x00, /* radiotap length */
9500 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9501 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9502 0x00, /* padding */
9503 0x00, 0x00, /* RX and TX flags to indicate that */
9504 0x00, 0x00, /* this is the injected frame directly */
9505 };
9506 struct iovec iov[2] = {
9507 {
9508 .iov_base = &rtap_hdr,
9509 .iov_len = sizeof(rtap_hdr),
9510 },
9511 {
9512 .iov_base = (void *) data,
9513 .iov_len = len,
9514 }
9515 };
9516 struct msghdr msg = {
9517 .msg_name = NULL,
9518 .msg_namelen = 0,
9519 .msg_iov = iov,
9520 .msg_iovlen = 2,
9521 .msg_control = NULL,
9522 .msg_controllen = 0,
9523 .msg_flags = 0,
9524 };
9525
9526 if (encrypt)
9527 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9528
9529 return sendmsg(s, &msg, 0);
9530}
9531
9532
9533int open_monitor(const char *ifname)
9534{
9535#ifdef __QNXNTO__
9536 struct sockaddr_dl ll;
9537 int s;
9538
9539 memset(&ll, 0, sizeof(ll));
9540 ll.sdl_family = AF_LINK;
9541 ll.sdl_index = if_nametoindex(ifname);
9542 if (ll.sdl_index == 0) {
9543 perror("if_nametoindex");
9544 return -1;
9545 }
9546 s = socket(PF_INET, SOCK_RAW, 0);
9547#else /* __QNXNTO__ */
9548 struct sockaddr_ll ll;
9549 int s;
9550
9551 memset(&ll, 0, sizeof(ll));
9552 ll.sll_family = AF_PACKET;
9553 ll.sll_ifindex = if_nametoindex(ifname);
9554 if (ll.sll_ifindex == 0) {
9555 perror("if_nametoindex");
9556 return -1;
9557 }
9558 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9559#endif /* __QNXNTO__ */
9560 if (s < 0) {
9561 perror("socket[PF_PACKET,SOCK_RAW]");
9562 return -1;
9563 }
9564
9565 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9566 perror("monitor socket bind");
9567 close(s);
9568 return -1;
9569 }
9570
9571 return s;
9572}
9573
9574
9575static int hex2num(char c)
9576{
9577 if (c >= '0' && c <= '9')
9578 return c - '0';
9579 if (c >= 'a' && c <= 'f')
9580 return c - 'a' + 10;
9581 if (c >= 'A' && c <= 'F')
9582 return c - 'A' + 10;
9583 return -1;
9584}
9585
9586
9587int hwaddr_aton(const char *txt, unsigned char *addr)
9588{
9589 int i;
9590
9591 for (i = 0; i < 6; i++) {
9592 int a, b;
9593
9594 a = hex2num(*txt++);
9595 if (a < 0)
9596 return -1;
9597 b = hex2num(*txt++);
9598 if (b < 0)
9599 return -1;
9600 *addr++ = (a << 4) | b;
9601 if (i < 5 && *txt++ != ':')
9602 return -1;
9603 }
9604
9605 return 0;
9606}
9607
9608#endif /* defined(__linux__) || defined(__QNXNTO__) */
9609
9610enum send_frame_type {
9611 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9612};
9613enum send_frame_protection {
9614 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9615};
9616
9617
9618static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9619 enum send_frame_type frame,
9620 enum send_frame_protection protected,
9621 const char *dest)
9622{
9623#ifdef __linux__
9624 unsigned char buf[1000], *pos;
9625 int s, res;
9626 char bssid[20], addr[20];
9627 char result[32], ssid[100];
9628 size_t ssid_len;
9629
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009630 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009631 sizeof(result)) < 0 ||
9632 strncmp(result, "COMPLETED", 9) != 0) {
9633 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9634 return 0;
9635 }
9636
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009637 if (get_wpa_status(get_station_ifname(dut), "bssid",
9638 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009639 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9640 "current BSSID");
9641 return 0;
9642 }
9643
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009644 if (get_wpa_status(get_station_ifname(dut), "address",
9645 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009646 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9647 "own MAC address");
9648 return 0;
9649 }
9650
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009651 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009652 < 0) {
9653 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9654 "current SSID");
9655 return 0;
9656 }
9657 ssid_len = strlen(ssid);
9658
9659 pos = buf;
9660
9661 /* Frame Control */
9662 switch (frame) {
9663 case DISASSOC:
9664 *pos++ = 0xa0;
9665 break;
9666 case DEAUTH:
9667 *pos++ = 0xc0;
9668 break;
9669 case SAQUERY:
9670 *pos++ = 0xd0;
9671 break;
9672 case AUTH:
9673 *pos++ = 0xb0;
9674 break;
9675 case ASSOCREQ:
9676 *pos++ = 0x00;
9677 break;
9678 case REASSOCREQ:
9679 *pos++ = 0x20;
9680 break;
9681 case DLS_REQ:
9682 *pos++ = 0xd0;
9683 break;
9684 }
9685
9686 if (protected == INCORRECT_KEY)
9687 *pos++ = 0x40; /* Set Protected field to 1 */
9688 else
9689 *pos++ = 0x00;
9690
9691 /* Duration */
9692 *pos++ = 0x00;
9693 *pos++ = 0x00;
9694
9695 /* addr1 = DA (current AP) */
9696 hwaddr_aton(bssid, pos);
9697 pos += 6;
9698 /* addr2 = SA (own address) */
9699 hwaddr_aton(addr, pos);
9700 pos += 6;
9701 /* addr3 = BSSID (current AP) */
9702 hwaddr_aton(bssid, pos);
9703 pos += 6;
9704
9705 /* Seq# (to be filled by driver/mac80211) */
9706 *pos++ = 0x00;
9707 *pos++ = 0x00;
9708
9709 if (protected == INCORRECT_KEY) {
9710 /* CCMP parameters */
9711 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9712 pos += 8;
9713 }
9714
9715 if (protected == INCORRECT_KEY) {
9716 switch (frame) {
9717 case DEAUTH:
9718 /* Reason code (encrypted) */
9719 memcpy(pos, "\xa7\x39", 2);
9720 pos += 2;
9721 break;
9722 case DISASSOC:
9723 /* Reason code (encrypted) */
9724 memcpy(pos, "\xa7\x39", 2);
9725 pos += 2;
9726 break;
9727 case SAQUERY:
9728 /* Category|Action|TransID (encrypted) */
9729 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9730 pos += 4;
9731 break;
9732 default:
9733 return -1;
9734 }
9735
9736 /* CCMP MIC */
9737 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9738 pos += 8;
9739 } else {
9740 switch (frame) {
9741 case DEAUTH:
9742 /* reason code = 8 */
9743 *pos++ = 0x08;
9744 *pos++ = 0x00;
9745 break;
9746 case DISASSOC:
9747 /* reason code = 8 */
9748 *pos++ = 0x08;
9749 *pos++ = 0x00;
9750 break;
9751 case SAQUERY:
9752 /* Category - SA Query */
9753 *pos++ = 0x08;
9754 /* SA query Action - Request */
9755 *pos++ = 0x00;
9756 /* Transaction ID */
9757 *pos++ = 0x12;
9758 *pos++ = 0x34;
9759 break;
9760 case AUTH:
9761 /* Auth Alg (Open) */
9762 *pos++ = 0x00;
9763 *pos++ = 0x00;
9764 /* Seq# */
9765 *pos++ = 0x01;
9766 *pos++ = 0x00;
9767 /* Status code */
9768 *pos++ = 0x00;
9769 *pos++ = 0x00;
9770 break;
9771 case ASSOCREQ:
9772 /* Capability Information */
9773 *pos++ = 0x31;
9774 *pos++ = 0x04;
9775 /* Listen Interval */
9776 *pos++ = 0x0a;
9777 *pos++ = 0x00;
9778 /* SSID */
9779 *pos++ = 0x00;
9780 *pos++ = ssid_len;
9781 memcpy(pos, ssid, ssid_len);
9782 pos += ssid_len;
9783 /* Supported Rates */
9784 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9785 10);
9786 pos += 10;
9787 /* Extended Supported Rates */
9788 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9789 pos += 6;
9790 /* RSN */
9791 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9792 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9793 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9794 pos += 28;
9795 break;
9796 case REASSOCREQ:
9797 /* Capability Information */
9798 *pos++ = 0x31;
9799 *pos++ = 0x04;
9800 /* Listen Interval */
9801 *pos++ = 0x0a;
9802 *pos++ = 0x00;
9803 /* Current AP */
9804 hwaddr_aton(bssid, pos);
9805 pos += 6;
9806 /* SSID */
9807 *pos++ = 0x00;
9808 *pos++ = ssid_len;
9809 memcpy(pos, ssid, ssid_len);
9810 pos += ssid_len;
9811 /* Supported Rates */
9812 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9813 10);
9814 pos += 10;
9815 /* Extended Supported Rates */
9816 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9817 pos += 6;
9818 /* RSN */
9819 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9820 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9821 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9822 pos += 28;
9823 break;
9824 case DLS_REQ:
9825 /* Category - DLS */
9826 *pos++ = 0x02;
9827 /* DLS Action - Request */
9828 *pos++ = 0x00;
9829 /* Destination MACAddress */
9830 if (dest)
9831 hwaddr_aton(dest, pos);
9832 else
9833 memset(pos, 0, 6);
9834 pos += 6;
9835 /* Source MACAddress */
9836 hwaddr_aton(addr, pos);
9837 pos += 6;
9838 /* Capability Information */
9839 *pos++ = 0x10; /* Privacy */
9840 *pos++ = 0x06; /* QoS */
9841 /* DLS Timeout Value */
9842 *pos++ = 0x00;
9843 *pos++ = 0x01;
9844 /* Supported rates */
9845 *pos++ = 0x01;
9846 *pos++ = 0x08;
9847 *pos++ = 0x0c; /* 6 Mbps */
9848 *pos++ = 0x12; /* 9 Mbps */
9849 *pos++ = 0x18; /* 12 Mbps */
9850 *pos++ = 0x24; /* 18 Mbps */
9851 *pos++ = 0x30; /* 24 Mbps */
9852 *pos++ = 0x48; /* 36 Mbps */
9853 *pos++ = 0x60; /* 48 Mbps */
9854 *pos++ = 0x6c; /* 54 Mbps */
9855 /* TODO: Extended Supported Rates */
9856 /* TODO: HT Capabilities */
9857 break;
9858 }
9859 }
9860
9861 s = open_monitor("sigmadut");
9862 if (s < 0) {
9863 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9864 "monitor socket");
9865 return 0;
9866 }
9867
9868 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
9869 if (res < 0) {
9870 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9871 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309872 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009873 return 0;
9874 }
9875 if (res < pos - buf) {
9876 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
9877 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309878 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009879 return 0;
9880 }
9881
9882 close(s);
9883
9884 return 1;
9885#else /* __linux__ */
9886 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
9887 "yet supported");
9888 return 0;
9889#endif /* __linux__ */
9890}
9891
9892
9893static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
9894 struct sigma_conn *conn,
9895 struct sigma_cmd *cmd)
9896{
9897 const char *intf = get_param(cmd, "Interface");
9898 const char *sta, *val;
9899 unsigned char addr[ETH_ALEN];
9900 char buf[100];
9901
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +03009902 if (!intf)
9903 return -1;
9904
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009905 sta = get_param(cmd, "peer");
9906 if (sta == NULL)
9907 sta = get_param(cmd, "station");
9908 if (sta == NULL) {
9909 send_resp(dut, conn, SIGMA_ERROR,
9910 "ErrorCode,Missing peer address");
9911 return 0;
9912 }
9913 if (hwaddr_aton(sta, addr) < 0) {
9914 send_resp(dut, conn, SIGMA_ERROR,
9915 "ErrorCode,Invalid peer address");
9916 return 0;
9917 }
9918
9919 val = get_param(cmd, "type");
9920 if (val == NULL)
9921 return -1;
9922
9923 if (strcasecmp(val, "DISCOVERY") == 0) {
9924 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
9925 if (wpa_command(intf, buf) < 0) {
9926 send_resp(dut, conn, SIGMA_ERROR,
9927 "ErrorCode,Failed to send TDLS discovery");
9928 return 0;
9929 }
9930 return 1;
9931 }
9932
9933 if (strcasecmp(val, "SETUP") == 0) {
9934 int status = 0, timeout = 0;
9935
9936 val = get_param(cmd, "Status");
9937 if (val)
9938 status = atoi(val);
9939
9940 val = get_param(cmd, "Timeout");
9941 if (val)
9942 timeout = atoi(val);
9943
9944 if (status != 0 && status != 37) {
9945 send_resp(dut, conn, SIGMA_ERROR,
9946 "ErrorCode,Unsupported status value");
9947 return 0;
9948 }
9949
9950 if (timeout != 0 && timeout != 301) {
9951 send_resp(dut, conn, SIGMA_ERROR,
9952 "ErrorCode,Unsupported timeout value");
9953 return 0;
9954 }
9955
9956 if (status && timeout) {
9957 send_resp(dut, conn, SIGMA_ERROR,
9958 "ErrorCode,Unsupported timeout+status "
9959 "combination");
9960 return 0;
9961 }
9962
9963 if (status == 37 &&
9964 wpa_command(intf, "SET tdls_testing 0x200")) {
9965 send_resp(dut, conn, SIGMA_ERROR,
9966 "ErrorCode,Failed to enable "
9967 "decline setup response test mode");
9968 return 0;
9969 }
9970
9971 if (timeout == 301) {
9972 int res;
9973 if (dut->no_tpk_expiration)
9974 res = wpa_command(intf,
9975 "SET tdls_testing 0x108");
9976 else
9977 res = wpa_command(intf,
9978 "SET tdls_testing 0x8");
9979 if (res) {
9980 send_resp(dut, conn, SIGMA_ERROR,
9981 "ErrorCode,Failed to set short TPK "
9982 "lifetime");
9983 return 0;
9984 }
9985 }
9986
9987 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
9988 if (wpa_command(intf, buf) < 0) {
9989 send_resp(dut, conn, SIGMA_ERROR,
9990 "ErrorCode,Failed to send TDLS setup");
9991 return 0;
9992 }
9993 return 1;
9994 }
9995
9996 if (strcasecmp(val, "TEARDOWN") == 0) {
9997 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
9998 if (wpa_command(intf, buf) < 0) {
9999 send_resp(dut, conn, SIGMA_ERROR,
10000 "ErrorCode,Failed to send TDLS teardown");
10001 return 0;
10002 }
10003 return 1;
10004 }
10005
10006 send_resp(dut, conn, SIGMA_ERROR,
10007 "ErrorCode,Unsupported TDLS frame");
10008 return 0;
10009}
10010
10011
10012static int sta_ap_known(const char *ifname, const char *bssid)
10013{
10014 char buf[4096];
10015
Jouni Malinendd32f192018-09-15 02:55:19 +030010016 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010017 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
10018 return 0;
10019 if (strncmp(buf, "id=", 3) != 0)
10020 return 0;
10021 return 1;
10022}
10023
10024
10025static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
10026 const char *bssid)
10027{
10028 int res;
10029 struct wpa_ctrl *ctrl;
10030 char buf[256];
10031
10032 if (sta_ap_known(ifname, bssid))
10033 return 0;
10034 sigma_dut_print(dut, DUT_MSG_DEBUG,
10035 "AP not in BSS table - start scan");
10036
10037 ctrl = open_wpa_mon(ifname);
10038 if (ctrl == NULL) {
10039 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10040 "wpa_supplicant monitor connection");
10041 return -1;
10042 }
10043
10044 if (wpa_command(ifname, "SCAN") < 0) {
10045 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
10046 wpa_ctrl_detach(ctrl);
10047 wpa_ctrl_close(ctrl);
10048 return -1;
10049 }
10050
10051 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
10052 buf, sizeof(buf));
10053
10054 wpa_ctrl_detach(ctrl);
10055 wpa_ctrl_close(ctrl);
10056
10057 if (res < 0) {
10058 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
10059 return -1;
10060 }
10061
10062 if (sta_ap_known(ifname, bssid))
10063 return 0;
10064 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
10065 return -1;
10066}
10067
10068
10069static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
10070 struct sigma_conn *conn,
10071 struct sigma_cmd *cmd,
10072 const char *intf)
10073{
10074 char buf[200];
10075
10076 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
10077 if (system(buf) != 0) {
10078 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
10079 "ndsend");
10080 return 0;
10081 }
10082
10083 return 1;
10084}
10085
10086
10087static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
10088 struct sigma_conn *conn,
10089 struct sigma_cmd *cmd,
10090 const char *intf)
10091{
10092 char buf[200];
10093 const char *ip = get_param(cmd, "SenderIP");
10094
Peng Xu26b356d2017-10-04 17:58:16 -070010095 if (!ip)
10096 return 0;
10097
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010098 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
10099 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10100 if (system(buf) == 0) {
10101 sigma_dut_print(dut, DUT_MSG_INFO,
10102 "Neighbor Solicitation got a response "
10103 "for %s@%s", ip, intf);
10104 }
10105
10106 return 1;
10107}
10108
10109
10110static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
10111 struct sigma_conn *conn,
10112 struct sigma_cmd *cmd,
10113 const char *ifname)
10114{
10115 char buf[200];
10116 const char *ip = get_param(cmd, "SenderIP");
10117
10118 if (ip == NULL) {
10119 send_resp(dut, conn, SIGMA_ERROR,
10120 "ErrorCode,Missing SenderIP parameter");
10121 return 0;
10122 }
10123 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
10124 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10125 if (system(buf) != 0) {
10126 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
10127 "for %s@%s", ip, ifname);
10128 }
10129
10130 return 1;
10131}
10132
10133
10134static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
10135 struct sigma_conn *conn,
10136 struct sigma_cmd *cmd,
10137 const char *ifname)
10138{
10139 char buf[200];
10140 char ip[16];
10141 int s;
Peng Xub3756882017-10-04 14:39:09 -070010142 struct ifreq ifr;
10143 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010144
10145 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070010146 if (s < 0) {
10147 perror("socket");
10148 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010149 }
10150
Peng Xub3756882017-10-04 14:39:09 -070010151 memset(&ifr, 0, sizeof(ifr));
10152 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
10153 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
10154 sigma_dut_print(dut, DUT_MSG_INFO,
10155 "Failed to get %s IP address: %s",
10156 ifname, strerror(errno));
10157 close(s);
10158 return -1;
10159 }
10160 close(s);
10161
10162 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
10163 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
10164
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010165 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
10166 ip);
10167 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10168 if (system(buf) != 0) {
10169 }
10170
10171 return 1;
10172}
10173
10174
10175static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
10176 struct sigma_conn *conn,
10177 struct sigma_cmd *cmd,
10178 const char *ifname)
10179{
10180 char buf[200], addr[20];
10181 char dst[ETH_ALEN], src[ETH_ALEN];
10182 short ethtype = htons(ETH_P_ARP);
10183 char *pos;
10184 int s, res;
10185 const char *val;
10186 struct sockaddr_in taddr;
10187
10188 val = get_param(cmd, "dest");
10189 if (val)
10190 hwaddr_aton(val, (unsigned char *) dst);
10191
10192 val = get_param(cmd, "DestIP");
10193 if (val)
10194 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070010195 else
10196 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010197
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010198 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010199 sizeof(addr)) < 0)
10200 return -2;
10201 hwaddr_aton(addr, (unsigned char *) src);
10202
10203 pos = buf;
10204 *pos++ = 0x00;
10205 *pos++ = 0x01;
10206 *pos++ = 0x08;
10207 *pos++ = 0x00;
10208 *pos++ = 0x06;
10209 *pos++ = 0x04;
10210 *pos++ = 0x00;
10211 *pos++ = 0x02;
10212 memcpy(pos, src, ETH_ALEN);
10213 pos += ETH_ALEN;
10214 memcpy(pos, &taddr.sin_addr, 4);
10215 pos += 4;
10216 memcpy(pos, dst, ETH_ALEN);
10217 pos += ETH_ALEN;
10218 memcpy(pos, &taddr.sin_addr, 4);
10219 pos += 4;
10220
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010221 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010222 if (s < 0) {
10223 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
10224 "monitor socket");
10225 return 0;
10226 }
10227
10228 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
10229 if (res < 0) {
10230 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
10231 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053010232 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010233 return 0;
10234 }
10235
10236 close(s);
10237
10238 return 1;
10239}
10240
10241
10242static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
10243 struct sigma_conn *conn,
10244 struct sigma_cmd *cmd,
10245 const char *intf, const char *dest)
10246{
10247 char buf[100];
10248
10249 if (if_nametoindex("sigmadut") == 0) {
10250 snprintf(buf, sizeof(buf),
10251 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010252 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010253 if (system(buf) != 0 ||
10254 if_nametoindex("sigmadut") == 0) {
10255 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10256 "monitor interface with '%s'", buf);
10257 return -2;
10258 }
10259 }
10260
10261 if (system("ifconfig sigmadut up") != 0) {
10262 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10263 "monitor interface up");
10264 return -2;
10265 }
10266
10267 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
10268}
10269
10270
10271static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10272 struct sigma_conn *conn,
10273 struct sigma_cmd *cmd)
10274{
10275 const char *intf = get_param(cmd, "Interface");
10276 const char *dest = get_param(cmd, "Dest");
10277 const char *type = get_param(cmd, "FrameName");
10278 const char *val;
10279 char buf[200], *pos, *end;
10280 int count, count2;
10281
10282 if (type == NULL)
10283 type = get_param(cmd, "Type");
10284
10285 if (intf == NULL || dest == NULL || type == NULL)
10286 return -1;
10287
10288 if (strcasecmp(type, "NeighAdv") == 0)
10289 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10290
10291 if (strcasecmp(type, "NeighSolicitReq") == 0)
10292 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10293
10294 if (strcasecmp(type, "ARPProbe") == 0)
10295 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10296
10297 if (strcasecmp(type, "ARPAnnounce") == 0)
10298 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10299
10300 if (strcasecmp(type, "ARPReply") == 0)
10301 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10302
10303 if (strcasecmp(type, "DLS-request") == 0 ||
10304 strcasecmp(type, "DLSrequest") == 0)
10305 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10306 dest);
10307
10308 if (strcasecmp(type, "ANQPQuery") != 0 &&
10309 strcasecmp(type, "Query") != 0) {
10310 send_resp(dut, conn, SIGMA_ERROR,
10311 "ErrorCode,Unsupported HS 2.0 send frame type");
10312 return 0;
10313 }
10314
10315 if (sta_scan_ap(dut, intf, dest) < 0) {
10316 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10317 "the requested AP");
10318 return 0;
10319 }
10320
10321 pos = buf;
10322 end = buf + sizeof(buf);
10323 count = 0;
10324 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10325
10326 val = get_param(cmd, "ANQP_CAP_LIST");
10327 if (val && atoi(val)) {
10328 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10329 count++;
10330 }
10331
10332 val = get_param(cmd, "VENUE_NAME");
10333 if (val && atoi(val)) {
10334 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10335 count++;
10336 }
10337
10338 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10339 if (val && atoi(val)) {
10340 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10341 count++;
10342 }
10343
10344 val = get_param(cmd, "ROAMING_CONS");
10345 if (val && atoi(val)) {
10346 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10347 count++;
10348 }
10349
10350 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10351 if (val && atoi(val)) {
10352 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10353 count++;
10354 }
10355
10356 val = get_param(cmd, "NAI_REALM_LIST");
10357 if (val && atoi(val)) {
10358 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10359 count++;
10360 }
10361
10362 val = get_param(cmd, "3GPP_INFO");
10363 if (val && atoi(val)) {
10364 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10365 count++;
10366 }
10367
10368 val = get_param(cmd, "DOMAIN_LIST");
10369 if (val && atoi(val)) {
10370 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10371 count++;
10372 }
10373
Jouni Malinen34cf9532018-04-29 19:26:33 +030010374 val = get_param(cmd, "Venue_URL");
10375 if (val && atoi(val)) {
10376 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10377 count++;
10378 }
10379
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010380 val = get_param(cmd, "Advice_Of_Charge");
10381 if (val && atoi(val)) {
10382 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10383 count++;
10384 }
10385
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010386 if (count && wpa_command(intf, buf)) {
10387 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10388 return 0;
10389 }
10390
10391 pos = buf;
10392 end = buf + sizeof(buf);
10393 count2 = 0;
10394 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
10395
10396 val = get_param(cmd, "HS_CAP_LIST");
10397 if (val && atoi(val)) {
10398 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
10399 count2++;
10400 }
10401
10402 val = get_param(cmd, "OPER_NAME");
10403 if (val && atoi(val)) {
10404 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
10405 count2++;
10406 }
10407
10408 val = get_param(cmd, "WAN_METRICS");
10409 if (!val)
10410 val = get_param(cmd, "WAN_MAT");
10411 if (!val)
10412 val = get_param(cmd, "WAN_MET");
10413 if (val && atoi(val)) {
10414 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10415 count2++;
10416 }
10417
10418 val = get_param(cmd, "CONNECTION_CAPABILITY");
10419 if (val && atoi(val)) {
10420 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10421 count2++;
10422 }
10423
10424 val = get_param(cmd, "OP_CLASS");
10425 if (val && atoi(val)) {
10426 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10427 count2++;
10428 }
10429
10430 val = get_param(cmd, "OSU_PROVIDER_LIST");
10431 if (val && atoi(val)) {
10432 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10433 count2++;
10434 }
10435
Jouni Malinenf67afec2018-04-29 19:24:58 +030010436 val = get_param(cmd, "OPER_ICON_METADATA");
10437 if (!val)
10438 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10439 if (val && atoi(val)) {
10440 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10441 count2++;
10442 }
10443
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010444 if (count && count2) {
10445 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10446 "second query");
10447 sleep(1);
10448 }
10449
10450 if (count2 && wpa_command(intf, buf)) {
10451 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10452 "failed");
10453 return 0;
10454 }
10455
10456 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10457 if (val) {
10458 if (count || count2) {
10459 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10460 "sending out second query");
10461 sleep(1);
10462 }
10463
10464 if (strcmp(val, "1") == 0)
10465 val = "mail.example.com";
10466 snprintf(buf, end - pos,
10467 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10468 dest, val);
10469 if (wpa_command(intf, buf)) {
10470 send_resp(dut, conn, SIGMA_ERROR,
10471 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10472 "failed");
10473 return 0;
10474 }
10475 }
10476
10477 val = get_param(cmd, "ICON_REQUEST");
10478 if (val) {
10479 if (count || count2) {
10480 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10481 "sending out second query");
10482 sleep(1);
10483 }
10484
10485 snprintf(buf, end - pos,
10486 "HS20_ICON_REQUEST %s %s", dest, val);
10487 if (wpa_command(intf, buf)) {
10488 send_resp(dut, conn, SIGMA_ERROR,
10489 "ErrorCode,HS20_ICON_REQUEST failed");
10490 return 0;
10491 }
10492 }
10493
10494 return 1;
10495}
10496
10497
10498static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10499 struct sigma_conn *conn,
10500 struct sigma_cmd *cmd)
10501{
10502 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010503 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010504 int chwidth, nss;
10505
10506 val = get_param(cmd, "framename");
10507 if (!val)
10508 return -1;
10509 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10510
10511 /* Command sequence to generate Op mode notification */
10512 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010513 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010514
10515 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010516 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010517
10518 /* Extract Channel width */
10519 val = get_param(cmd, "Channel_width");
10520 if (val) {
10521 switch (atoi(val)) {
10522 case 20:
10523 chwidth = 0;
10524 break;
10525 case 40:
10526 chwidth = 1;
10527 break;
10528 case 80:
10529 chwidth = 2;
10530 break;
10531 case 160:
10532 chwidth = 3;
10533 break;
10534 default:
10535 chwidth = 2;
10536 break;
10537 }
10538
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010539 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010540 }
10541
10542 /* Extract NSS */
10543 val = get_param(cmd, "NSS");
10544 if (val) {
10545 switch (atoi(val)) {
10546 case 1:
10547 nss = 1;
10548 break;
10549 case 2:
10550 nss = 3;
10551 break;
10552 case 3:
10553 nss = 7;
10554 break;
10555 default:
10556 /* We do not support NSS > 3 */
10557 nss = 3;
10558 break;
10559 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010560 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010561 }
10562
10563 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010564 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010565 }
10566
10567 return 1;
10568}
10569
10570
10571static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
10572 struct sigma_conn *conn,
10573 struct sigma_cmd *cmd)
10574{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010575 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010576 case DRIVER_ATHEROS:
10577 return ath_sta_send_frame_vht(dut, conn, cmd);
10578 default:
10579 send_resp(dut, conn, SIGMA_ERROR,
10580 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
10581 return 0;
10582 }
10583}
10584
10585
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010586static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
10587 struct sigma_cmd *cmd)
10588{
10589 const char *val;
10590 const char *intf = get_param(cmd, "Interface");
10591
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010592 if (!intf)
10593 return -1;
10594
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010595 val = get_param(cmd, "framename");
10596 if (!val)
10597 return -1;
10598 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10599
10600 /* Command sequence to generate Op mode notification */
10601 if (val && strcasecmp(val, "action") == 0) {
10602 val = get_param(cmd, "PPDUTxType");
10603 if (val && strcasecmp(val, "TB") == 0) {
10604 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
10605 sigma_dut_print(dut, DUT_MSG_ERROR,
10606 "failed to send TB PPDU Tx cfg");
10607 send_resp(dut, conn, SIGMA_ERROR,
10608 "ErrorCode,set TB PPDU Tx cfg failed");
10609 return 0;
10610 }
10611 return 1;
10612 }
10613
10614 sigma_dut_print(dut, DUT_MSG_ERROR,
10615 "Action Tx type is not defined");
10616 }
10617
10618 return 1;
10619}
10620
10621
10622static int cmd_sta_send_frame_he(struct sigma_dut *dut,
10623 struct sigma_conn *conn,
10624 struct sigma_cmd *cmd)
10625{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010626 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010627 case DRIVER_WCN:
10628 return wcn_sta_send_frame_he(dut, conn, cmd);
10629 default:
10630 send_resp(dut, conn, SIGMA_ERROR,
10631 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
10632 return 0;
10633 }
10634}
10635
10636
Lior David0fe101e2017-03-09 16:09:50 +020010637#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010638
10639static int
10640wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
10641 const char *frame_name, const char *dest_mac)
10642{
10643 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
10644 const char *ssid = get_param(cmd, "ssid");
10645 const char *countstr = get_param(cmd, "count");
10646 const char *channelstr = get_param(cmd, "channel");
10647 const char *group_id = get_param(cmd, "groupid");
10648 const char *client_id = get_param(cmd, "clientmac");
10649 int count, channel, freq, i;
10650 const char *fname;
10651 char frame[1024], src_mac[20], group_id_attr[25],
10652 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
10653 const char *group_ssid;
10654 const int group_ssid_prefix_len = 9;
10655 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
10656 size_t framelen = sizeof(frame);
10657 struct template_frame_tag tags[2];
10658 size_t tags_total = ARRAY_SIZE(tags);
10659 int tag_index, len, dst_len;
10660
10661 if (!countstr || !channelstr) {
10662 sigma_dut_print(dut, DUT_MSG_ERROR,
10663 "Missing argument: count, channel");
10664 return -1;
10665 }
10666 if (isprobereq && !ssid) {
10667 sigma_dut_print(dut, DUT_MSG_ERROR,
10668 "Missing argument: ssid");
10669 return -1;
10670 }
10671 if (!isprobereq && (!group_id || !client_id)) {
10672 sigma_dut_print(dut, DUT_MSG_ERROR,
10673 "Missing argument: group_id, client_id");
10674 return -1;
10675 }
10676
10677 count = atoi(countstr);
10678 channel = atoi(channelstr);
10679 freq = channel_to_freq(dut, channel);
10680
10681 if (!freq) {
10682 sigma_dut_print(dut, DUT_MSG_ERROR,
10683 "invalid channel: %s", channelstr);
10684 return -1;
10685 }
10686
10687 if (isprobereq) {
10688 if (strcasecmp(ssid, "wildcard") == 0) {
10689 fname = "probe_req_wildcard.txt";
10690 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
10691 fname = "probe_req_P2P_Wildcard.txt";
10692 } else {
10693 sigma_dut_print(dut, DUT_MSG_ERROR,
10694 "invalid probe request type");
10695 return -1;
10696 }
10697 } else {
10698 fname = "P2P_device_discovery_req.txt";
10699 }
10700
10701 if (parse_template_frame_file(dut, fname, frame, &framelen,
10702 tags, &tags_total)) {
10703 sigma_dut_print(dut, DUT_MSG_ERROR,
10704 "invalid frame template: %s", fname);
10705 return -1;
10706 }
10707
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010708 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010709 src_mac, sizeof(src_mac)) < 0 ||
10710 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
10711 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
10712 return -1;
10713 /* Use wildcard BSSID, since we are in PBSS */
10714 memset(&hdr->addr3, 0xFF, ETH_ALEN);
10715
10716 if (!isprobereq) {
10717 tag_index = find_template_frame_tag(tags, tags_total, 1);
10718 if (tag_index < 0) {
10719 sigma_dut_print(dut, DUT_MSG_ERROR,
10720 "can't find device id attribute");
10721 return -1;
10722 }
10723 if (parse_mac_address(dut, client_id,
10724 (unsigned char *) client_mac)) {
10725 sigma_dut_print(dut, DUT_MSG_ERROR,
10726 "invalid client_id: %s", client_id);
10727 return -1;
10728 }
10729 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10730 framelen - tags[tag_index].offset,
10731 IEEE80211_P2P_ATTR_DEVICE_ID,
10732 client_mac, ETH_ALEN)) {
10733 sigma_dut_print(dut, DUT_MSG_ERROR,
10734 "fail to replace device id attribute");
10735 return -1;
10736 }
10737
10738 /*
10739 * group_id arg contains device MAC address followed by
10740 * space and SSID (DIRECT-somessid).
10741 * group id attribute contains device address (6 bytes)
10742 * followed by SSID prefix DIRECT-XX (9 bytes)
10743 */
10744 if (strlen(group_id) < sizeof(device_macstr)) {
10745 sigma_dut_print(dut, DUT_MSG_ERROR,
10746 "group_id arg too short");
10747 return -1;
10748 }
10749 memcpy(device_macstr, group_id, sizeof(device_macstr));
10750 device_macstr[sizeof(device_macstr) - 1] = '\0';
10751 if (parse_mac_address(dut, device_macstr,
10752 (unsigned char *) group_id_attr)) {
10753 sigma_dut_print(dut, DUT_MSG_ERROR,
10754 "fail to parse device address from group_id");
10755 return -1;
10756 }
10757 group_ssid = strchr(group_id, ' ');
10758 if (!group_ssid) {
10759 sigma_dut_print(dut, DUT_MSG_ERROR,
10760 "invalid group_id arg, no ssid");
10761 return -1;
10762 }
10763 group_ssid++;
10764 len = strlen(group_ssid);
10765 if (len < group_ssid_prefix_len) {
10766 sigma_dut_print(dut, DUT_MSG_ERROR,
10767 "group_id SSID too short");
10768 return -1;
10769 }
10770 dst_len = sizeof(group_id_attr) - ETH_ALEN;
10771 if (len > dst_len) {
10772 sigma_dut_print(dut, DUT_MSG_ERROR,
10773 "group_id SSID (%s) too long",
10774 group_ssid);
10775 return -1;
10776 }
10777
10778 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
10779 tag_index = find_template_frame_tag(tags, tags_total, 2);
10780 if (tag_index < 0) {
10781 sigma_dut_print(dut, DUT_MSG_ERROR,
10782 "can't find group id attribute");
10783 return -1;
10784 }
10785 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10786 framelen - tags[tag_index].offset,
10787 IEEE80211_P2P_ATTR_GROUP_ID,
10788 group_id_attr,
10789 sizeof(group_id_attr))) {
10790 sigma_dut_print(dut, DUT_MSG_ERROR,
10791 "fail to replace group id attribute");
10792 return -1;
10793 }
10794 }
10795
10796 for (i = 0; i < count; i++) {
10797 if (wil6210_transmit_frame(dut, freq,
10798 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
10799 frame, framelen)) {
10800 sigma_dut_print(dut, DUT_MSG_ERROR,
10801 "fail to transmit probe request frame");
10802 return -1;
10803 }
10804 }
10805
10806 return 0;
10807}
10808
10809
Lior David0fe101e2017-03-09 16:09:50 +020010810int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10811 struct sigma_cmd *cmd)
10812{
10813 const char *frame_name = get_param(cmd, "framename");
10814 const char *mac = get_param(cmd, "dest_mac");
10815
10816 if (!frame_name || !mac) {
10817 sigma_dut_print(dut, DUT_MSG_ERROR,
10818 "framename and dest_mac must be provided");
10819 return -1;
10820 }
10821
10822 if (strcasecmp(frame_name, "brp") == 0) {
10823 const char *l_rx = get_param(cmd, "L-RX");
10824 int l_rx_i;
10825
10826 if (!l_rx) {
10827 sigma_dut_print(dut, DUT_MSG_ERROR,
10828 "L-RX must be provided");
10829 return -1;
10830 }
10831 l_rx_i = atoi(l_rx);
10832
10833 sigma_dut_print(dut, DUT_MSG_INFO,
10834 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
10835 mac, l_rx);
10836 if (l_rx_i != 16) {
10837 sigma_dut_print(dut, DUT_MSG_ERROR,
10838 "unsupported L-RX: %s", l_rx);
10839 return -1;
10840 }
10841
10842 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
10843 return -1;
10844 } else if (strcasecmp(frame_name, "ssw") == 0) {
10845 sigma_dut_print(dut, DUT_MSG_INFO,
10846 "dev_send_frame: SLS, dest_mac %s", mac);
10847 if (wil6210_send_sls(dut, mac))
10848 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010849 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
10850 (strcasecmp(frame_name, "devdiscreq") == 0)) {
10851 sigma_dut_print(dut, DUT_MSG_INFO,
10852 "dev_send_frame: %s, dest_mac %s", frame_name,
10853 mac);
10854 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
10855 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020010856 } else {
10857 sigma_dut_print(dut, DUT_MSG_ERROR,
10858 "unsupported frame type: %s", frame_name);
10859 return -1;
10860 }
10861
10862 return 1;
10863}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010864
Lior David0fe101e2017-03-09 16:09:50 +020010865#endif /* __linux__ */
10866
10867
10868static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
10869 struct sigma_conn *conn,
10870 struct sigma_cmd *cmd)
10871{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010872 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020010873#ifdef __linux__
10874 case DRIVER_WIL6210:
10875 return wil6210_send_frame_60g(dut, conn, cmd);
10876#endif /* __linux__ */
10877 default:
10878 send_resp(dut, conn, SIGMA_ERROR,
10879 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
10880 return 0;
10881 }
10882}
10883
10884
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010885static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
10886 const char *intf, struct sigma_cmd *cmd)
10887{
10888 const char *val, *addr;
10889 char buf[100];
10890
10891 addr = get_param(cmd, "DestMac");
10892 if (!addr) {
10893 send_resp(dut, conn, SIGMA_INVALID,
10894 "ErrorCode,AP MAC address is missing");
10895 return 0;
10896 }
10897
10898 val = get_param(cmd, "ANQPQuery_ID");
10899 if (!val) {
10900 send_resp(dut, conn, SIGMA_INVALID,
10901 "ErrorCode,Missing ANQPQuery_ID");
10902 return 0;
10903 }
10904
10905 if (strcasecmp(val, "NeighborReportReq") == 0) {
10906 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
10907 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
10908 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
10909 } else {
10910 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
10911 val);
10912 send_resp(dut, conn, SIGMA_INVALID,
10913 "ErrorCode,Invalid ANQPQuery_ID");
10914 return 0;
10915 }
10916
Ashwini Patild174f2c2017-04-13 16:49:46 +053010917 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
10918 * (Address3 = Wildcard BSSID when sent to not-associated AP;
10919 * if associated, AP BSSID).
10920 */
10921 if (wpa_command(intf, "SET gas_address3 1") < 0) {
10922 send_resp(dut, conn, SIGMA_ERROR,
10923 "ErrorCode,Failed to set gas_address3");
10924 return 0;
10925 }
10926
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010927 if (wpa_command(intf, buf) < 0) {
10928 send_resp(dut, conn, SIGMA_ERROR,
10929 "ErrorCode,Failed to send ANQP query");
10930 return 0;
10931 }
10932
10933 return 1;
10934}
10935
10936
10937static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
10938 struct sigma_conn *conn,
10939 const char *intf,
10940 struct sigma_cmd *cmd)
10941{
10942 const char *val = get_param(cmd, "FrameName");
10943
10944 if (val && strcasecmp(val, "ANQPQuery") == 0)
10945 return mbo_send_anqp_query(dut, conn, intf, cmd);
10946
10947 return 2;
10948}
10949
10950
Jouni Malinenf7222712019-06-13 01:50:21 +030010951enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
10952 struct sigma_conn *conn,
10953 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010954{
10955 const char *intf = get_param(cmd, "Interface");
10956 const char *val;
10957 enum send_frame_type frame;
10958 enum send_frame_protection protected;
10959 char buf[100];
10960 unsigned char addr[ETH_ALEN];
10961 int res;
10962
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010963 if (!intf)
10964 return -1;
10965
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010966 val = get_param(cmd, "program");
10967 if (val == NULL)
10968 val = get_param(cmd, "frame");
10969 if (val && strcasecmp(val, "TDLS") == 0)
10970 return cmd_sta_send_frame_tdls(dut, conn, cmd);
10971 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030010972 strcasecmp(val, "HS2-R2") == 0 ||
10973 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010974 return cmd_sta_send_frame_hs2(dut, conn, cmd);
10975 if (val && strcasecmp(val, "VHT") == 0)
10976 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010977 if (val && strcasecmp(val, "HE") == 0)
10978 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070010979 if (val && strcasecmp(val, "LOC") == 0)
10980 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020010981 if (val && strcasecmp(val, "60GHz") == 0)
10982 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010983 if (val && strcasecmp(val, "MBO") == 0) {
10984 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
10985 if (res != 2)
10986 return res;
10987 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010988
10989 val = get_param(cmd, "TD_DISC");
10990 if (val) {
10991 if (hwaddr_aton(val, addr) < 0)
10992 return -1;
10993 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
10994 if (wpa_command(intf, buf) < 0) {
10995 send_resp(dut, conn, SIGMA_ERROR,
10996 "ErrorCode,Failed to send TDLS discovery");
10997 return 0;
10998 }
10999 return 1;
11000 }
11001
11002 val = get_param(cmd, "TD_Setup");
11003 if (val) {
11004 if (hwaddr_aton(val, addr) < 0)
11005 return -1;
11006 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
11007 if (wpa_command(intf, buf) < 0) {
11008 send_resp(dut, conn, SIGMA_ERROR,
11009 "ErrorCode,Failed to start TDLS setup");
11010 return 0;
11011 }
11012 return 1;
11013 }
11014
11015 val = get_param(cmd, "TD_TearDown");
11016 if (val) {
11017 if (hwaddr_aton(val, addr) < 0)
11018 return -1;
11019 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
11020 if (wpa_command(intf, buf) < 0) {
11021 send_resp(dut, conn, SIGMA_ERROR,
11022 "ErrorCode,Failed to tear down TDLS link");
11023 return 0;
11024 }
11025 return 1;
11026 }
11027
11028 val = get_param(cmd, "TD_ChannelSwitch");
11029 if (val) {
11030 /* TODO */
11031 send_resp(dut, conn, SIGMA_ERROR,
11032 "ErrorCode,TD_ChannelSwitch not yet supported");
11033 return 0;
11034 }
11035
11036 val = get_param(cmd, "TD_NF");
11037 if (val) {
11038 /* TODO */
11039 send_resp(dut, conn, SIGMA_ERROR,
11040 "ErrorCode,TD_NF not yet supported");
11041 return 0;
11042 }
11043
11044 val = get_param(cmd, "PMFFrameType");
11045 if (val == NULL)
11046 val = get_param(cmd, "FrameName");
11047 if (val == NULL)
11048 val = get_param(cmd, "Type");
11049 if (val == NULL)
11050 return -1;
11051 if (strcasecmp(val, "disassoc") == 0)
11052 frame = DISASSOC;
11053 else if (strcasecmp(val, "deauth") == 0)
11054 frame = DEAUTH;
11055 else if (strcasecmp(val, "saquery") == 0)
11056 frame = SAQUERY;
11057 else if (strcasecmp(val, "auth") == 0)
11058 frame = AUTH;
11059 else if (strcasecmp(val, "assocreq") == 0)
11060 frame = ASSOCREQ;
11061 else if (strcasecmp(val, "reassocreq") == 0)
11062 frame = REASSOCREQ;
11063 else if (strcasecmp(val, "neigreq") == 0) {
11064 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
11065
11066 val = get_param(cmd, "ssid");
11067 if (val == NULL)
11068 return -1;
11069
11070 res = send_neighbor_request(dut, intf, val);
11071 if (res) {
11072 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11073 "Failed to send neighbor report request");
11074 return 0;
11075 }
11076
11077 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053011078 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
11079 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011080 sigma_dut_print(dut, DUT_MSG_DEBUG,
11081 "Got Transition Management Query");
11082
Ashwini Patil5acd7382017-04-13 15:55:04 +053011083 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011084 if (res) {
11085 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11086 "Failed to send Transition Management Query");
11087 return 0;
11088 }
11089
11090 return 1;
11091 } else {
11092 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11093 "PMFFrameType");
11094 return 0;
11095 }
11096
11097 val = get_param(cmd, "PMFProtected");
11098 if (val == NULL)
11099 val = get_param(cmd, "Protected");
11100 if (val == NULL)
11101 return -1;
11102 if (strcasecmp(val, "Correct-key") == 0 ||
11103 strcasecmp(val, "CorrectKey") == 0)
11104 protected = CORRECT_KEY;
11105 else if (strcasecmp(val, "IncorrectKey") == 0)
11106 protected = INCORRECT_KEY;
11107 else if (strcasecmp(val, "Unprotected") == 0)
11108 protected = UNPROTECTED;
11109 else {
11110 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11111 "PMFProtected");
11112 return 0;
11113 }
11114
11115 if (protected != UNPROTECTED &&
11116 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
11117 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
11118 "PMFProtected for auth/assocreq/reassocreq");
11119 return 0;
11120 }
11121
11122 if (if_nametoindex("sigmadut") == 0) {
11123 snprintf(buf, sizeof(buf),
11124 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011125 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011126 if (system(buf) != 0 ||
11127 if_nametoindex("sigmadut") == 0) {
11128 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11129 "monitor interface with '%s'", buf);
11130 return -2;
11131 }
11132 }
11133
11134 if (system("ifconfig sigmadut up") != 0) {
11135 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11136 "monitor interface up");
11137 return -2;
11138 }
11139
11140 return sta_inject_frame(dut, conn, frame, protected, NULL);
11141}
11142
11143
11144static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
11145 struct sigma_conn *conn,
11146 struct sigma_cmd *cmd,
11147 const char *ifname)
11148{
11149 char buf[200];
11150 const char *val;
11151
11152 val = get_param(cmd, "ClearARP");
11153 if (val && atoi(val) == 1) {
11154 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
11155 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11156 if (system(buf) != 0) {
11157 send_resp(dut, conn, SIGMA_ERROR,
11158 "errorCode,Failed to clear ARP cache");
11159 return 0;
11160 }
11161 }
11162
11163 return 1;
11164}
11165
11166
11167int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
11168 struct sigma_cmd *cmd)
11169{
11170 const char *intf = get_param(cmd, "Interface");
11171 const char *val;
11172
11173 if (intf == NULL)
11174 return -1;
11175
11176 val = get_param(cmd, "program");
11177 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011178 strcasecmp(val, "HS2-R2") == 0 ||
11179 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011180 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
11181
11182 return -1;
11183}
11184
11185
Jouni Malinenf7222712019-06-13 01:50:21 +030011186static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
11187 struct sigma_conn *conn,
11188 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011189{
11190 const char *intf = get_param(cmd, "Interface");
11191 const char *mac = get_param(cmd, "MAC");
11192
11193 if (intf == NULL || mac == NULL)
11194 return -1;
11195
11196 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
11197 "interface %s to %s", intf, mac);
11198
11199 if (dut->set_macaddr) {
11200 char buf[128];
11201 int res;
11202 if (strcasecmp(mac, "default") == 0) {
11203 res = snprintf(buf, sizeof(buf), "%s",
11204 dut->set_macaddr);
11205 dut->tmp_mac_addr = 0;
11206 } else {
11207 res = snprintf(buf, sizeof(buf), "%s %s",
11208 dut->set_macaddr, mac);
11209 dut->tmp_mac_addr = 1;
11210 }
11211 if (res < 0 || res >= (int) sizeof(buf))
11212 return -1;
11213 if (system(buf) != 0) {
11214 send_resp(dut, conn, SIGMA_ERROR,
11215 "errorCode,Failed to set MAC "
11216 "address");
11217 return 0;
11218 }
11219 return 1;
11220 }
11221
11222 if (strcasecmp(mac, "default") == 0)
11223 return 1;
11224
11225 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11226 "command");
11227 return 0;
11228}
11229
11230
11231static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
11232 struct sigma_conn *conn, const char *intf,
11233 int val)
11234{
11235 char buf[200];
11236 int res;
11237
11238 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
11239 intf, val);
11240 if (res < 0 || res >= (int) sizeof(buf))
11241 return -1;
11242 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11243 if (system(buf) != 0) {
11244 send_resp(dut, conn, SIGMA_ERROR,
11245 "errorCode,Failed to configure offchannel mode");
11246 return 0;
11247 }
11248
11249 return 1;
11250}
11251
11252
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011253static int off_chan_val(enum sec_ch_offset off)
11254{
11255 switch (off) {
11256 case SEC_CH_NO:
11257 return 0;
11258 case SEC_CH_40ABOVE:
11259 return 40;
11260 case SEC_CH_40BELOW:
11261 return -40;
11262 }
11263
11264 return 0;
11265}
11266
11267
11268static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
11269 const char *intf, int off_ch_num,
11270 enum sec_ch_offset sec)
11271{
11272 char buf[200];
11273 int res;
11274
11275 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
11276 intf, off_ch_num);
11277 if (res < 0 || res >= (int) sizeof(buf))
11278 return -1;
11279 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11280 if (system(buf) != 0) {
11281 send_resp(dut, conn, SIGMA_ERROR,
11282 "errorCode,Failed to set offchan");
11283 return 0;
11284 }
11285
11286 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
11287 intf, off_chan_val(sec));
11288 if (res < 0 || res >= (int) sizeof(buf))
11289 return -1;
11290 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11291 if (system(buf) != 0) {
11292 send_resp(dut, conn, SIGMA_ERROR,
11293 "errorCode,Failed to set sec chan offset");
11294 return 0;
11295 }
11296
11297 return 1;
11298}
11299
11300
11301static int tdls_set_offchannel_offset(struct sigma_dut *dut,
11302 struct sigma_conn *conn,
11303 const char *intf, int off_ch_num,
11304 enum sec_ch_offset sec)
11305{
11306 char buf[200];
11307 int res;
11308
11309 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
11310 off_ch_num);
11311 if (res < 0 || res >= (int) sizeof(buf))
11312 return -1;
11313 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11314
11315 if (wpa_command(intf, buf) < 0) {
11316 send_resp(dut, conn, SIGMA_ERROR,
11317 "ErrorCode,Failed to set offchan");
11318 return 0;
11319 }
11320 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
11321 off_chan_val(sec));
11322 if (res < 0 || res >= (int) sizeof(buf))
11323 return -1;
11324
11325 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11326
11327 if (wpa_command(intf, buf) < 0) {
11328 send_resp(dut, conn, SIGMA_ERROR,
11329 "ErrorCode,Failed to set sec chan offset");
11330 return 0;
11331 }
11332
11333 return 1;
11334}
11335
11336
11337static int tdls_set_offchannel_mode(struct sigma_dut *dut,
11338 struct sigma_conn *conn,
11339 const char *intf, int val)
11340{
11341 char buf[200];
11342 int res;
11343
11344 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
11345 val);
11346 if (res < 0 || res >= (int) sizeof(buf))
11347 return -1;
11348 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11349
11350 if (wpa_command(intf, buf) < 0) {
11351 send_resp(dut, conn, SIGMA_ERROR,
11352 "ErrorCode,Failed to configure offchannel mode");
11353 return 0;
11354 }
11355
11356 return 1;
11357}
11358
11359
11360static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
11361 struct sigma_conn *conn,
11362 struct sigma_cmd *cmd)
11363{
11364 const char *val;
11365 enum {
11366 CHSM_NOT_SET,
11367 CHSM_ENABLE,
11368 CHSM_DISABLE,
11369 CHSM_REJREQ,
11370 CHSM_UNSOLRESP
11371 } chsm = CHSM_NOT_SET;
11372 int off_ch_num = -1;
11373 enum sec_ch_offset sec_ch = SEC_CH_NO;
11374 int res;
11375
11376 val = get_param(cmd, "Uapsd");
11377 if (val) {
11378 char buf[100];
11379 if (strcasecmp(val, "Enable") == 0)
11380 snprintf(buf, sizeof(buf), "SET ps 99");
11381 else if (strcasecmp(val, "Disable") == 0)
11382 snprintf(buf, sizeof(buf), "SET ps 98");
11383 else {
11384 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11385 "Unsupported uapsd parameter value");
11386 return 0;
11387 }
11388 if (wpa_command(intf, buf)) {
11389 send_resp(dut, conn, SIGMA_ERROR,
11390 "ErrorCode,Failed to change U-APSD "
11391 "powersave mode");
11392 return 0;
11393 }
11394 }
11395
11396 val = get_param(cmd, "TPKTIMER");
11397 if (val && strcasecmp(val, "DISABLE") == 0) {
11398 if (wpa_command(intf, "SET tdls_testing 0x100")) {
11399 send_resp(dut, conn, SIGMA_ERROR,
11400 "ErrorCode,Failed to enable no TPK "
11401 "expiration test mode");
11402 return 0;
11403 }
11404 dut->no_tpk_expiration = 1;
11405 }
11406
11407 val = get_param(cmd, "ChSwitchMode");
11408 if (val) {
11409 if (strcasecmp(val, "Enable") == 0 ||
11410 strcasecmp(val, "Initiate") == 0)
11411 chsm = CHSM_ENABLE;
11412 else if (strcasecmp(val, "Disable") == 0 ||
11413 strcasecmp(val, "passive") == 0)
11414 chsm = CHSM_DISABLE;
11415 else if (strcasecmp(val, "RejReq") == 0)
11416 chsm = CHSM_REJREQ;
11417 else if (strcasecmp(val, "UnSolResp") == 0)
11418 chsm = CHSM_UNSOLRESP;
11419 else {
11420 send_resp(dut, conn, SIGMA_ERROR,
11421 "ErrorCode,Unknown ChSwitchMode value");
11422 return 0;
11423 }
11424 }
11425
11426 val = get_param(cmd, "OffChNum");
11427 if (val) {
11428 off_ch_num = atoi(val);
11429 if (off_ch_num == 0) {
11430 send_resp(dut, conn, SIGMA_ERROR,
11431 "ErrorCode,Invalid OffChNum");
11432 return 0;
11433 }
11434 }
11435
11436 val = get_param(cmd, "SecChOffset");
11437 if (val) {
11438 if (strcmp(val, "20") == 0)
11439 sec_ch = SEC_CH_NO;
11440 else if (strcasecmp(val, "40above") == 0)
11441 sec_ch = SEC_CH_40ABOVE;
11442 else if (strcasecmp(val, "40below") == 0)
11443 sec_ch = SEC_CH_40BELOW;
11444 else {
11445 send_resp(dut, conn, SIGMA_ERROR,
11446 "ErrorCode,Unknown SecChOffset value");
11447 return 0;
11448 }
11449 }
11450
11451 if (chsm == CHSM_NOT_SET) {
11452 /* no offchannel changes requested */
11453 return 1;
11454 }
11455
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011456 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
11457 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011458 send_resp(dut, conn, SIGMA_ERROR,
11459 "ErrorCode,Unknown interface");
11460 return 0;
11461 }
11462
11463 switch (chsm) {
11464 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030011465 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011466 break;
11467 case CHSM_ENABLE:
11468 if (off_ch_num < 0) {
11469 send_resp(dut, conn, SIGMA_ERROR,
11470 "ErrorCode,Missing OffChNum argument");
11471 return 0;
11472 }
11473 if (wifi_chip_type == DRIVER_WCN) {
11474 res = tdls_set_offchannel_offset(dut, conn, intf,
11475 off_ch_num, sec_ch);
11476 } else {
11477 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11478 sec_ch);
11479 }
11480 if (res != 1)
11481 return res;
11482 if (wifi_chip_type == DRIVER_WCN)
11483 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
11484 else
11485 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
11486 break;
11487 case CHSM_DISABLE:
11488 if (wifi_chip_type == DRIVER_WCN)
11489 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
11490 else
11491 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
11492 break;
11493 case CHSM_REJREQ:
11494 if (wifi_chip_type == DRIVER_WCN)
11495 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
11496 else
11497 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
11498 break;
11499 case CHSM_UNSOLRESP:
11500 if (off_ch_num < 0) {
11501 send_resp(dut, conn, SIGMA_ERROR,
11502 "ErrorCode,Missing OffChNum argument");
11503 return 0;
11504 }
11505 if (wifi_chip_type == DRIVER_WCN) {
11506 res = tdls_set_offchannel_offset(dut, conn, intf,
11507 off_ch_num, sec_ch);
11508 } else {
11509 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11510 sec_ch);
11511 }
11512 if (res != 1)
11513 return res;
11514 if (wifi_chip_type == DRIVER_WCN)
11515 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
11516 else
11517 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
11518 break;
11519 }
11520
11521 return res;
11522}
11523
11524
11525static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11526 struct sigma_conn *conn,
11527 struct sigma_cmd *cmd)
11528{
11529 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011530 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011531
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011532 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080011533
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011534 val = get_param(cmd, "nss_mcs_opt");
11535 if (val) {
11536 /* String (nss_operating_mode; mcs_operating_mode) */
11537 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011538 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011539
11540 token = strdup(val);
11541 if (!token)
11542 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011543 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011544 if (!result) {
11545 sigma_dut_print(dut, DUT_MSG_ERROR,
11546 "VHT NSS not specified");
11547 goto failed;
11548 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011549 if (strcasecmp(result, "def") != 0) {
11550 nss = atoi(result);
11551 if (nss == 4)
11552 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011553 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011554 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011555
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011556 }
11557
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011558 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011559 if (!result) {
11560 sigma_dut_print(dut, DUT_MSG_ERROR,
11561 "VHT MCS not specified");
11562 goto failed;
11563 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011564 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011565 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011566 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011567 } else {
11568 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011569 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011570 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011571 }
11572 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011573 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011574 }
11575
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011576 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011577 return 1;
11578failed:
11579 free(token);
11580 return 0;
11581}
11582
11583
11584static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11585 struct sigma_conn *conn,
11586 struct sigma_cmd *cmd)
11587{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011588 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011589 case DRIVER_ATHEROS:
11590 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
11591 default:
11592 send_resp(dut, conn, SIGMA_ERROR,
11593 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
11594 return 0;
11595 }
11596}
11597
11598
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011599static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11600 struct sigma_conn *conn,
11601 struct sigma_cmd *cmd)
11602{
11603 const char *val;
11604 char *token = NULL, *result;
11605 char buf[60];
11606
11607 val = get_param(cmd, "nss_mcs_opt");
11608 if (val) {
11609 /* String (nss_operating_mode; mcs_operating_mode) */
11610 int nss, mcs, ratecode;
11611 char *saveptr;
11612
11613 token = strdup(val);
11614 if (!token)
11615 return -2;
11616
11617 result = strtok_r(token, ";", &saveptr);
11618 if (!result) {
11619 sigma_dut_print(dut, DUT_MSG_ERROR,
11620 "HE NSS not specified");
11621 goto failed;
11622 }
11623 nss = 1;
11624 if (strcasecmp(result, "def") != 0)
11625 nss = atoi(result);
11626
11627 result = strtok_r(NULL, ";", &saveptr);
11628 if (!result) {
11629 sigma_dut_print(dut, DUT_MSG_ERROR,
11630 "HE MCS not specified");
11631 goto failed;
11632 }
11633 mcs = 7;
11634 if (strcasecmp(result, "def") != 0)
11635 mcs = atoi(result);
11636
Arif Hussain557bf412018-05-25 17:29:36 -070011637 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011638 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070011639 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011640 } else if (nss > 2) {
11641 sigma_dut_print(dut, DUT_MSG_ERROR,
11642 "HE NSS %d not supported", nss);
11643 goto failed;
11644 }
11645
Arif Hussain557bf412018-05-25 17:29:36 -070011646 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
11647 if (system(buf) != 0) {
11648 sigma_dut_print(dut, DUT_MSG_ERROR,
11649 "nss_mcs_opt: iwpriv %s nss %d failed",
11650 intf, nss);
11651 goto failed;
11652 }
Arif Hussainac6c5112018-05-25 17:34:00 -070011653 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070011654
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011655 /* Add the MCS to the ratecode */
11656 if (mcs >= 0 && mcs <= 11) {
11657 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070011658#ifdef NL80211_SUPPORT
11659 if (dut->device_type == STA_testbed) {
11660 enum he_mcs_config mcs_config;
11661 int ret;
11662
11663 if (mcs <= 7)
11664 mcs_config = HE_80_MCS0_7;
11665 else if (mcs <= 9)
11666 mcs_config = HE_80_MCS0_9;
11667 else
11668 mcs_config = HE_80_MCS0_11;
11669 ret = sta_set_he_mcs(dut, intf, mcs_config);
11670 if (ret) {
11671 sigma_dut_print(dut, DUT_MSG_ERROR,
11672 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
11673 mcs, mcs_config, ret);
11674 goto failed;
11675 }
11676 }
11677#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011678 } else {
11679 sigma_dut_print(dut, DUT_MSG_ERROR,
11680 "HE MCS %d not supported", mcs);
11681 goto failed;
11682 }
11683 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
11684 intf, ratecode);
11685 if (system(buf) != 0) {
11686 sigma_dut_print(dut, DUT_MSG_ERROR,
11687 "iwpriv setting of 11ax rates failed");
11688 goto failed;
11689 }
11690 free(token);
11691 }
11692
11693 val = get_param(cmd, "GI");
11694 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011695 int fix_rate_sgi;
11696
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011697 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011698 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011699 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011700 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011701 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
11702 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011703 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011704 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011705 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
11706 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011707 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011708 } else {
11709 send_resp(dut, conn, SIGMA_ERROR,
11710 "errorCode,GI value not supported");
11711 return 0;
11712 }
11713 if (system(buf) != 0) {
11714 send_resp(dut, conn, SIGMA_ERROR,
11715 "errorCode,Failed to set shortgi");
11716 return 0;
11717 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011718 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
11719 intf, fix_rate_sgi);
11720 if (system(buf) != 0) {
11721 send_resp(dut, conn, SIGMA_ERROR,
11722 "errorCode,Failed to set fix rate shortgi");
11723 return STATUS_SENT;
11724 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011725 }
11726
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011727 val = get_param(cmd, "LTF");
11728 if (val) {
11729#ifdef NL80211_SUPPORT
11730 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011731 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011732 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011733 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011734 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011735 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011736 } else {
11737 send_resp(dut, conn, SIGMA_ERROR,
11738 "errorCode, LTF value not supported");
11739 return 0;
11740 }
11741#else /* NL80211_SUPPORT */
11742 sigma_dut_print(dut, DUT_MSG_ERROR,
11743 "LTF cannot be set without NL80211_SUPPORT defined");
11744 return -2;
11745#endif /* NL80211_SUPPORT */
11746 }
11747
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070011748 val = get_param(cmd, "TxSUPPDU");
11749 if (val) {
11750 int set_val = 1;
11751
11752 if (strcasecmp(val, "Enable") == 0)
11753 set_val = 1;
11754 else if (strcasecmp(val, "Disable") == 0)
11755 set_val = 0;
11756
11757 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
11758 send_resp(dut, conn, SIGMA_ERROR,
11759 "ErrorCode,Failed to set Tx SU PPDU config");
11760 return 0;
11761 }
11762 }
11763
Arif Hussain480d5f42019-03-12 14:40:42 -070011764 val = get_param(cmd, "TWT_Setup");
11765 if (val) {
11766 if (strcasecmp(val, "Request") == 0) {
11767 if (sta_twt_request(dut, conn, cmd)) {
11768 send_resp(dut, conn, SIGMA_ERROR,
11769 "ErrorCode,sta_twt_request failed");
11770 return STATUS_SENT;
11771 }
11772 } else if (strcasecmp(val, "Teardown") == 0) {
11773 if (sta_twt_teardown(dut, conn, cmd)) {
11774 send_resp(dut, conn, SIGMA_ERROR,
11775 "ErrorCode,sta_twt_teardown failed");
11776 return STATUS_SENT;
11777 }
11778 }
11779 }
11780
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080011781 val = get_param(cmd, "transmitOMI");
11782 if (val && sta_transmit_omi(dut, conn, cmd)) {
11783 send_resp(dut, conn, SIGMA_ERROR,
11784 "ErrorCode,sta_transmit_omi failed");
11785 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070011786 }
11787
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011788 val = get_param(cmd, "Powersave");
11789 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011790 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011791
11792 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011793 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011794 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011795 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011796 } else {
11797 sigma_dut_print(dut, DUT_MSG_ERROR,
11798 "Unsupported Powersave value '%s'",
11799 val);
11800 return -1;
11801 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011802 if (set_power_save_wcn(dut, intf, ps) < 0)
11803 return 0;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011804 }
11805
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080011806 val = get_param(cmd, "MU_EDCA");
11807 if (val) {
11808 if (strcasecmp(val, "Override") == 0) {
11809 if (sta_set_mu_edca_override(dut, intf, 1)) {
11810 send_resp(dut, conn, SIGMA_ERROR,
11811 "errorCode,MU EDCA override set failed");
11812 return STATUS_SENT;
11813 }
11814 } else if (strcasecmp(val, "Disable") == 0) {
11815 if (sta_set_mu_edca_override(dut, intf, 0)) {
11816 send_resp(dut, conn, SIGMA_ERROR,
11817 "errorCode,MU EDCA override disable failed");
11818 return STATUS_SENT;
11819 }
11820 }
11821 }
11822
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011823 return 1;
11824
11825failed:
11826 free(token);
11827 return -2;
11828}
11829
11830
11831static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11832 struct sigma_conn *conn,
11833 struct sigma_cmd *cmd)
11834{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011835 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011836 case DRIVER_WCN:
11837 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
11838 default:
11839 send_resp(dut, conn, SIGMA_ERROR,
11840 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
11841 return 0;
11842 }
11843}
11844
11845
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011846static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
11847 struct sigma_conn *conn,
11848 struct sigma_cmd *cmd)
11849{
11850 const char *val;
11851
11852 val = get_param(cmd, "powersave");
11853 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011854 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011855
11856 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011857 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011858 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011859 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011860 } else {
11861 sigma_dut_print(dut, DUT_MSG_ERROR,
11862 "Unsupported power save config");
11863 return -1;
11864 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011865 if (set_power_save_wcn(dut, intf, ps) < 0)
11866 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011867 return 1;
11868 }
11869
11870 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
11871
11872 return 0;
11873}
11874
11875
Ashwini Patil5acd7382017-04-13 15:55:04 +053011876static int btm_query_candidate_list(struct sigma_dut *dut,
11877 struct sigma_conn *conn,
11878 struct sigma_cmd *cmd)
11879{
11880 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
11881 int len, ret;
11882 char buf[10];
11883
11884 /*
11885 * Neighbor Report elements format:
11886 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
11887 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
11888 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
11889 */
11890
11891 bssid = get_param(cmd, "Nebor_BSSID");
11892 if (!bssid) {
11893 send_resp(dut, conn, SIGMA_INVALID,
11894 "errorCode,Nebor_BSSID is missing");
11895 return 0;
11896 }
11897
11898 info = get_param(cmd, "Nebor_Bssid_Info");
11899 if (!info) {
11900 sigma_dut_print(dut, DUT_MSG_INFO,
11901 "Using default value for Nebor_Bssid_Info: %s",
11902 DEFAULT_NEIGHBOR_BSSID_INFO);
11903 info = DEFAULT_NEIGHBOR_BSSID_INFO;
11904 }
11905
11906 op_class = get_param(cmd, "Nebor_Op_Class");
11907 if (!op_class) {
11908 send_resp(dut, conn, SIGMA_INVALID,
11909 "errorCode,Nebor_Op_Class is missing");
11910 return 0;
11911 }
11912
11913 ch = get_param(cmd, "Nebor_Op_Ch");
11914 if (!ch) {
11915 send_resp(dut, conn, SIGMA_INVALID,
11916 "errorCode,Nebor_Op_Ch is missing");
11917 return 0;
11918 }
11919
11920 phy_type = get_param(cmd, "Nebor_Phy_Type");
11921 if (!phy_type) {
11922 sigma_dut_print(dut, DUT_MSG_INFO,
11923 "Using default value for Nebor_Phy_Type: %s",
11924 DEFAULT_NEIGHBOR_PHY_TYPE);
11925 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
11926 }
11927
11928 /* Parse optional subelements */
11929 buf[0] = '\0';
11930 pref = get_param(cmd, "Nebor_Pref");
11931 if (pref) {
11932 /* hexdump for preferrence subelement */
11933 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
11934 if (ret < 0 || ret >= (int) sizeof(buf)) {
11935 sigma_dut_print(dut, DUT_MSG_ERROR,
11936 "snprintf failed for optional subelement ret: %d",
11937 ret);
11938 send_resp(dut, conn, SIGMA_ERROR,
11939 "errorCode,snprintf failed for subelement");
11940 return 0;
11941 }
11942 }
11943
11944 if (!dut->btm_query_cand_list) {
11945 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
11946 if (!dut->btm_query_cand_list) {
11947 send_resp(dut, conn, SIGMA_ERROR,
11948 "errorCode,Failed to allocate memory for btm_query_cand_list");
11949 return 0;
11950 }
11951 }
11952
11953 len = strlen(dut->btm_query_cand_list);
11954 ret = snprintf(dut->btm_query_cand_list + len,
11955 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
11956 bssid, info, op_class, ch, phy_type, buf);
11957 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
11958 sigma_dut_print(dut, DUT_MSG_ERROR,
11959 "snprintf failed for neighbor report list ret: %d",
11960 ret);
11961 send_resp(dut, conn, SIGMA_ERROR,
11962 "errorCode,snprintf failed for neighbor report");
11963 free(dut->btm_query_cand_list);
11964 dut->btm_query_cand_list = NULL;
11965 return 0;
11966 }
11967
11968 return 1;
11969}
11970
11971
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011972int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
11973 struct sigma_ese_alloc *allocs, int *allocs_size)
11974{
11975 int max_count = *allocs_size;
11976 int count = 0, i;
11977 const char *val;
11978
11979 do {
11980 val = get_param_indexed(cmd, "AllocID", count);
11981 if (val)
11982 count++;
11983 } while (val);
11984
11985 if (count == 0 || count > max_count) {
11986 sigma_dut_print(dut, DUT_MSG_ERROR,
11987 "Invalid number of allocations(%d)", count);
11988 return -1;
11989 }
11990
11991 for (i = 0; i < count; i++) {
11992 val = get_param_indexed(cmd, "PercentBI", i);
11993 if (!val) {
11994 sigma_dut_print(dut, DUT_MSG_ERROR,
11995 "Missing PercentBI parameter at index %d",
11996 i);
11997 return -1;
11998 }
11999 allocs[i].percent_bi = atoi(val);
12000
12001 val = get_param_indexed(cmd, "SrcAID", i);
12002 if (val)
12003 allocs[i].src_aid = strtol(val, NULL, 0);
12004 else
12005 allocs[i].src_aid = ESE_BCAST_AID;
12006
12007 val = get_param_indexed(cmd, "DestAID", i);
12008 if (val)
12009 allocs[i].dst_aid = strtol(val, NULL, 0);
12010 else
12011 allocs[i].dst_aid = ESE_BCAST_AID;
12012
12013 allocs[i].type = ESE_CBAP;
12014 sigma_dut_print(dut, DUT_MSG_INFO,
12015 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
12016 i, allocs[i].percent_bi, allocs[i].src_aid,
12017 allocs[i].dst_aid);
12018 }
12019
12020 *allocs_size = count;
12021 return 0;
12022}
12023
12024
12025static int sta_set_60g_ese(struct sigma_dut *dut, int count,
12026 struct sigma_ese_alloc *allocs)
12027{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012028 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012029#ifdef __linux__
12030 case DRIVER_WIL6210:
12031 if (wil6210_set_ese(dut, count, allocs))
12032 return -1;
12033 return 1;
12034#endif /* __linux__ */
12035 default:
12036 sigma_dut_print(dut, DUT_MSG_ERROR,
12037 "Unsupported sta_set_60g_ese with the current driver");
12038 return -1;
12039 }
12040}
12041
12042
12043static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
12044 struct sigma_conn *conn,
12045 struct sigma_cmd *cmd)
12046{
12047 const char *val;
12048
12049 val = get_param(cmd, "ExtSchIE");
12050 if (val && !strcasecmp(val, "Enable")) {
12051 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
12052 int count = MAX_ESE_ALLOCS;
12053
12054 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
12055 return -1;
12056 return sta_set_60g_ese(dut, count, allocs);
12057 }
12058
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012059 val = get_param(cmd, "MCS_FixedRate");
12060 if (val) {
12061 int sta_mcs = atoi(val);
12062
12063 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
12064 sta_mcs);
12065 wil6210_set_force_mcs(dut, 1, sta_mcs);
12066
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012067 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012068 }
12069
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012070 send_resp(dut, conn, SIGMA_ERROR,
12071 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012072 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012073}
12074
12075
Jouni Malinen6250cb02020-04-15 13:54:45 +030012076static enum sigma_cmd_result
12077cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
12078 struct sigma_conn *conn,
12079 struct sigma_cmd *cmd)
12080{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012081 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030012082
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053012083 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030012084 if (val && atoi(val) == 1) {
12085 if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
12086 send_resp(dut, conn, SIGMA_ERROR,
12087 "errorCode,Failed to set ft_rsnxe_used");
12088 return STATUS_SENT_ERROR;
12089 }
12090 return SUCCESS_SEND_STATUS;
12091 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012092
12093 oci_chan = get_param(cmd, "OCIChannel");
12094 oci_frametype = get_param(cmd, "OCIFrameType");
12095 if (oci_chan && oci_frametype) {
12096 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
12097 char buf[100];
12098
12099 if (!oci_freq) {
12100 send_resp(dut, conn, SIGMA_ERROR,
12101 "errorCode,Invalid OCIChannel number");
12102 return STATUS_SENT_ERROR;
12103 }
12104
12105 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
12106 snprintf(buf, sizeof(buf),
12107 "SET oci_freq_override_eapol %d", oci_freq);
12108 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12109 snprintf(buf, sizeof(buf),
12110 "SET oci_freq_override_saquery_req %d",
12111 oci_freq);
12112 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12113 snprintf(buf, sizeof(buf),
12114 "SET oci_freq_override_saquery_resp %d",
12115 oci_freq);
12116 } else {
12117 send_resp(dut, conn, SIGMA_ERROR,
12118 "errorCode,Unsupported OCIFrameType");
12119 return STATUS_SENT_ERROR;
12120 }
12121 if (wpa_command(intf, buf) < 0) {
12122 send_resp(dut, conn, SIGMA_ERROR,
12123 "errorCode,Failed to set oci_freq_override");
12124 return STATUS_SENT_ERROR;
12125 }
12126 return SUCCESS_SEND_STATUS;
12127 }
12128
Jouni Malinen6250cb02020-04-15 13:54:45 +030012129 send_resp(dut, conn, SIGMA_ERROR,
12130 "errorCode,Unsupported WPA3 rfeature");
12131 return STATUS_SENT_ERROR;
12132}
12133
12134
Jouni Malinenf7222712019-06-13 01:50:21 +030012135static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
12136 struct sigma_conn *conn,
12137 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012138{
12139 const char *intf = get_param(cmd, "Interface");
12140 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012141 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012142
12143 if (intf == NULL || prog == NULL)
12144 return -1;
12145
Ashwini Patil5acd7382017-04-13 15:55:04 +053012146 /* BSS Transition candidate list for BTM query */
12147 val = get_param(cmd, "Nebor_BSSID");
12148 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
12149 return 0;
12150
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012151 if (strcasecmp(prog, "TDLS") == 0)
12152 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
12153
12154 if (strcasecmp(prog, "VHT") == 0)
12155 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
12156
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012157 if (strcasecmp(prog, "HE") == 0)
12158 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
12159
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012160 if (strcasecmp(prog, "MBO") == 0) {
12161 val = get_param(cmd, "Cellular_Data_Cap");
12162 if (val &&
12163 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12164 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053012165
12166 val = get_param(cmd, "Ch_Pref");
12167 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12168 return 0;
12169
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012170 return 1;
12171 }
12172
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012173 if (strcasecmp(prog, "60GHz") == 0)
12174 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
12175
Jouni Malinen6250cb02020-04-15 13:54:45 +030012176 if (strcasecmp(prog, "WPA3") == 0)
12177 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
12178
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012179 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
12180 return 0;
12181}
12182
12183
Jouni Malinenf7222712019-06-13 01:50:21 +030012184static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
12185 struct sigma_conn *conn,
12186 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012187{
12188 const char *intf = get_param(cmd, "Interface");
12189 const char *mode = get_param(cmd, "Mode");
12190 int res;
12191
12192 if (intf == NULL || mode == NULL)
12193 return -1;
12194
12195 if (strcasecmp(mode, "On") == 0)
12196 res = wpa_command(intf, "SET radio_disabled 0");
12197 else if (strcasecmp(mode, "Off") == 0)
12198 res = wpa_command(intf, "SET radio_disabled 1");
12199 else
12200 return -1;
12201
12202 if (res) {
12203 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12204 "radio mode");
12205 return 0;
12206 }
12207
12208 return 1;
12209}
12210
12211
Jouni Malinenf7222712019-06-13 01:50:21 +030012212static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
12213 struct sigma_conn *conn,
12214 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012215{
12216 const char *intf = get_param(cmd, "Interface");
12217 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012218 const char *prog = get_param(cmd, "program");
12219 const char *powersave = get_param(cmd, "powersave");
12220 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012221
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012222 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012223 return -1;
12224
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012225 if (prog && strcasecmp(prog, "60GHz") == 0) {
12226 /*
12227 * The CAPI mode parameter does not exist in 60G
12228 * unscheduled PS.
12229 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080012230 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012231 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012232 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020012233 strcasecmp(prog, "HE") == 0) {
12234 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012235 } else {
12236 if (mode == NULL)
12237 return -1;
12238
12239 if (strcasecmp(mode, "On") == 0)
12240 res = set_ps(intf, dut, 1);
12241 else if (strcasecmp(mode, "Off") == 0)
12242 res = set_ps(intf, dut, 0);
12243 else
12244 return -1;
12245 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012246
12247 if (res) {
12248 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12249 "power save mode");
12250 return 0;
12251 }
12252
12253 return 1;
12254}
12255
12256
Jouni Malinenf7222712019-06-13 01:50:21 +030012257static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
12258 struct sigma_conn *conn,
12259 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012260{
12261 const char *intf = get_param(cmd, "Interface");
12262 const char *val, *bssid;
12263 int res;
12264 char *buf;
12265 size_t buf_len;
12266
12267 val = get_param(cmd, "BSSID_FILTER");
12268 if (val == NULL)
12269 return -1;
12270
12271 bssid = get_param(cmd, "BSSID_List");
12272 if (atoi(val) == 0 || bssid == NULL) {
12273 /* Disable BSSID filter */
12274 if (wpa_command(intf, "SET bssid_filter ")) {
12275 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
12276 "to disable BSSID filter");
12277 return 0;
12278 }
12279
12280 return 1;
12281 }
12282
12283 buf_len = 100 + strlen(bssid);
12284 buf = malloc(buf_len);
12285 if (buf == NULL)
12286 return -1;
12287
12288 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
12289 res = wpa_command(intf, buf);
12290 free(buf);
12291 if (res) {
12292 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
12293 "BSSID filter");
12294 return 0;
12295 }
12296
12297 return 1;
12298}
12299
12300
Jouni Malinenf7222712019-06-13 01:50:21 +030012301static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
12302 struct sigma_conn *conn,
12303 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012304{
12305 const char *intf = get_param(cmd, "Interface");
12306 const char *val;
12307
12308 /* TODO: ARP */
12309
12310 val = get_param(cmd, "HS2_CACHE_PROFILE");
12311 if (val && strcasecmp(val, "All") == 0)
12312 hs2_clear_credentials(intf);
12313
12314 return 1;
12315}
12316
12317
Jouni Malinenf7222712019-06-13 01:50:21 +030012318static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
12319 struct sigma_conn *conn,
12320 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012321{
12322 const char *intf = get_param(cmd, "Interface");
12323 const char *key_type = get_param(cmd, "KeyType");
12324 char buf[100], resp[200];
12325
12326 if (key_type == NULL)
12327 return -1;
12328
12329 if (strcasecmp(key_type, "GTK") == 0) {
12330 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
12331 strncmp(buf, "FAIL", 4) == 0) {
12332 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12333 "not fetch current GTK");
12334 return 0;
12335 }
12336 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
12337 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12338 return 0;
12339 } else {
12340 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12341 "KeyType");
12342 return 0;
12343 }
12344
12345 return 1;
12346}
12347
12348
12349static int hs2_set_policy(struct sigma_dut *dut)
12350{
12351#ifdef ANDROID
12352 system("ip rule del prio 23000");
12353 if (system("ip rule add from all lookup main prio 23000") != 0) {
12354 sigma_dut_print(dut, DUT_MSG_ERROR,
12355 "Failed to run:ip rule add from all lookup main prio");
12356 return -1;
12357 }
12358 if (system("ip route flush cache") != 0) {
12359 sigma_dut_print(dut, DUT_MSG_ERROR,
12360 "Failed to run ip route flush cache");
12361 return -1;
12362 }
12363 return 1;
12364#else /* ANDROID */
12365 return 0;
12366#endif /* ANDROID */
12367}
12368
12369
Jouni Malinenf7222712019-06-13 01:50:21 +030012370static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
12371 struct sigma_conn *conn,
12372 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012373{
12374 const char *intf = get_param(cmd, "Interface");
12375 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030012376 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012377 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030012378 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012379 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
12380 int tries = 0;
12381 int ignore_blacklist = 0;
12382 const char *events[] = {
12383 "CTRL-EVENT-CONNECTED",
12384 "INTERWORKING-BLACKLISTED",
12385 "INTERWORKING-NO-MATCH",
12386 NULL
12387 };
12388
12389 start_sta_mode(dut);
12390
Jouni Malinen439352d2018-09-13 03:42:23 +030012391 if (band) {
12392 if (strcmp(band, "2.4") == 0) {
12393 wpa_command(intf, "SET setband 2G");
12394 } else if (strcmp(band, "5") == 0) {
12395 wpa_command(intf, "SET setband 5G");
12396 } else {
12397 send_resp(dut, conn, SIGMA_ERROR,
12398 "errorCode,Unsupported band");
12399 return 0;
12400 }
12401 }
12402
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012403 blacklisted[0] = '\0';
12404 if (val && atoi(val))
12405 ignore_blacklist = 1;
12406
12407try_again:
12408 ctrl = open_wpa_mon(intf);
12409 if (ctrl == NULL) {
12410 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12411 "wpa_supplicant monitor connection");
12412 return -2;
12413 }
12414
12415 tries++;
12416 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
12417 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
12418 "Interworking connection");
12419 wpa_ctrl_detach(ctrl);
12420 wpa_ctrl_close(ctrl);
12421 return 0;
12422 }
12423
12424 buf[0] = '\0';
12425 while (1) {
12426 char *pos;
12427 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
12428 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
12429 if (!pos)
12430 break;
12431 pos += 25;
12432 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
12433 pos);
12434 if (!blacklisted[0])
12435 memcpy(blacklisted, pos, strlen(pos) + 1);
12436 }
12437
12438 if (ignore_blacklist && blacklisted[0]) {
12439 char *end;
12440 end = strchr(blacklisted, ' ');
12441 if (end)
12442 *end = '\0';
12443 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
12444 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030012445 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
12446 blacklisted);
12447 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012448 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
12449 wpa_ctrl_detach(ctrl);
12450 wpa_ctrl_close(ctrl);
12451 return 0;
12452 }
12453 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
12454 buf, sizeof(buf));
12455 }
12456
12457 wpa_ctrl_detach(ctrl);
12458 wpa_ctrl_close(ctrl);
12459
12460 if (res < 0) {
12461 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12462 "connect");
12463 return 0;
12464 }
12465
12466 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
12467 strstr(buf, "INTERWORKING-BLACKLISTED")) {
12468 if (tries < 2) {
12469 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
12470 goto try_again;
12471 }
12472 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
12473 "matching credentials found");
12474 return 0;
12475 }
12476
12477 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12478 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12479 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12480 "get current BSSID/SSID");
12481 return 0;
12482 }
12483
12484 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
12485 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12486 hs2_set_policy(dut);
12487 return 0;
12488}
12489
12490
Jouni Malinenf7222712019-06-13 01:50:21 +030012491static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
12492 struct sigma_conn *conn,
12493 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030012494{
12495 const char *intf = get_param(cmd, "Interface");
12496 const char *display = get_param(cmd, "Display");
12497 struct wpa_ctrl *ctrl;
12498 char buf[300], params[400], *pos;
12499 char bssid[20];
12500 int info_avail = 0;
12501 unsigned int old_timeout;
12502 int res;
12503
12504 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
12505 send_resp(dut, conn, SIGMA_ERROR,
12506 "ErrorCode,Could not get current BSSID");
12507 return 0;
12508 }
12509 ctrl = open_wpa_mon(intf);
12510 if (!ctrl) {
12511 sigma_dut_print(dut, DUT_MSG_ERROR,
12512 "Failed to open wpa_supplicant monitor connection");
12513 return -2;
12514 }
12515
12516 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
12517 wpa_command(intf, buf);
12518
12519 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
12520 if (res < 0) {
12521 send_resp(dut, conn, SIGMA_ERROR,
12522 "ErrorCode,Could not complete GAS query");
12523 goto fail;
12524 }
12525
12526 old_timeout = dut->default_timeout;
12527 dut->default_timeout = 2;
12528 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
12529 dut->default_timeout = old_timeout;
12530 if (res < 0)
12531 goto done;
12532 pos = strchr(buf, ' ');
12533 if (!pos)
12534 goto done;
12535 pos++;
12536 pos = strchr(pos, ' ');
12537 if (!pos)
12538 goto done;
12539 pos++;
12540 info_avail = 1;
12541 snprintf(params, sizeof(params), "browser %s", pos);
12542
12543 if (display && strcasecmp(display, "Yes") == 0) {
12544 pid_t pid;
12545
12546 pid = fork();
12547 if (pid < 0) {
12548 perror("fork");
12549 return -1;
12550 }
12551
12552 if (pid == 0) {
12553 run_hs20_osu(dut, params);
12554 exit(0);
12555 }
12556 }
12557
12558done:
12559 snprintf(buf, sizeof(buf), "Info_available,%s",
12560 info_avail ? "Yes" : "No");
12561 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12562fail:
12563 wpa_ctrl_detach(ctrl);
12564 wpa_ctrl_close(ctrl);
12565 return 0;
12566}
12567
12568
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012569static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
12570 struct sigma_conn *conn,
12571 const char *ifname,
12572 struct sigma_cmd *cmd)
12573{
12574 const char *val;
12575 int id;
12576
12577 id = add_cred(ifname);
12578 if (id < 0)
12579 return -2;
12580 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12581
12582 val = get_param(cmd, "prefer");
12583 if (val && atoi(val) > 0)
12584 set_cred(ifname, id, "priority", "1");
12585
12586 val = get_param(cmd, "REALM");
12587 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12588 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12589 "realm");
12590 return 0;
12591 }
12592
12593 val = get_param(cmd, "HOME_FQDN");
12594 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12595 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12596 "home_fqdn");
12597 return 0;
12598 }
12599
12600 val = get_param(cmd, "Username");
12601 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12602 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12603 "username");
12604 return 0;
12605 }
12606
12607 val = get_param(cmd, "Password");
12608 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
12609 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12610 "password");
12611 return 0;
12612 }
12613
12614 val = get_param(cmd, "ROOT_CA");
12615 if (val) {
12616 char fname[200];
12617 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12618#ifdef __linux__
12619 if (!file_exists(fname)) {
12620 char msg[300];
12621 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12622 "file (%s) not found", fname);
12623 send_resp(dut, conn, SIGMA_ERROR, msg);
12624 return 0;
12625 }
12626#endif /* __linux__ */
12627 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12628 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12629 "not set root CA");
12630 return 0;
12631 }
12632 }
12633
12634 return 1;
12635}
12636
12637
12638static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
12639{
12640 FILE *in, *out;
12641 char buf[500];
12642 int found = 0;
12643
12644 in = fopen("devdetail.xml", "r");
12645 if (in == NULL)
12646 return -1;
12647 out = fopen("devdetail.xml.tmp", "w");
12648 if (out == NULL) {
12649 fclose(in);
12650 return -1;
12651 }
12652
12653 while (fgets(buf, sizeof(buf), in)) {
12654 char *pos = strstr(buf, "<IMSI>");
12655 if (pos) {
12656 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
12657 imsi);
12658 pos += 6;
12659 *pos = '\0';
12660 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
12661 found++;
12662 } else {
12663 fprintf(out, "%s", buf);
12664 }
12665 }
12666
12667 fclose(out);
12668 fclose(in);
12669 if (found)
12670 rename("devdetail.xml.tmp", "devdetail.xml");
12671 else
12672 unlink("devdetail.xml.tmp");
12673
12674 return 0;
12675}
12676
12677
12678static int sta_add_credential_sim(struct sigma_dut *dut,
12679 struct sigma_conn *conn,
12680 const char *ifname, struct sigma_cmd *cmd)
12681{
12682 const char *val, *imsi = NULL;
12683 int id;
12684 char buf[200];
12685 int res;
12686 const char *pos;
12687 size_t mnc_len;
12688 char plmn_mcc[4];
12689 char plmn_mnc[4];
12690
12691 id = add_cred(ifname);
12692 if (id < 0)
12693 return -2;
12694 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12695
12696 val = get_param(cmd, "prefer");
12697 if (val && atoi(val) > 0)
12698 set_cred(ifname, id, "priority", "1");
12699
12700 val = get_param(cmd, "PLMN_MCC");
12701 if (val == NULL) {
12702 send_resp(dut, conn, SIGMA_ERROR,
12703 "errorCode,Missing PLMN_MCC");
12704 return 0;
12705 }
12706 if (strlen(val) != 3) {
12707 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
12708 return 0;
12709 }
12710 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
12711
12712 val = get_param(cmd, "PLMN_MNC");
12713 if (val == NULL) {
12714 send_resp(dut, conn, SIGMA_ERROR,
12715 "errorCode,Missing PLMN_MNC");
12716 return 0;
12717 }
12718 if (strlen(val) != 2 && strlen(val) != 3) {
12719 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
12720 return 0;
12721 }
12722 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
12723
12724 val = get_param(cmd, "IMSI");
12725 if (val == NULL) {
12726 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
12727 "IMSI");
12728 return 0;
12729 }
12730
12731 imsi = pos = val;
12732
12733 if (strncmp(plmn_mcc, pos, 3) != 0) {
12734 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
12735 return 0;
12736 }
12737 pos += 3;
12738
12739 mnc_len = strlen(plmn_mnc);
12740 if (mnc_len < 2) {
12741 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
12742 return 0;
12743 }
12744
12745 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
12746 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
12747 return 0;
12748 }
12749 pos += mnc_len;
12750
12751 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
12752 if (res < 0 || res >= (int) sizeof(buf))
12753 return -1;
12754 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
12755 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12756 "not set IMSI");
12757 return 0;
12758 }
12759
12760 val = get_param(cmd, "Password");
12761 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
12762 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12763 "not set password");
12764 return 0;
12765 }
12766
Jouni Malinenba630452018-06-22 11:49:59 +030012767 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012768 /*
12769 * Set provisioning_sp for the test cases where SIM/USIM
12770 * provisioning is used.
12771 */
12772 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
12773 "wi-fi.org") < 0) {
12774 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12775 "not set provisioning_sp");
12776 return 0;
12777 }
12778
12779 update_devdetail_imsi(dut, imsi);
12780 }
12781
12782 return 1;
12783}
12784
12785
12786static int sta_add_credential_cert(struct sigma_dut *dut,
12787 struct sigma_conn *conn,
12788 const char *ifname,
12789 struct sigma_cmd *cmd)
12790{
12791 const char *val;
12792 int id;
12793
12794 id = add_cred(ifname);
12795 if (id < 0)
12796 return -2;
12797 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12798
12799 val = get_param(cmd, "prefer");
12800 if (val && atoi(val) > 0)
12801 set_cred(ifname, id, "priority", "1");
12802
12803 val = get_param(cmd, "REALM");
12804 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12805 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12806 "realm");
12807 return 0;
12808 }
12809
12810 val = get_param(cmd, "HOME_FQDN");
12811 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12812 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12813 "home_fqdn");
12814 return 0;
12815 }
12816
12817 val = get_param(cmd, "Username");
12818 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12819 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12820 "username");
12821 return 0;
12822 }
12823
12824 val = get_param(cmd, "clientCertificate");
12825 if (val) {
12826 char fname[200];
12827 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12828#ifdef __linux__
12829 if (!file_exists(fname)) {
12830 char msg[300];
12831 snprintf(msg, sizeof(msg),
12832 "ErrorCode,clientCertificate "
12833 "file (%s) not found", fname);
12834 send_resp(dut, conn, SIGMA_ERROR, msg);
12835 return 0;
12836 }
12837#endif /* __linux__ */
12838 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
12839 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12840 "not set client_cert");
12841 return 0;
12842 }
12843 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
12844 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12845 "not set private_key");
12846 return 0;
12847 }
12848 }
12849
12850 val = get_param(cmd, "ROOT_CA");
12851 if (val) {
12852 char fname[200];
12853 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12854#ifdef __linux__
12855 if (!file_exists(fname)) {
12856 char msg[300];
12857 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12858 "file (%s) not found", fname);
12859 send_resp(dut, conn, SIGMA_ERROR, msg);
12860 return 0;
12861 }
12862#endif /* __linux__ */
12863 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12864 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12865 "not set root CA");
12866 return 0;
12867 }
12868 }
12869
12870 return 1;
12871}
12872
12873
Jouni Malinenf7222712019-06-13 01:50:21 +030012874static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
12875 struct sigma_conn *conn,
12876 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012877{
12878 const char *intf = get_param(cmd, "Interface");
12879 const char *type;
12880
12881 start_sta_mode(dut);
12882
12883 type = get_param(cmd, "Type");
12884 if (!type)
12885 return -1;
12886
12887 if (strcasecmp(type, "uname_pwd") == 0)
12888 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
12889
12890 if (strcasecmp(type, "sim") == 0)
12891 return sta_add_credential_sim(dut, conn, intf, cmd);
12892
12893 if (strcasecmp(type, "cert") == 0)
12894 return sta_add_credential_cert(dut, conn, intf, cmd);
12895
12896 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
12897 "type");
12898 return 0;
12899}
12900
12901
Jouni Malinenf7222712019-06-13 01:50:21 +030012902static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
12903 struct sigma_conn *conn,
12904 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012905{
12906 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012907 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Arif Hussain66a4af02019-02-07 15:04:51 -080012908 char buf[4096];
vamsi krishna89ad8c62017-09-19 12:51:18 +053012909 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080012910 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012911 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012912 enum sigma_cmd_result status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012913
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020012914 start_sta_mode(dut);
12915
Arif Hussain66a4af02019-02-07 15:04:51 -080012916 val = get_param(cmd, "GetParameter");
12917 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012918 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080012919 buf, sizeof(buf)) < 0) {
12920 sigma_dut_print(dut, DUT_MSG_ERROR,
12921 "Could not get ssid bssid");
12922 return ERROR_SEND_STATUS;
12923 }
12924
12925 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
12926 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12927 return STATUS_SENT;
12928 }
12929
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012930 val = get_param(cmd, "HESSID");
12931 if (val) {
12932 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
12933 if (res < 0 || res >= (int) sizeof(buf))
12934 return -1;
12935 wpa_command(intf, buf);
12936 }
12937
12938 val = get_param(cmd, "ACCS_NET_TYPE");
12939 if (val) {
12940 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
12941 val);
12942 if (res < 0 || res >= (int) sizeof(buf))
12943 return -1;
12944 wpa_command(intf, buf);
12945 }
12946
vamsi krishna89ad8c62017-09-19 12:51:18 +053012947 bssid = get_param(cmd, "Bssid");
12948 ssid = get_param(cmd, "Ssid");
12949
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080012950 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
12951 dut->device_type == STA_testbed) {
12952 ssid = NULL;
12953 wildcard_ssid = 1;
12954 }
12955
vamsi krishna89ad8c62017-09-19 12:51:18 +053012956 if (ssid) {
12957 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
12958 send_resp(dut, conn, SIGMA_ERROR,
12959 "ErrorCode,Too long SSID");
12960 return 0;
12961 }
12962 ascii2hexstr(ssid, ssid_hex);
12963 }
12964
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012965 short_ssid = get_param(cmd, "ShortSSID");
12966 if (short_ssid) {
12967 uint32_t short_ssid_hex;
12968
12969 short_ssid_hex = strtoul(short_ssid, NULL, 16);
12970 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
12971 (((short_ssid_hex >> 8) & 0xFF) << 16) |
12972 (((short_ssid_hex >> 16) & 0xFF) << 8) |
12973 ((short_ssid_hex >> 24) & 0xFF);
12974
12975 res = snprintf(buf, sizeof(buf),
12976 "VENDOR_ELEM_ADD 14 ff053a%08x",
12977 short_ssid_hex);
12978 if (res < 0 || res >= (int) sizeof(buf) ||
12979 wpa_command(intf, buf)) {
12980 send_resp(dut, conn, SIGMA_ERROR,
12981 "errorCode,Failed to add short SSID");
12982 return STATUS_SENT_ERROR;
12983 }
12984 }
12985
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080012986 scan_freq = get_param(cmd, "ChnlFreq");
12987
12988 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053012989 bssid ? " bssid=": "",
12990 bssid ? bssid : "",
12991 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080012992 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080012993 wildcard_ssid ? " wildcard_ssid=1" : "",
12994 scan_freq ? " freq=" : "",
12995 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012996 if (res < 0 || res >= (int) sizeof(buf)) {
12997 send_resp(dut, conn, SIGMA_ERROR,
12998 "errorCode,Could not build scan command");
12999 status = STATUS_SENT_ERROR;
13000 goto remove_s_ssid;
13001 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053013002
13003 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013004 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
13005 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013006 status = STATUS_SENT_ERROR;
13007 } else {
13008 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013009 }
13010
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013011remove_s_ssid:
13012 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
13013 sigma_dut_print(dut, DUT_MSG_ERROR,
13014 "Failed to delete vendor element");
13015
13016 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013017}
13018
13019
Jouni Malinenf7222712019-06-13 01:50:21 +030013020static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
13021 struct sigma_conn *conn,
13022 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013023{
13024 const char *intf = get_param(cmd, "Interface");
13025 const char *bssid;
13026 char buf[4096], *pos;
13027 int freq, chan;
13028 char *ssid;
13029 char resp[100];
13030 int res;
13031 struct wpa_ctrl *ctrl;
13032
13033 bssid = get_param(cmd, "BSSID");
13034 if (!bssid) {
13035 send_resp(dut, conn, SIGMA_INVALID,
13036 "errorCode,BSSID argument is missing");
13037 return 0;
13038 }
13039
13040 ctrl = open_wpa_mon(intf);
13041 if (!ctrl) {
13042 sigma_dut_print(dut, DUT_MSG_ERROR,
13043 "Failed to open wpa_supplicant monitor connection");
13044 return -1;
13045 }
13046
13047 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
13048 send_resp(dut, conn, SIGMA_ERROR,
13049 "errorCode,Could not start scan");
13050 wpa_ctrl_detach(ctrl);
13051 wpa_ctrl_close(ctrl);
13052 return 0;
13053 }
13054
13055 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
13056 buf, sizeof(buf));
13057
13058 wpa_ctrl_detach(ctrl);
13059 wpa_ctrl_close(ctrl);
13060
13061 if (res < 0) {
13062 send_resp(dut, conn, SIGMA_ERROR,
13063 "errorCode,Scan did not complete");
13064 return 0;
13065 }
13066
13067 snprintf(buf, sizeof(buf), "BSS %s", bssid);
13068 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
13069 strncmp(buf, "id=", 3) != 0) {
13070 send_resp(dut, conn, SIGMA_ERROR,
13071 "errorCode,Specified BSSID not found");
13072 return 0;
13073 }
13074
13075 pos = strstr(buf, "\nfreq=");
13076 if (!pos) {
13077 send_resp(dut, conn, SIGMA_ERROR,
13078 "errorCode,Channel not found");
13079 return 0;
13080 }
13081 freq = atoi(pos + 6);
13082 chan = freq_to_channel(freq);
13083
13084 pos = strstr(buf, "\nssid=");
13085 if (!pos) {
13086 send_resp(dut, conn, SIGMA_ERROR,
13087 "errorCode,SSID not found");
13088 return 0;
13089 }
13090 ssid = pos + 6;
13091 pos = strchr(ssid, '\n');
13092 if (pos)
13093 *pos = '\0';
13094 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
13095 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13096 return 0;
13097}
13098
13099
Jouni Malinenf7222712019-06-13 01:50:21 +030013100static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
13101 struct sigma_conn *conn,
13102 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013103{
13104#ifdef __linux__
13105 struct timeval tv;
13106 struct tm tm;
13107 time_t t;
13108 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013109 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013110
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013111 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013112
13113 memset(&tm, 0, sizeof(tm));
13114 val = get_param(cmd, "seconds");
13115 if (val)
13116 tm.tm_sec = atoi(val);
13117 val = get_param(cmd, "minutes");
13118 if (val)
13119 tm.tm_min = atoi(val);
13120 val = get_param(cmd, "hours");
13121 if (val)
13122 tm.tm_hour = atoi(val);
13123 val = get_param(cmd, "date");
13124 if (val)
13125 tm.tm_mday = atoi(val);
13126 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013127 if (val) {
13128 v = atoi(val);
13129 if (v < 1 || v > 12) {
13130 send_resp(dut, conn, SIGMA_INVALID,
13131 "errorCode,Invalid month");
13132 return 0;
13133 }
13134 tm.tm_mon = v - 1;
13135 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013136 val = get_param(cmd, "year");
13137 if (val) {
13138 int year = atoi(val);
13139#ifdef ANDROID
13140 if (year > 2035)
13141 year = 2035; /* years beyond 2035 not supported */
13142#endif /* ANDROID */
13143 tm.tm_year = year - 1900;
13144 }
13145 t = mktime(&tm);
13146 if (t == (time_t) -1) {
13147 send_resp(dut, conn, SIGMA_ERROR,
13148 "errorCode,Invalid date or time");
13149 return 0;
13150 }
13151
13152 memset(&tv, 0, sizeof(tv));
13153 tv.tv_sec = t;
13154
13155 if (settimeofday(&tv, NULL) < 0) {
13156 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
13157 strerror(errno));
13158 send_resp(dut, conn, SIGMA_ERROR,
13159 "errorCode,Failed to set time");
13160 return 0;
13161 }
13162
13163 return 1;
13164#endif /* __linux__ */
13165
13166 return -1;
13167}
13168
13169
Jouni Malinenf7222712019-06-13 01:50:21 +030013170static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
13171 struct sigma_conn *conn,
13172 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013173{
13174 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013175 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013176 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013177 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013178 int res;
13179 struct wpa_ctrl *ctrl;
13180
13181 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013182 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013183
13184 val = get_param(cmd, "ProdESSAssoc");
13185 if (val)
13186 prod_ess_assoc = atoi(val);
13187
13188 kill_dhcp_client(dut, intf);
13189 if (start_dhcp_client(dut, intf) < 0)
13190 return -2;
13191
13192 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
13193 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13194 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013195 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013196 prod_ess_assoc ? "" : "-N",
13197 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013198 name ? "'" : "",
13199 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
13200 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013201
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053013202 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013203 if (run_hs20_osu(dut, buf) < 0) {
13204 FILE *f;
13205
13206 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
13207
13208 f = fopen("hs20-osu-client.res", "r");
13209 if (f) {
13210 char resp[400], res[300], *pos;
13211 if (!fgets(res, sizeof(res), f))
13212 res[0] = '\0';
13213 pos = strchr(res, '\n');
13214 if (pos)
13215 *pos = '\0';
13216 fclose(f);
13217 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
13218 res);
13219 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
13220 if (system(resp) != 0) {
13221 }
13222 snprintf(resp, sizeof(resp),
13223 "SSID,,BSSID,,failureReason,%s", res);
13224 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13225 return 0;
13226 }
13227
13228 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13229 return 0;
13230 }
13231
13232 if (!prod_ess_assoc)
13233 goto report;
13234
13235 ctrl = open_wpa_mon(intf);
13236 if (ctrl == NULL) {
13237 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13238 "wpa_supplicant monitor connection");
13239 return -1;
13240 }
13241
13242 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13243 buf, sizeof(buf));
13244
13245 wpa_ctrl_detach(ctrl);
13246 wpa_ctrl_close(ctrl);
13247
13248 if (res < 0) {
13249 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
13250 "network after OSU");
13251 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13252 return 0;
13253 }
13254
13255report:
13256 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13257 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13258 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
13259 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13260 return 0;
13261 }
13262
13263 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
13264 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013265 return 0;
13266}
13267
13268
Jouni Malinenf7222712019-06-13 01:50:21 +030013269static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
13270 struct sigma_conn *conn,
13271 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013272{
13273 const char *val;
13274 int timeout = 120;
13275
13276 val = get_param(cmd, "PolicyUpdate");
13277 if (val == NULL || atoi(val) == 0)
13278 return 1; /* No operation requested */
13279
13280 val = get_param(cmd, "Timeout");
13281 if (val)
13282 timeout = atoi(val);
13283
13284 if (timeout) {
13285 /* TODO: time out the command and return
13286 * PolicyUpdateStatus,TIMEOUT if needed. */
13287 }
13288
13289 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
13290 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13291 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
13292 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
13293 return 0;
13294 }
13295
13296 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
13297 return 0;
13298}
13299
13300
Jouni Malinenf7222712019-06-13 01:50:21 +030013301static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
13302 struct sigma_conn *conn,
13303 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013304{
13305 struct wpa_ctrl *ctrl;
13306 const char *intf = get_param(cmd, "Interface");
13307 const char *bssid = get_param(cmd, "Bssid");
13308 const char *ssid = get_param(cmd, "SSID");
13309 const char *security = get_param(cmd, "Security");
13310 const char *passphrase = get_param(cmd, "Passphrase");
13311 const char *pin = get_param(cmd, "PIN");
13312 char buf[1000];
13313 char ssid_hex[200], passphrase_hex[200];
13314 const char *keymgmt, *cipher;
13315
13316 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013317 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013318
13319 if (!bssid) {
13320 send_resp(dut, conn, SIGMA_ERROR,
13321 "ErrorCode,Missing Bssid argument");
13322 return 0;
13323 }
13324
13325 if (!ssid) {
13326 send_resp(dut, conn, SIGMA_ERROR,
13327 "ErrorCode,Missing SSID argument");
13328 return 0;
13329 }
13330
13331 if (!security) {
13332 send_resp(dut, conn, SIGMA_ERROR,
13333 "ErrorCode,Missing Security argument");
13334 return 0;
13335 }
13336
13337 if (!passphrase) {
13338 send_resp(dut, conn, SIGMA_ERROR,
13339 "ErrorCode,Missing Passphrase argument");
13340 return 0;
13341 }
13342
13343 if (!pin) {
13344 send_resp(dut, conn, SIGMA_ERROR,
13345 "ErrorCode,Missing PIN argument");
13346 return 0;
13347 }
13348
vamsi krishna8c9c1562017-05-12 15:51:46 +053013349 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
13350 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013351 send_resp(dut, conn, SIGMA_ERROR,
13352 "ErrorCode,Too long SSID/passphrase");
13353 return 0;
13354 }
13355
13356 ctrl = open_wpa_mon(intf);
13357 if (ctrl == NULL) {
13358 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13359 "wpa_supplicant monitor connection");
13360 return -2;
13361 }
13362
13363 if (strcasecmp(security, "wpa2-psk") == 0) {
13364 keymgmt = "WPA2PSK";
13365 cipher = "CCMP";
13366 } else {
13367 wpa_ctrl_detach(ctrl);
13368 wpa_ctrl_close(ctrl);
13369 send_resp(dut, conn, SIGMA_ERROR,
13370 "ErrorCode,Unsupported Security value");
13371 return 0;
13372 }
13373
13374 ascii2hexstr(ssid, ssid_hex);
13375 ascii2hexstr(passphrase, passphrase_hex);
13376 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
13377 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
13378
13379 if (wpa_command(intf, buf) < 0) {
13380 wpa_ctrl_detach(ctrl);
13381 wpa_ctrl_close(ctrl);
13382 send_resp(dut, conn, SIGMA_ERROR,
13383 "ErrorCode,Failed to start registrar");
13384 return 0;
13385 }
13386
13387 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
13388 dut->er_oper_performed = 1;
13389
13390 return wps_connection_event(dut, conn, ctrl, intf, 0);
13391}
13392
13393
Jouni Malinenf7222712019-06-13 01:50:21 +030013394static enum sigma_cmd_result
13395cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
13396 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013397{
13398 struct wpa_ctrl *ctrl;
13399 const char *intf = get_param(cmd, "Interface");
13400 const char *bssid = get_param(cmd, "Bssid");
13401 char buf[100];
13402
13403 if (!bssid) {
13404 send_resp(dut, conn, SIGMA_ERROR,
13405 "ErrorCode,Missing Bssid argument");
13406 return 0;
13407 }
13408
13409 ctrl = open_wpa_mon(intf);
13410 if (ctrl == NULL) {
13411 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13412 "wpa_supplicant monitor connection");
13413 return -2;
13414 }
13415
13416 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
13417
13418 if (wpa_command(intf, buf) < 0) {
13419 wpa_ctrl_detach(ctrl);
13420 wpa_ctrl_close(ctrl);
13421 send_resp(dut, conn, SIGMA_ERROR,
13422 "ErrorCode,Failed to start registrar");
13423 return 0;
13424 }
13425
13426 return wps_connection_event(dut, conn, ctrl, intf, 0);
13427}
13428
13429
Jouni Malinenf7222712019-06-13 01:50:21 +030013430static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
13431 struct sigma_conn *conn,
13432 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053013433{
13434 struct wpa_ctrl *ctrl;
13435 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013436 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013437 const char *config_method = get_param(cmd, "WPSConfigMethod");
13438 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053013439 int res;
13440 char buf[256];
13441 const char *events[] = {
13442 "CTRL-EVENT-CONNECTED",
13443 "WPS-OVERLAP-DETECTED",
13444 "WPS-TIMEOUT",
13445 "WPS-FAIL",
13446 NULL
13447 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013448 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053013449
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013450 /* 60G WPS tests do not pass Interface parameter */
13451 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013452 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013453
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013454 if (dut->mode == SIGMA_MODE_AP)
13455 return ap_wps_registration(dut, conn, cmd);
13456
13457 if (config_method) {
13458 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
13459 * sta_wps_enter_pin before calling start_wps_registration. */
13460 if (strcasecmp(config_method, "PBC") == 0)
13461 dut->wps_method = WFA_CS_WPS_PBC;
13462 }
13463 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
13464 send_resp(dut, conn, SIGMA_ERROR,
13465 "ErrorCode,WPS parameters not yet set");
13466 return STATUS_SENT;
13467 }
13468
13469 /* Make sure WPS is enabled (also for STA mode) */
13470 dut->wps_disable = 0;
13471
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013472 if (dut->band == WPS_BAND_60G && network_mode &&
13473 strcasecmp(network_mode, "PBSS") == 0) {
13474 sigma_dut_print(dut, DUT_MSG_DEBUG,
13475 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013476 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013477 return -2;
13478 }
13479
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013480 if (dut->force_rsn_ie) {
13481 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
13482 dut->force_rsn_ie);
13483 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
13484 sigma_dut_print(dut, DUT_MSG_INFO,
13485 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020013486 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013487 }
13488 }
13489
vamsi krishna9b144002017-09-20 13:28:13 +053013490 ctrl = open_wpa_mon(intf);
13491 if (!ctrl) {
13492 sigma_dut_print(dut, DUT_MSG_ERROR,
13493 "Failed to open wpa_supplicant monitor connection");
13494 return -2;
13495 }
13496
13497 role = get_param(cmd, "WpsRole");
13498 if (!role) {
13499 send_resp(dut, conn, SIGMA_INVALID,
13500 "ErrorCode,WpsRole not provided");
13501 goto fail;
13502 }
13503
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013504 if (strcasecmp(role, "Enrollee") != 0) {
13505 /* Registrar role for STA not supported */
13506 send_resp(dut, conn, SIGMA_ERROR,
13507 "ErrorCode,Unsupported WpsRole value");
13508 goto fail;
13509 }
13510
13511 if (is_60g_sigma_dut(dut)) {
13512 if (dut->wps_method == WFA_CS_WPS_PBC)
13513 snprintf(buf, sizeof(buf), "WPS_PBC");
13514 else /* WFA_CS_WPS_PIN_KEYPAD */
13515 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
13516 dut->wps_pin);
13517 if (wpa_command(intf, buf) < 0) {
13518 send_resp(dut, conn, SIGMA_ERROR,
13519 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053013520 goto fail;
13521 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013522 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13523 if (res < 0) {
13524 send_resp(dut, conn, SIGMA_ERROR,
13525 "ErrorCode,WPS connection did not complete");
13526 goto fail;
13527 }
13528 if (strstr(buf, "WPS-TIMEOUT")) {
13529 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
13530 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13531 send_resp(dut, conn, SIGMA_COMPLETE,
13532 "WpsState,OverlapSession");
13533 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13534 send_resp(dut, conn, SIGMA_COMPLETE,
13535 "WpsState,Successful");
13536 } else {
13537 send_resp(dut, conn, SIGMA_COMPLETE,
13538 "WpsState,Failure");
13539 }
13540 } else {
13541 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053013542 if (wpa_command(intf, "WPS_PBC") < 0) {
13543 send_resp(dut, conn, SIGMA_ERROR,
13544 "ErrorCode,Failed to enable PBC");
13545 goto fail;
13546 }
13547 } else {
13548 /* TODO: PIN method */
13549 send_resp(dut, conn, SIGMA_ERROR,
13550 "ErrorCode,Unsupported WpsConfigMethod value");
13551 goto fail;
13552 }
13553 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13554 if (res < 0) {
13555 send_resp(dut, conn, SIGMA_ERROR,
13556 "ErrorCode,WPS connection did not complete");
13557 goto fail;
13558 }
13559 if (strstr(buf, "WPS-TIMEOUT")) {
13560 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
13561 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13562 send_resp(dut, conn, SIGMA_ERROR,
13563 "ErrorCode,OverlapSession");
13564 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13565 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
13566 } else {
13567 send_resp(dut, conn, SIGMA_ERROR,
13568 "ErrorCode,WPS operation failed");
13569 }
vamsi krishna9b144002017-09-20 13:28:13 +053013570 }
13571
13572fail:
13573 wpa_ctrl_detach(ctrl);
13574 wpa_ctrl_close(ctrl);
13575 return 0;
13576}
13577
13578
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013579static int req_intf(struct sigma_cmd *cmd)
13580{
13581 return get_param(cmd, "interface") == NULL ? -1 : 0;
13582}
13583
13584
13585void sta_register_cmds(void)
13586{
13587 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
13588 cmd_sta_get_ip_config);
13589 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
13590 cmd_sta_set_ip_config);
13591 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
13592 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
13593 cmd_sta_get_mac_address);
13594 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
13595 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
13596 cmd_sta_verify_ip_connection);
13597 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
13598 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
13599 cmd_sta_set_encryption);
13600 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
13601 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
13602 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
13603 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
13604 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
13605 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
13606 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
13607 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
13608 cmd_sta_set_eapakaprime);
13609 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
13610 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
13611 /* TODO: sta_set_ibss */
13612 /* TODO: sta_set_mode */
13613 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
13614 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
13615 /* TODO: sta_up_load */
13616 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
13617 cmd_sta_preset_testparameters);
13618 /* TODO: sta_set_system */
13619 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
13620 /* TODO: sta_set_rifs_test */
13621 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
13622 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
13623 /* TODO: sta_send_coexist_mgmt */
13624 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
13625 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
13626 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
13627 sigma_dut_reg_cmd("sta_reset_default", req_intf,
13628 cmd_sta_reset_default);
13629 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
13630 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
13631 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
13632 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
13633 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013634 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013635 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
13636 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
13637 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
13638 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
13639 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013640 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
13641 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013642 sigma_dut_reg_cmd("sta_add_credential", req_intf,
13643 cmd_sta_add_credential);
13644 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013645 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013646 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
13647 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
13648 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
13649 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
13650 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
13651 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030013652 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013653 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
13654 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013655 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053013656 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013657}