blob: 84cc0066a48a6fe82985e4bd9f4ec1f845d193be [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;
Jouni Malinen67433fc2020-06-26 22:50:33 +03008059 dut->client_privacy = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308060
Sunil Duttfebf8a82018-02-09 18:50:13 +05308061 if (dut->program != PROGRAM_VHT)
8062 return cmd_sta_p2p_reset(dut, conn, cmd);
8063
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08008064 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008065}
8066
8067
Jouni Malinenf7222712019-06-13 01:50:21 +03008068static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
8069 struct sigma_conn *conn,
8070 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008071{
8072 const char *program = get_param(cmd, "Program");
8073
8074 if (program == NULL)
8075 return -1;
8076#ifdef ANDROID_NAN
8077 if (strcasecmp(program, "NAN") == 0)
8078 return nan_cmd_sta_get_events(dut, conn, cmd);
8079#endif /* ANDROID_NAN */
8080 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8081 return 0;
8082}
8083
8084
Jouni Malinen82905202018-04-29 17:20:10 +03008085static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
8086 struct sigma_cmd *cmd)
8087{
8088 const char *url = get_param(cmd, "url");
8089 const char *method = get_param(cmd, "method");
8090 pid_t pid;
8091 int status;
8092
8093 if (!url || !method)
8094 return -1;
8095
8096 /* TODO: Add support for method,post */
8097 if (strcasecmp(method, "get") != 0) {
8098 send_resp(dut, conn, SIGMA_ERROR,
8099 "ErrorCode,Unsupported method");
8100 return 0;
8101 }
8102
8103 pid = fork();
8104 if (pid < 0) {
8105 perror("fork");
8106 return -1;
8107 }
8108
8109 if (pid == 0) {
8110 char * argv[5] = { "wget", "-O", "/dev/null",
8111 (char *) url, NULL };
8112
8113 execv("/usr/bin/wget", argv);
8114 perror("execv");
8115 exit(0);
8116 return -1;
8117 }
8118
8119 if (waitpid(pid, &status, 0) < 0) {
8120 perror("waitpid");
8121 return -1;
8122 }
8123
8124 if (WIFEXITED(status)) {
8125 const char *errmsg;
8126
8127 if (WEXITSTATUS(status) == 0)
8128 return 1;
8129 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
8130 WEXITSTATUS(status));
8131 switch (WEXITSTATUS(status)) {
8132 case 4:
8133 errmsg = "errmsg,Network failure";
8134 break;
8135 case 8:
8136 errmsg = "errmsg,Server issued an error response";
8137 break;
8138 default:
8139 errmsg = "errmsg,Unknown failure from wget";
8140 break;
8141 }
8142 send_resp(dut, conn, SIGMA_ERROR, errmsg);
8143 return 0;
8144 }
8145
8146 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
8147 return 0;
8148}
8149
8150
Jouni Malinenf7222712019-06-13 01:50:21 +03008151static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
8152 struct sigma_conn *conn,
8153 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008154{
8155 const char *program = get_param(cmd, "Prog");
8156
Jouni Malinen82905202018-04-29 17:20:10 +03008157 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008158 return -1;
8159#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03008160 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008161 return nan_cmd_sta_exec_action(dut, conn, cmd);
8162#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03008163
8164 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07008165 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03008166
8167 if (get_param(cmd, "url"))
8168 return sta_exec_action_url(dut, conn, cmd);
8169
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008170 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8171 return 0;
8172}
8173
8174
Jouni Malinenf7222712019-06-13 01:50:21 +03008175static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
8176 struct sigma_conn *conn,
8177 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008178{
8179 const char *intf = get_param(cmd, "Interface");
8180 const char *val, *mcs32, *rate;
8181
8182 val = get_param(cmd, "GREENFIELD");
8183 if (val) {
8184 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
8185 /* Enable GD */
8186 send_resp(dut, conn, SIGMA_ERROR,
8187 "ErrorCode,GF not supported");
8188 return 0;
8189 }
8190 }
8191
8192 val = get_param(cmd, "SGI20");
8193 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008194 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008195 case DRIVER_ATHEROS:
8196 ath_sta_set_sgi(dut, intf, val);
8197 break;
8198 default:
8199 send_resp(dut, conn, SIGMA_ERROR,
8200 "ErrorCode,SGI20 not supported");
8201 return 0;
8202 }
8203 }
8204
8205 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
8206 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
8207 if (mcs32 && rate) {
8208 /* TODO */
8209 send_resp(dut, conn, SIGMA_ERROR,
8210 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
8211 return 0;
8212 } else if (mcs32 && !rate) {
8213 /* TODO */
8214 send_resp(dut, conn, SIGMA_ERROR,
8215 "ErrorCode,MCS32 not supported");
8216 return 0;
8217 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008218 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008219 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008220 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008221 ath_sta_set_11nrates(dut, intf, rate);
8222 break;
8223 default:
8224 send_resp(dut, conn, SIGMA_ERROR,
8225 "ErrorCode,MCS32_FIXEDRATE not supported");
8226 return 0;
8227 }
8228 }
8229
8230 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8231}
8232
8233
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008234static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8235 int mcs_config)
8236{
8237#ifdef NL80211_SUPPORT
8238 int ret;
8239
8240 switch (mcs_config) {
8241 case HE_80_MCS0_7:
8242 case HE_80_MCS0_9:
8243 case HE_80_MCS0_11:
8244 ret = sta_set_he_mcs(dut, intf, mcs_config);
8245 if (ret) {
8246 sigma_dut_print(dut, DUT_MSG_ERROR,
8247 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8248 mcs_config, ret);
8249 }
8250 break;
8251 default:
8252 sigma_dut_print(dut, DUT_MSG_ERROR,
8253 "cmd_set_max_he_mcs: Invalid mcs %d",
8254 mcs_config);
8255 break;
8256 }
8257#else /* NL80211_SUPPORT */
8258 sigma_dut_print(dut, DUT_MSG_ERROR,
8259 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8260#endif /* NL80211_SUPPORT */
8261}
8262
8263
Arif Hussain480d5f42019-03-12 14:40:42 -07008264static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8265 struct sigma_cmd *cmd)
8266{
8267#ifdef NL80211_SUPPORT
8268 struct nlattr *params;
8269 struct nlattr *attr;
8270 struct nlattr *attr1;
8271 struct nl_msg *msg;
8272 int ifindex, ret;
8273 const char *val;
8274 const char *intf = get_param(cmd, "Interface");
8275 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8276 wake_interval_mantissa = 512;
8277 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
8278 protection = 0;
8279
8280 ifindex = if_nametoindex(intf);
8281 if (ifindex == 0) {
8282 sigma_dut_print(dut, DUT_MSG_ERROR,
8283 "%s: Index for interface %s failed",
8284 __func__, intf);
8285 return -1;
8286 }
8287
8288 val = get_param(cmd, "FlowType");
8289 if (val) {
8290 flow_type = atoi(val);
8291 if (flow_type != 0 && flow_type != 1) {
8292 sigma_dut_print(dut, DUT_MSG_ERROR,
8293 "TWT: Invalid FlowType %d", flow_type);
8294 return -1;
8295 }
8296 }
8297
8298 val = get_param(cmd, "TWT_Trigger");
8299 if (val) {
8300 twt_trigger = atoi(val);
8301 if (twt_trigger != 0 && twt_trigger != 1) {
8302 sigma_dut_print(dut, DUT_MSG_ERROR,
8303 "TWT: Invalid TWT_Trigger %d",
8304 twt_trigger);
8305 return -1;
8306 }
8307 }
8308
8309 val = get_param(cmd, "Protection");
8310 if (val) {
8311 protection = atoi(val);
8312 if (protection != 0 && protection != 1) {
8313 sigma_dut_print(dut, DUT_MSG_ERROR,
8314 "TWT: Invalid Protection %d",
8315 protection);
8316 return -1;
8317 }
8318 }
8319
8320 val = get_param(cmd, "TargetWakeTime");
8321 if (val)
8322 target_wake_time = atoi(val);
8323
8324 val = get_param(cmd, "WakeIntervalMantissa");
8325 if (val)
8326 wake_interval_mantissa = atoi(val);
8327
8328 val = get_param(cmd, "WakeIntervalExp");
8329 if (val)
8330 wake_interval_exp = atoi(val);
8331
8332 val = get_param(cmd, "NominalMinWakeDur");
8333 if (val)
8334 nominal_min_wake_dur = atoi(val);
8335
8336 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8337 NL80211_CMD_VENDOR)) ||
8338 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8339 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8340 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8341 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8342 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8343 !(params = nla_nest_start(
8344 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
8345 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8346 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8347 wake_interval_exp) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008348 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, 1) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008349 (twt_trigger &&
8350 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008351 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8352 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008353 (protection &&
8354 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008355 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8356 target_wake_time) ||
8357 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8358 nominal_min_wake_dur) ||
8359 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8360 wake_interval_mantissa)) {
8361 sigma_dut_print(dut, DUT_MSG_ERROR,
8362 "%s: err in adding vendor_cmd and vendor_data",
8363 __func__);
8364 nlmsg_free(msg);
8365 return -1;
8366 }
8367 nla_nest_end(msg, attr1);
8368 nla_nest_end(msg, params);
8369 nla_nest_end(msg, attr);
8370
8371 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8372 if (ret) {
8373 sigma_dut_print(dut, DUT_MSG_ERROR,
8374 "%s: err in send_and_recv_msgs, ret=%d",
8375 __func__, ret);
8376 }
8377
8378 return ret;
8379#else /* NL80211_SUPPORT */
8380 sigma_dut_print(dut, DUT_MSG_ERROR,
8381 "TWT request cannot be done without NL80211_SUPPORT defined");
8382 return -1;
8383#endif /* NL80211_SUPPORT */
8384}
8385
8386
8387static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8388 struct sigma_cmd *cmd)
8389{
8390 #ifdef NL80211_SUPPORT
8391 struct nlattr *params;
8392 struct nlattr *attr;
8393 struct nlattr *attr1;
8394 int ifindex, ret;
8395 struct nl_msg *msg;
8396 const char *intf = get_param(cmd, "Interface");
8397
8398 ifindex = if_nametoindex(intf);
8399 if (ifindex == 0) {
8400 sigma_dut_print(dut, DUT_MSG_ERROR,
8401 "%s: Index for interface %s failed",
8402 __func__, intf);
8403 return -1;
8404 }
8405
8406 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8407 NL80211_CMD_VENDOR)) ||
8408 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8409 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8410 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8411 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8412 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8413 !(params = nla_nest_start(
8414 msg,
8415 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8416 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8417 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8418 sigma_dut_print(dut, DUT_MSG_ERROR,
8419 "%s: err in adding vendor_cmd and vendor_data",
8420 __func__);
8421 nlmsg_free(msg);
8422 return -1;
8423 }
8424 nla_nest_end(msg, attr1);
8425 nla_nest_end(msg, params);
8426 nla_nest_end(msg, attr);
8427
8428 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8429 if (ret) {
8430 sigma_dut_print(dut, DUT_MSG_ERROR,
8431 "%s: err in send_and_recv_msgs, ret=%d",
8432 __func__, ret);
8433 }
8434
8435 return ret;
8436#else /* NL80211_SUPPORT */
8437 sigma_dut_print(dut, DUT_MSG_ERROR,
8438 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8439 return -1;
8440#endif /* NL80211_SUPPORT */
8441}
8442
8443
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008444static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8445 struct sigma_cmd *cmd)
8446{
8447#ifdef NL80211_SUPPORT
8448 struct nlattr *params;
8449 struct nlattr *attr;
8450 struct nlattr *attr1;
8451 struct nl_msg *msg;
8452 int ifindex, ret;
8453 const char *val;
8454 const char *intf = get_param(cmd, "Interface");
8455 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8456 ulmu_data_dis = 0;
8457
8458 ifindex = if_nametoindex(intf);
8459 if (ifindex == 0) {
8460 sigma_dut_print(dut, DUT_MSG_ERROR,
8461 "%s: Index for interface %s failed",
8462 __func__, intf);
8463 return -1;
8464 }
8465 val = get_param(cmd, "OMCtrl_RxNSS");
8466 if (val)
8467 rx_nss = atoi(val);
8468
8469 val = get_param(cmd, "OMCtrl_ChnlWidth");
8470 if (val)
8471 ch_bw = atoi(val);
8472
8473 val = get_param(cmd, "OMCtrl_ULMUDisable");
8474 if (val)
8475 ulmu_dis = atoi(val);
8476
8477 val = get_param(cmd, "OMCtrl_TxNSTS");
8478 if (val)
8479 tx_nsts = atoi(val);
8480
8481 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8482 if (val)
8483 ulmu_data_dis = atoi(val);
8484
8485 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8486 NL80211_CMD_VENDOR)) ||
8487 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8488 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8489 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8490 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8491 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8492 !(params = nla_nest_start(
8493 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8494 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8495 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8496 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8497 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8498 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8499 ulmu_data_dis) ||
8500 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8501 ulmu_dis)) {
8502 sigma_dut_print(dut, DUT_MSG_ERROR,
8503 "%s: err in adding vendor_cmd and vendor_data",
8504 __func__);
8505 nlmsg_free(msg);
8506 return -1;
8507 }
8508 nla_nest_end(msg, attr1);
8509 nla_nest_end(msg, params);
8510 nla_nest_end(msg, attr);
8511
8512 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8513 if (ret) {
8514 sigma_dut_print(dut, DUT_MSG_ERROR,
8515 "%s: err in send_and_recv_msgs, ret=%d",
8516 __func__, ret);
8517 }
8518
8519 return ret;
8520#else /* NL80211_SUPPORT */
8521 sigma_dut_print(dut, DUT_MSG_ERROR,
8522 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8523 return -1;
8524#endif /* NL80211_SUPPORT */
8525}
8526
8527
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008528static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8529 struct sigma_conn *conn,
8530 struct sigma_cmd *cmd)
8531{
8532 const char *intf = get_param(cmd, "Interface");
8533 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008534 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008535 int tkip = -1;
8536 int wep = -1;
8537
Arif Hussaina37e9552018-06-20 17:05:59 -07008538 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008539 val = get_param(cmd, "SGI80");
8540 if (val) {
8541 int sgi80;
8542
8543 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008544 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008545 }
8546
8547 val = get_param(cmd, "TxBF");
8548 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008549 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008550 case DRIVER_WCN:
8551 if (sta_set_tx_beamformee(dut, intf, 1)) {
8552 send_resp(dut, conn, SIGMA_ERROR,
8553 "ErrorCode,Failed to set TX beamformee enable");
8554 return 0;
8555 }
8556 break;
8557 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008558 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008559 send_resp(dut, conn, SIGMA_ERROR,
8560 "ErrorCode,Setting vhtsubfee failed");
8561 return 0;
8562 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008563 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008564 send_resp(dut, conn, SIGMA_ERROR,
8565 "ErrorCode,Setting vhtsubfer failed");
8566 return 0;
8567 }
8568 break;
8569 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008570 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008571 "Unsupported driver type");
8572 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008573 }
8574 }
8575
8576 val = get_param(cmd, "MU_TxBF");
8577 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008578 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008579 case DRIVER_ATHEROS:
8580 ath_sta_set_txsp_stream(dut, intf, "1SS");
8581 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008582 run_iwpriv(dut, intf, "vhtmubfee 1");
8583 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308584 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008585 case DRIVER_WCN:
8586 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8587 send_resp(dut, conn, SIGMA_ERROR,
8588 "ErrorCode,Failed to set RX/TXSP_STREAM");
8589 return 0;
8590 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308591 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008592 default:
8593 sigma_dut_print(dut, DUT_MSG_ERROR,
8594 "Setting SP_STREAM not supported");
8595 break;
8596 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008597 }
8598
8599 val = get_param(cmd, "LDPC");
8600 if (val) {
8601 int ldpc;
8602
8603 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008604 run_iwpriv(dut, intf, "ldpc %d", ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008605 }
8606
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008607 val = get_param(cmd, "BCC");
8608 if (val) {
8609 int bcc;
8610
8611 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8612 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8613 * is mutually exclusive to bcc */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008614 run_iwpriv(dut, intf, "ldpc %d", !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008615 }
8616
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008617 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8618 if (val && dut->sta_nss == 1)
8619 cmd_set_max_he_mcs(dut, intf, atoi(val));
8620
8621 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8622 if (val && dut->sta_nss == 2)
8623 cmd_set_max_he_mcs(dut, intf, atoi(val));
8624
Arif Hussainac6c5112018-05-25 17:34:00 -07008625 val = get_param(cmd, "MCS_FixedRate");
8626 if (val) {
8627#ifdef NL80211_SUPPORT
8628 int mcs, ratecode = 0;
8629 enum he_mcs_config mcs_config;
8630 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008631 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008632
8633 ratecode = (0x07 & dut->sta_nss) << 5;
8634 mcs = atoi(val);
8635 /* Add the MCS to the ratecode */
8636 if (mcs >= 0 && mcs <= 11) {
8637 ratecode += mcs;
8638 if (dut->device_type == STA_testbed &&
8639 mcs > 7 && mcs <= 11) {
8640 if (mcs <= 9)
8641 mcs_config = HE_80_MCS0_9;
8642 else
8643 mcs_config = HE_80_MCS0_11;
8644 ret = sta_set_he_mcs(dut, intf, mcs_config);
8645 if (ret) {
8646 sigma_dut_print(dut, DUT_MSG_ERROR,
8647 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8648 mcs, mcs_config, ret);
8649 }
8650 }
8651 snprintf(buf, sizeof(buf),
8652 "iwpriv %s set_11ax_rate 0x%03x",
8653 intf, ratecode);
8654 if (system(buf) != 0) {
8655 sigma_dut_print(dut, DUT_MSG_ERROR,
8656 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8657 ratecode);
8658 }
8659 } else {
8660 sigma_dut_print(dut, DUT_MSG_ERROR,
8661 "MCS_FixedRate: HE MCS %d not supported",
8662 mcs);
8663 }
8664#else /* NL80211_SUPPORT */
8665 sigma_dut_print(dut, DUT_MSG_ERROR,
8666 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8667#endif /* NL80211_SUPPORT */
8668 }
8669
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008670 val = get_param(cmd, "opt_md_notif_ie");
8671 if (val) {
8672 char *result = NULL;
8673 char delim[] = ";";
8674 char token[30];
8675 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308676 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008677
Peng Xub8fc5cc2017-05-10 17:27:28 -07008678 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308679 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008680
8681 /* Extract the NSS information */
8682 if (result) {
8683 value = atoi(result);
8684 switch (value) {
8685 case 1:
8686 config_val = 1;
8687 break;
8688 case 2:
8689 config_val = 3;
8690 break;
8691 case 3:
8692 config_val = 7;
8693 break;
8694 case 4:
8695 config_val = 15;
8696 break;
8697 default:
8698 config_val = 3;
8699 break;
8700 }
8701
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008702 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8703 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008704
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008705 }
8706
8707 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308708 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008709 if (result) {
8710 value = atoi(result);
8711 switch (value) {
8712 case 20:
8713 config_val = 0;
8714 break;
8715 case 40:
8716 config_val = 1;
8717 break;
8718 case 80:
8719 config_val = 2;
8720 break;
8721 case 160:
8722 config_val = 3;
8723 break;
8724 default:
8725 config_val = 2;
8726 break;
8727 }
8728
8729 dut->chwidth = config_val;
8730
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008731 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008732 }
8733
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008734 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008735 }
8736
8737 val = get_param(cmd, "nss_mcs_cap");
8738 if (val) {
8739 int nss, mcs;
8740 char token[20];
8741 char *result = NULL;
8742 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308743 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008744
Peng Xub8fc5cc2017-05-10 17:27:28 -07008745 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308746 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308747 if (!result) {
8748 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008749 "NSS not specified");
8750 send_resp(dut, conn, SIGMA_ERROR,
8751 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308752 return 0;
8753 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008754 nss = atoi(result);
8755
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008756 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07008757 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008758
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308759 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008760 if (result == NULL) {
8761 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008762 "MCS not specified");
8763 send_resp(dut, conn, SIGMA_ERROR,
8764 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008765 return 0;
8766 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308767 result = strtok_r(result, "-", &saveptr);
8768 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308769 if (!result) {
8770 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008771 "MCS not specified");
8772 send_resp(dut, conn, SIGMA_ERROR,
8773 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308774 return 0;
8775 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008776 mcs = atoi(result);
8777
Arif Hussaina37e9552018-06-20 17:05:59 -07008778 if (program && strcasecmp(program, "HE") == 0) {
8779#ifdef NL80211_SUPPORT
8780 enum he_mcs_config mcs_config;
8781 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008782
Arif Hussaina37e9552018-06-20 17:05:59 -07008783 if (mcs >= 0 && mcs <= 7) {
8784 mcs_config = HE_80_MCS0_7;
8785 } else if (mcs > 7 && mcs <= 9) {
8786 mcs_config = HE_80_MCS0_9;
8787 } else if (mcs > 9 && mcs <= 11) {
8788 mcs_config = HE_80_MCS0_11;
8789 } else {
8790 sigma_dut_print(dut, DUT_MSG_ERROR,
8791 "nss_mcs_cap: HE: Invalid mcs: %d",
8792 mcs);
8793 send_resp(dut, conn, SIGMA_ERROR,
8794 "errorCode,Invalid MCS");
8795 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008796 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008797
8798 ret = sta_set_he_mcs(dut, intf, mcs_config);
8799 if (ret) {
8800 sigma_dut_print(dut, DUT_MSG_ERROR,
8801 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
8802 mcs_config, ret);
8803 send_resp(dut, conn, SIGMA_ERROR,
8804 "errorCode,Failed to set MCS");
8805 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008806 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008807#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008808 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008809 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
8810#endif /* NL80211_SUPPORT */
8811 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008812 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07008813
8814 switch (nss) {
8815 case 1:
8816 switch (mcs) {
8817 case 7:
8818 vht_mcsmap = 0xfffc;
8819 break;
8820 case 8:
8821 vht_mcsmap = 0xfffd;
8822 break;
8823 case 9:
8824 vht_mcsmap = 0xfffe;
8825 break;
8826 default:
8827 vht_mcsmap = 0xfffe;
8828 break;
8829 }
8830 break;
8831 case 2:
8832 switch (mcs) {
8833 case 7:
8834 vht_mcsmap = 0xfff0;
8835 break;
8836 case 8:
8837 vht_mcsmap = 0xfff5;
8838 break;
8839 case 9:
8840 vht_mcsmap = 0xfffa;
8841 break;
8842 default:
8843 vht_mcsmap = 0xfffa;
8844 break;
8845 }
8846 break;
8847 case 3:
8848 switch (mcs) {
8849 case 7:
8850 vht_mcsmap = 0xffc0;
8851 break;
8852 case 8:
8853 vht_mcsmap = 0xffd5;
8854 break;
8855 case 9:
8856 vht_mcsmap = 0xffea;
8857 break;
8858 default:
8859 vht_mcsmap = 0xffea;
8860 break;
8861 }
8862 break;
8863 default:
8864 vht_mcsmap = 0xffea;
8865 break;
8866 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008867 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008868 }
8869 }
8870
8871 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
8872
8873 val = get_param(cmd, "Vht_tkip");
8874 if (val)
8875 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8876
8877 val = get_param(cmd, "Vht_wep");
8878 if (val)
8879 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8880
8881 if (tkip != -1 || wep != -1) {
8882 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008883 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008884 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008885 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008886 } else {
8887 sigma_dut_print(dut, DUT_MSG_ERROR,
8888 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
8889 return 0;
8890 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008891 }
8892
Arif Hussain55f00da2018-07-03 08:28:26 -07008893 val = get_param(cmd, "txBandwidth");
8894 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008895 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07008896 case DRIVER_WCN:
8897 if (wcn_sta_set_width(dut, intf, val) < 0) {
8898 send_resp(dut, conn, SIGMA_ERROR,
8899 "ErrorCode,Failed to set txBandwidth");
8900 return 0;
8901 }
8902 break;
8903 case DRIVER_ATHEROS:
8904 if (ath_set_width(dut, conn, intf, val) < 0) {
8905 send_resp(dut, conn, SIGMA_ERROR,
8906 "ErrorCode,Failed to set txBandwidth");
8907 return 0;
8908 }
8909 break;
8910 default:
8911 sigma_dut_print(dut, DUT_MSG_ERROR,
8912 "Setting txBandwidth not supported");
8913 break;
8914 }
8915 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008916
Arif Hussain9765f7d2018-07-03 08:28:26 -07008917 val = get_param(cmd, "BeamformeeSTS");
8918 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07008919 if (sta_set_tx_beamformee(dut, intf, 1)) {
8920 send_resp(dut, conn, SIGMA_ERROR,
8921 "ErrorCode,Failed to set TX beamformee enable");
8922 return 0;
8923 }
8924
Arif Hussain9765f7d2018-07-03 08:28:26 -07008925 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
8926 send_resp(dut, conn, SIGMA_ERROR,
8927 "ErrorCode,Failed to set BeamformeeSTS");
8928 return 0;
8929 }
8930 }
8931
Arif Hussain68d23f52018-07-11 13:39:08 -07008932 val = get_param(cmd, "Trig_MAC_Padding_Dur");
8933 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008934#ifdef NL80211_SUPPORT
8935 enum qca_wlan_he_mac_padding_dur set_val;
8936
8937 switch (atoi(val)) {
8938 case 16:
8939 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
8940 break;
8941 case 8:
8942 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
8943 break;
8944 default:
8945 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
8946 break;
8947 }
8948 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008949 send_resp(dut, conn, SIGMA_ERROR,
8950 "ErrorCode,Failed to set MAC padding duration");
8951 return 0;
8952 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008953#else /* NL80211_SUPPORT */
8954 sigma_dut_print(dut, DUT_MSG_ERROR,
8955 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
8956#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008957 }
8958
Arif Hussain480d5f42019-03-12 14:40:42 -07008959 val = get_param(cmd, "TWT_ReqSupport");
8960 if (val) {
8961 int set_val;
8962
8963 if (strcasecmp(val, "Enable") == 0) {
8964 set_val = 1;
8965 } else if (strcasecmp(val, "Disable") == 0) {
8966 set_val = 0;
8967 } else {
8968 send_resp(dut, conn, SIGMA_ERROR,
8969 "ErrorCode,Invalid TWT_ReqSupport");
8970 return STATUS_SENT;
8971 }
8972
8973 if (sta_set_twt_req_support(dut, intf, set_val)) {
8974 sigma_dut_print(dut, DUT_MSG_ERROR,
8975 "Failed to set TWT req support %d",
8976 set_val);
8977 send_resp(dut, conn, SIGMA_ERROR,
8978 "ErrorCode,Failed to set TWT_ReqSupport");
8979 return STATUS_SENT;
8980 }
8981 }
8982
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008983 val = get_param(cmd, "MU_EDCA");
8984 if (val && (strcasecmp(val, "Override") == 0)) {
8985 if (sta_set_mu_edca_override(dut, intf, 1)) {
8986 send_resp(dut, conn, SIGMA_ERROR,
8987 "ErrorCode,Failed to set MU EDCA override");
8988 return 0;
8989 }
8990 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008991
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008992 val = get_param(cmd, "OMControl");
8993 if (val) {
8994 int set_val = 1;
8995
8996 if (strcasecmp(val, "Enable") == 0)
8997 set_val = 1;
8998 else if (strcasecmp(val, "Disable") == 0)
8999 set_val = 0;
9000
9001 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
9002 send_resp(dut, conn, SIGMA_ERROR,
9003 "ErrorCode,Failed to set OM ctrl supp");
9004 return 0;
9005 }
9006 }
9007
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009008 val = get_param(cmd, "ADDBAResp_BufSize");
9009 if (val) {
9010 int buf_size;
9011
9012 if (strcasecmp(val, "gt64") == 0)
9013 buf_size = 256;
9014 else
9015 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009016 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009017 sta_set_addba_buf_size(dut, intf, buf_size)) {
9018 send_resp(dut, conn, SIGMA_ERROR,
9019 "ErrorCode,set addbaresp_buff_size failed");
9020 return 0;
9021 }
9022 }
9023
9024 val = get_param(cmd, "ADDBAReq_BufSize");
9025 if (val) {
9026 int buf_size;
9027
9028 if (strcasecmp(val, "gt64") == 0)
9029 buf_size = 256;
9030 else
9031 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009032 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009033 sta_set_addba_buf_size(dut, intf, buf_size)) {
9034 send_resp(dut, conn, SIGMA_ERROR,
9035 "ErrorCode,set addbareq_buff_size failed");
9036 return 0;
9037 }
9038 }
9039
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009040 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9041}
9042
9043
9044static int sta_set_wireless_60g(struct sigma_dut *dut,
9045 struct sigma_conn *conn,
9046 struct sigma_cmd *cmd)
9047{
9048 const char *dev_role = get_param(cmd, "DevRole");
9049
9050 if (!dev_role) {
9051 send_resp(dut, conn, SIGMA_INVALID,
9052 "ErrorCode,DevRole not specified");
9053 return 0;
9054 }
9055
9056 if (strcasecmp(dev_role, "PCP") == 0)
9057 return sta_set_60g_pcp(dut, conn, cmd);
9058 if (strcasecmp(dev_role, "STA") == 0)
9059 return sta_set_60g_sta(dut, conn, cmd);
9060 send_resp(dut, conn, SIGMA_INVALID,
9061 "ErrorCode,DevRole not supported");
9062 return 0;
9063}
9064
9065
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309066static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
9067 struct sigma_cmd *cmd)
9068{
9069 int status;
9070 const char *intf = get_param(cmd, "Interface");
9071 const char *val = get_param(cmd, "DevRole");
9072
9073 if (val && strcasecmp(val, "STA-CFON") == 0) {
9074 status = sta_cfon_set_wireless(dut, conn, cmd);
9075 if (status)
9076 return status;
9077 }
9078 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9079}
9080
9081
Jouni Malinen67433fc2020-06-26 22:50:33 +03009082static enum sigma_cmd_result
9083sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
9084 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309085{
9086 const char *intf = get_param(cmd, "Interface");
9087 const char *val;
9088
9089 val = get_param(cmd, "ocvc");
9090 if (val)
9091 dut->ocvc = atoi(val);
9092
Jouni Malinen67433fc2020-06-26 22:50:33 +03009093 val = get_param(cmd, "ClientPrivacy");
9094 if (val) {
9095 dut->client_privacy = atoi(val);
9096 if (dut->client_privacy &&
9097 (wpa_command(intf, "SET mac_addr 1") < 0 ||
9098 wpa_command(intf, "SET rand_addr_lifetime 1") < 0 ||
9099 wpa_command(intf, "SET preassoc_mac_addr 1") < 0 ||
9100 wpa_command(intf, "SET gas_rand_mac_addr 1") < 0 ||
9101 wpa_command(intf, "SET gas_rand_addr_lifetime 1") < 0)) {
9102 send_resp(dut, conn, SIGMA_ERROR,
9103 "errorCode,Failed to enable random MAC address use");
9104 return STATUS_SENT_ERROR;
9105 }
9106 }
9107
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309108 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9109}
9110
9111
Jouni Malinenf7222712019-06-13 01:50:21 +03009112static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
9113 struct sigma_conn *conn,
9114 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009115{
9116 const char *val;
9117
9118 val = get_param(cmd, "Program");
9119 if (val) {
9120 if (strcasecmp(val, "11n") == 0)
9121 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08009122 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009123 return cmd_sta_set_wireless_vht(dut, conn, cmd);
9124 if (strcasecmp(val, "60ghz") == 0)
9125 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309126 if (strcasecmp(val, "OCE") == 0)
9127 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02009128 /* sta_set_wireless in WPS program is only used for 60G */
9129 if (is_60g_sigma_dut(dut))
9130 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309131 if (strcasecmp(val, "WPA3") == 0)
9132 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009133 send_resp(dut, conn, SIGMA_ERROR,
9134 "ErrorCode,Program value not supported");
9135 } else {
9136 send_resp(dut, conn, SIGMA_ERROR,
9137 "ErrorCode,Program argument not available");
9138 }
9139
9140 return 0;
9141}
9142
9143
9144static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
9145 int tid)
9146{
9147 char buf[100];
9148 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
9149
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05309150 if (tid < 0 ||
9151 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
9152 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
9153 return;
9154 }
9155
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009156 /*
9157 * Two ways to ensure that addba request with a
9158 * non zero TID could be sent out. EV 117296
9159 */
9160 snprintf(buf, sizeof(buf),
9161 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
9162 tid);
9163 if (system(buf) != 0) {
9164 sigma_dut_print(dut, DUT_MSG_ERROR,
9165 "Ping did not send out");
9166 }
9167
9168 snprintf(buf, sizeof(buf),
9169 "iwconfig %s | grep Access | awk '{print $6}' > %s",
9170 intf, VI_QOS_TMP_FILE);
9171 if (system(buf) != 0)
9172 return;
9173
9174 snprintf(buf, sizeof(buf),
9175 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
9176 intf, VI_QOS_TMP_FILE);
9177 if (system(buf) != 0)
9178 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
9179
9180 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
9181 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
9182 if (system(buf) != 0) {
9183 sigma_dut_print(dut, DUT_MSG_ERROR,
9184 "VI_QOS_TEMP_FILE generation error failed");
9185 }
9186 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9187 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9188 if (system(buf) != 0) {
9189 sigma_dut_print(dut, DUT_MSG_ERROR,
9190 "VI_QOS_FILE generation failed");
9191 }
9192
9193 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9194 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9195 if (system(buf) != 0) {
9196 sigma_dut_print(dut, DUT_MSG_ERROR,
9197 "VI_QOS_FILE generation failed");
9198 }
9199
9200 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
9201 if (system(buf) != 0) {
9202 }
9203}
9204
9205
9206static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9207 struct sigma_cmd *cmd)
9208{
9209 const char *intf = get_param(cmd, "Interface");
9210 const char *val;
9211 int tid = 0;
9212 char buf[100];
9213
9214 val = get_param(cmd, "TID");
9215 if (val) {
9216 tid = atoi(val);
9217 if (tid)
9218 ath_sta_inject_frame(dut, intf, tid);
9219 }
9220
9221 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009222 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009223
9224 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
9225 if (system(buf) != 0) {
9226 sigma_dut_print(dut, DUT_MSG_ERROR,
9227 "wifitool senddelba failed");
9228 }
9229
9230 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
9231 if (system(buf) != 0) {
9232 sigma_dut_print(dut, DUT_MSG_ERROR,
9233 "wifitool sendaddba failed");
9234 }
9235
9236 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9237
9238 return 1;
9239}
9240
9241
Lior David9981b512017-01-20 13:16:40 +02009242#ifdef __linux__
9243
9244static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
9245 int agg_size)
9246{
9247 char dir[128], buf[128];
9248 FILE *f;
9249 regex_t re;
9250 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03009251 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02009252
9253 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
9254 sigma_dut_print(dut, DUT_MSG_ERROR,
9255 "failed to get wil6210 debugfs dir");
9256 return -1;
9257 }
9258
Jouni Malinen3aa72862019-05-29 23:14:51 +03009259 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
9260 if (res < 0 || res >= sizeof(buf))
9261 return -1;
Lior David9981b512017-01-20 13:16:40 +02009262 f = fopen(buf, "r");
9263 if (!f) {
9264 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009265 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009266 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9267 if (res < 0 || res >= sizeof(buf))
9268 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009269 f = fopen(buf, "r");
9270 if (!f) {
9271 sigma_dut_print(dut, DUT_MSG_ERROR,
9272 "failed to open: %s", buf);
9273 return -1;
9274 }
Lior David9981b512017-01-20 13:16:40 +02009275 }
9276
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009277 /* can be either VRING tx... or RING... */
9278 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009279 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9280 goto out;
9281 }
9282
9283 /* find TX VRING for the mac address */
9284 found = 0;
9285 while (fgets(buf, sizeof(buf), f)) {
9286 if (strcasestr(buf, dest_mac)) {
9287 found = 1;
9288 break;
9289 }
9290 }
9291
9292 if (!found) {
9293 sigma_dut_print(dut, DUT_MSG_ERROR,
9294 "no TX VRING for %s", dest_mac);
9295 goto out;
9296 }
9297
9298 /* extract VRING ID, "VRING tx_<id> = {" */
9299 if (!fgets(buf, sizeof(buf), f)) {
9300 sigma_dut_print(dut, DUT_MSG_ERROR,
9301 "no VRING start line for %s", dest_mac);
9302 goto out;
9303 }
9304
9305 rc = regexec(&re, buf, 2, m, 0);
9306 regfree(&re);
9307 if (rc || m[1].rm_so < 0) {
9308 sigma_dut_print(dut, DUT_MSG_ERROR,
9309 "no VRING TX ID for %s", dest_mac);
9310 goto out;
9311 }
9312 buf[m[1].rm_eo] = 0;
9313 vring_id = atoi(&buf[m[1].rm_so]);
9314
9315 /* send the addba command */
9316 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009317 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9318 if (res < 0 || res >= sizeof(buf))
9319 return -1;
Lior David9981b512017-01-20 13:16:40 +02009320 f = fopen(buf, "w");
9321 if (!f) {
9322 sigma_dut_print(dut, DUT_MSG_ERROR,
9323 "failed to open: %s", buf);
9324 return -1;
9325 }
9326
9327 fprintf(f, "add %d %d\n", vring_id, agg_size);
9328
9329 ret = 0;
9330
9331out:
9332 fclose(f);
9333
9334 return ret;
9335}
9336
9337
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009338int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9339 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009340{
9341 const char *val;
9342 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009343
9344 val = get_param(cmd, "TID");
9345 if (val) {
9346 tid = atoi(val);
9347 if (tid != 0) {
9348 sigma_dut_print(dut, DUT_MSG_ERROR,
9349 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9350 tid);
9351 }
9352 }
9353
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009354 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009355 if (!val) {
9356 sigma_dut_print(dut, DUT_MSG_ERROR,
9357 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009358 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009359 }
9360
Lior David9981b512017-01-20 13:16:40 +02009361 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009362 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009363
9364 return 1;
9365}
9366
Lior David9981b512017-01-20 13:16:40 +02009367#endif /* __linux__ */
9368
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009369
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009370static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9371 struct sigma_cmd *cmd)
9372{
9373#ifdef NL80211_SUPPORT
9374 const char *intf = get_param(cmd, "Interface");
9375 const char *val;
9376 int tid = -1;
9377 int bufsize = 64;
9378 struct nl_msg *msg;
9379 int ret = 0;
9380 struct nlattr *params;
9381 int ifindex;
9382
9383 val = get_param(cmd, "TID");
9384 if (val)
9385 tid = atoi(val);
9386
9387 if (tid == -1) {
9388 send_resp(dut, conn, SIGMA_ERROR,
9389 "ErrorCode,sta_send_addba tid invalid");
9390 return 0;
9391 }
9392
9393 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9394
9395 ifindex = if_nametoindex(intf);
9396 if (ifindex == 0) {
9397 sigma_dut_print(dut, DUT_MSG_ERROR,
9398 "%s: Index for interface %s failed",
9399 __func__, intf);
9400 send_resp(dut, conn, SIGMA_ERROR,
9401 "ErrorCode,sta_send_addba interface invalid");
9402 return 0;
9403 }
9404
9405 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9406 NL80211_CMD_VENDOR)) ||
9407 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9408 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9409 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9410 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9411 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9412 nla_put_u8(msg,
9413 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9414 QCA_WLAN_ADD_BA) ||
9415 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9416 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009417 nla_put_u16(msg,
9418 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9419 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009420 sigma_dut_print(dut, DUT_MSG_ERROR,
9421 "%s: err in adding vendor_cmd and vendor_data",
9422 __func__);
9423 nlmsg_free(msg);
9424 send_resp(dut, conn, SIGMA_ERROR,
9425 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9426 return 0;
9427 }
9428 nla_nest_end(msg, params);
9429
9430 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9431 if (ret) {
9432 sigma_dut_print(dut, DUT_MSG_ERROR,
9433 "%s: err in send_and_recv_msgs, ret=%d",
9434 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309435 if (ret == -EOPNOTSUPP)
9436 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009437 send_resp(dut, conn, SIGMA_ERROR,
9438 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9439 return 0;
9440 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009441#else /* NL80211_SUPPORT */
9442 sigma_dut_print(dut, DUT_MSG_ERROR,
9443 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009444#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309445
9446 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009447}
9448
9449
Jouni Malinenf7222712019-06-13 01:50:21 +03009450static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9451 struct sigma_conn *conn,
9452 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009453{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009454 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009455 case DRIVER_ATHEROS:
9456 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009457 case DRIVER_WCN:
9458 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009459#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009460 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009461 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009462#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009463 default:
9464 /*
9465 * There is no driver specific implementation for other drivers.
9466 * Ignore the command and report COMPLETE since the following
9467 * throughput test operation will end up sending ADDBA anyway.
9468 */
9469 return 1;
9470 }
9471}
9472
9473
9474int inject_eth_frame(int s, const void *data, size_t len,
9475 unsigned short ethtype, char *dst, char *src)
9476{
9477 struct iovec iov[4] = {
9478 {
9479 .iov_base = dst,
9480 .iov_len = ETH_ALEN,
9481 },
9482 {
9483 .iov_base = src,
9484 .iov_len = ETH_ALEN,
9485 },
9486 {
9487 .iov_base = &ethtype,
9488 .iov_len = sizeof(unsigned short),
9489 },
9490 {
9491 .iov_base = (void *) data,
9492 .iov_len = len,
9493 }
9494 };
9495 struct msghdr msg = {
9496 .msg_name = NULL,
9497 .msg_namelen = 0,
9498 .msg_iov = iov,
9499 .msg_iovlen = 4,
9500 .msg_control = NULL,
9501 .msg_controllen = 0,
9502 .msg_flags = 0,
9503 };
9504
9505 return sendmsg(s, &msg, 0);
9506}
9507
9508#if defined(__linux__) || defined(__QNXNTO__)
9509
9510int inject_frame(int s, const void *data, size_t len, int encrypt)
9511{
9512#define IEEE80211_RADIOTAP_F_WEP 0x04
9513#define IEEE80211_RADIOTAP_F_FRAG 0x08
9514 unsigned char rtap_hdr[] = {
9515 0x00, 0x00, /* radiotap version */
9516 0x0e, 0x00, /* radiotap length */
9517 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9518 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9519 0x00, /* padding */
9520 0x00, 0x00, /* RX and TX flags to indicate that */
9521 0x00, 0x00, /* this is the injected frame directly */
9522 };
9523 struct iovec iov[2] = {
9524 {
9525 .iov_base = &rtap_hdr,
9526 .iov_len = sizeof(rtap_hdr),
9527 },
9528 {
9529 .iov_base = (void *) data,
9530 .iov_len = len,
9531 }
9532 };
9533 struct msghdr msg = {
9534 .msg_name = NULL,
9535 .msg_namelen = 0,
9536 .msg_iov = iov,
9537 .msg_iovlen = 2,
9538 .msg_control = NULL,
9539 .msg_controllen = 0,
9540 .msg_flags = 0,
9541 };
9542
9543 if (encrypt)
9544 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9545
9546 return sendmsg(s, &msg, 0);
9547}
9548
9549
9550int open_monitor(const char *ifname)
9551{
9552#ifdef __QNXNTO__
9553 struct sockaddr_dl ll;
9554 int s;
9555
9556 memset(&ll, 0, sizeof(ll));
9557 ll.sdl_family = AF_LINK;
9558 ll.sdl_index = if_nametoindex(ifname);
9559 if (ll.sdl_index == 0) {
9560 perror("if_nametoindex");
9561 return -1;
9562 }
9563 s = socket(PF_INET, SOCK_RAW, 0);
9564#else /* __QNXNTO__ */
9565 struct sockaddr_ll ll;
9566 int s;
9567
9568 memset(&ll, 0, sizeof(ll));
9569 ll.sll_family = AF_PACKET;
9570 ll.sll_ifindex = if_nametoindex(ifname);
9571 if (ll.sll_ifindex == 0) {
9572 perror("if_nametoindex");
9573 return -1;
9574 }
9575 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9576#endif /* __QNXNTO__ */
9577 if (s < 0) {
9578 perror("socket[PF_PACKET,SOCK_RAW]");
9579 return -1;
9580 }
9581
9582 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9583 perror("monitor socket bind");
9584 close(s);
9585 return -1;
9586 }
9587
9588 return s;
9589}
9590
9591
9592static int hex2num(char c)
9593{
9594 if (c >= '0' && c <= '9')
9595 return c - '0';
9596 if (c >= 'a' && c <= 'f')
9597 return c - 'a' + 10;
9598 if (c >= 'A' && c <= 'F')
9599 return c - 'A' + 10;
9600 return -1;
9601}
9602
9603
9604int hwaddr_aton(const char *txt, unsigned char *addr)
9605{
9606 int i;
9607
9608 for (i = 0; i < 6; i++) {
9609 int a, b;
9610
9611 a = hex2num(*txt++);
9612 if (a < 0)
9613 return -1;
9614 b = hex2num(*txt++);
9615 if (b < 0)
9616 return -1;
9617 *addr++ = (a << 4) | b;
9618 if (i < 5 && *txt++ != ':')
9619 return -1;
9620 }
9621
9622 return 0;
9623}
9624
9625#endif /* defined(__linux__) || defined(__QNXNTO__) */
9626
9627enum send_frame_type {
9628 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9629};
9630enum send_frame_protection {
9631 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9632};
9633
9634
9635static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9636 enum send_frame_type frame,
9637 enum send_frame_protection protected,
9638 const char *dest)
9639{
9640#ifdef __linux__
9641 unsigned char buf[1000], *pos;
9642 int s, res;
9643 char bssid[20], addr[20];
9644 char result[32], ssid[100];
9645 size_t ssid_len;
9646
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009647 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009648 sizeof(result)) < 0 ||
9649 strncmp(result, "COMPLETED", 9) != 0) {
9650 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9651 return 0;
9652 }
9653
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009654 if (get_wpa_status(get_station_ifname(dut), "bssid",
9655 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009656 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9657 "current BSSID");
9658 return 0;
9659 }
9660
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009661 if (get_wpa_status(get_station_ifname(dut), "address",
9662 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009663 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9664 "own MAC address");
9665 return 0;
9666 }
9667
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009668 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009669 < 0) {
9670 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9671 "current SSID");
9672 return 0;
9673 }
9674 ssid_len = strlen(ssid);
9675
9676 pos = buf;
9677
9678 /* Frame Control */
9679 switch (frame) {
9680 case DISASSOC:
9681 *pos++ = 0xa0;
9682 break;
9683 case DEAUTH:
9684 *pos++ = 0xc0;
9685 break;
9686 case SAQUERY:
9687 *pos++ = 0xd0;
9688 break;
9689 case AUTH:
9690 *pos++ = 0xb0;
9691 break;
9692 case ASSOCREQ:
9693 *pos++ = 0x00;
9694 break;
9695 case REASSOCREQ:
9696 *pos++ = 0x20;
9697 break;
9698 case DLS_REQ:
9699 *pos++ = 0xd0;
9700 break;
9701 }
9702
9703 if (protected == INCORRECT_KEY)
9704 *pos++ = 0x40; /* Set Protected field to 1 */
9705 else
9706 *pos++ = 0x00;
9707
9708 /* Duration */
9709 *pos++ = 0x00;
9710 *pos++ = 0x00;
9711
9712 /* addr1 = DA (current AP) */
9713 hwaddr_aton(bssid, pos);
9714 pos += 6;
9715 /* addr2 = SA (own address) */
9716 hwaddr_aton(addr, pos);
9717 pos += 6;
9718 /* addr3 = BSSID (current AP) */
9719 hwaddr_aton(bssid, pos);
9720 pos += 6;
9721
9722 /* Seq# (to be filled by driver/mac80211) */
9723 *pos++ = 0x00;
9724 *pos++ = 0x00;
9725
9726 if (protected == INCORRECT_KEY) {
9727 /* CCMP parameters */
9728 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9729 pos += 8;
9730 }
9731
9732 if (protected == INCORRECT_KEY) {
9733 switch (frame) {
9734 case DEAUTH:
9735 /* Reason code (encrypted) */
9736 memcpy(pos, "\xa7\x39", 2);
9737 pos += 2;
9738 break;
9739 case DISASSOC:
9740 /* Reason code (encrypted) */
9741 memcpy(pos, "\xa7\x39", 2);
9742 pos += 2;
9743 break;
9744 case SAQUERY:
9745 /* Category|Action|TransID (encrypted) */
9746 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9747 pos += 4;
9748 break;
9749 default:
9750 return -1;
9751 }
9752
9753 /* CCMP MIC */
9754 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9755 pos += 8;
9756 } else {
9757 switch (frame) {
9758 case DEAUTH:
9759 /* reason code = 8 */
9760 *pos++ = 0x08;
9761 *pos++ = 0x00;
9762 break;
9763 case DISASSOC:
9764 /* reason code = 8 */
9765 *pos++ = 0x08;
9766 *pos++ = 0x00;
9767 break;
9768 case SAQUERY:
9769 /* Category - SA Query */
9770 *pos++ = 0x08;
9771 /* SA query Action - Request */
9772 *pos++ = 0x00;
9773 /* Transaction ID */
9774 *pos++ = 0x12;
9775 *pos++ = 0x34;
9776 break;
9777 case AUTH:
9778 /* Auth Alg (Open) */
9779 *pos++ = 0x00;
9780 *pos++ = 0x00;
9781 /* Seq# */
9782 *pos++ = 0x01;
9783 *pos++ = 0x00;
9784 /* Status code */
9785 *pos++ = 0x00;
9786 *pos++ = 0x00;
9787 break;
9788 case ASSOCREQ:
9789 /* Capability Information */
9790 *pos++ = 0x31;
9791 *pos++ = 0x04;
9792 /* Listen Interval */
9793 *pos++ = 0x0a;
9794 *pos++ = 0x00;
9795 /* SSID */
9796 *pos++ = 0x00;
9797 *pos++ = ssid_len;
9798 memcpy(pos, ssid, ssid_len);
9799 pos += ssid_len;
9800 /* Supported Rates */
9801 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9802 10);
9803 pos += 10;
9804 /* Extended Supported Rates */
9805 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9806 pos += 6;
9807 /* RSN */
9808 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9809 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9810 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9811 pos += 28;
9812 break;
9813 case REASSOCREQ:
9814 /* Capability Information */
9815 *pos++ = 0x31;
9816 *pos++ = 0x04;
9817 /* Listen Interval */
9818 *pos++ = 0x0a;
9819 *pos++ = 0x00;
9820 /* Current AP */
9821 hwaddr_aton(bssid, pos);
9822 pos += 6;
9823 /* SSID */
9824 *pos++ = 0x00;
9825 *pos++ = ssid_len;
9826 memcpy(pos, ssid, ssid_len);
9827 pos += ssid_len;
9828 /* Supported Rates */
9829 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9830 10);
9831 pos += 10;
9832 /* Extended Supported Rates */
9833 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9834 pos += 6;
9835 /* RSN */
9836 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9837 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9838 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9839 pos += 28;
9840 break;
9841 case DLS_REQ:
9842 /* Category - DLS */
9843 *pos++ = 0x02;
9844 /* DLS Action - Request */
9845 *pos++ = 0x00;
9846 /* Destination MACAddress */
9847 if (dest)
9848 hwaddr_aton(dest, pos);
9849 else
9850 memset(pos, 0, 6);
9851 pos += 6;
9852 /* Source MACAddress */
9853 hwaddr_aton(addr, pos);
9854 pos += 6;
9855 /* Capability Information */
9856 *pos++ = 0x10; /* Privacy */
9857 *pos++ = 0x06; /* QoS */
9858 /* DLS Timeout Value */
9859 *pos++ = 0x00;
9860 *pos++ = 0x01;
9861 /* Supported rates */
9862 *pos++ = 0x01;
9863 *pos++ = 0x08;
9864 *pos++ = 0x0c; /* 6 Mbps */
9865 *pos++ = 0x12; /* 9 Mbps */
9866 *pos++ = 0x18; /* 12 Mbps */
9867 *pos++ = 0x24; /* 18 Mbps */
9868 *pos++ = 0x30; /* 24 Mbps */
9869 *pos++ = 0x48; /* 36 Mbps */
9870 *pos++ = 0x60; /* 48 Mbps */
9871 *pos++ = 0x6c; /* 54 Mbps */
9872 /* TODO: Extended Supported Rates */
9873 /* TODO: HT Capabilities */
9874 break;
9875 }
9876 }
9877
9878 s = open_monitor("sigmadut");
9879 if (s < 0) {
9880 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9881 "monitor socket");
9882 return 0;
9883 }
9884
9885 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
9886 if (res < 0) {
9887 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9888 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309889 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009890 return 0;
9891 }
9892 if (res < pos - buf) {
9893 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
9894 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309895 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009896 return 0;
9897 }
9898
9899 close(s);
9900
9901 return 1;
9902#else /* __linux__ */
9903 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
9904 "yet supported");
9905 return 0;
9906#endif /* __linux__ */
9907}
9908
9909
9910static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
9911 struct sigma_conn *conn,
9912 struct sigma_cmd *cmd)
9913{
9914 const char *intf = get_param(cmd, "Interface");
9915 const char *sta, *val;
9916 unsigned char addr[ETH_ALEN];
9917 char buf[100];
9918
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +03009919 if (!intf)
9920 return -1;
9921
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009922 sta = get_param(cmd, "peer");
9923 if (sta == NULL)
9924 sta = get_param(cmd, "station");
9925 if (sta == NULL) {
9926 send_resp(dut, conn, SIGMA_ERROR,
9927 "ErrorCode,Missing peer address");
9928 return 0;
9929 }
9930 if (hwaddr_aton(sta, addr) < 0) {
9931 send_resp(dut, conn, SIGMA_ERROR,
9932 "ErrorCode,Invalid peer address");
9933 return 0;
9934 }
9935
9936 val = get_param(cmd, "type");
9937 if (val == NULL)
9938 return -1;
9939
9940 if (strcasecmp(val, "DISCOVERY") == 0) {
9941 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
9942 if (wpa_command(intf, buf) < 0) {
9943 send_resp(dut, conn, SIGMA_ERROR,
9944 "ErrorCode,Failed to send TDLS discovery");
9945 return 0;
9946 }
9947 return 1;
9948 }
9949
9950 if (strcasecmp(val, "SETUP") == 0) {
9951 int status = 0, timeout = 0;
9952
9953 val = get_param(cmd, "Status");
9954 if (val)
9955 status = atoi(val);
9956
9957 val = get_param(cmd, "Timeout");
9958 if (val)
9959 timeout = atoi(val);
9960
9961 if (status != 0 && status != 37) {
9962 send_resp(dut, conn, SIGMA_ERROR,
9963 "ErrorCode,Unsupported status value");
9964 return 0;
9965 }
9966
9967 if (timeout != 0 && timeout != 301) {
9968 send_resp(dut, conn, SIGMA_ERROR,
9969 "ErrorCode,Unsupported timeout value");
9970 return 0;
9971 }
9972
9973 if (status && timeout) {
9974 send_resp(dut, conn, SIGMA_ERROR,
9975 "ErrorCode,Unsupported timeout+status "
9976 "combination");
9977 return 0;
9978 }
9979
9980 if (status == 37 &&
9981 wpa_command(intf, "SET tdls_testing 0x200")) {
9982 send_resp(dut, conn, SIGMA_ERROR,
9983 "ErrorCode,Failed to enable "
9984 "decline setup response test mode");
9985 return 0;
9986 }
9987
9988 if (timeout == 301) {
9989 int res;
9990 if (dut->no_tpk_expiration)
9991 res = wpa_command(intf,
9992 "SET tdls_testing 0x108");
9993 else
9994 res = wpa_command(intf,
9995 "SET tdls_testing 0x8");
9996 if (res) {
9997 send_resp(dut, conn, SIGMA_ERROR,
9998 "ErrorCode,Failed to set short TPK "
9999 "lifetime");
10000 return 0;
10001 }
10002 }
10003
10004 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
10005 if (wpa_command(intf, buf) < 0) {
10006 send_resp(dut, conn, SIGMA_ERROR,
10007 "ErrorCode,Failed to send TDLS setup");
10008 return 0;
10009 }
10010 return 1;
10011 }
10012
10013 if (strcasecmp(val, "TEARDOWN") == 0) {
10014 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
10015 if (wpa_command(intf, buf) < 0) {
10016 send_resp(dut, conn, SIGMA_ERROR,
10017 "ErrorCode,Failed to send TDLS teardown");
10018 return 0;
10019 }
10020 return 1;
10021 }
10022
10023 send_resp(dut, conn, SIGMA_ERROR,
10024 "ErrorCode,Unsupported TDLS frame");
10025 return 0;
10026}
10027
10028
10029static int sta_ap_known(const char *ifname, const char *bssid)
10030{
10031 char buf[4096];
10032
Jouni Malinendd32f192018-09-15 02:55:19 +030010033 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010034 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
10035 return 0;
10036 if (strncmp(buf, "id=", 3) != 0)
10037 return 0;
10038 return 1;
10039}
10040
10041
10042static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
10043 const char *bssid)
10044{
10045 int res;
10046 struct wpa_ctrl *ctrl;
10047 char buf[256];
10048
10049 if (sta_ap_known(ifname, bssid))
10050 return 0;
10051 sigma_dut_print(dut, DUT_MSG_DEBUG,
10052 "AP not in BSS table - start scan");
10053
10054 ctrl = open_wpa_mon(ifname);
10055 if (ctrl == NULL) {
10056 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10057 "wpa_supplicant monitor connection");
10058 return -1;
10059 }
10060
10061 if (wpa_command(ifname, "SCAN") < 0) {
10062 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
10063 wpa_ctrl_detach(ctrl);
10064 wpa_ctrl_close(ctrl);
10065 return -1;
10066 }
10067
10068 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
10069 buf, sizeof(buf));
10070
10071 wpa_ctrl_detach(ctrl);
10072 wpa_ctrl_close(ctrl);
10073
10074 if (res < 0) {
10075 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
10076 return -1;
10077 }
10078
10079 if (sta_ap_known(ifname, bssid))
10080 return 0;
10081 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
10082 return -1;
10083}
10084
10085
10086static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
10087 struct sigma_conn *conn,
10088 struct sigma_cmd *cmd,
10089 const char *intf)
10090{
10091 char buf[200];
10092
10093 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
10094 if (system(buf) != 0) {
10095 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
10096 "ndsend");
10097 return 0;
10098 }
10099
10100 return 1;
10101}
10102
10103
10104static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
10105 struct sigma_conn *conn,
10106 struct sigma_cmd *cmd,
10107 const char *intf)
10108{
10109 char buf[200];
10110 const char *ip = get_param(cmd, "SenderIP");
10111
Peng Xu26b356d2017-10-04 17:58:16 -070010112 if (!ip)
10113 return 0;
10114
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010115 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
10116 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10117 if (system(buf) == 0) {
10118 sigma_dut_print(dut, DUT_MSG_INFO,
10119 "Neighbor Solicitation got a response "
10120 "for %s@%s", ip, intf);
10121 }
10122
10123 return 1;
10124}
10125
10126
10127static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
10128 struct sigma_conn *conn,
10129 struct sigma_cmd *cmd,
10130 const char *ifname)
10131{
10132 char buf[200];
10133 const char *ip = get_param(cmd, "SenderIP");
10134
10135 if (ip == NULL) {
10136 send_resp(dut, conn, SIGMA_ERROR,
10137 "ErrorCode,Missing SenderIP parameter");
10138 return 0;
10139 }
10140 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
10141 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10142 if (system(buf) != 0) {
10143 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
10144 "for %s@%s", ip, ifname);
10145 }
10146
10147 return 1;
10148}
10149
10150
10151static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
10152 struct sigma_conn *conn,
10153 struct sigma_cmd *cmd,
10154 const char *ifname)
10155{
10156 char buf[200];
10157 char ip[16];
10158 int s;
Peng Xub3756882017-10-04 14:39:09 -070010159 struct ifreq ifr;
10160 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010161
10162 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070010163 if (s < 0) {
10164 perror("socket");
10165 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010166 }
10167
Peng Xub3756882017-10-04 14:39:09 -070010168 memset(&ifr, 0, sizeof(ifr));
10169 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
10170 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
10171 sigma_dut_print(dut, DUT_MSG_INFO,
10172 "Failed to get %s IP address: %s",
10173 ifname, strerror(errno));
10174 close(s);
10175 return -1;
10176 }
10177 close(s);
10178
10179 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
10180 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
10181
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010182 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
10183 ip);
10184 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10185 if (system(buf) != 0) {
10186 }
10187
10188 return 1;
10189}
10190
10191
10192static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
10193 struct sigma_conn *conn,
10194 struct sigma_cmd *cmd,
10195 const char *ifname)
10196{
10197 char buf[200], addr[20];
10198 char dst[ETH_ALEN], src[ETH_ALEN];
10199 short ethtype = htons(ETH_P_ARP);
10200 char *pos;
10201 int s, res;
10202 const char *val;
10203 struct sockaddr_in taddr;
10204
10205 val = get_param(cmd, "dest");
10206 if (val)
10207 hwaddr_aton(val, (unsigned char *) dst);
10208
10209 val = get_param(cmd, "DestIP");
10210 if (val)
10211 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070010212 else
10213 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010214
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010215 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010216 sizeof(addr)) < 0)
10217 return -2;
10218 hwaddr_aton(addr, (unsigned char *) src);
10219
10220 pos = buf;
10221 *pos++ = 0x00;
10222 *pos++ = 0x01;
10223 *pos++ = 0x08;
10224 *pos++ = 0x00;
10225 *pos++ = 0x06;
10226 *pos++ = 0x04;
10227 *pos++ = 0x00;
10228 *pos++ = 0x02;
10229 memcpy(pos, src, ETH_ALEN);
10230 pos += ETH_ALEN;
10231 memcpy(pos, &taddr.sin_addr, 4);
10232 pos += 4;
10233 memcpy(pos, dst, ETH_ALEN);
10234 pos += ETH_ALEN;
10235 memcpy(pos, &taddr.sin_addr, 4);
10236 pos += 4;
10237
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010238 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010239 if (s < 0) {
10240 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
10241 "monitor socket");
10242 return 0;
10243 }
10244
10245 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
10246 if (res < 0) {
10247 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
10248 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053010249 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010250 return 0;
10251 }
10252
10253 close(s);
10254
10255 return 1;
10256}
10257
10258
10259static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
10260 struct sigma_conn *conn,
10261 struct sigma_cmd *cmd,
10262 const char *intf, const char *dest)
10263{
10264 char buf[100];
10265
10266 if (if_nametoindex("sigmadut") == 0) {
10267 snprintf(buf, sizeof(buf),
10268 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010269 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010270 if (system(buf) != 0 ||
10271 if_nametoindex("sigmadut") == 0) {
10272 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10273 "monitor interface with '%s'", buf);
10274 return -2;
10275 }
10276 }
10277
10278 if (system("ifconfig sigmadut up") != 0) {
10279 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10280 "monitor interface up");
10281 return -2;
10282 }
10283
10284 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
10285}
10286
10287
10288static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10289 struct sigma_conn *conn,
10290 struct sigma_cmd *cmd)
10291{
10292 const char *intf = get_param(cmd, "Interface");
10293 const char *dest = get_param(cmd, "Dest");
10294 const char *type = get_param(cmd, "FrameName");
10295 const char *val;
10296 char buf[200], *pos, *end;
10297 int count, count2;
10298
10299 if (type == NULL)
10300 type = get_param(cmd, "Type");
10301
10302 if (intf == NULL || dest == NULL || type == NULL)
10303 return -1;
10304
10305 if (strcasecmp(type, "NeighAdv") == 0)
10306 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10307
10308 if (strcasecmp(type, "NeighSolicitReq") == 0)
10309 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10310
10311 if (strcasecmp(type, "ARPProbe") == 0)
10312 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10313
10314 if (strcasecmp(type, "ARPAnnounce") == 0)
10315 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10316
10317 if (strcasecmp(type, "ARPReply") == 0)
10318 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10319
10320 if (strcasecmp(type, "DLS-request") == 0 ||
10321 strcasecmp(type, "DLSrequest") == 0)
10322 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10323 dest);
10324
10325 if (strcasecmp(type, "ANQPQuery") != 0 &&
10326 strcasecmp(type, "Query") != 0) {
10327 send_resp(dut, conn, SIGMA_ERROR,
10328 "ErrorCode,Unsupported HS 2.0 send frame type");
10329 return 0;
10330 }
10331
10332 if (sta_scan_ap(dut, intf, dest) < 0) {
10333 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10334 "the requested AP");
10335 return 0;
10336 }
10337
10338 pos = buf;
10339 end = buf + sizeof(buf);
10340 count = 0;
10341 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10342
10343 val = get_param(cmd, "ANQP_CAP_LIST");
10344 if (val && atoi(val)) {
10345 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10346 count++;
10347 }
10348
10349 val = get_param(cmd, "VENUE_NAME");
10350 if (val && atoi(val)) {
10351 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10352 count++;
10353 }
10354
10355 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10356 if (val && atoi(val)) {
10357 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10358 count++;
10359 }
10360
10361 val = get_param(cmd, "ROAMING_CONS");
10362 if (val && atoi(val)) {
10363 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10364 count++;
10365 }
10366
10367 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10368 if (val && atoi(val)) {
10369 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10370 count++;
10371 }
10372
10373 val = get_param(cmd, "NAI_REALM_LIST");
10374 if (val && atoi(val)) {
10375 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10376 count++;
10377 }
10378
10379 val = get_param(cmd, "3GPP_INFO");
10380 if (val && atoi(val)) {
10381 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10382 count++;
10383 }
10384
10385 val = get_param(cmd, "DOMAIN_LIST");
10386 if (val && atoi(val)) {
10387 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10388 count++;
10389 }
10390
Jouni Malinen34cf9532018-04-29 19:26:33 +030010391 val = get_param(cmd, "Venue_URL");
10392 if (val && atoi(val)) {
10393 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10394 count++;
10395 }
10396
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010397 val = get_param(cmd, "Advice_Of_Charge");
10398 if (val && atoi(val)) {
10399 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10400 count++;
10401 }
10402
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010403 if (count && wpa_command(intf, buf)) {
10404 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10405 return 0;
10406 }
10407
10408 pos = buf;
10409 end = buf + sizeof(buf);
10410 count2 = 0;
10411 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
10412
10413 val = get_param(cmd, "HS_CAP_LIST");
10414 if (val && atoi(val)) {
10415 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
10416 count2++;
10417 }
10418
10419 val = get_param(cmd, "OPER_NAME");
10420 if (val && atoi(val)) {
10421 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
10422 count2++;
10423 }
10424
10425 val = get_param(cmd, "WAN_METRICS");
10426 if (!val)
10427 val = get_param(cmd, "WAN_MAT");
10428 if (!val)
10429 val = get_param(cmd, "WAN_MET");
10430 if (val && atoi(val)) {
10431 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10432 count2++;
10433 }
10434
10435 val = get_param(cmd, "CONNECTION_CAPABILITY");
10436 if (val && atoi(val)) {
10437 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10438 count2++;
10439 }
10440
10441 val = get_param(cmd, "OP_CLASS");
10442 if (val && atoi(val)) {
10443 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10444 count2++;
10445 }
10446
10447 val = get_param(cmd, "OSU_PROVIDER_LIST");
10448 if (val && atoi(val)) {
10449 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10450 count2++;
10451 }
10452
Jouni Malinenf67afec2018-04-29 19:24:58 +030010453 val = get_param(cmd, "OPER_ICON_METADATA");
10454 if (!val)
10455 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10456 if (val && atoi(val)) {
10457 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10458 count2++;
10459 }
10460
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010461 if (count && count2) {
10462 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10463 "second query");
10464 sleep(1);
10465 }
10466
10467 if (count2 && wpa_command(intf, buf)) {
10468 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10469 "failed");
10470 return 0;
10471 }
10472
10473 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10474 if (val) {
10475 if (count || count2) {
10476 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10477 "sending out second query");
10478 sleep(1);
10479 }
10480
10481 if (strcmp(val, "1") == 0)
10482 val = "mail.example.com";
10483 snprintf(buf, end - pos,
10484 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10485 dest, val);
10486 if (wpa_command(intf, buf)) {
10487 send_resp(dut, conn, SIGMA_ERROR,
10488 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10489 "failed");
10490 return 0;
10491 }
10492 }
10493
10494 val = get_param(cmd, "ICON_REQUEST");
10495 if (val) {
10496 if (count || count2) {
10497 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10498 "sending out second query");
10499 sleep(1);
10500 }
10501
10502 snprintf(buf, end - pos,
10503 "HS20_ICON_REQUEST %s %s", dest, val);
10504 if (wpa_command(intf, buf)) {
10505 send_resp(dut, conn, SIGMA_ERROR,
10506 "ErrorCode,HS20_ICON_REQUEST failed");
10507 return 0;
10508 }
10509 }
10510
10511 return 1;
10512}
10513
10514
10515static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10516 struct sigma_conn *conn,
10517 struct sigma_cmd *cmd)
10518{
10519 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010520 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010521 int chwidth, nss;
10522
10523 val = get_param(cmd, "framename");
10524 if (!val)
10525 return -1;
10526 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10527
10528 /* Command sequence to generate Op mode notification */
10529 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010530 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010531
10532 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010533 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010534
10535 /* Extract Channel width */
10536 val = get_param(cmd, "Channel_width");
10537 if (val) {
10538 switch (atoi(val)) {
10539 case 20:
10540 chwidth = 0;
10541 break;
10542 case 40:
10543 chwidth = 1;
10544 break;
10545 case 80:
10546 chwidth = 2;
10547 break;
10548 case 160:
10549 chwidth = 3;
10550 break;
10551 default:
10552 chwidth = 2;
10553 break;
10554 }
10555
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010556 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010557 }
10558
10559 /* Extract NSS */
10560 val = get_param(cmd, "NSS");
10561 if (val) {
10562 switch (atoi(val)) {
10563 case 1:
10564 nss = 1;
10565 break;
10566 case 2:
10567 nss = 3;
10568 break;
10569 case 3:
10570 nss = 7;
10571 break;
10572 default:
10573 /* We do not support NSS > 3 */
10574 nss = 3;
10575 break;
10576 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010577 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010578 }
10579
10580 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010581 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010582 }
10583
10584 return 1;
10585}
10586
10587
10588static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
10589 struct sigma_conn *conn,
10590 struct sigma_cmd *cmd)
10591{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010592 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010593 case DRIVER_ATHEROS:
10594 return ath_sta_send_frame_vht(dut, conn, cmd);
10595 default:
10596 send_resp(dut, conn, SIGMA_ERROR,
10597 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
10598 return 0;
10599 }
10600}
10601
10602
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010603static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
10604 struct sigma_cmd *cmd)
10605{
10606 const char *val;
10607 const char *intf = get_param(cmd, "Interface");
10608
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010609 if (!intf)
10610 return -1;
10611
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010612 val = get_param(cmd, "framename");
10613 if (!val)
10614 return -1;
10615 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10616
10617 /* Command sequence to generate Op mode notification */
10618 if (val && strcasecmp(val, "action") == 0) {
10619 val = get_param(cmd, "PPDUTxType");
10620 if (val && strcasecmp(val, "TB") == 0) {
10621 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
10622 sigma_dut_print(dut, DUT_MSG_ERROR,
10623 "failed to send TB PPDU Tx cfg");
10624 send_resp(dut, conn, SIGMA_ERROR,
10625 "ErrorCode,set TB PPDU Tx cfg failed");
10626 return 0;
10627 }
10628 return 1;
10629 }
10630
10631 sigma_dut_print(dut, DUT_MSG_ERROR,
10632 "Action Tx type is not defined");
10633 }
10634
10635 return 1;
10636}
10637
10638
10639static int cmd_sta_send_frame_he(struct sigma_dut *dut,
10640 struct sigma_conn *conn,
10641 struct sigma_cmd *cmd)
10642{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010643 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010644 case DRIVER_WCN:
10645 return wcn_sta_send_frame_he(dut, conn, cmd);
10646 default:
10647 send_resp(dut, conn, SIGMA_ERROR,
10648 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
10649 return 0;
10650 }
10651}
10652
10653
Lior David0fe101e2017-03-09 16:09:50 +020010654#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010655
10656static int
10657wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
10658 const char *frame_name, const char *dest_mac)
10659{
10660 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
10661 const char *ssid = get_param(cmd, "ssid");
10662 const char *countstr = get_param(cmd, "count");
10663 const char *channelstr = get_param(cmd, "channel");
10664 const char *group_id = get_param(cmd, "groupid");
10665 const char *client_id = get_param(cmd, "clientmac");
10666 int count, channel, freq, i;
10667 const char *fname;
10668 char frame[1024], src_mac[20], group_id_attr[25],
10669 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
10670 const char *group_ssid;
10671 const int group_ssid_prefix_len = 9;
10672 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
10673 size_t framelen = sizeof(frame);
10674 struct template_frame_tag tags[2];
10675 size_t tags_total = ARRAY_SIZE(tags);
10676 int tag_index, len, dst_len;
10677
10678 if (!countstr || !channelstr) {
10679 sigma_dut_print(dut, DUT_MSG_ERROR,
10680 "Missing argument: count, channel");
10681 return -1;
10682 }
10683 if (isprobereq && !ssid) {
10684 sigma_dut_print(dut, DUT_MSG_ERROR,
10685 "Missing argument: ssid");
10686 return -1;
10687 }
10688 if (!isprobereq && (!group_id || !client_id)) {
10689 sigma_dut_print(dut, DUT_MSG_ERROR,
10690 "Missing argument: group_id, client_id");
10691 return -1;
10692 }
10693
10694 count = atoi(countstr);
10695 channel = atoi(channelstr);
10696 freq = channel_to_freq(dut, channel);
10697
10698 if (!freq) {
10699 sigma_dut_print(dut, DUT_MSG_ERROR,
10700 "invalid channel: %s", channelstr);
10701 return -1;
10702 }
10703
10704 if (isprobereq) {
10705 if (strcasecmp(ssid, "wildcard") == 0) {
10706 fname = "probe_req_wildcard.txt";
10707 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
10708 fname = "probe_req_P2P_Wildcard.txt";
10709 } else {
10710 sigma_dut_print(dut, DUT_MSG_ERROR,
10711 "invalid probe request type");
10712 return -1;
10713 }
10714 } else {
10715 fname = "P2P_device_discovery_req.txt";
10716 }
10717
10718 if (parse_template_frame_file(dut, fname, frame, &framelen,
10719 tags, &tags_total)) {
10720 sigma_dut_print(dut, DUT_MSG_ERROR,
10721 "invalid frame template: %s", fname);
10722 return -1;
10723 }
10724
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010725 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010726 src_mac, sizeof(src_mac)) < 0 ||
10727 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
10728 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
10729 return -1;
10730 /* Use wildcard BSSID, since we are in PBSS */
10731 memset(&hdr->addr3, 0xFF, ETH_ALEN);
10732
10733 if (!isprobereq) {
10734 tag_index = find_template_frame_tag(tags, tags_total, 1);
10735 if (tag_index < 0) {
10736 sigma_dut_print(dut, DUT_MSG_ERROR,
10737 "can't find device id attribute");
10738 return -1;
10739 }
10740 if (parse_mac_address(dut, client_id,
10741 (unsigned char *) client_mac)) {
10742 sigma_dut_print(dut, DUT_MSG_ERROR,
10743 "invalid client_id: %s", client_id);
10744 return -1;
10745 }
10746 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10747 framelen - tags[tag_index].offset,
10748 IEEE80211_P2P_ATTR_DEVICE_ID,
10749 client_mac, ETH_ALEN)) {
10750 sigma_dut_print(dut, DUT_MSG_ERROR,
10751 "fail to replace device id attribute");
10752 return -1;
10753 }
10754
10755 /*
10756 * group_id arg contains device MAC address followed by
10757 * space and SSID (DIRECT-somessid).
10758 * group id attribute contains device address (6 bytes)
10759 * followed by SSID prefix DIRECT-XX (9 bytes)
10760 */
10761 if (strlen(group_id) < sizeof(device_macstr)) {
10762 sigma_dut_print(dut, DUT_MSG_ERROR,
10763 "group_id arg too short");
10764 return -1;
10765 }
10766 memcpy(device_macstr, group_id, sizeof(device_macstr));
10767 device_macstr[sizeof(device_macstr) - 1] = '\0';
10768 if (parse_mac_address(dut, device_macstr,
10769 (unsigned char *) group_id_attr)) {
10770 sigma_dut_print(dut, DUT_MSG_ERROR,
10771 "fail to parse device address from group_id");
10772 return -1;
10773 }
10774 group_ssid = strchr(group_id, ' ');
10775 if (!group_ssid) {
10776 sigma_dut_print(dut, DUT_MSG_ERROR,
10777 "invalid group_id arg, no ssid");
10778 return -1;
10779 }
10780 group_ssid++;
10781 len = strlen(group_ssid);
10782 if (len < group_ssid_prefix_len) {
10783 sigma_dut_print(dut, DUT_MSG_ERROR,
10784 "group_id SSID too short");
10785 return -1;
10786 }
10787 dst_len = sizeof(group_id_attr) - ETH_ALEN;
10788 if (len > dst_len) {
10789 sigma_dut_print(dut, DUT_MSG_ERROR,
10790 "group_id SSID (%s) too long",
10791 group_ssid);
10792 return -1;
10793 }
10794
10795 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
10796 tag_index = find_template_frame_tag(tags, tags_total, 2);
10797 if (tag_index < 0) {
10798 sigma_dut_print(dut, DUT_MSG_ERROR,
10799 "can't find group id attribute");
10800 return -1;
10801 }
10802 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10803 framelen - tags[tag_index].offset,
10804 IEEE80211_P2P_ATTR_GROUP_ID,
10805 group_id_attr,
10806 sizeof(group_id_attr))) {
10807 sigma_dut_print(dut, DUT_MSG_ERROR,
10808 "fail to replace group id attribute");
10809 return -1;
10810 }
10811 }
10812
10813 for (i = 0; i < count; i++) {
10814 if (wil6210_transmit_frame(dut, freq,
10815 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
10816 frame, framelen)) {
10817 sigma_dut_print(dut, DUT_MSG_ERROR,
10818 "fail to transmit probe request frame");
10819 return -1;
10820 }
10821 }
10822
10823 return 0;
10824}
10825
10826
Lior David0fe101e2017-03-09 16:09:50 +020010827int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10828 struct sigma_cmd *cmd)
10829{
10830 const char *frame_name = get_param(cmd, "framename");
10831 const char *mac = get_param(cmd, "dest_mac");
10832
10833 if (!frame_name || !mac) {
10834 sigma_dut_print(dut, DUT_MSG_ERROR,
10835 "framename and dest_mac must be provided");
10836 return -1;
10837 }
10838
10839 if (strcasecmp(frame_name, "brp") == 0) {
10840 const char *l_rx = get_param(cmd, "L-RX");
10841 int l_rx_i;
10842
10843 if (!l_rx) {
10844 sigma_dut_print(dut, DUT_MSG_ERROR,
10845 "L-RX must be provided");
10846 return -1;
10847 }
10848 l_rx_i = atoi(l_rx);
10849
10850 sigma_dut_print(dut, DUT_MSG_INFO,
10851 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
10852 mac, l_rx);
10853 if (l_rx_i != 16) {
10854 sigma_dut_print(dut, DUT_MSG_ERROR,
10855 "unsupported L-RX: %s", l_rx);
10856 return -1;
10857 }
10858
10859 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
10860 return -1;
10861 } else if (strcasecmp(frame_name, "ssw") == 0) {
10862 sigma_dut_print(dut, DUT_MSG_INFO,
10863 "dev_send_frame: SLS, dest_mac %s", mac);
10864 if (wil6210_send_sls(dut, mac))
10865 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010866 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
10867 (strcasecmp(frame_name, "devdiscreq") == 0)) {
10868 sigma_dut_print(dut, DUT_MSG_INFO,
10869 "dev_send_frame: %s, dest_mac %s", frame_name,
10870 mac);
10871 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
10872 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020010873 } else {
10874 sigma_dut_print(dut, DUT_MSG_ERROR,
10875 "unsupported frame type: %s", frame_name);
10876 return -1;
10877 }
10878
10879 return 1;
10880}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010881
Lior David0fe101e2017-03-09 16:09:50 +020010882#endif /* __linux__ */
10883
10884
10885static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
10886 struct sigma_conn *conn,
10887 struct sigma_cmd *cmd)
10888{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010889 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020010890#ifdef __linux__
10891 case DRIVER_WIL6210:
10892 return wil6210_send_frame_60g(dut, conn, cmd);
10893#endif /* __linux__ */
10894 default:
10895 send_resp(dut, conn, SIGMA_ERROR,
10896 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
10897 return 0;
10898 }
10899}
10900
10901
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010902static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
10903 const char *intf, struct sigma_cmd *cmd)
10904{
10905 const char *val, *addr;
10906 char buf[100];
10907
10908 addr = get_param(cmd, "DestMac");
10909 if (!addr) {
10910 send_resp(dut, conn, SIGMA_INVALID,
10911 "ErrorCode,AP MAC address is missing");
10912 return 0;
10913 }
10914
10915 val = get_param(cmd, "ANQPQuery_ID");
10916 if (!val) {
10917 send_resp(dut, conn, SIGMA_INVALID,
10918 "ErrorCode,Missing ANQPQuery_ID");
10919 return 0;
10920 }
10921
10922 if (strcasecmp(val, "NeighborReportReq") == 0) {
10923 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
10924 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
10925 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
10926 } else {
10927 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
10928 val);
10929 send_resp(dut, conn, SIGMA_INVALID,
10930 "ErrorCode,Invalid ANQPQuery_ID");
10931 return 0;
10932 }
10933
Ashwini Patild174f2c2017-04-13 16:49:46 +053010934 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
10935 * (Address3 = Wildcard BSSID when sent to not-associated AP;
10936 * if associated, AP BSSID).
10937 */
10938 if (wpa_command(intf, "SET gas_address3 1") < 0) {
10939 send_resp(dut, conn, SIGMA_ERROR,
10940 "ErrorCode,Failed to set gas_address3");
10941 return 0;
10942 }
10943
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010944 if (wpa_command(intf, buf) < 0) {
10945 send_resp(dut, conn, SIGMA_ERROR,
10946 "ErrorCode,Failed to send ANQP query");
10947 return 0;
10948 }
10949
10950 return 1;
10951}
10952
10953
10954static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
10955 struct sigma_conn *conn,
10956 const char *intf,
10957 struct sigma_cmd *cmd)
10958{
10959 const char *val = get_param(cmd, "FrameName");
10960
10961 if (val && strcasecmp(val, "ANQPQuery") == 0)
10962 return mbo_send_anqp_query(dut, conn, intf, cmd);
10963
10964 return 2;
10965}
10966
10967
Jouni Malinenf7222712019-06-13 01:50:21 +030010968enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
10969 struct sigma_conn *conn,
10970 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010971{
10972 const char *intf = get_param(cmd, "Interface");
10973 const char *val;
10974 enum send_frame_type frame;
10975 enum send_frame_protection protected;
10976 char buf[100];
10977 unsigned char addr[ETH_ALEN];
10978 int res;
10979
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010980 if (!intf)
10981 return -1;
10982
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010983 val = get_param(cmd, "program");
10984 if (val == NULL)
10985 val = get_param(cmd, "frame");
10986 if (val && strcasecmp(val, "TDLS") == 0)
10987 return cmd_sta_send_frame_tdls(dut, conn, cmd);
10988 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030010989 strcasecmp(val, "HS2-R2") == 0 ||
10990 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010991 return cmd_sta_send_frame_hs2(dut, conn, cmd);
10992 if (val && strcasecmp(val, "VHT") == 0)
10993 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010994 if (val && strcasecmp(val, "HE") == 0)
10995 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070010996 if (val && strcasecmp(val, "LOC") == 0)
10997 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020010998 if (val && strcasecmp(val, "60GHz") == 0)
10999 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011000 if (val && strcasecmp(val, "MBO") == 0) {
11001 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
11002 if (res != 2)
11003 return res;
11004 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011005
11006 val = get_param(cmd, "TD_DISC");
11007 if (val) {
11008 if (hwaddr_aton(val, addr) < 0)
11009 return -1;
11010 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
11011 if (wpa_command(intf, buf) < 0) {
11012 send_resp(dut, conn, SIGMA_ERROR,
11013 "ErrorCode,Failed to send TDLS discovery");
11014 return 0;
11015 }
11016 return 1;
11017 }
11018
11019 val = get_param(cmd, "TD_Setup");
11020 if (val) {
11021 if (hwaddr_aton(val, addr) < 0)
11022 return -1;
11023 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
11024 if (wpa_command(intf, buf) < 0) {
11025 send_resp(dut, conn, SIGMA_ERROR,
11026 "ErrorCode,Failed to start TDLS setup");
11027 return 0;
11028 }
11029 return 1;
11030 }
11031
11032 val = get_param(cmd, "TD_TearDown");
11033 if (val) {
11034 if (hwaddr_aton(val, addr) < 0)
11035 return -1;
11036 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
11037 if (wpa_command(intf, buf) < 0) {
11038 send_resp(dut, conn, SIGMA_ERROR,
11039 "ErrorCode,Failed to tear down TDLS link");
11040 return 0;
11041 }
11042 return 1;
11043 }
11044
11045 val = get_param(cmd, "TD_ChannelSwitch");
11046 if (val) {
11047 /* TODO */
11048 send_resp(dut, conn, SIGMA_ERROR,
11049 "ErrorCode,TD_ChannelSwitch not yet supported");
11050 return 0;
11051 }
11052
11053 val = get_param(cmd, "TD_NF");
11054 if (val) {
11055 /* TODO */
11056 send_resp(dut, conn, SIGMA_ERROR,
11057 "ErrorCode,TD_NF not yet supported");
11058 return 0;
11059 }
11060
11061 val = get_param(cmd, "PMFFrameType");
11062 if (val == NULL)
11063 val = get_param(cmd, "FrameName");
11064 if (val == NULL)
11065 val = get_param(cmd, "Type");
11066 if (val == NULL)
11067 return -1;
11068 if (strcasecmp(val, "disassoc") == 0)
11069 frame = DISASSOC;
11070 else if (strcasecmp(val, "deauth") == 0)
11071 frame = DEAUTH;
11072 else if (strcasecmp(val, "saquery") == 0)
11073 frame = SAQUERY;
11074 else if (strcasecmp(val, "auth") == 0)
11075 frame = AUTH;
11076 else if (strcasecmp(val, "assocreq") == 0)
11077 frame = ASSOCREQ;
11078 else if (strcasecmp(val, "reassocreq") == 0)
11079 frame = REASSOCREQ;
11080 else if (strcasecmp(val, "neigreq") == 0) {
11081 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
11082
11083 val = get_param(cmd, "ssid");
11084 if (val == NULL)
11085 return -1;
11086
11087 res = send_neighbor_request(dut, intf, val);
11088 if (res) {
11089 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11090 "Failed to send neighbor report request");
11091 return 0;
11092 }
11093
11094 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053011095 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
11096 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011097 sigma_dut_print(dut, DUT_MSG_DEBUG,
11098 "Got Transition Management Query");
11099
Ashwini Patil5acd7382017-04-13 15:55:04 +053011100 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011101 if (res) {
11102 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11103 "Failed to send Transition Management Query");
11104 return 0;
11105 }
11106
11107 return 1;
11108 } else {
11109 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11110 "PMFFrameType");
11111 return 0;
11112 }
11113
11114 val = get_param(cmd, "PMFProtected");
11115 if (val == NULL)
11116 val = get_param(cmd, "Protected");
11117 if (val == NULL)
11118 return -1;
11119 if (strcasecmp(val, "Correct-key") == 0 ||
11120 strcasecmp(val, "CorrectKey") == 0)
11121 protected = CORRECT_KEY;
11122 else if (strcasecmp(val, "IncorrectKey") == 0)
11123 protected = INCORRECT_KEY;
11124 else if (strcasecmp(val, "Unprotected") == 0)
11125 protected = UNPROTECTED;
11126 else {
11127 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11128 "PMFProtected");
11129 return 0;
11130 }
11131
11132 if (protected != UNPROTECTED &&
11133 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
11134 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
11135 "PMFProtected for auth/assocreq/reassocreq");
11136 return 0;
11137 }
11138
11139 if (if_nametoindex("sigmadut") == 0) {
11140 snprintf(buf, sizeof(buf),
11141 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011142 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011143 if (system(buf) != 0 ||
11144 if_nametoindex("sigmadut") == 0) {
11145 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11146 "monitor interface with '%s'", buf);
11147 return -2;
11148 }
11149 }
11150
11151 if (system("ifconfig sigmadut up") != 0) {
11152 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11153 "monitor interface up");
11154 return -2;
11155 }
11156
11157 return sta_inject_frame(dut, conn, frame, protected, NULL);
11158}
11159
11160
11161static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
11162 struct sigma_conn *conn,
11163 struct sigma_cmd *cmd,
11164 const char *ifname)
11165{
11166 char buf[200];
11167 const char *val;
11168
11169 val = get_param(cmd, "ClearARP");
11170 if (val && atoi(val) == 1) {
11171 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
11172 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11173 if (system(buf) != 0) {
11174 send_resp(dut, conn, SIGMA_ERROR,
11175 "errorCode,Failed to clear ARP cache");
11176 return 0;
11177 }
11178 }
11179
11180 return 1;
11181}
11182
11183
11184int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
11185 struct sigma_cmd *cmd)
11186{
11187 const char *intf = get_param(cmd, "Interface");
11188 const char *val;
11189
11190 if (intf == NULL)
11191 return -1;
11192
11193 val = get_param(cmd, "program");
11194 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011195 strcasecmp(val, "HS2-R2") == 0 ||
11196 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011197 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
11198
11199 return -1;
11200}
11201
11202
Jouni Malinenf7222712019-06-13 01:50:21 +030011203static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
11204 struct sigma_conn *conn,
11205 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011206{
11207 const char *intf = get_param(cmd, "Interface");
11208 const char *mac = get_param(cmd, "MAC");
11209
11210 if (intf == NULL || mac == NULL)
11211 return -1;
11212
11213 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
11214 "interface %s to %s", intf, mac);
11215
11216 if (dut->set_macaddr) {
11217 char buf[128];
11218 int res;
11219 if (strcasecmp(mac, "default") == 0) {
11220 res = snprintf(buf, sizeof(buf), "%s",
11221 dut->set_macaddr);
11222 dut->tmp_mac_addr = 0;
11223 } else {
11224 res = snprintf(buf, sizeof(buf), "%s %s",
11225 dut->set_macaddr, mac);
11226 dut->tmp_mac_addr = 1;
11227 }
11228 if (res < 0 || res >= (int) sizeof(buf))
11229 return -1;
11230 if (system(buf) != 0) {
11231 send_resp(dut, conn, SIGMA_ERROR,
11232 "errorCode,Failed to set MAC "
11233 "address");
11234 return 0;
11235 }
11236 return 1;
11237 }
11238
11239 if (strcasecmp(mac, "default") == 0)
11240 return 1;
11241
11242 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11243 "command");
11244 return 0;
11245}
11246
11247
11248static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
11249 struct sigma_conn *conn, const char *intf,
11250 int val)
11251{
11252 char buf[200];
11253 int res;
11254
11255 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
11256 intf, val);
11257 if (res < 0 || res >= (int) sizeof(buf))
11258 return -1;
11259 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11260 if (system(buf) != 0) {
11261 send_resp(dut, conn, SIGMA_ERROR,
11262 "errorCode,Failed to configure offchannel mode");
11263 return 0;
11264 }
11265
11266 return 1;
11267}
11268
11269
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011270static int off_chan_val(enum sec_ch_offset off)
11271{
11272 switch (off) {
11273 case SEC_CH_NO:
11274 return 0;
11275 case SEC_CH_40ABOVE:
11276 return 40;
11277 case SEC_CH_40BELOW:
11278 return -40;
11279 }
11280
11281 return 0;
11282}
11283
11284
11285static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
11286 const char *intf, int off_ch_num,
11287 enum sec_ch_offset sec)
11288{
11289 char buf[200];
11290 int res;
11291
11292 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
11293 intf, off_ch_num);
11294 if (res < 0 || res >= (int) sizeof(buf))
11295 return -1;
11296 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11297 if (system(buf) != 0) {
11298 send_resp(dut, conn, SIGMA_ERROR,
11299 "errorCode,Failed to set offchan");
11300 return 0;
11301 }
11302
11303 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
11304 intf, off_chan_val(sec));
11305 if (res < 0 || res >= (int) sizeof(buf))
11306 return -1;
11307 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11308 if (system(buf) != 0) {
11309 send_resp(dut, conn, SIGMA_ERROR,
11310 "errorCode,Failed to set sec chan offset");
11311 return 0;
11312 }
11313
11314 return 1;
11315}
11316
11317
11318static int tdls_set_offchannel_offset(struct sigma_dut *dut,
11319 struct sigma_conn *conn,
11320 const char *intf, int off_ch_num,
11321 enum sec_ch_offset sec)
11322{
11323 char buf[200];
11324 int res;
11325
11326 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
11327 off_ch_num);
11328 if (res < 0 || res >= (int) sizeof(buf))
11329 return -1;
11330 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11331
11332 if (wpa_command(intf, buf) < 0) {
11333 send_resp(dut, conn, SIGMA_ERROR,
11334 "ErrorCode,Failed to set offchan");
11335 return 0;
11336 }
11337 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
11338 off_chan_val(sec));
11339 if (res < 0 || res >= (int) sizeof(buf))
11340 return -1;
11341
11342 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11343
11344 if (wpa_command(intf, buf) < 0) {
11345 send_resp(dut, conn, SIGMA_ERROR,
11346 "ErrorCode,Failed to set sec chan offset");
11347 return 0;
11348 }
11349
11350 return 1;
11351}
11352
11353
11354static int tdls_set_offchannel_mode(struct sigma_dut *dut,
11355 struct sigma_conn *conn,
11356 const char *intf, int val)
11357{
11358 char buf[200];
11359 int res;
11360
11361 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
11362 val);
11363 if (res < 0 || res >= (int) sizeof(buf))
11364 return -1;
11365 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11366
11367 if (wpa_command(intf, buf) < 0) {
11368 send_resp(dut, conn, SIGMA_ERROR,
11369 "ErrorCode,Failed to configure offchannel mode");
11370 return 0;
11371 }
11372
11373 return 1;
11374}
11375
11376
11377static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
11378 struct sigma_conn *conn,
11379 struct sigma_cmd *cmd)
11380{
11381 const char *val;
11382 enum {
11383 CHSM_NOT_SET,
11384 CHSM_ENABLE,
11385 CHSM_DISABLE,
11386 CHSM_REJREQ,
11387 CHSM_UNSOLRESP
11388 } chsm = CHSM_NOT_SET;
11389 int off_ch_num = -1;
11390 enum sec_ch_offset sec_ch = SEC_CH_NO;
11391 int res;
11392
11393 val = get_param(cmd, "Uapsd");
11394 if (val) {
11395 char buf[100];
11396 if (strcasecmp(val, "Enable") == 0)
11397 snprintf(buf, sizeof(buf), "SET ps 99");
11398 else if (strcasecmp(val, "Disable") == 0)
11399 snprintf(buf, sizeof(buf), "SET ps 98");
11400 else {
11401 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11402 "Unsupported uapsd parameter value");
11403 return 0;
11404 }
11405 if (wpa_command(intf, buf)) {
11406 send_resp(dut, conn, SIGMA_ERROR,
11407 "ErrorCode,Failed to change U-APSD "
11408 "powersave mode");
11409 return 0;
11410 }
11411 }
11412
11413 val = get_param(cmd, "TPKTIMER");
11414 if (val && strcasecmp(val, "DISABLE") == 0) {
11415 if (wpa_command(intf, "SET tdls_testing 0x100")) {
11416 send_resp(dut, conn, SIGMA_ERROR,
11417 "ErrorCode,Failed to enable no TPK "
11418 "expiration test mode");
11419 return 0;
11420 }
11421 dut->no_tpk_expiration = 1;
11422 }
11423
11424 val = get_param(cmd, "ChSwitchMode");
11425 if (val) {
11426 if (strcasecmp(val, "Enable") == 0 ||
11427 strcasecmp(val, "Initiate") == 0)
11428 chsm = CHSM_ENABLE;
11429 else if (strcasecmp(val, "Disable") == 0 ||
11430 strcasecmp(val, "passive") == 0)
11431 chsm = CHSM_DISABLE;
11432 else if (strcasecmp(val, "RejReq") == 0)
11433 chsm = CHSM_REJREQ;
11434 else if (strcasecmp(val, "UnSolResp") == 0)
11435 chsm = CHSM_UNSOLRESP;
11436 else {
11437 send_resp(dut, conn, SIGMA_ERROR,
11438 "ErrorCode,Unknown ChSwitchMode value");
11439 return 0;
11440 }
11441 }
11442
11443 val = get_param(cmd, "OffChNum");
11444 if (val) {
11445 off_ch_num = atoi(val);
11446 if (off_ch_num == 0) {
11447 send_resp(dut, conn, SIGMA_ERROR,
11448 "ErrorCode,Invalid OffChNum");
11449 return 0;
11450 }
11451 }
11452
11453 val = get_param(cmd, "SecChOffset");
11454 if (val) {
11455 if (strcmp(val, "20") == 0)
11456 sec_ch = SEC_CH_NO;
11457 else if (strcasecmp(val, "40above") == 0)
11458 sec_ch = SEC_CH_40ABOVE;
11459 else if (strcasecmp(val, "40below") == 0)
11460 sec_ch = SEC_CH_40BELOW;
11461 else {
11462 send_resp(dut, conn, SIGMA_ERROR,
11463 "ErrorCode,Unknown SecChOffset value");
11464 return 0;
11465 }
11466 }
11467
11468 if (chsm == CHSM_NOT_SET) {
11469 /* no offchannel changes requested */
11470 return 1;
11471 }
11472
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011473 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
11474 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011475 send_resp(dut, conn, SIGMA_ERROR,
11476 "ErrorCode,Unknown interface");
11477 return 0;
11478 }
11479
11480 switch (chsm) {
11481 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030011482 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011483 break;
11484 case CHSM_ENABLE:
11485 if (off_ch_num < 0) {
11486 send_resp(dut, conn, SIGMA_ERROR,
11487 "ErrorCode,Missing OffChNum argument");
11488 return 0;
11489 }
11490 if (wifi_chip_type == DRIVER_WCN) {
11491 res = tdls_set_offchannel_offset(dut, conn, intf,
11492 off_ch_num, sec_ch);
11493 } else {
11494 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11495 sec_ch);
11496 }
11497 if (res != 1)
11498 return res;
11499 if (wifi_chip_type == DRIVER_WCN)
11500 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
11501 else
11502 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
11503 break;
11504 case CHSM_DISABLE:
11505 if (wifi_chip_type == DRIVER_WCN)
11506 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
11507 else
11508 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
11509 break;
11510 case CHSM_REJREQ:
11511 if (wifi_chip_type == DRIVER_WCN)
11512 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
11513 else
11514 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
11515 break;
11516 case CHSM_UNSOLRESP:
11517 if (off_ch_num < 0) {
11518 send_resp(dut, conn, SIGMA_ERROR,
11519 "ErrorCode,Missing OffChNum argument");
11520 return 0;
11521 }
11522 if (wifi_chip_type == DRIVER_WCN) {
11523 res = tdls_set_offchannel_offset(dut, conn, intf,
11524 off_ch_num, sec_ch);
11525 } else {
11526 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11527 sec_ch);
11528 }
11529 if (res != 1)
11530 return res;
11531 if (wifi_chip_type == DRIVER_WCN)
11532 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
11533 else
11534 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
11535 break;
11536 }
11537
11538 return res;
11539}
11540
11541
11542static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11543 struct sigma_conn *conn,
11544 struct sigma_cmd *cmd)
11545{
11546 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011547 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011548
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011549 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080011550
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011551 val = get_param(cmd, "nss_mcs_opt");
11552 if (val) {
11553 /* String (nss_operating_mode; mcs_operating_mode) */
11554 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011555 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011556
11557 token = strdup(val);
11558 if (!token)
11559 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011560 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011561 if (!result) {
11562 sigma_dut_print(dut, DUT_MSG_ERROR,
11563 "VHT NSS not specified");
11564 goto failed;
11565 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011566 if (strcasecmp(result, "def") != 0) {
11567 nss = atoi(result);
11568 if (nss == 4)
11569 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011570 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011571 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011572
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011573 }
11574
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011575 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011576 if (!result) {
11577 sigma_dut_print(dut, DUT_MSG_ERROR,
11578 "VHT MCS not specified");
11579 goto failed;
11580 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011581 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011582 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011583 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011584 } else {
11585 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011586 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011587 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011588 }
11589 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011590 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011591 }
11592
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011593 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011594 return 1;
11595failed:
11596 free(token);
11597 return 0;
11598}
11599
11600
11601static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11602 struct sigma_conn *conn,
11603 struct sigma_cmd *cmd)
11604{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011605 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011606 case DRIVER_ATHEROS:
11607 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
11608 default:
11609 send_resp(dut, conn, SIGMA_ERROR,
11610 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
11611 return 0;
11612 }
11613}
11614
11615
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011616static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11617 struct sigma_conn *conn,
11618 struct sigma_cmd *cmd)
11619{
11620 const char *val;
11621 char *token = NULL, *result;
11622 char buf[60];
11623
11624 val = get_param(cmd, "nss_mcs_opt");
11625 if (val) {
11626 /* String (nss_operating_mode; mcs_operating_mode) */
11627 int nss, mcs, ratecode;
11628 char *saveptr;
11629
11630 token = strdup(val);
11631 if (!token)
11632 return -2;
11633
11634 result = strtok_r(token, ";", &saveptr);
11635 if (!result) {
11636 sigma_dut_print(dut, DUT_MSG_ERROR,
11637 "HE NSS not specified");
11638 goto failed;
11639 }
11640 nss = 1;
11641 if (strcasecmp(result, "def") != 0)
11642 nss = atoi(result);
11643
11644 result = strtok_r(NULL, ";", &saveptr);
11645 if (!result) {
11646 sigma_dut_print(dut, DUT_MSG_ERROR,
11647 "HE MCS not specified");
11648 goto failed;
11649 }
11650 mcs = 7;
11651 if (strcasecmp(result, "def") != 0)
11652 mcs = atoi(result);
11653
Arif Hussain557bf412018-05-25 17:29:36 -070011654 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011655 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070011656 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011657 } else if (nss > 2) {
11658 sigma_dut_print(dut, DUT_MSG_ERROR,
11659 "HE NSS %d not supported", nss);
11660 goto failed;
11661 }
11662
Arif Hussain557bf412018-05-25 17:29:36 -070011663 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
11664 if (system(buf) != 0) {
11665 sigma_dut_print(dut, DUT_MSG_ERROR,
11666 "nss_mcs_opt: iwpriv %s nss %d failed",
11667 intf, nss);
11668 goto failed;
11669 }
Arif Hussainac6c5112018-05-25 17:34:00 -070011670 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070011671
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011672 /* Add the MCS to the ratecode */
11673 if (mcs >= 0 && mcs <= 11) {
11674 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070011675#ifdef NL80211_SUPPORT
11676 if (dut->device_type == STA_testbed) {
11677 enum he_mcs_config mcs_config;
11678 int ret;
11679
11680 if (mcs <= 7)
11681 mcs_config = HE_80_MCS0_7;
11682 else if (mcs <= 9)
11683 mcs_config = HE_80_MCS0_9;
11684 else
11685 mcs_config = HE_80_MCS0_11;
11686 ret = sta_set_he_mcs(dut, intf, mcs_config);
11687 if (ret) {
11688 sigma_dut_print(dut, DUT_MSG_ERROR,
11689 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
11690 mcs, mcs_config, ret);
11691 goto failed;
11692 }
11693 }
11694#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011695 } else {
11696 sigma_dut_print(dut, DUT_MSG_ERROR,
11697 "HE MCS %d not supported", mcs);
11698 goto failed;
11699 }
11700 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
11701 intf, ratecode);
11702 if (system(buf) != 0) {
11703 sigma_dut_print(dut, DUT_MSG_ERROR,
11704 "iwpriv setting of 11ax rates failed");
11705 goto failed;
11706 }
11707 free(token);
11708 }
11709
11710 val = get_param(cmd, "GI");
11711 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011712 int fix_rate_sgi;
11713
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011714 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011715 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011716 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011717 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011718 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
11719 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011720 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011721 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011722 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
11723 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011724 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011725 } else {
11726 send_resp(dut, conn, SIGMA_ERROR,
11727 "errorCode,GI value not supported");
11728 return 0;
11729 }
11730 if (system(buf) != 0) {
11731 send_resp(dut, conn, SIGMA_ERROR,
11732 "errorCode,Failed to set shortgi");
11733 return 0;
11734 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011735 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
11736 intf, fix_rate_sgi);
11737 if (system(buf) != 0) {
11738 send_resp(dut, conn, SIGMA_ERROR,
11739 "errorCode,Failed to set fix rate shortgi");
11740 return STATUS_SENT;
11741 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011742 }
11743
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011744 val = get_param(cmd, "LTF");
11745 if (val) {
11746#ifdef NL80211_SUPPORT
11747 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011748 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011749 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011750 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011751 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011752 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011753 } else {
11754 send_resp(dut, conn, SIGMA_ERROR,
11755 "errorCode, LTF value not supported");
11756 return 0;
11757 }
11758#else /* NL80211_SUPPORT */
11759 sigma_dut_print(dut, DUT_MSG_ERROR,
11760 "LTF cannot be set without NL80211_SUPPORT defined");
11761 return -2;
11762#endif /* NL80211_SUPPORT */
11763 }
11764
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070011765 val = get_param(cmd, "TxSUPPDU");
11766 if (val) {
11767 int set_val = 1;
11768
11769 if (strcasecmp(val, "Enable") == 0)
11770 set_val = 1;
11771 else if (strcasecmp(val, "Disable") == 0)
11772 set_val = 0;
11773
11774 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
11775 send_resp(dut, conn, SIGMA_ERROR,
11776 "ErrorCode,Failed to set Tx SU PPDU config");
11777 return 0;
11778 }
11779 }
11780
Arif Hussain480d5f42019-03-12 14:40:42 -070011781 val = get_param(cmd, "TWT_Setup");
11782 if (val) {
11783 if (strcasecmp(val, "Request") == 0) {
11784 if (sta_twt_request(dut, conn, cmd)) {
11785 send_resp(dut, conn, SIGMA_ERROR,
11786 "ErrorCode,sta_twt_request failed");
11787 return STATUS_SENT;
11788 }
11789 } else if (strcasecmp(val, "Teardown") == 0) {
11790 if (sta_twt_teardown(dut, conn, cmd)) {
11791 send_resp(dut, conn, SIGMA_ERROR,
11792 "ErrorCode,sta_twt_teardown failed");
11793 return STATUS_SENT;
11794 }
11795 }
11796 }
11797
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080011798 val = get_param(cmd, "transmitOMI");
11799 if (val && sta_transmit_omi(dut, conn, cmd)) {
11800 send_resp(dut, conn, SIGMA_ERROR,
11801 "ErrorCode,sta_transmit_omi failed");
11802 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070011803 }
11804
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011805 val = get_param(cmd, "Powersave");
11806 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011807 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011808
11809 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011810 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011811 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011812 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011813 } else {
11814 sigma_dut_print(dut, DUT_MSG_ERROR,
11815 "Unsupported Powersave value '%s'",
11816 val);
11817 return -1;
11818 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011819 if (set_power_save_wcn(dut, intf, ps) < 0)
11820 return 0;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011821 }
11822
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080011823 val = get_param(cmd, "MU_EDCA");
11824 if (val) {
11825 if (strcasecmp(val, "Override") == 0) {
11826 if (sta_set_mu_edca_override(dut, intf, 1)) {
11827 send_resp(dut, conn, SIGMA_ERROR,
11828 "errorCode,MU EDCA override set failed");
11829 return STATUS_SENT;
11830 }
11831 } else if (strcasecmp(val, "Disable") == 0) {
11832 if (sta_set_mu_edca_override(dut, intf, 0)) {
11833 send_resp(dut, conn, SIGMA_ERROR,
11834 "errorCode,MU EDCA override disable failed");
11835 return STATUS_SENT;
11836 }
11837 }
11838 }
11839
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011840 return 1;
11841
11842failed:
11843 free(token);
11844 return -2;
11845}
11846
11847
11848static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11849 struct sigma_conn *conn,
11850 struct sigma_cmd *cmd)
11851{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011852 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011853 case DRIVER_WCN:
11854 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
11855 default:
11856 send_resp(dut, conn, SIGMA_ERROR,
11857 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
11858 return 0;
11859 }
11860}
11861
11862
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011863static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
11864 struct sigma_conn *conn,
11865 struct sigma_cmd *cmd)
11866{
11867 const char *val;
11868
11869 val = get_param(cmd, "powersave");
11870 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011871 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011872
11873 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011874 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011875 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011876 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011877 } else {
11878 sigma_dut_print(dut, DUT_MSG_ERROR,
11879 "Unsupported power save config");
11880 return -1;
11881 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011882 if (set_power_save_wcn(dut, intf, ps) < 0)
11883 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011884 return 1;
11885 }
11886
11887 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
11888
11889 return 0;
11890}
11891
11892
Ashwini Patil5acd7382017-04-13 15:55:04 +053011893static int btm_query_candidate_list(struct sigma_dut *dut,
11894 struct sigma_conn *conn,
11895 struct sigma_cmd *cmd)
11896{
11897 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
11898 int len, ret;
11899 char buf[10];
11900
11901 /*
11902 * Neighbor Report elements format:
11903 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
11904 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
11905 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
11906 */
11907
11908 bssid = get_param(cmd, "Nebor_BSSID");
11909 if (!bssid) {
11910 send_resp(dut, conn, SIGMA_INVALID,
11911 "errorCode,Nebor_BSSID is missing");
11912 return 0;
11913 }
11914
11915 info = get_param(cmd, "Nebor_Bssid_Info");
11916 if (!info) {
11917 sigma_dut_print(dut, DUT_MSG_INFO,
11918 "Using default value for Nebor_Bssid_Info: %s",
11919 DEFAULT_NEIGHBOR_BSSID_INFO);
11920 info = DEFAULT_NEIGHBOR_BSSID_INFO;
11921 }
11922
11923 op_class = get_param(cmd, "Nebor_Op_Class");
11924 if (!op_class) {
11925 send_resp(dut, conn, SIGMA_INVALID,
11926 "errorCode,Nebor_Op_Class is missing");
11927 return 0;
11928 }
11929
11930 ch = get_param(cmd, "Nebor_Op_Ch");
11931 if (!ch) {
11932 send_resp(dut, conn, SIGMA_INVALID,
11933 "errorCode,Nebor_Op_Ch is missing");
11934 return 0;
11935 }
11936
11937 phy_type = get_param(cmd, "Nebor_Phy_Type");
11938 if (!phy_type) {
11939 sigma_dut_print(dut, DUT_MSG_INFO,
11940 "Using default value for Nebor_Phy_Type: %s",
11941 DEFAULT_NEIGHBOR_PHY_TYPE);
11942 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
11943 }
11944
11945 /* Parse optional subelements */
11946 buf[0] = '\0';
11947 pref = get_param(cmd, "Nebor_Pref");
11948 if (pref) {
11949 /* hexdump for preferrence subelement */
11950 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
11951 if (ret < 0 || ret >= (int) sizeof(buf)) {
11952 sigma_dut_print(dut, DUT_MSG_ERROR,
11953 "snprintf failed for optional subelement ret: %d",
11954 ret);
11955 send_resp(dut, conn, SIGMA_ERROR,
11956 "errorCode,snprintf failed for subelement");
11957 return 0;
11958 }
11959 }
11960
11961 if (!dut->btm_query_cand_list) {
11962 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
11963 if (!dut->btm_query_cand_list) {
11964 send_resp(dut, conn, SIGMA_ERROR,
11965 "errorCode,Failed to allocate memory for btm_query_cand_list");
11966 return 0;
11967 }
11968 }
11969
11970 len = strlen(dut->btm_query_cand_list);
11971 ret = snprintf(dut->btm_query_cand_list + len,
11972 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
11973 bssid, info, op_class, ch, phy_type, buf);
11974 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
11975 sigma_dut_print(dut, DUT_MSG_ERROR,
11976 "snprintf failed for neighbor report list ret: %d",
11977 ret);
11978 send_resp(dut, conn, SIGMA_ERROR,
11979 "errorCode,snprintf failed for neighbor report");
11980 free(dut->btm_query_cand_list);
11981 dut->btm_query_cand_list = NULL;
11982 return 0;
11983 }
11984
11985 return 1;
11986}
11987
11988
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011989int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
11990 struct sigma_ese_alloc *allocs, int *allocs_size)
11991{
11992 int max_count = *allocs_size;
11993 int count = 0, i;
11994 const char *val;
11995
11996 do {
11997 val = get_param_indexed(cmd, "AllocID", count);
11998 if (val)
11999 count++;
12000 } while (val);
12001
12002 if (count == 0 || count > max_count) {
12003 sigma_dut_print(dut, DUT_MSG_ERROR,
12004 "Invalid number of allocations(%d)", count);
12005 return -1;
12006 }
12007
12008 for (i = 0; i < count; i++) {
12009 val = get_param_indexed(cmd, "PercentBI", i);
12010 if (!val) {
12011 sigma_dut_print(dut, DUT_MSG_ERROR,
12012 "Missing PercentBI parameter at index %d",
12013 i);
12014 return -1;
12015 }
12016 allocs[i].percent_bi = atoi(val);
12017
12018 val = get_param_indexed(cmd, "SrcAID", i);
12019 if (val)
12020 allocs[i].src_aid = strtol(val, NULL, 0);
12021 else
12022 allocs[i].src_aid = ESE_BCAST_AID;
12023
12024 val = get_param_indexed(cmd, "DestAID", i);
12025 if (val)
12026 allocs[i].dst_aid = strtol(val, NULL, 0);
12027 else
12028 allocs[i].dst_aid = ESE_BCAST_AID;
12029
12030 allocs[i].type = ESE_CBAP;
12031 sigma_dut_print(dut, DUT_MSG_INFO,
12032 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
12033 i, allocs[i].percent_bi, allocs[i].src_aid,
12034 allocs[i].dst_aid);
12035 }
12036
12037 *allocs_size = count;
12038 return 0;
12039}
12040
12041
12042static int sta_set_60g_ese(struct sigma_dut *dut, int count,
12043 struct sigma_ese_alloc *allocs)
12044{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012045 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012046#ifdef __linux__
12047 case DRIVER_WIL6210:
12048 if (wil6210_set_ese(dut, count, allocs))
12049 return -1;
12050 return 1;
12051#endif /* __linux__ */
12052 default:
12053 sigma_dut_print(dut, DUT_MSG_ERROR,
12054 "Unsupported sta_set_60g_ese with the current driver");
12055 return -1;
12056 }
12057}
12058
12059
12060static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
12061 struct sigma_conn *conn,
12062 struct sigma_cmd *cmd)
12063{
12064 const char *val;
12065
12066 val = get_param(cmd, "ExtSchIE");
12067 if (val && !strcasecmp(val, "Enable")) {
12068 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
12069 int count = MAX_ESE_ALLOCS;
12070
12071 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
12072 return -1;
12073 return sta_set_60g_ese(dut, count, allocs);
12074 }
12075
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012076 val = get_param(cmd, "MCS_FixedRate");
12077 if (val) {
12078 int sta_mcs = atoi(val);
12079
12080 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
12081 sta_mcs);
12082 wil6210_set_force_mcs(dut, 1, sta_mcs);
12083
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012084 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012085 }
12086
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012087 send_resp(dut, conn, SIGMA_ERROR,
12088 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012089 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012090}
12091
12092
Jouni Malinen6250cb02020-04-15 13:54:45 +030012093static enum sigma_cmd_result
12094cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
12095 struct sigma_conn *conn,
12096 struct sigma_cmd *cmd)
12097{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012098 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030012099
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053012100 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030012101 if (val && atoi(val) == 1) {
12102 if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
12103 send_resp(dut, conn, SIGMA_ERROR,
12104 "errorCode,Failed to set ft_rsnxe_used");
12105 return STATUS_SENT_ERROR;
12106 }
12107 return SUCCESS_SEND_STATUS;
12108 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012109
12110 oci_chan = get_param(cmd, "OCIChannel");
12111 oci_frametype = get_param(cmd, "OCIFrameType");
12112 if (oci_chan && oci_frametype) {
12113 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
12114 char buf[100];
12115
12116 if (!oci_freq) {
12117 send_resp(dut, conn, SIGMA_ERROR,
12118 "errorCode,Invalid OCIChannel number");
12119 return STATUS_SENT_ERROR;
12120 }
12121
12122 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
12123 snprintf(buf, sizeof(buf),
12124 "SET oci_freq_override_eapol %d", oci_freq);
12125 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12126 snprintf(buf, sizeof(buf),
12127 "SET oci_freq_override_saquery_req %d",
12128 oci_freq);
12129 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12130 snprintf(buf, sizeof(buf),
12131 "SET oci_freq_override_saquery_resp %d",
12132 oci_freq);
12133 } else {
12134 send_resp(dut, conn, SIGMA_ERROR,
12135 "errorCode,Unsupported OCIFrameType");
12136 return STATUS_SENT_ERROR;
12137 }
12138 if (wpa_command(intf, buf) < 0) {
12139 send_resp(dut, conn, SIGMA_ERROR,
12140 "errorCode,Failed to set oci_freq_override");
12141 return STATUS_SENT_ERROR;
12142 }
12143 return SUCCESS_SEND_STATUS;
12144 }
12145
Jouni Malinen6250cb02020-04-15 13:54:45 +030012146 send_resp(dut, conn, SIGMA_ERROR,
12147 "errorCode,Unsupported WPA3 rfeature");
12148 return STATUS_SENT_ERROR;
12149}
12150
12151
Jouni Malinenf7222712019-06-13 01:50:21 +030012152static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
12153 struct sigma_conn *conn,
12154 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012155{
12156 const char *intf = get_param(cmd, "Interface");
12157 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012158 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012159
12160 if (intf == NULL || prog == NULL)
12161 return -1;
12162
Ashwini Patil5acd7382017-04-13 15:55:04 +053012163 /* BSS Transition candidate list for BTM query */
12164 val = get_param(cmd, "Nebor_BSSID");
12165 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
12166 return 0;
12167
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012168 if (strcasecmp(prog, "TDLS") == 0)
12169 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
12170
12171 if (strcasecmp(prog, "VHT") == 0)
12172 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
12173
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012174 if (strcasecmp(prog, "HE") == 0)
12175 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
12176
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012177 if (strcasecmp(prog, "MBO") == 0) {
12178 val = get_param(cmd, "Cellular_Data_Cap");
12179 if (val &&
12180 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12181 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053012182
12183 val = get_param(cmd, "Ch_Pref");
12184 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12185 return 0;
12186
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012187 return 1;
12188 }
12189
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012190 if (strcasecmp(prog, "60GHz") == 0)
12191 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
12192
Jouni Malinen6250cb02020-04-15 13:54:45 +030012193 if (strcasecmp(prog, "WPA3") == 0)
12194 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
12195
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012196 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
12197 return 0;
12198}
12199
12200
Jouni Malinenf7222712019-06-13 01:50:21 +030012201static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
12202 struct sigma_conn *conn,
12203 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012204{
12205 const char *intf = get_param(cmd, "Interface");
12206 const char *mode = get_param(cmd, "Mode");
12207 int res;
12208
12209 if (intf == NULL || mode == NULL)
12210 return -1;
12211
12212 if (strcasecmp(mode, "On") == 0)
12213 res = wpa_command(intf, "SET radio_disabled 0");
12214 else if (strcasecmp(mode, "Off") == 0)
12215 res = wpa_command(intf, "SET radio_disabled 1");
12216 else
12217 return -1;
12218
12219 if (res) {
12220 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12221 "radio mode");
12222 return 0;
12223 }
12224
12225 return 1;
12226}
12227
12228
Jouni Malinenf7222712019-06-13 01:50:21 +030012229static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
12230 struct sigma_conn *conn,
12231 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012232{
12233 const char *intf = get_param(cmd, "Interface");
12234 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012235 const char *prog = get_param(cmd, "program");
12236 const char *powersave = get_param(cmd, "powersave");
12237 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012238
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012239 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012240 return -1;
12241
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012242 if (prog && strcasecmp(prog, "60GHz") == 0) {
12243 /*
12244 * The CAPI mode parameter does not exist in 60G
12245 * unscheduled PS.
12246 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080012247 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012248 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012249 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020012250 strcasecmp(prog, "HE") == 0) {
12251 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012252 } else {
12253 if (mode == NULL)
12254 return -1;
12255
12256 if (strcasecmp(mode, "On") == 0)
12257 res = set_ps(intf, dut, 1);
12258 else if (strcasecmp(mode, "Off") == 0)
12259 res = set_ps(intf, dut, 0);
12260 else
12261 return -1;
12262 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012263
12264 if (res) {
12265 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12266 "power save mode");
12267 return 0;
12268 }
12269
12270 return 1;
12271}
12272
12273
Jouni Malinenf7222712019-06-13 01:50:21 +030012274static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
12275 struct sigma_conn *conn,
12276 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012277{
12278 const char *intf = get_param(cmd, "Interface");
12279 const char *val, *bssid;
12280 int res;
12281 char *buf;
12282 size_t buf_len;
12283
12284 val = get_param(cmd, "BSSID_FILTER");
12285 if (val == NULL)
12286 return -1;
12287
12288 bssid = get_param(cmd, "BSSID_List");
12289 if (atoi(val) == 0 || bssid == NULL) {
12290 /* Disable BSSID filter */
12291 if (wpa_command(intf, "SET bssid_filter ")) {
12292 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
12293 "to disable BSSID filter");
12294 return 0;
12295 }
12296
12297 return 1;
12298 }
12299
12300 buf_len = 100 + strlen(bssid);
12301 buf = malloc(buf_len);
12302 if (buf == NULL)
12303 return -1;
12304
12305 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
12306 res = wpa_command(intf, buf);
12307 free(buf);
12308 if (res) {
12309 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
12310 "BSSID filter");
12311 return 0;
12312 }
12313
12314 return 1;
12315}
12316
12317
Jouni Malinenf7222712019-06-13 01:50:21 +030012318static enum sigma_cmd_result cmd_sta_reset_parm(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 *val;
12324
12325 /* TODO: ARP */
12326
12327 val = get_param(cmd, "HS2_CACHE_PROFILE");
12328 if (val && strcasecmp(val, "All") == 0)
12329 hs2_clear_credentials(intf);
12330
12331 return 1;
12332}
12333
12334
Jouni Malinenf7222712019-06-13 01:50:21 +030012335static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
12336 struct sigma_conn *conn,
12337 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012338{
12339 const char *intf = get_param(cmd, "Interface");
12340 const char *key_type = get_param(cmd, "KeyType");
12341 char buf[100], resp[200];
12342
12343 if (key_type == NULL)
12344 return -1;
12345
12346 if (strcasecmp(key_type, "GTK") == 0) {
12347 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
12348 strncmp(buf, "FAIL", 4) == 0) {
12349 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12350 "not fetch current GTK");
12351 return 0;
12352 }
12353 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
12354 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12355 return 0;
12356 } else {
12357 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12358 "KeyType");
12359 return 0;
12360 }
12361
12362 return 1;
12363}
12364
12365
12366static int hs2_set_policy(struct sigma_dut *dut)
12367{
12368#ifdef ANDROID
12369 system("ip rule del prio 23000");
12370 if (system("ip rule add from all lookup main prio 23000") != 0) {
12371 sigma_dut_print(dut, DUT_MSG_ERROR,
12372 "Failed to run:ip rule add from all lookup main prio");
12373 return -1;
12374 }
12375 if (system("ip route flush cache") != 0) {
12376 sigma_dut_print(dut, DUT_MSG_ERROR,
12377 "Failed to run ip route flush cache");
12378 return -1;
12379 }
12380 return 1;
12381#else /* ANDROID */
12382 return 0;
12383#endif /* ANDROID */
12384}
12385
12386
Jouni Malinenf7222712019-06-13 01:50:21 +030012387static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
12388 struct sigma_conn *conn,
12389 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012390{
12391 const char *intf = get_param(cmd, "Interface");
12392 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030012393 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012394 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030012395 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012396 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
12397 int tries = 0;
12398 int ignore_blacklist = 0;
12399 const char *events[] = {
12400 "CTRL-EVENT-CONNECTED",
12401 "INTERWORKING-BLACKLISTED",
12402 "INTERWORKING-NO-MATCH",
12403 NULL
12404 };
12405
12406 start_sta_mode(dut);
12407
Jouni Malinen439352d2018-09-13 03:42:23 +030012408 if (band) {
12409 if (strcmp(band, "2.4") == 0) {
12410 wpa_command(intf, "SET setband 2G");
12411 } else if (strcmp(band, "5") == 0) {
12412 wpa_command(intf, "SET setband 5G");
12413 } else {
12414 send_resp(dut, conn, SIGMA_ERROR,
12415 "errorCode,Unsupported band");
12416 return 0;
12417 }
12418 }
12419
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012420 blacklisted[0] = '\0';
12421 if (val && atoi(val))
12422 ignore_blacklist = 1;
12423
12424try_again:
12425 ctrl = open_wpa_mon(intf);
12426 if (ctrl == NULL) {
12427 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12428 "wpa_supplicant monitor connection");
12429 return -2;
12430 }
12431
12432 tries++;
12433 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
12434 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
12435 "Interworking connection");
12436 wpa_ctrl_detach(ctrl);
12437 wpa_ctrl_close(ctrl);
12438 return 0;
12439 }
12440
12441 buf[0] = '\0';
12442 while (1) {
12443 char *pos;
12444 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
12445 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
12446 if (!pos)
12447 break;
12448 pos += 25;
12449 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
12450 pos);
12451 if (!blacklisted[0])
12452 memcpy(blacklisted, pos, strlen(pos) + 1);
12453 }
12454
12455 if (ignore_blacklist && blacklisted[0]) {
12456 char *end;
12457 end = strchr(blacklisted, ' ');
12458 if (end)
12459 *end = '\0';
12460 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
12461 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030012462 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
12463 blacklisted);
12464 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012465 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
12466 wpa_ctrl_detach(ctrl);
12467 wpa_ctrl_close(ctrl);
12468 return 0;
12469 }
12470 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
12471 buf, sizeof(buf));
12472 }
12473
12474 wpa_ctrl_detach(ctrl);
12475 wpa_ctrl_close(ctrl);
12476
12477 if (res < 0) {
12478 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12479 "connect");
12480 return 0;
12481 }
12482
12483 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
12484 strstr(buf, "INTERWORKING-BLACKLISTED")) {
12485 if (tries < 2) {
12486 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
12487 goto try_again;
12488 }
12489 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
12490 "matching credentials found");
12491 return 0;
12492 }
12493
12494 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12495 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12496 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12497 "get current BSSID/SSID");
12498 return 0;
12499 }
12500
12501 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
12502 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12503 hs2_set_policy(dut);
12504 return 0;
12505}
12506
12507
Jouni Malinenf7222712019-06-13 01:50:21 +030012508static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
12509 struct sigma_conn *conn,
12510 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030012511{
12512 const char *intf = get_param(cmd, "Interface");
12513 const char *display = get_param(cmd, "Display");
12514 struct wpa_ctrl *ctrl;
12515 char buf[300], params[400], *pos;
12516 char bssid[20];
12517 int info_avail = 0;
12518 unsigned int old_timeout;
12519 int res;
12520
12521 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
12522 send_resp(dut, conn, SIGMA_ERROR,
12523 "ErrorCode,Could not get current BSSID");
12524 return 0;
12525 }
12526 ctrl = open_wpa_mon(intf);
12527 if (!ctrl) {
12528 sigma_dut_print(dut, DUT_MSG_ERROR,
12529 "Failed to open wpa_supplicant monitor connection");
12530 return -2;
12531 }
12532
12533 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
12534 wpa_command(intf, buf);
12535
12536 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
12537 if (res < 0) {
12538 send_resp(dut, conn, SIGMA_ERROR,
12539 "ErrorCode,Could not complete GAS query");
12540 goto fail;
12541 }
12542
12543 old_timeout = dut->default_timeout;
12544 dut->default_timeout = 2;
12545 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
12546 dut->default_timeout = old_timeout;
12547 if (res < 0)
12548 goto done;
12549 pos = strchr(buf, ' ');
12550 if (!pos)
12551 goto done;
12552 pos++;
12553 pos = strchr(pos, ' ');
12554 if (!pos)
12555 goto done;
12556 pos++;
12557 info_avail = 1;
12558 snprintf(params, sizeof(params), "browser %s", pos);
12559
12560 if (display && strcasecmp(display, "Yes") == 0) {
12561 pid_t pid;
12562
12563 pid = fork();
12564 if (pid < 0) {
12565 perror("fork");
12566 return -1;
12567 }
12568
12569 if (pid == 0) {
12570 run_hs20_osu(dut, params);
12571 exit(0);
12572 }
12573 }
12574
12575done:
12576 snprintf(buf, sizeof(buf), "Info_available,%s",
12577 info_avail ? "Yes" : "No");
12578 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12579fail:
12580 wpa_ctrl_detach(ctrl);
12581 wpa_ctrl_close(ctrl);
12582 return 0;
12583}
12584
12585
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012586static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
12587 struct sigma_conn *conn,
12588 const char *ifname,
12589 struct sigma_cmd *cmd)
12590{
12591 const char *val;
12592 int id;
12593
12594 id = add_cred(ifname);
12595 if (id < 0)
12596 return -2;
12597 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12598
12599 val = get_param(cmd, "prefer");
12600 if (val && atoi(val) > 0)
12601 set_cred(ifname, id, "priority", "1");
12602
12603 val = get_param(cmd, "REALM");
12604 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12605 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12606 "realm");
12607 return 0;
12608 }
12609
12610 val = get_param(cmd, "HOME_FQDN");
12611 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12612 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12613 "home_fqdn");
12614 return 0;
12615 }
12616
12617 val = get_param(cmd, "Username");
12618 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12619 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12620 "username");
12621 return 0;
12622 }
12623
12624 val = get_param(cmd, "Password");
12625 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
12626 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12627 "password");
12628 return 0;
12629 }
12630
12631 val = get_param(cmd, "ROOT_CA");
12632 if (val) {
12633 char fname[200];
12634 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12635#ifdef __linux__
12636 if (!file_exists(fname)) {
12637 char msg[300];
12638 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12639 "file (%s) not found", fname);
12640 send_resp(dut, conn, SIGMA_ERROR, msg);
12641 return 0;
12642 }
12643#endif /* __linux__ */
12644 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12645 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12646 "not set root CA");
12647 return 0;
12648 }
12649 }
12650
12651 return 1;
12652}
12653
12654
12655static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
12656{
12657 FILE *in, *out;
12658 char buf[500];
12659 int found = 0;
12660
12661 in = fopen("devdetail.xml", "r");
12662 if (in == NULL)
12663 return -1;
12664 out = fopen("devdetail.xml.tmp", "w");
12665 if (out == NULL) {
12666 fclose(in);
12667 return -1;
12668 }
12669
12670 while (fgets(buf, sizeof(buf), in)) {
12671 char *pos = strstr(buf, "<IMSI>");
12672 if (pos) {
12673 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
12674 imsi);
12675 pos += 6;
12676 *pos = '\0';
12677 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
12678 found++;
12679 } else {
12680 fprintf(out, "%s", buf);
12681 }
12682 }
12683
12684 fclose(out);
12685 fclose(in);
12686 if (found)
12687 rename("devdetail.xml.tmp", "devdetail.xml");
12688 else
12689 unlink("devdetail.xml.tmp");
12690
12691 return 0;
12692}
12693
12694
12695static int sta_add_credential_sim(struct sigma_dut *dut,
12696 struct sigma_conn *conn,
12697 const char *ifname, struct sigma_cmd *cmd)
12698{
12699 const char *val, *imsi = NULL;
12700 int id;
12701 char buf[200];
12702 int res;
12703 const char *pos;
12704 size_t mnc_len;
12705 char plmn_mcc[4];
12706 char plmn_mnc[4];
12707
12708 id = add_cred(ifname);
12709 if (id < 0)
12710 return -2;
12711 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12712
12713 val = get_param(cmd, "prefer");
12714 if (val && atoi(val) > 0)
12715 set_cred(ifname, id, "priority", "1");
12716
12717 val = get_param(cmd, "PLMN_MCC");
12718 if (val == NULL) {
12719 send_resp(dut, conn, SIGMA_ERROR,
12720 "errorCode,Missing PLMN_MCC");
12721 return 0;
12722 }
12723 if (strlen(val) != 3) {
12724 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
12725 return 0;
12726 }
12727 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
12728
12729 val = get_param(cmd, "PLMN_MNC");
12730 if (val == NULL) {
12731 send_resp(dut, conn, SIGMA_ERROR,
12732 "errorCode,Missing PLMN_MNC");
12733 return 0;
12734 }
12735 if (strlen(val) != 2 && strlen(val) != 3) {
12736 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
12737 return 0;
12738 }
12739 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
12740
12741 val = get_param(cmd, "IMSI");
12742 if (val == NULL) {
12743 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
12744 "IMSI");
12745 return 0;
12746 }
12747
12748 imsi = pos = val;
12749
12750 if (strncmp(plmn_mcc, pos, 3) != 0) {
12751 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
12752 return 0;
12753 }
12754 pos += 3;
12755
12756 mnc_len = strlen(plmn_mnc);
12757 if (mnc_len < 2) {
12758 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
12759 return 0;
12760 }
12761
12762 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
12763 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
12764 return 0;
12765 }
12766 pos += mnc_len;
12767
12768 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
12769 if (res < 0 || res >= (int) sizeof(buf))
12770 return -1;
12771 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
12772 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12773 "not set IMSI");
12774 return 0;
12775 }
12776
12777 val = get_param(cmd, "Password");
12778 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
12779 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12780 "not set password");
12781 return 0;
12782 }
12783
Jouni Malinenba630452018-06-22 11:49:59 +030012784 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012785 /*
12786 * Set provisioning_sp for the test cases where SIM/USIM
12787 * provisioning is used.
12788 */
12789 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
12790 "wi-fi.org") < 0) {
12791 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12792 "not set provisioning_sp");
12793 return 0;
12794 }
12795
12796 update_devdetail_imsi(dut, imsi);
12797 }
12798
12799 return 1;
12800}
12801
12802
12803static int sta_add_credential_cert(struct sigma_dut *dut,
12804 struct sigma_conn *conn,
12805 const char *ifname,
12806 struct sigma_cmd *cmd)
12807{
12808 const char *val;
12809 int id;
12810
12811 id = add_cred(ifname);
12812 if (id < 0)
12813 return -2;
12814 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12815
12816 val = get_param(cmd, "prefer");
12817 if (val && atoi(val) > 0)
12818 set_cred(ifname, id, "priority", "1");
12819
12820 val = get_param(cmd, "REALM");
12821 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12822 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12823 "realm");
12824 return 0;
12825 }
12826
12827 val = get_param(cmd, "HOME_FQDN");
12828 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12829 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12830 "home_fqdn");
12831 return 0;
12832 }
12833
12834 val = get_param(cmd, "Username");
12835 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12836 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12837 "username");
12838 return 0;
12839 }
12840
12841 val = get_param(cmd, "clientCertificate");
12842 if (val) {
12843 char fname[200];
12844 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12845#ifdef __linux__
12846 if (!file_exists(fname)) {
12847 char msg[300];
12848 snprintf(msg, sizeof(msg),
12849 "ErrorCode,clientCertificate "
12850 "file (%s) not found", fname);
12851 send_resp(dut, conn, SIGMA_ERROR, msg);
12852 return 0;
12853 }
12854#endif /* __linux__ */
12855 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
12856 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12857 "not set client_cert");
12858 return 0;
12859 }
12860 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
12861 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12862 "not set private_key");
12863 return 0;
12864 }
12865 }
12866
12867 val = get_param(cmd, "ROOT_CA");
12868 if (val) {
12869 char fname[200];
12870 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12871#ifdef __linux__
12872 if (!file_exists(fname)) {
12873 char msg[300];
12874 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12875 "file (%s) not found", fname);
12876 send_resp(dut, conn, SIGMA_ERROR, msg);
12877 return 0;
12878 }
12879#endif /* __linux__ */
12880 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12881 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12882 "not set root CA");
12883 return 0;
12884 }
12885 }
12886
12887 return 1;
12888}
12889
12890
Jouni Malinenf7222712019-06-13 01:50:21 +030012891static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
12892 struct sigma_conn *conn,
12893 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012894{
12895 const char *intf = get_param(cmd, "Interface");
12896 const char *type;
12897
12898 start_sta_mode(dut);
12899
12900 type = get_param(cmd, "Type");
12901 if (!type)
12902 return -1;
12903
12904 if (strcasecmp(type, "uname_pwd") == 0)
12905 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
12906
12907 if (strcasecmp(type, "sim") == 0)
12908 return sta_add_credential_sim(dut, conn, intf, cmd);
12909
12910 if (strcasecmp(type, "cert") == 0)
12911 return sta_add_credential_cert(dut, conn, intf, cmd);
12912
12913 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
12914 "type");
12915 return 0;
12916}
12917
12918
Jouni Malinenf7222712019-06-13 01:50:21 +030012919static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
12920 struct sigma_conn *conn,
12921 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012922{
12923 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012924 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Arif Hussain66a4af02019-02-07 15:04:51 -080012925 char buf[4096];
vamsi krishna89ad8c62017-09-19 12:51:18 +053012926 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080012927 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012928 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012929 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030012930 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012931
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020012932 start_sta_mode(dut);
12933
Arif Hussain66a4af02019-02-07 15:04:51 -080012934 val = get_param(cmd, "GetParameter");
12935 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012936 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080012937 buf, sizeof(buf)) < 0) {
12938 sigma_dut_print(dut, DUT_MSG_ERROR,
12939 "Could not get ssid bssid");
12940 return ERROR_SEND_STATUS;
12941 }
12942
12943 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
12944 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12945 return STATUS_SENT;
12946 }
12947
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012948 val = get_param(cmd, "HESSID");
12949 if (val) {
12950 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
12951 if (res < 0 || res >= (int) sizeof(buf))
12952 return -1;
12953 wpa_command(intf, buf);
12954 }
12955
12956 val = get_param(cmd, "ACCS_NET_TYPE");
12957 if (val) {
12958 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
12959 val);
12960 if (res < 0 || res >= (int) sizeof(buf))
12961 return -1;
12962 wpa_command(intf, buf);
12963 }
12964
vamsi krishna89ad8c62017-09-19 12:51:18 +053012965 bssid = get_param(cmd, "Bssid");
12966 ssid = get_param(cmd, "Ssid");
12967
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080012968 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
12969 dut->device_type == STA_testbed) {
12970 ssid = NULL;
12971 wildcard_ssid = 1;
12972 }
12973
vamsi krishna89ad8c62017-09-19 12:51:18 +053012974 if (ssid) {
12975 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
12976 send_resp(dut, conn, SIGMA_ERROR,
12977 "ErrorCode,Too long SSID");
12978 return 0;
12979 }
12980 ascii2hexstr(ssid, ssid_hex);
12981 }
12982
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012983 short_ssid = get_param(cmd, "ShortSSID");
12984 if (short_ssid) {
12985 uint32_t short_ssid_hex;
12986
12987 short_ssid_hex = strtoul(short_ssid, NULL, 16);
12988 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
12989 (((short_ssid_hex >> 8) & 0xFF) << 16) |
12990 (((short_ssid_hex >> 16) & 0xFF) << 8) |
12991 ((short_ssid_hex >> 24) & 0xFF);
12992
12993 res = snprintf(buf, sizeof(buf),
12994 "VENDOR_ELEM_ADD 14 ff053a%08x",
12995 short_ssid_hex);
12996 if (res < 0 || res >= (int) sizeof(buf) ||
12997 wpa_command(intf, buf)) {
12998 send_resp(dut, conn, SIGMA_ERROR,
12999 "errorCode,Failed to add short SSID");
13000 return STATUS_SENT_ERROR;
13001 }
13002 }
13003
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013004 scan_freq = get_param(cmd, "ChnlFreq");
13005
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013006 val = get_param(cmd, "WaitCompletion");
13007 if (val && atoi(val) == 1) {
13008 ctrl = open_wpa_mon(intf);
13009 if (!ctrl) {
13010 send_resp(dut, conn, SIGMA_ERROR,
13011 "errorCode,Failed to open monitor socket");
13012 return STATUS_SENT_ERROR;
13013 }
13014 }
13015
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013016 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053013017 bssid ? " bssid=": "",
13018 bssid ? bssid : "",
13019 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013020 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013021 wildcard_ssid ? " wildcard_ssid=1" : "",
13022 scan_freq ? " freq=" : "",
13023 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013024 if (res < 0 || res >= (int) sizeof(buf)) {
13025 send_resp(dut, conn, SIGMA_ERROR,
13026 "errorCode,Could not build scan command");
13027 status = STATUS_SENT_ERROR;
13028 goto remove_s_ssid;
13029 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053013030
13031 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013032 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
13033 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013034 status = STATUS_SENT_ERROR;
13035 } else {
13036 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013037 }
13038
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013039remove_s_ssid:
13040 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
13041 sigma_dut_print(dut, DUT_MSG_ERROR,
13042 "Failed to delete vendor element");
13043
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013044 if (ctrl) {
13045 if (status == SUCCESS_SEND_STATUS) {
13046 res = get_wpa_cli_event(dut, ctrl,
13047 "CTRL-EVENT-SCAN-RESULTS",
13048 buf, sizeof(buf));
13049 if (res < 0) {
13050 send_resp(dut, conn, SIGMA_ERROR,
13051 "ErrorCode,scan did not complete");
13052 status = STATUS_SENT_ERROR;
13053 }
13054 }
13055
13056 wpa_ctrl_detach(ctrl);
13057 wpa_ctrl_close(ctrl);
13058 }
13059
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013060 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013061}
13062
13063
Jouni Malinenf7222712019-06-13 01:50:21 +030013064static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
13065 struct sigma_conn *conn,
13066 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013067{
13068 const char *intf = get_param(cmd, "Interface");
13069 const char *bssid;
13070 char buf[4096], *pos;
13071 int freq, chan;
13072 char *ssid;
13073 char resp[100];
13074 int res;
13075 struct wpa_ctrl *ctrl;
13076
13077 bssid = get_param(cmd, "BSSID");
13078 if (!bssid) {
13079 send_resp(dut, conn, SIGMA_INVALID,
13080 "errorCode,BSSID argument is missing");
13081 return 0;
13082 }
13083
13084 ctrl = open_wpa_mon(intf);
13085 if (!ctrl) {
13086 sigma_dut_print(dut, DUT_MSG_ERROR,
13087 "Failed to open wpa_supplicant monitor connection");
13088 return -1;
13089 }
13090
13091 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
13092 send_resp(dut, conn, SIGMA_ERROR,
13093 "errorCode,Could not start scan");
13094 wpa_ctrl_detach(ctrl);
13095 wpa_ctrl_close(ctrl);
13096 return 0;
13097 }
13098
13099 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
13100 buf, sizeof(buf));
13101
13102 wpa_ctrl_detach(ctrl);
13103 wpa_ctrl_close(ctrl);
13104
13105 if (res < 0) {
13106 send_resp(dut, conn, SIGMA_ERROR,
13107 "errorCode,Scan did not complete");
13108 return 0;
13109 }
13110
13111 snprintf(buf, sizeof(buf), "BSS %s", bssid);
13112 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
13113 strncmp(buf, "id=", 3) != 0) {
13114 send_resp(dut, conn, SIGMA_ERROR,
13115 "errorCode,Specified BSSID not found");
13116 return 0;
13117 }
13118
13119 pos = strstr(buf, "\nfreq=");
13120 if (!pos) {
13121 send_resp(dut, conn, SIGMA_ERROR,
13122 "errorCode,Channel not found");
13123 return 0;
13124 }
13125 freq = atoi(pos + 6);
13126 chan = freq_to_channel(freq);
13127
13128 pos = strstr(buf, "\nssid=");
13129 if (!pos) {
13130 send_resp(dut, conn, SIGMA_ERROR,
13131 "errorCode,SSID not found");
13132 return 0;
13133 }
13134 ssid = pos + 6;
13135 pos = strchr(ssid, '\n');
13136 if (pos)
13137 *pos = '\0';
13138 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
13139 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13140 return 0;
13141}
13142
13143
Jouni Malinenf7222712019-06-13 01:50:21 +030013144static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
13145 struct sigma_conn *conn,
13146 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013147{
13148#ifdef __linux__
13149 struct timeval tv;
13150 struct tm tm;
13151 time_t t;
13152 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013153 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013154
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013155 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013156
13157 memset(&tm, 0, sizeof(tm));
13158 val = get_param(cmd, "seconds");
13159 if (val)
13160 tm.tm_sec = atoi(val);
13161 val = get_param(cmd, "minutes");
13162 if (val)
13163 tm.tm_min = atoi(val);
13164 val = get_param(cmd, "hours");
13165 if (val)
13166 tm.tm_hour = atoi(val);
13167 val = get_param(cmd, "date");
13168 if (val)
13169 tm.tm_mday = atoi(val);
13170 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013171 if (val) {
13172 v = atoi(val);
13173 if (v < 1 || v > 12) {
13174 send_resp(dut, conn, SIGMA_INVALID,
13175 "errorCode,Invalid month");
13176 return 0;
13177 }
13178 tm.tm_mon = v - 1;
13179 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013180 val = get_param(cmd, "year");
13181 if (val) {
13182 int year = atoi(val);
13183#ifdef ANDROID
13184 if (year > 2035)
13185 year = 2035; /* years beyond 2035 not supported */
13186#endif /* ANDROID */
13187 tm.tm_year = year - 1900;
13188 }
13189 t = mktime(&tm);
13190 if (t == (time_t) -1) {
13191 send_resp(dut, conn, SIGMA_ERROR,
13192 "errorCode,Invalid date or time");
13193 return 0;
13194 }
13195
13196 memset(&tv, 0, sizeof(tv));
13197 tv.tv_sec = t;
13198
13199 if (settimeofday(&tv, NULL) < 0) {
13200 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
13201 strerror(errno));
13202 send_resp(dut, conn, SIGMA_ERROR,
13203 "errorCode,Failed to set time");
13204 return 0;
13205 }
13206
13207 return 1;
13208#endif /* __linux__ */
13209
13210 return -1;
13211}
13212
13213
Jouni Malinenf7222712019-06-13 01:50:21 +030013214static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
13215 struct sigma_conn *conn,
13216 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013217{
13218 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013219 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013220 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013221 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013222 int res;
13223 struct wpa_ctrl *ctrl;
13224
13225 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013226 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013227
13228 val = get_param(cmd, "ProdESSAssoc");
13229 if (val)
13230 prod_ess_assoc = atoi(val);
13231
13232 kill_dhcp_client(dut, intf);
13233 if (start_dhcp_client(dut, intf) < 0)
13234 return -2;
13235
13236 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
13237 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13238 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013239 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013240 prod_ess_assoc ? "" : "-N",
13241 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013242 name ? "'" : "",
13243 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
13244 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013245
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053013246 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013247 if (run_hs20_osu(dut, buf) < 0) {
13248 FILE *f;
13249
13250 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
13251
13252 f = fopen("hs20-osu-client.res", "r");
13253 if (f) {
13254 char resp[400], res[300], *pos;
13255 if (!fgets(res, sizeof(res), f))
13256 res[0] = '\0';
13257 pos = strchr(res, '\n');
13258 if (pos)
13259 *pos = '\0';
13260 fclose(f);
13261 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
13262 res);
13263 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
13264 if (system(resp) != 0) {
13265 }
13266 snprintf(resp, sizeof(resp),
13267 "SSID,,BSSID,,failureReason,%s", res);
13268 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13269 return 0;
13270 }
13271
13272 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13273 return 0;
13274 }
13275
13276 if (!prod_ess_assoc)
13277 goto report;
13278
13279 ctrl = open_wpa_mon(intf);
13280 if (ctrl == NULL) {
13281 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13282 "wpa_supplicant monitor connection");
13283 return -1;
13284 }
13285
13286 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13287 buf, sizeof(buf));
13288
13289 wpa_ctrl_detach(ctrl);
13290 wpa_ctrl_close(ctrl);
13291
13292 if (res < 0) {
13293 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
13294 "network after OSU");
13295 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13296 return 0;
13297 }
13298
13299report:
13300 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13301 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13302 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
13303 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13304 return 0;
13305 }
13306
13307 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
13308 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013309 return 0;
13310}
13311
13312
Jouni Malinenf7222712019-06-13 01:50:21 +030013313static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
13314 struct sigma_conn *conn,
13315 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013316{
13317 const char *val;
13318 int timeout = 120;
13319
13320 val = get_param(cmd, "PolicyUpdate");
13321 if (val == NULL || atoi(val) == 0)
13322 return 1; /* No operation requested */
13323
13324 val = get_param(cmd, "Timeout");
13325 if (val)
13326 timeout = atoi(val);
13327
13328 if (timeout) {
13329 /* TODO: time out the command and return
13330 * PolicyUpdateStatus,TIMEOUT if needed. */
13331 }
13332
13333 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
13334 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13335 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
13336 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
13337 return 0;
13338 }
13339
13340 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
13341 return 0;
13342}
13343
13344
Jouni Malinenf7222712019-06-13 01:50:21 +030013345static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
13346 struct sigma_conn *conn,
13347 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013348{
13349 struct wpa_ctrl *ctrl;
13350 const char *intf = get_param(cmd, "Interface");
13351 const char *bssid = get_param(cmd, "Bssid");
13352 const char *ssid = get_param(cmd, "SSID");
13353 const char *security = get_param(cmd, "Security");
13354 const char *passphrase = get_param(cmd, "Passphrase");
13355 const char *pin = get_param(cmd, "PIN");
13356 char buf[1000];
13357 char ssid_hex[200], passphrase_hex[200];
13358 const char *keymgmt, *cipher;
13359
13360 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013361 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013362
13363 if (!bssid) {
13364 send_resp(dut, conn, SIGMA_ERROR,
13365 "ErrorCode,Missing Bssid argument");
13366 return 0;
13367 }
13368
13369 if (!ssid) {
13370 send_resp(dut, conn, SIGMA_ERROR,
13371 "ErrorCode,Missing SSID argument");
13372 return 0;
13373 }
13374
13375 if (!security) {
13376 send_resp(dut, conn, SIGMA_ERROR,
13377 "ErrorCode,Missing Security argument");
13378 return 0;
13379 }
13380
13381 if (!passphrase) {
13382 send_resp(dut, conn, SIGMA_ERROR,
13383 "ErrorCode,Missing Passphrase argument");
13384 return 0;
13385 }
13386
13387 if (!pin) {
13388 send_resp(dut, conn, SIGMA_ERROR,
13389 "ErrorCode,Missing PIN argument");
13390 return 0;
13391 }
13392
vamsi krishna8c9c1562017-05-12 15:51:46 +053013393 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
13394 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013395 send_resp(dut, conn, SIGMA_ERROR,
13396 "ErrorCode,Too long SSID/passphrase");
13397 return 0;
13398 }
13399
13400 ctrl = open_wpa_mon(intf);
13401 if (ctrl == NULL) {
13402 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13403 "wpa_supplicant monitor connection");
13404 return -2;
13405 }
13406
13407 if (strcasecmp(security, "wpa2-psk") == 0) {
13408 keymgmt = "WPA2PSK";
13409 cipher = "CCMP";
13410 } else {
13411 wpa_ctrl_detach(ctrl);
13412 wpa_ctrl_close(ctrl);
13413 send_resp(dut, conn, SIGMA_ERROR,
13414 "ErrorCode,Unsupported Security value");
13415 return 0;
13416 }
13417
13418 ascii2hexstr(ssid, ssid_hex);
13419 ascii2hexstr(passphrase, passphrase_hex);
13420 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
13421 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
13422
13423 if (wpa_command(intf, buf) < 0) {
13424 wpa_ctrl_detach(ctrl);
13425 wpa_ctrl_close(ctrl);
13426 send_resp(dut, conn, SIGMA_ERROR,
13427 "ErrorCode,Failed to start registrar");
13428 return 0;
13429 }
13430
13431 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
13432 dut->er_oper_performed = 1;
13433
13434 return wps_connection_event(dut, conn, ctrl, intf, 0);
13435}
13436
13437
Jouni Malinenf7222712019-06-13 01:50:21 +030013438static enum sigma_cmd_result
13439cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
13440 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013441{
13442 struct wpa_ctrl *ctrl;
13443 const char *intf = get_param(cmd, "Interface");
13444 const char *bssid = get_param(cmd, "Bssid");
13445 char buf[100];
13446
13447 if (!bssid) {
13448 send_resp(dut, conn, SIGMA_ERROR,
13449 "ErrorCode,Missing Bssid argument");
13450 return 0;
13451 }
13452
13453 ctrl = open_wpa_mon(intf);
13454 if (ctrl == NULL) {
13455 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13456 "wpa_supplicant monitor connection");
13457 return -2;
13458 }
13459
13460 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
13461
13462 if (wpa_command(intf, buf) < 0) {
13463 wpa_ctrl_detach(ctrl);
13464 wpa_ctrl_close(ctrl);
13465 send_resp(dut, conn, SIGMA_ERROR,
13466 "ErrorCode,Failed to start registrar");
13467 return 0;
13468 }
13469
13470 return wps_connection_event(dut, conn, ctrl, intf, 0);
13471}
13472
13473
Jouni Malinenf7222712019-06-13 01:50:21 +030013474static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
13475 struct sigma_conn *conn,
13476 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053013477{
13478 struct wpa_ctrl *ctrl;
13479 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013480 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013481 const char *config_method = get_param(cmd, "WPSConfigMethod");
13482 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053013483 int res;
13484 char buf[256];
13485 const char *events[] = {
13486 "CTRL-EVENT-CONNECTED",
13487 "WPS-OVERLAP-DETECTED",
13488 "WPS-TIMEOUT",
13489 "WPS-FAIL",
13490 NULL
13491 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013492 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053013493
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013494 /* 60G WPS tests do not pass Interface parameter */
13495 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013496 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013497
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013498 if (dut->mode == SIGMA_MODE_AP)
13499 return ap_wps_registration(dut, conn, cmd);
13500
13501 if (config_method) {
13502 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
13503 * sta_wps_enter_pin before calling start_wps_registration. */
13504 if (strcasecmp(config_method, "PBC") == 0)
13505 dut->wps_method = WFA_CS_WPS_PBC;
13506 }
13507 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
13508 send_resp(dut, conn, SIGMA_ERROR,
13509 "ErrorCode,WPS parameters not yet set");
13510 return STATUS_SENT;
13511 }
13512
13513 /* Make sure WPS is enabled (also for STA mode) */
13514 dut->wps_disable = 0;
13515
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013516 if (dut->band == WPS_BAND_60G && network_mode &&
13517 strcasecmp(network_mode, "PBSS") == 0) {
13518 sigma_dut_print(dut, DUT_MSG_DEBUG,
13519 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013520 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013521 return -2;
13522 }
13523
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013524 if (dut->force_rsn_ie) {
13525 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
13526 dut->force_rsn_ie);
13527 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
13528 sigma_dut_print(dut, DUT_MSG_INFO,
13529 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020013530 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013531 }
13532 }
13533
vamsi krishna9b144002017-09-20 13:28:13 +053013534 ctrl = open_wpa_mon(intf);
13535 if (!ctrl) {
13536 sigma_dut_print(dut, DUT_MSG_ERROR,
13537 "Failed to open wpa_supplicant monitor connection");
13538 return -2;
13539 }
13540
13541 role = get_param(cmd, "WpsRole");
13542 if (!role) {
13543 send_resp(dut, conn, SIGMA_INVALID,
13544 "ErrorCode,WpsRole not provided");
13545 goto fail;
13546 }
13547
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013548 if (strcasecmp(role, "Enrollee") != 0) {
13549 /* Registrar role for STA not supported */
13550 send_resp(dut, conn, SIGMA_ERROR,
13551 "ErrorCode,Unsupported WpsRole value");
13552 goto fail;
13553 }
13554
13555 if (is_60g_sigma_dut(dut)) {
13556 if (dut->wps_method == WFA_CS_WPS_PBC)
13557 snprintf(buf, sizeof(buf), "WPS_PBC");
13558 else /* WFA_CS_WPS_PIN_KEYPAD */
13559 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
13560 dut->wps_pin);
13561 if (wpa_command(intf, buf) < 0) {
13562 send_resp(dut, conn, SIGMA_ERROR,
13563 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053013564 goto fail;
13565 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013566 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13567 if (res < 0) {
13568 send_resp(dut, conn, SIGMA_ERROR,
13569 "ErrorCode,WPS connection did not complete");
13570 goto fail;
13571 }
13572 if (strstr(buf, "WPS-TIMEOUT")) {
13573 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
13574 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13575 send_resp(dut, conn, SIGMA_COMPLETE,
13576 "WpsState,OverlapSession");
13577 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13578 send_resp(dut, conn, SIGMA_COMPLETE,
13579 "WpsState,Successful");
13580 } else {
13581 send_resp(dut, conn, SIGMA_COMPLETE,
13582 "WpsState,Failure");
13583 }
13584 } else {
13585 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053013586 if (wpa_command(intf, "WPS_PBC") < 0) {
13587 send_resp(dut, conn, SIGMA_ERROR,
13588 "ErrorCode,Failed to enable PBC");
13589 goto fail;
13590 }
13591 } else {
13592 /* TODO: PIN method */
13593 send_resp(dut, conn, SIGMA_ERROR,
13594 "ErrorCode,Unsupported WpsConfigMethod value");
13595 goto fail;
13596 }
13597 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13598 if (res < 0) {
13599 send_resp(dut, conn, SIGMA_ERROR,
13600 "ErrorCode,WPS connection did not complete");
13601 goto fail;
13602 }
13603 if (strstr(buf, "WPS-TIMEOUT")) {
13604 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
13605 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13606 send_resp(dut, conn, SIGMA_ERROR,
13607 "ErrorCode,OverlapSession");
13608 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13609 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
13610 } else {
13611 send_resp(dut, conn, SIGMA_ERROR,
13612 "ErrorCode,WPS operation failed");
13613 }
vamsi krishna9b144002017-09-20 13:28:13 +053013614 }
13615
13616fail:
13617 wpa_ctrl_detach(ctrl);
13618 wpa_ctrl_close(ctrl);
13619 return 0;
13620}
13621
13622
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013623static int req_intf(struct sigma_cmd *cmd)
13624{
13625 return get_param(cmd, "interface") == NULL ? -1 : 0;
13626}
13627
13628
13629void sta_register_cmds(void)
13630{
13631 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
13632 cmd_sta_get_ip_config);
13633 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
13634 cmd_sta_set_ip_config);
13635 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
13636 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
13637 cmd_sta_get_mac_address);
13638 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
13639 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
13640 cmd_sta_verify_ip_connection);
13641 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
13642 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
13643 cmd_sta_set_encryption);
13644 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
13645 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
13646 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
13647 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
13648 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
13649 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
13650 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
13651 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
13652 cmd_sta_set_eapakaprime);
13653 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
13654 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
13655 /* TODO: sta_set_ibss */
13656 /* TODO: sta_set_mode */
13657 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
13658 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
13659 /* TODO: sta_up_load */
13660 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
13661 cmd_sta_preset_testparameters);
13662 /* TODO: sta_set_system */
13663 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
13664 /* TODO: sta_set_rifs_test */
13665 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
13666 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
13667 /* TODO: sta_send_coexist_mgmt */
13668 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
13669 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
13670 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
13671 sigma_dut_reg_cmd("sta_reset_default", req_intf,
13672 cmd_sta_reset_default);
13673 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
13674 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
13675 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
13676 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
13677 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013678 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013679 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
13680 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
13681 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
13682 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
13683 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013684 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
13685 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013686 sigma_dut_reg_cmd("sta_add_credential", req_intf,
13687 cmd_sta_add_credential);
13688 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013689 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013690 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
13691 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
13692 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
13693 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
13694 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
13695 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030013696 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013697 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
13698 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013699 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053013700 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013701}