blob: 13d1727044711142dd41d60a270402ea53285f8c [file] [log] [blame]
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001/*
2 * Sigma Control API DUT (station/AP)
3 * Copyright (c) 2010-2011, Atheros Communications, Inc.
Jouni Malinen9d7e31d2017-12-22 18:55:04 +02004 * Copyright (c) 2011-2017, Qualcomm Atheros, Inc.
Jouni Malinenc12ea4a2018-01-05 21:07:10 +02005 * Copyright (c) 2018, The Linux Foundation
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006 * All Rights Reserved.
7 * Licensed under the Clear BSD license. See README for more details.
8 */
9
10#include "sigma_dut.h"
11#include <sys/ioctl.h>
12#include <sys/stat.h>
Jouni Malinen82905202018-04-29 17:20:10 +030013#include <sys/wait.h>
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030014#include <ctype.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015#ifdef __linux__
Lior Davidcc88b562017-01-03 18:52:09 +020016#include <regex.h>
17#include <dirent.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020018#include <sys/time.h>
19#include <netpacket/packet.h>
20#include <linux/if_ether.h>
21#ifdef ANDROID
22#include <cutils/properties.h>
23#include <android/log.h>
24#include "keystore_get.h"
25#else /* ANDROID */
26#include <ifaddrs.h>
27#endif /* ANDROID */
28#include <netdb.h>
29#endif /* __linux__ */
30#ifdef __QNXNTO__
31#include <net/if_dl.h>
32#endif /* __QNXNTO__ */
33#include "wpa_ctrl.h"
34#include "wpa_helpers.h"
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070035#include "miracast.h"
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070036#include "qca-vendor_copy.h"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020037
38/* Temporary files for sta_send_addba */
39#define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp"
40#define VI_QOS_FILE "/tmp/vi-qos.txt"
41#define VI_QOS_REFFILE "/etc/vi-qos.txt"
42
43/*
44 * MTU for Ethernet need to take into account 8-byte SNAP header
45 * to be added when encapsulating Ethernet frame into 802.11
46 */
47#ifndef IEEE80211_MAX_DATA_LEN_DMG
48#define IEEE80211_MAX_DATA_LEN_DMG 7920
49#endif
50#ifndef IEEE80211_SNAP_LEN_DMG
51#define IEEE80211_SNAP_LEN_DMG 8
52#endif
53
Ashwini Patil00402582017-04-13 12:29:39 +053054#define NON_PREF_CH_LIST_SIZE 100
Ashwini Patil5acd7382017-04-13 15:55:04 +053055#define NEIGHBOR_REPORT_SIZE 1000
56#define DEFAULT_NEIGHBOR_BSSID_INFO "17"
57#define DEFAULT_NEIGHBOR_PHY_TYPE "1"
Ashwini Patil00402582017-04-13 12:29:39 +053058
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030059#define WIL_DEFAULT_BI 100
60
61/* default remain on channel time for transmitting frames (milliseconds) */
62#define WIL_TRANSMIT_FRAME_DEFAULT_ROC 500
63#define IEEE80211_P2P_ATTR_DEVICE_ID 3
64#define IEEE80211_P2P_ATTR_GROUP_ID 15
65
66/* describes tagged bytes in template frame file */
67struct template_frame_tag {
68 int num;
69 int offset;
70 size_t len;
71};
72
Jouni Malinencd4e3c32015-10-29 12:39:56 +020073extern char *sigma_wpas_ctrl;
74extern char *sigma_cert_path;
75extern enum driver_type wifi_chip_type;
76extern char *sigma_radio_ifname[];
77
Lior David0fe101e2017-03-09 16:09:50 +020078#ifdef __linux__
79#define WIL_WMI_MAX_PAYLOAD 248
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020080#define WIL_WMI_ESE_CFG_CMDID 0xa01
Lior David0fe101e2017-03-09 16:09:50 +020081#define WIL_WMI_BF_TRIG_CMDID 0x83a
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020082#define WIL_WMI_UNIT_TEST_CMDID 0x900
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030083#define WIL_WMI_P2P_CFG_CMDID 0x910
84#define WIL_WMI_START_LISTEN_CMDID 0x914
85#define WIL_WMI_DISCOVERY_STOP_CMDID 0x917
Lior David0fe101e2017-03-09 16:09:50 +020086
87struct wil_wmi_header {
88 uint8_t mid;
89 uint8_t reserved;
90 uint16_t cmd;
91 uint32_t ts;
92} __attribute__((packed));
93
94enum wil_wmi_bf_trig_type {
95 WIL_WMI_SLS,
96 WIL_WMI_BRP_RX,
97 WIL_WMI_BRP_TX,
98};
99
100struct wil_wmi_bf_trig_cmd {
101 /* enum wil_wmi_bf_trig_type */
102 uint32_t bf_type;
103 /* cid when type == WMI_BRP_RX */
104 uint32_t sta_id;
105 uint32_t reserved;
106 /* mac address when type = WIL_WMI_SLS */
107 uint8_t dest_mac[6];
108} __attribute__((packed));
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200109
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200110enum wil_wmi_sched_scheme_advertisment {
111 WIL_WMI_ADVERTISE_ESE_DISABLED,
112 WIL_WMI_ADVERTISE_ESE_IN_BEACON,
113 WIL_WMI_ADVERTISE_ESE_IN_ANNOUNCE_FRAME,
114};
115
116enum wil_wmi_ese_slot_type {
117 WIL_WMI_ESE_SP,
118 WIL_WMI_ESE_CBAP,
119 WIL_WMI_ESE_ANNOUNCE_NO_ACK,
120};
121
122struct wil_wmi_ese_slot {
123 /* offset from start of BI in microseconds */
124 uint32_t tbtt_offset;
125 uint8_t flags;
126 /* enum wil_wmi_ese_slot_type */
127 uint8_t slot_type;
128 /* duration in microseconds */
129 uint16_t duration;
130 /* frame exchange sequence duration, microseconds */
131 uint16_t tx_op;
132 /* time between 2 blocks for periodic allocation(microseconds) */
133 uint16_t period;
134 /* number of blocks in periodic allocation */
135 uint8_t num_blocks;
136 /* for semi-active allocations */
137 uint8_t idle_period;
138 uint8_t src_aid;
139 uint8_t dst_aid;
140 uint32_t reserved;
141} __attribute__((packed));
142
143#define WIL_WMI_MAX_ESE_SLOTS 4
144struct wil_wmi_ese_cfg {
145 uint8_t serial_num;
146 /* wil_wmi_sched_scheme_advertisment */
147 uint8_t ese_advertisment;
148 uint16_t flags;
149 uint8_t num_allocs;
150 uint8_t reserved[3];
151 uint64_t start_tbtt;
152 /* allocations list */
153 struct wil_wmi_ese_slot slots[WIL_WMI_MAX_ESE_SLOTS];
154} __attribute__((packed));
155
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200156#define WIL_WMI_UT_FORCE_MCS 6
157struct wil_wmi_force_mcs {
158 /* WIL_WMI_UT_HW_SYSAPI */
159 uint16_t module_id;
160 /* WIL_WMI_UT_FORCE_MCS */
161 uint16_t subtype_id;
162 /* cid (ignored in oob_mode, affects all stations) */
163 uint32_t cid;
164 /* 1 to force MCS, 0 to restore default behavior */
165 uint32_t force_enable;
166 /* MCS index, 0-12 */
167 uint32_t mcs;
168} __attribute__((packed));
169
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200170#define WIL_WMI_UT_HW_SYSAPI 10
171#define WIL_WMI_UT_FORCE_RSN_IE 0x29
172struct wil_wmi_force_rsn_ie {
173 /* WIL_WMI_UT_HW_SYSAPI */
174 uint16_t module_id;
175 /* WIL_WMI_UT_FORCE_RSN_IE */
176 uint16_t subtype_id;
177 /* 0 = no change, 1 = remove if exists, 2 = add if does not exist */
178 uint32_t state;
179} __attribute__((packed));
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300180
181enum wil_wmi_discovery_mode {
182 WMI_DISCOVERY_MODE_NON_OFFLOAD,
183 WMI_DISCOVERY_MODE_OFFLOAD,
184 WMI_DISCOVERY_MODE_PEER2PEER,
185};
186
187struct wil_wmi_p2p_cfg_cmd {
188 /* enum wil_wmi_discovery_mode */
189 uint8_t discovery_mode;
190 /* 0-based (wireless channel - 1) */
191 uint8_t channel;
192 /* set to WIL_DEFAULT_BI */
193 uint16_t bcon_interval;
194} __attribute__((packed));
Lior David0fe101e2017-03-09 16:09:50 +0200195#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200196
197#ifdef ANDROID
198
199static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname);
200
201#define ANDROID_KEYSTORE_GET 'g'
202#define ANDROID_KEYSTORE_GET_PUBKEY 'b'
203
204static int android_keystore_get(char cmd, const char *key, unsigned char *val)
205{
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200206 /* Android 4.3 changed keystore design, so need to use keystore_get() */
207#ifndef KEYSTORE_MESSAGE_SIZE
208#define KEYSTORE_MESSAGE_SIZE 65535
209#endif /* KEYSTORE_MESSAGE_SIZE */
210
211 ssize_t len;
212 uint8_t *value = NULL;
213
214 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
215 "keystore command '%c' key '%s' --> keystore_get",
216 cmd, key);
217
218 len = keystore_get(key, strlen(key), &value);
219 if (len < 0) {
220 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
221 "keystore_get() failed");
222 return -1;
223 }
224
225 if (len > KEYSTORE_MESSAGE_SIZE)
226 len = KEYSTORE_MESSAGE_SIZE;
227 memcpy(val, value, len);
228 free(value);
229 return len;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200230}
231#endif /* ANDROID */
232
233
Vinita S. Maloo0fcb57d2020-04-24 14:03:56 +0530234#ifdef NL80211_SUPPORT
235static int nl80211_sta_set_power_save(struct sigma_dut *dut,
236 const char *intf,
237 enum nl80211_ps_state ps_state)
238{
239 struct nl_msg *msg;
240 int ifindex, ret;
241
242 ifindex = if_nametoindex(intf);
243 if (ifindex == 0) {
244 sigma_dut_print(dut, DUT_MSG_ERROR,
245 "%s: Index for interface %s not found",
246 __func__, intf);
247 return -1;
248 }
249
250 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
251 NL80211_CMD_SET_POWER_SAVE);
252 if (!msg) {
253 sigma_dut_print(dut, DUT_MSG_ERROR,
254 "%s: err in creating nl80211 msg", __func__);
255 return -1;
256 }
257
258 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) {
259 sigma_dut_print(dut, DUT_MSG_ERROR,
260 "%s: err in populating nl80211 msg", __func__);
261 nlmsg_free(msg);
262 return -1;
263 }
264
265 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
266 if (ret) {
267 sigma_dut_print(dut, DUT_MSG_ERROR,
268 "%s: err in send_and_recv_msgs, ret=%d (%s)",
269 __func__, ret, strerror(-ret));
270 return -1;
271 }
272
273 return 0;
274}
275#endif /* NL80211_SUPPORT */
276
277
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530278static int set_power_save_wcn(struct sigma_dut *dut, const char *intf, int ps)
279{
280 char buf[100];
Vinita S. Maloo0fcb57d2020-04-24 14:03:56 +0530281#ifdef NL80211_SUPPORT
282 enum nl80211_ps_state ps_state;
283
284 ps_state = ps == 1 ? NL80211_PS_ENABLED : NL80211_PS_DISABLED;
285 if (nl80211_sta_set_power_save(dut, intf, ps_state) == 0)
286 return 0;
287#endif /* NL80211_SUPPORT */
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530288
289 snprintf(buf, sizeof(buf), "iwpriv %s setPower %d", intf, ps);
290 if (system(buf) != 0) {
291 sigma_dut_print(dut, DUT_MSG_ERROR,
292 "iwpriv setPower %d failed", ps);
293 return -1;
294 }
295 return 0;
296}
297
298
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200299int set_ps(const char *intf, struct sigma_dut *dut, int enabled)
300{
301#ifdef __linux__
302 char buf[100];
303
304 if (wifi_chip_type == DRIVER_WCN) {
305 if (enabled) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530306 if (set_power_save_wcn(dut, intf, 1) < 0) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530307 snprintf(buf, sizeof(buf),
308 "iwpriv wlan0 dump 906");
309 if (system(buf) != 0)
310 goto set_power_save;
311 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200312 } else {
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530313 if (set_power_save_wcn(dut, intf, 2) < 0) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530314 snprintf(buf, sizeof(buf),
315 "iwpriv wlan0 dump 905");
316 if (system(buf) != 0)
317 goto set_power_save;
318 snprintf(buf, sizeof(buf),
319 "iwpriv wlan0 dump 912");
320 if (system(buf) != 0)
321 goto set_power_save;
322 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200323 }
324
325 return 0;
326 }
327
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530328set_power_save:
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200329 snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s",
330 intf, enabled ? "on" : "off");
331 if (system(buf) != 0) {
332 snprintf(buf, sizeof(buf), "iw dev %s set power_save %s",
333 intf, enabled ? "on" : "off");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530334 if (system(buf) != 0) {
335 sigma_dut_print(dut, DUT_MSG_ERROR,
336 "Failed to set power save %s",
337 enabled ? "on" : "off");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200338 return -1;
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530339 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200340 }
341
342 return 0;
343#else /* __linux__ */
344 return -1;
345#endif /* __linux__ */
346}
347
348
Lior Davidcc88b562017-01-03 18:52:09 +0200349#ifdef __linux__
Lior David0fe101e2017-03-09 16:09:50 +0200350
Lior Davidcc88b562017-01-03 18:52:09 +0200351static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path,
352 size_t len)
353{
354 DIR *dir, *wil_dir;
355 struct dirent *entry;
356 int ret = -1;
357 const char *root_path = "/sys/kernel/debug/ieee80211";
358
359 dir = opendir(root_path);
360 if (!dir)
361 return -2;
362
363 while ((entry = readdir(dir))) {
364 if (strcmp(entry->d_name, ".") == 0 ||
365 strcmp(entry->d_name, "..") == 0)
366 continue;
367
368 if (snprintf(path, len, "%s/%s/wil6210",
369 root_path, entry->d_name) >= (int) len) {
370 ret = -3;
371 break;
372 }
373
374 wil_dir = opendir(path);
375 if (wil_dir) {
376 closedir(wil_dir);
377 ret = 0;
378 break;
379 }
380 }
381
382 closedir(dir);
383 return ret;
384}
Lior David0fe101e2017-03-09 16:09:50 +0200385
386
387static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command,
388 void *payload, uint16_t length)
389{
390 struct {
391 struct wil_wmi_header hdr;
392 char payload[WIL_WMI_MAX_PAYLOAD];
393 } __attribute__((packed)) cmd;
394 char buf[128], fname[128];
395 size_t towrite, written;
396 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300397 int res;
Lior David0fe101e2017-03-09 16:09:50 +0200398
399 if (length > WIL_WMI_MAX_PAYLOAD) {
400 sigma_dut_print(dut, DUT_MSG_ERROR,
401 "payload too large(%u, max %u)",
402 length, WIL_WMI_MAX_PAYLOAD);
403 return -1;
404 }
405
406 memset(&cmd.hdr, 0, sizeof(cmd.hdr));
407 cmd.hdr.cmd = command;
408 memcpy(cmd.payload, payload, length);
409
410 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
411 sigma_dut_print(dut, DUT_MSG_ERROR,
412 "failed to get wil6210 debugfs dir");
413 return -1;
414 }
415
Jouni Malinen3aa72862019-05-29 23:14:51 +0300416 res = snprintf(fname, sizeof(fname), "%s/wmi_send", buf);
417 if (res < 0 || res >= sizeof(fname))
418 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200419 f = fopen(fname, "wb");
420 if (!f) {
421 sigma_dut_print(dut, DUT_MSG_ERROR,
422 "failed to open: %s", fname);
423 return -1;
424 }
425
426 towrite = sizeof(cmd.hdr) + length;
427 written = fwrite(&cmd, 1, towrite, f);
428 fclose(f);
429 if (written != towrite) {
430 sigma_dut_print(dut, DUT_MSG_ERROR,
431 "failed to send wmi %u", command);
432 return -1;
433 }
434
435 return 0;
436}
437
438
439static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid,
440 const char *pattern, unsigned int *field)
441{
442 char buf[128], fname[128];
443 FILE *f;
444 regex_t re;
445 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +0300446 int rc, ret = -1, res;
Lior David0fe101e2017-03-09 16:09:50 +0200447
448 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
449 sigma_dut_print(dut, DUT_MSG_ERROR,
450 "failed to get wil6210 debugfs dir");
451 return -1;
452 }
453
Jouni Malinen3aa72862019-05-29 23:14:51 +0300454 res = snprintf(fname, sizeof(fname), "%s/stations", buf);
455 if (res < 0 || res >= sizeof(fname))
456 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200457 f = fopen(fname, "r");
458 if (!f) {
459 sigma_dut_print(dut, DUT_MSG_ERROR,
460 "failed to open: %s", fname);
461 return -1;
462 }
463
464 if (regcomp(&re, pattern, REG_EXTENDED)) {
465 sigma_dut_print(dut, DUT_MSG_ERROR,
466 "regcomp failed: %s", pattern);
467 goto out;
468 }
469
470 /*
471 * find the entry for the mac address
472 * line is of the form: [n] 11:22:33:44:55:66 state AID aid
473 */
474 while (fgets(buf, sizeof(buf), f)) {
475 if (strcasestr(buf, bssid)) {
476 /* extract the field (CID/AID/state) */
477 rc = regexec(&re, buf, 2, m, 0);
478 if (!rc && (m[1].rm_so >= 0)) {
479 buf[m[1].rm_eo] = 0;
480 *field = atoi(&buf[m[1].rm_so]);
481 ret = 0;
482 break;
483 }
484 }
485 }
486
487 regfree(&re);
488 if (ret)
489 sigma_dut_print(dut, DUT_MSG_ERROR,
490 "could not extract field");
491
492out:
493 fclose(f);
494
495 return ret;
496}
497
498
499static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid,
500 unsigned int *cid)
501{
502 const char *pattern = "\\[([0-9]+)\\]";
503
504 return wil6210_get_sta_info_field(dut, bssid, pattern, cid);
505}
506
507
508static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac,
509 int l_rx)
510{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700511 struct wil_wmi_bf_trig_cmd cmd;
Lior David0fe101e2017-03-09 16:09:50 +0200512 unsigned int cid;
513
Rakesh Sunki556237d2017-03-30 14:49:31 -0700514 memset(&cmd, 0, sizeof(cmd));
515
Lior David0fe101e2017-03-09 16:09:50 +0200516 if (wil6210_get_cid(dut, mac, &cid))
517 return -1;
518
519 cmd.bf_type = WIL_WMI_BRP_RX;
520 cmd.sta_id = cid;
521 /* training length (l_rx) is ignored, FW always uses length 16 */
522 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
523 &cmd, sizeof(cmd));
524}
525
526
527static int wil6210_send_sls(struct sigma_dut *dut, const char *mac)
528{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700529 struct wil_wmi_bf_trig_cmd cmd;
530
531 memset(&cmd, 0, sizeof(cmd));
Lior David0fe101e2017-03-09 16:09:50 +0200532
533 if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac))
534 return -1;
535
536 cmd.bf_type = WIL_WMI_SLS;
537 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
538 &cmd, sizeof(cmd));
539}
540
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200541
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200542int wil6210_set_ese(struct sigma_dut *dut, int count,
543 struct sigma_ese_alloc *allocs)
544{
545 struct wil_wmi_ese_cfg cmd = { };
546 int i;
547
548 if (count == 0 || count > WIL_WMI_MAX_ESE_SLOTS)
549 return -1;
550
551 if (dut->ap_bcnint <= 0) {
552 sigma_dut_print(dut, DUT_MSG_ERROR,
553 "invalid beacon interval(%d), check test",
554 dut->ap_bcnint);
555 return -1;
556 }
557
558 cmd.ese_advertisment = WIL_WMI_ADVERTISE_ESE_IN_BEACON;
559 cmd.flags = 0x1d;
560 cmd.num_allocs = count;
561 for (i = 0; i < count; i++) {
562 /*
563 * Convert percent from BI (BI specified in milliseconds)
564 * to absolute duration in microseconds.
565 */
566 cmd.slots[i].duration =
567 (allocs[i].percent_bi * dut->ap_bcnint * 1000) / 100;
568 switch (allocs[i].type) {
569 case ESE_CBAP:
570 cmd.slots[i].slot_type = WIL_WMI_ESE_CBAP;
571 break;
572 case ESE_SP:
573 cmd.slots[i].slot_type = WIL_WMI_ESE_SP;
574 break;
575 default:
576 sigma_dut_print(dut, DUT_MSG_ERROR,
577 "invalid slot type(%d) at index %d",
578 allocs[i].type, i);
579 return -1;
580 }
581 cmd.slots[i].src_aid = allocs[i].src_aid;
582 cmd.slots[i].dst_aid = allocs[i].dst_aid;
583 sigma_dut_print(dut, DUT_MSG_INFO,
584 "slot %d, duration %u, type %d, srcAID %u dstAID %u",
585 i, cmd.slots[i].duration,
586 cmd.slots[i].slot_type, cmd.slots[i].src_aid,
587 cmd.slots[i].dst_aid);
588 }
589
590 return wil6210_wmi_send(dut, WIL_WMI_ESE_CFG_CMDID, &cmd, sizeof(cmd));
591}
592
593
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200594int wil6210_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
595{
596 struct wil_wmi_force_mcs cmd = { };
597
598 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
599 cmd.subtype_id = WIL_WMI_UT_FORCE_MCS;
600 cmd.force_enable = (uint32_t) force;
601 cmd.mcs = (uint32_t) mcs;
602
603 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
604 &cmd, sizeof(cmd));
605}
606
607
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200608static int wil6210_force_rsn_ie(struct sigma_dut *dut, int state)
609{
610 struct wil_wmi_force_rsn_ie cmd = { };
611
612 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
613 cmd.subtype_id = WIL_WMI_UT_FORCE_RSN_IE;
614 cmd.state = (uint32_t) state;
615
616 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
617 &cmd, sizeof(cmd));
618}
619
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300620
621/*
622 * this function is also used to configure generic remain-on-channel
623 */
624static int wil6210_p2p_cfg(struct sigma_dut *dut, int freq)
625{
626 struct wil_wmi_p2p_cfg_cmd cmd = { };
627 int channel = freq_to_channel(freq);
628
629 if (channel < 0)
630 return -1;
631 cmd.discovery_mode = WMI_DISCOVERY_MODE_NON_OFFLOAD;
632 cmd.channel = channel - 1;
633 cmd.bcon_interval = WIL_DEFAULT_BI;
634 cmd.discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER;
635
636 return wil6210_wmi_send(dut, WIL_WMI_P2P_CFG_CMDID,
637 &cmd, sizeof(cmd));
638}
639
640
641static int wil6210_remain_on_channel(struct sigma_dut *dut, int freq)
642{
643 int ret = wil6210_p2p_cfg(dut, freq);
644
645 if (ret)
646 return ret;
647
648 ret = wil6210_wmi_send(dut, WIL_WMI_START_LISTEN_CMDID, NULL, 0);
649 if (!ret) {
650 /*
651 * wait a bit to allow FW to setup the radio
652 * especially important if we switch channels
653 */
654 usleep(500000);
655 }
656
657 return ret;
658}
659
660
661static int wil6210_stop_discovery(struct sigma_dut *dut)
662{
663 return wil6210_wmi_send(dut, WIL_WMI_DISCOVERY_STOP_CMDID, NULL, 0);
664}
665
666
667static int wil6210_transmit_frame(struct sigma_dut *dut, int freq,
668 int wait_duration,
669 const char *frame, size_t frame_len)
670{
671 char buf[128], fname[128];
672 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300673 int res = 0, r;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300674 size_t written;
675
676 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
677 sigma_dut_print(dut, DUT_MSG_ERROR,
678 "failed to get wil6210 debugfs dir");
679 return -1;
680 }
Jouni Malinen3aa72862019-05-29 23:14:51 +0300681 r = snprintf(fname, sizeof(fname), "%s/tx_mgmt", buf);
682 if (r < 0 || r >= sizeof(fname))
683 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300684
685 if (wil6210_remain_on_channel(dut, freq)) {
686 sigma_dut_print(dut, DUT_MSG_ERROR,
687 "failed to listen on channel");
688 return -1;
689 }
690
691 f = fopen(fname, "wb");
692 if (!f) {
693 sigma_dut_print(dut, DUT_MSG_ERROR,
694 "failed to open: %s", fname);
695 res = -1;
696 goto out_stop;
697 }
698 written = fwrite(frame, 1, frame_len, f);
699 fclose(f);
700
701 if (written != frame_len) {
702 sigma_dut_print(dut, DUT_MSG_ERROR,
703 "failed to transmit frame (got %zd, expected %zd)",
704 written, frame_len);
705 res = -1;
706 goto out_stop;
707 }
708
709 usleep(wait_duration * 1000);
710
711out_stop:
712 wil6210_stop_discovery(dut);
713 return res;
714}
715
716
717static int find_template_frame_tag(struct template_frame_tag *tags,
718 int total_tags, int tag_num)
719{
720 int i;
721
722 for (i = 0; i < total_tags; i++) {
723 if (tag_num == tags[i].num)
724 return i;
725 }
726
727 return -1;
728}
729
730
731static int replace_p2p_attribute(struct sigma_dut *dut, char *buf, size_t len,
732 int id, const char *value, size_t val_len)
733{
734 struct wfa_p2p_attribute *attr = (struct wfa_p2p_attribute *) buf;
735
736 if (len < 3 + val_len) {
737 sigma_dut_print(dut, DUT_MSG_ERROR,
738 "not enough space to replace P2P attribute");
739 return -1;
740 }
741
742 if (attr->len != val_len) {
743 sigma_dut_print(dut, DUT_MSG_ERROR,
744 "attribute length mismatch (need %zu have %hu)",
745 val_len, attr->len);
746 return -1;
747 }
748
749 if (attr->id != id) {
750 sigma_dut_print(dut, DUT_MSG_ERROR,
751 "incorrect attribute id (expected %d actual %d)",
752 id, attr->id);
753 return -1;
754 }
755
756 memcpy(attr->variable, value, val_len);
757
758 return 0;
759}
760
761
762static int parse_template_frame_file(struct sigma_dut *dut, const char *fname,
763 char *buf, size_t *length,
764 struct template_frame_tag *tags,
765 size_t *num_tags)
766{
767 char line[512];
768 FILE *f;
769 size_t offset = 0, tag_index = 0;
770 int num, index;
771 int in_tag = 0, tag_num = 0, tag_offset = 0;
772
773 if (*length < sizeof(struct ieee80211_hdr_3addr)) {
774 sigma_dut_print(dut, DUT_MSG_ERROR,
775 "supplied buffer is too small");
776 return -1;
777 }
778
779 f = fopen(fname, "r");
780 if (!f) {
781 sigma_dut_print(dut, DUT_MSG_ERROR,
782 "failed to open template file %s", fname);
783 return -1;
784 }
785
786 /*
787 * template file format: lines beginning with # are comments and
788 * ignored.
789 * It is possible to tag bytes in the frame to make it easy
790 * to replace fields in the template, espcially if they appear
791 * in variable-sized sections (such as IEs)
792 * This is done by a line beginning with $NUM where NUM is an integer
793 * tag number. It can be followed by space(s) and comment.
794 * The next line is considered the tagged bytes. The parser will fill
795 * the tag number, offset and length of the tagged bytes.
796 * rest of the lines contain frame bytes as sequence of hex digits,
797 * 2 digits for each byte. Spaces are allowed between bytes.
798 * On bytes lines only hex digits and spaces are allowed
799 */
800 while (!feof(f)) {
801 if (!fgets(line, sizeof(line), f))
802 break;
803 index = 0;
804 while (isspace((unsigned char) line[index]))
805 index++;
806 if (!line[index] || line[index] == '#')
807 continue;
808 if (line[index] == '$') {
809 if (tags) {
810 index++;
811 tag_num = strtol(&line[index], NULL, 0);
812 tag_offset = offset;
813 in_tag = 1;
814 }
815 continue;
816 }
817 while (line[index]) {
818 if (isspace((unsigned char) line[index])) {
819 index++;
820 continue;
821 }
822 num = hex_byte(&line[index]);
823 if (num < 0)
824 break;
825 buf[offset++] = num;
826 if (offset == *length)
827 goto out;
828 index += 2;
829 }
830
831 if (in_tag) {
832 if (tag_index < *num_tags) {
833 tags[tag_index].num = tag_num;
834 tags[tag_index].offset = tag_offset;
835 tags[tag_index].len = offset - tag_offset;
836 tag_index++;
837 } else {
838 sigma_dut_print(dut, DUT_MSG_INFO,
839 "too many tags, tag ignored");
840 }
841 in_tag = 0;
842 }
843 }
844
845 if (num_tags)
846 *num_tags = tag_index;
847out:
848 fclose(f);
849 if (offset < sizeof(struct ieee80211_hdr_3addr)) {
850 sigma_dut_print(dut, DUT_MSG_ERROR,
851 "template frame is too small");
852 return -1;
853 }
854
855 *length = offset;
856 return 0;
857}
858
Lior Davidcc88b562017-01-03 18:52:09 +0200859#endif /* __linux__ */
860
861
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200862static void static_ip_file(int proto, const char *addr, const char *mask,
863 const char *gw)
864{
865 if (proto) {
866 FILE *f = fopen("static-ip", "w");
867 if (f) {
868 fprintf(f, "%d %s %s %s\n", proto, addr,
869 mask ? mask : "N/A",
870 gw ? gw : "N/A");
871 fclose(f);
872 }
873 } else {
874 unlink("static-ip");
875 }
876}
877
878
879static int send_neighbor_request(struct sigma_dut *dut, const char *intf,
880 const char *ssid)
881{
882#ifdef __linux__
883 char buf[100];
884
885 snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s",
886 intf, ssid);
887 sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf);
888
889 if (system(buf) != 0) {
890 sigma_dut_print(dut, DUT_MSG_ERROR,
891 "iwpriv neighbor request failed");
892 return -1;
893 }
894
895 sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send");
896
897 return 0;
898#else /* __linux__ */
899 return -1;
900#endif /* __linux__ */
901}
902
903
904static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf,
Ashwini Patil5acd7382017-04-13 15:55:04 +0530905 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200906{
Ashwini Patil5acd7382017-04-13 15:55:04 +0530907 const char *val;
908 int reason_code = 0;
909 char buf[1024];
910
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200911 /*
912 * In the earlier builds we used WNM_QUERY and in later
913 * builds used WNM_BSS_QUERY.
914 */
915
Ashwini Patil5acd7382017-04-13 15:55:04 +0530916 val = get_param(cmd, "BTMQuery_Reason_Code");
917 if (val)
918 reason_code = atoi(val);
919
920 val = get_param(cmd, "Cand_List");
921 if (val && atoi(val) == 1 && dut->btm_query_cand_list) {
922 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code,
923 dut->btm_query_cand_list);
924 free(dut->btm_query_cand_list);
925 dut->btm_query_cand_list = NULL;
926 } else {
927 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code);
928 }
929
930 if (wpa_command(intf, buf) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200931 sigma_dut_print(dut, DUT_MSG_ERROR,
932 "transition management query failed");
933 return -1;
934 }
935
936 sigma_dut_print(dut, DUT_MSG_DEBUG,
937 "transition management query sent");
938
939 return 0;
940}
941
942
943int is_ip_addr(const char *str)
944{
945 const char *pos = str;
946 struct in_addr addr;
947
948 while (*pos) {
949 if (*pos != '.' && (*pos < '0' || *pos > '9'))
950 return 0;
951 pos++;
952 }
953
954 return inet_aton(str, &addr);
955}
956
957
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200958int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
959 size_t buf_len)
960{
vamsi krishnaa11d0732018-05-16 12:19:48 +0530961 char tmp[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200962 char ip[16], mask[15], dns[16], sec_dns[16];
963 int is_dhcp = 0;
964 int s;
965#ifdef ANDROID
966 char prop[PROPERTY_VALUE_MAX];
vamsi krishnaa11d0732018-05-16 12:19:48 +0530967#else /* ANDROID */
968 FILE *f;
969#ifdef __linux__
970 const char *str_ps;
971#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200972#endif /* ANDROID */
973
974 ip[0] = '\0';
975 mask[0] = '\0';
976 dns[0] = '\0';
977 sec_dns[0] = '\0';
978
979 s = socket(PF_INET, SOCK_DGRAM, 0);
980 if (s >= 0) {
981 struct ifreq ifr;
982 struct sockaddr_in saddr;
983
984 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700985 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200986 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
987 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
988 "%s IP address: %s",
989 ifname, strerror(errno));
990 } else {
991 memcpy(&saddr, &ifr.ifr_addr,
992 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700993 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200994 }
995
996 if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) {
997 memcpy(&saddr, &ifr.ifr_addr,
998 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700999 strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001000 }
1001 close(s);
1002 }
1003
1004#ifdef ANDROID
1005 snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname);
1006 if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) {
1007 snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname);
1008 if (property_get(tmp, prop, NULL) != 0 &&
1009 strcmp(prop, "ok") == 0) {
1010 snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress",
1011 ifname);
1012 if (property_get(tmp, prop, NULL) != 0 &&
1013 strcmp(ip, prop) == 0)
1014 is_dhcp = 1;
1015 }
1016 }
1017
1018 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -07001019 if (property_get(tmp, prop, NULL) != 0)
1020 strlcpy(dns, prop, sizeof(dns));
1021 else if (property_get("net.dns1", prop, NULL) != 0)
1022 strlcpy(dns, prop, sizeof(dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001023
1024 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -07001025 if (property_get(tmp, prop, NULL) != 0)
1026 strlcpy(sec_dns, prop, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001027#else /* ANDROID */
1028#ifdef __linux__
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001029 if (get_driver_type(dut) == DRIVER_OPENWRT)
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301030 str_ps = "ps -w";
1031 else
1032 str_ps = "ps ax";
1033 snprintf(tmp, sizeof(tmp),
1034 "%s | grep dhclient | grep -v grep | grep -q %s",
1035 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001036 if (system(tmp) == 0)
1037 is_dhcp = 1;
1038 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301039 snprintf(tmp, sizeof(tmp),
1040 "%s | grep udhcpc | grep -v grep | grep -q %s",
1041 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001042 if (system(tmp) == 0)
1043 is_dhcp = 1;
1044 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301045 snprintf(tmp, sizeof(tmp),
1046 "%s | grep dhcpcd | grep -v grep | grep -q %s",
1047 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001048 if (system(tmp) == 0)
1049 is_dhcp = 1;
1050 }
1051 }
1052#endif /* __linux__ */
1053
1054 f = fopen("/etc/resolv.conf", "r");
1055 if (f) {
vamsi krishnaa11d0732018-05-16 12:19:48 +05301056 char *pos, *pos2;
1057
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001058 while (fgets(tmp, sizeof(tmp), f)) {
1059 if (strncmp(tmp, "nameserver", 10) != 0)
1060 continue;
1061 pos = tmp + 10;
1062 while (*pos == ' ' || *pos == '\t')
1063 pos++;
1064 pos2 = pos;
1065 while (*pos2) {
1066 if (*pos2 == '\n' || *pos2 == '\r') {
1067 *pos2 = '\0';
1068 break;
1069 }
1070 pos2++;
1071 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07001072 if (!dns[0])
1073 strlcpy(dns, pos, sizeof(dns));
1074 else if (!sec_dns[0])
1075 strlcpy(sec_dns, pos, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001076 }
1077 fclose(f);
1078 }
1079#endif /* ANDROID */
1080
1081 snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s",
1082 is_dhcp, ip, mask, dns);
1083 buf[buf_len - 1] = '\0';
1084
1085 return 0;
1086}
1087
1088
1089
1090
1091int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf,
1092 size_t buf_len)
1093{
1094#ifdef __linux__
1095#ifdef ANDROID
1096 char cmd[200], result[1000], *pos, *end;
1097 FILE *f;
1098 size_t len;
1099
1100 snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname);
1101 f = popen(cmd, "r");
1102 if (f == NULL)
1103 return -1;
1104 len = fread(result, 1, sizeof(result) - 1, f);
1105 pclose(f);
1106 if (len == 0)
1107 return -1;
1108 result[len] = '\0';
1109 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result);
1110
1111 pos = strstr(result, "inet6 ");
1112 if (pos == NULL)
1113 return -1;
1114 pos += 6;
1115 end = strchr(pos, ' ');
1116 if (end)
1117 *end = '\0';
1118 end = strchr(pos, '/');
1119 if (end)
1120 *end = '\0';
1121 snprintf(buf, buf_len, "ip,%s", pos);
1122 buf[buf_len - 1] = '\0';
1123 return 0;
1124#else /* ANDROID */
1125 struct ifaddrs *ifaddr, *ifa;
1126 int res, found = 0;
1127 char host[NI_MAXHOST];
1128
1129 if (getifaddrs(&ifaddr) < 0) {
1130 perror("getifaddrs");
1131 return -1;
1132 }
1133
1134 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
1135 if (strcasecmp(ifname, ifa->ifa_name) != 0)
1136 continue;
1137 if (ifa->ifa_addr == NULL ||
1138 ifa->ifa_addr->sa_family != AF_INET6)
1139 continue;
1140
1141 res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
1142 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
1143 if (res != 0) {
1144 sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s",
1145 gai_strerror(res));
1146 continue;
1147 }
1148 if (strncmp(host, "fe80::", 6) == 0)
1149 continue; /* skip link-local */
1150
1151 sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host);
1152 found = 1;
1153 break;
1154 }
1155
1156 freeifaddrs(ifaddr);
1157
1158 if (found) {
1159 char *pos;
1160 pos = strchr(host, '%');
1161 if (pos)
1162 *pos = '\0';
1163 snprintf(buf, buf_len, "ip,%s", host);
1164 buf[buf_len - 1] = '\0';
1165 return 0;
1166 }
1167
1168#endif /* ANDROID */
1169#endif /* __linux__ */
1170 return -1;
1171}
1172
1173
Jouni Malinenf7222712019-06-13 01:50:21 +03001174static enum sigma_cmd_result cmd_sta_get_ip_config(struct sigma_dut *dut,
1175 struct sigma_conn *conn,
1176 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001177{
1178 const char *intf = get_param(cmd, "Interface");
1179 const char *ifname;
1180 char buf[200];
1181 const char *val;
1182 int type = 1;
1183
1184 if (intf == NULL)
1185 return -1;
1186
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001187 if (strcmp(intf, get_main_ifname(dut)) == 0)
1188 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001189 else
1190 ifname = intf;
1191
1192 /*
1193 * UCC may assume the IP address to be available immediately after
1194 * association without trying to run sta_get_ip_config multiple times.
1195 * Sigma CAPI does not specify this command as a block command that
1196 * would wait for the address to become available, but to pass tests
1197 * more reliably, it looks like such a wait may be needed here.
1198 */
1199 if (wait_ip_addr(dut, ifname, 15) < 0) {
1200 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address "
1201 "for sta_get_ip_config");
1202 /*
1203 * Try to continue anyway since many UCC tests do not really
1204 * care about the return value from here..
1205 */
1206 }
1207
1208 val = get_param(cmd, "Type");
1209 if (val)
1210 type = atoi(val);
1211 if (type == 2 || dut->last_set_ip_config_ipv6) {
1212 int i;
1213
1214 /*
1215 * Since we do not have proper wait for IPv6 addresses, use a
1216 * fixed two second delay here as a workaround for UCC script
1217 * assuming IPv6 address is available when this command returns.
1218 * Some scripts did not use Type,2 properly for IPv6, so include
1219 * also the cases where the previous sta_set_ip_config indicated
1220 * use of IPv6.
1221 */
1222 sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address");
1223 for (i = 0; i < 10; i++) {
1224 sleep(1);
1225 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0)
1226 {
1227 sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address");
1228 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1229#ifdef ANDROID
1230 sigma_dut_print(dut, DUT_MSG_INFO,
1231 "Adding IPv6 rule on Android");
1232 add_ipv6_rule(dut, intf);
1233#endif /* ANDROID */
1234
1235 return 0;
1236 }
1237 }
1238 }
1239 if (type == 1) {
1240 if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0)
1241 return -2;
1242 } else if (type == 2) {
1243 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0)
1244 return -2;
1245 } else {
1246 send_resp(dut, conn, SIGMA_ERROR,
1247 "errorCode,Unsupported address type");
1248 return 0;
1249 }
1250
1251 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1252 return 0;
1253}
1254
1255
1256static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname)
1257{
1258#ifdef __linux__
1259 char buf[200];
1260 char path[128];
1261 struct stat s;
1262
1263#ifdef ANDROID
1264 snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname);
1265#else /* ANDROID */
1266 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname);
1267#endif /* ANDROID */
1268 if (stat(path, &s) == 0) {
1269 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1270 sigma_dut_print(dut, DUT_MSG_INFO,
1271 "Kill previous DHCP client: %s", buf);
1272 if (system(buf) != 0)
1273 sigma_dut_print(dut, DUT_MSG_INFO,
1274 "Failed to kill DHCP client");
1275 unlink(path);
1276 sleep(1);
1277 } else {
1278 snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname);
1279
1280 if (stat(path, &s) == 0) {
1281 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1282 sigma_dut_print(dut, DUT_MSG_INFO,
1283 "Kill previous DHCP client: %s", buf);
1284 if (system(buf) != 0)
1285 sigma_dut_print(dut, DUT_MSG_INFO,
1286 "Failed to kill DHCP client");
1287 unlink(path);
1288 sleep(1);
1289 }
1290 }
1291#endif /* __linux__ */
1292}
1293
1294
1295static int start_dhcp_client(struct sigma_dut *dut, const char *ifname)
1296{
1297#ifdef __linux__
1298 char buf[200];
1299
1300#ifdef ANDROID
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301301 if (access("/system/bin/dhcpcd", F_OK) != -1) {
1302 snprintf(buf, sizeof(buf),
1303 "/system/bin/dhcpcd -b %s", ifname);
1304 } else if (access("/system/bin/dhcptool", F_OK) != -1) {
1305 snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname);
Ankita Bajaj8454e5d2019-04-05 16:04:55 +05301306 } else if (access("/vendor/bin/dhcpcd", F_OK) != -1) {
1307 snprintf(buf, sizeof(buf), "/vendor/bin/dhcpcd -b %s", ifname);
1308 } else if (access("/vendor/bin/dhcptool", F_OK) != -1) {
1309 snprintf(buf, sizeof(buf), "/vendor/bin/dhcptool %s", ifname);
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301310 } else {
1311 sigma_dut_print(dut, DUT_MSG_ERROR,
1312 "DHCP client program missing");
1313 return 0;
1314 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001315#else /* ANDROID */
1316 snprintf(buf, sizeof(buf),
1317 "dhclient -nw -pf /var/run/dhclient-%s.pid %s",
1318 ifname, ifname);
1319#endif /* ANDROID */
1320 sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf);
1321 if (system(buf) != 0) {
1322 snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname);
1323 if (system(buf) != 0) {
1324 sigma_dut_print(dut, DUT_MSG_INFO,
1325 "Failed to start DHCP client");
1326#ifndef ANDROID
1327 return -1;
1328#endif /* ANDROID */
1329 }
1330 }
1331#endif /* __linux__ */
1332
1333 return 0;
1334}
1335
1336
1337static int clear_ip_addr(struct sigma_dut *dut, const char *ifname)
1338{
1339#ifdef __linux__
1340 char buf[200];
1341
1342 snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname);
1343 if (system(buf) != 0) {
1344 sigma_dut_print(dut, DUT_MSG_INFO,
1345 "Failed to clear IP addresses");
1346 return -1;
1347 }
1348#endif /* __linux__ */
1349
1350 return 0;
1351}
1352
1353
1354#ifdef ANDROID
1355static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname)
1356{
1357 char cmd[200], *result, *pos;
1358 FILE *fp;
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301359 int tableid;
1360 size_t len, result_len = 1000;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001361
1362 snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s",
1363 ifname);
1364 fp = popen(cmd, "r");
1365 if (fp == NULL)
1366 return -1;
1367
1368 result = malloc(result_len);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301369 if (result == NULL) {
1370 fclose(fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001371 return -1;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301372 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001373
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301374 len = fread(result, 1, result_len - 1, fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001375 fclose(fp);
1376
1377 if (len == 0) {
1378 free(result);
1379 return -1;
1380 }
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301381 result[len] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001382
1383 pos = strstr(result, "table ");
1384 if (pos == NULL) {
1385 free(result);
1386 return -1;
1387 }
1388
1389 pos += strlen("table ");
1390 tableid = atoi(pos);
1391 if (tableid != 0) {
1392 if (system("ip -6 rule del prio 22000") != 0) {
1393 /* ignore any error */
1394 }
1395 snprintf(cmd, sizeof(cmd),
1396 "ip -6 rule add from all lookup %d prio 22000",
1397 tableid);
1398 if (system(cmd) != 0) {
1399 sigma_dut_print(dut, DUT_MSG_INFO,
1400 "Failed to run %s", cmd);
1401 free(result);
1402 return -1;
1403 }
1404 } else {
1405 sigma_dut_print(dut, DUT_MSG_INFO,
1406 "No Valid Table Id found %s", pos);
1407 free(result);
1408 return -1;
1409 }
1410 free(result);
1411
1412 return 0;
1413}
1414#endif /* ANDROID */
1415
1416
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301417int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
1418 const char *ip, const char *mask)
1419{
1420 char buf[200];
1421
1422 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
1423 ifname, ip, mask);
1424 return system(buf) == 0;
1425}
1426
1427
1428int set_ipv4_gw(struct sigma_dut *dut, const char *gw)
1429{
1430 char buf[200];
1431
1432 if (!is_ip_addr(gw)) {
1433 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw);
1434 return -1;
1435 }
1436
1437 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
1438 if (!dut->no_ip_addr_set && system(buf) != 0) {
1439 snprintf(buf, sizeof(buf), "ip ro re default via %s",
1440 gw);
1441 if (system(buf) != 0)
1442 return 0;
1443 }
1444
1445 return 1;
1446}
1447
1448
Jouni Malinenf7222712019-06-13 01:50:21 +03001449static enum sigma_cmd_result cmd_sta_set_ip_config(struct sigma_dut *dut,
1450 struct sigma_conn *conn,
1451 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001452{
1453 const char *intf = get_param(cmd, "Interface");
1454 const char *ifname;
1455 char buf[200];
1456 const char *val, *ip, *mask, *gw;
1457 int type = 1;
1458
1459 if (intf == NULL)
1460 return -1;
1461
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001462 if (strcmp(intf, get_main_ifname(dut)) == 0)
1463 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001464 else
1465 ifname = intf;
1466
1467 if (if_nametoindex(ifname) == 0) {
1468 send_resp(dut, conn, SIGMA_ERROR,
1469 "ErrorCode,Unknown interface");
1470 return 0;
1471 }
1472
1473 val = get_param(cmd, "Type");
1474 if (val) {
1475 type = atoi(val);
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301476 if (type < 1 || type > 3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001477 send_resp(dut, conn, SIGMA_ERROR,
1478 "ErrorCode,Unsupported address type");
1479 return 0;
1480 }
1481 }
1482
1483 dut->last_set_ip_config_ipv6 = 0;
1484
1485 val = get_param(cmd, "dhcp");
1486 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
1487 static_ip_file(0, NULL, NULL, NULL);
1488#ifdef __linux__
1489 if (type == 2) {
1490 dut->last_set_ip_config_ipv6 = 1;
1491 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
1492 "stateless address autoconfiguration");
1493#ifdef ANDROID
1494 /*
1495 * This sleep is required as the assignment in case of
1496 * Android is taking time and is done by the kernel.
1497 * The subsequent ping for IPv6 is impacting HS20 test
1498 * case.
1499 */
1500 sleep(2);
1501 add_ipv6_rule(dut, intf);
1502#endif /* ANDROID */
1503 /* Assume this happens by default */
1504 return 1;
1505 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301506 if (type != 3) {
1507 kill_dhcp_client(dut, ifname);
1508 if (start_dhcp_client(dut, ifname) < 0)
1509 return -2;
1510 } else {
1511 sigma_dut_print(dut, DUT_MSG_DEBUG,
1512 "Using FILS HLP DHCPv4 Rapid Commit");
1513 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001514
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001515 return 1;
1516#endif /* __linux__ */
1517 return -2;
1518 }
1519
1520 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301521 if (!ip) {
1522 send_resp(dut, conn, SIGMA_INVALID,
1523 "ErrorCode,Missing IP address");
1524 return 0;
1525 }
1526
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001527 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301528 if (!mask) {
1529 send_resp(dut, conn, SIGMA_INVALID,
1530 "ErrorCode,Missing subnet mask");
1531 return 0;
1532 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001533
1534 if (type == 2) {
1535 int net = atoi(mask);
1536
1537 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
1538 return -1;
1539
1540 if (dut->no_ip_addr_set) {
1541 snprintf(buf, sizeof(buf),
1542 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
1543 ifname);
1544 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1545 if (system(buf) != 0) {
1546 sigma_dut_print(dut, DUT_MSG_DEBUG,
1547 "Failed to disable IPv6 address before association");
1548 }
1549 } else {
Veerendranath Jakkam176181c2020-05-16 00:19:21 +05301550 if (set_ipv6_addr(dut, ip, mask, ifname) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001551 send_resp(dut, conn, SIGMA_ERROR,
1552 "ErrorCode,Failed to set IPv6 address");
1553 return 0;
1554 }
1555 }
1556
1557 dut->last_set_ip_config_ipv6 = 1;
1558 static_ip_file(6, ip, mask, NULL);
1559 return 1;
1560 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301561 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001562 return -1;
1563 }
1564
1565 kill_dhcp_client(dut, ifname);
1566
1567 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301568 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001569 send_resp(dut, conn, SIGMA_ERROR,
1570 "ErrorCode,Failed to set IP address");
1571 return 0;
1572 }
1573 }
1574
1575 gw = get_param(cmd, "defaultGateway");
1576 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301577 if (set_ipv4_gw(dut, gw) < 1) {
1578 send_resp(dut, conn, SIGMA_ERROR,
1579 "ErrorCode,Failed to set default gateway");
1580 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001581 }
1582 }
1583
1584 val = get_param(cmd, "primary-dns");
1585 if (val) {
1586 /* TODO */
1587 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1588 "setting", val);
1589 }
1590
1591 val = get_param(cmd, "secondary-dns");
1592 if (val) {
1593 /* TODO */
1594 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1595 "setting", val);
1596 }
1597
1598 static_ip_file(4, ip, mask, gw);
1599
1600 return 1;
1601}
1602
1603
Jouni Malinenf7222712019-06-13 01:50:21 +03001604static enum sigma_cmd_result cmd_sta_get_info(struct sigma_dut *dut,
1605 struct sigma_conn *conn,
1606 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001607{
1608 /* const char *intf = get_param(cmd, "Interface"); */
1609 /* TODO: could report more details here */
1610 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1611 return 0;
1612}
1613
1614
Jouni Malinenf7222712019-06-13 01:50:21 +03001615static enum sigma_cmd_result cmd_sta_get_mac_address(struct sigma_dut *dut,
1616 struct sigma_conn *conn,
1617 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001618{
1619 /* const char *intf = get_param(cmd, "Interface"); */
1620 char addr[20], resp[50];
1621
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301622 if (dut->dev_role == DEVROLE_STA_CFON)
1623 return sta_cfon_get_mac_address(dut, conn, cmd);
1624
Jouni Malinen9540e012019-11-05 17:08:42 +02001625 start_sta_mode(dut);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001626 if (get_wpa_status(get_station_ifname(dut), "address",
1627 addr, sizeof(addr)) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001628 return -2;
1629
1630 snprintf(resp, sizeof(resp), "mac,%s", addr);
1631 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1632 return 0;
1633}
1634
1635
Jouni Malinenf7222712019-06-13 01:50:21 +03001636static enum sigma_cmd_result cmd_sta_is_connected(struct sigma_dut *dut,
1637 struct sigma_conn *conn,
1638 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001639{
1640 /* const char *intf = get_param(cmd, "Interface"); */
1641 int connected = 0;
1642 char result[32];
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001643 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001644 sizeof(result)) < 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001645 sigma_dut_print(dut, DUT_MSG_INFO,
1646 "Could not get interface %s status",
1647 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001648 return -2;
1649 }
1650
1651 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1652 if (strncmp(result, "COMPLETED", 9) == 0)
1653 connected = 1;
1654
1655 if (connected)
1656 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1657 else
1658 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1659
1660 return 0;
1661}
1662
1663
Jouni Malinenf7222712019-06-13 01:50:21 +03001664static enum sigma_cmd_result
1665cmd_sta_verify_ip_connection(struct sigma_dut *dut, struct sigma_conn *conn,
1666 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001667{
1668 /* const char *intf = get_param(cmd, "Interface"); */
1669 const char *dst, *timeout;
1670 int wait_time = 90;
1671 char buf[100];
1672 int res;
1673
1674 dst = get_param(cmd, "destination");
1675 if (dst == NULL || !is_ip_addr(dst))
1676 return -1;
1677
1678 timeout = get_param(cmd, "timeout");
1679 if (timeout) {
1680 wait_time = atoi(timeout);
1681 if (wait_time < 1)
1682 wait_time = 1;
1683 }
1684
1685 /* TODO: force renewal of IP lease if DHCP is enabled */
1686
1687 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1688 res = system(buf);
1689 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1690 if (res == 0)
1691 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1692 else if (res == 256)
1693 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1694 else
1695 return -2;
1696
1697 return 0;
1698}
1699
1700
Jouni Malinenf7222712019-06-13 01:50:21 +03001701static enum sigma_cmd_result cmd_sta_get_bssid(struct sigma_dut *dut,
1702 struct sigma_conn *conn,
1703 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001704{
1705 /* const char *intf = get_param(cmd, "Interface"); */
1706 char bssid[20], resp[50];
1707
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001708 if (get_wpa_status(get_station_ifname(dut), "bssid",
1709 bssid, sizeof(bssid)) < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001710 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001711
1712 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1713 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1714 return 0;
1715}
1716
1717
1718#ifdef __SAMSUNG__
1719static int add_use_network(const char *ifname)
1720{
1721 char buf[100];
1722
1723 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1724 wpa_command(ifname, buf);
1725 return 0;
1726}
1727#endif /* __SAMSUNG__ */
1728
1729
1730static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1731 const char *ifname, struct sigma_cmd *cmd)
1732{
1733 const char *ssid = get_param(cmd, "ssid");
1734 int id;
1735 const char *val;
1736
1737 if (ssid == NULL)
1738 return -1;
1739
1740 start_sta_mode(dut);
1741
1742#ifdef __SAMSUNG__
1743 add_use_network(ifname);
1744#endif /* __SAMSUNG__ */
1745
1746 id = add_network(ifname);
1747 if (id < 0)
1748 return -2;
1749 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1750
1751 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1752 return -2;
1753
1754 dut->infra_network_id = id;
1755 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1756
1757 val = get_param(cmd, "program");
1758 if (!val)
1759 val = get_param(cmd, "prog");
1760 if (val && strcasecmp(val, "hs2") == 0) {
1761 char buf[100];
1762 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1763 wpa_command(ifname, buf);
1764
1765 val = get_param(cmd, "prefer");
1766 if (val && atoi(val) > 0)
1767 set_network(ifname, id, "priority", "1");
1768 }
1769
1770 return id;
1771}
1772
1773
Jouni Malinenf7222712019-06-13 01:50:21 +03001774static enum sigma_cmd_result cmd_sta_set_encryption(struct sigma_dut *dut,
1775 struct sigma_conn *conn,
1776 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001777{
1778 const char *intf = get_param(cmd, "Interface");
1779 const char *ssid = get_param(cmd, "ssid");
1780 const char *type = get_param(cmd, "encpType");
1781 const char *ifname;
1782 char buf[200];
1783 int id;
1784
1785 if (intf == NULL || ssid == NULL)
1786 return -1;
1787
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001788 if (strcmp(intf, get_main_ifname(dut)) == 0)
1789 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001790 else
1791 ifname = intf;
1792
1793 id = add_network_common(dut, conn, ifname, cmd);
1794 if (id < 0)
1795 return id;
1796
1797 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1798 return -2;
1799
1800 if (type && strcasecmp(type, "wep") == 0) {
1801 const char *val;
1802 int i;
1803
1804 val = get_param(cmd, "activeKey");
1805 if (val) {
1806 int keyid;
1807 keyid = atoi(val);
1808 if (keyid < 1 || keyid > 4)
1809 return -1;
1810 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1811 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1812 return -2;
1813 }
1814
1815 for (i = 0; i < 4; i++) {
1816 snprintf(buf, sizeof(buf), "key%d", i + 1);
1817 val = get_param(cmd, buf);
1818 if (val == NULL)
1819 continue;
1820 snprintf(buf, sizeof(buf), "wep_key%d", i);
1821 if (set_network(ifname, id, buf, val) < 0)
1822 return -2;
1823 }
1824 }
1825
1826 return 1;
1827}
1828
1829
Jouni Malinene4fde732019-03-25 22:29:37 +02001830static int set_akm_suites(struct sigma_dut *dut, const char *ifname,
1831 int id, const char *val)
1832{
1833 char key_mgmt[200], *end, *pos;
1834 const char *in_pos = val;
1835
Jouni Malinen8179fee2019-03-28 03:19:47 +02001836 dut->akm_values = 0;
Jouni Malinene4fde732019-03-25 22:29:37 +02001837 pos = key_mgmt;
1838 end = pos + sizeof(key_mgmt);
1839 while (*in_pos) {
1840 int res, akm = atoi(in_pos);
1841 const char *str;
1842
Jouni Malinen8179fee2019-03-28 03:19:47 +02001843 if (akm >= 0 && akm < 32)
1844 dut->akm_values |= 1 << akm;
1845
Jouni Malinene4fde732019-03-25 22:29:37 +02001846 switch (akm) {
1847 case AKM_WPA_EAP:
1848 str = "WPA-EAP";
1849 break;
1850 case AKM_WPA_PSK:
1851 str = "WPA-PSK";
1852 break;
1853 case AKM_FT_EAP:
1854 str = "FT-EAP";
1855 break;
1856 case AKM_FT_PSK:
1857 str = "FT-PSK";
1858 break;
1859 case AKM_EAP_SHA256:
1860 str = "WPA-EAP-SHA256";
1861 break;
1862 case AKM_PSK_SHA256:
1863 str = "WPA-PSK-SHA256";
1864 break;
1865 case AKM_SAE:
1866 str = "SAE";
1867 break;
1868 case AKM_FT_SAE:
1869 str = "FT-SAE";
1870 break;
1871 case AKM_SUITE_B:
1872 str = "WPA-EAP-SUITE-B-192";
1873 break;
1874 case AKM_FT_SUITE_B:
1875 str = "FT-EAP-SHA384";
1876 break;
1877 case AKM_FILS_SHA256:
1878 str = "FILS-SHA256";
1879 break;
1880 case AKM_FILS_SHA384:
1881 str = "FILS-SHA384";
1882 break;
1883 case AKM_FT_FILS_SHA256:
1884 str = "FT-FILS-SHA256";
1885 break;
1886 case AKM_FT_FILS_SHA384:
1887 str = "FT-FILS-SHA384";
1888 break;
1889 default:
1890 sigma_dut_print(dut, DUT_MSG_ERROR,
1891 "Unsupported AKMSuitetype %d", akm);
1892 return -1;
1893 }
1894
1895 res = snprintf(pos, end - pos, "%s%s",
1896 pos == key_mgmt ? "" : " ", str);
1897 if (res < 0 || res >= end - pos)
1898 return -1;
1899 pos += res;
1900
1901 in_pos = strchr(in_pos, ';');
1902 if (!in_pos)
1903 break;
1904 while (*in_pos == ';')
1905 in_pos++;
1906 }
1907 sigma_dut_print(dut, DUT_MSG_DEBUG, "AKMSuiteType %s --> %s",
1908 val, key_mgmt);
1909 return set_network(ifname, id, "key_mgmt", key_mgmt);
1910}
1911
1912
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001913static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1914 const char *ifname, struct sigma_cmd *cmd)
1915{
1916 const char *val;
1917 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001918 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001919 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301920 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001921
1922 id = add_network_common(dut, conn, ifname, cmd);
1923 if (id < 0)
1924 return id;
1925
Jouni Malinen47dcc952017-10-09 16:43:24 +03001926 val = get_param(cmd, "Type");
1927 owe = val && strcasecmp(val, "OWE") == 0;
1928
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001929 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001930 if (!val && owe)
1931 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001932 if (val == NULL) {
Jouni Malinene4fde732019-03-25 22:29:37 +02001933 /* keyMgmtType is being replaced with AKMSuiteType, so ignore
1934 * this missing parameter and assume proto=WPA2. */
1935 if (set_network(ifname, id, "proto", "WPA2") < 0)
1936 return ERROR_SEND_STATUS;
1937 } else if (strcasecmp(val, "wpa") == 0 ||
1938 strcasecmp(val, "wpa-psk") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001939 if (set_network(ifname, id, "proto", "WPA") < 0)
1940 return -2;
1941 } else if (strcasecmp(val, "wpa2") == 0 ||
1942 strcasecmp(val, "wpa2-psk") == 0 ||
1943 strcasecmp(val, "wpa2-ft") == 0 ||
1944 strcasecmp(val, "wpa2-sha256") == 0) {
1945 if (set_network(ifname, id, "proto", "WPA2") < 0)
1946 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301947 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1948 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001949 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1950 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001951 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301952 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001953 if (set_network(ifname, id, "proto", "WPA2") < 0)
1954 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001955 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001956 } else {
1957 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1958 return 0;
1959 }
1960
1961 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001962 if (val) {
1963 cipher_set = 1;
1964 if (strcasecmp(val, "tkip") == 0) {
1965 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1966 return -2;
1967 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1968 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1969 return -2;
1970 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1971 if (set_network(ifname, id, "pairwise",
1972 "CCMP TKIP") < 0)
1973 return -2;
1974 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1975 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1976 return -2;
1977 if (set_network(ifname, id, "group", "GCMP") < 0)
1978 return -2;
1979 } else {
1980 send_resp(dut, conn, SIGMA_ERROR,
1981 "errorCode,Unrecognized encpType value");
1982 return 0;
1983 }
1984 }
1985
1986 val = get_param(cmd, "PairwiseCipher");
1987 if (val) {
1988 cipher_set = 1;
1989 /* TODO: Support space separated list */
1990 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1991 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
1992 return -2;
1993 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1994 if (set_network(ifname, id, "pairwise",
1995 "CCMP-256") < 0)
1996 return -2;
1997 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1998 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1999 return -2;
2000 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2001 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
2002 return -2;
2003 } else {
2004 send_resp(dut, conn, SIGMA_ERROR,
2005 "errorCode,Unrecognized PairwiseCipher value");
2006 return 0;
2007 }
2008 }
2009
Jouni Malinen47dcc952017-10-09 16:43:24 +03002010 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03002011 send_resp(dut, conn, SIGMA_ERROR,
2012 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002013 return 0;
2014 }
Jouni Malinenad395a22017-09-01 21:13:46 +03002015
2016 val = get_param(cmd, "GroupCipher");
2017 if (val) {
2018 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2019 if (set_network(ifname, id, "group", "GCMP-256") < 0)
2020 return -2;
2021 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2022 if (set_network(ifname, id, "group", "CCMP-256") < 0)
2023 return -2;
2024 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2025 if (set_network(ifname, id, "group", "GCMP") < 0)
2026 return -2;
2027 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2028 if (set_network(ifname, id, "group", "CCMP") < 0)
2029 return -2;
2030 } else {
2031 send_resp(dut, conn, SIGMA_ERROR,
2032 "errorCode,Unrecognized GroupCipher value");
2033 return 0;
2034 }
2035 }
2036
Jouni Malinen7b239522017-09-14 21:37:18 +03002037 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03002038 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03002039 const char *cipher;
2040
2041 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
2042 cipher = "BIP-GMAC-256";
2043 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
2044 cipher = "BIP-CMAC-256";
2045 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
2046 cipher = "BIP-GMAC-128";
2047 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
2048 cipher = "AES-128-CMAC";
2049 } else {
2050 send_resp(dut, conn, SIGMA_INVALID,
2051 "errorCode,Unsupported GroupMgntCipher");
2052 return 0;
2053 }
2054 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
2055 send_resp(dut, conn, SIGMA_INVALID,
2056 "errorCode,Failed to set GroupMgntCipher");
2057 return 0;
2058 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002059 }
2060
Jouni Malinene4fde732019-03-25 22:29:37 +02002061 val = get_param(cmd, "AKMSuiteType");
2062 if (val && set_akm_suites(dut, ifname, id, val) < 0)
2063 return ERROR_SEND_STATUS;
2064
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002065 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302066
2067 if (dut->program == PROGRAM_OCE) {
2068 dut->sta_pmf = STA_PMF_OPTIONAL;
2069 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2070 return -2;
2071 }
2072
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002073 val = get_param(cmd, "PMF");
2074 if (val) {
2075 if (strcasecmp(val, "Required") == 0 ||
2076 strcasecmp(val, "Forced_Required") == 0) {
2077 dut->sta_pmf = STA_PMF_REQUIRED;
2078 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2079 return -2;
2080 } else if (strcasecmp(val, "Optional") == 0) {
2081 dut->sta_pmf = STA_PMF_OPTIONAL;
2082 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2083 return -2;
2084 } else if (strcasecmp(val, "Disabled") == 0 ||
Kiran Kumar Lokere07da3b22018-12-16 22:42:49 -08002085 strcasecmp(val, "Disable") == 0 ||
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002086 strcasecmp(val, "Forced_Disabled") == 0) {
2087 dut->sta_pmf = STA_PMF_DISABLED;
2088 } else {
2089 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
2090 return 0;
2091 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05302092 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02002093 dut->sta_pmf = STA_PMF_REQUIRED;
2094 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2095 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002096 }
2097
Jouni Malinen0165c7f2020-03-26 11:51:58 +02002098 val = get_param(cmd, "BeaconProtection");
2099 if (val && atoi(val) == 1 &&
2100 set_network(ifname, id, "beacon_prot", "1") < 0)
2101 return ERROR_SEND_STATUS;
2102
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002103 return id;
2104}
2105
2106
Jouni Malinenf7222712019-06-13 01:50:21 +03002107static enum sigma_cmd_result cmd_sta_set_psk(struct sigma_dut *dut,
2108 struct sigma_conn *conn,
2109 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002110{
2111 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002112 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002113 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002114 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002115 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002116 const char *ifname, *val, *alg;
2117 int id;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002118 char buf[50];
Jouni Malinen11e55212019-11-22 21:46:59 +02002119 int sae_pwe = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002120
2121 if (intf == NULL)
2122 return -1;
2123
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002124 if (strcmp(intf, get_main_ifname(dut)) == 0)
2125 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002126 else
2127 ifname = intf;
2128
2129 id = set_wpa_common(dut, conn, ifname, cmd);
2130 if (id < 0)
2131 return id;
2132
2133 val = get_param(cmd, "keyMgmtType");
2134 alg = get_param(cmd, "micAlg");
2135
Jouni Malinen992a81e2017-08-22 13:57:47 +03002136 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002137 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002138 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2139 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002140 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002141 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2142 return -2;
2143 }
2144 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2145 sigma_dut_print(dut, DUT_MSG_ERROR,
2146 "Failed to clear sae_groups to default");
2147 return -2;
2148 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002149 if (!pmf) {
2150 dut->sta_pmf = STA_PMF_REQUIRED;
2151 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2152 return -2;
2153 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002154 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2155 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2156 if (set_network(ifname, id, "key_mgmt",
2157 "FT-SAE FT-PSK") < 0)
2158 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002159 } else if (!akm) {
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002160 if (set_network(ifname, id, "key_mgmt",
2161 "SAE WPA-PSK") < 0)
2162 return -2;
2163 }
2164 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2165 sigma_dut_print(dut, DUT_MSG_ERROR,
2166 "Failed to clear sae_groups to default");
2167 return -2;
2168 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002169 if (!pmf) {
2170 dut->sta_pmf = STA_PMF_OPTIONAL;
2171 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2172 return -2;
2173 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002174 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002175 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2176 return -2;
2177 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2178 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2179 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302180 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2181 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2182 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002183 } else if (!akm &&
2184 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2185 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002186 if (set_network(ifname, id, "key_mgmt",
2187 "WPA-PSK WPA-PSK-SHA256") < 0)
2188 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002189 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002190 if (set_network(ifname, id, "key_mgmt",
2191 "WPA-PSK WPA-PSK-SHA256") < 0)
2192 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002193 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002194 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2195 return -2;
2196 }
2197
2198 val = get_param(cmd, "passPhrase");
2199 if (val == NULL)
2200 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002201 if (type && strcasecmp(type, "SAE") == 0) {
2202 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2203 return -2;
2204 } else {
2205 if (set_network_quoted(ifname, id, "psk", val) < 0)
2206 return -2;
2207 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002208
Jouni Malinen78d10c42019-03-25 22:34:32 +02002209 val = get_param(cmd, "PasswordId");
2210 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2211 return ERROR_SEND_STATUS;
2212
Jouni Malinen992a81e2017-08-22 13:57:47 +03002213 val = get_param(cmd, "ECGroupID");
2214 if (val) {
Jouni Malinenb54f0df2019-12-12 01:57:29 +02002215 snprintf(buf, sizeof(buf), "SET sae_groups %s", val);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002216 if (wpa_command(ifname, buf) != 0) {
2217 sigma_dut_print(dut, DUT_MSG_ERROR,
2218 "Failed to clear sae_groups");
2219 return -2;
2220 }
2221 }
2222
Jouni Malinen68143132017-09-02 02:34:08 +03002223 val = get_param(cmd, "InvalidSAEElement");
2224 if (val) {
2225 free(dut->sae_commit_override);
2226 dut->sae_commit_override = strdup(val);
2227 }
2228
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002229 val = get_param(cmd, "PMKID_Include");
2230 if (val) {
2231 snprintf(buf, sizeof(buf), "SET sae_pmkid_in_assoc %d",
2232 get_enable_disable(val));
2233 wpa_command(intf, buf);
2234 }
2235
Jouni Malineneeb43d32019-12-06 17:40:07 +02002236 val = get_param(cmd, "IgnoreH2E_RSNXE_BSSMemSel");
2237 if (val) {
2238 snprintf(buf, sizeof(buf), "SET ignore_sae_h2e_only %d",
2239 get_enable_disable(val));
2240 wpa_command(intf, buf);
2241 }
2242
Jouni Malinenf2348d22019-12-07 11:52:55 +02002243 val = get_param(cmd, "ECGroupID_RGE");
2244 if (val) {
2245 snprintf(buf, sizeof(buf), "SET extra_sae_rejected_groups %s",
2246 val);
2247 wpa_command(intf, buf);
2248 }
2249
Jouni Malinen99e55022019-12-07 13:59:41 +02002250 val = get_param(cmd, "RSNXE_Content");
2251 if (val) {
2252 const char *param;
2253
2254 if (strncasecmp(val, "AssocReq:", 9) == 0) {
2255 val += 9;
2256 param = "rsnxe_override_assoc";
2257 } else if (strncasecmp(val, "EapolM2:", 8) == 0) {
2258 val += 8;
2259 param = "rsnxe_override_eapol";
2260 } else {
2261 send_resp(dut, conn, SIGMA_ERROR,
2262 "errorCode,Unsupported RSNXE_Content value");
2263 return STATUS_SENT_ERROR;
2264 }
2265 snprintf(buf, sizeof(buf), "SET %s %s", param, val);
2266 wpa_command(intf, buf);
2267 }
2268
Jouni Malinen11e55212019-11-22 21:46:59 +02002269 val = get_param(cmd, "sae_pwe");
2270 if (val) {
2271 if (strcasecmp(val, "h2e") == 0) {
2272 dut->sae_pwe = SAE_PWE_H2E;
Jouni Malinen7244a412019-12-07 11:54:10 +02002273 } else if (strcasecmp(val, "loop") == 0 ||
2274 strcasecmp(val, "looping") == 0) {
Jouni Malinen11e55212019-11-22 21:46:59 +02002275 dut->sae_pwe = SAE_PWE_LOOP;
2276 } else {
2277 send_resp(dut, conn, SIGMA_ERROR,
2278 "errorCode,Unsupported sae_pwe value");
2279 return STATUS_SENT_ERROR;
2280 }
2281 }
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302282
2283 val = get_param(cmd, "Clear_RSNXE");
2284 if (val && strcmp(val, "1") == 0 &&
2285 (wpa_command(intf, "SET rsnxe_override_assoc ") ||
2286 wpa_command(intf, "SET rsnxe_override_eapol "))) {
2287 send_resp(dut, conn, SIGMA_ERROR,
2288 "errorCode,Failed to clear RSNXE");
Jouni Malinenb11498c2020-08-03 11:05:53 +03002289 return STATUS_SENT_ERROR;
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302290 }
2291
Jouni Malinenc0078772020-03-04 21:23:16 +02002292 if (dut->sae_pwe == SAE_PWE_LOOP && get_param(cmd, "PasswordId"))
2293 sae_pwe = 3;
2294 else if (dut->sae_pwe == SAE_PWE_LOOP)
Jouni Malinen11e55212019-11-22 21:46:59 +02002295 sae_pwe = 0;
2296 else if (dut->sae_pwe == SAE_PWE_H2E)
2297 sae_pwe = 1;
2298 else if (dut->sae_h2e_default)
2299 sae_pwe = 2;
2300 snprintf(buf, sizeof(buf), "SET sae_pwe %d", sae_pwe);
2301 if (sae_pwe >= 0 && wpa_command(ifname, buf) != 0)
2302 return ERROR_SEND_STATUS;
2303
Veerendranath Jakkam0316be12020-06-23 20:11:41 +05302304 val = get_param(cmd, "sae_pk");
2305 if (val && strcmp(val, "0") == 0 &&
2306 set_network(ifname, id, "sae_pk", "2") < 0)
2307 return ERROR_SEND_STATUS;
2308
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002309 if (dut->program == PROGRAM_60GHZ && network_mode &&
2310 strcasecmp(network_mode, "PBSS") == 0 &&
2311 set_network(ifname, id, "pbss", "1") < 0)
2312 return -2;
2313
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002314 return 1;
2315}
2316
2317
Jouni Malinen8ac93452019-08-14 15:19:13 +03002318static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2319 struct sigma_conn *conn,
2320 const char *ifname, int id)
2321{
2322 char buf[200];
2323
2324 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2325 if (!file_exists(buf))
2326 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2327 if (!file_exists(buf))
2328 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2329 if (!file_exists(buf)) {
2330 char msg[300];
2331
2332 snprintf(msg, sizeof(msg),
2333 "ErrorCode,trustedRootCA system store (%s) not found",
2334 buf);
2335 send_resp(dut, conn, SIGMA_ERROR, msg);
2336 return STATUS_SENT_ERROR;
2337 }
2338
2339 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2340 return ERROR_SEND_STATUS;
2341
2342 return SUCCESS_SEND_STATUS;
2343}
2344
2345
2346static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2347 struct sigma_conn *conn,
2348 const char *ifname, int id,
2349 const char *val)
2350{
2351 char buf[200];
2352#ifdef ANDROID
2353 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2354 int length;
2355#endif /* ANDROID */
2356
2357 if (strcmp(val, "DEFAULT") == 0)
2358 return set_trust_root_system(dut, conn, ifname, id);
2359
2360#ifdef ANDROID
2361 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2362 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2363 if (length > 0) {
2364 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2365 buf);
2366 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2367 goto ca_cert_selected;
2368 }
2369#endif /* ANDROID */
2370
2371 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2372#ifdef __linux__
2373 if (!file_exists(buf)) {
2374 char msg[300];
2375
2376 snprintf(msg, sizeof(msg),
2377 "ErrorCode,trustedRootCA file (%s) not found", buf);
2378 send_resp(dut, conn, SIGMA_ERROR, msg);
2379 return STATUS_SENT_ERROR;
2380 }
2381#endif /* __linux__ */
2382#ifdef ANDROID
2383ca_cert_selected:
2384#endif /* ANDROID */
2385 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2386 return ERROR_SEND_STATUS;
2387
2388 return SUCCESS_SEND_STATUS;
2389}
2390
2391
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002392static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302393 const char *ifname, int username_identity,
2394 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002395{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002396 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002397 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002398 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002399 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002400 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002401
2402 id = set_wpa_common(dut, conn, ifname, cmd);
2403 if (id < 0)
2404 return id;
2405
2406 val = get_param(cmd, "keyMgmtType");
2407 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302408 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002409 trust_root = get_param(cmd, "trustedRootCA");
2410 domain = get_param(cmd, "Domain");
2411 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002412
Jouni Malinenad395a22017-09-01 21:13:46 +03002413 if (val && strcasecmp(val, "SuiteB") == 0) {
2414 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2415 0)
2416 return -2;
2417 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002418 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2419 return -2;
2420 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2421 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2422 return -2;
2423 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2424 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2425 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002426 } else if (!akm &&
2427 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2428 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002429 if (set_network(ifname, id, "key_mgmt",
2430 "WPA-EAP WPA-EAP-SHA256") < 0)
2431 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302432 } else if (akm && atoi(akm) == 14) {
2433 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2434 dut->sta_pmf == STA_PMF_REQUIRED) {
2435 if (set_network(ifname, id, "key_mgmt",
2436 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2437 return -2;
2438 } else {
2439 if (set_network(ifname, id, "key_mgmt",
2440 "WPA-EAP FILS-SHA256") < 0)
2441 return -2;
2442 }
2443
Jouni Malinen8179fee2019-03-28 03:19:47 +02002444 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302445 } else if (akm && atoi(akm) == 15) {
2446 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2447 dut->sta_pmf == STA_PMF_REQUIRED) {
2448 if (set_network(ifname, id, "key_mgmt",
2449 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2450 return -2;
2451 } else {
2452 if (set_network(ifname, id, "key_mgmt",
2453 "WPA-EAP FILS-SHA384") < 0)
2454 return -2;
2455 }
2456
Jouni Malinen8179fee2019-03-28 03:19:47 +02002457 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002458 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002459 if (set_network(ifname, id, "key_mgmt",
2460 "WPA-EAP WPA-EAP-SHA256") < 0)
2461 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002462 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002463 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2464 return -2;
2465 }
2466
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002467 if (trust_root) {
2468 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2469 !domain_suffix) {
2470 send_resp(dut, conn, SIGMA_ERROR,
2471 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2472 return STATUS_SENT_ERROR;
2473 }
2474 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002475 if (res != SUCCESS_SEND_STATUS)
2476 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002477 }
2478
Jouni Malinen53264f62019-05-03 13:04:40 +03002479 val = get_param(cmd, "ServerCert");
2480 if (val) {
2481 FILE *f;
2482 char *result = NULL, *pos;
2483
2484 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2485 val);
2486 f = fopen(buf, "r");
2487 if (f) {
2488 result = fgets(buf, sizeof(buf), f);
2489 fclose(f);
2490 }
2491 if (!result) {
2492 snprintf(buf2, sizeof(buf2),
2493 "ErrorCode,ServerCert hash could not be read from %s",
2494 buf);
2495 send_resp(dut, conn, SIGMA_ERROR, buf2);
2496 return STATUS_SENT_ERROR;
2497 }
2498 pos = strchr(buf, '\n');
2499 if (pos)
2500 *pos = '\0';
2501 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2502 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2503 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002504
2505 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2506 if (file_exists(buf)) {
2507 sigma_dut_print(dut, DUT_MSG_DEBUG,
2508 "TOD policy enabled for the configured ServerCert hash");
2509 dut->sta_tod_policy = 1;
2510 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002511 }
2512
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002513 if (domain &&
2514 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002515 return ERROR_SEND_STATUS;
2516
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002517 if (domain_suffix &&
2518 set_network_quoted(ifname, id, "domain_suffix_match",
2519 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002520 return ERROR_SEND_STATUS;
2521
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302522 if (username_identity) {
2523 val = get_param(cmd, "username");
2524 if (val) {
2525 if (set_network_quoted(ifname, id, "identity", val) < 0)
2526 return -2;
2527 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002528
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302529 val = get_param(cmd, "password");
2530 if (val) {
2531 if (set_network_quoted(ifname, id, "password", val) < 0)
2532 return -2;
2533 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002534 }
2535
Jouni Malinen8179fee2019-03-28 03:19:47 +02002536 if (dut->akm_values &
2537 ((1 << AKM_FILS_SHA256) |
2538 (1 << AKM_FILS_SHA384) |
2539 (1 << AKM_FT_FILS_SHA256) |
2540 (1 << AKM_FT_FILS_SHA384)))
2541 erp = 1;
2542 if (erp && set_network(ifname, id, "erp", "1") < 0)
2543 return ERROR_SEND_STATUS;
2544
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002545 dut->sta_associate_wait_connect = 1;
2546
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002547 return id;
2548}
2549
2550
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002551static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2552{
2553 const char *val;
2554
2555 if (!cipher)
2556 return 0;
2557
2558 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2559 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2560 else if (strcasecmp(cipher,
2561 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2562 val = "ECDHE-RSA-AES256-GCM-SHA384";
2563 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2564 val = "DHE-RSA-AES256-GCM-SHA384";
2565 else if (strcasecmp(cipher,
2566 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2567 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2568 else
2569 return -1;
2570
2571 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2572 set_network_quoted(ifname, id, "phase1", "");
2573
2574 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2575}
2576
2577
Jouni Malinenf7222712019-06-13 01:50:21 +03002578static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2579 struct sigma_conn *conn,
2580 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002581{
2582 const char *intf = get_param(cmd, "Interface");
2583 const char *ifname, *val;
2584 int id;
2585 char buf[200];
2586#ifdef ANDROID
2587 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2588 int length;
2589 int jb_or_newer = 0;
2590 char prop[PROPERTY_VALUE_MAX];
2591#endif /* ANDROID */
2592
2593 if (intf == NULL)
2594 return -1;
2595
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002596 if (strcmp(intf, get_main_ifname(dut)) == 0)
2597 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002598 else
2599 ifname = intf;
2600
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302601 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002602 if (id < 0)
2603 return id;
2604
2605 if (set_network(ifname, id, "eap", "TLS") < 0)
2606 return -2;
2607
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302608 if (!get_param(cmd, "username") &&
2609 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002610 "wifi-user@wifilabs.local") < 0)
2611 return -2;
2612
2613 val = get_param(cmd, "clientCertificate");
2614 if (val == NULL)
2615 return -1;
2616#ifdef ANDROID
2617 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2618 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2619 if (length < 0) {
2620 /*
2621 * JB started reporting keystore type mismatches, so retry with
2622 * the GET_PUBKEY command if the generic GET fails.
2623 */
2624 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2625 buf, kvalue);
2626 }
2627
2628 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2629 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2630 if (strncmp(prop, "4.0", 3) != 0)
2631 jb_or_newer = 1;
2632 } else
2633 jb_or_newer = 1; /* assume newer */
2634
2635 if (jb_or_newer && length > 0) {
2636 sigma_dut_print(dut, DUT_MSG_INFO,
2637 "Use Android keystore [%s]", buf);
2638 if (set_network(ifname, id, "engine", "1") < 0)
2639 return -2;
2640 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2641 return -2;
2642 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2643 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2644 return -2;
2645 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2646 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2647 return -2;
2648 return 1;
2649 } else if (length > 0) {
2650 sigma_dut_print(dut, DUT_MSG_INFO,
2651 "Use Android keystore [%s]", buf);
2652 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2653 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2654 return -2;
2655 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2656 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2657 return -2;
2658 return 1;
2659 }
2660#endif /* ANDROID */
2661
2662 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2663#ifdef __linux__
2664 if (!file_exists(buf)) {
2665 char msg[300];
2666 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2667 "(%s) not found", buf);
2668 send_resp(dut, conn, SIGMA_ERROR, msg);
2669 return -3;
2670 }
2671#endif /* __linux__ */
2672 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2673 return -2;
2674 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2675 return -2;
2676
2677 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2678 return -2;
2679
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002680 val = get_param(cmd, "keyMgmtType");
2681 if (val && strcasecmp(val, "SuiteB") == 0) {
2682 val = get_param(cmd, "CertType");
2683 if (val && strcasecmp(val, "RSA") == 0) {
2684 if (set_network_quoted(ifname, id, "phase1",
2685 "tls_suiteb=1") < 0)
2686 return -2;
2687 } else {
2688 if (set_network_quoted(ifname, id, "openssl_ciphers",
2689 "SUITEB192") < 0)
2690 return -2;
2691 }
2692
2693 val = get_param(cmd, "TLSCipher");
2694 if (set_tls_cipher(ifname, id, val) < 0) {
2695 send_resp(dut, conn, SIGMA_ERROR,
2696 "ErrorCode,Unsupported TLSCipher value");
2697 return -3;
2698 }
2699 }
2700
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002701 return 1;
2702}
2703
2704
Jouni Malinenf7222712019-06-13 01:50:21 +03002705static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2706 struct sigma_conn *conn,
2707 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002708{
2709 const char *intf = get_param(cmd, "Interface");
2710 const char *ifname;
2711 int id;
2712
2713 if (intf == NULL)
2714 return -1;
2715
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002716 if (strcmp(intf, get_main_ifname(dut)) == 0)
2717 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002718 else
2719 ifname = intf;
2720
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302721 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002722 if (id < 0)
2723 return id;
2724
2725 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2726 send_resp(dut, conn, SIGMA_ERROR,
2727 "errorCode,Failed to set TTLS method");
2728 return 0;
2729 }
2730
2731 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2732 send_resp(dut, conn, SIGMA_ERROR,
2733 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2734 return 0;
2735 }
2736
2737 return 1;
2738}
2739
2740
Jouni Malinenf7222712019-06-13 01:50:21 +03002741static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2742 struct sigma_conn *conn,
2743 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002744{
2745 const char *intf = get_param(cmd, "Interface");
2746 const char *ifname;
2747 int id;
2748
2749 if (intf == NULL)
2750 return -1;
2751
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002752 if (strcmp(intf, get_main_ifname(dut)) == 0)
2753 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002754 else
2755 ifname = intf;
2756
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302757 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002758 if (id < 0)
2759 return id;
2760
2761 if (set_network(ifname, id, "eap", "SIM") < 0)
2762 return -2;
2763
2764 return 1;
2765}
2766
2767
Jouni Malinenf7222712019-06-13 01:50:21 +03002768static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2769 struct sigma_conn *conn,
2770 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002771{
2772 const char *intf = get_param(cmd, "Interface");
2773 const char *ifname, *val;
2774 int id;
2775 char buf[100];
2776
2777 if (intf == NULL)
2778 return -1;
2779
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002780 if (strcmp(intf, get_main_ifname(dut)) == 0)
2781 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002782 else
2783 ifname = intf;
2784
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302785 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002786 if (id < 0)
2787 return id;
2788
2789 if (set_network(ifname, id, "eap", "PEAP") < 0)
2790 return -2;
2791
2792 val = get_param(cmd, "innerEAP");
2793 if (val) {
2794 if (strcasecmp(val, "MSCHAPv2") == 0) {
2795 if (set_network_quoted(ifname, id, "phase2",
2796 "auth=MSCHAPV2") < 0)
2797 return -2;
2798 } else if (strcasecmp(val, "GTC") == 0) {
2799 if (set_network_quoted(ifname, id, "phase2",
2800 "auth=GTC") < 0)
2801 return -2;
2802 } else
2803 return -1;
2804 }
2805
2806 val = get_param(cmd, "peapVersion");
2807 if (val) {
2808 int ver = atoi(val);
2809 if (ver < 0 || ver > 1)
2810 return -1;
2811 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2812 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2813 return -2;
2814 }
2815
2816 return 1;
2817}
2818
2819
Jouni Malinenf7222712019-06-13 01:50:21 +03002820static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2821 struct sigma_conn *conn,
2822 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002823{
2824 const char *intf = get_param(cmd, "Interface");
2825 const char *ifname, *val;
2826 int id;
2827 char buf[100];
2828
2829 if (intf == NULL)
2830 return -1;
2831
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002832 if (strcmp(intf, get_main_ifname(dut)) == 0)
2833 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002834 else
2835 ifname = intf;
2836
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302837 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002838 if (id < 0)
2839 return id;
2840
2841 if (set_network(ifname, id, "eap", "FAST") < 0)
2842 return -2;
2843
2844 val = get_param(cmd, "innerEAP");
2845 if (val) {
2846 if (strcasecmp(val, "MSCHAPV2") == 0) {
2847 if (set_network_quoted(ifname, id, "phase2",
2848 "auth=MSCHAPV2") < 0)
2849 return -2;
2850 } else if (strcasecmp(val, "GTC") == 0) {
2851 if (set_network_quoted(ifname, id, "phase2",
2852 "auth=GTC") < 0)
2853 return -2;
2854 } else
2855 return -1;
2856 }
2857
2858 val = get_param(cmd, "validateServer");
2859 if (val) {
2860 /* TODO */
2861 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2862 "validateServer=%s", val);
2863 }
2864
2865 val = get_param(cmd, "pacFile");
2866 if (val) {
2867 snprintf(buf, sizeof(buf), "blob://%s", val);
2868 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2869 return -2;
2870 }
2871
2872 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2873 0)
2874 return -2;
2875
2876 return 1;
2877}
2878
2879
Jouni Malinenf7222712019-06-13 01:50:21 +03002880static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2881 struct sigma_conn *conn,
2882 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002883{
2884 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302885 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002886 const char *ifname;
2887 int id;
2888
2889 if (intf == NULL)
2890 return -1;
2891
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002892 if (strcmp(intf, get_main_ifname(dut)) == 0)
2893 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002894 else
2895 ifname = intf;
2896
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302897 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002898 if (id < 0)
2899 return id;
2900
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302901 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2902 * hexadecimal).
2903 */
2904 if (username && username[0] == '6') {
2905 if (set_network(ifname, id, "eap", "AKA'") < 0)
2906 return -2;
2907 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002908 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302909 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002910
2911 return 1;
2912}
2913
2914
Jouni Malinenf7222712019-06-13 01:50:21 +03002915static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2916 struct sigma_conn *conn,
2917 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002918{
2919 const char *intf = get_param(cmd, "Interface");
2920 const char *ifname;
2921 int id;
2922
2923 if (intf == NULL)
2924 return -1;
2925
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002926 if (strcmp(intf, get_main_ifname(dut)) == 0)
2927 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002928 else
2929 ifname = intf;
2930
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302931 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002932 if (id < 0)
2933 return id;
2934
2935 if (set_network(ifname, id, "eap", "AKA'") < 0)
2936 return -2;
2937
2938 return 1;
2939}
2940
2941
2942static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2943 struct sigma_cmd *cmd)
2944{
2945 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002946 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002947 const char *ifname;
2948 int id;
2949
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002950 if (strcmp(intf, get_main_ifname(dut)) == 0)
2951 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002952 else
2953 ifname = intf;
2954
2955 id = add_network_common(dut, conn, ifname, cmd);
2956 if (id < 0)
2957 return id;
2958
2959 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2960 return -2;
2961
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002962 if (dut->program == PROGRAM_60GHZ && network_mode &&
2963 strcasecmp(network_mode, "PBSS") == 0 &&
2964 set_network(ifname, id, "pbss", "1") < 0)
2965 return -2;
2966
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002967 return 1;
2968}
2969
2970
Jouni Malinen47dcc952017-10-09 16:43:24 +03002971static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2972 struct sigma_cmd *cmd)
2973{
2974 const char *intf = get_param(cmd, "Interface");
2975 const char *ifname, *val;
2976 int id;
2977
2978 if (intf == NULL)
2979 return -1;
2980
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002981 if (strcmp(intf, get_main_ifname(dut)) == 0)
2982 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002983 else
2984 ifname = intf;
2985
2986 id = set_wpa_common(dut, conn, ifname, cmd);
2987 if (id < 0)
2988 return id;
2989
2990 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
2991 return -2;
2992
2993 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03002994 if (val && strcmp(val, "0") == 0) {
2995 if (wpa_command(ifname,
2996 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
2997 sigma_dut_print(dut, DUT_MSG_ERROR,
2998 "Failed to set OWE DH Param element override");
2999 return -2;
3000 }
Hu Wang6010ce72020-03-05 19:33:53 +08003001 } else if (val &&
3002 (set_network(ifname, id, "owe_group", val) < 0 ||
3003 (dut->owe_ptk_workaround &&
3004 set_network(ifname, id, "owe_ptk_workaround", "1") < 0))) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003005 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003006 "Failed to set owe_group");
Jouni Malinen47dcc952017-10-09 16:43:24 +03003007 return -2;
3008 }
3009
3010 return 1;
3011}
3012
3013
Jouni Malinenf7222712019-06-13 01:50:21 +03003014static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3015 struct sigma_conn *conn,
3016 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003017{
3018 const char *type = get_param(cmd, "Type");
3019
3020 if (type == NULL) {
3021 send_resp(dut, conn, SIGMA_ERROR,
3022 "ErrorCode,Missing Type argument");
3023 return 0;
3024 }
3025
3026 if (strcasecmp(type, "OPEN") == 0)
3027 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003028 if (strcasecmp(type, "OWE") == 0)
3029 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003030 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003031 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003032 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003033 return cmd_sta_set_psk(dut, conn, cmd);
3034 if (strcasecmp(type, "EAPTLS") == 0)
3035 return cmd_sta_set_eaptls(dut, conn, cmd);
3036 if (strcasecmp(type, "EAPTTLS") == 0)
3037 return cmd_sta_set_eapttls(dut, conn, cmd);
3038 if (strcasecmp(type, "EAPPEAP") == 0)
3039 return cmd_sta_set_peap(dut, conn, cmd);
3040 if (strcasecmp(type, "EAPSIM") == 0)
3041 return cmd_sta_set_eapsim(dut, conn, cmd);
3042 if (strcasecmp(type, "EAPFAST") == 0)
3043 return cmd_sta_set_eapfast(dut, conn, cmd);
3044 if (strcasecmp(type, "EAPAKA") == 0)
3045 return cmd_sta_set_eapaka(dut, conn, cmd);
3046 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3047 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003048 if (strcasecmp(type, "wep") == 0)
3049 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003050
3051 send_resp(dut, conn, SIGMA_ERROR,
3052 "ErrorCode,Unsupported Type value");
3053 return 0;
3054}
3055
3056
3057int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3058{
3059#ifdef __linux__
3060 /* special handling for ath6kl */
3061 char path[128], fname[128], *pos;
3062 ssize_t res;
3063 FILE *f;
3064
Jouni Malinene39cd562019-05-29 23:39:56 +03003065 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3066 intf);
3067 if (res < 0 || res >= sizeof(fname))
3068 return 0;
3069 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003070 if (res < 0)
3071 return 0; /* not ath6kl */
3072
3073 if (res >= (int) sizeof(path))
3074 res = sizeof(path) - 1;
3075 path[res] = '\0';
3076 pos = strrchr(path, '/');
3077 if (pos == NULL)
3078 pos = path;
3079 else
3080 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003081 res = snprintf(fname, sizeof(fname),
3082 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3083 "create_qos", pos);
3084 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003085 return 0; /* not ath6kl */
3086
3087 if (uapsd) {
3088 f = fopen(fname, "w");
3089 if (f == NULL)
3090 return -1;
3091
3092 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3093 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3094 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3095 "20000 0\n");
3096 fclose(f);
3097 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003098 res = snprintf(fname, sizeof(fname),
3099 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3100 "delete_qos", pos);
3101 if (res < 0 || res >= sizeof(fname))
3102 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003103
3104 f = fopen(fname, "w");
3105 if (f == NULL)
3106 return -1;
3107
3108 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3109 fprintf(f, "2 4\n");
3110 fclose(f);
3111 }
3112#endif /* __linux__ */
3113
3114 return 0;
3115}
3116
3117
Jouni Malinenf7222712019-06-13 01:50:21 +03003118static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3119 struct sigma_conn *conn,
3120 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003121{
3122 const char *intf = get_param(cmd, "Interface");
3123 /* const char *ssid = get_param(cmd, "ssid"); */
3124 const char *val;
3125 int max_sp_len = 4;
3126 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3127 char buf[100];
3128 int ret1, ret2;
3129
3130 val = get_param(cmd, "maxSPLength");
3131 if (val) {
3132 max_sp_len = atoi(val);
3133 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3134 max_sp_len != 4)
3135 return -1;
3136 }
3137
3138 val = get_param(cmd, "acBE");
3139 if (val)
3140 ac_be = atoi(val);
3141
3142 val = get_param(cmd, "acBK");
3143 if (val)
3144 ac_bk = atoi(val);
3145
3146 val = get_param(cmd, "acVI");
3147 if (val)
3148 ac_vi = atoi(val);
3149
3150 val = get_param(cmd, "acVO");
3151 if (val)
3152 ac_vo = atoi(val);
3153
3154 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3155
3156 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3157 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3158 ret1 = wpa_command(intf, buf);
3159
3160 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3161 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3162 ret2 = wpa_command(intf, buf);
3163
3164 if (ret1 && ret2) {
3165 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3166 "UAPSD parameters.");
3167 return -2;
3168 }
3169
3170 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3171 send_resp(dut, conn, SIGMA_ERROR,
3172 "ErrorCode,Failed to set ath6kl QoS parameters");
3173 return 0;
3174 }
3175
3176 return 1;
3177}
3178
3179
Jouni Malinenf7222712019-06-13 01:50:21 +03003180static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3181 struct sigma_conn *conn,
3182 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003183{
3184 char buf[1000];
3185 const char *intf = get_param(cmd, "Interface");
3186 const char *grp = get_param(cmd, "Group");
3187 const char *act = get_param(cmd, "Action");
3188 const char *tid = get_param(cmd, "Tid");
3189 const char *dir = get_param(cmd, "Direction");
3190 const char *psb = get_param(cmd, "Psb");
3191 const char *up = get_param(cmd, "Up");
3192 const char *fixed = get_param(cmd, "Fixed");
3193 const char *size = get_param(cmd, "Size");
3194 const char *msize = get_param(cmd, "Maxsize");
3195 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3196 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3197 const char *inact = get_param(cmd, "Inactivity");
3198 const char *sus = get_param(cmd, "Suspension");
3199 const char *mindr = get_param(cmd, "Mindatarate");
3200 const char *meandr = get_param(cmd, "Meandatarate");
3201 const char *peakdr = get_param(cmd, "Peakdatarate");
3202 const char *phyrate = get_param(cmd, "Phyrate");
3203 const char *burstsize = get_param(cmd, "Burstsize");
3204 const char *sba = get_param(cmd, "Sba");
3205 int direction;
3206 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003207 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003208 int fixed_int;
3209 int psb_ts;
3210
3211 if (intf == NULL || grp == NULL || act == NULL )
3212 return -1;
3213
3214 if (strcasecmp(act, "addts") == 0) {
3215 if (tid == NULL || dir == NULL || psb == NULL ||
3216 up == NULL || fixed == NULL || size == NULL)
3217 return -1;
3218
3219 /*
3220 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3221 * possible values, but WMM-AC and V-E test scripts use "UP,
3222 * "DOWN", and "BIDI".
3223 */
3224 if (strcasecmp(dir, "uplink") == 0 ||
3225 strcasecmp(dir, "up") == 0) {
3226 direction = 0;
3227 } else if (strcasecmp(dir, "downlink") == 0 ||
3228 strcasecmp(dir, "down") == 0) {
3229 direction = 1;
3230 } else if (strcasecmp(dir, "bidi") == 0) {
3231 direction = 2;
3232 } else {
3233 sigma_dut_print(dut, DUT_MSG_ERROR,
3234 "Direction %s not supported", dir);
3235 return -1;
3236 }
3237
3238 if (strcasecmp(psb, "legacy") == 0) {
3239 psb_ts = 0;
3240 } else if (strcasecmp(psb, "uapsd") == 0) {
3241 psb_ts = 1;
3242 } else {
3243 sigma_dut_print(dut, DUT_MSG_ERROR,
3244 "PSB %s not supported", psb);
3245 return -1;
3246 }
3247
3248 if (atoi(tid) < 0 || atoi(tid) > 7) {
3249 sigma_dut_print(dut, DUT_MSG_ERROR,
3250 "TID %s not supported", tid);
3251 return -1;
3252 }
3253
3254 if (strcasecmp(fixed, "true") == 0) {
3255 fixed_int = 1;
3256 } else {
3257 fixed_int = 0;
3258 }
3259
Peng Xu93319622017-10-04 17:58:16 -07003260 if (sba)
3261 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003262
3263 dut->dialog_token++;
3264 handle = 7000 + dut->dialog_token;
3265
3266 /*
3267 * size: convert to hex
3268 * maxsi: convert to hex
3269 * mindr: convert to hex
3270 * meandr: convert to hex
3271 * peakdr: convert to hex
3272 * burstsize: convert to hex
3273 * phyrate: convert to hex
3274 * sba: convert to hex with modification
3275 * minsi: convert to integer
3276 * sus: convert to integer
3277 * inact: convert to integer
3278 * maxsi: convert to integer
3279 */
3280
3281 /*
3282 * The Nominal MSDU Size field is 2 octets long and contains an
3283 * unsigned integer that specifies the nominal size, in octets,
3284 * of MSDUs belonging to the traffic under this traffic
3285 * specification and is defined in Figure 16. If the Fixed
3286 * subfield is set to 1, then the size of the MSDU is fixed and
3287 * is indicated by the Size Subfield. If the Fixed subfield is
3288 * set to 0, then the size of the MSDU might not be fixed and
3289 * the Size indicates the nominal MSDU size.
3290 *
3291 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3292 * and specifies the excess allocation of time (and bandwidth)
3293 * over and above the stated rates required to transport an MSDU
3294 * belonging to the traffic in this TSPEC. This field is
3295 * represented as an unsigned binary number with an implicit
3296 * binary point after the leftmost 3 bits. For example, an SBA
3297 * of 1.75 is represented as 0x3800. This field is included to
3298 * account for retransmissions. As such, the value of this field
3299 * must be greater than unity.
3300 */
3301
3302 snprintf(buf, sizeof(buf),
3303 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3304 " 0x%X 0x%X 0x%X"
3305 " 0x%X 0x%X 0x%X"
3306 " 0x%X %d %d %d %d"
3307 " %d %d",
3308 intf, handle, tid, direction, psb_ts, up,
3309 (unsigned int) ((fixed_int << 15) | atoi(size)),
3310 msize ? atoi(msize) : 0,
3311 mindr ? atoi(mindr) : 0,
3312 meandr ? atoi(meandr) : 0,
3313 peakdr ? atoi(peakdr) : 0,
3314 burstsize ? atoi(burstsize) : 0,
3315 phyrate ? atoi(phyrate) : 0,
3316 sba ? ((unsigned int) (((int) sba_fv << 13) |
3317 (int)((sba_fv - (int) sba_fv) *
3318 8192))) : 0,
3319 minsi ? atoi(minsi) : 0,
3320 sus ? atoi(sus) : 0,
3321 0, 0,
3322 inact ? atoi(inact) : 0,
3323 maxsi ? atoi(maxsi) : 0);
3324
3325 if (system(buf) != 0) {
3326 sigma_dut_print(dut, DUT_MSG_ERROR,
3327 "iwpriv addtspec request failed");
3328 send_resp(dut, conn, SIGMA_ERROR,
3329 "errorCode,Failed to execute addTspec command");
3330 return 0;
3331 }
3332
3333 sigma_dut_print(dut, DUT_MSG_INFO,
3334 "iwpriv addtspec request send");
3335
3336 /* Mapping handle to a TID */
3337 dut->tid_to_handle[atoi(tid)] = handle;
3338 } else if (strcasecmp(act, "delts") == 0) {
3339 if (tid == NULL)
3340 return -1;
3341
3342 if (atoi(tid) < 0 || atoi(tid) > 7) {
3343 sigma_dut_print(dut, DUT_MSG_ERROR,
3344 "TID %s not supported", tid);
3345 send_resp(dut, conn, SIGMA_ERROR,
3346 "errorCode,Unsupported TID");
3347 return 0;
3348 }
3349
3350 handle = dut->tid_to_handle[atoi(tid)];
3351
3352 if (handle < 7000 || handle > 7255) {
3353 /* Invalid handle ie no mapping for that TID */
3354 sigma_dut_print(dut, DUT_MSG_ERROR,
3355 "handle-> %d not found", handle);
3356 }
3357
3358 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3359 intf, handle);
3360
3361 if (system(buf) != 0) {
3362 sigma_dut_print(dut, DUT_MSG_ERROR,
3363 "iwpriv deltspec request failed");
3364 send_resp(dut, conn, SIGMA_ERROR,
3365 "errorCode,Failed to execute delTspec command");
3366 return 0;
3367 }
3368
3369 sigma_dut_print(dut, DUT_MSG_INFO,
3370 "iwpriv deltspec request send");
3371
3372 dut->tid_to_handle[atoi(tid)] = 0;
3373 } else {
3374 sigma_dut_print(dut, DUT_MSG_ERROR,
3375 "Action type %s not supported", act);
3376 send_resp(dut, conn, SIGMA_ERROR,
3377 "errorCode,Unsupported Action");
3378 return 0;
3379 }
3380
3381 return 1;
3382}
3383
3384
vamsi krishna52e16f92017-08-29 12:37:34 +05303385static int find_network(struct sigma_dut *dut, const char *ssid)
3386{
3387 char list[4096];
3388 char *pos;
3389
3390 sigma_dut_print(dut, DUT_MSG_DEBUG,
3391 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003392 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303393 list, sizeof(list)) < 0)
3394 return -1;
3395 pos = strstr(list, ssid);
3396 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3397 return -1;
3398
3399 while (pos > list && pos[-1] != '\n')
3400 pos--;
3401 dut->infra_network_id = atoi(pos);
3402 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3403 return 0;
3404}
3405
3406
Sunil Dutt44595082018-02-12 19:41:45 +05303407#ifdef NL80211_SUPPORT
3408static int sta_config_rsnie(struct sigma_dut *dut, int val)
3409{
3410 struct nl_msg *msg;
3411 int ret;
3412 struct nlattr *params;
3413 int ifindex;
3414
3415 ifindex = if_nametoindex("wlan0");
3416 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3417 NL80211_CMD_VENDOR)) ||
3418 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3419 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3420 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3421 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
3422 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3423 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) {
3424 sigma_dut_print(dut, DUT_MSG_ERROR,
3425 "%s: err in adding vendor_cmd and vendor_data",
3426 __func__);
3427 nlmsg_free(msg);
3428 return -1;
3429 }
3430 nla_nest_end(msg, params);
3431
3432 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3433 if (ret) {
3434 sigma_dut_print(dut, DUT_MSG_ERROR,
3435 "%s: err in send_and_recv_msgs, ret=%d",
3436 __func__, ret);
3437 return ret;
3438 }
3439
3440 return 0;
3441}
3442#endif /* NL80211_SUPPORT */
3443
3444
Jouni Malinenf7222712019-06-13 01:50:21 +03003445static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3446 struct sigma_conn *conn,
3447 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003448{
3449 /* const char *intf = get_param(cmd, "Interface"); */
3450 const char *ssid = get_param(cmd, "ssid");
3451 const char *wps_param = get_param(cmd, "WPS");
3452 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003453 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003454 const char *network_mode = get_param(cmd, "network_mode");
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303455 const char *ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003456 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003457 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003458 int e;
3459 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3460 struct wpa_ctrl *ctrl = NULL;
3461 int num_network_not_found = 0;
3462 int num_disconnected = 0;
3463 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003464
3465 if (ssid == NULL)
3466 return -1;
3467
Jouni Malinen37d5c692019-08-19 16:56:55 +03003468 dut->server_cert_tod = 0;
3469
Jouni Malinen3c367e82017-06-23 17:01:47 +03003470 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303471#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003472 if (get_driver_type(dut) == DRIVER_WCN) {
Sunil Dutt44595082018-02-12 19:41:45 +05303473 sta_config_rsnie(dut, 1);
3474 dut->config_rsnie = 1;
3475 }
3476#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003477 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3478 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003479 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03003480 send_resp(dut, conn, SIGMA_ERROR,
3481 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3482 return 0;
3483 }
3484 }
3485
Jouni Malinen68143132017-09-02 02:34:08 +03003486 if (dut->sae_commit_override) {
3487 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3488 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003489 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03003490 send_resp(dut, conn, SIGMA_ERROR,
3491 "ErrorCode,Failed to set SAE commit override");
3492 return 0;
3493 }
3494 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303495#ifdef ANDROID
3496 if (dut->fils_hlp)
3497 process_fils_hlp(dut);
3498#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003499
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003500 if (wps_param &&
3501 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3502 wps = 1;
3503
Vamsi Krishnac1633d22020-05-06 18:31:21 +05303504 if (dut->ocvc &&
3505 set_network(get_station_ifname(dut), dut->infra_network_id,
3506 "ocv", "1") < 0)
3507 return ERROR_SEND_STATUS;
3508
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003509 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003510 if (dut->program == PROGRAM_60GHZ && network_mode &&
3511 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003512 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003513 "pbss", "1") < 0)
3514 return -2;
3515
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003516 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3517 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3518 "parameters not yet set");
3519 return 0;
3520 }
3521 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003522 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003523 return -2;
3524 } else {
3525 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3526 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003527 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003528 return -2;
3529 }
3530 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303531 if (strcmp(ssid, dut->infra_ssid) == 0) {
3532 sigma_dut_print(dut, DUT_MSG_DEBUG,
3533 "sta_associate for the most recently added network");
3534 } else if (find_network(dut, ssid) < 0) {
3535 sigma_dut_print(dut, DUT_MSG_DEBUG,
3536 "sta_associate for a previously stored network profile");
3537 send_resp(dut, conn, SIGMA_ERROR,
3538 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003539 return 0;
3540 }
3541
3542 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003543 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003544 "bssid", bssid) < 0) {
3545 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3546 "Invalid bssid argument");
3547 return 0;
3548 }
3549
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303550 if ((dut->program == PROGRAM_WPA3 &&
3551 dut->sta_associate_wait_connect) ||
3552 dut->program == PROGRAM_QM) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003553 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003554 if (!ctrl)
3555 return ERROR_SEND_STATUS;
3556 }
3557
Jouni Malinen46a19b62017-06-23 14:31:27 +03003558 extra[0] = '\0';
3559 if (chan)
3560 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003561 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003562 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3563 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003564 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003565 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3566 "network id %d on %s",
3567 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003568 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003569 ret = ERROR_SEND_STATUS;
3570 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003571 }
3572 }
3573
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003574 if (!ctrl)
3575 return SUCCESS_SEND_STATUS;
3576
3577 /* Wait for connection result to be able to store server certificate
3578 * hash for trust root override testing
3579 * (dev_exec_action,ServerCertTrust). */
3580
3581 for (e = 0; e < 20; e++) {
3582 const char *events[] = {
3583 "CTRL-EVENT-EAP-PEER-CERT",
3584 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3585 "CTRL-EVENT-DISCONNECTED",
3586 "CTRL-EVENT-CONNECTED",
3587 "CTRL-EVENT-NETWORK-NOT-FOUND",
3588 NULL
3589 };
3590 char buf[1024];
3591 int res;
3592
3593 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3594 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02003595 send_resp(dut, conn, SIGMA_COMPLETE,
3596 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003597 ret = STATUS_SENT_ERROR;
3598 break;
3599 }
3600 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3601 buf);
3602
3603 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3604 strstr(buf, " depth=0")) {
3605 char *pos = strstr(buf, " hash=");
3606
3607 if (pos) {
3608 char *end;
3609
Jouni Malinen34b19cb2019-08-16 16:37:17 +03003610 if (strstr(buf, " tod=1"))
3611 tod = 1;
3612 else if (strstr(buf, " tod=2"))
3613 tod = 2;
3614 else
3615 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003616 sigma_dut_print(dut, DUT_MSG_DEBUG,
3617 "Server certificate TOD policy: %d",
3618 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03003619 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003620
3621 pos += 6;
3622 end = strchr(pos, ' ');
3623 if (end)
3624 *end = '\0';
3625 strlcpy(dut->server_cert_hash, pos,
3626 sizeof(dut->server_cert_hash));
3627 sigma_dut_print(dut, DUT_MSG_DEBUG,
3628 "Server certificate hash: %s",
3629 dut->server_cert_hash);
3630 }
3631 }
3632
3633 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3634 send_resp(dut, conn, SIGMA_COMPLETE,
3635 "Result,TLS server certificate validation failed");
3636 ret = STATUS_SENT_ERROR;
3637 break;
3638 }
3639
3640 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3641 num_network_not_found++;
3642
3643 if (num_network_not_found > 2) {
3644 send_resp(dut, conn, SIGMA_COMPLETE,
3645 "Result,Network not found");
3646 ret = STATUS_SENT_ERROR;
3647 break;
3648 }
3649 }
3650
3651 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3652 num_disconnected++;
3653
3654 if (num_disconnected > 2) {
3655 send_resp(dut, conn, SIGMA_COMPLETE,
3656 "Result,Connection failed");
3657 ret = STATUS_SENT_ERROR;
3658 break;
3659 }
3660 }
3661
3662 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3663 if (tod >= 0) {
3664 sigma_dut_print(dut, DUT_MSG_DEBUG,
3665 "Network profile TOD policy update: %d -> %d",
3666 dut->sta_tod_policy, tod);
3667 dut->sta_tod_policy = tod;
3668 }
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303669 if (dut->program == PROGRAM_QM) {
3670 unsigned char iface_mac_addr[ETH_ALEN];
3671 char ipv6[100];
3672
3673 if (get_hwaddr(ifname, iface_mac_addr) < 0) {
3674 sigma_dut_print(dut, DUT_MSG_ERROR,
3675 "%s: get_hwaddr %s failed",
3676 __func__, ifname);
3677 ret = ERROR_SEND_STATUS;
3678 break;
3679 }
3680
3681 convert_mac_addr_to_ipv6_lladdr(iface_mac_addr,
3682 ipv6,
3683 sizeof(ipv6));
3684
3685 if (set_ipv6_addr(dut, ipv6, "64", ifname) !=
3686 0) {
3687 ret = ERROR_SEND_STATUS;
3688 break;
3689 }
3690 }
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003691 break;
3692 }
3693 }
3694done:
3695 if (ctrl) {
3696 wpa_ctrl_detach(ctrl);
3697 wpa_ctrl_close(ctrl);
3698 }
3699 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003700}
3701
3702
3703static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3704{
3705 char buf[500], cmd[200];
3706 int res;
3707
3708 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3709 * default path */
3710 res = snprintf(cmd, sizeof(cmd),
3711 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3712 file_exists("./hs20-osu-client") ?
3713 "./hs20-osu-client" : "hs20-osu-client",
3714 sigma_wpas_ctrl,
3715 dut->summary_log ? "-s " : "",
3716 dut->summary_log ? dut->summary_log : "");
3717 if (res < 0 || res >= (int) sizeof(cmd))
3718 return -1;
3719
3720 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3721 if (res < 0 || res >= (int) sizeof(buf))
3722 return -1;
3723 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3724
3725 if (system(buf) != 0) {
3726 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3727 return -1;
3728 }
3729 sigma_dut_print(dut, DUT_MSG_DEBUG,
3730 "Completed hs20-osu-client operation");
3731
3732 return 0;
3733}
3734
3735
3736static int download_ppsmo(struct sigma_dut *dut,
3737 struct sigma_conn *conn,
3738 const char *intf,
3739 struct sigma_cmd *cmd)
3740{
3741 const char *name, *path, *val;
3742 char url[500], buf[600], fbuf[100];
3743 char *fqdn = NULL;
3744
3745 name = get_param(cmd, "FileName");
3746 path = get_param(cmd, "FilePath");
3747 if (name == NULL || path == NULL)
3748 return -1;
3749
3750 if (strcasecmp(path, "VendorSpecific") == 0) {
3751 snprintf(url, sizeof(url), "PPS/%s", name);
3752 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3753 "from the device (%s)", url);
3754 if (!file_exists(url)) {
3755 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3756 "PPS MO file does not exist");
3757 return 0;
3758 }
3759 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3760 if (system(buf) != 0) {
3761 send_resp(dut, conn, SIGMA_ERROR,
3762 "errorCode,Failed to copy PPS MO");
3763 return 0;
3764 }
3765 } else if (strncasecmp(path, "http:", 5) != 0 &&
3766 strncasecmp(path, "https:", 6) != 0) {
3767 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3768 "Unsupported FilePath value");
3769 return 0;
3770 } else {
3771 snprintf(url, sizeof(url), "%s/%s", path, name);
3772 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3773 url);
3774 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3775 remove("pps-tnds.xml");
3776 if (system(buf) != 0) {
3777 send_resp(dut, conn, SIGMA_ERROR,
3778 "errorCode,Failed to download PPS MO");
3779 return 0;
3780 }
3781 }
3782
3783 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3784 send_resp(dut, conn, SIGMA_ERROR,
3785 "errorCode,Failed to parse downloaded PPSMO");
3786 return 0;
3787 }
3788 unlink("pps-tnds.xml");
3789
3790 val = get_param(cmd, "managementTreeURI");
3791 if (val) {
3792 const char *pos, *end;
3793 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3794 val);
3795 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3796 send_resp(dut, conn, SIGMA_ERROR,
3797 "errorCode,Invalid managementTreeURI prefix");
3798 return 0;
3799 }
3800 pos = val + 8;
3801 end = strchr(pos, '/');
3802 if (end == NULL ||
3803 strcmp(end, "/PerProviderSubscription") != 0) {
3804 send_resp(dut, conn, SIGMA_ERROR,
3805 "errorCode,Invalid managementTreeURI postfix");
3806 return 0;
3807 }
3808 if (end - pos >= (int) sizeof(fbuf)) {
3809 send_resp(dut, conn, SIGMA_ERROR,
3810 "errorCode,Too long FQDN in managementTreeURI");
3811 return 0;
3812 }
3813 memcpy(fbuf, pos, end - pos);
3814 fbuf[end - pos] = '\0';
3815 fqdn = fbuf;
3816 sigma_dut_print(dut, DUT_MSG_INFO,
3817 "FQDN from managementTreeURI: %s", fqdn);
3818 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3819 FILE *f = fopen("pps-fqdn", "r");
3820 if (f) {
3821 if (fgets(fbuf, sizeof(fbuf), f)) {
3822 fbuf[sizeof(fbuf) - 1] = '\0';
3823 fqdn = fbuf;
3824 sigma_dut_print(dut, DUT_MSG_DEBUG,
3825 "Use FQDN %s", fqdn);
3826 }
3827 fclose(f);
3828 }
3829 }
3830
3831 if (fqdn == NULL) {
3832 send_resp(dut, conn, SIGMA_ERROR,
3833 "errorCode,No FQDN specified");
3834 return 0;
3835 }
3836
3837 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3838 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3839 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3840
3841 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3842 if (rename("pps.xml", buf) < 0) {
3843 send_resp(dut, conn, SIGMA_ERROR,
3844 "errorCode,Could not move PPS MO");
3845 return 0;
3846 }
3847
3848 if (strcasecmp(path, "VendorSpecific") == 0) {
3849 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3850 fqdn);
3851 if (system(buf)) {
3852 send_resp(dut, conn, SIGMA_ERROR,
3853 "errorCode,Failed to copy OSU CA cert");
3854 return 0;
3855 }
3856
3857 snprintf(buf, sizeof(buf),
3858 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3859 fqdn);
3860 if (system(buf)) {
3861 send_resp(dut, conn, SIGMA_ERROR,
3862 "errorCode,Failed to copy AAA CA cert");
3863 return 0;
3864 }
3865 } else {
3866 snprintf(buf, sizeof(buf),
3867 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3868 fqdn, fqdn);
3869 if (run_hs20_osu(dut, buf) < 0) {
3870 send_resp(dut, conn, SIGMA_ERROR,
3871 "errorCode,Failed to download OSU CA cert");
3872 return 0;
3873 }
3874
3875 snprintf(buf, sizeof(buf),
3876 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3877 fqdn, fqdn);
3878 if (run_hs20_osu(dut, buf) < 0) {
3879 sigma_dut_print(dut, DUT_MSG_INFO,
3880 "Failed to download AAA CA cert");
3881 }
3882 }
3883
3884 if (file_exists("next-client-cert.pem")) {
3885 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3886 if (rename("next-client-cert.pem", buf) < 0) {
3887 send_resp(dut, conn, SIGMA_ERROR,
3888 "errorCode,Could not move client certificate");
3889 return 0;
3890 }
3891 }
3892
3893 if (file_exists("next-client-key.pem")) {
3894 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3895 if (rename("next-client-key.pem", buf) < 0) {
3896 send_resp(dut, conn, SIGMA_ERROR,
3897 "errorCode,Could not move client key");
3898 return 0;
3899 }
3900 }
3901
3902 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3903 if (run_hs20_osu(dut, buf) < 0) {
3904 send_resp(dut, conn, SIGMA_ERROR,
3905 "errorCode,Failed to configure credential from "
3906 "PPSMO");
3907 return 0;
3908 }
3909
3910 return 1;
3911}
3912
3913
3914static int download_cert(struct sigma_dut *dut,
3915 struct sigma_conn *conn,
3916 const char *intf,
3917 struct sigma_cmd *cmd)
3918{
3919 const char *name, *path;
3920 char url[500], buf[600];
3921
3922 name = get_param(cmd, "FileName");
3923 path = get_param(cmd, "FilePath");
3924 if (name == NULL || path == NULL)
3925 return -1;
3926
3927 if (strcasecmp(path, "VendorSpecific") == 0) {
3928 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
3929 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3930 "certificate from the device (%s)", url);
3931 if (!file_exists(url)) {
3932 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3933 "certificate file does not exist");
3934 return 0;
3935 }
3936 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
3937 if (system(buf) != 0) {
3938 send_resp(dut, conn, SIGMA_ERROR,
3939 "errorCode,Failed to copy client "
3940 "certificate");
3941 return 0;
3942 }
3943
3944 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
3945 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3946 "private key from the device (%s)", url);
3947 if (!file_exists(url)) {
3948 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3949 "private key file does not exist");
3950 return 0;
3951 }
3952 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
3953 if (system(buf) != 0) {
3954 send_resp(dut, conn, SIGMA_ERROR,
3955 "errorCode,Failed to copy client key");
3956 return 0;
3957 }
3958 } else if (strncasecmp(path, "http:", 5) != 0 &&
3959 strncasecmp(path, "https:", 6) != 0) {
3960 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3961 "Unsupported FilePath value");
3962 return 0;
3963 } else {
3964 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
3965 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
3966 "certificate/key from %s", url);
3967 snprintf(buf, sizeof(buf),
3968 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
3969 if (system(buf) != 0) {
3970 send_resp(dut, conn, SIGMA_ERROR,
3971 "errorCode,Failed to download client "
3972 "certificate");
3973 return 0;
3974 }
3975
3976 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
3977 {
3978 send_resp(dut, conn, SIGMA_ERROR,
3979 "errorCode,Failed to copy client key");
3980 return 0;
3981 }
3982 }
3983
3984 return 1;
3985}
3986
3987
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003988static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
3989 struct sigma_conn *conn,
3990 struct sigma_cmd *cmd)
3991{
3992 const char *val;
3993 const char *intf = get_param(cmd, "interface");
3994
3995 if (!intf)
3996 return -1;
3997
3998 val = get_param(cmd, "WscIEFragment");
3999 if (val && strcasecmp(val, "enable") == 0) {
4000 sigma_dut_print(dut, DUT_MSG_DEBUG,
4001 "Enable WSC IE fragmentation");
4002
4003 dut->wsc_fragment = 1;
4004 /* set long attributes to force fragmentation */
4005 if (wpa_command(intf, "SET device_name "
4006 WPS_LONG_DEVICE_NAME) < 0)
4007 return -2;
4008 if (wpa_command(intf, "SET manufacturer "
4009 WPS_LONG_MANUFACTURER) < 0)
4010 return -2;
4011 if (wpa_command(intf, "SET model_name "
4012 WPS_LONG_MODEL_NAME) < 0)
4013 return -2;
4014 if (wpa_command(intf, "SET model_number "
4015 WPS_LONG_MODEL_NUMBER) < 0)
4016 return -2;
4017 if (wpa_command(intf, "SET serial_number "
4018 WPS_LONG_SERIAL_NUMBER) < 0)
4019 return -2;
4020 }
4021
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02004022 val = get_param(cmd, "RSN_IE");
4023 if (val) {
4024 if (strcasecmp(val, "disable") == 0)
4025 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
4026 else if (strcasecmp(val, "enable") == 0)
4027 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
4028 }
4029
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004030 val = get_param(cmd, "WpsVersion");
4031 if (val)
4032 dut->wps_forced_version = get_wps_forced_version(dut, val);
4033
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004034 val = get_param(cmd, "WscEAPFragment");
4035 if (val && strcasecmp(val, "enable") == 0)
4036 dut->eap_fragment = 1;
4037
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004038 return 1;
4039}
4040
4041
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004042static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4043 struct sigma_conn *conn,
4044 const char *intf,
4045 struct sigma_cmd *cmd)
4046{
4047 const char *val;
4048
4049 val = get_param(cmd, "FileType");
4050 if (val && strcasecmp(val, "PPSMO") == 0)
4051 return download_ppsmo(dut, conn, intf, cmd);
4052 if (val && strcasecmp(val, "CERT") == 0)
4053 return download_cert(dut, conn, intf, cmd);
4054 if (val) {
4055 send_resp(dut, conn, SIGMA_ERROR,
4056 "ErrorCode,Unsupported FileType");
4057 return 0;
4058 }
4059
4060 return 1;
4061}
4062
4063
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304064static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4065 struct sigma_conn *conn,
4066 const char *intf,
4067 struct sigma_cmd *cmd)
4068{
4069 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304070 char buf[1000];
4071 char text[20];
4072 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304073
4074 val = get_param(cmd, "OCESupport");
4075 if (val && strcasecmp(val, "Disable") == 0) {
4076 if (wpa_command(intf, "SET oce 0") < 0) {
4077 send_resp(dut, conn, SIGMA_ERROR,
4078 "ErrorCode,Failed to disable OCE");
4079 return 0;
4080 }
4081 } else if (val && strcasecmp(val, "Enable") == 0) {
4082 if (wpa_command(intf, "SET oce 1") < 0) {
4083 send_resp(dut, conn, SIGMA_ERROR,
4084 "ErrorCode,Failed to enable OCE");
4085 return 0;
4086 }
4087 }
4088
vamsi krishnaa2799492017-12-05 14:28:01 +05304089 val = get_param(cmd, "FILScap");
4090 if (val && (atoi(val) == 1)) {
4091 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4092 send_resp(dut, conn, SIGMA_ERROR,
4093 "ErrorCode,Failed to enable FILS");
4094 return 0;
4095 }
4096 } else if (val && (atoi(val) == 0)) {
4097 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4098 send_resp(dut, conn, SIGMA_ERROR,
4099 "ErrorCode,Failed to disable FILS");
4100 return 0;
4101 }
4102 }
4103
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304104 val = get_param(cmd, "FILSHLP");
4105 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004106 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304107 sizeof(text)) < 0)
4108 return -2;
4109 hwaddr_aton(text, addr);
4110 snprintf(buf, sizeof(buf),
4111 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4112 "080045100140000040004011399e00000000ffffffff00440043"
4113 "012cb30001010600fd4f46410000000000000000000000000000"
4114 "000000000000"
4115 "%02x%02x%02x%02x%02x%02x"
4116 "0000000000000000000000000000000000000000000000000000"
4117 "0000000000000000000000000000000000000000000000000000"
4118 "0000000000000000000000000000000000000000000000000000"
4119 "0000000000000000000000000000000000000000000000000000"
4120 "0000000000000000000000000000000000000000000000000000"
4121 "0000000000000000000000000000000000000000000000000000"
4122 "0000000000000000000000000000000000000000000000000000"
4123 "0000000000000000000000000000000000000000638253633501"
4124 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4125 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4126 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4127 if (wpa_command(intf, buf)) {
4128 send_resp(dut, conn, SIGMA_ERROR,
4129 "ErrorCode,Failed to add HLP");
4130 return 0;
4131 }
4132 dut->fils_hlp = 1;
4133 }
4134
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304135 return 1;
4136}
4137
4138
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004139static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4140 const char *val)
4141{
4142 int counter = 0;
4143 char token[50];
4144 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304145 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004146
Peng Xub8fc5cc2017-05-10 17:27:28 -07004147 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004148 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304149 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004150 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004151 if (strcmp(result, "disable") == 0)
4152 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4153 else
4154 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304155 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004156 counter++;
4157 }
4158}
4159
4160
4161static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4162 const char *val)
4163{
4164 char buf[100];
4165
4166 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4167 if (system(buf) != 0) {
4168 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4169 }
4170}
4171
4172
4173static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4174 const char *val)
4175{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004176 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004177 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004178 }
4179}
4180
4181
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004182static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4183 const char *val)
4184{
4185#ifdef NL80211_SUPPORT
4186 struct nl_msg *msg;
4187 int ret = 0;
4188 struct nlattr *params;
4189 int ifindex;
4190 int wmmenable = 1;
4191
4192 if (val &&
4193 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4194 wmmenable = 0;
4195
4196 ifindex = if_nametoindex(intf);
4197 if (ifindex == 0) {
4198 sigma_dut_print(dut, DUT_MSG_ERROR,
4199 "%s: Index for interface %s failed",
4200 __func__, intf);
4201 return -1;
4202 }
4203
4204 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4205 NL80211_CMD_VENDOR)) ||
4206 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4207 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4208 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4209 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4210 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4211 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4212 wmmenable)) {
4213 sigma_dut_print(dut, DUT_MSG_ERROR,
4214 "%s: err in adding vendor_cmd and vendor_data",
4215 __func__);
4216 nlmsg_free(msg);
4217 return -1;
4218 }
4219 nla_nest_end(msg, params);
4220
4221 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4222 if (ret) {
4223 sigma_dut_print(dut, DUT_MSG_ERROR,
4224 "%s: err in send_and_recv_msgs, ret=%d",
4225 __func__, ret);
4226 }
4227 return ret;
4228#else /* NL80211_SUPPORT */
4229 sigma_dut_print(dut, DUT_MSG_ERROR,
4230 "WMM cannot be changed without NL80211_SUPPORT defined");
4231 return -1;
4232#endif /* NL80211_SUPPORT */
4233}
4234
4235
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004236static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4237 const char *val)
4238{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004239 int sgi20;
4240
4241 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4242
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004243 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004244}
4245
4246
4247static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4248 const char *val)
4249{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304250 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004251
4252 /* Disable Tx Beam forming when using a fixed rate */
4253 ath_disable_txbf(dut, intf);
4254
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304255 v = atoi(val);
4256 if (v < 0 || v > 32) {
4257 sigma_dut_print(dut, DUT_MSG_ERROR,
4258 "Invalid Fixed MCS rate: %d", v);
4259 return;
4260 }
4261 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004262
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004263 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004264
4265 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004266 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004267}
4268
4269
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004270static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4271 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004272{
4273 char buf[60];
4274
4275 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4276 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4277 else
4278 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4279
4280 if (system(buf) != 0)
4281 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4282}
4283
4284
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004285static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4286 int ampdu)
4287{
4288 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004289 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004290
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004291 if (ampdu)
4292 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004293 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4294 if (system(buf) != 0) {
4295 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4296 return -1;
4297 }
4298
4299 return 0;
4300}
4301
4302
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004303static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4304 const char *val)
4305{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004306 run_iwpriv(dut, intf, "tx_stbc %s", val);
4307 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004308}
4309
4310
4311static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4312 const char *val)
4313{
4314 char buf[60];
4315
Peng Xucc317ed2017-05-18 16:44:37 -07004316 if (strcmp(val, "160") == 0) {
4317 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4318 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004319 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4320 } else if (strcmp(val, "40") == 0) {
4321 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4322 } else if (strcmp(val, "20") == 0) {
4323 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4324 } else if (strcasecmp(val, "Auto") == 0) {
4325 buf[0] = '\0';
4326 } else {
4327 sigma_dut_print(dut, DUT_MSG_ERROR,
4328 "WIDTH/CTS_WIDTH value not supported");
4329 return -1;
4330 }
4331
4332 if (buf[0] != '\0' && system(buf) != 0) {
4333 sigma_dut_print(dut, DUT_MSG_ERROR,
4334 "Failed to set WIDTH/CTS_WIDTH");
4335 return -1;
4336 }
4337
4338 return 0;
4339}
4340
4341
4342int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4343 const char *intf, const char *val)
4344{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004345 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004346 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004347 dut->chwidth = 0;
4348 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004349 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004350 dut->chwidth = 0;
4351 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004352 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004353 dut->chwidth = 1;
4354 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004355 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004356 dut->chwidth = 2;
4357 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004358 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004359 dut->chwidth = 3;
4360 } else {
4361 send_resp(dut, conn, SIGMA_ERROR,
4362 "ErrorCode,WIDTH not supported");
4363 return -1;
4364 }
4365
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004366 return 0;
4367}
4368
4369
4370static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4371 const char *val)
4372{
4373 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004374 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004375
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004376 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004377 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004378 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004379 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004380 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004381 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004382 } else {
4383 sigma_dut_print(dut, DUT_MSG_ERROR,
4384 "SP_STREAM value not supported");
4385 return -1;
4386 }
4387
4388 if (system(buf) != 0) {
4389 sigma_dut_print(dut, DUT_MSG_ERROR,
4390 "Failed to set SP_STREAM");
4391 return -1;
4392 }
4393
Arif Hussainac6c5112018-05-25 17:34:00 -07004394 dut->sta_nss = sta_nss;
4395
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004396 return 0;
4397}
4398
4399
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304400static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4401 const char *val)
4402{
4403 char buf[60];
4404
4405 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
4406 if (system(buf) != 0)
4407 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4408
4409 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
4410 if (system(buf) != 0)
4411 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4412}
4413
4414
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304415static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4416 struct sigma_conn *conn,
4417 const char *intf, int capa)
4418{
4419 char buf[32];
4420
4421 if (capa > 0 && capa < 4) {
4422 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4423 if (wpa_command(intf, buf) < 0) {
4424 send_resp(dut, conn, SIGMA_ERROR,
4425 "ErrorCode, Failed to set cellular data capability");
4426 return 0;
4427 }
4428 return 1;
4429 }
4430
4431 sigma_dut_print(dut, DUT_MSG_ERROR,
4432 "Invalid Cellular data capability: %d", capa);
4433 send_resp(dut, conn, SIGMA_INVALID,
4434 "ErrorCode,Invalid cellular data capability");
4435 return 0;
4436}
4437
4438
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304439static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4440 const char *intf, const char *val)
4441{
4442 if (strcasecmp(val, "Disable") == 0) {
4443 if (wpa_command(intf, "SET roaming 0") < 0) {
4444 send_resp(dut, conn, SIGMA_ERROR,
4445 "ErrorCode,Failed to disable roaming");
4446 return 0;
4447 }
4448 return 1;
4449 }
4450
4451 if (strcasecmp(val, "Enable") == 0) {
4452 if (wpa_command(intf, "SET roaming 1") < 0) {
4453 send_resp(dut, conn, SIGMA_ERROR,
4454 "ErrorCode,Failed to enable roaming");
4455 return 0;
4456 }
4457 return 1;
4458 }
4459
4460 sigma_dut_print(dut, DUT_MSG_ERROR,
4461 "Invalid value provided for roaming: %s", val);
4462 send_resp(dut, conn, SIGMA_INVALID,
4463 "ErrorCode,Unknown value provided for Roaming");
4464 return 0;
4465}
4466
4467
Ashwini Patila75de5a2017-04-13 16:35:05 +05304468static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4469 struct sigma_conn *conn,
4470 const char *intf, const char *val)
4471{
4472 if (strcasecmp(val, "Disable") == 0) {
4473 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4474 send_resp(dut, conn, SIGMA_ERROR,
4475 "ErrorCode,Failed to disable Assoc_disallow");
4476 return 0;
4477 }
4478 return 1;
4479 }
4480
4481 if (strcasecmp(val, "Enable") == 0) {
4482 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4483 send_resp(dut, conn, SIGMA_ERROR,
4484 "ErrorCode,Failed to enable Assoc_disallow");
4485 return 0;
4486 }
4487 return 1;
4488 }
4489
4490 sigma_dut_print(dut, DUT_MSG_ERROR,
4491 "Invalid value provided for Assoc_disallow: %s", val);
4492 send_resp(dut, conn, SIGMA_INVALID,
4493 "ErrorCode,Unknown value provided for Assoc_disallow");
4494 return 0;
4495}
4496
4497
Ashwini Patilc63161e2017-04-13 16:30:23 +05304498static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4499 const char *intf, const char *val)
4500{
4501 if (strcasecmp(val, "Reject") == 0) {
4502 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4503 send_resp(dut, conn, SIGMA_ERROR,
4504 "ErrorCode,Failed to Reject BTM Request");
4505 return 0;
4506 }
4507 return 1;
4508 }
4509
4510 if (strcasecmp(val, "Accept") == 0) {
4511 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4512 send_resp(dut, conn, SIGMA_ERROR,
4513 "ErrorCode,Failed to Accept BTM Request");
4514 return 0;
4515 }
4516 return 1;
4517 }
4518
4519 sigma_dut_print(dut, DUT_MSG_ERROR,
4520 "Invalid value provided for BSS_Transition: %s", val);
4521 send_resp(dut, conn, SIGMA_INVALID,
4522 "ErrorCode,Unknown value provided for BSS_Transition");
4523 return 0;
4524}
4525
4526
Ashwini Patil00402582017-04-13 12:29:39 +05304527static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4528 struct sigma_conn *conn,
4529 const char *intf,
4530 struct sigma_cmd *cmd)
4531{
4532 const char *ch, *pref, *op_class, *reason;
4533 char buf[120];
4534 int len, ret;
4535
4536 pref = get_param(cmd, "Ch_Pref");
4537 if (!pref)
4538 return 1;
4539
4540 if (strcasecmp(pref, "clear") == 0) {
4541 free(dut->non_pref_ch_list);
4542 dut->non_pref_ch_list = NULL;
4543 } else {
4544 op_class = get_param(cmd, "Ch_Op_Class");
4545 if (!op_class) {
4546 send_resp(dut, conn, SIGMA_INVALID,
4547 "ErrorCode,Ch_Op_Class not provided");
4548 return 0;
4549 }
4550
4551 ch = get_param(cmd, "Ch_Pref_Num");
4552 if (!ch) {
4553 send_resp(dut, conn, SIGMA_INVALID,
4554 "ErrorCode,Ch_Pref_Num not provided");
4555 return 0;
4556 }
4557
4558 reason = get_param(cmd, "Ch_Reason_Code");
4559 if (!reason) {
4560 send_resp(dut, conn, SIGMA_INVALID,
4561 "ErrorCode,Ch_Reason_Code not provided");
4562 return 0;
4563 }
4564
4565 if (!dut->non_pref_ch_list) {
4566 dut->non_pref_ch_list =
4567 calloc(1, NON_PREF_CH_LIST_SIZE);
4568 if (!dut->non_pref_ch_list) {
4569 send_resp(dut, conn, SIGMA_ERROR,
4570 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4571 return 0;
4572 }
4573 }
4574 len = strlen(dut->non_pref_ch_list);
4575 ret = snprintf(dut->non_pref_ch_list + len,
4576 NON_PREF_CH_LIST_SIZE - len,
4577 " %s:%s:%s:%s", op_class, ch, pref, reason);
4578 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4579 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4580 dut->non_pref_ch_list);
4581 } else {
4582 sigma_dut_print(dut, DUT_MSG_ERROR,
4583 "snprintf failed for non_pref_list, ret = %d",
4584 ret);
4585 send_resp(dut, conn, SIGMA_ERROR,
4586 "ErrorCode,snprintf failed");
4587 free(dut->non_pref_ch_list);
4588 dut->non_pref_ch_list = NULL;
4589 return 0;
4590 }
4591 }
4592
4593 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4594 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4595 if (ret < 0 || ret >= (int) sizeof(buf)) {
4596 sigma_dut_print(dut, DUT_MSG_DEBUG,
4597 "snprintf failed for set non_pref_chan, ret: %d",
4598 ret);
4599 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4600 return 0;
4601 }
4602
4603 if (wpa_command(intf, buf) < 0) {
4604 send_resp(dut, conn, SIGMA_ERROR,
4605 "ErrorCode,Failed to set non-preferred channel list");
4606 return 0;
4607 }
4608
4609 return 1;
4610}
4611
4612
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004613#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004614
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004615static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4616 uint8_t cfg)
4617{
4618 struct nl_msg *msg;
4619 int ret = 0;
4620 struct nlattr *params;
4621 int ifindex;
4622
4623 ifindex = if_nametoindex(intf);
4624 if (ifindex == 0) {
4625 sigma_dut_print(dut, DUT_MSG_ERROR,
4626 "%s: Index for interface %s failed",
4627 __func__, intf);
4628 return -1;
4629 }
4630
4631 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4632 NL80211_CMD_VENDOR)) ||
4633 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4634 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4635 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4636 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4637 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4638 nla_put_u8(msg,
4639 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4640 cfg)) {
4641 sigma_dut_print(dut, DUT_MSG_ERROR,
4642 "%s: err in adding vendor_cmd and vendor_data",
4643 __func__);
4644 nlmsg_free(msg);
4645 return -1;
4646 }
4647 nla_nest_end(msg, params);
4648
4649 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4650 if (ret) {
4651 sigma_dut_print(dut, DUT_MSG_ERROR,
4652 "%s: err in send_and_recv_msgs, ret=%d",
4653 __func__, ret);
4654 }
4655 return ret;
4656}
4657
4658
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004659static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4660 enum he_fragmentation_val frag)
4661{
4662 struct nl_msg *msg;
4663 int ret = 0;
4664 struct nlattr *params;
4665 int ifindex;
4666
4667 ifindex = if_nametoindex(intf);
4668 if (ifindex == 0) {
4669 sigma_dut_print(dut, DUT_MSG_ERROR,
4670 "%s: Index for interface %s failed",
4671 __func__, intf);
4672 return -1;
4673 }
4674
4675 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4676 NL80211_CMD_VENDOR)) ||
4677 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4678 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4679 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4680 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4681 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4682 nla_put_u8(msg,
4683 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
4684 frag)) {
4685 sigma_dut_print(dut, DUT_MSG_ERROR,
4686 "%s: err in adding vendor_cmd and vendor_data",
4687 __func__);
4688 nlmsg_free(msg);
4689 return -1;
4690 }
4691 nla_nest_end(msg, params);
4692
4693 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4694 if (ret) {
4695 sigma_dut_print(dut, DUT_MSG_ERROR,
4696 "%s: err in send_and_recv_msgs, ret=%d",
4697 __func__, ret);
4698 }
4699 return ret;
4700}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004701
4702
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08004703int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
4704 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004705{
4706 struct nl_msg *msg;
4707 int ret = 0;
4708 struct nlattr *params;
4709 int ifindex;
4710
4711 ifindex = if_nametoindex(intf);
4712 if (ifindex == 0) {
4713 sigma_dut_print(dut, DUT_MSG_ERROR,
4714 "%s: Index for interface %s failed",
4715 __func__, intf);
4716 return -1;
4717 }
4718
4719 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4720 NL80211_CMD_VENDOR)) ||
4721 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4722 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4723 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4724 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4725 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4726 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
4727 ltf)) {
4728 sigma_dut_print(dut, DUT_MSG_ERROR,
4729 "%s: err in adding vendor_cmd and vendor_data",
4730 __func__);
4731 nlmsg_free(msg);
4732 return -1;
4733 }
4734 nla_nest_end(msg, params);
4735
4736 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4737 if (ret) {
4738 sigma_dut_print(dut, DUT_MSG_ERROR,
4739 "%s: err in send_and_recv_msgs, ret=%d",
4740 __func__, ret);
4741 }
4742 return ret;
4743}
4744
4745
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004746static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4747 int noack, enum qca_wlan_ac_type ac)
4748{
4749 struct nl_msg *msg;
4750 int ret = 0;
4751 struct nlattr *params;
4752 int ifindex;
4753
4754 ifindex = if_nametoindex(intf);
4755 if (ifindex == 0) {
4756 sigma_dut_print(dut, DUT_MSG_ERROR,
4757 "%s: Index for interface %s failed",
4758 __func__, intf);
4759 return -1;
4760 }
4761
4762 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4763 NL80211_CMD_VENDOR)) ||
4764 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4765 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4766 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4767 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4768 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4769 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4770 noack) ||
4771 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4772 ac)) {
4773 sigma_dut_print(dut, DUT_MSG_ERROR,
4774 "%s: err in adding vendor_cmd and vendor_data",
4775 __func__);
4776 nlmsg_free(msg);
4777 return -1;
4778 }
4779 nla_nest_end(msg, params);
4780
4781 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4782 if (ret) {
4783 sigma_dut_print(dut, DUT_MSG_ERROR,
4784 "%s: err in send_and_recv_msgs, ret=%d",
4785 __func__, ret);
4786 }
4787 return ret;
4788}
4789
4790
4791static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4792 const char *val)
4793{
4794 int noack, ret;
4795 char token[100];
4796 char *result;
4797 char *saveptr;
4798 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4799
4800 strlcpy(token, val, sizeof(token));
4801 token[sizeof(token) - 1] = '\0';
4802 result = strtok_r(token, ":", &saveptr);
4803 while (result) {
4804 noack = strcasecmp(result, "Disable") != 0;
4805 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4806 if (ret) {
4807 sigma_dut_print(dut, DUT_MSG_ERROR,
4808 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4809 ac, ret);
4810 }
4811 result = strtok_r(NULL, ":", &saveptr);
4812 ac++;
4813 }
4814}
4815
Vinita S. Maloo7462e812020-05-22 15:16:04 +05304816
4817static int nlvendor_sta_set_phymode(struct sigma_dut *dut, const char *intf,
4818 enum qca_wlan_vendor_phy_mode val)
4819{
4820 struct nl_msg *msg;
4821 struct nlattr *params;
4822 int ifindex, ret;
4823
4824 ifindex = if_nametoindex(intf);
4825 if (ifindex == 0) {
4826 sigma_dut_print(dut, DUT_MSG_ERROR,
4827 "%s: Index for interface %s not found",
4828 __func__, intf);
4829 return -1;
4830 }
4831
4832 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4833 NL80211_CMD_VENDOR);
4834 if (!msg) {
4835 sigma_dut_print(dut, DUT_MSG_ERROR,
4836 "%s: err in adding vendor_cmd", __func__);
4837 return -1;
4838 }
4839
4840 if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4841 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4842 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) {
4843 sigma_dut_print(dut, DUT_MSG_ERROR,
4844 "%s: err in adding vendor_attr", __func__);
4845 nlmsg_free(msg);
4846 return -1;
4847 }
4848
4849 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
4850 if (!params || nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_PHY_MODE,
4851 val)) {
4852 sigma_dut_print(dut, DUT_MSG_ERROR,
4853 "%s: err in adding vendor_data", __func__);
4854 nlmsg_free(msg);
4855 return -1;
4856 }
4857
4858 nla_nest_end(msg, params);
4859 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4860 if (ret) {
4861 sigma_dut_print(dut, DUT_MSG_ERROR,
4862 "%s: err in send_and_recv_msgs, ret=%d (%s)",
4863 __func__, ret, strerror(-ret));
4864 return ret;
4865 }
4866
4867 return 0;
4868}
4869
4870
4871static enum qca_wlan_vendor_phy_mode get_qca_vendor_phymode(const char *val)
4872{
4873 if (strcmp(val, "11a") == 0) {
4874 /* IEEE80211_MODE_11A */
4875 return QCA_WLAN_VENDOR_PHY_MODE_11A;
4876 }
4877
4878 if (strcmp(val, "11g") == 0) {
4879 /* IEEE80211_MODE_11G */
4880 return QCA_WLAN_VENDOR_PHY_MODE_11G;
4881 }
4882
4883 if (strcmp(val, "11b") == 0) {
4884 /* IEEE80211_MODE_11B */
4885 return QCA_WLAN_VENDOR_PHY_MODE_11B;
4886 }
4887
4888 if (strcmp(val, "11n") == 0 ||
4889 strcmp(val, "11nl") == 0 ||
4890 strcmp(val, "11nl(nabg)") == 0) {
4891 /* IEEE80211_MODE_11AGN */
4892 return QCA_WLAN_VENDOR_PHY_MODE_11AGN;
4893 }
4894
4895 if (strcmp(val, "11ng") == 0) {
4896 /* IEEE80211_MODE_11NG_HT40 */
4897 return QCA_WLAN_VENDOR_PHY_MODE_11NG_HT40;
4898 }
4899
4900 if (strcmp(val, "AC") == 0 ||
4901 strcasecmp(val, "11AC") == 0) {
4902 /* IEEE80211_MODE_11AC_VHT80 */
4903 return QCA_WLAN_VENDOR_PHY_MODE_11AC_VHT80;
4904 }
4905
4906 if (strcmp(val, "11na") == 0 ||
4907 strcasecmp(val, "11an") == 0) {
4908 /* IEEE80211_MODE_11NA_HT40 */
4909 return QCA_WLAN_VENDOR_PHY_MODE_11NA_HT40;
4910 }
4911
4912 if (strcmp(val, "11ax") == 0 ||
4913 strcmp(val, "auto") == 0) {
4914 /* IEEE80211_MODE_AUTO */
4915 return QCA_WLAN_VENDOR_PHY_MODE_AUTO;
4916 }
4917
4918 return -1;
4919}
4920
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004921#endif /* NL80211_SUPPORT */
4922
4923
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05304924static int get_phymode(const char *val)
4925{
4926 if (strcmp(val, "11a") == 0)
4927 return 1; /* IEEE80211_MODE_11A */
4928 if (strcmp(val, "11g") == 0)
4929 return 3; /* IEEE80211_MODE_11G */
4930 if (strcmp(val, "11b") == 0)
4931 return 2; /* IEEE80211_MODE_11B */
4932 if (strcmp(val, "11n") == 0 ||
4933 strcmp(val, "11nl") == 0 ||
4934 strcmp(val, "11nl(nabg)") == 0)
4935 return 22; /* IEEE80211_MODE_11AGN */
4936 if (strcmp(val, "11ng") == 0)
4937 return 13; /* IEEE80211_MODE_11NG_HT40 */
4938 if (strcmp(val, "AC") == 0 ||
4939 strcasecmp(val, "11AC") == 0)
4940 return 19; /* IEEE80211_MODE_11AC_VHT80 */
4941 if (strcmp(val, "11na") == 0 ||
4942 strcasecmp(val, "11an") == 0)
4943 return 14; /* IEEE80211_MODE_11NA_HT40 */
4944 if (strcmp(val, "11ax") == 0 ||
4945 strcmp(val, "auto") == 0)
4946 return 0; /* IEEE80211_MODE_AUTO */
4947 return -1;
4948}
4949
4950
4951static void sta_set_phymode(struct sigma_dut *dut, const char *intf,
4952 const char *val)
4953{
4954 char buf[100];
4955 int len, phymode;
Vinita S. Maloo7462e812020-05-22 15:16:04 +05304956#ifdef NL80211_SUPPORT
4957 enum qca_wlan_vendor_phy_mode qca_phymode;
4958
4959 qca_phymode = get_qca_vendor_phymode(val);
4960 if (qca_phymode == -1) {
4961 sigma_dut_print(dut, DUT_MSG_DEBUG,
4962 "Ignoring mode change for mode: %s",
4963 val);
4964 return;
4965 }
4966
4967 if (nlvendor_sta_set_phymode(dut, intf, qca_phymode) == 0)
4968 return;
4969#endif /* NL80211_SUPPORT */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05304970
4971 phymode = get_phymode(val);
4972 if (phymode == -1) {
4973 sigma_dut_print(dut, DUT_MSG_DEBUG,
4974 "Ignoring mode change for mode: %s",
4975 val);
4976 return;
4977 }
4978
4979 len = snprintf(buf, sizeof(buf), "iwpriv %s setphymode %d", intf,
4980 phymode);
4981 if (len < 0 || len >= sizeof(buf)) {
4982 sigma_dut_print(dut, DUT_MSG_ERROR,
4983 "Failed to set phymode");
4984 return;
4985 }
4986
4987 if (system(buf) != 0)
4988 sigma_dut_print(dut, DUT_MSG_ERROR,
4989 "iwpriv setting of phymode failed");
4990}
4991
4992
Jouni Malinenf7222712019-06-13 01:50:21 +03004993static enum sigma_cmd_result
4994cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
4995 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004996{
4997 const char *intf = get_param(cmd, "Interface");
4998 const char *val;
4999
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03005000 val = get_param(cmd, "FT_DS");
5001 if (val) {
5002 if (strcasecmp(val, "Enable") == 0) {
5003 dut->sta_ft_ds = 1;
5004 } else if (strcasecmp(val, "Disable") == 0) {
5005 dut->sta_ft_ds = 0;
5006 } else {
5007 send_resp(dut, conn, SIGMA_ERROR,
5008 "errorCode,Unsupported value for FT_DS");
5009 return STATUS_SENT_ERROR;
5010 }
5011 }
5012
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005013 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03005014 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
5015 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005016 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
5017 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005018
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005019 if (val && strcasecmp(val, "LOC") == 0)
5020 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02005021 if (val && strcasecmp(val, "60GHZ") == 0) {
5022 val = get_param(cmd, "WPS");
5023 if (val && strcasecmp(val, "disable") == 0) {
5024 dut->wps_disable = 1;
5025 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
5026 } else {
5027 /* wps_disable can have other value from the previous
5028 * test, so make sure it has the correct value.
5029 */
5030 dut->wps_disable = 0;
5031 }
5032
5033 val = get_param(cmd, "P2P");
5034 if (val && strcasecmp(val, "disable") == 0)
5035 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
5036 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005037
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02005038 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
5039 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
5040
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005041#ifdef ANDROID_NAN
5042 if (val && strcasecmp(val, "NAN") == 0)
5043 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
5044#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005045#ifdef MIRACAST
5046 if (val && (strcasecmp(val, "WFD") == 0 ||
5047 strcasecmp(val, "DisplayR2") == 0))
5048 return miracast_preset_testparameters(dut, conn, cmd);
5049#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005050
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07005051 if (val &&
5052 (strcasecmp(val, "MBO") == 0 || strcasecmp(val, "HE") == 0)) {
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305053 val = get_param(cmd, "Cellular_Data_Cap");
5054 if (val &&
5055 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
5056 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05305057
5058 val = get_param(cmd, "Ch_Pref");
5059 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
5060 return 0;
5061
Ashwini Patilc63161e2017-04-13 16:30:23 +05305062 val = get_param(cmd, "BSS_Transition");
5063 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
5064 return 0;
5065
Ashwini Patila75de5a2017-04-13 16:35:05 +05305066 val = get_param(cmd, "Assoc_Disallow");
5067 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
5068 return 0;
5069
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305070 val = get_param(cmd, "Roaming");
5071 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
5072 return 0;
5073
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305074 return 1;
5075 }
5076
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305077 if (val && strcasecmp(val, "OCE") == 0)
5078 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
5079
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005080#if 0
5081 val = get_param(cmd, "Supplicant");
5082 if (val && strcasecmp(val, "Default") != 0) {
5083 send_resp(dut, conn, SIGMA_ERROR,
5084 "ErrorCode,Only default(Vendor) supplicant "
5085 "supported");
5086 return 0;
5087 }
5088#endif
5089
5090 val = get_param(cmd, "RTS");
5091 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005092 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005093 case DRIVER_ATHEROS:
5094 ath_sta_set_rts(dut, intf, val);
5095 break;
5096 default:
5097#if 0
5098 send_resp(dut, conn, SIGMA_ERROR,
5099 "ErrorCode,Setting RTS not supported");
5100 return 0;
5101#else
5102 sigma_dut_print(dut, DUT_MSG_DEBUG,
5103 "Setting RTS not supported");
5104 break;
5105#endif
5106 }
5107 }
5108
5109#if 0
5110 val = get_param(cmd, "FRGMNT");
5111 if (val) {
5112 /* TODO */
5113 send_resp(dut, conn, SIGMA_ERROR,
5114 "ErrorCode,Setting FRGMNT not supported");
5115 return 0;
5116 }
5117#endif
5118
5119#if 0
5120 val = get_param(cmd, "Preamble");
5121 if (val) {
5122 /* TODO: Long/Short */
5123 send_resp(dut, conn, SIGMA_ERROR,
5124 "ErrorCode,Setting Preamble not supported");
5125 return 0;
5126 }
5127#endif
5128
5129 val = get_param(cmd, "Mode");
5130 if (val) {
5131 if (strcmp(val, "11b") == 0 ||
5132 strcmp(val, "11g") == 0 ||
5133 strcmp(val, "11a") == 0 ||
5134 strcmp(val, "11n") == 0 ||
5135 strcmp(val, "11ng") == 0 ||
5136 strcmp(val, "11nl") == 0 ||
5137 strcmp(val, "11nl(nabg)") == 0 ||
5138 strcmp(val, "AC") == 0 ||
5139 strcmp(val, "11AC") == 0 ||
5140 strcmp(val, "11ac") == 0 ||
5141 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08005142 strcmp(val, "11an") == 0 ||
5143 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005144 /* STA supports all modes by default */
5145 } else {
5146 send_resp(dut, conn, SIGMA_ERROR,
5147 "ErrorCode,Setting Mode not supported");
5148 return 0;
5149 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005150
5151 /* Change the mode only in case of testbed for HE program
5152 * and for 11a and 11g modes only. */
5153 if (dut->program == PROGRAM_HE &&
5154 dut->device_type == STA_testbed) {
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305155 sta_set_phymode(dut, intf, val);
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005156 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005157 }
5158
5159 val = get_param(cmd, "wmm");
5160 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005161 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005162 case DRIVER_ATHEROS:
5163 ath_sta_set_wmm(dut, intf, val);
5164 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005165 case DRIVER_WCN:
5166 wcn_sta_set_wmm(dut, intf, val);
5167 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005168 default:
5169 sigma_dut_print(dut, DUT_MSG_DEBUG,
5170 "Setting wmm not supported");
5171 break;
5172 }
5173 }
5174
5175 val = get_param(cmd, "Powersave");
5176 if (val) {
5177 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005178 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305179 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005180 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005181 }
5182
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005183 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005184 "P2P_SET ps 0") < 0)
5185 return -2;
5186 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005187 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5188 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005189 } else if (strcmp(val, "1") == 0 ||
5190 strcasecmp(val, "PSPoll") == 0 ||
5191 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005192 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305193 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005194 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005195 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005196 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005197 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005198 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005199 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005200 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005201 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005202 "P2P_SET ps 99") < 0)
5203 return -2;
5204 } else if (strcmp(val, "2") == 0 ||
5205 strcasecmp(val, "Fast") == 0) {
5206 /* TODO */
5207 send_resp(dut, conn, SIGMA_ERROR,
5208 "ErrorCode,Powersave=Fast not supported");
5209 return 0;
5210 } else if (strcmp(val, "3") == 0 ||
5211 strcasecmp(val, "PSNonPoll") == 0) {
5212 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005213 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5214 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005215
5216 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005217 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005218 "P2P_SET ps 1") < 0)
5219 return -2;
5220 } else
5221 return -1;
5222 }
5223
5224 val = get_param(cmd, "NoAck");
5225 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005226 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005227 case DRIVER_ATHEROS:
5228 ath_sta_set_noack(dut, intf, val);
5229 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005230#ifdef NL80211_SUPPORT
5231 case DRIVER_WCN:
5232 wcn_sta_set_noack(dut, intf, val);
5233 break;
5234#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005235 default:
5236 send_resp(dut, conn, SIGMA_ERROR,
5237 "ErrorCode,Setting NoAck not supported");
5238 return 0;
5239 }
5240 }
5241
5242 val = get_param(cmd, "IgnoreChswitchProhibit");
5243 if (val) {
5244 /* TODO: Enabled/disabled */
5245 if (strcasecmp(val, "Enabled") == 0) {
5246 send_resp(dut, conn, SIGMA_ERROR,
5247 "ErrorCode,Enabling IgnoreChswitchProhibit "
5248 "not supported");
5249 return 0;
5250 }
5251 }
5252
5253 val = get_param(cmd, "TDLS");
5254 if (val) {
5255 if (strcasecmp(val, "Disabled") == 0) {
5256 if (wpa_command(intf, "SET tdls_disabled 1")) {
5257 send_resp(dut, conn, SIGMA_ERROR,
5258 "ErrorCode,Failed to disable TDLS");
5259 return 0;
5260 }
5261 } else if (strcasecmp(val, "Enabled") == 0) {
5262 if (wpa_command(intf, "SET tdls_disabled 0")) {
5263 send_resp(dut, conn, SIGMA_ERROR,
5264 "ErrorCode,Failed to enable TDLS");
5265 return 0;
5266 }
5267 } else {
5268 send_resp(dut, conn, SIGMA_ERROR,
5269 "ErrorCode,Unsupported TDLS value");
5270 return 0;
5271 }
5272 }
5273
5274 val = get_param(cmd, "TDLSmode");
5275 if (val) {
5276 if (strcasecmp(val, "Default") == 0) {
5277 wpa_command(intf, "SET tdls_testing 0");
5278 } else if (strcasecmp(val, "APProhibit") == 0) {
5279 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5280 send_resp(dut, conn, SIGMA_ERROR,
5281 "ErrorCode,Failed to enable ignore "
5282 "APProhibit TDLS mode");
5283 return 0;
5284 }
5285 } else if (strcasecmp(val, "HiLoMac") == 0) {
5286 /* STA should respond with TDLS setup req for a TDLS
5287 * setup req */
5288 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5289 send_resp(dut, conn, SIGMA_ERROR,
5290 "ErrorCode,Failed to enable HiLoMac "
5291 "TDLS mode");
5292 return 0;
5293 }
5294 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5295 /*
5296 * Since all security modes are enabled by default when
5297 * Sigma control is used, there is no need to do
5298 * anything here.
5299 */
5300 } else if (strcasecmp(val, "ExistLink") == 0) {
5301 /*
5302 * Since we allow new TDLS Setup Request even if there
5303 * is an existing link, nothing needs to be done for
5304 * this.
5305 */
5306 } else {
5307 /* TODO:
5308 * ExistLink: STA should send TDLS setup req even if
5309 * direct link already exists
5310 */
5311 send_resp(dut, conn, SIGMA_ERROR,
5312 "ErrorCode,Unsupported TDLSmode value");
5313 return 0;
5314 }
5315 }
5316
5317 val = get_param(cmd, "FakePubKey");
5318 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5319 send_resp(dut, conn, SIGMA_ERROR,
5320 "ErrorCode,Failed to enable FakePubKey");
5321 return 0;
5322 }
5323
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005324#ifdef NL80211_SUPPORT
5325 val = get_param(cmd, "FrgmntSupport");
5326 if (val) {
5327 if (strcasecmp(val, "Enable") == 0) {
5328 if (sta_set_he_fragmentation(dut, intf,
5329 HE_FRAG_LEVEL1)) {
5330 send_resp(dut, conn, SIGMA_ERROR,
5331 "ErrorCode,Failed to enable HE Fragmentation");
5332 return 0;
5333 }
5334 } else if (strcasecmp(val, "Disable") == 0) {
5335 if (sta_set_he_fragmentation(dut, intf,
5336 HE_FRAG_DISABLE)) {
5337 send_resp(dut, conn, SIGMA_ERROR,
5338 "ErrorCode,Failed to disable HE Fragmentation");
5339 return 0;
5340 }
5341 }
5342 }
5343#endif /* NL80211_SUPPORT */
5344
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305345 val = get_param(cmd, "IncludeMSCSDescriptor");
5346 if (val && strcasecmp(val, "1") == 0) {
5347 char buf[128];
5348 int len;
5349
5350 len = snprintf(buf, sizeof(buf),
5351 "MSCS add up_bitmap=0xF0 up_limit=7 stream_timeout=60000 frame_classifier=045F%032x",
5352 0);
5353
5354 if (len < 0 || len >= sizeof(buf)) {
5355 sigma_dut_print(dut, DUT_MSG_ERROR,
5356 "Failed to build MSCS Descriptor IE");
5357 return ERROR_SEND_STATUS;
5358 }
5359
5360 if (wpa_command(intf, buf) != 0) {
5361 send_resp(dut, conn, SIGMA_ERROR,
5362 "ErrorCode,Failed to include MSCS descriptor");
5363 return STATUS_SENT_ERROR;
5364 }
5365 }
5366
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005367 return 1;
5368}
5369
5370
5371static const char * ath_get_radio_name(const char *radio_name)
5372{
5373 if (radio_name == NULL)
5374 return "wifi0";
5375 if (strcmp(radio_name, "wifi1") == 0)
5376 return "wifi1";
5377 if (strcmp(radio_name, "wifi2") == 0)
5378 return "wifi2";
5379 return "wifi0";
5380}
5381
5382
5383static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5384 const char *val)
5385{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005386 unsigned int vht_mcsmap = 0;
5387 int txchainmask = 0;
5388 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5389
5390 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5391 if (dut->testbed_flag_txsp == 1) {
5392 vht_mcsmap = 0xfffc;
5393 dut->testbed_flag_txsp = 0;
5394 } else {
5395 vht_mcsmap = 0xfffe;
5396 }
5397 txchainmask = 1;
5398 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5399 if (dut->testbed_flag_txsp == 1) {
5400 vht_mcsmap = 0xfff0;
5401 dut->testbed_flag_txsp = 0;
5402 } else {
5403 vht_mcsmap = 0xfffa;
5404 }
5405 txchainmask = 3;
5406 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5407 if (dut->testbed_flag_txsp == 1) {
5408 vht_mcsmap = 0xffc0;
5409 dut->testbed_flag_txsp = 0;
5410 } else {
5411 vht_mcsmap = 0xffea;
5412 }
5413 txchainmask = 7;
5414 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5415 if (dut->testbed_flag_txsp == 1) {
5416 vht_mcsmap = 0xff00;
5417 dut->testbed_flag_txsp = 0;
5418 } else {
5419 vht_mcsmap = 0xffaa;
5420 }
5421 txchainmask = 15;
5422 } else {
5423 if (dut->testbed_flag_txsp == 1) {
5424 vht_mcsmap = 0xffc0;
5425 dut->testbed_flag_txsp = 0;
5426 } else {
5427 vht_mcsmap = 0xffea;
5428 }
5429 }
5430
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005431 if (txchainmask)
5432 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005433
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005434 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005435}
5436
5437
5438static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5439 const char *val)
5440{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005441 unsigned int vht_mcsmap = 0;
5442 int rxchainmask = 0;
5443 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5444
5445 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5446 if (dut->testbed_flag_rxsp == 1) {
5447 vht_mcsmap = 0xfffc;
5448 dut->testbed_flag_rxsp = 0;
5449 } else {
5450 vht_mcsmap = 0xfffe;
5451 }
5452 rxchainmask = 1;
5453 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5454 if (dut->testbed_flag_rxsp == 1) {
5455 vht_mcsmap = 0xfff0;
5456 dut->testbed_flag_rxsp = 0;
5457 } else {
5458 vht_mcsmap = 0xfffa;
5459 }
5460 rxchainmask = 3;
5461 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5462 if (dut->testbed_flag_rxsp == 1) {
5463 vht_mcsmap = 0xffc0;
5464 dut->testbed_flag_rxsp = 0;
5465 } else {
5466 vht_mcsmap = 0xffea;
5467 }
5468 rxchainmask = 7;
5469 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5470 if (dut->testbed_flag_rxsp == 1) {
5471 vht_mcsmap = 0xff00;
5472 dut->testbed_flag_rxsp = 0;
5473 } else {
5474 vht_mcsmap = 0xffaa;
5475 }
5476 rxchainmask = 15;
5477 } else {
5478 if (dut->testbed_flag_rxsp == 1) {
5479 vht_mcsmap = 0xffc0;
5480 dut->testbed_flag_rxsp = 0;
5481 } else {
5482 vht_mcsmap = 0xffea;
5483 }
5484 }
5485
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005486 if (rxchainmask)
5487 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005488
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005489 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005490}
5491
5492
5493void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5494{
5495 if (strcasecmp(val, "enable") == 0) {
5496 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5497 != 0) {
5498 sigma_dut_print(dut, DUT_MSG_ERROR,
5499 "Disable BB_VHTSIGB_CRC_CALC failed");
5500 }
5501
5502 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5503 != 0) {
5504 sigma_dut_print(dut, DUT_MSG_ERROR,
5505 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5506 }
5507 } else {
5508 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5509 != 0) {
5510 sigma_dut_print(dut, DUT_MSG_ERROR,
5511 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5512 }
5513
5514 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5515 != 0) {
5516 sigma_dut_print(dut, DUT_MSG_ERROR,
5517 "Enable BB_VHTSIGB_CRC_CALC failed");
5518 }
5519 }
5520}
5521
5522
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005523static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5524 const char *val)
5525{
5526 char buf[60];
5527
5528 if (strcmp(val, "20") == 0) {
5529 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5530 dut->chwidth = 0;
5531 } else if (strcmp(val, "40") == 0) {
5532 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5533 dut->chwidth = 1;
5534 } else if (strcmp(val, "80") == 0) {
5535 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5536 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305537 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005538 buf[0] = '\0';
5539 } else {
5540 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5541 val);
5542 return -1;
5543 }
5544
5545 if (buf[0] != '\0' && system(buf) != 0) {
5546 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5547 return -1;
5548 }
5549
5550 return 0;
5551}
5552
5553
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005554static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5555 const char *intf, int addbareject)
5556{
5557#ifdef NL80211_SUPPORT
5558 struct nl_msg *msg;
5559 int ret = 0;
5560 struct nlattr *params;
5561 int ifindex;
5562
5563 ifindex = if_nametoindex(intf);
5564 if (ifindex == 0) {
5565 sigma_dut_print(dut, DUT_MSG_ERROR,
5566 "%s: Index for interface %s failed",
5567 __func__, intf);
5568 return -1;
5569 }
5570
5571 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5572 NL80211_CMD_VENDOR)) ||
5573 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5574 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5575 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5576 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5577 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5578 nla_put_u8(msg,
5579 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5580 !addbareject)) {
5581 sigma_dut_print(dut, DUT_MSG_ERROR,
5582 "%s: err in adding vendor_cmd and vendor_data",
5583 __func__);
5584 nlmsg_free(msg);
5585 return -1;
5586 }
5587 nla_nest_end(msg, params);
5588
5589 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5590 if (ret) {
5591 sigma_dut_print(dut, DUT_MSG_ERROR,
5592 "%s: err in send_and_recv_msgs, ret=%d",
5593 __func__, ret);
5594 }
5595 return ret;
5596#else /* NL80211_SUPPORT */
5597 sigma_dut_print(dut, DUT_MSG_ERROR,
5598 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5599 return -1;
5600#endif /* NL80211_SUPPORT */
5601}
5602
5603
5604static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5605 int addbareject)
5606{
5607 int ret;
5608
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005609 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005610 case DRIVER_WCN:
5611 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5612 if (ret) {
5613 sigma_dut_print(dut, DUT_MSG_ERROR,
5614 "nlvendor_sta_set_addba_reject failed, ret:%d",
5615 ret);
5616 return ret;
5617 }
5618 break;
5619 default:
5620 sigma_dut_print(dut, DUT_MSG_ERROR,
5621 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5622 ret = -1;
5623 break;
5624 }
5625
5626 return ret;
5627}
5628
5629
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005630static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5631 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005632{
5633#ifdef NL80211_SUPPORT
5634 struct nl_msg *msg;
5635 int ret = 0;
5636 struct nlattr *params;
5637 int ifindex;
5638
5639 ifindex = if_nametoindex(intf);
5640 if (ifindex == 0) {
5641 sigma_dut_print(dut, DUT_MSG_ERROR,
5642 "%s: Index for interface %s failed",
5643 __func__, intf);
5644 return -1;
5645 }
5646
5647 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5648 NL80211_CMD_VENDOR)) ||
5649 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5650 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5651 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5652 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5653 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5654 nla_put_u8(msg,
5655 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005656 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005657 sigma_dut_print(dut, DUT_MSG_ERROR,
5658 "%s: err in adding vendor_cmd and vendor_data",
5659 __func__);
5660 nlmsg_free(msg);
5661 return -1;
5662 }
5663 nla_nest_end(msg, params);
5664
5665 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5666 if (ret) {
5667 sigma_dut_print(dut, DUT_MSG_ERROR,
5668 "%s: err in send_and_recv_msgs, ret=%d",
5669 __func__, ret);
5670 }
5671 return ret;
5672#else /* NL80211_SUPPORT */
5673 sigma_dut_print(dut, DUT_MSG_ERROR,
5674 "Disable addba not possible without NL80211_SUPPORT defined");
5675 return -1;
5676#endif /* NL80211_SUPPORT */
5677}
5678
5679
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305680#ifdef NL80211_SUPPORT
5681static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5682{
5683 struct nl_msg *msg;
5684 int ret = 0;
5685 int ifindex;
5686
5687 ifindex = if_nametoindex(intf);
5688 if (ifindex == 0) {
5689 sigma_dut_print(dut, DUT_MSG_ERROR,
5690 "%s: Index for interface %s failed",
5691 __func__, intf);
5692 return -1;
5693 }
5694
5695 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5696 NL80211_CMD_SET_WIPHY)) ||
5697 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5698 sigma_dut_print(dut, DUT_MSG_ERROR,
5699 "%s: err in adding RTS threshold",
5700 __func__);
5701 nlmsg_free(msg);
5702 return -1;
5703 }
5704
5705 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5706 if (ret) {
5707 sigma_dut_print(dut, DUT_MSG_ERROR,
5708 "%s: err in send_and_recv_msgs, ret=%d",
5709 __func__, ret);
5710 }
5711 return ret;
5712}
5713#endif /* NL80211_SUPPORT */
5714
5715
5716static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5717{
5718 char buf[100];
5719
5720#ifdef NL80211_SUPPORT
5721 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5722 return 0;
5723 sigma_dut_print(dut, DUT_MSG_DEBUG,
5724 "Fall back to using iwconfig for setting RTS threshold");
5725#endif /* NL80211_SUPPORT */
5726
5727 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5728 if (system(buf) != 0) {
5729 sigma_dut_print(dut, DUT_MSG_ERROR,
5730 "Failed to set RTS threshold %d", val);
5731 return -1;
5732 }
5733 return 0;
5734}
5735
5736
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005737static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5738 struct sigma_conn *conn,
5739 struct sigma_cmd *cmd)
5740{
5741 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005742 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005743 char buf[128];
5744 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005745
5746 val = get_param(cmd, "40_INTOLERANT");
5747 if (val) {
5748 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5749 /* TODO: iwpriv ht40intol through wpa_supplicant */
5750 send_resp(dut, conn, SIGMA_ERROR,
5751 "ErrorCode,40_INTOLERANT not supported");
5752 return 0;
5753 }
5754 }
5755
5756 val = get_param(cmd, "ADDBA_REJECT");
5757 if (val) {
5758 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5759 /* reject any ADDBA with status "decline" */
5760 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005761 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005762 } else {
5763 /* accept ADDBA */
5764 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005765 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005766 }
5767 }
5768
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005769 if (addbareject >= 0 &&
5770 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5771 send_resp(dut, conn, SIGMA_ERROR,
5772 "ErrorCode,set addba_reject failed");
5773 return 0;
5774 }
5775
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005776 val = get_param(cmd, "AMPDU");
5777 if (val) {
5778 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5779 /* enable AMPDU Aggregation */
5780 if (ampdu == 0) {
5781 send_resp(dut, conn, SIGMA_ERROR,
5782 "ErrorCode,Mismatch in "
5783 "addba_reject/ampdu - "
5784 "not supported");
5785 return 0;
5786 }
5787 ampdu = 1;
5788 } else {
5789 /* disable AMPDU Aggregation */
5790 if (ampdu == 1) {
5791 send_resp(dut, conn, SIGMA_ERROR,
5792 "ErrorCode,Mismatch in "
5793 "addba_reject/ampdu - "
5794 "not supported");
5795 return 0;
5796 }
5797 ampdu = 0;
5798 }
5799 }
5800
5801 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005802 int ret;
5803
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005804 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5805 ampdu ? "Enabling" : "Disabling");
5806 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005807 if (wpa_command(intf, buf) < 0 &&
5808 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005809 send_resp(dut, conn, SIGMA_ERROR,
5810 "ErrorCode,set aggr failed");
5811 return 0;
5812 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005813
5814 if (ampdu == 0) {
5815 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005816 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005817 if (ret) {
5818 sigma_dut_print(dut, DUT_MSG_ERROR,
5819 "Failed to disable addba, ret:%d",
5820 ret);
5821 }
5822 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005823 }
5824
5825 val = get_param(cmd, "AMSDU");
5826 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005827 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005828 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005829 case DRIVER_WCN:
5830 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005831 break;
5832 default:
5833 if (strcmp(val, "1") == 0 ||
5834 strcasecmp(val, "Enable") == 0) {
5835 /* Enable AMSDU Aggregation */
5836 send_resp(dut, conn, SIGMA_ERROR,
5837 "ErrorCode,AMSDU aggregation not supported");
5838 return 0;
5839 }
5840 break;
5841 }
5842 }
5843
5844 val = get_param(cmd, "STBC_RX");
5845 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005846 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005847 case DRIVER_ATHEROS:
5848 ath_sta_set_stbc(dut, intf, val);
5849 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305850 case DRIVER_WCN:
5851 wcn_sta_set_stbc(dut, intf, val);
5852 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005853 default:
5854 send_resp(dut, conn, SIGMA_ERROR,
5855 "ErrorCode,STBC_RX not supported");
5856 return 0;
5857 }
5858 }
5859
5860 val = get_param(cmd, "WIDTH");
5861 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005862 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005863 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005864 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005865 send_resp(dut, conn, SIGMA_ERROR,
5866 "ErrorCode,Failed to set WIDTH");
5867 return 0;
5868 }
5869 break;
5870 case DRIVER_ATHEROS:
5871 if (ath_set_width(dut, conn, intf, val) < 0)
5872 return 0;
5873 break;
5874 default:
5875 sigma_dut_print(dut, DUT_MSG_ERROR,
5876 "Setting WIDTH not supported");
5877 break;
5878 }
5879 }
5880
5881 val = get_param(cmd, "SMPS");
5882 if (val) {
5883 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5884 send_resp(dut, conn, SIGMA_ERROR,
5885 "ErrorCode,SMPS not supported");
5886 return 0;
5887 }
5888
5889 val = get_param(cmd, "TXSP_STREAM");
5890 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005891 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005892 case DRIVER_WCN:
5893 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5894 send_resp(dut, conn, SIGMA_ERROR,
5895 "ErrorCode,Failed to set TXSP_STREAM");
5896 return 0;
5897 }
5898 break;
5899 case DRIVER_ATHEROS:
5900 ath_sta_set_txsp_stream(dut, intf, val);
5901 break;
5902 default:
5903 sigma_dut_print(dut, DUT_MSG_ERROR,
5904 "Setting TXSP_STREAM not supported");
5905 break;
5906 }
5907 }
5908
5909 val = get_param(cmd, "RXSP_STREAM");
5910 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005911 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005912 case DRIVER_WCN:
5913 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5914 send_resp(dut, conn, SIGMA_ERROR,
5915 "ErrorCode,Failed to set RXSP_STREAM");
5916 return 0;
5917 }
5918 break;
5919 case DRIVER_ATHEROS:
5920 ath_sta_set_rxsp_stream(dut, intf, val);
5921 break;
5922 default:
5923 sigma_dut_print(dut, DUT_MSG_ERROR,
5924 "Setting RXSP_STREAM not supported");
5925 break;
5926 }
5927 }
5928
5929 val = get_param(cmd, "DYN_BW_SGNL");
5930 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005931 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005932 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08005933 if (strcasecmp(val, "enable") == 0) {
5934 snprintf(buf, sizeof(buf),
5935 "iwpriv %s cwmenable 1", intf);
5936 if (system(buf) != 0) {
5937 sigma_dut_print(dut, DUT_MSG_ERROR,
5938 "iwpriv cwmenable 1 failed");
5939 return 0;
5940 }
5941 } else if (strcasecmp(val, "disable") == 0) {
5942 snprintf(buf, sizeof(buf),
5943 "iwpriv %s cwmenable 0", intf);
5944 if (system(buf) != 0) {
5945 sigma_dut_print(dut, DUT_MSG_ERROR,
5946 "iwpriv cwmenable 0 failed");
5947 return 0;
5948 }
5949 } else {
5950 sigma_dut_print(dut, DUT_MSG_ERROR,
5951 "Unsupported DYN_BW_SGL");
5952 }
5953
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005954 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5955 if (system(buf) != 0) {
5956 sigma_dut_print(dut, DUT_MSG_ERROR,
5957 "Failed to set cts_cbw in DYN_BW_SGNL");
5958 return 0;
5959 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005960 break;
5961 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005962 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005963 ath_config_dyn_bw_sig(dut, intf, val);
5964 break;
5965 default:
5966 sigma_dut_print(dut, DUT_MSG_ERROR,
5967 "Failed to set DYN_BW_SGNL");
5968 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005969 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005970 }
5971
5972 val = get_param(cmd, "RTS_FORCE");
5973 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005974 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005975 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305976 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005977 sigma_dut_print(dut, DUT_MSG_ERROR,
5978 "Failed to set RTS_FORCE 64");
5979 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03005980 res = snprintf(buf, sizeof(buf),
5981 "wifitool %s beeliner_fw_test 100 1",
5982 intf);
5983 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08005984 sigma_dut_print(dut, DUT_MSG_ERROR,
5985 "wifitool beeliner_fw_test 100 1 failed");
5986 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005987 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305988 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005989 sigma_dut_print(dut, DUT_MSG_ERROR,
5990 "Failed to set RTS_FORCE 2347");
5991 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005992 } else {
5993 send_resp(dut, conn, SIGMA_ERROR,
5994 "ErrorCode,RTS_FORCE value not supported");
5995 return 0;
5996 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005997 }
5998
5999 val = get_param(cmd, "CTS_WIDTH");
6000 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006001 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006002 case DRIVER_WCN:
6003 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
6004 send_resp(dut, conn, SIGMA_ERROR,
6005 "ErrorCode,Failed to set CTS_WIDTH");
6006 return 0;
6007 }
6008 break;
6009 case DRIVER_ATHEROS:
6010 ath_set_cts_width(dut, intf, val);
6011 break;
6012 default:
6013 sigma_dut_print(dut, DUT_MSG_ERROR,
6014 "Setting CTS_WIDTH not supported");
6015 break;
6016 }
6017 }
6018
6019 val = get_param(cmd, "BW_SGNL");
6020 if (val) {
6021 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006022 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006023 } else if (strcasecmp(val, "Disable") == 0) {
6024 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006025 } else {
6026 send_resp(dut, conn, SIGMA_ERROR,
6027 "ErrorCode,BW_SGNL value not supported");
6028 return 0;
6029 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006030 }
6031
6032 val = get_param(cmd, "Band");
6033 if (val) {
6034 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
6035 /* STA supports all bands by default */
6036 } else {
6037 send_resp(dut, conn, SIGMA_ERROR,
6038 "ErrorCode,Unsupported Band");
6039 return 0;
6040 }
6041 }
6042
6043 val = get_param(cmd, "zero_crc");
6044 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006045 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006046 case DRIVER_ATHEROS:
6047 ath_set_zero_crc(dut, val);
6048 break;
6049 default:
6050 break;
6051 }
6052 }
6053
6054 return 1;
6055}
6056
6057
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006058static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
6059{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006060 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006061#ifdef __linux__
6062 case DRIVER_WIL6210:
6063 return wil6210_set_force_mcs(dut, force, mcs);
6064#endif /* __linux__ */
6065 default:
6066 sigma_dut_print(dut, DUT_MSG_ERROR,
6067 "Unsupported sta_set_force_mcs with the current driver");
6068 return -1;
6069 }
6070}
6071
6072
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006073static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
6074{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006075 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006076#ifdef __linux__
6077 case DRIVER_WIL6210:
6078 return wil6210_force_rsn_ie(dut, state);
6079#endif /* __linux__ */
6080 default:
6081 sigma_dut_print(dut, DUT_MSG_ERROR,
6082 "Unsupported sta_60g_force_rsn_ie with the current driver");
6083 return -1;
6084 }
6085}
6086
6087
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006088static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
6089 struct sigma_cmd *cmd)
6090{
6091 const char *val;
6092 char buf[100];
6093
6094 val = get_param(cmd, "MSDUSize");
6095 if (val) {
6096 int mtu;
6097
6098 dut->amsdu_size = atoi(val);
6099 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
6100 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
6101 sigma_dut_print(dut, DUT_MSG_ERROR,
6102 "MSDUSize %d is above max %d or below min %d",
6103 dut->amsdu_size,
6104 IEEE80211_MAX_DATA_LEN_DMG,
6105 IEEE80211_SNAP_LEN_DMG);
6106 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006107 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006108 }
6109
6110 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
6111 sigma_dut_print(dut, DUT_MSG_DEBUG,
6112 "Setting amsdu_size to %d", mtu);
6113 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006114 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006115
6116 if (system(buf) != 0) {
6117 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
6118 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006119 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006120 }
6121 }
6122
6123 val = get_param(cmd, "BAckRcvBuf");
6124 if (val) {
6125 dut->back_rcv_buf = atoi(val);
6126 if (dut->back_rcv_buf == 0) {
6127 sigma_dut_print(dut, DUT_MSG_ERROR,
6128 "Failed to convert %s or value is 0",
6129 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006130 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006131 }
6132
6133 sigma_dut_print(dut, DUT_MSG_DEBUG,
6134 "Setting BAckRcvBuf to %s", val);
6135 }
6136
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006137 val = get_param(cmd, "MCS_FixedRate");
6138 if (val) {
6139 if (sta_set_force_mcs(dut, 1, atoi(val))) {
6140 sigma_dut_print(dut, DUT_MSG_ERROR,
6141 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006142 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006143 }
6144 }
6145
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006146 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006147}
6148
6149
6150static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
6151 struct sigma_cmd *cmd)
6152{
6153 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006154 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006155 const char *val;
6156 char buf[100];
6157
6158 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006159 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006160 if (wpa_command(ifname, "PING") != 0) {
6161 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006162 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006163 }
6164
6165 wpa_command(ifname, "FLUSH");
6166 net_id = add_network_common(dut, conn, ifname, cmd);
6167 if (net_id < 0) {
6168 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
6169 return net_id;
6170 }
6171
6172 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
6173 if (set_network(ifname, net_id, "mode", "2") < 0) {
6174 sigma_dut_print(dut, DUT_MSG_ERROR,
6175 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006176 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006177 }
6178
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006179 if (set_network(ifname, net_id, "pbss", "1") < 0)
6180 return -2;
6181
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006182 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006183 "Supplicant set network with mode 2. network_id %d",
6184 net_id);
6185
6186 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6187 sigma_dut_print(dut, DUT_MSG_INFO,
6188 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006189 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006190 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006191
6192 val = get_param(cmd, "Security");
6193 if (val && strcasecmp(val, "OPEN") == 0) {
6194 dut->ap_key_mgmt = AP_OPEN;
6195 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6196 sigma_dut_print(dut, DUT_MSG_ERROR,
6197 "Failed to set supplicant to %s security",
6198 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006199 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006200 }
6201 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6202 dut->ap_key_mgmt = AP_WPA2_PSK;
6203 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6204 sigma_dut_print(dut, DUT_MSG_ERROR,
6205 "Failed to set supplicant to %s security",
6206 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006207 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006208 }
6209
6210 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6211 sigma_dut_print(dut, DUT_MSG_ERROR,
6212 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006213 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006214 }
6215 } else if (val) {
6216 sigma_dut_print(dut, DUT_MSG_ERROR,
6217 "Requested Security %s is not supported on 60GHz",
6218 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006219 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006220 }
6221
6222 val = get_param(cmd, "Encrypt");
6223 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6224 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6225 sigma_dut_print(dut, DUT_MSG_ERROR,
6226 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006227 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006228 }
6229 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6230 sigma_dut_print(dut, DUT_MSG_ERROR,
6231 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006232 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006233 }
6234 } else if (val) {
6235 sigma_dut_print(dut, DUT_MSG_ERROR,
6236 "Requested Encrypt %s is not supported on 60 GHz",
6237 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006238 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006239 }
6240
6241 val = get_param(cmd, "PSK");
6242 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6243 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6244 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006245 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006246 }
6247
6248 /* Convert 60G channel to freq */
6249 switch (dut->ap_channel) {
6250 case 1:
6251 val = "58320";
6252 break;
6253 case 2:
6254 val = "60480";
6255 break;
6256 case 3:
6257 val = "62640";
6258 break;
6259 default:
6260 sigma_dut_print(dut, DUT_MSG_ERROR,
6261 "Failed to configure channel %d. Not supported",
6262 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006263 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006264 }
6265
6266 if (set_network(ifname, net_id, "frequency", val) < 0) {
6267 sigma_dut_print(dut, DUT_MSG_ERROR,
6268 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006269 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006270 }
6271
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006272 if (dut->eap_fragment) {
6273 sigma_dut_print(dut, DUT_MSG_DEBUG,
6274 "Set EAP fragment size to 128 bytes.");
6275 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6276 return ERROR_SEND_STATUS;
6277 }
6278
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006279 sigma_dut_print(dut, DUT_MSG_DEBUG,
6280 "Supplicant set network with frequency");
6281
6282 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6283 if (wpa_command(ifname, buf) < 0) {
6284 sigma_dut_print(dut, DUT_MSG_INFO,
6285 "Failed to select network id %d on %s",
6286 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006287 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006288 }
6289
6290 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6291
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006292 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006293}
6294
6295
Lior David67543f52017-01-03 19:04:22 +02006296static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6297{
6298 char buf[128], fname[128];
6299 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006300 int res;
Lior David67543f52017-01-03 19:04:22 +02006301
6302 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6303 sigma_dut_print(dut, DUT_MSG_ERROR,
6304 "failed to get wil6210 debugfs dir");
6305 return -1;
6306 }
6307
Jouni Malinen3aa72862019-05-29 23:14:51 +03006308 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6309 if (res < 0 || res >= sizeof(fname))
6310 return -1;
Lior David67543f52017-01-03 19:04:22 +02006311 f = fopen(fname, "w");
6312 if (!f) {
6313 sigma_dut_print(dut, DUT_MSG_ERROR,
6314 "failed to open: %s", fname);
6315 return -1;
6316 }
6317
6318 fprintf(f, "%d\n", abft_len);
6319 fclose(f);
6320
6321 return 0;
6322}
6323
6324
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006325int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6326 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006327{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006328 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006329 case DRIVER_WIL6210:
6330 return wil6210_set_abft_len(dut, abft_len);
6331 default:
6332 sigma_dut_print(dut, DUT_MSG_ERROR,
6333 "set abft_len not supported");
6334 return -1;
6335 }
6336}
6337
6338
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006339static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6340 struct sigma_cmd *cmd)
6341{
6342 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006343 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006344
6345 if (dut->dev_role != DEVROLE_PCP) {
6346 send_resp(dut, conn, SIGMA_INVALID,
6347 "ErrorCode,Invalid DevRole");
6348 return 0;
6349 }
6350
6351 val = get_param(cmd, "SSID");
6352 if (val) {
6353 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6354 send_resp(dut, conn, SIGMA_INVALID,
6355 "ErrorCode,Invalid SSID");
6356 return -1;
6357 }
6358
Peng Xub8fc5cc2017-05-10 17:27:28 -07006359 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006360 }
6361
6362 val = get_param(cmd, "CHANNEL");
6363 if (val) {
6364 const char *pos;
6365
6366 dut->ap_channel = atoi(val);
6367 pos = strchr(val, ';');
6368 if (pos) {
6369 pos++;
6370 dut->ap_channel_1 = atoi(pos);
6371 }
6372 }
6373
6374 switch (dut->ap_channel) {
6375 case 1:
6376 case 2:
6377 case 3:
6378 break;
6379 default:
6380 sigma_dut_print(dut, DUT_MSG_ERROR,
6381 "Channel %d is not supported", dut->ap_channel);
6382 send_resp(dut, conn, SIGMA_ERROR,
6383 "Requested channel is not supported");
6384 return -1;
6385 }
6386
6387 val = get_param(cmd, "BCNINT");
6388 if (val)
6389 dut->ap_bcnint = atoi(val);
6390
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006391 val = get_param(cmd, "AllocType");
6392 if (val) {
6393 send_resp(dut, conn, SIGMA_ERROR,
6394 "ErrorCode,AllocType is not supported yet");
6395 return -1;
6396 }
6397
6398 val = get_param(cmd, "PercentBI");
6399 if (val) {
6400 send_resp(dut, conn, SIGMA_ERROR,
6401 "ErrorCode,PercentBI is not supported yet");
6402 return -1;
6403 }
6404
6405 val = get_param(cmd, "CBAPOnly");
6406 if (val) {
6407 send_resp(dut, conn, SIGMA_ERROR,
6408 "ErrorCode,CBAPOnly is not supported yet");
6409 return -1;
6410 }
6411
6412 val = get_param(cmd, "AMPDU");
6413 if (val) {
6414 if (strcasecmp(val, "Enable") == 0)
6415 dut->ap_ampdu = 1;
6416 else if (strcasecmp(val, "Disable") == 0)
6417 dut->ap_ampdu = 2;
6418 else {
6419 send_resp(dut, conn, SIGMA_ERROR,
6420 "ErrorCode,AMPDU value is not Enable nor Disabled");
6421 return -1;
6422 }
6423 }
6424
6425 val = get_param(cmd, "AMSDU");
6426 if (val) {
6427 if (strcasecmp(val, "Enable") == 0)
6428 dut->ap_amsdu = 1;
6429 else if (strcasecmp(val, "Disable") == 0)
6430 dut->ap_amsdu = 2;
6431 }
6432
6433 val = get_param(cmd, "NumMSDU");
6434 if (val) {
6435 send_resp(dut, conn, SIGMA_ERROR,
6436 "ErrorCode, NumMSDU is not supported yet");
6437 return -1;
6438 }
6439
6440 val = get_param(cmd, "ABFTLRang");
6441 if (val) {
6442 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006443 "ABFTLRang parameter %s", val);
6444 if (strcmp(val, "Gt1") == 0)
6445 abft_len = 2; /* 2 slots in this case */
6446 }
6447
6448 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6449 send_resp(dut, conn, SIGMA_ERROR,
6450 "ErrorCode, Can't set ABFT length");
6451 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006452 }
6453
6454 if (sta_pcp_start(dut, conn, cmd) < 0) {
6455 send_resp(dut, conn, SIGMA_ERROR,
6456 "ErrorCode, Can't start PCP role");
6457 return -1;
6458 }
6459
6460 return sta_set_60g_common(dut, conn, cmd);
6461}
6462
6463
6464static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6465 struct sigma_cmd *cmd)
6466{
6467 const char *val = get_param(cmd, "DiscoveryMode");
6468
6469 if (dut->dev_role != DEVROLE_STA) {
6470 send_resp(dut, conn, SIGMA_INVALID,
6471 "ErrorCode,Invalid DevRole");
6472 return 0;
6473 }
6474
6475 if (val) {
6476 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6477 /* Ignore Discovery mode till Driver expose API. */
6478#if 0
6479 if (strcasecmp(val, "1") == 0) {
6480 send_resp(dut, conn, SIGMA_INVALID,
6481 "ErrorCode,DiscoveryMode 1 not supported");
6482 return 0;
6483 }
6484
6485 if (strcasecmp(val, "0") == 0) {
6486 /* OK */
6487 } else {
6488 send_resp(dut, conn, SIGMA_INVALID,
6489 "ErrorCode,DiscoveryMode not supported");
6490 return 0;
6491 }
6492#endif
6493 }
6494
6495 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006496 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006497 return sta_set_60g_common(dut, conn, cmd);
6498}
6499
6500
Jouni Malinenf7222712019-06-13 01:50:21 +03006501static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6502 struct sigma_conn *conn,
6503 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006504{
6505 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006506 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306507
Jouni Malinened77e672018-01-10 16:45:13 +02006508 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006509 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006510 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306511 wpa_command(intf, "DISCONNECT");
6512 return 1;
6513 }
6514
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006515 disconnect_station(dut);
6516 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6517 * due to cached results. */
6518 wpa_command(intf, "SET ignore_old_scan_res 1");
6519 wpa_command(intf, "BSS_FLUSH");
6520 return 1;
6521}
6522
6523
Jouni Malinenf7222712019-06-13 01:50:21 +03006524static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6525 struct sigma_conn *conn,
6526 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006527{
6528 const char *intf = get_param(cmd, "Interface");
6529 const char *bssid = get_param(cmd, "bssid");
6530 const char *val = get_param(cmd, "CHANNEL");
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006531 const char *freq_val = get_param(cmd, "ChnlFreq");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006532 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306533 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306534 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006535 int res;
6536 int chan = 0;
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006537 int freq = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006538 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306539 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006540 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006541
6542 if (bssid == NULL) {
6543 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6544 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006545 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006546 }
6547
6548 if (val)
6549 chan = atoi(val);
6550
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006551 if (freq_val)
6552 freq = atoi(freq_val);
6553
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006554 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6555 /* The current network may be from sta_associate or
6556 * sta_hs2_associate
6557 */
6558 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6559 0 ||
6560 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006561 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006562 }
6563
6564 ctrl = open_wpa_mon(intf);
6565 if (ctrl == NULL) {
6566 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6567 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006568 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006569 }
6570
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006571 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05306572 sizeof(result)) < 0 ||
6573 strncmp(result, "COMPLETED", 9) != 0) {
6574 sigma_dut_print(dut, DUT_MSG_DEBUG,
6575 "sta_reassoc: Not connected");
6576 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006577 } else if (dut->sta_ft_ds) {
6578 sigma_dut_print(dut, DUT_MSG_DEBUG,
6579 "sta_reassoc: Use FT-over-DS");
6580 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306581 }
6582
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306583 if (dut->rsne_override) {
6584#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006585 if (get_driver_type(dut) == DRIVER_WCN &&
6586 dut->config_rsnie == 0) {
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306587 sta_config_rsnie(dut, 1);
6588 dut->config_rsnie = 1;
6589 }
6590#endif /* NL80211_SUPPORT */
6591 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6592 dut->rsne_override);
6593 if (wpa_command(intf, buf) < 0) {
6594 send_resp(dut, conn, SIGMA_ERROR,
6595 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6596 return 0;
6597 }
6598 }
6599
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006600 if (ft_ds) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006601 if (chan || freq) {
6602 if (!freq)
6603 freq = channel_to_freq(dut, chan);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006604 if (!freq) {
6605 sigma_dut_print(dut, DUT_MSG_ERROR,
6606 "Invalid channel number provided: %d",
6607 chan);
6608 send_resp(dut, conn, SIGMA_INVALID,
6609 "ErrorCode,Invalid channel number");
6610 goto close_mon_conn;
6611 }
6612 res = snprintf(buf, sizeof(buf),
6613 "SCAN TYPE=ONLY freq=%d", freq);
6614 } else {
6615 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6616 }
6617 if (res < 0 || res >= (int) sizeof(buf)) {
6618 send_resp(dut, conn, SIGMA_ERROR,
6619 "ErrorCode,snprintf failed");
6620 goto close_mon_conn;
6621 }
6622 if (wpa_command(intf, buf) < 0) {
6623 sigma_dut_print(dut, DUT_MSG_INFO,
6624 "Failed to start scan");
6625 send_resp(dut, conn, SIGMA_ERROR,
6626 "ErrorCode,scan failed");
6627 goto close_mon_conn;
6628 }
6629
6630 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6631 buf, sizeof(buf));
6632 if (res < 0) {
6633 sigma_dut_print(dut, DUT_MSG_INFO,
6634 "Scan did not complete");
6635 send_resp(dut, conn, SIGMA_ERROR,
6636 "ErrorCode,scan did not complete");
6637 goto close_mon_conn;
6638 }
6639
6640 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6641 if (res > 0 && res < (int) sizeof(buf))
6642 res = wpa_command(intf, buf);
6643
6644 if (res < 0 || res >= (int) sizeof(buf)) {
6645 send_resp(dut, conn, SIGMA_ERROR,
6646 "errorCode,FT_DS command failed");
6647 status = STATUS_SENT_ERROR;
6648 goto close_mon_conn;
6649 }
6650 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006651 if (chan || freq) {
6652 if (!freq)
6653 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306654 if (!freq) {
6655 sigma_dut_print(dut, DUT_MSG_ERROR,
6656 "Invalid channel number provided: %d",
6657 chan);
6658 send_resp(dut, conn, SIGMA_INVALID,
6659 "ErrorCode,Invalid channel number");
6660 goto close_mon_conn;
6661 }
6662 res = snprintf(buf, sizeof(buf),
6663 "SCAN TYPE=ONLY freq=%d", freq);
6664 } else {
6665 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6666 }
6667 if (res < 0 || res >= (int) sizeof(buf)) {
6668 send_resp(dut, conn, SIGMA_ERROR,
6669 "ErrorCode,snprintf failed");
6670 goto close_mon_conn;
6671 }
6672 if (wpa_command(intf, buf) < 0) {
6673 sigma_dut_print(dut, DUT_MSG_INFO,
6674 "Failed to start scan");
6675 send_resp(dut, conn, SIGMA_ERROR,
6676 "ErrorCode,scan failed");
6677 goto close_mon_conn;
6678 }
6679
6680 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6681 buf, sizeof(buf));
6682 if (res < 0) {
6683 sigma_dut_print(dut, DUT_MSG_INFO,
6684 "Scan did not complete");
6685 send_resp(dut, conn, SIGMA_ERROR,
6686 "ErrorCode,scan did not complete");
6687 goto close_mon_conn;
6688 }
6689
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006690 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6691 < 0) {
6692 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6693 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006694 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306695 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006696 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306697 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006698 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306699 if (res < 0 || res >= (int) sizeof(buf) ||
6700 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006701 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306702 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306703 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006704 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006705 sigma_dut_print(dut, DUT_MSG_INFO,
6706 "sta_reassoc: Run %s successful", buf);
6707 } else if (wpa_command(intf, "REASSOCIATE")) {
6708 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6709 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306710 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006711 }
6712
6713 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6714 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306715 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006716 send_resp(dut, conn, SIGMA_ERROR,
6717 "errorCode,Connection did not complete");
6718 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306719 goto close_mon_conn;
6720 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006721 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006722
Ashwini Patil467efef2017-05-25 12:18:27 +05306723close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006724 wpa_ctrl_detach(ctrl);
6725 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306726 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006727}
6728
6729
6730static void hs2_clear_credentials(const char *intf)
6731{
6732 wpa_command(intf, "REMOVE_CRED all");
6733}
6734
6735
Lior Davidcc88b562017-01-03 18:52:09 +02006736#ifdef __linux__
6737static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6738 unsigned int *aid)
6739{
Lior David0fe101e2017-03-09 16:09:50 +02006740 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006741
Lior David0fe101e2017-03-09 16:09:50 +02006742 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006743}
6744#endif /* __linux__ */
6745
6746
6747static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6748 unsigned int *aid)
6749{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006750 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02006751#ifdef __linux__
6752 case DRIVER_WIL6210:
6753 return wil6210_get_aid(dut, bssid, aid);
6754#endif /* __linux__ */
6755 default:
6756 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6757 return -1;
6758 }
6759}
6760
6761
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006762static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6763 struct sigma_cmd *cmd)
6764{
6765 char buf[MAX_CMD_LEN];
6766 char bss_list[MAX_CMD_LEN];
6767 const char *parameter = get_param(cmd, "Parameter");
6768
6769 if (parameter == NULL)
6770 return -1;
6771
Lior Davidcc88b562017-01-03 18:52:09 +02006772 if (strcasecmp(parameter, "AID") == 0) {
6773 unsigned int aid = 0;
6774 char bssid[20];
6775
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006776 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02006777 bssid, sizeof(bssid)) < 0) {
6778 sigma_dut_print(dut, DUT_MSG_ERROR,
6779 "could not get bssid");
6780 return -2;
6781 }
6782
6783 if (sta_get_aid_60g(dut, bssid, &aid))
6784 return -2;
6785
6786 snprintf(buf, sizeof(buf), "aid,%d", aid);
6787 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6788 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6789 return 0;
6790 }
6791
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006792 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6793 char *bss_line;
6794 char *bss_id = NULL;
6795 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306796 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006797
6798 if (ifname == NULL) {
6799 sigma_dut_print(dut, DUT_MSG_INFO,
6800 "For get DiscoveredDevList need Interface name.");
6801 return -1;
6802 }
6803
6804 /*
6805 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6806 * of BSSIDs in "bssid=<BSSID>\n"
6807 */
6808 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6809 bss_list,
6810 sizeof(bss_list)) < 0) {
6811 sigma_dut_print(dut, DUT_MSG_ERROR,
6812 "Failed to get bss list");
6813 return -1;
6814 }
6815
6816 sigma_dut_print(dut, DUT_MSG_DEBUG,
6817 "bss list for ifname:%s is:%s",
6818 ifname, bss_list);
6819
6820 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306821 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006822 while (bss_line) {
6823 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6824 bss_id) {
6825 int len;
6826
6827 len = snprintf(buf + strlen(buf),
6828 sizeof(buf) - strlen(buf),
6829 ",%s", bss_id);
6830 free(bss_id);
6831 bss_id = NULL;
6832 if (len < 0) {
6833 sigma_dut_print(dut,
6834 DUT_MSG_ERROR,
6835 "Failed to read BSSID");
6836 send_resp(dut, conn, SIGMA_ERROR,
6837 "ErrorCode,Failed to read BSS ID");
6838 return 0;
6839 }
6840
6841 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6842 sigma_dut_print(dut,
6843 DUT_MSG_ERROR,
6844 "Response buf too small for list");
6845 send_resp(dut, conn,
6846 SIGMA_ERROR,
6847 "ErrorCode,Response buf too small for list");
6848 return 0;
6849 }
6850 }
6851
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306852 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006853 }
6854
6855 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6856 buf);
6857 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6858 return 0;
6859 }
6860
6861 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6862 return 0;
6863}
6864
6865
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006866static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6867 struct sigma_cmd *cmd)
6868{
6869 char buf[MAX_CMD_LEN];
6870 const char *parameter = get_param(cmd, "Parameter");
6871
6872 if (!parameter)
6873 return -1;
6874
6875 if (strcasecmp(parameter, "RSSI") == 0) {
6876 char rssi[10];
6877
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006878 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006879 rssi, sizeof(rssi)) < 0) {
6880 sigma_dut_print(dut, DUT_MSG_ERROR,
6881 "Could not get RSSI");
6882 return -2;
6883 }
6884
6885 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6886 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6887 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6888 return 0;
6889 }
6890
6891 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6892 return 0;
6893}
6894
6895
Jouni Malinenca0abd32020-02-09 20:18:10 +02006896static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
6897 struct sigma_conn *conn,
6898 struct sigma_cmd *cmd)
6899{
6900 const char *intf = get_param(cmd, "Interface");
6901 char buf[4096], bssid[20], resp[200], *pos, *tmp;
6902
6903 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
6904 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
6905 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
6906 send_resp(dut, conn, SIGMA_ERROR,
6907 "ErrorCode,PMKSA_GET not supported");
6908 return STATUS_SENT_ERROR;
6909 }
6910
6911 if (strncmp(buf, "FAIL", 4) == 0 ||
6912 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
6913 send_resp(dut, conn, SIGMA_ERROR,
6914 "ErrorCode,Could not find current network");
6915 return STATUS_SENT_ERROR;
6916 }
6917
6918 pos = buf;
6919 while (pos) {
6920 if (strncmp(pos, bssid, 17) == 0) {
6921 pos = strchr(pos, ' ');
6922 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05306923 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02006924 pos++;
6925 pos = strchr(pos, ' ');
6926 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05306927 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02006928 pos++;
6929 tmp = strchr(pos, ' ');
6930 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05306931 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02006932 *tmp = '\0';
6933 break;
6934 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02006935 pos = strchr(pos, '\n');
6936 if (pos)
6937 pos++;
6938 }
6939
6940 if (!pos) {
6941 send_resp(dut, conn, SIGMA_ERROR,
6942 "ErrorCode,PMK not available");
6943 return STATUS_SENT_ERROR;
6944 }
6945
6946 snprintf(resp, sizeof(resp), "PMK,%s", pos);
6947 send_resp(dut, conn, SIGMA_COMPLETE, resp);
6948 return STATUS_SENT;
6949}
6950
6951
Jouni Malinenf7222712019-06-13 01:50:21 +03006952static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
6953 struct sigma_conn *conn,
6954 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006955{
6956 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02006957 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006958
Jouni Malinenca0abd32020-02-09 20:18:10 +02006959 if (!parameter)
6960 return INVALID_SEND_STATUS;
6961
6962 if (strcasecmp(parameter, "PMK") == 0)
6963 return sta_get_pmk(dut, conn, cmd);
6964
6965 if (!program)
6966 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006967
6968 if (strcasecmp(program, "P2PNFC") == 0)
6969 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
6970
6971 if (strcasecmp(program, "60ghz") == 0)
6972 return sta_get_parameter_60g(dut, conn, cmd);
6973
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006974 if (strcasecmp(program, "he") == 0)
6975 return sta_get_parameter_he(dut, conn, cmd);
6976
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006977#ifdef ANDROID_NAN
6978 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07006979 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006980#endif /* ANDROID_NAN */
6981
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006982#ifdef MIRACAST
6983 if (strcasecmp(program, "WFD") == 0 ||
6984 strcasecmp(program, "DisplayR2") == 0)
6985 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
6986#endif /* MIRACAST */
6987
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006988 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6989 return 0;
6990}
6991
6992
6993static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
6994 const char *type)
6995{
6996 char buf[100];
6997
6998 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006999 run_iwpriv(dut, intf, "chwidth 2");
7000 run_iwpriv(dut, intf, "mode 11ACVHT80");
7001 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007002 }
7003
7004 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007005 run_iwpriv(dut, intf, "chwidth 0");
7006 run_iwpriv(dut, intf, "mode 11naht40");
7007 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007008 }
7009
7010 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007011 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007012
7013 /* Reset CTS width */
7014 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
7015 intf);
7016 if (system(buf) != 0) {
7017 sigma_dut_print(dut, DUT_MSG_ERROR,
7018 "wifitool %s beeliner_fw_test 54 0 failed",
7019 intf);
7020 }
7021
7022 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007023 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007024
7025 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
7026 if (system(buf) != 0) {
7027 sigma_dut_print(dut, DUT_MSG_ERROR,
7028 "iwpriv rts failed");
7029 }
7030 }
7031
7032 if (type && strcasecmp(type, "Testbed") == 0) {
7033 dut->testbed_flag_txsp = 1;
7034 dut->testbed_flag_rxsp = 1;
7035 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007036 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007037
7038 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007039 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007040
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007041 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007042
7043 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007044 run_iwpriv(dut, intf, "tx_stbc 0");
7045 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007046
7047 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007048 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007049 }
7050
7051 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007052 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07007053 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007054
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007055 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007056 }
7057}
7058
7059
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007060#ifdef NL80211_SUPPORT
7061static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
7062 enum he_mcs_config mcs)
7063{
7064 struct nl_msg *msg;
7065 int ret = 0;
7066 struct nlattr *params;
7067 int ifindex;
7068
7069 ifindex = if_nametoindex(intf);
7070 if (ifindex == 0) {
7071 sigma_dut_print(dut, DUT_MSG_ERROR,
7072 "%s: Index for interface %s failed",
7073 __func__, intf);
7074 return -1;
7075 }
7076
7077 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7078 NL80211_CMD_VENDOR)) ||
7079 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7080 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7081 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7082 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7083 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7084 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
7085 mcs)) {
7086 sigma_dut_print(dut, DUT_MSG_ERROR,
7087 "%s: err in adding vendor_cmd and vendor_data",
7088 __func__);
7089 nlmsg_free(msg);
7090 return -1;
7091 }
7092 nla_nest_end(msg, params);
7093
7094 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7095 if (ret) {
7096 sigma_dut_print(dut, DUT_MSG_ERROR,
7097 "%s: err in send_and_recv_msgs, ret=%d",
7098 __func__, ret);
7099 }
7100 return ret;
7101}
7102#endif /* NL80211_SUPPORT */
7103
7104
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007105static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
7106 const char *intf, int enable)
7107{
7108#ifdef NL80211_SUPPORT
7109 struct nl_msg *msg;
7110 int ret = 0;
7111 struct nlattr *params;
7112 int ifindex;
7113
7114 ifindex = if_nametoindex(intf);
7115 if (ifindex == 0) {
7116 sigma_dut_print(dut, DUT_MSG_ERROR,
7117 "%s: Index for interface %s failed",
7118 __func__, intf);
7119 return -1;
7120 }
7121
7122 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7123 NL80211_CMD_VENDOR)) ||
7124 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7125 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7126 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7127 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7128 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7129 nla_put_u8(msg,
7130 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
7131 enable)) {
7132 sigma_dut_print(dut, DUT_MSG_ERROR,
7133 "%s: err in adding vendor_cmd and vendor_data",
7134 __func__);
7135 nlmsg_free(msg);
7136 return -1;
7137 }
7138 nla_nest_end(msg, params);
7139
7140 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7141 if (ret) {
7142 sigma_dut_print(dut, DUT_MSG_ERROR,
7143 "%s: err in send_and_recv_msgs, ret=%d",
7144 __func__, ret);
7145 }
7146 return ret;
7147#else /* NL80211_SUPPORT */
7148 sigma_dut_print(dut, DUT_MSG_ERROR,
7149 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
7150 return -1;
7151#endif /* NL80211_SUPPORT */
7152}
7153
7154
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007155static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
7156 const char *intf, int enable)
7157{
7158#ifdef NL80211_SUPPORT
7159 struct nl_msg *msg;
7160 int ret = 0;
7161 struct nlattr *params;
7162 int ifindex;
7163
7164 ifindex = if_nametoindex(intf);
7165 if (ifindex == 0) {
7166 sigma_dut_print(dut, DUT_MSG_ERROR,
7167 "%s: Index for interface %s failed",
7168 __func__, intf);
7169 return -1;
7170 }
7171
7172 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7173 NL80211_CMD_VENDOR)) ||
7174 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7175 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7176 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7177 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7178 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7179 nla_put_u8(msg,
7180 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7181 enable)) {
7182 sigma_dut_print(dut, DUT_MSG_ERROR,
7183 "%s: err in adding vendor_cmd and vendor_data",
7184 __func__);
7185 nlmsg_free(msg);
7186 return -1;
7187 }
7188 nla_nest_end(msg, params);
7189
7190 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7191 if (ret) {
7192 sigma_dut_print(dut, DUT_MSG_ERROR,
7193 "%s: err in send_and_recv_msgs, ret=%d",
7194 __func__, ret);
7195 }
7196 return ret;
7197#else /* NL80211_SUPPORT */
7198 sigma_dut_print(dut, DUT_MSG_ERROR,
7199 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7200 return -1;
7201#endif /* NL80211_SUPPORT */
7202}
7203
7204
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007205#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007206
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007207static int sta_set_he_testbed_def(struct sigma_dut *dut,
7208 const char *intf, int cfg)
7209{
7210 struct nl_msg *msg;
7211 int ret = 0;
7212 struct nlattr *params;
7213 int ifindex;
7214
7215 ifindex = if_nametoindex(intf);
7216 if (ifindex == 0) {
7217 sigma_dut_print(dut, DUT_MSG_ERROR,
7218 "%s: Index for interface %s failed",
7219 __func__, intf);
7220 return -1;
7221 }
7222
7223 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7224 NL80211_CMD_VENDOR)) ||
7225 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7226 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7227 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7228 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7229 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7230 nla_put_u8(msg,
7231 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7232 cfg)) {
7233 sigma_dut_print(dut, DUT_MSG_ERROR,
7234 "%s: err in adding vendor_cmd and vendor_data",
7235 __func__);
7236 nlmsg_free(msg);
7237 return -1;
7238 }
7239 nla_nest_end(msg, params);
7240
7241 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7242 if (ret) {
7243 sigma_dut_print(dut, DUT_MSG_ERROR,
7244 "%s: err in send_and_recv_msgs, ret=%d",
7245 __func__, ret);
7246 }
7247 return ret;
7248}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007249
7250
7251static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7252{
7253 struct nl_msg *msg;
7254 int ret = 0;
7255 struct nlattr *params;
7256 int ifindex;
7257
7258 ifindex = if_nametoindex(intf);
7259 if (ifindex == 0) {
7260 sigma_dut_print(dut, DUT_MSG_ERROR,
7261 "%s: Index for interface %s failed",
7262 __func__, intf);
7263 return -1;
7264 }
7265
7266 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7267 NL80211_CMD_VENDOR)) ||
7268 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7269 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7270 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7271 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7272 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7273 nla_put_u8(msg,
7274 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7275 cfg)) {
7276 sigma_dut_print(dut, DUT_MSG_ERROR,
7277 "%s: err in adding vendor_cmd and vendor_data",
7278 __func__);
7279 nlmsg_free(msg);
7280 return -1;
7281 }
7282 nla_nest_end(msg, params);
7283
7284 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7285 if (ret) {
7286 sigma_dut_print(dut, DUT_MSG_ERROR,
7287 "%s: err in send_and_recv_msgs, ret=%d",
7288 __func__, ret);
7289 }
7290 return ret;
7291}
7292
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007293#endif /* NL80211_SUPPORT */
7294
7295
Qiwei Caib6806972020-01-15 13:52:11 +08007296int sta_set_addba_buf_size(struct sigma_dut *dut,
7297 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007298{
7299#ifdef NL80211_SUPPORT
7300 struct nl_msg *msg;
7301 int ret = 0;
7302 struct nlattr *params;
7303 int ifindex;
7304
7305 ifindex = if_nametoindex(intf);
7306 if (ifindex == 0) {
7307 sigma_dut_print(dut, DUT_MSG_ERROR,
7308 "%s: Index for interface %s failed",
7309 __func__, intf);
7310 return -1;
7311 }
7312
7313 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7314 NL80211_CMD_VENDOR)) ||
7315 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7316 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7317 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7318 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7319 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07007320 nla_put_u16(msg,
7321 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
7322 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007323 sigma_dut_print(dut, DUT_MSG_ERROR,
7324 "%s: err in adding vendor_cmd and vendor_data",
7325 __func__);
7326 nlmsg_free(msg);
7327 return -1;
7328 }
7329 nla_nest_end(msg, params);
7330
7331 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7332 if (ret) {
7333 sigma_dut_print(dut, DUT_MSG_ERROR,
7334 "%s: err in send_and_recv_msgs, ret=%d",
7335 __func__, ret);
7336 }
7337 return ret;
7338#else /* NL80211_SUPPORT */
7339 sigma_dut_print(dut, DUT_MSG_ERROR,
7340 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7341 return -1;
7342#endif /* NL80211_SUPPORT */
7343}
7344
7345
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007346static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
7347 int enable)
7348{
7349#ifdef NL80211_SUPPORT
7350 struct nl_msg *msg;
7351 int ret = 0;
7352 struct nlattr *params;
7353 int ifindex;
7354
7355 ifindex = if_nametoindex(intf);
7356 if (ifindex == 0) {
7357 sigma_dut_print(dut, DUT_MSG_ERROR,
7358 "%s: Index for interface %s failed",
7359 __func__, intf);
7360 return -1;
7361 }
7362
7363 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7364 NL80211_CMD_VENDOR)) ||
7365 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7366 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7367 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7368 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7369 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7370 nla_put_u8(msg,
7371 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7372 enable)) {
7373 sigma_dut_print(dut, DUT_MSG_ERROR,
7374 "%s: err in adding vendor_cmd and vendor_data",
7375 __func__);
7376 nlmsg_free(msg);
7377 return -1;
7378 }
7379 nla_nest_end(msg, params);
7380
7381 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7382 if (ret) {
7383 sigma_dut_print(dut, DUT_MSG_ERROR,
7384 "%s: err in send_and_recv_msgs, ret=%d",
7385 __func__, ret);
7386 }
7387 return ret;
7388#else /* NL80211_SUPPORT */
7389 sigma_dut_print(dut, DUT_MSG_ERROR,
7390 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7391 return -1;
7392#endif /* NL80211_SUPPORT */
7393}
7394
7395
Arif Hussain9765f7d2018-07-03 08:28:26 -07007396static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7397 int val)
7398{
7399#ifdef NL80211_SUPPORT
7400 struct nl_msg *msg;
7401 int ret = 0;
7402 struct nlattr *params;
7403 int ifindex;
7404
7405 ifindex = if_nametoindex(intf);
7406 if (ifindex == 0) {
7407 sigma_dut_print(dut, DUT_MSG_ERROR,
7408 "%s: Index for interface %s failed, val:%d",
7409 __func__, intf, val);
7410 return -1;
7411 }
7412
7413 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7414 NL80211_CMD_VENDOR)) ||
7415 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7416 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7417 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7418 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7419 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7420 nla_put_u8(msg,
7421 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7422 val)) {
7423 sigma_dut_print(dut, DUT_MSG_ERROR,
7424 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7425 __func__, val);
7426 nlmsg_free(msg);
7427 return -1;
7428 }
7429 nla_nest_end(msg, params);
7430
7431 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7432 if (ret) {
7433 sigma_dut_print(dut, DUT_MSG_ERROR,
7434 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7435 __func__, ret, val);
7436 }
7437 return ret;
7438#else /* NL80211_SUPPORT */
7439 sigma_dut_print(dut, DUT_MSG_ERROR,
7440 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7441 return -1;
7442#endif /* NL80211_SUPPORT */
7443}
7444
7445
Arif Hussain68d23f52018-07-11 13:39:08 -07007446#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007447static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7448 enum qca_wlan_he_mac_padding_dur val)
7449{
Arif Hussain68d23f52018-07-11 13:39:08 -07007450 struct nl_msg *msg;
7451 int ret = 0;
7452 struct nlattr *params;
7453 int ifindex;
7454
7455 ifindex = if_nametoindex(intf);
7456 if (ifindex == 0) {
7457 sigma_dut_print(dut, DUT_MSG_ERROR,
7458 "%s: Index for interface %s failed, val:%d",
7459 __func__, intf, val);
7460 return -1;
7461 }
7462
7463 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7464 NL80211_CMD_VENDOR)) ||
7465 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7466 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7467 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7468 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7469 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7470 nla_put_u8(msg,
7471 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
7472 val)) {
7473 sigma_dut_print(dut, DUT_MSG_ERROR,
7474 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7475 __func__, val);
7476 nlmsg_free(msg);
7477 return -1;
7478 }
7479 nla_nest_end(msg, params);
7480
7481 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7482 if (ret) {
7483 sigma_dut_print(dut, DUT_MSG_ERROR,
7484 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7485 __func__, ret, val);
7486 }
7487 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07007488}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007489#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007490
7491
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007492static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7493 int val)
7494{
7495#ifdef NL80211_SUPPORT
7496 struct nl_msg *msg;
7497 int ret = 0;
7498 struct nlattr *params;
7499 int ifindex;
7500
7501 ifindex = if_nametoindex(intf);
7502 if (ifindex == 0) {
7503 sigma_dut_print(dut, DUT_MSG_ERROR,
7504 "%s: Index for interface %s failed, val:%d",
7505 __func__, intf, val);
7506 return -1;
7507 }
7508
7509 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7510 NL80211_CMD_VENDOR)) ||
7511 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7512 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7513 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7514 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7515 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7516 nla_put_u8(msg,
7517 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7518 val)) {
7519 sigma_dut_print(dut, DUT_MSG_ERROR,
7520 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7521 __func__, val);
7522 nlmsg_free(msg);
7523 return -1;
7524 }
7525 nla_nest_end(msg, params);
7526
7527 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7528 if (ret) {
7529 sigma_dut_print(dut, DUT_MSG_ERROR,
7530 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7531 __func__, ret, val);
7532 }
7533 return ret;
7534#else /* NL80211_SUPPORT */
7535 sigma_dut_print(dut, DUT_MSG_ERROR,
7536 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7537 return -1;
7538#endif /* NL80211_SUPPORT */
7539}
7540
7541
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007542#ifdef NL80211_SUPPORT
7543static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7544{
7545 struct nl_msg *msg;
7546 int ret = 0;
7547 struct nlattr *params;
7548 int ifindex;
7549
7550 ifindex = if_nametoindex(intf);
7551 if (ifindex == 0) {
7552 sigma_dut_print(dut, DUT_MSG_ERROR,
7553 "%s: Index for interface %s failed",
7554 __func__, intf);
7555 return -1;
7556 }
7557
7558 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7559 NL80211_CMD_VENDOR)) ||
7560 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7561 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7562 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7563 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7564 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7565 nla_put_flag(msg,
7566 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
7567 sigma_dut_print(dut, DUT_MSG_ERROR,
7568 "%s: err in adding vendor_cmd and vendor_data",
7569 __func__);
7570 nlmsg_free(msg);
7571 return -1;
7572 }
7573 nla_nest_end(msg, params);
7574
7575 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7576 if (ret) {
7577 sigma_dut_print(dut, DUT_MSG_ERROR,
7578 "%s: err in send_and_recv_msgs, ret=%d",
7579 __func__, ret);
7580 }
7581 return ret;
7582}
7583#endif /* NL80211_SUPPORT */
7584
7585
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007586static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7587 int val)
7588{
7589#ifdef NL80211_SUPPORT
7590 struct nl_msg *msg;
7591 int ret = 0;
7592 struct nlattr *params;
7593 int ifindex;
7594
7595 ifindex = if_nametoindex(intf);
7596 if (ifindex == 0) {
7597 sigma_dut_print(dut, DUT_MSG_ERROR,
7598 "%s: Index for interface %s failed, val:%d",
7599 __func__, intf, val);
7600 return -1;
7601 }
7602
7603 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7604 NL80211_CMD_VENDOR)) ||
7605 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7606 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7607 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7608 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7609 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7610 nla_put_u8(msg,
7611 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
7612 val)) {
7613 sigma_dut_print(dut, DUT_MSG_ERROR,
7614 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7615 __func__, val);
7616 nlmsg_free(msg);
7617 return -1;
7618 }
7619 nla_nest_end(msg, params);
7620
7621 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7622 if (ret) {
7623 sigma_dut_print(dut, DUT_MSG_ERROR,
7624 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7625 __func__, ret, val);
7626 }
7627 return ret;
7628#else /* NL80211_SUPPORT */
7629 sigma_dut_print(dut, DUT_MSG_ERROR,
7630 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7631 return -1;
7632#endif /* NL80211_SUPPORT */
7633}
7634
7635
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007636static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7637 int val)
7638{
7639#ifdef NL80211_SUPPORT
7640 struct nl_msg *msg;
7641 int ret = 0;
7642 struct nlattr *params;
7643 int ifindex;
7644
7645 ifindex = if_nametoindex(intf);
7646 if (ifindex == 0) {
7647 sigma_dut_print(dut, DUT_MSG_ERROR,
7648 "%s: Index for interface %s failed, val:%d",
7649 __func__, intf, val);
7650 return -1;
7651 }
7652
7653 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7654 NL80211_CMD_VENDOR)) ||
7655 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7656 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7657 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7658 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7659 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7660 nla_put_u8(msg,
7661 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
7662 val)) {
7663 sigma_dut_print(dut, DUT_MSG_ERROR,
7664 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7665 __func__, val);
7666 nlmsg_free(msg);
7667 return -1;
7668 }
7669 nla_nest_end(msg, params);
7670
7671 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7672 if (ret) {
7673 sigma_dut_print(dut, DUT_MSG_ERROR,
7674 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7675 __func__, ret, val);
7676 }
7677 return ret;
7678#else /* NL80211_SUPPORT */
7679 sigma_dut_print(dut, DUT_MSG_ERROR,
7680 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7681 return -1;
7682#endif /* NL80211_SUPPORT */
7683}
7684
7685
Arif Hussain480d5f42019-03-12 14:40:42 -07007686static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7687 int val)
7688{
7689#ifdef NL80211_SUPPORT
7690 struct nl_msg *msg;
7691 int ret;
7692 struct nlattr *params;
7693 int ifindex;
7694
7695 ifindex = if_nametoindex(intf);
7696 if (ifindex == 0) {
7697 sigma_dut_print(dut, DUT_MSG_ERROR,
7698 "%s: Index for interface %s failed, val:%d",
7699 __func__, intf, val);
7700 return -1;
7701 }
7702
7703 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7704 NL80211_CMD_VENDOR)) ||
7705 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7706 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7707 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7708 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7709 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7710 nla_put_u8(msg,
7711 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT,
7712 val)) {
7713 sigma_dut_print(dut, DUT_MSG_ERROR,
7714 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7715 __func__, val);
7716 nlmsg_free(msg);
7717 return -1;
7718 }
7719 nla_nest_end(msg, params);
7720
7721 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7722 if (ret) {
7723 sigma_dut_print(dut, DUT_MSG_ERROR,
7724 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7725 __func__, ret, val);
7726 }
7727 return ret;
7728#else /* NL80211_SUPPORT */
7729 sigma_dut_print(dut, DUT_MSG_ERROR,
7730 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7731 return -1;
7732#endif /* NL80211_SUPPORT */
7733}
7734
7735
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007736static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7737 const char *type)
7738{
7739 char buf[60];
7740
7741 if (dut->program == PROGRAM_HE) {
7742 /* resetting phymode to auto in case of HE program */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05307743 sta_set_phymode(dut, intf, "auto");
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007744
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007745 /* reset the rate to Auto rate */
7746 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7747 intf);
7748 if (system(buf) != 0) {
7749 sigma_dut_print(dut, DUT_MSG_ERROR,
7750 "iwpriv %s set_11ax_rate 0xff failed",
7751 intf);
7752 }
7753
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007754 /* reset the LDPC setting */
7755 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7756 if (system(buf) != 0) {
7757 sigma_dut_print(dut, DUT_MSG_ERROR,
7758 "iwpriv %s ldpc 1 failed", intf);
7759 }
7760
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007761 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05307762 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007763
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007764 /* remove all network profiles */
7765 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007766
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007767 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7768 sta_set_addba_buf_size(dut, intf, 64);
7769
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007770#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007771 /* Reset the device HE capabilities to its default supported
7772 * configuration. */
7773 sta_set_he_testbed_def(dut, intf, 0);
7774
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007775 /* Disable noackpolicy for all AC */
7776 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7777 sigma_dut_print(dut, DUT_MSG_ERROR,
7778 "Disable of noackpolicy for all AC failed");
7779 }
7780#endif /* NL80211_SUPPORT */
7781
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007782 /* Enable WMM by default */
7783 if (wcn_sta_set_wmm(dut, intf, "on")) {
7784 sigma_dut_print(dut, DUT_MSG_ERROR,
7785 "Enable of WMM in sta_reset_default_wcn failed");
7786 }
7787
7788 /* Disable ADDBA_REJECT by default */
7789 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7790 sigma_dut_print(dut, DUT_MSG_ERROR,
7791 "Disable of addba_reject in sta_reset_default_wcn failed");
7792 }
7793
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007794 /* Enable sending of ADDBA by default */
7795 if (nlvendor_config_send_addba(dut, intf, 1)) {
7796 sigma_dut_print(dut, DUT_MSG_ERROR,
7797 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7798 }
7799
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007800 /* Enable AMPDU by default */
7801 iwpriv_sta_set_ampdu(dut, intf, 1);
7802
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007803#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08007804 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007805 sigma_dut_print(dut, DUT_MSG_ERROR,
7806 "Set LTF config to default in sta_reset_default_wcn failed");
7807 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007808
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007809 /* set the beamformee NSTS(maximum number of
7810 * space-time streams) to default DUT config
7811 */
7812 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007813 sigma_dut_print(dut, DUT_MSG_ERROR,
7814 "Failed to set BeamformeeSTS");
7815 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007816
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007817 if (sta_set_mac_padding_duration(
7818 dut, intf,
7819 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007820 sigma_dut_print(dut, DUT_MSG_ERROR,
7821 "Failed to set MAC padding duration");
7822 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007823
7824 if (sta_set_mu_edca_override(dut, intf, 0)) {
7825 sigma_dut_print(dut, DUT_MSG_ERROR,
7826 "ErrorCode,Failed to set MU EDCA override disable");
7827 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007828
7829 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7830 sigma_dut_print(dut, DUT_MSG_ERROR,
7831 "Failed to set OM ctrl supp");
7832 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007833
7834 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7835 sigma_dut_print(dut, DUT_MSG_ERROR,
7836 "Failed to set Tx SU PPDU enable");
7837 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007838
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007839 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7840 sigma_dut_print(dut, DUT_MSG_ERROR,
7841 "failed to send TB PPDU Tx cfg");
7842 }
7843
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007844 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7845 sigma_dut_print(dut, DUT_MSG_ERROR,
7846 "Failed to set OM ctrl reset");
7847 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007848
7849 /* +HTC-HE support default on */
7850 if (sta_set_he_htc_supp(dut, intf, 1)) {
7851 sigma_dut_print(dut, DUT_MSG_ERROR,
7852 "Setting of +HTC-HE support failed");
7853 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007854#endif /* NL80211_SUPPORT */
7855
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007856 if (sta_set_tx_beamformee(dut, intf, 1)) {
7857 sigma_dut_print(dut, DUT_MSG_ERROR,
7858 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7859 }
7860
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007861 wpa_command(intf, "SET oce 1");
7862
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007863 /* Set nss to 1 and MCS 0-7 in case of testbed */
7864 if (type && strcasecmp(type, "Testbed") == 0) {
7865#ifdef NL80211_SUPPORT
7866 int ret;
7867#endif /* NL80211_SUPPORT */
7868
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007869 wpa_command(intf, "SET oce 0");
7870
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007871 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7872 if (system(buf) != 0) {
7873 sigma_dut_print(dut, DUT_MSG_ERROR,
7874 "iwpriv %s nss failed", intf);
7875 }
7876
7877#ifdef NL80211_SUPPORT
7878 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7879 if (ret) {
7880 sigma_dut_print(dut, DUT_MSG_ERROR,
7881 "Setting of MCS failed, ret:%d",
7882 ret);
7883 }
7884#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007885
7886 /* Disable STBC as default */
7887 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007888
7889 /* Disable AMSDU as default */
7890 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007891
7892#ifdef NL80211_SUPPORT
7893 /* HE fragmentation default off */
7894 if (sta_set_he_fragmentation(dut, intf,
7895 HE_FRAG_DISABLE)) {
7896 sigma_dut_print(dut, DUT_MSG_ERROR,
7897 "Setting of HE fragmentation failed");
7898 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007899
7900 /* set the beamformee NSTS(maximum number of
7901 * space-time streams) to default testbed config
7902 */
7903 if (sta_set_beamformee_sts(dut, intf, 3)) {
7904 sigma_dut_print(dut, DUT_MSG_ERROR,
7905 "Failed to set BeamformeeSTS");
7906 }
7907
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007908 /* +HTC-HE support default off */
7909 if (sta_set_he_htc_supp(dut, intf, 0)) {
7910 sigma_dut_print(dut, DUT_MSG_ERROR,
7911 "Setting of +HTC-HE support failed");
7912 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007913
7914 /* Set device HE capabilities to testbed default
7915 * configuration. */
7916 if (sta_set_he_testbed_def(dut, intf, 1)) {
7917 sigma_dut_print(dut, DUT_MSG_DEBUG,
7918 "Failed to set HE defaults");
7919 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007920
7921 /* Disable VHT support in 2.4 GHz for testbed */
7922 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007923#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007924
7925 /* Enable WEP/TKIP with HE capability in testbed */
7926 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
7927 sigma_dut_print(dut, DUT_MSG_ERROR,
7928 "Enabling HE config with WEP/TKIP failed");
7929 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007930 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007931
7932 /* Defaults in case of DUT */
7933 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07007934 /* Enable STBC by default */
7935 wcn_sta_set_stbc(dut, intf, "1");
7936
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007937 /* set nss to 2 */
7938 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
7939 if (system(buf) != 0) {
7940 sigma_dut_print(dut, DUT_MSG_ERROR,
7941 "iwpriv %s nss 2 failed", intf);
7942 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007943 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007944
7945#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07007946 /* Set HE_MCS to 0-11 */
7947 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007948 sigma_dut_print(dut, DUT_MSG_ERROR,
7949 "Setting of MCS failed");
7950 }
7951#endif /* NL80211_SUPPORT */
7952
7953 /* Disable WEP/TKIP with HE capability in DUT */
7954 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
7955 sigma_dut_print(dut, DUT_MSG_ERROR,
7956 "Enabling HE config with WEP/TKIP failed");
7957 }
7958 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007959 }
7960}
7961
7962
Jouni Malinenf7222712019-06-13 01:50:21 +03007963static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
7964 struct sigma_conn *conn,
7965 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007966{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007967 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007968 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007969 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007970 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307971 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007972
Jouni Malinenb21f0542019-11-04 17:53:38 +02007973 if (dut->station_ifname_2g &&
7974 strcmp(dut->station_ifname_2g, intf) == 0)
7975 dut->use_5g = 0;
7976 else if (dut->station_ifname_5g &&
7977 strcmp(dut->station_ifname_5g, intf) == 0)
7978 dut->use_5g = 1;
7979
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007980 if (!program)
7981 program = get_param(cmd, "prog");
7982 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007983 dut->device_type = STA_unknown;
7984 type = get_param(cmd, "type");
7985 if (type && strcasecmp(type, "Testbed") == 0)
7986 dut->device_type = STA_testbed;
7987 if (type && strcasecmp(type, "DUT") == 0)
7988 dut->device_type = STA_dut;
7989
7990 if (dut->program == PROGRAM_TDLS) {
7991 /* Clear TDLS testing mode */
7992 wpa_command(intf, "SET tdls_disabled 0");
7993 wpa_command(intf, "SET tdls_testing 0");
7994 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007995 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05307996 /* Enable the WCN driver in TDLS Explicit trigger mode
7997 */
7998 wpa_command(intf, "SET tdls_external_control 0");
7999 wpa_command(intf, "SET tdls_trigger_control 0");
8000 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008001 }
8002
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008003#ifdef MIRACAST
8004 if (dut->program == PROGRAM_WFD ||
8005 dut->program == PROGRAM_DISPLAYR2)
8006 miracast_sta_reset_default(dut, conn, cmd);
8007#endif /* MIRACAST */
8008
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008009 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008010 case DRIVER_ATHEROS:
8011 sta_reset_default_ath(dut, intf, type);
8012 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008013 case DRIVER_WCN:
8014 sta_reset_default_wcn(dut, intf, type);
8015 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008016 default:
8017 break;
8018 }
8019
8020#ifdef ANDROID_NAN
8021 if (dut->program == PROGRAM_NAN)
8022 nan_cmd_sta_reset_default(dut, conn, cmd);
8023#endif /* ANDROID_NAN */
8024
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05308025 if (dut->program == PROGRAM_LOC &&
8026 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
8027 return ERROR_SEND_STATUS;
8028
Jouni Malinenba630452018-06-22 11:49:59 +03008029 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008030 unlink("SP/wi-fi.org/pps.xml");
8031 if (system("rm -r SP/*") != 0) {
8032 }
8033 unlink("next-client-cert.pem");
8034 unlink("next-client-key.pem");
8035 }
8036
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008037 /* For WPS program of the 60 GHz band the band type needs to be saved */
8038 if (dut->program == PROGRAM_WPS) {
8039 if (band && strcasecmp(band, "60GHz") == 0) {
8040 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008041 /* For 60 GHz enable WPS for WPS TCs */
8042 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008043 } else {
8044 dut->band = WPS_BAND_NON_60G;
8045 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008046 } else if (dut->program == PROGRAM_60GHZ) {
8047 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
8048 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008049 }
8050
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02008051 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008052 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008053 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008054
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008055 sigma_dut_print(dut, DUT_MSG_INFO,
8056 "WPS 60 GHz program, wps_disable = %d",
8057 dut->wps_disable);
8058
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008059 if (!dev_role) {
8060 send_resp(dut, conn, SIGMA_ERROR,
8061 "errorCode,Missing DevRole argument");
8062 return 0;
8063 }
8064
8065 if (strcasecmp(dev_role, "STA") == 0)
8066 dut->dev_role = DEVROLE_STA;
8067 else if (strcasecmp(dev_role, "PCP") == 0)
8068 dut->dev_role = DEVROLE_PCP;
8069 else {
8070 send_resp(dut, conn, SIGMA_ERROR,
8071 "errorCode,Unknown DevRole");
8072 return 0;
8073 }
8074
8075 if (dut->device_type == STA_unknown) {
8076 sigma_dut_print(dut, DUT_MSG_ERROR,
8077 "Device type is not STA testbed or DUT");
8078 send_resp(dut, conn, SIGMA_ERROR,
8079 "errorCode,Unknown device type");
8080 return 0;
8081 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008082
8083 sigma_dut_print(dut, DUT_MSG_DEBUG,
8084 "Setting msdu_size to MAX: 7912");
8085 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008086 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008087
8088 if (system(buf) != 0) {
8089 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
8090 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008091 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008092 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008093
8094 if (sta_set_force_mcs(dut, 0, 1)) {
8095 sigma_dut_print(dut, DUT_MSG_ERROR,
8096 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008097 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008098 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008099 }
8100
8101 wpa_command(intf, "WPS_ER_STOP");
8102 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05308103 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008104 wpa_command(intf, "SET radio_disabled 0");
8105
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02008106 dut->wps_forced_version = 0;
8107
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008108 if (dut->wsc_fragment) {
8109 dut->wsc_fragment = 0;
8110 wpa_command(intf, "SET device_name Test client");
8111 wpa_command(intf, "SET manufacturer ");
8112 wpa_command(intf, "SET model_name ");
8113 wpa_command(intf, "SET model_number ");
8114 wpa_command(intf, "SET serial_number ");
8115 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02008116 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
8117 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
8118 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
8119 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008120
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008121 if (dut->tmp_mac_addr && dut->set_macaddr) {
8122 dut->tmp_mac_addr = 0;
8123 if (system(dut->set_macaddr) != 0) {
8124 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
8125 "temporary MAC address");
8126 }
8127 }
8128
8129 set_ps(intf, dut, 0);
8130
Jouni Malinenba630452018-06-22 11:49:59 +03008131 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
8132 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008133 wpa_command(intf, "SET interworking 1");
8134 wpa_command(intf, "SET hs20 1");
8135 }
8136
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008137 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03008138 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008139 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008140 wpa_command(intf, "SET pmf 1");
8141 } else {
8142 wpa_command(intf, "SET pmf 0");
8143 }
8144
8145 hs2_clear_credentials(intf);
8146 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
8147 wpa_command(intf, "SET access_network_type 15");
8148
8149 static_ip_file(0, NULL, NULL, NULL);
8150 kill_dhcp_client(dut, intf);
8151 clear_ip_addr(dut, intf);
8152
8153 dut->er_oper_performed = 0;
8154 dut->er_oper_bssid[0] = '\0';
8155
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008156 if (dut->program == PROGRAM_LOC) {
8157 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008158 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008159 }
8160
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07008161 if (dut->program == PROGRAM_MBO || dut->program == PROGRAM_HE) {
Ashwini Patil00402582017-04-13 12:29:39 +05308162 free(dut->non_pref_ch_list);
8163 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05308164 free(dut->btm_query_cand_list);
8165 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05308166 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05308167 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05308168 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05308169 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05308170 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05308171 }
8172
Jouni Malinen3c367e82017-06-23 17:01:47 +03008173 free(dut->rsne_override);
8174 dut->rsne_override = NULL;
8175
Jouni Malinen68143132017-09-02 02:34:08 +03008176 free(dut->sae_commit_override);
8177 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03008178 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02008179 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03008180
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008181 dut->sta_associate_wait_connect = 0;
8182 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03008183 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008184 dut->sta_tod_policy = 0;
8185
Jouni Malinend86e5822017-08-29 03:55:32 +03008186 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02008187 free(dut->dpp_peer_uri);
8188 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02008189 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02008190 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03008191 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03008192
Jouni Malinenfac9cad2017-10-10 18:35:55 +03008193 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
8194
vamsi krishnaa2799492017-12-05 14:28:01 +05308195 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308196 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05308197 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05308198 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
8199 dut->fils_hlp = 0;
8200#ifdef ANDROID
8201 hlp_thread_cleanup(dut);
8202#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05308203 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308204
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308205 if (dut->program == PROGRAM_QM)
8206 wpa_command(intf, "SET interworking 1");
8207
Jouni Malinen8179fee2019-03-28 03:19:47 +02008208 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03008209 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02008210
Sunil Dutt076081f2018-02-05 19:45:50 +05308211#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008212 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05308213 dut->config_rsnie == 1) {
8214 dut->config_rsnie = 0;
8215 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05308216 }
8217#endif /* NL80211_SUPPORT */
8218
Sunil Duttfebf8a82018-02-09 18:50:13 +05308219 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
8220 dut->dev_role = DEVROLE_STA_CFON;
8221 return sta_cfon_reset_default(dut, conn, cmd);
8222 }
8223
Jouni Malinen439352d2018-09-13 03:42:23 +03008224 wpa_command(intf, "SET setband AUTO");
8225
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308226 dut->ocvc = 0;
Jouni Malinen67433fc2020-06-26 22:50:33 +03008227 dut->client_privacy = 0;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05308228 dut->saquery_oci_freq = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308229
Sunil Duttfebf8a82018-02-09 18:50:13 +05308230 if (dut->program != PROGRAM_VHT)
8231 return cmd_sta_p2p_reset(dut, conn, cmd);
8232
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08008233 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008234}
8235
8236
Jouni Malinenf7222712019-06-13 01:50:21 +03008237static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
8238 struct sigma_conn *conn,
8239 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008240{
8241 const char *program = get_param(cmd, "Program");
8242
8243 if (program == NULL)
8244 return -1;
8245#ifdef ANDROID_NAN
8246 if (strcasecmp(program, "NAN") == 0)
8247 return nan_cmd_sta_get_events(dut, conn, cmd);
8248#endif /* ANDROID_NAN */
8249 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8250 return 0;
8251}
8252
8253
Jouni Malinen82905202018-04-29 17:20:10 +03008254static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
8255 struct sigma_cmd *cmd)
8256{
8257 const char *url = get_param(cmd, "url");
8258 const char *method = get_param(cmd, "method");
8259 pid_t pid;
8260 int status;
8261
8262 if (!url || !method)
8263 return -1;
8264
8265 /* TODO: Add support for method,post */
8266 if (strcasecmp(method, "get") != 0) {
8267 send_resp(dut, conn, SIGMA_ERROR,
8268 "ErrorCode,Unsupported method");
8269 return 0;
8270 }
8271
8272 pid = fork();
8273 if (pid < 0) {
8274 perror("fork");
8275 return -1;
8276 }
8277
8278 if (pid == 0) {
8279 char * argv[5] = { "wget", "-O", "/dev/null",
8280 (char *) url, NULL };
8281
8282 execv("/usr/bin/wget", argv);
8283 perror("execv");
8284 exit(0);
8285 return -1;
8286 }
8287
8288 if (waitpid(pid, &status, 0) < 0) {
8289 perror("waitpid");
8290 return -1;
8291 }
8292
8293 if (WIFEXITED(status)) {
8294 const char *errmsg;
8295
8296 if (WEXITSTATUS(status) == 0)
8297 return 1;
8298 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
8299 WEXITSTATUS(status));
8300 switch (WEXITSTATUS(status)) {
8301 case 4:
8302 errmsg = "errmsg,Network failure";
8303 break;
8304 case 8:
8305 errmsg = "errmsg,Server issued an error response";
8306 break;
8307 default:
8308 errmsg = "errmsg,Unknown failure from wget";
8309 break;
8310 }
8311 send_resp(dut, conn, SIGMA_ERROR, errmsg);
8312 return 0;
8313 }
8314
8315 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
8316 return 0;
8317}
8318
8319
Jouni Malinenf7222712019-06-13 01:50:21 +03008320static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
8321 struct sigma_conn *conn,
8322 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008323{
8324 const char *program = get_param(cmd, "Prog");
8325
Jouni Malinen82905202018-04-29 17:20:10 +03008326 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008327 return -1;
8328#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03008329 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008330 return nan_cmd_sta_exec_action(dut, conn, cmd);
8331#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03008332
8333 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07008334 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03008335
8336 if (get_param(cmd, "url"))
8337 return sta_exec_action_url(dut, conn, cmd);
8338
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008339 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8340 return 0;
8341}
8342
8343
Jouni Malinenf7222712019-06-13 01:50:21 +03008344static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
8345 struct sigma_conn *conn,
8346 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008347{
8348 const char *intf = get_param(cmd, "Interface");
8349 const char *val, *mcs32, *rate;
8350
8351 val = get_param(cmd, "GREENFIELD");
8352 if (val) {
8353 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
8354 /* Enable GD */
8355 send_resp(dut, conn, SIGMA_ERROR,
8356 "ErrorCode,GF not supported");
8357 return 0;
8358 }
8359 }
8360
8361 val = get_param(cmd, "SGI20");
8362 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008363 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008364 case DRIVER_ATHEROS:
8365 ath_sta_set_sgi(dut, intf, val);
8366 break;
8367 default:
8368 send_resp(dut, conn, SIGMA_ERROR,
8369 "ErrorCode,SGI20 not supported");
8370 return 0;
8371 }
8372 }
8373
8374 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
8375 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
8376 if (mcs32 && rate) {
8377 /* TODO */
8378 send_resp(dut, conn, SIGMA_ERROR,
8379 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
8380 return 0;
8381 } else if (mcs32 && !rate) {
8382 /* TODO */
8383 send_resp(dut, conn, SIGMA_ERROR,
8384 "ErrorCode,MCS32 not supported");
8385 return 0;
8386 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008387 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008388 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008389 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008390 ath_sta_set_11nrates(dut, intf, rate);
8391 break;
8392 default:
8393 send_resp(dut, conn, SIGMA_ERROR,
8394 "ErrorCode,MCS32_FIXEDRATE not supported");
8395 return 0;
8396 }
8397 }
8398
8399 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8400}
8401
8402
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008403static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8404 int mcs_config)
8405{
8406#ifdef NL80211_SUPPORT
8407 int ret;
8408
8409 switch (mcs_config) {
8410 case HE_80_MCS0_7:
8411 case HE_80_MCS0_9:
8412 case HE_80_MCS0_11:
8413 ret = sta_set_he_mcs(dut, intf, mcs_config);
8414 if (ret) {
8415 sigma_dut_print(dut, DUT_MSG_ERROR,
8416 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8417 mcs_config, ret);
8418 }
8419 break;
8420 default:
8421 sigma_dut_print(dut, DUT_MSG_ERROR,
8422 "cmd_set_max_he_mcs: Invalid mcs %d",
8423 mcs_config);
8424 break;
8425 }
8426#else /* NL80211_SUPPORT */
8427 sigma_dut_print(dut, DUT_MSG_ERROR,
8428 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8429#endif /* NL80211_SUPPORT */
8430}
8431
8432
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008433#define TWT_REQUEST_CMD 0
8434#define TWT_SUGGEST_CMD 1
8435#define TWT_DEMAND_CMD 2
8436
Arif Hussain480d5f42019-03-12 14:40:42 -07008437static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8438 struct sigma_cmd *cmd)
8439{
8440#ifdef NL80211_SUPPORT
8441 struct nlattr *params;
8442 struct nlattr *attr;
8443 struct nlattr *attr1;
8444 struct nl_msg *msg;
8445 int ifindex, ret;
8446 const char *val;
8447 const char *intf = get_param(cmd, "Interface");
8448 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8449 wake_interval_mantissa = 512;
8450 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008451 protection = 0, cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
Arif Hussain480d5f42019-03-12 14:40:42 -07008452
8453 ifindex = if_nametoindex(intf);
8454 if (ifindex == 0) {
8455 sigma_dut_print(dut, DUT_MSG_ERROR,
8456 "%s: Index for interface %s failed",
8457 __func__, intf);
8458 return -1;
8459 }
8460
8461 val = get_param(cmd, "FlowType");
8462 if (val) {
8463 flow_type = atoi(val);
8464 if (flow_type != 0 && flow_type != 1) {
8465 sigma_dut_print(dut, DUT_MSG_ERROR,
8466 "TWT: Invalid FlowType %d", flow_type);
8467 return -1;
8468 }
8469 }
8470
8471 val = get_param(cmd, "TWT_Trigger");
8472 if (val) {
8473 twt_trigger = atoi(val);
8474 if (twt_trigger != 0 && twt_trigger != 1) {
8475 sigma_dut_print(dut, DUT_MSG_ERROR,
8476 "TWT: Invalid TWT_Trigger %d",
8477 twt_trigger);
8478 return -1;
8479 }
8480 }
8481
8482 val = get_param(cmd, "Protection");
8483 if (val) {
8484 protection = atoi(val);
8485 if (protection != 0 && protection != 1) {
8486 sigma_dut_print(dut, DUT_MSG_ERROR,
8487 "TWT: Invalid Protection %d",
8488 protection);
8489 return -1;
8490 }
8491 }
8492
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008493 val = get_param(cmd, "SetupCommand");
8494 if (val) {
8495 cmd_type = atoi(val);
8496 if (cmd_type == TWT_REQUEST_CMD)
8497 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_REQUEST;
8498 else if (cmd_type == TWT_SUGGEST_CMD)
8499 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
8500 else if (cmd_type == TWT_DEMAND_CMD)
8501 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_DEMAND;
8502 else
8503 sigma_dut_print(dut, DUT_MSG_ERROR,
8504 "Default suggest is used for cmd %d",
8505 cmd_type);
8506 }
8507
Arif Hussain480d5f42019-03-12 14:40:42 -07008508 val = get_param(cmd, "TargetWakeTime");
8509 if (val)
8510 target_wake_time = atoi(val);
8511
8512 val = get_param(cmd, "WakeIntervalMantissa");
8513 if (val)
8514 wake_interval_mantissa = atoi(val);
8515
8516 val = get_param(cmd, "WakeIntervalExp");
8517 if (val)
8518 wake_interval_exp = atoi(val);
8519
8520 val = get_param(cmd, "NominalMinWakeDur");
8521 if (val)
8522 nominal_min_wake_dur = atoi(val);
8523
8524 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8525 NL80211_CMD_VENDOR)) ||
8526 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8527 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8528 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8529 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8530 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8531 !(params = nla_nest_start(
8532 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
8533 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8534 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8535 wake_interval_exp) ||
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008536 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, cmd_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008537 (twt_trigger &&
8538 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008539 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8540 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008541 (protection &&
8542 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008543 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8544 target_wake_time) ||
8545 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8546 nominal_min_wake_dur) ||
8547 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8548 wake_interval_mantissa)) {
8549 sigma_dut_print(dut, DUT_MSG_ERROR,
8550 "%s: err in adding vendor_cmd and vendor_data",
8551 __func__);
8552 nlmsg_free(msg);
8553 return -1;
8554 }
8555 nla_nest_end(msg, attr1);
8556 nla_nest_end(msg, params);
8557 nla_nest_end(msg, attr);
8558
8559 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8560 if (ret) {
8561 sigma_dut_print(dut, DUT_MSG_ERROR,
8562 "%s: err in send_and_recv_msgs, ret=%d",
8563 __func__, ret);
8564 }
8565
8566 return ret;
8567#else /* NL80211_SUPPORT */
8568 sigma_dut_print(dut, DUT_MSG_ERROR,
8569 "TWT request cannot be done without NL80211_SUPPORT defined");
8570 return -1;
8571#endif /* NL80211_SUPPORT */
8572}
8573
8574
8575static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8576 struct sigma_cmd *cmd)
8577{
8578 #ifdef NL80211_SUPPORT
8579 struct nlattr *params;
8580 struct nlattr *attr;
8581 struct nlattr *attr1;
8582 int ifindex, ret;
8583 struct nl_msg *msg;
8584 const char *intf = get_param(cmd, "Interface");
8585
8586 ifindex = if_nametoindex(intf);
8587 if (ifindex == 0) {
8588 sigma_dut_print(dut, DUT_MSG_ERROR,
8589 "%s: Index for interface %s failed",
8590 __func__, intf);
8591 return -1;
8592 }
8593
8594 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8595 NL80211_CMD_VENDOR)) ||
8596 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8597 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8598 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8599 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8600 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8601 !(params = nla_nest_start(
8602 msg,
8603 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8604 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8605 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8606 sigma_dut_print(dut, DUT_MSG_ERROR,
8607 "%s: err in adding vendor_cmd and vendor_data",
8608 __func__);
8609 nlmsg_free(msg);
8610 return -1;
8611 }
8612 nla_nest_end(msg, attr1);
8613 nla_nest_end(msg, params);
8614 nla_nest_end(msg, attr);
8615
8616 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8617 if (ret) {
8618 sigma_dut_print(dut, DUT_MSG_ERROR,
8619 "%s: err in send_and_recv_msgs, ret=%d",
8620 __func__, ret);
8621 }
8622
8623 return ret;
8624#else /* NL80211_SUPPORT */
8625 sigma_dut_print(dut, DUT_MSG_ERROR,
8626 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8627 return -1;
8628#endif /* NL80211_SUPPORT */
8629}
8630
8631
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008632static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8633 struct sigma_cmd *cmd)
8634{
8635#ifdef NL80211_SUPPORT
8636 struct nlattr *params;
8637 struct nlattr *attr;
8638 struct nlattr *attr1;
8639 struct nl_msg *msg;
8640 int ifindex, ret;
8641 const char *val;
8642 const char *intf = get_param(cmd, "Interface");
8643 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8644 ulmu_data_dis = 0;
8645
8646 ifindex = if_nametoindex(intf);
8647 if (ifindex == 0) {
8648 sigma_dut_print(dut, DUT_MSG_ERROR,
8649 "%s: Index for interface %s failed",
8650 __func__, intf);
8651 return -1;
8652 }
8653 val = get_param(cmd, "OMCtrl_RxNSS");
8654 if (val)
8655 rx_nss = atoi(val);
8656
8657 val = get_param(cmd, "OMCtrl_ChnlWidth");
8658 if (val)
8659 ch_bw = atoi(val);
8660
8661 val = get_param(cmd, "OMCtrl_ULMUDisable");
8662 if (val)
8663 ulmu_dis = atoi(val);
8664
8665 val = get_param(cmd, "OMCtrl_TxNSTS");
8666 if (val)
8667 tx_nsts = atoi(val);
8668
8669 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8670 if (val)
8671 ulmu_data_dis = atoi(val);
8672
8673 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8674 NL80211_CMD_VENDOR)) ||
8675 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8676 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8677 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8678 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8679 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8680 !(params = nla_nest_start(
8681 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8682 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8683 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8684 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8685 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8686 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8687 ulmu_data_dis) ||
8688 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8689 ulmu_dis)) {
8690 sigma_dut_print(dut, DUT_MSG_ERROR,
8691 "%s: err in adding vendor_cmd and vendor_data",
8692 __func__);
8693 nlmsg_free(msg);
8694 return -1;
8695 }
8696 nla_nest_end(msg, attr1);
8697 nla_nest_end(msg, params);
8698 nla_nest_end(msg, attr);
8699
8700 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8701 if (ret) {
8702 sigma_dut_print(dut, DUT_MSG_ERROR,
8703 "%s: err in send_and_recv_msgs, ret=%d",
8704 __func__, ret);
8705 }
8706
8707 return ret;
8708#else /* NL80211_SUPPORT */
8709 sigma_dut_print(dut, DUT_MSG_ERROR,
8710 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8711 return -1;
8712#endif /* NL80211_SUPPORT */
8713}
8714
8715
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008716static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8717 struct sigma_conn *conn,
8718 struct sigma_cmd *cmd)
8719{
8720 const char *intf = get_param(cmd, "Interface");
8721 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008722 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008723 int tkip = -1;
8724 int wep = -1;
8725
Arif Hussaina37e9552018-06-20 17:05:59 -07008726 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008727 val = get_param(cmd, "SGI80");
8728 if (val) {
8729 int sgi80;
8730
8731 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008732 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008733 }
8734
8735 val = get_param(cmd, "TxBF");
8736 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008737 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008738 case DRIVER_WCN:
8739 if (sta_set_tx_beamformee(dut, intf, 1)) {
8740 send_resp(dut, conn, SIGMA_ERROR,
8741 "ErrorCode,Failed to set TX beamformee enable");
8742 return 0;
8743 }
8744 break;
8745 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008746 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008747 send_resp(dut, conn, SIGMA_ERROR,
8748 "ErrorCode,Setting vhtsubfee failed");
8749 return 0;
8750 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008751 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008752 send_resp(dut, conn, SIGMA_ERROR,
8753 "ErrorCode,Setting vhtsubfer failed");
8754 return 0;
8755 }
8756 break;
8757 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008758 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008759 "Unsupported driver type");
8760 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008761 }
8762 }
8763
8764 val = get_param(cmd, "MU_TxBF");
8765 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008766 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008767 case DRIVER_ATHEROS:
8768 ath_sta_set_txsp_stream(dut, intf, "1SS");
8769 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008770 run_iwpriv(dut, intf, "vhtmubfee 1");
8771 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308772 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008773 case DRIVER_WCN:
8774 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8775 send_resp(dut, conn, SIGMA_ERROR,
8776 "ErrorCode,Failed to set RX/TXSP_STREAM");
8777 return 0;
8778 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308779 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008780 default:
8781 sigma_dut_print(dut, DUT_MSG_ERROR,
8782 "Setting SP_STREAM not supported");
8783 break;
8784 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008785 }
8786
8787 val = get_param(cmd, "LDPC");
8788 if (val) {
8789 int ldpc;
8790
8791 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008792 run_iwpriv(dut, intf, "ldpc %d", ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008793 }
8794
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008795 val = get_param(cmd, "BCC");
8796 if (val) {
8797 int bcc;
8798
8799 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8800 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8801 * is mutually exclusive to bcc */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008802 run_iwpriv(dut, intf, "ldpc %d", !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008803 }
8804
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008805 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8806 if (val && dut->sta_nss == 1)
8807 cmd_set_max_he_mcs(dut, intf, atoi(val));
8808
8809 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8810 if (val && dut->sta_nss == 2)
8811 cmd_set_max_he_mcs(dut, intf, atoi(val));
8812
Arif Hussainac6c5112018-05-25 17:34:00 -07008813 val = get_param(cmd, "MCS_FixedRate");
8814 if (val) {
8815#ifdef NL80211_SUPPORT
8816 int mcs, ratecode = 0;
8817 enum he_mcs_config mcs_config;
8818 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008819 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008820
8821 ratecode = (0x07 & dut->sta_nss) << 5;
8822 mcs = atoi(val);
8823 /* Add the MCS to the ratecode */
8824 if (mcs >= 0 && mcs <= 11) {
8825 ratecode += mcs;
8826 if (dut->device_type == STA_testbed &&
8827 mcs > 7 && mcs <= 11) {
8828 if (mcs <= 9)
8829 mcs_config = HE_80_MCS0_9;
8830 else
8831 mcs_config = HE_80_MCS0_11;
8832 ret = sta_set_he_mcs(dut, intf, mcs_config);
8833 if (ret) {
8834 sigma_dut_print(dut, DUT_MSG_ERROR,
8835 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8836 mcs, mcs_config, ret);
8837 }
8838 }
8839 snprintf(buf, sizeof(buf),
8840 "iwpriv %s set_11ax_rate 0x%03x",
8841 intf, ratecode);
8842 if (system(buf) != 0) {
8843 sigma_dut_print(dut, DUT_MSG_ERROR,
8844 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8845 ratecode);
8846 }
8847 } else {
8848 sigma_dut_print(dut, DUT_MSG_ERROR,
8849 "MCS_FixedRate: HE MCS %d not supported",
8850 mcs);
8851 }
8852#else /* NL80211_SUPPORT */
8853 sigma_dut_print(dut, DUT_MSG_ERROR,
8854 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8855#endif /* NL80211_SUPPORT */
8856 }
8857
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008858 val = get_param(cmd, "opt_md_notif_ie");
8859 if (val) {
8860 char *result = NULL;
8861 char delim[] = ";";
8862 char token[30];
8863 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308864 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008865
Peng Xub8fc5cc2017-05-10 17:27:28 -07008866 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308867 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008868
8869 /* Extract the NSS information */
8870 if (result) {
8871 value = atoi(result);
8872 switch (value) {
8873 case 1:
8874 config_val = 1;
8875 break;
8876 case 2:
8877 config_val = 3;
8878 break;
8879 case 3:
8880 config_val = 7;
8881 break;
8882 case 4:
8883 config_val = 15;
8884 break;
8885 default:
8886 config_val = 3;
8887 break;
8888 }
8889
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008890 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8891 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008892
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008893 }
8894
8895 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308896 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008897 if (result) {
8898 value = atoi(result);
8899 switch (value) {
8900 case 20:
8901 config_val = 0;
8902 break;
8903 case 40:
8904 config_val = 1;
8905 break;
8906 case 80:
8907 config_val = 2;
8908 break;
8909 case 160:
8910 config_val = 3;
8911 break;
8912 default:
8913 config_val = 2;
8914 break;
8915 }
8916
8917 dut->chwidth = config_val;
8918
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008919 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008920 }
8921
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008922 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008923 }
8924
8925 val = get_param(cmd, "nss_mcs_cap");
8926 if (val) {
8927 int nss, mcs;
8928 char token[20];
8929 char *result = NULL;
8930 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308931 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008932
Peng Xub8fc5cc2017-05-10 17:27:28 -07008933 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308934 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308935 if (!result) {
8936 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008937 "NSS not specified");
8938 send_resp(dut, conn, SIGMA_ERROR,
8939 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308940 return 0;
8941 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008942 nss = atoi(result);
8943
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008944 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07008945 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008946
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308947 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008948 if (result == NULL) {
8949 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008950 "MCS not specified");
8951 send_resp(dut, conn, SIGMA_ERROR,
8952 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008953 return 0;
8954 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308955 result = strtok_r(result, "-", &saveptr);
8956 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308957 if (!result) {
8958 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008959 "MCS not specified");
8960 send_resp(dut, conn, SIGMA_ERROR,
8961 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308962 return 0;
8963 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008964 mcs = atoi(result);
8965
Arif Hussaina37e9552018-06-20 17:05:59 -07008966 if (program && strcasecmp(program, "HE") == 0) {
8967#ifdef NL80211_SUPPORT
8968 enum he_mcs_config mcs_config;
8969 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008970
Arif Hussaina37e9552018-06-20 17:05:59 -07008971 if (mcs >= 0 && mcs <= 7) {
8972 mcs_config = HE_80_MCS0_7;
8973 } else if (mcs > 7 && mcs <= 9) {
8974 mcs_config = HE_80_MCS0_9;
8975 } else if (mcs > 9 && mcs <= 11) {
8976 mcs_config = HE_80_MCS0_11;
8977 } else {
8978 sigma_dut_print(dut, DUT_MSG_ERROR,
8979 "nss_mcs_cap: HE: Invalid mcs: %d",
8980 mcs);
8981 send_resp(dut, conn, SIGMA_ERROR,
8982 "errorCode,Invalid MCS");
8983 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008984 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008985
8986 ret = sta_set_he_mcs(dut, intf, mcs_config);
8987 if (ret) {
8988 sigma_dut_print(dut, DUT_MSG_ERROR,
8989 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
8990 mcs_config, ret);
8991 send_resp(dut, conn, SIGMA_ERROR,
8992 "errorCode,Failed to set MCS");
8993 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008994 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008995#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008996 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008997 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
8998#endif /* NL80211_SUPPORT */
8999 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009000 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07009001
9002 switch (nss) {
9003 case 1:
9004 switch (mcs) {
9005 case 7:
9006 vht_mcsmap = 0xfffc;
9007 break;
9008 case 8:
9009 vht_mcsmap = 0xfffd;
9010 break;
9011 case 9:
9012 vht_mcsmap = 0xfffe;
9013 break;
9014 default:
9015 vht_mcsmap = 0xfffe;
9016 break;
9017 }
9018 break;
9019 case 2:
9020 switch (mcs) {
9021 case 7:
9022 vht_mcsmap = 0xfff0;
9023 break;
9024 case 8:
9025 vht_mcsmap = 0xfff5;
9026 break;
9027 case 9:
9028 vht_mcsmap = 0xfffa;
9029 break;
9030 default:
9031 vht_mcsmap = 0xfffa;
9032 break;
9033 }
9034 break;
9035 case 3:
9036 switch (mcs) {
9037 case 7:
9038 vht_mcsmap = 0xffc0;
9039 break;
9040 case 8:
9041 vht_mcsmap = 0xffd5;
9042 break;
9043 case 9:
9044 vht_mcsmap = 0xffea;
9045 break;
9046 default:
9047 vht_mcsmap = 0xffea;
9048 break;
9049 }
9050 break;
9051 default:
9052 vht_mcsmap = 0xffea;
9053 break;
9054 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009055 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009056 }
9057 }
9058
9059 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
9060
9061 val = get_param(cmd, "Vht_tkip");
9062 if (val)
9063 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9064
9065 val = get_param(cmd, "Vht_wep");
9066 if (val)
9067 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9068
9069 if (tkip != -1 || wep != -1) {
9070 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009071 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009072 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009073 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009074 } else {
9075 sigma_dut_print(dut, DUT_MSG_ERROR,
9076 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
9077 return 0;
9078 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009079 }
9080
Arif Hussain55f00da2018-07-03 08:28:26 -07009081 val = get_param(cmd, "txBandwidth");
9082 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009083 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07009084 case DRIVER_WCN:
9085 if (wcn_sta_set_width(dut, intf, val) < 0) {
9086 send_resp(dut, conn, SIGMA_ERROR,
9087 "ErrorCode,Failed to set txBandwidth");
9088 return 0;
9089 }
9090 break;
9091 case DRIVER_ATHEROS:
9092 if (ath_set_width(dut, conn, intf, val) < 0) {
9093 send_resp(dut, conn, SIGMA_ERROR,
9094 "ErrorCode,Failed to set txBandwidth");
9095 return 0;
9096 }
9097 break;
9098 default:
9099 sigma_dut_print(dut, DUT_MSG_ERROR,
9100 "Setting txBandwidth not supported");
9101 break;
9102 }
9103 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009104
Arif Hussain9765f7d2018-07-03 08:28:26 -07009105 val = get_param(cmd, "BeamformeeSTS");
9106 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07009107 if (sta_set_tx_beamformee(dut, intf, 1)) {
9108 send_resp(dut, conn, SIGMA_ERROR,
9109 "ErrorCode,Failed to set TX beamformee enable");
9110 return 0;
9111 }
9112
Arif Hussain9765f7d2018-07-03 08:28:26 -07009113 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
9114 send_resp(dut, conn, SIGMA_ERROR,
9115 "ErrorCode,Failed to set BeamformeeSTS");
9116 return 0;
9117 }
9118 }
9119
Arif Hussain68d23f52018-07-11 13:39:08 -07009120 val = get_param(cmd, "Trig_MAC_Padding_Dur");
9121 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07009122#ifdef NL80211_SUPPORT
9123 enum qca_wlan_he_mac_padding_dur set_val;
9124
9125 switch (atoi(val)) {
9126 case 16:
9127 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
9128 break;
9129 case 8:
9130 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
9131 break;
9132 default:
9133 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
9134 break;
9135 }
9136 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07009137 send_resp(dut, conn, SIGMA_ERROR,
9138 "ErrorCode,Failed to set MAC padding duration");
9139 return 0;
9140 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07009141#else /* NL80211_SUPPORT */
9142 sigma_dut_print(dut, DUT_MSG_ERROR,
9143 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
9144#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07009145 }
9146
Arif Hussain480d5f42019-03-12 14:40:42 -07009147 val = get_param(cmd, "TWT_ReqSupport");
9148 if (val) {
9149 int set_val;
9150
9151 if (strcasecmp(val, "Enable") == 0) {
9152 set_val = 1;
9153 } else if (strcasecmp(val, "Disable") == 0) {
9154 set_val = 0;
9155 } else {
9156 send_resp(dut, conn, SIGMA_ERROR,
9157 "ErrorCode,Invalid TWT_ReqSupport");
9158 return STATUS_SENT;
9159 }
9160
9161 if (sta_set_twt_req_support(dut, intf, set_val)) {
9162 sigma_dut_print(dut, DUT_MSG_ERROR,
9163 "Failed to set TWT req support %d",
9164 set_val);
9165 send_resp(dut, conn, SIGMA_ERROR,
9166 "ErrorCode,Failed to set TWT_ReqSupport");
9167 return STATUS_SENT;
9168 }
9169 }
9170
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07009171 val = get_param(cmd, "MU_EDCA");
9172 if (val && (strcasecmp(val, "Override") == 0)) {
9173 if (sta_set_mu_edca_override(dut, intf, 1)) {
9174 send_resp(dut, conn, SIGMA_ERROR,
9175 "ErrorCode,Failed to set MU EDCA override");
9176 return 0;
9177 }
9178 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009179
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07009180 val = get_param(cmd, "OMControl");
9181 if (val) {
9182 int set_val = 1;
9183
9184 if (strcasecmp(val, "Enable") == 0)
9185 set_val = 1;
9186 else if (strcasecmp(val, "Disable") == 0)
9187 set_val = 0;
9188
9189 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
9190 send_resp(dut, conn, SIGMA_ERROR,
9191 "ErrorCode,Failed to set OM ctrl supp");
9192 return 0;
9193 }
9194 }
9195
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009196 val = get_param(cmd, "ADDBAResp_BufSize");
9197 if (val) {
9198 int buf_size;
9199
9200 if (strcasecmp(val, "gt64") == 0)
9201 buf_size = 256;
9202 else
9203 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009204 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009205 sta_set_addba_buf_size(dut, intf, buf_size)) {
9206 send_resp(dut, conn, SIGMA_ERROR,
9207 "ErrorCode,set addbaresp_buff_size failed");
9208 return 0;
9209 }
9210 }
9211
9212 val = get_param(cmd, "ADDBAReq_BufSize");
9213 if (val) {
9214 int buf_size;
9215
9216 if (strcasecmp(val, "gt64") == 0)
9217 buf_size = 256;
9218 else
9219 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009220 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009221 sta_set_addba_buf_size(dut, intf, buf_size)) {
9222 send_resp(dut, conn, SIGMA_ERROR,
9223 "ErrorCode,set addbareq_buff_size failed");
9224 return 0;
9225 }
9226 }
9227
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009228 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9229}
9230
9231
9232static int sta_set_wireless_60g(struct sigma_dut *dut,
9233 struct sigma_conn *conn,
9234 struct sigma_cmd *cmd)
9235{
9236 const char *dev_role = get_param(cmd, "DevRole");
9237
9238 if (!dev_role) {
9239 send_resp(dut, conn, SIGMA_INVALID,
9240 "ErrorCode,DevRole not specified");
9241 return 0;
9242 }
9243
9244 if (strcasecmp(dev_role, "PCP") == 0)
9245 return sta_set_60g_pcp(dut, conn, cmd);
9246 if (strcasecmp(dev_role, "STA") == 0)
9247 return sta_set_60g_sta(dut, conn, cmd);
9248 send_resp(dut, conn, SIGMA_INVALID,
9249 "ErrorCode,DevRole not supported");
9250 return 0;
9251}
9252
9253
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309254static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
9255 struct sigma_cmd *cmd)
9256{
9257 int status;
9258 const char *intf = get_param(cmd, "Interface");
9259 const char *val = get_param(cmd, "DevRole");
9260
9261 if (val && strcasecmp(val, "STA-CFON") == 0) {
9262 status = sta_cfon_set_wireless(dut, conn, cmd);
9263 if (status)
9264 return status;
9265 }
9266 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9267}
9268
9269
Jouni Malinen67433fc2020-06-26 22:50:33 +03009270static enum sigma_cmd_result
9271sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
9272 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309273{
9274 const char *intf = get_param(cmd, "Interface");
9275 const char *val;
9276
9277 val = get_param(cmd, "ocvc");
9278 if (val)
9279 dut->ocvc = atoi(val);
9280
Jouni Malinen67433fc2020-06-26 22:50:33 +03009281 val = get_param(cmd, "ClientPrivacy");
9282 if (val) {
9283 dut->client_privacy = atoi(val);
9284 if (dut->client_privacy &&
9285 (wpa_command(intf, "SET mac_addr 1") < 0 ||
9286 wpa_command(intf, "SET rand_addr_lifetime 1") < 0 ||
9287 wpa_command(intf, "SET preassoc_mac_addr 1") < 0 ||
9288 wpa_command(intf, "SET gas_rand_mac_addr 1") < 0 ||
9289 wpa_command(intf, "SET gas_rand_addr_lifetime 1") < 0)) {
9290 send_resp(dut, conn, SIGMA_ERROR,
9291 "errorCode,Failed to enable random MAC address use");
9292 return STATUS_SENT_ERROR;
9293 }
9294 }
9295
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309296 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9297}
9298
9299
Jouni Malinenf7222712019-06-13 01:50:21 +03009300static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
9301 struct sigma_conn *conn,
9302 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009303{
9304 const char *val;
9305
9306 val = get_param(cmd, "Program");
9307 if (val) {
9308 if (strcasecmp(val, "11n") == 0)
9309 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08009310 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009311 return cmd_sta_set_wireless_vht(dut, conn, cmd);
9312 if (strcasecmp(val, "60ghz") == 0)
9313 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309314 if (strcasecmp(val, "OCE") == 0)
9315 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02009316 /* sta_set_wireless in WPS program is only used for 60G */
9317 if (is_60g_sigma_dut(dut))
9318 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309319 if (strcasecmp(val, "WPA3") == 0)
9320 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009321 send_resp(dut, conn, SIGMA_ERROR,
9322 "ErrorCode,Program value not supported");
9323 } else {
9324 send_resp(dut, conn, SIGMA_ERROR,
9325 "ErrorCode,Program argument not available");
9326 }
9327
9328 return 0;
9329}
9330
9331
9332static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
9333 int tid)
9334{
9335 char buf[100];
9336 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
9337
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05309338 if (tid < 0 ||
9339 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
9340 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
9341 return;
9342 }
9343
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009344 /*
9345 * Two ways to ensure that addba request with a
9346 * non zero TID could be sent out. EV 117296
9347 */
9348 snprintf(buf, sizeof(buf),
9349 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
9350 tid);
9351 if (system(buf) != 0) {
9352 sigma_dut_print(dut, DUT_MSG_ERROR,
9353 "Ping did not send out");
9354 }
9355
9356 snprintf(buf, sizeof(buf),
9357 "iwconfig %s | grep Access | awk '{print $6}' > %s",
9358 intf, VI_QOS_TMP_FILE);
9359 if (system(buf) != 0)
9360 return;
9361
9362 snprintf(buf, sizeof(buf),
9363 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
9364 intf, VI_QOS_TMP_FILE);
9365 if (system(buf) != 0)
9366 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
9367
9368 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
9369 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
9370 if (system(buf) != 0) {
9371 sigma_dut_print(dut, DUT_MSG_ERROR,
9372 "VI_QOS_TEMP_FILE generation error failed");
9373 }
9374 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9375 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9376 if (system(buf) != 0) {
9377 sigma_dut_print(dut, DUT_MSG_ERROR,
9378 "VI_QOS_FILE generation failed");
9379 }
9380
9381 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9382 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9383 if (system(buf) != 0) {
9384 sigma_dut_print(dut, DUT_MSG_ERROR,
9385 "VI_QOS_FILE generation failed");
9386 }
9387
9388 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
9389 if (system(buf) != 0) {
9390 }
9391}
9392
9393
9394static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9395 struct sigma_cmd *cmd)
9396{
9397 const char *intf = get_param(cmd, "Interface");
9398 const char *val;
9399 int tid = 0;
9400 char buf[100];
9401
9402 val = get_param(cmd, "TID");
9403 if (val) {
9404 tid = atoi(val);
9405 if (tid)
9406 ath_sta_inject_frame(dut, intf, tid);
9407 }
9408
9409 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009410 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009411
9412 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
9413 if (system(buf) != 0) {
9414 sigma_dut_print(dut, DUT_MSG_ERROR,
9415 "wifitool senddelba failed");
9416 }
9417
9418 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
9419 if (system(buf) != 0) {
9420 sigma_dut_print(dut, DUT_MSG_ERROR,
9421 "wifitool sendaddba failed");
9422 }
9423
9424 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9425
9426 return 1;
9427}
9428
9429
Lior David9981b512017-01-20 13:16:40 +02009430#ifdef __linux__
9431
9432static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
9433 int agg_size)
9434{
9435 char dir[128], buf[128];
9436 FILE *f;
9437 regex_t re;
9438 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03009439 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02009440
9441 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
9442 sigma_dut_print(dut, DUT_MSG_ERROR,
9443 "failed to get wil6210 debugfs dir");
9444 return -1;
9445 }
9446
Jouni Malinen3aa72862019-05-29 23:14:51 +03009447 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
9448 if (res < 0 || res >= sizeof(buf))
9449 return -1;
Lior David9981b512017-01-20 13:16:40 +02009450 f = fopen(buf, "r");
9451 if (!f) {
9452 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009453 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009454 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9455 if (res < 0 || res >= sizeof(buf))
9456 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009457 f = fopen(buf, "r");
9458 if (!f) {
9459 sigma_dut_print(dut, DUT_MSG_ERROR,
9460 "failed to open: %s", buf);
9461 return -1;
9462 }
Lior David9981b512017-01-20 13:16:40 +02009463 }
9464
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009465 /* can be either VRING tx... or RING... */
9466 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009467 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9468 goto out;
9469 }
9470
9471 /* find TX VRING for the mac address */
9472 found = 0;
9473 while (fgets(buf, sizeof(buf), f)) {
9474 if (strcasestr(buf, dest_mac)) {
9475 found = 1;
9476 break;
9477 }
9478 }
9479
9480 if (!found) {
9481 sigma_dut_print(dut, DUT_MSG_ERROR,
9482 "no TX VRING for %s", dest_mac);
9483 goto out;
9484 }
9485
9486 /* extract VRING ID, "VRING tx_<id> = {" */
9487 if (!fgets(buf, sizeof(buf), f)) {
9488 sigma_dut_print(dut, DUT_MSG_ERROR,
9489 "no VRING start line for %s", dest_mac);
9490 goto out;
9491 }
9492
9493 rc = regexec(&re, buf, 2, m, 0);
9494 regfree(&re);
9495 if (rc || m[1].rm_so < 0) {
9496 sigma_dut_print(dut, DUT_MSG_ERROR,
9497 "no VRING TX ID for %s", dest_mac);
9498 goto out;
9499 }
9500 buf[m[1].rm_eo] = 0;
9501 vring_id = atoi(&buf[m[1].rm_so]);
9502
9503 /* send the addba command */
9504 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009505 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9506 if (res < 0 || res >= sizeof(buf))
9507 return -1;
Lior David9981b512017-01-20 13:16:40 +02009508 f = fopen(buf, "w");
9509 if (!f) {
9510 sigma_dut_print(dut, DUT_MSG_ERROR,
9511 "failed to open: %s", buf);
9512 return -1;
9513 }
9514
9515 fprintf(f, "add %d %d\n", vring_id, agg_size);
9516
9517 ret = 0;
9518
9519out:
9520 fclose(f);
9521
9522 return ret;
9523}
9524
9525
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009526int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9527 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009528{
9529 const char *val;
9530 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009531
9532 val = get_param(cmd, "TID");
9533 if (val) {
9534 tid = atoi(val);
9535 if (tid != 0) {
9536 sigma_dut_print(dut, DUT_MSG_ERROR,
9537 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9538 tid);
9539 }
9540 }
9541
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009542 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009543 if (!val) {
9544 sigma_dut_print(dut, DUT_MSG_ERROR,
9545 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009546 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009547 }
9548
Lior David9981b512017-01-20 13:16:40 +02009549 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009550 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009551
9552 return 1;
9553}
9554
Lior David9981b512017-01-20 13:16:40 +02009555#endif /* __linux__ */
9556
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009557
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009558static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9559 struct sigma_cmd *cmd)
9560{
9561#ifdef NL80211_SUPPORT
9562 const char *intf = get_param(cmd, "Interface");
9563 const char *val;
9564 int tid = -1;
9565 int bufsize = 64;
9566 struct nl_msg *msg;
9567 int ret = 0;
9568 struct nlattr *params;
9569 int ifindex;
9570
9571 val = get_param(cmd, "TID");
9572 if (val)
9573 tid = atoi(val);
9574
9575 if (tid == -1) {
9576 send_resp(dut, conn, SIGMA_ERROR,
9577 "ErrorCode,sta_send_addba tid invalid");
9578 return 0;
9579 }
9580
9581 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9582
9583 ifindex = if_nametoindex(intf);
9584 if (ifindex == 0) {
9585 sigma_dut_print(dut, DUT_MSG_ERROR,
9586 "%s: Index for interface %s failed",
9587 __func__, intf);
9588 send_resp(dut, conn, SIGMA_ERROR,
9589 "ErrorCode,sta_send_addba interface invalid");
9590 return 0;
9591 }
9592
9593 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9594 NL80211_CMD_VENDOR)) ||
9595 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9596 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9597 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9598 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9599 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9600 nla_put_u8(msg,
9601 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9602 QCA_WLAN_ADD_BA) ||
9603 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9604 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009605 nla_put_u16(msg,
9606 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9607 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009608 sigma_dut_print(dut, DUT_MSG_ERROR,
9609 "%s: err in adding vendor_cmd and vendor_data",
9610 __func__);
9611 nlmsg_free(msg);
9612 send_resp(dut, conn, SIGMA_ERROR,
9613 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9614 return 0;
9615 }
9616 nla_nest_end(msg, params);
9617
9618 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9619 if (ret) {
9620 sigma_dut_print(dut, DUT_MSG_ERROR,
9621 "%s: err in send_and_recv_msgs, ret=%d",
9622 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309623 if (ret == -EOPNOTSUPP)
9624 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009625 send_resp(dut, conn, SIGMA_ERROR,
9626 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9627 return 0;
9628 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009629#else /* NL80211_SUPPORT */
9630 sigma_dut_print(dut, DUT_MSG_ERROR,
9631 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009632#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309633
9634 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009635}
9636
9637
Jouni Malinenf7222712019-06-13 01:50:21 +03009638static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9639 struct sigma_conn *conn,
9640 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009641{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009642 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009643 case DRIVER_ATHEROS:
9644 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009645 case DRIVER_WCN:
9646 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009647#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009648 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009649 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009650#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009651 default:
9652 /*
9653 * There is no driver specific implementation for other drivers.
9654 * Ignore the command and report COMPLETE since the following
9655 * throughput test operation will end up sending ADDBA anyway.
9656 */
9657 return 1;
9658 }
9659}
9660
9661
9662int inject_eth_frame(int s, const void *data, size_t len,
9663 unsigned short ethtype, char *dst, char *src)
9664{
9665 struct iovec iov[4] = {
9666 {
9667 .iov_base = dst,
9668 .iov_len = ETH_ALEN,
9669 },
9670 {
9671 .iov_base = src,
9672 .iov_len = ETH_ALEN,
9673 },
9674 {
9675 .iov_base = &ethtype,
9676 .iov_len = sizeof(unsigned short),
9677 },
9678 {
9679 .iov_base = (void *) data,
9680 .iov_len = len,
9681 }
9682 };
9683 struct msghdr msg = {
9684 .msg_name = NULL,
9685 .msg_namelen = 0,
9686 .msg_iov = iov,
9687 .msg_iovlen = 4,
9688 .msg_control = NULL,
9689 .msg_controllen = 0,
9690 .msg_flags = 0,
9691 };
9692
9693 return sendmsg(s, &msg, 0);
9694}
9695
9696#if defined(__linux__) || defined(__QNXNTO__)
9697
9698int inject_frame(int s, const void *data, size_t len, int encrypt)
9699{
9700#define IEEE80211_RADIOTAP_F_WEP 0x04
9701#define IEEE80211_RADIOTAP_F_FRAG 0x08
9702 unsigned char rtap_hdr[] = {
9703 0x00, 0x00, /* radiotap version */
9704 0x0e, 0x00, /* radiotap length */
9705 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9706 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9707 0x00, /* padding */
9708 0x00, 0x00, /* RX and TX flags to indicate that */
9709 0x00, 0x00, /* this is the injected frame directly */
9710 };
9711 struct iovec iov[2] = {
9712 {
9713 .iov_base = &rtap_hdr,
9714 .iov_len = sizeof(rtap_hdr),
9715 },
9716 {
9717 .iov_base = (void *) data,
9718 .iov_len = len,
9719 }
9720 };
9721 struct msghdr msg = {
9722 .msg_name = NULL,
9723 .msg_namelen = 0,
9724 .msg_iov = iov,
9725 .msg_iovlen = 2,
9726 .msg_control = NULL,
9727 .msg_controllen = 0,
9728 .msg_flags = 0,
9729 };
9730
9731 if (encrypt)
9732 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9733
9734 return sendmsg(s, &msg, 0);
9735}
9736
9737
9738int open_monitor(const char *ifname)
9739{
9740#ifdef __QNXNTO__
9741 struct sockaddr_dl ll;
9742 int s;
9743
9744 memset(&ll, 0, sizeof(ll));
9745 ll.sdl_family = AF_LINK;
9746 ll.sdl_index = if_nametoindex(ifname);
9747 if (ll.sdl_index == 0) {
9748 perror("if_nametoindex");
9749 return -1;
9750 }
9751 s = socket(PF_INET, SOCK_RAW, 0);
9752#else /* __QNXNTO__ */
9753 struct sockaddr_ll ll;
9754 int s;
9755
9756 memset(&ll, 0, sizeof(ll));
9757 ll.sll_family = AF_PACKET;
9758 ll.sll_ifindex = if_nametoindex(ifname);
9759 if (ll.sll_ifindex == 0) {
9760 perror("if_nametoindex");
9761 return -1;
9762 }
9763 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9764#endif /* __QNXNTO__ */
9765 if (s < 0) {
9766 perror("socket[PF_PACKET,SOCK_RAW]");
9767 return -1;
9768 }
9769
9770 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9771 perror("monitor socket bind");
9772 close(s);
9773 return -1;
9774 }
9775
9776 return s;
9777}
9778
9779
9780static int hex2num(char c)
9781{
9782 if (c >= '0' && c <= '9')
9783 return c - '0';
9784 if (c >= 'a' && c <= 'f')
9785 return c - 'a' + 10;
9786 if (c >= 'A' && c <= 'F')
9787 return c - 'A' + 10;
9788 return -1;
9789}
9790
9791
9792int hwaddr_aton(const char *txt, unsigned char *addr)
9793{
9794 int i;
9795
9796 for (i = 0; i < 6; i++) {
9797 int a, b;
9798
9799 a = hex2num(*txt++);
9800 if (a < 0)
9801 return -1;
9802 b = hex2num(*txt++);
9803 if (b < 0)
9804 return -1;
9805 *addr++ = (a << 4) | b;
9806 if (i < 5 && *txt++ != ':')
9807 return -1;
9808 }
9809
9810 return 0;
9811}
9812
9813#endif /* defined(__linux__) || defined(__QNXNTO__) */
9814
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309815
9816#ifdef NL80211_SUPPORT
9817static int nl80211_send_frame_cmd(struct sigma_dut *dut, const char *intf,
9818 const u8 *data, size_t data_len, int freq)
9819{
9820 struct nl_msg *msg;
9821 int ret = 0;
9822 int ifindex;
9823
9824 ifindex = if_nametoindex(intf);
9825 if (ifindex == 0) {
9826 sigma_dut_print(dut, DUT_MSG_ERROR,
9827 "%s: Index for interface %s failed",
9828 __func__, intf);
9829 return -1;
9830 }
9831
9832 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9833 NL80211_CMD_FRAME)) ||
9834 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
9835 nla_put(msg, NL80211_ATTR_FRAME, data_len, data)) {
9836 sigma_dut_print(dut, DUT_MSG_ERROR,
9837 "%s: Error in adding NL80211_CMD_FRAME",
9838 __func__);
9839 nlmsg_free(msg);
9840 return -1;
9841 }
9842
9843 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9844 if (ret) {
9845 sigma_dut_print(dut, DUT_MSG_ERROR,
9846 "nl80211: Frame command failed: ret=%d (%s) req=%u",
9847 ret, strerror(-ret), freq);
9848 return -1;
9849 }
9850
9851 return 0;
9852}
9853#endif /* NL80211_SUPPORT */
9854
9855
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009856enum send_frame_type {
9857 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9858};
9859enum send_frame_protection {
9860 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9861};
9862
9863
9864static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309865 const char *intf, enum send_frame_type frame,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009866 enum send_frame_protection protected,
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309867 const char *dest, int use_monitor)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009868{
9869#ifdef __linux__
9870 unsigned char buf[1000], *pos;
9871 int s, res;
9872 char bssid[20], addr[20];
9873 char result[32], ssid[100];
9874 size_t ssid_len;
9875
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009876 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009877 sizeof(result)) < 0 ||
9878 strncmp(result, "COMPLETED", 9) != 0) {
9879 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9880 return 0;
9881 }
9882
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009883 if (get_wpa_status(get_station_ifname(dut), "bssid",
9884 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009885 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9886 "current BSSID");
9887 return 0;
9888 }
9889
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009890 if (get_wpa_status(get_station_ifname(dut), "address",
9891 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009892 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9893 "own MAC address");
9894 return 0;
9895 }
9896
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009897 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009898 < 0) {
9899 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9900 "current SSID");
9901 return 0;
9902 }
9903 ssid_len = strlen(ssid);
9904
9905 pos = buf;
9906
9907 /* Frame Control */
9908 switch (frame) {
9909 case DISASSOC:
9910 *pos++ = 0xa0;
9911 break;
9912 case DEAUTH:
9913 *pos++ = 0xc0;
9914 break;
9915 case SAQUERY:
9916 *pos++ = 0xd0;
9917 break;
9918 case AUTH:
9919 *pos++ = 0xb0;
9920 break;
9921 case ASSOCREQ:
9922 *pos++ = 0x00;
9923 break;
9924 case REASSOCREQ:
9925 *pos++ = 0x20;
9926 break;
9927 case DLS_REQ:
9928 *pos++ = 0xd0;
9929 break;
9930 }
9931
9932 if (protected == INCORRECT_KEY)
9933 *pos++ = 0x40; /* Set Protected field to 1 */
9934 else
9935 *pos++ = 0x00;
9936
9937 /* Duration */
9938 *pos++ = 0x00;
9939 *pos++ = 0x00;
9940
9941 /* addr1 = DA (current AP) */
9942 hwaddr_aton(bssid, pos);
9943 pos += 6;
9944 /* addr2 = SA (own address) */
9945 hwaddr_aton(addr, pos);
9946 pos += 6;
9947 /* addr3 = BSSID (current AP) */
9948 hwaddr_aton(bssid, pos);
9949 pos += 6;
9950
9951 /* Seq# (to be filled by driver/mac80211) */
9952 *pos++ = 0x00;
9953 *pos++ = 0x00;
9954
9955 if (protected == INCORRECT_KEY) {
9956 /* CCMP parameters */
9957 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9958 pos += 8;
9959 }
9960
9961 if (protected == INCORRECT_KEY) {
9962 switch (frame) {
9963 case DEAUTH:
9964 /* Reason code (encrypted) */
9965 memcpy(pos, "\xa7\x39", 2);
9966 pos += 2;
9967 break;
9968 case DISASSOC:
9969 /* Reason code (encrypted) */
9970 memcpy(pos, "\xa7\x39", 2);
9971 pos += 2;
9972 break;
9973 case SAQUERY:
9974 /* Category|Action|TransID (encrypted) */
9975 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9976 pos += 4;
9977 break;
9978 default:
9979 return -1;
9980 }
9981
9982 /* CCMP MIC */
9983 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9984 pos += 8;
9985 } else {
9986 switch (frame) {
9987 case DEAUTH:
9988 /* reason code = 8 */
9989 *pos++ = 0x08;
9990 *pos++ = 0x00;
9991 break;
9992 case DISASSOC:
9993 /* reason code = 8 */
9994 *pos++ = 0x08;
9995 *pos++ = 0x00;
9996 break;
9997 case SAQUERY:
9998 /* Category - SA Query */
9999 *pos++ = 0x08;
10000 /* SA query Action - Request */
10001 *pos++ = 0x00;
10002 /* Transaction ID */
10003 *pos++ = 0x12;
10004 *pos++ = 0x34;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053010005 if (dut->saquery_oci_freq) {
10006 /* OCI IE - Extended ID */
10007 *pos++ = 0xFF;
10008 *pos++ = 0x04;
10009 *pos++ = 0x36;
10010 /* Operating Class */
10011 *pos++ = 0x74;
10012 /* Primary Channel */
10013 *pos++ = freq_to_channel(dut->saquery_oci_freq);
10014 /* Frequency Segment 1 Channel Number */
10015 *pos++ = 0x00;
10016 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010017 break;
10018 case AUTH:
10019 /* Auth Alg (Open) */
10020 *pos++ = 0x00;
10021 *pos++ = 0x00;
10022 /* Seq# */
10023 *pos++ = 0x01;
10024 *pos++ = 0x00;
10025 /* Status code */
10026 *pos++ = 0x00;
10027 *pos++ = 0x00;
10028 break;
10029 case ASSOCREQ:
10030 /* Capability Information */
10031 *pos++ = 0x31;
10032 *pos++ = 0x04;
10033 /* Listen Interval */
10034 *pos++ = 0x0a;
10035 *pos++ = 0x00;
10036 /* SSID */
10037 *pos++ = 0x00;
10038 *pos++ = ssid_len;
10039 memcpy(pos, ssid, ssid_len);
10040 pos += ssid_len;
10041 /* Supported Rates */
10042 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
10043 10);
10044 pos += 10;
10045 /* Extended Supported Rates */
10046 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
10047 pos += 6;
10048 /* RSN */
10049 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
10050 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
10051 "\x00\x00\x00\x00\x0f\xac\x06", 28);
10052 pos += 28;
10053 break;
10054 case REASSOCREQ:
10055 /* Capability Information */
10056 *pos++ = 0x31;
10057 *pos++ = 0x04;
10058 /* Listen Interval */
10059 *pos++ = 0x0a;
10060 *pos++ = 0x00;
10061 /* Current AP */
10062 hwaddr_aton(bssid, pos);
10063 pos += 6;
10064 /* SSID */
10065 *pos++ = 0x00;
10066 *pos++ = ssid_len;
10067 memcpy(pos, ssid, ssid_len);
10068 pos += ssid_len;
10069 /* Supported Rates */
10070 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
10071 10);
10072 pos += 10;
10073 /* Extended Supported Rates */
10074 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
10075 pos += 6;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053010076 /* RSNE - Group and Pairwise ciphers */
10077 memcpy(pos,
10078 "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04",
10079 14);
10080 pos += 14;
10081 /* RSNE - AKM Suite count */
10082 *pos++ = 0x01;
10083 *pos++ = 0x00;
10084 /* RSNE - AKM Suites */
10085 if (dut->program == PROGRAM_WPA3)
10086 memcpy(pos, "\x00\x0f\xac\x08", 4);
10087 else
10088 memcpy(pos, "\x00\x0f\xac\x02", 4);
10089 pos += 4;
10090 /* RSNE - Capabilities */
10091 *pos++ = 0xc0;
10092 if (dut->ocvc)
10093 *pos++ = 0x40;
10094 else
10095 *pos++ = 0x00;
10096 /* RSNE - PMKID list and Group Management Ciphers */
10097 memcpy(pos, "\x00\x00\x00\x0f\xac\x06", 6);
10098 pos += 6;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010099 break;
10100 case DLS_REQ:
10101 /* Category - DLS */
10102 *pos++ = 0x02;
10103 /* DLS Action - Request */
10104 *pos++ = 0x00;
10105 /* Destination MACAddress */
10106 if (dest)
10107 hwaddr_aton(dest, pos);
10108 else
10109 memset(pos, 0, 6);
10110 pos += 6;
10111 /* Source MACAddress */
10112 hwaddr_aton(addr, pos);
10113 pos += 6;
10114 /* Capability Information */
10115 *pos++ = 0x10; /* Privacy */
10116 *pos++ = 0x06; /* QoS */
10117 /* DLS Timeout Value */
10118 *pos++ = 0x00;
10119 *pos++ = 0x01;
10120 /* Supported rates */
10121 *pos++ = 0x01;
10122 *pos++ = 0x08;
10123 *pos++ = 0x0c; /* 6 Mbps */
10124 *pos++ = 0x12; /* 9 Mbps */
10125 *pos++ = 0x18; /* 12 Mbps */
10126 *pos++ = 0x24; /* 18 Mbps */
10127 *pos++ = 0x30; /* 24 Mbps */
10128 *pos++ = 0x48; /* 36 Mbps */
10129 *pos++ = 0x60; /* 48 Mbps */
10130 *pos++ = 0x6c; /* 54 Mbps */
10131 /* TODO: Extended Supported Rates */
10132 /* TODO: HT Capabilities */
10133 break;
10134 }
10135 }
10136
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010137 if (use_monitor) {
10138 s = open_monitor("sigmadut");
10139 if (s < 0) {
10140 send_resp(dut, conn, SIGMA_ERROR,
10141 "errorCode,Failed to open monitor socket");
10142 return 0;
10143 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010144
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010145 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
10146 if (res < 0) {
10147 send_resp(dut, conn, SIGMA_ERROR,
10148 "errorCode,Failed to inject frame");
10149 close(s);
10150 return 0;
10151 }
10152 if (res < pos - buf) {
10153 send_resp(dut, conn, SIGMA_ERROR,
10154 "errorCode,Only partial frame sent");
10155 close(s);
10156 return 0;
10157 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010158
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010159 close(s);
10160 } else {
10161#ifdef NL80211_SUPPORT
10162 int freq;
10163 char freq_str[10];
10164
10165 if (get_wpa_status(get_station_ifname(dut), "freq",
10166 freq_str, sizeof(freq_str)) < 0) {
10167 send_resp(dut, conn, SIGMA_ERROR,
10168 "errorCode,Could not get current operating frequency");
10169 return 0;
10170 }
10171 freq = atoi(freq_str);
10172
10173 if (nl80211_send_frame_cmd(dut, intf, buf, pos - buf, freq)) {
10174 send_resp(dut, conn, SIGMA_ERROR,
10175 "errorCode,Failed to inject frame");
10176 return 0;
10177 }
10178#else /* NL80211_SUPPORT */
10179 send_resp(dut, conn, SIGMA_ERROR,
10180 "errorCode,Failed to inject frame (no NL80211_SUPPORT)");
10181 return 0;
10182#endif /* NL80211_SUPPORT */
10183 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010184
10185 return 1;
10186#else /* __linux__ */
10187 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
10188 "yet supported");
10189 return 0;
10190#endif /* __linux__ */
10191}
10192
10193
10194static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
10195 struct sigma_conn *conn,
10196 struct sigma_cmd *cmd)
10197{
10198 const char *intf = get_param(cmd, "Interface");
10199 const char *sta, *val;
10200 unsigned char addr[ETH_ALEN];
10201 char buf[100];
10202
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010203 if (!intf)
10204 return -1;
10205
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010206 sta = get_param(cmd, "peer");
10207 if (sta == NULL)
10208 sta = get_param(cmd, "station");
10209 if (sta == NULL) {
10210 send_resp(dut, conn, SIGMA_ERROR,
10211 "ErrorCode,Missing peer address");
10212 return 0;
10213 }
10214 if (hwaddr_aton(sta, addr) < 0) {
10215 send_resp(dut, conn, SIGMA_ERROR,
10216 "ErrorCode,Invalid peer address");
10217 return 0;
10218 }
10219
10220 val = get_param(cmd, "type");
10221 if (val == NULL)
10222 return -1;
10223
10224 if (strcasecmp(val, "DISCOVERY") == 0) {
10225 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
10226 if (wpa_command(intf, buf) < 0) {
10227 send_resp(dut, conn, SIGMA_ERROR,
10228 "ErrorCode,Failed to send TDLS discovery");
10229 return 0;
10230 }
10231 return 1;
10232 }
10233
10234 if (strcasecmp(val, "SETUP") == 0) {
10235 int status = 0, timeout = 0;
10236
10237 val = get_param(cmd, "Status");
10238 if (val)
10239 status = atoi(val);
10240
10241 val = get_param(cmd, "Timeout");
10242 if (val)
10243 timeout = atoi(val);
10244
10245 if (status != 0 && status != 37) {
10246 send_resp(dut, conn, SIGMA_ERROR,
10247 "ErrorCode,Unsupported status value");
10248 return 0;
10249 }
10250
10251 if (timeout != 0 && timeout != 301) {
10252 send_resp(dut, conn, SIGMA_ERROR,
10253 "ErrorCode,Unsupported timeout value");
10254 return 0;
10255 }
10256
10257 if (status && timeout) {
10258 send_resp(dut, conn, SIGMA_ERROR,
10259 "ErrorCode,Unsupported timeout+status "
10260 "combination");
10261 return 0;
10262 }
10263
10264 if (status == 37 &&
10265 wpa_command(intf, "SET tdls_testing 0x200")) {
10266 send_resp(dut, conn, SIGMA_ERROR,
10267 "ErrorCode,Failed to enable "
10268 "decline setup response test mode");
10269 return 0;
10270 }
10271
10272 if (timeout == 301) {
10273 int res;
10274 if (dut->no_tpk_expiration)
10275 res = wpa_command(intf,
10276 "SET tdls_testing 0x108");
10277 else
10278 res = wpa_command(intf,
10279 "SET tdls_testing 0x8");
10280 if (res) {
10281 send_resp(dut, conn, SIGMA_ERROR,
10282 "ErrorCode,Failed to set short TPK "
10283 "lifetime");
10284 return 0;
10285 }
10286 }
10287
10288 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
10289 if (wpa_command(intf, buf) < 0) {
10290 send_resp(dut, conn, SIGMA_ERROR,
10291 "ErrorCode,Failed to send TDLS setup");
10292 return 0;
10293 }
10294 return 1;
10295 }
10296
10297 if (strcasecmp(val, "TEARDOWN") == 0) {
10298 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
10299 if (wpa_command(intf, buf) < 0) {
10300 send_resp(dut, conn, SIGMA_ERROR,
10301 "ErrorCode,Failed to send TDLS teardown");
10302 return 0;
10303 }
10304 return 1;
10305 }
10306
10307 send_resp(dut, conn, SIGMA_ERROR,
10308 "ErrorCode,Unsupported TDLS frame");
10309 return 0;
10310}
10311
10312
10313static int sta_ap_known(const char *ifname, const char *bssid)
10314{
10315 char buf[4096];
10316
Jouni Malinendd32f192018-09-15 02:55:19 +030010317 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010318 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
10319 return 0;
10320 if (strncmp(buf, "id=", 3) != 0)
10321 return 0;
10322 return 1;
10323}
10324
10325
10326static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
10327 const char *bssid)
10328{
10329 int res;
10330 struct wpa_ctrl *ctrl;
10331 char buf[256];
10332
10333 if (sta_ap_known(ifname, bssid))
10334 return 0;
10335 sigma_dut_print(dut, DUT_MSG_DEBUG,
10336 "AP not in BSS table - start scan");
10337
10338 ctrl = open_wpa_mon(ifname);
10339 if (ctrl == NULL) {
10340 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10341 "wpa_supplicant monitor connection");
10342 return -1;
10343 }
10344
10345 if (wpa_command(ifname, "SCAN") < 0) {
10346 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
10347 wpa_ctrl_detach(ctrl);
10348 wpa_ctrl_close(ctrl);
10349 return -1;
10350 }
10351
10352 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
10353 buf, sizeof(buf));
10354
10355 wpa_ctrl_detach(ctrl);
10356 wpa_ctrl_close(ctrl);
10357
10358 if (res < 0) {
10359 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
10360 return -1;
10361 }
10362
10363 if (sta_ap_known(ifname, bssid))
10364 return 0;
10365 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
10366 return -1;
10367}
10368
10369
10370static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
10371 struct sigma_conn *conn,
10372 struct sigma_cmd *cmd,
10373 const char *intf)
10374{
10375 char buf[200];
10376
10377 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
10378 if (system(buf) != 0) {
10379 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
10380 "ndsend");
10381 return 0;
10382 }
10383
10384 return 1;
10385}
10386
10387
10388static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
10389 struct sigma_conn *conn,
10390 struct sigma_cmd *cmd,
10391 const char *intf)
10392{
10393 char buf[200];
10394 const char *ip = get_param(cmd, "SenderIP");
10395
Peng Xu26b356d2017-10-04 17:58:16 -070010396 if (!ip)
10397 return 0;
10398
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010399 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
10400 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10401 if (system(buf) == 0) {
10402 sigma_dut_print(dut, DUT_MSG_INFO,
10403 "Neighbor Solicitation got a response "
10404 "for %s@%s", ip, intf);
10405 }
10406
10407 return 1;
10408}
10409
10410
10411static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
10412 struct sigma_conn *conn,
10413 struct sigma_cmd *cmd,
10414 const char *ifname)
10415{
10416 char buf[200];
10417 const char *ip = get_param(cmd, "SenderIP");
10418
10419 if (ip == NULL) {
10420 send_resp(dut, conn, SIGMA_ERROR,
10421 "ErrorCode,Missing SenderIP parameter");
10422 return 0;
10423 }
10424 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
10425 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10426 if (system(buf) != 0) {
10427 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
10428 "for %s@%s", ip, ifname);
10429 }
10430
10431 return 1;
10432}
10433
10434
10435static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
10436 struct sigma_conn *conn,
10437 struct sigma_cmd *cmd,
10438 const char *ifname)
10439{
10440 char buf[200];
10441 char ip[16];
10442 int s;
Peng Xub3756882017-10-04 14:39:09 -070010443 struct ifreq ifr;
10444 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010445
10446 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070010447 if (s < 0) {
10448 perror("socket");
10449 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010450 }
10451
Peng Xub3756882017-10-04 14:39:09 -070010452 memset(&ifr, 0, sizeof(ifr));
10453 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
10454 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
10455 sigma_dut_print(dut, DUT_MSG_INFO,
10456 "Failed to get %s IP address: %s",
10457 ifname, strerror(errno));
10458 close(s);
10459 return -1;
10460 }
10461 close(s);
10462
10463 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
10464 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
10465
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010466 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
10467 ip);
10468 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10469 if (system(buf) != 0) {
10470 }
10471
10472 return 1;
10473}
10474
10475
10476static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
10477 struct sigma_conn *conn,
10478 struct sigma_cmd *cmd,
10479 const char *ifname)
10480{
10481 char buf[200], addr[20];
10482 char dst[ETH_ALEN], src[ETH_ALEN];
10483 short ethtype = htons(ETH_P_ARP);
10484 char *pos;
10485 int s, res;
10486 const char *val;
10487 struct sockaddr_in taddr;
10488
10489 val = get_param(cmd, "dest");
10490 if (val)
10491 hwaddr_aton(val, (unsigned char *) dst);
10492
10493 val = get_param(cmd, "DestIP");
10494 if (val)
10495 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070010496 else
10497 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010498
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010499 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010500 sizeof(addr)) < 0)
10501 return -2;
10502 hwaddr_aton(addr, (unsigned char *) src);
10503
10504 pos = buf;
10505 *pos++ = 0x00;
10506 *pos++ = 0x01;
10507 *pos++ = 0x08;
10508 *pos++ = 0x00;
10509 *pos++ = 0x06;
10510 *pos++ = 0x04;
10511 *pos++ = 0x00;
10512 *pos++ = 0x02;
10513 memcpy(pos, src, ETH_ALEN);
10514 pos += ETH_ALEN;
10515 memcpy(pos, &taddr.sin_addr, 4);
10516 pos += 4;
10517 memcpy(pos, dst, ETH_ALEN);
10518 pos += ETH_ALEN;
10519 memcpy(pos, &taddr.sin_addr, 4);
10520 pos += 4;
10521
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010522 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010523 if (s < 0) {
10524 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
10525 "monitor socket");
10526 return 0;
10527 }
10528
10529 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
10530 if (res < 0) {
10531 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
10532 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053010533 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010534 return 0;
10535 }
10536
10537 close(s);
10538
10539 return 1;
10540}
10541
10542
10543static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
10544 struct sigma_conn *conn,
10545 struct sigma_cmd *cmd,
10546 const char *intf, const char *dest)
10547{
10548 char buf[100];
10549
10550 if (if_nametoindex("sigmadut") == 0) {
10551 snprintf(buf, sizeof(buf),
10552 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010553 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010554 if (system(buf) != 0 ||
10555 if_nametoindex("sigmadut") == 0) {
10556 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10557 "monitor interface with '%s'", buf);
10558 return -2;
10559 }
10560 }
10561
10562 if (system("ifconfig sigmadut up") != 0) {
10563 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10564 "monitor interface up");
10565 return -2;
10566 }
10567
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010568 return sta_inject_frame(dut, conn, intf, DLS_REQ, UNPROTECTED, dest, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010569}
10570
10571
10572static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10573 struct sigma_conn *conn,
10574 struct sigma_cmd *cmd)
10575{
10576 const char *intf = get_param(cmd, "Interface");
10577 const char *dest = get_param(cmd, "Dest");
10578 const char *type = get_param(cmd, "FrameName");
10579 const char *val;
10580 char buf[200], *pos, *end;
10581 int count, count2;
10582
10583 if (type == NULL)
10584 type = get_param(cmd, "Type");
10585
10586 if (intf == NULL || dest == NULL || type == NULL)
10587 return -1;
10588
10589 if (strcasecmp(type, "NeighAdv") == 0)
10590 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10591
10592 if (strcasecmp(type, "NeighSolicitReq") == 0)
10593 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10594
10595 if (strcasecmp(type, "ARPProbe") == 0)
10596 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10597
10598 if (strcasecmp(type, "ARPAnnounce") == 0)
10599 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10600
10601 if (strcasecmp(type, "ARPReply") == 0)
10602 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10603
10604 if (strcasecmp(type, "DLS-request") == 0 ||
10605 strcasecmp(type, "DLSrequest") == 0)
10606 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10607 dest);
10608
10609 if (strcasecmp(type, "ANQPQuery") != 0 &&
10610 strcasecmp(type, "Query") != 0) {
10611 send_resp(dut, conn, SIGMA_ERROR,
10612 "ErrorCode,Unsupported HS 2.0 send frame type");
10613 return 0;
10614 }
10615
10616 if (sta_scan_ap(dut, intf, dest) < 0) {
10617 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10618 "the requested AP");
10619 return 0;
10620 }
10621
10622 pos = buf;
10623 end = buf + sizeof(buf);
10624 count = 0;
10625 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10626
10627 val = get_param(cmd, "ANQP_CAP_LIST");
10628 if (val && atoi(val)) {
10629 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10630 count++;
10631 }
10632
10633 val = get_param(cmd, "VENUE_NAME");
10634 if (val && atoi(val)) {
10635 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10636 count++;
10637 }
10638
10639 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10640 if (val && atoi(val)) {
10641 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10642 count++;
10643 }
10644
10645 val = get_param(cmd, "ROAMING_CONS");
10646 if (val && atoi(val)) {
10647 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10648 count++;
10649 }
10650
10651 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10652 if (val && atoi(val)) {
10653 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10654 count++;
10655 }
10656
10657 val = get_param(cmd, "NAI_REALM_LIST");
10658 if (val && atoi(val)) {
10659 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10660 count++;
10661 }
10662
10663 val = get_param(cmd, "3GPP_INFO");
10664 if (val && atoi(val)) {
10665 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10666 count++;
10667 }
10668
10669 val = get_param(cmd, "DOMAIN_LIST");
10670 if (val && atoi(val)) {
10671 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10672 count++;
10673 }
10674
Jouni Malinen34cf9532018-04-29 19:26:33 +030010675 val = get_param(cmd, "Venue_URL");
10676 if (val && atoi(val)) {
10677 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10678 count++;
10679 }
10680
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010681 val = get_param(cmd, "Advice_Of_Charge");
10682 if (val && atoi(val)) {
10683 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10684 count++;
10685 }
10686
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010687 if (count && wpa_command(intf, buf)) {
10688 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10689 return 0;
10690 }
10691
10692 pos = buf;
10693 end = buf + sizeof(buf);
10694 count2 = 0;
10695 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
10696
10697 val = get_param(cmd, "HS_CAP_LIST");
10698 if (val && atoi(val)) {
10699 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
10700 count2++;
10701 }
10702
10703 val = get_param(cmd, "OPER_NAME");
10704 if (val && atoi(val)) {
10705 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
10706 count2++;
10707 }
10708
10709 val = get_param(cmd, "WAN_METRICS");
10710 if (!val)
10711 val = get_param(cmd, "WAN_MAT");
10712 if (!val)
10713 val = get_param(cmd, "WAN_MET");
10714 if (val && atoi(val)) {
10715 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10716 count2++;
10717 }
10718
10719 val = get_param(cmd, "CONNECTION_CAPABILITY");
10720 if (val && atoi(val)) {
10721 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10722 count2++;
10723 }
10724
10725 val = get_param(cmd, "OP_CLASS");
10726 if (val && atoi(val)) {
10727 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10728 count2++;
10729 }
10730
10731 val = get_param(cmd, "OSU_PROVIDER_LIST");
10732 if (val && atoi(val)) {
10733 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10734 count2++;
10735 }
10736
Jouni Malinenf67afec2018-04-29 19:24:58 +030010737 val = get_param(cmd, "OPER_ICON_METADATA");
10738 if (!val)
10739 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10740 if (val && atoi(val)) {
10741 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10742 count2++;
10743 }
10744
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010745 if (count && count2) {
10746 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10747 "second query");
10748 sleep(1);
10749 }
10750
10751 if (count2 && wpa_command(intf, buf)) {
10752 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10753 "failed");
10754 return 0;
10755 }
10756
10757 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10758 if (val) {
10759 if (count || count2) {
10760 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10761 "sending out second query");
10762 sleep(1);
10763 }
10764
10765 if (strcmp(val, "1") == 0)
10766 val = "mail.example.com";
10767 snprintf(buf, end - pos,
10768 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10769 dest, val);
10770 if (wpa_command(intf, buf)) {
10771 send_resp(dut, conn, SIGMA_ERROR,
10772 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10773 "failed");
10774 return 0;
10775 }
10776 }
10777
10778 val = get_param(cmd, "ICON_REQUEST");
10779 if (val) {
10780 if (count || count2) {
10781 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10782 "sending out second query");
10783 sleep(1);
10784 }
10785
10786 snprintf(buf, end - pos,
10787 "HS20_ICON_REQUEST %s %s", dest, val);
10788 if (wpa_command(intf, buf)) {
10789 send_resp(dut, conn, SIGMA_ERROR,
10790 "ErrorCode,HS20_ICON_REQUEST failed");
10791 return 0;
10792 }
10793 }
10794
10795 return 1;
10796}
10797
10798
10799static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10800 struct sigma_conn *conn,
10801 struct sigma_cmd *cmd)
10802{
10803 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010804 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010805 int chwidth, nss;
10806
10807 val = get_param(cmd, "framename");
10808 if (!val)
10809 return -1;
10810 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10811
10812 /* Command sequence to generate Op mode notification */
10813 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010814 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010815
10816 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010817 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010818
10819 /* Extract Channel width */
10820 val = get_param(cmd, "Channel_width");
10821 if (val) {
10822 switch (atoi(val)) {
10823 case 20:
10824 chwidth = 0;
10825 break;
10826 case 40:
10827 chwidth = 1;
10828 break;
10829 case 80:
10830 chwidth = 2;
10831 break;
10832 case 160:
10833 chwidth = 3;
10834 break;
10835 default:
10836 chwidth = 2;
10837 break;
10838 }
10839
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010840 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010841 }
10842
10843 /* Extract NSS */
10844 val = get_param(cmd, "NSS");
10845 if (val) {
10846 switch (atoi(val)) {
10847 case 1:
10848 nss = 1;
10849 break;
10850 case 2:
10851 nss = 3;
10852 break;
10853 case 3:
10854 nss = 7;
10855 break;
10856 default:
10857 /* We do not support NSS > 3 */
10858 nss = 3;
10859 break;
10860 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010861 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010862 }
10863
10864 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010865 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010866 }
10867
10868 return 1;
10869}
10870
10871
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010872static int wcn_sta_set_pmf_config(struct sigma_dut *dut, const char *intf,
10873 enum send_frame_protection protected)
10874{
10875#ifdef NL80211_SUPPORT
10876 struct nl_msg *msg;
10877 int ret = 0;
10878 struct nlattr *params;
10879 int ifindex;
10880
10881 ifindex = if_nametoindex(intf);
10882 if (ifindex == 0) {
10883 sigma_dut_print(dut, DUT_MSG_ERROR,
10884 "%s: Index for interface %s failed",
10885 __func__, intf);
10886 return -1;
10887 }
10888
10889 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10890 NL80211_CMD_VENDOR)) ||
10891 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
10892 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10893 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10894 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
10895 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10896 nla_put_u8(msg,
10897 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PMF_PROTECTION,
10898 protected)) {
10899 sigma_dut_print(dut, DUT_MSG_ERROR,
10900 "%s: err in adding vendor_cmd and vendor_data",
10901 __func__);
10902 nlmsg_free(msg);
10903 return -1;
10904 }
10905 nla_nest_end(msg, params);
10906
10907 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
10908 if (ret) {
10909 sigma_dut_print(dut, DUT_MSG_ERROR,
10910 "%s: err in send_and_recv_msgs, ret=%d",
10911 __func__, ret);
10912 }
10913 return ret;
10914#else /* NL80211_SUPPORT */
10915 sigma_dut_print(dut, DUT_MSG_ERROR,
10916 "PMF config cannot be set without NL80211_SUPPORT defined");
10917 return -1;
10918#endif /* NL80211_SUPPORT */
10919}
10920
10921
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010922static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
10923 struct sigma_conn *conn,
10924 struct sigma_cmd *cmd)
10925{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010926 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010927 case DRIVER_ATHEROS:
10928 return ath_sta_send_frame_vht(dut, conn, cmd);
10929 default:
10930 send_resp(dut, conn, SIGMA_ERROR,
10931 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
10932 return 0;
10933 }
10934}
10935
10936
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010937static int wcn_sta_send_disassoc(struct sigma_dut *dut, const char *intf)
10938{
10939#ifdef NL80211_SUPPORT
10940 struct nl_msg *msg;
10941 int ret = 0;
10942 struct nlattr *params;
10943 int ifindex;
10944
10945 ifindex = if_nametoindex(intf);
10946 if (ifindex == 0) {
10947 sigma_dut_print(dut, DUT_MSG_ERROR,
10948 "%s: Index for interface %s failed",
10949 __func__, intf);
10950 return -1;
10951 }
10952
10953 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10954 NL80211_CMD_VENDOR)) ||
10955 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
10956 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10957 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10958 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
10959 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10960 nla_put_flag(msg,
10961 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISASSOC_TX)) {
10962 sigma_dut_print(dut, DUT_MSG_ERROR,
10963 "%s: err in adding vendor_cmd and vendor_data",
10964 __func__);
10965 nlmsg_free(msg);
10966 return -1;
10967 }
10968 nla_nest_end(msg, params);
10969
10970 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
10971 if (ret) {
10972 sigma_dut_print(dut, DUT_MSG_ERROR,
10973 "%s: err in send_and_recv_msgs, ret=%d",
10974 __func__, ret);
10975 }
10976 return ret;
10977#else /* NL80211_SUPPORT */
10978 sigma_dut_print(dut, DUT_MSG_ERROR,
10979 "Disassoc Tx cannot be done without NL80211_SUPPORT defined");
10980 return -1;
10981#endif /* NL80211_SUPPORT */
10982}
10983
10984
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010985static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
10986 struct sigma_cmd *cmd)
10987{
10988 const char *val;
10989 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010990 enum send_frame_protection protected;
10991 const char *pmf;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010992
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010993 if (!intf)
10994 return -1;
10995
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010996 val = get_param(cmd, "framename");
10997 if (!val)
10998 return -1;
10999 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
11000
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011001 pmf = get_param(cmd, "PMFProtected");
11002 if (!pmf)
11003 pmf = get_param(cmd, "Protected");
11004 if (pmf) {
11005 if (strcasecmp(pmf, "Correct-key") == 0 ||
11006 strcasecmp(pmf, "CorrectKey") == 0) {
11007 protected = CORRECT_KEY;
11008 } else if (strcasecmp(pmf, "IncorrectKey") == 0) {
11009 protected = INCORRECT_KEY;
11010 } else if (strcasecmp(pmf, "Unprotected") == 0) {
11011 protected = UNPROTECTED;
11012 } else {
11013 send_resp(dut, conn, SIGMA_ERROR,
11014 "errorCode,Unsupported PMFProtected");
11015 return STATUS_SENT_ERROR;
11016 }
11017 sigma_dut_print(dut, DUT_MSG_DEBUG, "Config PMF protection %d",
11018 protected);
11019 wcn_sta_set_pmf_config(dut, intf, protected);
11020 }
11021
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011022 /* Command sequence to generate Op mode notification */
11023 if (val && strcasecmp(val, "action") == 0) {
11024 val = get_param(cmd, "PPDUTxType");
11025 if (val && strcasecmp(val, "TB") == 0) {
11026 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
11027 sigma_dut_print(dut, DUT_MSG_ERROR,
11028 "failed to send TB PPDU Tx cfg");
11029 send_resp(dut, conn, SIGMA_ERROR,
11030 "ErrorCode,set TB PPDU Tx cfg failed");
11031 return 0;
11032 }
11033 return 1;
11034 }
11035
11036 sigma_dut_print(dut, DUT_MSG_ERROR,
11037 "Action Tx type is not defined");
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011038
11039 return SUCCESS_SEND_STATUS;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011040 }
11041
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011042 if (strcasecmp(val, "disassoc") == 0)
11043 wcn_sta_send_disassoc(dut, intf);
11044
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011045 return 1;
11046}
11047
11048
11049static int cmd_sta_send_frame_he(struct sigma_dut *dut,
11050 struct sigma_conn *conn,
11051 struct sigma_cmd *cmd)
11052{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011053 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011054 case DRIVER_WCN:
11055 return wcn_sta_send_frame_he(dut, conn, cmd);
11056 default:
11057 send_resp(dut, conn, SIGMA_ERROR,
11058 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
11059 return 0;
11060 }
11061}
11062
11063
Lior David0fe101e2017-03-09 16:09:50 +020011064#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011065
11066static int
11067wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
11068 const char *frame_name, const char *dest_mac)
11069{
11070 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
11071 const char *ssid = get_param(cmd, "ssid");
11072 const char *countstr = get_param(cmd, "count");
11073 const char *channelstr = get_param(cmd, "channel");
11074 const char *group_id = get_param(cmd, "groupid");
11075 const char *client_id = get_param(cmd, "clientmac");
11076 int count, channel, freq, i;
11077 const char *fname;
11078 char frame[1024], src_mac[20], group_id_attr[25],
11079 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
11080 const char *group_ssid;
11081 const int group_ssid_prefix_len = 9;
11082 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
11083 size_t framelen = sizeof(frame);
11084 struct template_frame_tag tags[2];
11085 size_t tags_total = ARRAY_SIZE(tags);
11086 int tag_index, len, dst_len;
11087
11088 if (!countstr || !channelstr) {
11089 sigma_dut_print(dut, DUT_MSG_ERROR,
11090 "Missing argument: count, channel");
11091 return -1;
11092 }
11093 if (isprobereq && !ssid) {
11094 sigma_dut_print(dut, DUT_MSG_ERROR,
11095 "Missing argument: ssid");
11096 return -1;
11097 }
11098 if (!isprobereq && (!group_id || !client_id)) {
11099 sigma_dut_print(dut, DUT_MSG_ERROR,
11100 "Missing argument: group_id, client_id");
11101 return -1;
11102 }
11103
11104 count = atoi(countstr);
11105 channel = atoi(channelstr);
11106 freq = channel_to_freq(dut, channel);
11107
11108 if (!freq) {
11109 sigma_dut_print(dut, DUT_MSG_ERROR,
11110 "invalid channel: %s", channelstr);
11111 return -1;
11112 }
11113
11114 if (isprobereq) {
11115 if (strcasecmp(ssid, "wildcard") == 0) {
11116 fname = "probe_req_wildcard.txt";
11117 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
11118 fname = "probe_req_P2P_Wildcard.txt";
11119 } else {
11120 sigma_dut_print(dut, DUT_MSG_ERROR,
11121 "invalid probe request type");
11122 return -1;
11123 }
11124 } else {
11125 fname = "P2P_device_discovery_req.txt";
11126 }
11127
11128 if (parse_template_frame_file(dut, fname, frame, &framelen,
11129 tags, &tags_total)) {
11130 sigma_dut_print(dut, DUT_MSG_ERROR,
11131 "invalid frame template: %s", fname);
11132 return -1;
11133 }
11134
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011135 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011136 src_mac, sizeof(src_mac)) < 0 ||
11137 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
11138 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
11139 return -1;
11140 /* Use wildcard BSSID, since we are in PBSS */
11141 memset(&hdr->addr3, 0xFF, ETH_ALEN);
11142
11143 if (!isprobereq) {
11144 tag_index = find_template_frame_tag(tags, tags_total, 1);
11145 if (tag_index < 0) {
11146 sigma_dut_print(dut, DUT_MSG_ERROR,
11147 "can't find device id attribute");
11148 return -1;
11149 }
11150 if (parse_mac_address(dut, client_id,
11151 (unsigned char *) client_mac)) {
11152 sigma_dut_print(dut, DUT_MSG_ERROR,
11153 "invalid client_id: %s", client_id);
11154 return -1;
11155 }
11156 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11157 framelen - tags[tag_index].offset,
11158 IEEE80211_P2P_ATTR_DEVICE_ID,
11159 client_mac, ETH_ALEN)) {
11160 sigma_dut_print(dut, DUT_MSG_ERROR,
11161 "fail to replace device id attribute");
11162 return -1;
11163 }
11164
11165 /*
11166 * group_id arg contains device MAC address followed by
11167 * space and SSID (DIRECT-somessid).
11168 * group id attribute contains device address (6 bytes)
11169 * followed by SSID prefix DIRECT-XX (9 bytes)
11170 */
11171 if (strlen(group_id) < sizeof(device_macstr)) {
11172 sigma_dut_print(dut, DUT_MSG_ERROR,
11173 "group_id arg too short");
11174 return -1;
11175 }
11176 memcpy(device_macstr, group_id, sizeof(device_macstr));
11177 device_macstr[sizeof(device_macstr) - 1] = '\0';
11178 if (parse_mac_address(dut, device_macstr,
11179 (unsigned char *) group_id_attr)) {
11180 sigma_dut_print(dut, DUT_MSG_ERROR,
11181 "fail to parse device address from group_id");
11182 return -1;
11183 }
11184 group_ssid = strchr(group_id, ' ');
11185 if (!group_ssid) {
11186 sigma_dut_print(dut, DUT_MSG_ERROR,
11187 "invalid group_id arg, no ssid");
11188 return -1;
11189 }
11190 group_ssid++;
11191 len = strlen(group_ssid);
11192 if (len < group_ssid_prefix_len) {
11193 sigma_dut_print(dut, DUT_MSG_ERROR,
11194 "group_id SSID too short");
11195 return -1;
11196 }
11197 dst_len = sizeof(group_id_attr) - ETH_ALEN;
11198 if (len > dst_len) {
11199 sigma_dut_print(dut, DUT_MSG_ERROR,
11200 "group_id SSID (%s) too long",
11201 group_ssid);
11202 return -1;
11203 }
11204
11205 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
11206 tag_index = find_template_frame_tag(tags, tags_total, 2);
11207 if (tag_index < 0) {
11208 sigma_dut_print(dut, DUT_MSG_ERROR,
11209 "can't find group id attribute");
11210 return -1;
11211 }
11212 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11213 framelen - tags[tag_index].offset,
11214 IEEE80211_P2P_ATTR_GROUP_ID,
11215 group_id_attr,
11216 sizeof(group_id_attr))) {
11217 sigma_dut_print(dut, DUT_MSG_ERROR,
11218 "fail to replace group id attribute");
11219 return -1;
11220 }
11221 }
11222
11223 for (i = 0; i < count; i++) {
11224 if (wil6210_transmit_frame(dut, freq,
11225 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
11226 frame, framelen)) {
11227 sigma_dut_print(dut, DUT_MSG_ERROR,
11228 "fail to transmit probe request frame");
11229 return -1;
11230 }
11231 }
11232
11233 return 0;
11234}
11235
11236
Lior David0fe101e2017-03-09 16:09:50 +020011237int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
11238 struct sigma_cmd *cmd)
11239{
11240 const char *frame_name = get_param(cmd, "framename");
11241 const char *mac = get_param(cmd, "dest_mac");
11242
11243 if (!frame_name || !mac) {
11244 sigma_dut_print(dut, DUT_MSG_ERROR,
11245 "framename and dest_mac must be provided");
11246 return -1;
11247 }
11248
11249 if (strcasecmp(frame_name, "brp") == 0) {
11250 const char *l_rx = get_param(cmd, "L-RX");
11251 int l_rx_i;
11252
11253 if (!l_rx) {
11254 sigma_dut_print(dut, DUT_MSG_ERROR,
11255 "L-RX must be provided");
11256 return -1;
11257 }
11258 l_rx_i = atoi(l_rx);
11259
11260 sigma_dut_print(dut, DUT_MSG_INFO,
11261 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
11262 mac, l_rx);
11263 if (l_rx_i != 16) {
11264 sigma_dut_print(dut, DUT_MSG_ERROR,
11265 "unsupported L-RX: %s", l_rx);
11266 return -1;
11267 }
11268
11269 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
11270 return -1;
11271 } else if (strcasecmp(frame_name, "ssw") == 0) {
11272 sigma_dut_print(dut, DUT_MSG_INFO,
11273 "dev_send_frame: SLS, dest_mac %s", mac);
11274 if (wil6210_send_sls(dut, mac))
11275 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011276 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
11277 (strcasecmp(frame_name, "devdiscreq") == 0)) {
11278 sigma_dut_print(dut, DUT_MSG_INFO,
11279 "dev_send_frame: %s, dest_mac %s", frame_name,
11280 mac);
11281 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
11282 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020011283 } else {
11284 sigma_dut_print(dut, DUT_MSG_ERROR,
11285 "unsupported frame type: %s", frame_name);
11286 return -1;
11287 }
11288
11289 return 1;
11290}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011291
Lior David0fe101e2017-03-09 16:09:50 +020011292#endif /* __linux__ */
11293
11294
11295static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
11296 struct sigma_conn *conn,
11297 struct sigma_cmd *cmd)
11298{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011299 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020011300#ifdef __linux__
11301 case DRIVER_WIL6210:
11302 return wil6210_send_frame_60g(dut, conn, cmd);
11303#endif /* __linux__ */
11304 default:
11305 send_resp(dut, conn, SIGMA_ERROR,
11306 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
11307 return 0;
11308 }
11309}
11310
11311
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011312static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
11313 const char *intf, struct sigma_cmd *cmd)
11314{
11315 const char *val, *addr;
11316 char buf[100];
11317
11318 addr = get_param(cmd, "DestMac");
11319 if (!addr) {
11320 send_resp(dut, conn, SIGMA_INVALID,
11321 "ErrorCode,AP MAC address is missing");
11322 return 0;
11323 }
11324
11325 val = get_param(cmd, "ANQPQuery_ID");
11326 if (!val) {
11327 send_resp(dut, conn, SIGMA_INVALID,
11328 "ErrorCode,Missing ANQPQuery_ID");
11329 return 0;
11330 }
11331
11332 if (strcasecmp(val, "NeighborReportReq") == 0) {
11333 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
11334 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
11335 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
11336 } else {
11337 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
11338 val);
11339 send_resp(dut, conn, SIGMA_INVALID,
11340 "ErrorCode,Invalid ANQPQuery_ID");
11341 return 0;
11342 }
11343
Ashwini Patild174f2c2017-04-13 16:49:46 +053011344 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
11345 * (Address3 = Wildcard BSSID when sent to not-associated AP;
11346 * if associated, AP BSSID).
11347 */
11348 if (wpa_command(intf, "SET gas_address3 1") < 0) {
11349 send_resp(dut, conn, SIGMA_ERROR,
11350 "ErrorCode,Failed to set gas_address3");
11351 return 0;
11352 }
11353
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011354 if (wpa_command(intf, buf) < 0) {
11355 send_resp(dut, conn, SIGMA_ERROR,
11356 "ErrorCode,Failed to send ANQP query");
11357 return 0;
11358 }
11359
11360 return 1;
11361}
11362
11363
11364static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
11365 struct sigma_conn *conn,
11366 const char *intf,
11367 struct sigma_cmd *cmd)
11368{
11369 const char *val = get_param(cmd, "FrameName");
11370
11371 if (val && strcasecmp(val, "ANQPQuery") == 0)
11372 return mbo_send_anqp_query(dut, conn, intf, cmd);
11373
11374 return 2;
11375}
11376
11377
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011378static enum sigma_cmd_result cmd_sta_send_frame_wpa3(struct sigma_dut *dut,
11379 struct sigma_conn *conn,
11380 const char *intf,
11381 struct sigma_cmd *cmd)
11382{
11383 const char *val = get_param(cmd, "framename");
11384
11385 if (!val)
11386 return INVALID_SEND_STATUS;
11387
11388 if (strcasecmp(val, "SAQueryReq") == 0) {
11389 val = get_param(cmd, "OCIChannel");
11390
11391 if (!val) {
11392 send_resp(dut, conn, SIGMA_ERROR,
11393 "errorCode,OCIChannel not present");
11394 return STATUS_SENT_ERROR;
11395 }
11396
11397 dut->saquery_oci_freq = channel_to_freq(dut, atoi(val));
11398 if (!dut->saquery_oci_freq) {
11399 send_resp(dut, conn, SIGMA_ERROR,
11400 "errorCode,Invalid OCIChannel number");
11401 return STATUS_SENT_ERROR;
11402 }
11403
11404 return sta_inject_frame(dut, conn, intf, SAQUERY, CORRECT_KEY,
11405 NULL, 0);
11406 }
11407
11408 if (strcasecmp(val, "reassocreq") == 0)
11409 return sta_inject_frame(dut, conn, intf, REASSOCREQ,
11410 CORRECT_KEY, NULL, 0);
11411
11412 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported framename");
11413 return STATUS_SENT_ERROR;
11414}
11415
11416
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011417static enum sigma_cmd_result
11418cmd_sta_send_frame_mscs(struct sigma_dut *dut, struct sigma_conn *conn,
11419 const char *intf, struct sigma_cmd *cmd)
11420{
11421 char buf[128], *pos;
11422 const char *val, *classifier_type = "04", *type;
11423 int len, rem_len;
11424 u8 up_bitmap;
11425
11426 val = get_param(cmd, "FrameName");
11427 type = get_param(cmd, "Request_Type");
11428 if (!val || !type || strcasecmp(val, "MSCSReq") != 0) {
11429 sigma_dut_print(dut, DUT_MSG_ERROR,
11430 "%s: frame name or type not valid", __func__);
11431 return INVALID_SEND_STATUS;
11432 }
11433
11434 rem_len = sizeof(buf);
11435 pos = buf;
11436 if (strcasecmp(type, "add") == 0) {
11437 len = snprintf(pos, rem_len, "MSCS add");
11438 } else if (strcasecmp(type, "update") == 0) {
11439 len = snprintf(pos, rem_len, "MSCS change");
11440 } else if (strcasecmp(type, "remove") == 0) {
11441 if (wpa_command(intf, "MSCS remove") != 0) {
11442 send_resp(dut, conn, SIGMA_ERROR,
11443 "ErrorCode,Failed to send MSCS frame req");
11444 return STATUS_SENT_ERROR;
11445 }
11446 return SUCCESS_SEND_STATUS;
11447 } else {
11448 sigma_dut_print(dut, DUT_MSG_ERROR,
11449 "%s: request type invalid", __func__);
11450 return INVALID_SEND_STATUS;
11451 }
11452
11453 if (len < 0 || len >= rem_len)
11454 goto fail;
11455
11456 pos += len;
11457 rem_len -= len;
11458
11459 val = get_param(cmd, "User_Priority_Bitmap");
11460 if (!val) {
11461 sigma_dut_print(dut, DUT_MSG_ERROR,
11462 "%s: user priority bitmap empty", __func__);
11463 return INVALID_SEND_STATUS;
11464 }
11465
11466 switch (atoi(val)) {
11467 case 0:
11468 up_bitmap = 0x00;
11469 break;
11470 case 1:
11471 up_bitmap = 0xF0;
11472 break;
11473 case 2:
11474 up_bitmap = 0xF6;
11475 break;
11476 default:
11477 sigma_dut_print(dut, DUT_MSG_ERROR,
11478 "%s: Unknown User_Priority_Bitmap value %d",
11479 __func__, atoi(val));
11480 return INVALID_SEND_STATUS;
11481 }
11482
11483 len = snprintf(pos, rem_len, " up_bitmap=%02x", up_bitmap);
11484 if (len < 0 || len >= rem_len)
11485 goto fail;
11486
11487 pos += len;
11488 rem_len -= len;
11489
11490 val = get_param(cmd, "User_Priority_Limit");
11491 if (!val) {
11492 sigma_dut_print(dut, DUT_MSG_ERROR,
11493 "%s: invalid user priority limit", __func__);
11494 return INVALID_SEND_STATUS;
11495 }
11496
11497 len = snprintf(pos, rem_len, " up_limit=%s", val);
11498 if (len < 0 || len >= rem_len)
11499 goto fail;
11500
11501 pos += len;
11502 rem_len -= len;
11503
11504 val = get_param(cmd, "Stream_Timeout");
11505 if (!val)
11506 val = get_param(cmd, "Stream_Timtout");
11507 if (!val) {
11508 sigma_dut_print(dut, DUT_MSG_ERROR,
11509 "%s: invalid stream timeout", __func__);
11510 return INVALID_SEND_STATUS;
11511 }
11512
11513 len = snprintf(pos, rem_len, " stream_timeout=%s", val);
11514 if (len < 0 || len >= rem_len)
11515 goto fail;
11516
11517 pos += len;
11518 rem_len -= len;
11519
11520 val = get_param(cmd, "TCLAS_Mask");
11521 if (!val) {
11522 sigma_dut_print(dut, DUT_MSG_ERROR,
11523 "%s: invalid tclas mask", __func__);
11524 return INVALID_SEND_STATUS;
11525 }
11526
11527 len = snprintf(pos, rem_len, " frame_classifier=%s%lx%032x",
11528 classifier_type, strtol(val, NULL, 2), 0);
11529 if (len < 0 || len >= rem_len)
11530 goto fail;
11531
11532 if (wpa_command(intf, buf) != 0) {
11533 send_resp(dut, conn, SIGMA_ERROR,
11534 "ErrorCode,Failed to send MSCS frame req");
11535 return STATUS_SENT_ERROR;
11536 }
11537
11538 sigma_dut_print(dut, DUT_MSG_DEBUG,
11539 "MSCS frame request sent: %s", buf);
11540
11541 return SUCCESS_SEND_STATUS;
11542fail:
11543 sigma_dut_print(dut, DUT_MSG_ERROR,
11544 "Failed to create MSCS frame req");
11545 return ERROR_SEND_STATUS;
11546}
11547
11548
Jouni Malinenf7222712019-06-13 01:50:21 +030011549enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
11550 struct sigma_conn *conn,
11551 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011552{
11553 const char *intf = get_param(cmd, "Interface");
11554 const char *val;
11555 enum send_frame_type frame;
11556 enum send_frame_protection protected;
11557 char buf[100];
11558 unsigned char addr[ETH_ALEN];
11559 int res;
11560
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011561 if (!intf)
11562 return -1;
11563
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011564 val = get_param(cmd, "program");
11565 if (val == NULL)
11566 val = get_param(cmd, "frame");
11567 if (val && strcasecmp(val, "TDLS") == 0)
11568 return cmd_sta_send_frame_tdls(dut, conn, cmd);
11569 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011570 strcasecmp(val, "HS2-R2") == 0 ||
11571 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011572 return cmd_sta_send_frame_hs2(dut, conn, cmd);
11573 if (val && strcasecmp(val, "VHT") == 0)
11574 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011575 if (val && strcasecmp(val, "HE") == 0)
11576 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070011577 if (val && strcasecmp(val, "LOC") == 0)
11578 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020011579 if (val && strcasecmp(val, "60GHz") == 0)
11580 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011581 if (val && strcasecmp(val, "MBO") == 0) {
11582 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
11583 if (res != 2)
11584 return res;
11585 }
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011586 if (val && strcasecmp(val, "WPA3") == 0)
11587 return cmd_sta_send_frame_wpa3(dut, conn, intf, cmd);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011588 if (val && strcasecmp(val, "QM") == 0)
11589 return cmd_sta_send_frame_mscs(dut, conn, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011590
11591 val = get_param(cmd, "TD_DISC");
11592 if (val) {
11593 if (hwaddr_aton(val, addr) < 0)
11594 return -1;
11595 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
11596 if (wpa_command(intf, buf) < 0) {
11597 send_resp(dut, conn, SIGMA_ERROR,
11598 "ErrorCode,Failed to send TDLS discovery");
11599 return 0;
11600 }
11601 return 1;
11602 }
11603
11604 val = get_param(cmd, "TD_Setup");
11605 if (val) {
11606 if (hwaddr_aton(val, addr) < 0)
11607 return -1;
11608 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
11609 if (wpa_command(intf, buf) < 0) {
11610 send_resp(dut, conn, SIGMA_ERROR,
11611 "ErrorCode,Failed to start TDLS setup");
11612 return 0;
11613 }
11614 return 1;
11615 }
11616
11617 val = get_param(cmd, "TD_TearDown");
11618 if (val) {
11619 if (hwaddr_aton(val, addr) < 0)
11620 return -1;
11621 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
11622 if (wpa_command(intf, buf) < 0) {
11623 send_resp(dut, conn, SIGMA_ERROR,
11624 "ErrorCode,Failed to tear down TDLS link");
11625 return 0;
11626 }
11627 return 1;
11628 }
11629
11630 val = get_param(cmd, "TD_ChannelSwitch");
11631 if (val) {
11632 /* TODO */
11633 send_resp(dut, conn, SIGMA_ERROR,
11634 "ErrorCode,TD_ChannelSwitch not yet supported");
11635 return 0;
11636 }
11637
11638 val = get_param(cmd, "TD_NF");
11639 if (val) {
11640 /* TODO */
11641 send_resp(dut, conn, SIGMA_ERROR,
11642 "ErrorCode,TD_NF not yet supported");
11643 return 0;
11644 }
11645
11646 val = get_param(cmd, "PMFFrameType");
11647 if (val == NULL)
11648 val = get_param(cmd, "FrameName");
11649 if (val == NULL)
11650 val = get_param(cmd, "Type");
11651 if (val == NULL)
11652 return -1;
11653 if (strcasecmp(val, "disassoc") == 0)
11654 frame = DISASSOC;
11655 else if (strcasecmp(val, "deauth") == 0)
11656 frame = DEAUTH;
11657 else if (strcasecmp(val, "saquery") == 0)
11658 frame = SAQUERY;
11659 else if (strcasecmp(val, "auth") == 0)
11660 frame = AUTH;
11661 else if (strcasecmp(val, "assocreq") == 0)
11662 frame = ASSOCREQ;
11663 else if (strcasecmp(val, "reassocreq") == 0)
11664 frame = REASSOCREQ;
11665 else if (strcasecmp(val, "neigreq") == 0) {
11666 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
11667
11668 val = get_param(cmd, "ssid");
11669 if (val == NULL)
11670 return -1;
11671
11672 res = send_neighbor_request(dut, intf, val);
11673 if (res) {
11674 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11675 "Failed to send neighbor report request");
11676 return 0;
11677 }
11678
11679 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053011680 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
11681 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011682 sigma_dut_print(dut, DUT_MSG_DEBUG,
11683 "Got Transition Management Query");
11684
Ashwini Patil5acd7382017-04-13 15:55:04 +053011685 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011686 if (res) {
11687 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11688 "Failed to send Transition Management Query");
11689 return 0;
11690 }
11691
11692 return 1;
11693 } else {
11694 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11695 "PMFFrameType");
11696 return 0;
11697 }
11698
11699 val = get_param(cmd, "PMFProtected");
11700 if (val == NULL)
11701 val = get_param(cmd, "Protected");
11702 if (val == NULL)
11703 return -1;
11704 if (strcasecmp(val, "Correct-key") == 0 ||
11705 strcasecmp(val, "CorrectKey") == 0)
11706 protected = CORRECT_KEY;
11707 else if (strcasecmp(val, "IncorrectKey") == 0)
11708 protected = INCORRECT_KEY;
11709 else if (strcasecmp(val, "Unprotected") == 0)
11710 protected = UNPROTECTED;
11711 else {
11712 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11713 "PMFProtected");
11714 return 0;
11715 }
11716
11717 if (protected != UNPROTECTED &&
11718 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
11719 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
11720 "PMFProtected for auth/assocreq/reassocreq");
11721 return 0;
11722 }
11723
11724 if (if_nametoindex("sigmadut") == 0) {
11725 snprintf(buf, sizeof(buf),
11726 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011727 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011728 if (system(buf) != 0 ||
11729 if_nametoindex("sigmadut") == 0) {
11730 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11731 "monitor interface with '%s'", buf);
11732 return -2;
11733 }
11734 }
11735
11736 if (system("ifconfig sigmadut up") != 0) {
11737 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11738 "monitor interface up");
11739 return -2;
11740 }
11741
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011742 return sta_inject_frame(dut, conn, intf, frame, protected, NULL, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011743}
11744
11745
11746static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
11747 struct sigma_conn *conn,
11748 struct sigma_cmd *cmd,
11749 const char *ifname)
11750{
11751 char buf[200];
11752 const char *val;
11753
11754 val = get_param(cmd, "ClearARP");
11755 if (val && atoi(val) == 1) {
11756 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
11757 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11758 if (system(buf) != 0) {
11759 send_resp(dut, conn, SIGMA_ERROR,
11760 "errorCode,Failed to clear ARP cache");
11761 return 0;
11762 }
11763 }
11764
11765 return 1;
11766}
11767
11768
11769int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
11770 struct sigma_cmd *cmd)
11771{
11772 const char *intf = get_param(cmd, "Interface");
11773 const char *val;
11774
11775 if (intf == NULL)
11776 return -1;
11777
11778 val = get_param(cmd, "program");
11779 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011780 strcasecmp(val, "HS2-R2") == 0 ||
11781 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011782 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
11783
11784 return -1;
11785}
11786
11787
Jouni Malinenf7222712019-06-13 01:50:21 +030011788static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
11789 struct sigma_conn *conn,
11790 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011791{
11792 const char *intf = get_param(cmd, "Interface");
11793 const char *mac = get_param(cmd, "MAC");
11794
11795 if (intf == NULL || mac == NULL)
11796 return -1;
11797
11798 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
11799 "interface %s to %s", intf, mac);
11800
11801 if (dut->set_macaddr) {
11802 char buf[128];
11803 int res;
11804 if (strcasecmp(mac, "default") == 0) {
11805 res = snprintf(buf, sizeof(buf), "%s",
11806 dut->set_macaddr);
11807 dut->tmp_mac_addr = 0;
11808 } else {
11809 res = snprintf(buf, sizeof(buf), "%s %s",
11810 dut->set_macaddr, mac);
11811 dut->tmp_mac_addr = 1;
11812 }
11813 if (res < 0 || res >= (int) sizeof(buf))
11814 return -1;
11815 if (system(buf) != 0) {
11816 send_resp(dut, conn, SIGMA_ERROR,
11817 "errorCode,Failed to set MAC "
11818 "address");
11819 return 0;
11820 }
11821 return 1;
11822 }
11823
11824 if (strcasecmp(mac, "default") == 0)
11825 return 1;
11826
11827 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11828 "command");
11829 return 0;
11830}
11831
11832
11833static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
11834 struct sigma_conn *conn, const char *intf,
11835 int val)
11836{
11837 char buf[200];
11838 int res;
11839
11840 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
11841 intf, val);
11842 if (res < 0 || res >= (int) sizeof(buf))
11843 return -1;
11844 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11845 if (system(buf) != 0) {
11846 send_resp(dut, conn, SIGMA_ERROR,
11847 "errorCode,Failed to configure offchannel mode");
11848 return 0;
11849 }
11850
11851 return 1;
11852}
11853
11854
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011855static int off_chan_val(enum sec_ch_offset off)
11856{
11857 switch (off) {
11858 case SEC_CH_NO:
11859 return 0;
11860 case SEC_CH_40ABOVE:
11861 return 40;
11862 case SEC_CH_40BELOW:
11863 return -40;
11864 }
11865
11866 return 0;
11867}
11868
11869
11870static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
11871 const char *intf, int off_ch_num,
11872 enum sec_ch_offset sec)
11873{
11874 char buf[200];
11875 int res;
11876
11877 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
11878 intf, off_ch_num);
11879 if (res < 0 || res >= (int) sizeof(buf))
11880 return -1;
11881 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11882 if (system(buf) != 0) {
11883 send_resp(dut, conn, SIGMA_ERROR,
11884 "errorCode,Failed to set offchan");
11885 return 0;
11886 }
11887
11888 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
11889 intf, off_chan_val(sec));
11890 if (res < 0 || res >= (int) sizeof(buf))
11891 return -1;
11892 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11893 if (system(buf) != 0) {
11894 send_resp(dut, conn, SIGMA_ERROR,
11895 "errorCode,Failed to set sec chan offset");
11896 return 0;
11897 }
11898
11899 return 1;
11900}
11901
11902
11903static int tdls_set_offchannel_offset(struct sigma_dut *dut,
11904 struct sigma_conn *conn,
11905 const char *intf, int off_ch_num,
11906 enum sec_ch_offset sec)
11907{
11908 char buf[200];
11909 int res;
11910
11911 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
11912 off_ch_num);
11913 if (res < 0 || res >= (int) sizeof(buf))
11914 return -1;
11915 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11916
11917 if (wpa_command(intf, buf) < 0) {
11918 send_resp(dut, conn, SIGMA_ERROR,
11919 "ErrorCode,Failed to set offchan");
11920 return 0;
11921 }
11922 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
11923 off_chan_val(sec));
11924 if (res < 0 || res >= (int) sizeof(buf))
11925 return -1;
11926
11927 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11928
11929 if (wpa_command(intf, buf) < 0) {
11930 send_resp(dut, conn, SIGMA_ERROR,
11931 "ErrorCode,Failed to set sec chan offset");
11932 return 0;
11933 }
11934
11935 return 1;
11936}
11937
11938
11939static int tdls_set_offchannel_mode(struct sigma_dut *dut,
11940 struct sigma_conn *conn,
11941 const char *intf, int val)
11942{
11943 char buf[200];
11944 int res;
11945
11946 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
11947 val);
11948 if (res < 0 || res >= (int) sizeof(buf))
11949 return -1;
11950 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11951
11952 if (wpa_command(intf, buf) < 0) {
11953 send_resp(dut, conn, SIGMA_ERROR,
11954 "ErrorCode,Failed to configure offchannel mode");
11955 return 0;
11956 }
11957
11958 return 1;
11959}
11960
11961
11962static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
11963 struct sigma_conn *conn,
11964 struct sigma_cmd *cmd)
11965{
11966 const char *val;
11967 enum {
11968 CHSM_NOT_SET,
11969 CHSM_ENABLE,
11970 CHSM_DISABLE,
11971 CHSM_REJREQ,
11972 CHSM_UNSOLRESP
11973 } chsm = CHSM_NOT_SET;
11974 int off_ch_num = -1;
11975 enum sec_ch_offset sec_ch = SEC_CH_NO;
11976 int res;
11977
11978 val = get_param(cmd, "Uapsd");
11979 if (val) {
11980 char buf[100];
11981 if (strcasecmp(val, "Enable") == 0)
11982 snprintf(buf, sizeof(buf), "SET ps 99");
11983 else if (strcasecmp(val, "Disable") == 0)
11984 snprintf(buf, sizeof(buf), "SET ps 98");
11985 else {
11986 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11987 "Unsupported uapsd parameter value");
11988 return 0;
11989 }
11990 if (wpa_command(intf, buf)) {
11991 send_resp(dut, conn, SIGMA_ERROR,
11992 "ErrorCode,Failed to change U-APSD "
11993 "powersave mode");
11994 return 0;
11995 }
11996 }
11997
11998 val = get_param(cmd, "TPKTIMER");
11999 if (val && strcasecmp(val, "DISABLE") == 0) {
12000 if (wpa_command(intf, "SET tdls_testing 0x100")) {
12001 send_resp(dut, conn, SIGMA_ERROR,
12002 "ErrorCode,Failed to enable no TPK "
12003 "expiration test mode");
12004 return 0;
12005 }
12006 dut->no_tpk_expiration = 1;
12007 }
12008
12009 val = get_param(cmd, "ChSwitchMode");
12010 if (val) {
12011 if (strcasecmp(val, "Enable") == 0 ||
12012 strcasecmp(val, "Initiate") == 0)
12013 chsm = CHSM_ENABLE;
12014 else if (strcasecmp(val, "Disable") == 0 ||
12015 strcasecmp(val, "passive") == 0)
12016 chsm = CHSM_DISABLE;
12017 else if (strcasecmp(val, "RejReq") == 0)
12018 chsm = CHSM_REJREQ;
12019 else if (strcasecmp(val, "UnSolResp") == 0)
12020 chsm = CHSM_UNSOLRESP;
12021 else {
12022 send_resp(dut, conn, SIGMA_ERROR,
12023 "ErrorCode,Unknown ChSwitchMode value");
12024 return 0;
12025 }
12026 }
12027
12028 val = get_param(cmd, "OffChNum");
12029 if (val) {
12030 off_ch_num = atoi(val);
12031 if (off_ch_num == 0) {
12032 send_resp(dut, conn, SIGMA_ERROR,
12033 "ErrorCode,Invalid OffChNum");
12034 return 0;
12035 }
12036 }
12037
12038 val = get_param(cmd, "SecChOffset");
12039 if (val) {
12040 if (strcmp(val, "20") == 0)
12041 sec_ch = SEC_CH_NO;
12042 else if (strcasecmp(val, "40above") == 0)
12043 sec_ch = SEC_CH_40ABOVE;
12044 else if (strcasecmp(val, "40below") == 0)
12045 sec_ch = SEC_CH_40BELOW;
12046 else {
12047 send_resp(dut, conn, SIGMA_ERROR,
12048 "ErrorCode,Unknown SecChOffset value");
12049 return 0;
12050 }
12051 }
12052
12053 if (chsm == CHSM_NOT_SET) {
12054 /* no offchannel changes requested */
12055 return 1;
12056 }
12057
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012058 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
12059 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012060 send_resp(dut, conn, SIGMA_ERROR,
12061 "ErrorCode,Unknown interface");
12062 return 0;
12063 }
12064
12065 switch (chsm) {
12066 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030012067 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012068 break;
12069 case CHSM_ENABLE:
12070 if (off_ch_num < 0) {
12071 send_resp(dut, conn, SIGMA_ERROR,
12072 "ErrorCode,Missing OffChNum argument");
12073 return 0;
12074 }
12075 if (wifi_chip_type == DRIVER_WCN) {
12076 res = tdls_set_offchannel_offset(dut, conn, intf,
12077 off_ch_num, sec_ch);
12078 } else {
12079 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
12080 sec_ch);
12081 }
12082 if (res != 1)
12083 return res;
12084 if (wifi_chip_type == DRIVER_WCN)
12085 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
12086 else
12087 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
12088 break;
12089 case CHSM_DISABLE:
12090 if (wifi_chip_type == DRIVER_WCN)
12091 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
12092 else
12093 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
12094 break;
12095 case CHSM_REJREQ:
12096 if (wifi_chip_type == DRIVER_WCN)
12097 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
12098 else
12099 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
12100 break;
12101 case CHSM_UNSOLRESP:
12102 if (off_ch_num < 0) {
12103 send_resp(dut, conn, SIGMA_ERROR,
12104 "ErrorCode,Missing OffChNum argument");
12105 return 0;
12106 }
12107 if (wifi_chip_type == DRIVER_WCN) {
12108 res = tdls_set_offchannel_offset(dut, conn, intf,
12109 off_ch_num, sec_ch);
12110 } else {
12111 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
12112 sec_ch);
12113 }
12114 if (res != 1)
12115 return res;
12116 if (wifi_chip_type == DRIVER_WCN)
12117 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
12118 else
12119 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
12120 break;
12121 }
12122
12123 return res;
12124}
12125
12126
12127static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
12128 struct sigma_conn *conn,
12129 struct sigma_cmd *cmd)
12130{
12131 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053012132 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012133
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070012134 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080012135
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012136 val = get_param(cmd, "nss_mcs_opt");
12137 if (val) {
12138 /* String (nss_operating_mode; mcs_operating_mode) */
12139 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012140 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012141
12142 token = strdup(val);
12143 if (!token)
12144 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012145 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053012146 if (!result) {
12147 sigma_dut_print(dut, DUT_MSG_ERROR,
12148 "VHT NSS not specified");
12149 goto failed;
12150 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012151 if (strcasecmp(result, "def") != 0) {
12152 nss = atoi(result);
12153 if (nss == 4)
12154 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012155 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012156 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012157
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012158 }
12159
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012160 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053012161 if (!result) {
12162 sigma_dut_print(dut, DUT_MSG_ERROR,
12163 "VHT MCS not specified");
12164 goto failed;
12165 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012166 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012167 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012168 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012169 } else {
12170 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012171 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012172 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012173 }
12174 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012175 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012176 }
12177
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053012178 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012179 return 1;
12180failed:
12181 free(token);
12182 return 0;
12183}
12184
12185
12186static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
12187 struct sigma_conn *conn,
12188 struct sigma_cmd *cmd)
12189{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012190 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012191 case DRIVER_ATHEROS:
12192 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
12193 default:
12194 send_resp(dut, conn, SIGMA_ERROR,
12195 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
12196 return 0;
12197 }
12198}
12199
12200
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012201static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12202 struct sigma_conn *conn,
12203 struct sigma_cmd *cmd)
12204{
12205 const char *val;
12206 char *token = NULL, *result;
12207 char buf[60];
12208
12209 val = get_param(cmd, "nss_mcs_opt");
12210 if (val) {
12211 /* String (nss_operating_mode; mcs_operating_mode) */
12212 int nss, mcs, ratecode;
12213 char *saveptr;
12214
12215 token = strdup(val);
12216 if (!token)
12217 return -2;
12218
12219 result = strtok_r(token, ";", &saveptr);
12220 if (!result) {
12221 sigma_dut_print(dut, DUT_MSG_ERROR,
12222 "HE NSS not specified");
12223 goto failed;
12224 }
12225 nss = 1;
12226 if (strcasecmp(result, "def") != 0)
12227 nss = atoi(result);
12228
12229 result = strtok_r(NULL, ";", &saveptr);
12230 if (!result) {
12231 sigma_dut_print(dut, DUT_MSG_ERROR,
12232 "HE MCS not specified");
12233 goto failed;
12234 }
12235 mcs = 7;
12236 if (strcasecmp(result, "def") != 0)
12237 mcs = atoi(result);
12238
Arif Hussain557bf412018-05-25 17:29:36 -070012239 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012240 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070012241 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012242 } else if (nss > 2) {
12243 sigma_dut_print(dut, DUT_MSG_ERROR,
12244 "HE NSS %d not supported", nss);
12245 goto failed;
12246 }
12247
Arif Hussain557bf412018-05-25 17:29:36 -070012248 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
12249 if (system(buf) != 0) {
12250 sigma_dut_print(dut, DUT_MSG_ERROR,
12251 "nss_mcs_opt: iwpriv %s nss %d failed",
12252 intf, nss);
12253 goto failed;
12254 }
Arif Hussainac6c5112018-05-25 17:34:00 -070012255 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070012256
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012257 /* Add the MCS to the ratecode */
12258 if (mcs >= 0 && mcs <= 11) {
12259 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070012260#ifdef NL80211_SUPPORT
12261 if (dut->device_type == STA_testbed) {
12262 enum he_mcs_config mcs_config;
12263 int ret;
12264
12265 if (mcs <= 7)
12266 mcs_config = HE_80_MCS0_7;
12267 else if (mcs <= 9)
12268 mcs_config = HE_80_MCS0_9;
12269 else
12270 mcs_config = HE_80_MCS0_11;
12271 ret = sta_set_he_mcs(dut, intf, mcs_config);
12272 if (ret) {
12273 sigma_dut_print(dut, DUT_MSG_ERROR,
12274 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
12275 mcs, mcs_config, ret);
12276 goto failed;
12277 }
12278 }
12279#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012280 } else {
12281 sigma_dut_print(dut, DUT_MSG_ERROR,
12282 "HE MCS %d not supported", mcs);
12283 goto failed;
12284 }
12285 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
12286 intf, ratecode);
12287 if (system(buf) != 0) {
12288 sigma_dut_print(dut, DUT_MSG_ERROR,
12289 "iwpriv setting of 11ax rates failed");
12290 goto failed;
12291 }
12292 free(token);
12293 }
12294
12295 val = get_param(cmd, "GI");
12296 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012297 int fix_rate_sgi;
12298
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012299 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012300 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012301 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012302 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012303 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
12304 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012305 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012306 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012307 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
12308 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012309 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012310 } else {
12311 send_resp(dut, conn, SIGMA_ERROR,
12312 "errorCode,GI value not supported");
12313 return 0;
12314 }
12315 if (system(buf) != 0) {
12316 send_resp(dut, conn, SIGMA_ERROR,
12317 "errorCode,Failed to set shortgi");
12318 return 0;
12319 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012320 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
12321 intf, fix_rate_sgi);
12322 if (system(buf) != 0) {
12323 send_resp(dut, conn, SIGMA_ERROR,
12324 "errorCode,Failed to set fix rate shortgi");
12325 return STATUS_SENT;
12326 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012327 }
12328
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012329 val = get_param(cmd, "LTF");
12330 if (val) {
12331#ifdef NL80211_SUPPORT
12332 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012333 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012334 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012335 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012336 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012337 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012338 } else {
12339 send_resp(dut, conn, SIGMA_ERROR,
12340 "errorCode, LTF value not supported");
12341 return 0;
12342 }
12343#else /* NL80211_SUPPORT */
12344 sigma_dut_print(dut, DUT_MSG_ERROR,
12345 "LTF cannot be set without NL80211_SUPPORT defined");
12346 return -2;
12347#endif /* NL80211_SUPPORT */
12348 }
12349
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070012350 val = get_param(cmd, "TxSUPPDU");
12351 if (val) {
12352 int set_val = 1;
12353
12354 if (strcasecmp(val, "Enable") == 0)
12355 set_val = 1;
12356 else if (strcasecmp(val, "Disable") == 0)
12357 set_val = 0;
12358
12359 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
12360 send_resp(dut, conn, SIGMA_ERROR,
12361 "ErrorCode,Failed to set Tx SU PPDU config");
12362 return 0;
12363 }
12364 }
12365
Arif Hussain480d5f42019-03-12 14:40:42 -070012366 val = get_param(cmd, "TWT_Setup");
12367 if (val) {
12368 if (strcasecmp(val, "Request") == 0) {
12369 if (sta_twt_request(dut, conn, cmd)) {
12370 send_resp(dut, conn, SIGMA_ERROR,
12371 "ErrorCode,sta_twt_request failed");
12372 return STATUS_SENT;
12373 }
12374 } else if (strcasecmp(val, "Teardown") == 0) {
12375 if (sta_twt_teardown(dut, conn, cmd)) {
12376 send_resp(dut, conn, SIGMA_ERROR,
12377 "ErrorCode,sta_twt_teardown failed");
12378 return STATUS_SENT;
12379 }
12380 }
12381 }
12382
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080012383 val = get_param(cmd, "transmitOMI");
12384 if (val && sta_transmit_omi(dut, conn, cmd)) {
12385 send_resp(dut, conn, SIGMA_ERROR,
12386 "ErrorCode,sta_transmit_omi failed");
12387 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070012388 }
12389
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012390 val = get_param(cmd, "Powersave");
12391 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012392 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012393
12394 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012395 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012396 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012397 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012398 } else {
12399 sigma_dut_print(dut, DUT_MSG_ERROR,
12400 "Unsupported Powersave value '%s'",
12401 val);
12402 return -1;
12403 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012404 if (set_power_save_wcn(dut, intf, ps) < 0)
12405 return 0;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012406 }
12407
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080012408 val = get_param(cmd, "MU_EDCA");
12409 if (val) {
12410 if (strcasecmp(val, "Override") == 0) {
12411 if (sta_set_mu_edca_override(dut, intf, 1)) {
12412 send_resp(dut, conn, SIGMA_ERROR,
12413 "errorCode,MU EDCA override set failed");
12414 return STATUS_SENT;
12415 }
12416 } else if (strcasecmp(val, "Disable") == 0) {
12417 if (sta_set_mu_edca_override(dut, intf, 0)) {
12418 send_resp(dut, conn, SIGMA_ERROR,
12419 "errorCode,MU EDCA override disable failed");
12420 return STATUS_SENT;
12421 }
12422 }
12423 }
12424
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -070012425 val = get_param(cmd, "Ch_Pref");
12426 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12427 return STATUS_SENT;
12428
12429 val = get_param(cmd, "Cellular_Data_Cap");
12430 if (val && mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12431 return STATUS_SENT;
12432
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012433 return 1;
12434
12435failed:
12436 free(token);
12437 return -2;
12438}
12439
12440
12441static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12442 struct sigma_conn *conn,
12443 struct sigma_cmd *cmd)
12444{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012445 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012446 case DRIVER_WCN:
12447 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
12448 default:
12449 send_resp(dut, conn, SIGMA_ERROR,
12450 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
12451 return 0;
12452 }
12453}
12454
12455
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012456static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
12457 struct sigma_conn *conn,
12458 struct sigma_cmd *cmd)
12459{
12460 const char *val;
12461
12462 val = get_param(cmd, "powersave");
12463 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012464 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012465
12466 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012467 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012468 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012469 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012470 } else {
12471 sigma_dut_print(dut, DUT_MSG_ERROR,
12472 "Unsupported power save config");
12473 return -1;
12474 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012475 if (set_power_save_wcn(dut, intf, ps) < 0)
12476 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012477 return 1;
12478 }
12479
12480 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
12481
12482 return 0;
12483}
12484
12485
Ashwini Patil5acd7382017-04-13 15:55:04 +053012486static int btm_query_candidate_list(struct sigma_dut *dut,
12487 struct sigma_conn *conn,
12488 struct sigma_cmd *cmd)
12489{
12490 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
12491 int len, ret;
12492 char buf[10];
12493
12494 /*
12495 * Neighbor Report elements format:
12496 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
12497 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
12498 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
12499 */
12500
12501 bssid = get_param(cmd, "Nebor_BSSID");
12502 if (!bssid) {
12503 send_resp(dut, conn, SIGMA_INVALID,
12504 "errorCode,Nebor_BSSID is missing");
12505 return 0;
12506 }
12507
12508 info = get_param(cmd, "Nebor_Bssid_Info");
12509 if (!info) {
12510 sigma_dut_print(dut, DUT_MSG_INFO,
12511 "Using default value for Nebor_Bssid_Info: %s",
12512 DEFAULT_NEIGHBOR_BSSID_INFO);
12513 info = DEFAULT_NEIGHBOR_BSSID_INFO;
12514 }
12515
12516 op_class = get_param(cmd, "Nebor_Op_Class");
12517 if (!op_class) {
12518 send_resp(dut, conn, SIGMA_INVALID,
12519 "errorCode,Nebor_Op_Class is missing");
12520 return 0;
12521 }
12522
12523 ch = get_param(cmd, "Nebor_Op_Ch");
12524 if (!ch) {
12525 send_resp(dut, conn, SIGMA_INVALID,
12526 "errorCode,Nebor_Op_Ch is missing");
12527 return 0;
12528 }
12529
12530 phy_type = get_param(cmd, "Nebor_Phy_Type");
12531 if (!phy_type) {
12532 sigma_dut_print(dut, DUT_MSG_INFO,
12533 "Using default value for Nebor_Phy_Type: %s",
12534 DEFAULT_NEIGHBOR_PHY_TYPE);
12535 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
12536 }
12537
12538 /* Parse optional subelements */
12539 buf[0] = '\0';
12540 pref = get_param(cmd, "Nebor_Pref");
12541 if (pref) {
12542 /* hexdump for preferrence subelement */
12543 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
12544 if (ret < 0 || ret >= (int) sizeof(buf)) {
12545 sigma_dut_print(dut, DUT_MSG_ERROR,
12546 "snprintf failed for optional subelement ret: %d",
12547 ret);
12548 send_resp(dut, conn, SIGMA_ERROR,
12549 "errorCode,snprintf failed for subelement");
12550 return 0;
12551 }
12552 }
12553
12554 if (!dut->btm_query_cand_list) {
12555 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
12556 if (!dut->btm_query_cand_list) {
12557 send_resp(dut, conn, SIGMA_ERROR,
12558 "errorCode,Failed to allocate memory for btm_query_cand_list");
12559 return 0;
12560 }
12561 }
12562
12563 len = strlen(dut->btm_query_cand_list);
12564 ret = snprintf(dut->btm_query_cand_list + len,
12565 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
12566 bssid, info, op_class, ch, phy_type, buf);
12567 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
12568 sigma_dut_print(dut, DUT_MSG_ERROR,
12569 "snprintf failed for neighbor report list ret: %d",
12570 ret);
12571 send_resp(dut, conn, SIGMA_ERROR,
12572 "errorCode,snprintf failed for neighbor report");
12573 free(dut->btm_query_cand_list);
12574 dut->btm_query_cand_list = NULL;
12575 return 0;
12576 }
12577
12578 return 1;
12579}
12580
12581
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012582int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
12583 struct sigma_ese_alloc *allocs, int *allocs_size)
12584{
12585 int max_count = *allocs_size;
12586 int count = 0, i;
12587 const char *val;
12588
12589 do {
12590 val = get_param_indexed(cmd, "AllocID", count);
12591 if (val)
12592 count++;
12593 } while (val);
12594
12595 if (count == 0 || count > max_count) {
12596 sigma_dut_print(dut, DUT_MSG_ERROR,
12597 "Invalid number of allocations(%d)", count);
12598 return -1;
12599 }
12600
12601 for (i = 0; i < count; i++) {
12602 val = get_param_indexed(cmd, "PercentBI", i);
12603 if (!val) {
12604 sigma_dut_print(dut, DUT_MSG_ERROR,
12605 "Missing PercentBI parameter at index %d",
12606 i);
12607 return -1;
12608 }
12609 allocs[i].percent_bi = atoi(val);
12610
12611 val = get_param_indexed(cmd, "SrcAID", i);
12612 if (val)
12613 allocs[i].src_aid = strtol(val, NULL, 0);
12614 else
12615 allocs[i].src_aid = ESE_BCAST_AID;
12616
12617 val = get_param_indexed(cmd, "DestAID", i);
12618 if (val)
12619 allocs[i].dst_aid = strtol(val, NULL, 0);
12620 else
12621 allocs[i].dst_aid = ESE_BCAST_AID;
12622
12623 allocs[i].type = ESE_CBAP;
12624 sigma_dut_print(dut, DUT_MSG_INFO,
12625 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
12626 i, allocs[i].percent_bi, allocs[i].src_aid,
12627 allocs[i].dst_aid);
12628 }
12629
12630 *allocs_size = count;
12631 return 0;
12632}
12633
12634
12635static int sta_set_60g_ese(struct sigma_dut *dut, int count,
12636 struct sigma_ese_alloc *allocs)
12637{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012638 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012639#ifdef __linux__
12640 case DRIVER_WIL6210:
12641 if (wil6210_set_ese(dut, count, allocs))
12642 return -1;
12643 return 1;
12644#endif /* __linux__ */
12645 default:
12646 sigma_dut_print(dut, DUT_MSG_ERROR,
12647 "Unsupported sta_set_60g_ese with the current driver");
12648 return -1;
12649 }
12650}
12651
12652
12653static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
12654 struct sigma_conn *conn,
12655 struct sigma_cmd *cmd)
12656{
12657 const char *val;
12658
12659 val = get_param(cmd, "ExtSchIE");
12660 if (val && !strcasecmp(val, "Enable")) {
12661 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
12662 int count = MAX_ESE_ALLOCS;
12663
12664 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
12665 return -1;
12666 return sta_set_60g_ese(dut, count, allocs);
12667 }
12668
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012669 val = get_param(cmd, "MCS_FixedRate");
12670 if (val) {
12671 int sta_mcs = atoi(val);
12672
12673 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
12674 sta_mcs);
12675 wil6210_set_force_mcs(dut, 1, sta_mcs);
12676
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012677 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012678 }
12679
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012680 send_resp(dut, conn, SIGMA_ERROR,
12681 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012682 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012683}
12684
12685
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012686static int wcn_sta_override_oci(struct sigma_dut *dut, const char *intf,
12687 const char *oci_frametype, uint32_t oci_freq)
12688{
12689#ifdef NL80211_SUPPORT
12690 struct nl_msg *msg;
12691 int ret = 0;
12692 struct nlattr *params;
12693 struct nlattr *attr;
12694 int ifindex;
12695 u8 frame_type;
12696
12697 ifindex = if_nametoindex(intf);
12698 if (ifindex == 0) {
12699 sigma_dut_print(dut, DUT_MSG_ERROR,
12700 "%s: Index for interface %s failed",
12701 __func__, intf);
12702 return -1;
12703 }
12704
12705 if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12706 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_REQ;
12707 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12708 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_RESP;
12709 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
12710 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_FT_REASSOC_REQ;
12711 } else {
12712 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: Unknown frametype %s",
12713 __func__, oci_frametype);
12714 return -1;
12715 }
12716
12717
12718 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
12719 NL80211_CMD_VENDOR)) ||
12720 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
12721 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
12722 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
12723 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
12724 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
12725 !(params = nla_nest_start(
12726 msg,
12727 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OCI_OVERRIDE)) ||
12728 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FRAME_TYPE,
12729 frame_type) ||
12730 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FREQUENCY,
12731 oci_freq)) {
12732 sigma_dut_print(dut, DUT_MSG_ERROR,
12733 "%s: err in adding vendor_cmd and vendor_data",
12734 __func__);
12735 nlmsg_free(msg);
12736 return -1;
12737 }
12738 nla_nest_end(msg, params);
12739 nla_nest_end(msg, attr);
12740
12741 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
12742 if (ret) {
12743 sigma_dut_print(dut, DUT_MSG_ERROR,
12744 "%s: err in send_and_recv_msgs, ret=%d",
12745 __func__, ret);
12746 }
12747 return ret;
12748#else /* NL80211_SUPPORT */
12749 sigma_dut_print(dut, DUT_MSG_ERROR,
12750 "OCI override not possible without NL80211_SUPPORT defined");
12751 return -1;
12752#endif /* NL80211_SUPPORT */
12753}
12754
12755
Jouni Malinen6250cb02020-04-15 13:54:45 +030012756static enum sigma_cmd_result
12757cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
12758 struct sigma_conn *conn,
12759 struct sigma_cmd *cmd)
12760{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012761 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030012762
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053012763 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030012764 if (val && atoi(val) == 1) {
12765 if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
12766 send_resp(dut, conn, SIGMA_ERROR,
12767 "errorCode,Failed to set ft_rsnxe_used");
12768 return STATUS_SENT_ERROR;
12769 }
12770 return SUCCESS_SEND_STATUS;
12771 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012772
12773 oci_chan = get_param(cmd, "OCIChannel");
12774 oci_frametype = get_param(cmd, "OCIFrameType");
12775 if (oci_chan && oci_frametype) {
12776 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
12777 char buf[100];
12778
12779 if (!oci_freq) {
12780 send_resp(dut, conn, SIGMA_ERROR,
12781 "errorCode,Invalid OCIChannel number");
12782 return STATUS_SENT_ERROR;
12783 }
12784
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012785 if (wifi_chip_type == DRIVER_WCN &&
12786 (strcasecmp(oci_frametype, "SAQueryReq") == 0 ||
12787 strcasecmp(oci_frametype, "SAQueryResp") == 0 ||
12788 strcasecmp(oci_frametype, "Reassocreq") == 0)) {
12789 if (wcn_sta_override_oci(dut, intf, oci_frametype,
12790 oci_freq)) {
12791 send_resp(dut, conn, SIGMA_ERROR,
12792 "errorCode,Failed to override OCI");
12793 return STATUS_SENT_ERROR;
12794 }
12795 return SUCCESS_SEND_STATUS;
12796 }
12797
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012798 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
12799 snprintf(buf, sizeof(buf),
12800 "SET oci_freq_override_eapol %d", oci_freq);
12801 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12802 snprintf(buf, sizeof(buf),
12803 "SET oci_freq_override_saquery_req %d",
12804 oci_freq);
12805 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12806 snprintf(buf, sizeof(buf),
12807 "SET oci_freq_override_saquery_resp %d",
12808 oci_freq);
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012809 } else if (strcasecmp(oci_frametype, "GrpKeyM2") == 0) {
12810 snprintf(buf, sizeof(buf),
12811 "SET oci_freq_override_eapol_g2 %d",
12812 oci_freq);
12813 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
12814 snprintf(buf, sizeof(buf),
12815 "SET oci_freq_override_ft_assoc %d",
12816 oci_freq);
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012817 } else {
12818 send_resp(dut, conn, SIGMA_ERROR,
12819 "errorCode,Unsupported OCIFrameType");
12820 return STATUS_SENT_ERROR;
12821 }
12822 if (wpa_command(intf, buf) < 0) {
12823 send_resp(dut, conn, SIGMA_ERROR,
12824 "errorCode,Failed to set oci_freq_override");
12825 return STATUS_SENT_ERROR;
12826 }
12827 return SUCCESS_SEND_STATUS;
12828 }
12829
Jouni Malinen6250cb02020-04-15 13:54:45 +030012830 send_resp(dut, conn, SIGMA_ERROR,
12831 "errorCode,Unsupported WPA3 rfeature");
12832 return STATUS_SENT_ERROR;
12833}
12834
12835
Jouni Malinenf7222712019-06-13 01:50:21 +030012836static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
12837 struct sigma_conn *conn,
12838 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012839{
12840 const char *intf = get_param(cmd, "Interface");
12841 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012842 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012843
12844 if (intf == NULL || prog == NULL)
12845 return -1;
12846
Ashwini Patil5acd7382017-04-13 15:55:04 +053012847 /* BSS Transition candidate list for BTM query */
12848 val = get_param(cmd, "Nebor_BSSID");
12849 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
12850 return 0;
12851
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012852 if (strcasecmp(prog, "TDLS") == 0)
12853 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
12854
12855 if (strcasecmp(prog, "VHT") == 0)
12856 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
12857
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012858 if (strcasecmp(prog, "HE") == 0)
12859 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
12860
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012861 if (strcasecmp(prog, "MBO") == 0) {
12862 val = get_param(cmd, "Cellular_Data_Cap");
12863 if (val &&
12864 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12865 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053012866
12867 val = get_param(cmd, "Ch_Pref");
12868 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12869 return 0;
12870
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012871 return 1;
12872 }
12873
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012874 if (strcasecmp(prog, "60GHz") == 0)
12875 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
12876
Jouni Malinen6250cb02020-04-15 13:54:45 +030012877 if (strcasecmp(prog, "WPA3") == 0)
12878 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
12879
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012880 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
12881 return 0;
12882}
12883
12884
Jouni Malinenf7222712019-06-13 01:50:21 +030012885static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
12886 struct sigma_conn *conn,
12887 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012888{
12889 const char *intf = get_param(cmd, "Interface");
12890 const char *mode = get_param(cmd, "Mode");
12891 int res;
12892
12893 if (intf == NULL || mode == NULL)
12894 return -1;
12895
12896 if (strcasecmp(mode, "On") == 0)
12897 res = wpa_command(intf, "SET radio_disabled 0");
12898 else if (strcasecmp(mode, "Off") == 0)
12899 res = wpa_command(intf, "SET radio_disabled 1");
12900 else
12901 return -1;
12902
12903 if (res) {
12904 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12905 "radio mode");
12906 return 0;
12907 }
12908
12909 return 1;
12910}
12911
12912
Jouni Malinenf7222712019-06-13 01:50:21 +030012913static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
12914 struct sigma_conn *conn,
12915 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012916{
12917 const char *intf = get_param(cmd, "Interface");
12918 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012919 const char *prog = get_param(cmd, "program");
12920 const char *powersave = get_param(cmd, "powersave");
12921 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012922
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012923 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012924 return -1;
12925
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012926 if (prog && strcasecmp(prog, "60GHz") == 0) {
12927 /*
12928 * The CAPI mode parameter does not exist in 60G
12929 * unscheduled PS.
12930 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080012931 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012932 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012933 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020012934 strcasecmp(prog, "HE") == 0) {
12935 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012936 } else {
12937 if (mode == NULL)
12938 return -1;
12939
12940 if (strcasecmp(mode, "On") == 0)
12941 res = set_ps(intf, dut, 1);
12942 else if (strcasecmp(mode, "Off") == 0)
12943 res = set_ps(intf, dut, 0);
12944 else
12945 return -1;
12946 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012947
12948 if (res) {
12949 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12950 "power save mode");
12951 return 0;
12952 }
12953
12954 return 1;
12955}
12956
12957
Jouni Malinenf7222712019-06-13 01:50:21 +030012958static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
12959 struct sigma_conn *conn,
12960 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012961{
12962 const char *intf = get_param(cmd, "Interface");
12963 const char *val, *bssid;
12964 int res;
12965 char *buf;
12966 size_t buf_len;
12967
12968 val = get_param(cmd, "BSSID_FILTER");
12969 if (val == NULL)
12970 return -1;
12971
12972 bssid = get_param(cmd, "BSSID_List");
12973 if (atoi(val) == 0 || bssid == NULL) {
12974 /* Disable BSSID filter */
12975 if (wpa_command(intf, "SET bssid_filter ")) {
12976 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
12977 "to disable BSSID filter");
12978 return 0;
12979 }
12980
12981 return 1;
12982 }
12983
12984 buf_len = 100 + strlen(bssid);
12985 buf = malloc(buf_len);
12986 if (buf == NULL)
12987 return -1;
12988
12989 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
12990 res = wpa_command(intf, buf);
12991 free(buf);
12992 if (res) {
12993 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
12994 "BSSID filter");
12995 return 0;
12996 }
12997
12998 return 1;
12999}
13000
13001
Jouni Malinenf7222712019-06-13 01:50:21 +030013002static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
13003 struct sigma_conn *conn,
13004 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013005{
13006 const char *intf = get_param(cmd, "Interface");
13007 const char *val;
13008
13009 /* TODO: ARP */
13010
13011 val = get_param(cmd, "HS2_CACHE_PROFILE");
13012 if (val && strcasecmp(val, "All") == 0)
13013 hs2_clear_credentials(intf);
13014
13015 return 1;
13016}
13017
13018
Jouni Malinenf7222712019-06-13 01:50:21 +030013019static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
13020 struct sigma_conn *conn,
13021 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013022{
13023 const char *intf = get_param(cmd, "Interface");
13024 const char *key_type = get_param(cmd, "KeyType");
13025 char buf[100], resp[200];
13026
13027 if (key_type == NULL)
13028 return -1;
13029
13030 if (strcasecmp(key_type, "GTK") == 0) {
13031 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
13032 strncmp(buf, "FAIL", 4) == 0) {
13033 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13034 "not fetch current GTK");
13035 return 0;
13036 }
13037 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
13038 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13039 return 0;
13040 } else {
13041 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13042 "KeyType");
13043 return 0;
13044 }
13045
13046 return 1;
13047}
13048
13049
13050static int hs2_set_policy(struct sigma_dut *dut)
13051{
13052#ifdef ANDROID
13053 system("ip rule del prio 23000");
13054 if (system("ip rule add from all lookup main prio 23000") != 0) {
13055 sigma_dut_print(dut, DUT_MSG_ERROR,
13056 "Failed to run:ip rule add from all lookup main prio");
13057 return -1;
13058 }
13059 if (system("ip route flush cache") != 0) {
13060 sigma_dut_print(dut, DUT_MSG_ERROR,
13061 "Failed to run ip route flush cache");
13062 return -1;
13063 }
13064 return 1;
13065#else /* ANDROID */
13066 return 0;
13067#endif /* ANDROID */
13068}
13069
13070
Jouni Malinenf7222712019-06-13 01:50:21 +030013071static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
13072 struct sigma_conn *conn,
13073 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013074{
13075 const char *intf = get_param(cmd, "Interface");
13076 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030013077 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013078 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030013079 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013080 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
13081 int tries = 0;
13082 int ignore_blacklist = 0;
13083 const char *events[] = {
13084 "CTRL-EVENT-CONNECTED",
13085 "INTERWORKING-BLACKLISTED",
13086 "INTERWORKING-NO-MATCH",
13087 NULL
13088 };
13089
13090 start_sta_mode(dut);
13091
Jouni Malinen439352d2018-09-13 03:42:23 +030013092 if (band) {
13093 if (strcmp(band, "2.4") == 0) {
13094 wpa_command(intf, "SET setband 2G");
13095 } else if (strcmp(band, "5") == 0) {
13096 wpa_command(intf, "SET setband 5G");
13097 } else {
13098 send_resp(dut, conn, SIGMA_ERROR,
13099 "errorCode,Unsupported band");
13100 return 0;
13101 }
13102 }
13103
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013104 blacklisted[0] = '\0';
13105 if (val && atoi(val))
13106 ignore_blacklist = 1;
13107
13108try_again:
13109 ctrl = open_wpa_mon(intf);
13110 if (ctrl == NULL) {
13111 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13112 "wpa_supplicant monitor connection");
13113 return -2;
13114 }
13115
13116 tries++;
13117 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
13118 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
13119 "Interworking connection");
13120 wpa_ctrl_detach(ctrl);
13121 wpa_ctrl_close(ctrl);
13122 return 0;
13123 }
13124
13125 buf[0] = '\0';
13126 while (1) {
13127 char *pos;
13128 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13129 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
13130 if (!pos)
13131 break;
13132 pos += 25;
13133 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
13134 pos);
13135 if (!blacklisted[0])
13136 memcpy(blacklisted, pos, strlen(pos) + 1);
13137 }
13138
13139 if (ignore_blacklist && blacklisted[0]) {
13140 char *end;
13141 end = strchr(blacklisted, ' ');
13142 if (end)
13143 *end = '\0';
13144 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
13145 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030013146 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
13147 blacklisted);
13148 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013149 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
13150 wpa_ctrl_detach(ctrl);
13151 wpa_ctrl_close(ctrl);
13152 return 0;
13153 }
13154 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13155 buf, sizeof(buf));
13156 }
13157
13158 wpa_ctrl_detach(ctrl);
13159 wpa_ctrl_close(ctrl);
13160
13161 if (res < 0) {
13162 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
13163 "connect");
13164 return 0;
13165 }
13166
13167 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
13168 strstr(buf, "INTERWORKING-BLACKLISTED")) {
13169 if (tries < 2) {
13170 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
13171 goto try_again;
13172 }
13173 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
13174 "matching credentials found");
13175 return 0;
13176 }
13177
13178 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13179 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13180 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
13181 "get current BSSID/SSID");
13182 return 0;
13183 }
13184
13185 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
13186 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13187 hs2_set_policy(dut);
13188 return 0;
13189}
13190
13191
Jouni Malinenf7222712019-06-13 01:50:21 +030013192static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
13193 struct sigma_conn *conn,
13194 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013195{
13196 const char *intf = get_param(cmd, "Interface");
13197 const char *display = get_param(cmd, "Display");
13198 struct wpa_ctrl *ctrl;
13199 char buf[300], params[400], *pos;
13200 char bssid[20];
13201 int info_avail = 0;
13202 unsigned int old_timeout;
13203 int res;
13204
13205 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
13206 send_resp(dut, conn, SIGMA_ERROR,
13207 "ErrorCode,Could not get current BSSID");
13208 return 0;
13209 }
13210 ctrl = open_wpa_mon(intf);
13211 if (!ctrl) {
13212 sigma_dut_print(dut, DUT_MSG_ERROR,
13213 "Failed to open wpa_supplicant monitor connection");
13214 return -2;
13215 }
13216
13217 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
13218 wpa_command(intf, buf);
13219
13220 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
13221 if (res < 0) {
13222 send_resp(dut, conn, SIGMA_ERROR,
13223 "ErrorCode,Could not complete GAS query");
13224 goto fail;
13225 }
13226
13227 old_timeout = dut->default_timeout;
13228 dut->default_timeout = 2;
13229 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
13230 dut->default_timeout = old_timeout;
13231 if (res < 0)
13232 goto done;
13233 pos = strchr(buf, ' ');
13234 if (!pos)
13235 goto done;
13236 pos++;
13237 pos = strchr(pos, ' ');
13238 if (!pos)
13239 goto done;
13240 pos++;
13241 info_avail = 1;
13242 snprintf(params, sizeof(params), "browser %s", pos);
13243
13244 if (display && strcasecmp(display, "Yes") == 0) {
13245 pid_t pid;
13246
13247 pid = fork();
13248 if (pid < 0) {
13249 perror("fork");
13250 return -1;
13251 }
13252
13253 if (pid == 0) {
13254 run_hs20_osu(dut, params);
13255 exit(0);
13256 }
13257 }
13258
13259done:
13260 snprintf(buf, sizeof(buf), "Info_available,%s",
13261 info_avail ? "Yes" : "No");
13262 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13263fail:
13264 wpa_ctrl_detach(ctrl);
13265 wpa_ctrl_close(ctrl);
13266 return 0;
13267}
13268
13269
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013270static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
13271 struct sigma_conn *conn,
13272 const char *ifname,
13273 struct sigma_cmd *cmd)
13274{
13275 const char *val;
13276 int id;
13277
13278 id = add_cred(ifname);
13279 if (id < 0)
13280 return -2;
13281 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13282
13283 val = get_param(cmd, "prefer");
13284 if (val && atoi(val) > 0)
13285 set_cred(ifname, id, "priority", "1");
13286
13287 val = get_param(cmd, "REALM");
13288 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13289 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13290 "realm");
13291 return 0;
13292 }
13293
13294 val = get_param(cmd, "HOME_FQDN");
13295 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13296 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13297 "home_fqdn");
13298 return 0;
13299 }
13300
13301 val = get_param(cmd, "Username");
13302 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13303 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13304 "username");
13305 return 0;
13306 }
13307
13308 val = get_param(cmd, "Password");
13309 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
13310 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13311 "password");
13312 return 0;
13313 }
13314
13315 val = get_param(cmd, "ROOT_CA");
13316 if (val) {
13317 char fname[200];
13318 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13319#ifdef __linux__
13320 if (!file_exists(fname)) {
13321 char msg[300];
13322 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13323 "file (%s) not found", fname);
13324 send_resp(dut, conn, SIGMA_ERROR, msg);
13325 return 0;
13326 }
13327#endif /* __linux__ */
13328 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13329 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13330 "not set root CA");
13331 return 0;
13332 }
13333 }
13334
13335 return 1;
13336}
13337
13338
13339static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
13340{
13341 FILE *in, *out;
13342 char buf[500];
13343 int found = 0;
13344
13345 in = fopen("devdetail.xml", "r");
13346 if (in == NULL)
13347 return -1;
13348 out = fopen("devdetail.xml.tmp", "w");
13349 if (out == NULL) {
13350 fclose(in);
13351 return -1;
13352 }
13353
13354 while (fgets(buf, sizeof(buf), in)) {
13355 char *pos = strstr(buf, "<IMSI>");
13356 if (pos) {
13357 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
13358 imsi);
13359 pos += 6;
13360 *pos = '\0';
13361 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
13362 found++;
13363 } else {
13364 fprintf(out, "%s", buf);
13365 }
13366 }
13367
13368 fclose(out);
13369 fclose(in);
13370 if (found)
13371 rename("devdetail.xml.tmp", "devdetail.xml");
13372 else
13373 unlink("devdetail.xml.tmp");
13374
13375 return 0;
13376}
13377
13378
13379static int sta_add_credential_sim(struct sigma_dut *dut,
13380 struct sigma_conn *conn,
13381 const char *ifname, struct sigma_cmd *cmd)
13382{
13383 const char *val, *imsi = NULL;
13384 int id;
13385 char buf[200];
13386 int res;
13387 const char *pos;
13388 size_t mnc_len;
13389 char plmn_mcc[4];
13390 char plmn_mnc[4];
13391
13392 id = add_cred(ifname);
13393 if (id < 0)
13394 return -2;
13395 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13396
13397 val = get_param(cmd, "prefer");
13398 if (val && atoi(val) > 0)
13399 set_cred(ifname, id, "priority", "1");
13400
13401 val = get_param(cmd, "PLMN_MCC");
13402 if (val == NULL) {
13403 send_resp(dut, conn, SIGMA_ERROR,
13404 "errorCode,Missing PLMN_MCC");
13405 return 0;
13406 }
13407 if (strlen(val) != 3) {
13408 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
13409 return 0;
13410 }
13411 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
13412
13413 val = get_param(cmd, "PLMN_MNC");
13414 if (val == NULL) {
13415 send_resp(dut, conn, SIGMA_ERROR,
13416 "errorCode,Missing PLMN_MNC");
13417 return 0;
13418 }
13419 if (strlen(val) != 2 && strlen(val) != 3) {
13420 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
13421 return 0;
13422 }
13423 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
13424
13425 val = get_param(cmd, "IMSI");
13426 if (val == NULL) {
13427 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
13428 "IMSI");
13429 return 0;
13430 }
13431
13432 imsi = pos = val;
13433
13434 if (strncmp(plmn_mcc, pos, 3) != 0) {
13435 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
13436 return 0;
13437 }
13438 pos += 3;
13439
13440 mnc_len = strlen(plmn_mnc);
13441 if (mnc_len < 2) {
13442 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
13443 return 0;
13444 }
13445
13446 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
13447 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
13448 return 0;
13449 }
13450 pos += mnc_len;
13451
13452 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
13453 if (res < 0 || res >= (int) sizeof(buf))
13454 return -1;
13455 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
13456 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13457 "not set IMSI");
13458 return 0;
13459 }
13460
13461 val = get_param(cmd, "Password");
13462 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
13463 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13464 "not set password");
13465 return 0;
13466 }
13467
Jouni Malinenba630452018-06-22 11:49:59 +030013468 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013469 /*
13470 * Set provisioning_sp for the test cases where SIM/USIM
13471 * provisioning is used.
13472 */
13473 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
13474 "wi-fi.org") < 0) {
13475 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13476 "not set provisioning_sp");
13477 return 0;
13478 }
13479
13480 update_devdetail_imsi(dut, imsi);
13481 }
13482
13483 return 1;
13484}
13485
13486
13487static int sta_add_credential_cert(struct sigma_dut *dut,
13488 struct sigma_conn *conn,
13489 const char *ifname,
13490 struct sigma_cmd *cmd)
13491{
13492 const char *val;
13493 int id;
13494
13495 id = add_cred(ifname);
13496 if (id < 0)
13497 return -2;
13498 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13499
13500 val = get_param(cmd, "prefer");
13501 if (val && atoi(val) > 0)
13502 set_cred(ifname, id, "priority", "1");
13503
13504 val = get_param(cmd, "REALM");
13505 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13506 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13507 "realm");
13508 return 0;
13509 }
13510
13511 val = get_param(cmd, "HOME_FQDN");
13512 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13513 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13514 "home_fqdn");
13515 return 0;
13516 }
13517
13518 val = get_param(cmd, "Username");
13519 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13520 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13521 "username");
13522 return 0;
13523 }
13524
13525 val = get_param(cmd, "clientCertificate");
13526 if (val) {
13527 char fname[200];
13528 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13529#ifdef __linux__
13530 if (!file_exists(fname)) {
13531 char msg[300];
13532 snprintf(msg, sizeof(msg),
13533 "ErrorCode,clientCertificate "
13534 "file (%s) not found", fname);
13535 send_resp(dut, conn, SIGMA_ERROR, msg);
13536 return 0;
13537 }
13538#endif /* __linux__ */
13539 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
13540 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13541 "not set client_cert");
13542 return 0;
13543 }
13544 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
13545 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13546 "not set private_key");
13547 return 0;
13548 }
13549 }
13550
13551 val = get_param(cmd, "ROOT_CA");
13552 if (val) {
13553 char fname[200];
13554 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13555#ifdef __linux__
13556 if (!file_exists(fname)) {
13557 char msg[300];
13558 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13559 "file (%s) not found", fname);
13560 send_resp(dut, conn, SIGMA_ERROR, msg);
13561 return 0;
13562 }
13563#endif /* __linux__ */
13564 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13565 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13566 "not set root CA");
13567 return 0;
13568 }
13569 }
13570
13571 return 1;
13572}
13573
13574
Jouni Malinenf7222712019-06-13 01:50:21 +030013575static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
13576 struct sigma_conn *conn,
13577 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013578{
13579 const char *intf = get_param(cmd, "Interface");
13580 const char *type;
13581
13582 start_sta_mode(dut);
13583
13584 type = get_param(cmd, "Type");
13585 if (!type)
13586 return -1;
13587
13588 if (strcasecmp(type, "uname_pwd") == 0)
13589 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
13590
13591 if (strcasecmp(type, "sim") == 0)
13592 return sta_add_credential_sim(dut, conn, intf, cmd);
13593
13594 if (strcasecmp(type, "cert") == 0)
13595 return sta_add_credential_cert(dut, conn, intf, cmd);
13596
13597 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
13598 "type");
13599 return 0;
13600}
13601
13602
Jouni Malinenf7222712019-06-13 01:50:21 +030013603static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
13604 struct sigma_conn *conn,
13605 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013606{
13607 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013608 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Arif Hussain66a4af02019-02-07 15:04:51 -080013609 char buf[4096];
vamsi krishna89ad8c62017-09-19 12:51:18 +053013610 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013611 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013612 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013613 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013614 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013615
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020013616 start_sta_mode(dut);
13617
Arif Hussain66a4af02019-02-07 15:04:51 -080013618 val = get_param(cmd, "GetParameter");
13619 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013620 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080013621 buf, sizeof(buf)) < 0) {
13622 sigma_dut_print(dut, DUT_MSG_ERROR,
13623 "Could not get ssid bssid");
13624 return ERROR_SEND_STATUS;
13625 }
13626
13627 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
13628 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13629 return STATUS_SENT;
13630 }
13631
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013632 val = get_param(cmd, "HESSID");
13633 if (val) {
13634 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
13635 if (res < 0 || res >= (int) sizeof(buf))
13636 return -1;
13637 wpa_command(intf, buf);
13638 }
13639
13640 val = get_param(cmd, "ACCS_NET_TYPE");
13641 if (val) {
13642 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
13643 val);
13644 if (res < 0 || res >= (int) sizeof(buf))
13645 return -1;
13646 wpa_command(intf, buf);
13647 }
13648
vamsi krishna89ad8c62017-09-19 12:51:18 +053013649 bssid = get_param(cmd, "Bssid");
13650 ssid = get_param(cmd, "Ssid");
13651
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013652 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
13653 dut->device_type == STA_testbed) {
13654 ssid = NULL;
13655 wildcard_ssid = 1;
13656 }
13657
vamsi krishna89ad8c62017-09-19 12:51:18 +053013658 if (ssid) {
13659 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
13660 send_resp(dut, conn, SIGMA_ERROR,
13661 "ErrorCode,Too long SSID");
13662 return 0;
13663 }
13664 ascii2hexstr(ssid, ssid_hex);
13665 }
13666
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013667 short_ssid = get_param(cmd, "ShortSSID");
13668 if (short_ssid) {
13669 uint32_t short_ssid_hex;
13670
13671 short_ssid_hex = strtoul(short_ssid, NULL, 16);
13672 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
13673 (((short_ssid_hex >> 8) & 0xFF) << 16) |
13674 (((short_ssid_hex >> 16) & 0xFF) << 8) |
13675 ((short_ssid_hex >> 24) & 0xFF);
13676
13677 res = snprintf(buf, sizeof(buf),
13678 "VENDOR_ELEM_ADD 14 ff053a%08x",
13679 short_ssid_hex);
13680 if (res < 0 || res >= (int) sizeof(buf) ||
13681 wpa_command(intf, buf)) {
13682 send_resp(dut, conn, SIGMA_ERROR,
13683 "errorCode,Failed to add short SSID");
13684 return STATUS_SENT_ERROR;
13685 }
13686 }
13687
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013688 scan_freq = get_param(cmd, "ChnlFreq");
13689
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013690 val = get_param(cmd, "WaitCompletion");
13691 if (val && atoi(val) == 1) {
13692 ctrl = open_wpa_mon(intf);
13693 if (!ctrl) {
13694 send_resp(dut, conn, SIGMA_ERROR,
13695 "errorCode,Failed to open monitor socket");
13696 return STATUS_SENT_ERROR;
13697 }
13698 }
13699
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013700 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053013701 bssid ? " bssid=": "",
13702 bssid ? bssid : "",
13703 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013704 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013705 wildcard_ssid ? " wildcard_ssid=1" : "",
13706 scan_freq ? " freq=" : "",
13707 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013708 if (res < 0 || res >= (int) sizeof(buf)) {
13709 send_resp(dut, conn, SIGMA_ERROR,
13710 "errorCode,Could not build scan command");
13711 status = STATUS_SENT_ERROR;
13712 goto remove_s_ssid;
13713 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053013714
13715 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013716 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
13717 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013718 status = STATUS_SENT_ERROR;
13719 } else {
13720 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013721 }
13722
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013723remove_s_ssid:
13724 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
13725 sigma_dut_print(dut, DUT_MSG_ERROR,
13726 "Failed to delete vendor element");
13727
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013728 if (ctrl) {
13729 if (status == SUCCESS_SEND_STATUS) {
13730 res = get_wpa_cli_event(dut, ctrl,
13731 "CTRL-EVENT-SCAN-RESULTS",
13732 buf, sizeof(buf));
13733 if (res < 0) {
13734 send_resp(dut, conn, SIGMA_ERROR,
13735 "ErrorCode,scan did not complete");
13736 status = STATUS_SENT_ERROR;
13737 }
13738 }
13739
13740 wpa_ctrl_detach(ctrl);
13741 wpa_ctrl_close(ctrl);
13742 }
13743
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013744 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013745}
13746
13747
Jouni Malinenf7222712019-06-13 01:50:21 +030013748static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
13749 struct sigma_conn *conn,
13750 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013751{
13752 const char *intf = get_param(cmd, "Interface");
13753 const char *bssid;
13754 char buf[4096], *pos;
13755 int freq, chan;
13756 char *ssid;
13757 char resp[100];
13758 int res;
13759 struct wpa_ctrl *ctrl;
13760
13761 bssid = get_param(cmd, "BSSID");
13762 if (!bssid) {
13763 send_resp(dut, conn, SIGMA_INVALID,
13764 "errorCode,BSSID argument is missing");
13765 return 0;
13766 }
13767
13768 ctrl = open_wpa_mon(intf);
13769 if (!ctrl) {
13770 sigma_dut_print(dut, DUT_MSG_ERROR,
13771 "Failed to open wpa_supplicant monitor connection");
13772 return -1;
13773 }
13774
13775 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
13776 send_resp(dut, conn, SIGMA_ERROR,
13777 "errorCode,Could not start scan");
13778 wpa_ctrl_detach(ctrl);
13779 wpa_ctrl_close(ctrl);
13780 return 0;
13781 }
13782
13783 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
13784 buf, sizeof(buf));
13785
13786 wpa_ctrl_detach(ctrl);
13787 wpa_ctrl_close(ctrl);
13788
13789 if (res < 0) {
13790 send_resp(dut, conn, SIGMA_ERROR,
13791 "errorCode,Scan did not complete");
13792 return 0;
13793 }
13794
13795 snprintf(buf, sizeof(buf), "BSS %s", bssid);
13796 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
13797 strncmp(buf, "id=", 3) != 0) {
13798 send_resp(dut, conn, SIGMA_ERROR,
13799 "errorCode,Specified BSSID not found");
13800 return 0;
13801 }
13802
13803 pos = strstr(buf, "\nfreq=");
13804 if (!pos) {
13805 send_resp(dut, conn, SIGMA_ERROR,
13806 "errorCode,Channel not found");
13807 return 0;
13808 }
13809 freq = atoi(pos + 6);
13810 chan = freq_to_channel(freq);
13811
13812 pos = strstr(buf, "\nssid=");
13813 if (!pos) {
13814 send_resp(dut, conn, SIGMA_ERROR,
13815 "errorCode,SSID not found");
13816 return 0;
13817 }
13818 ssid = pos + 6;
13819 pos = strchr(ssid, '\n');
13820 if (pos)
13821 *pos = '\0';
13822 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
13823 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13824 return 0;
13825}
13826
13827
Jouni Malinenf7222712019-06-13 01:50:21 +030013828static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
13829 struct sigma_conn *conn,
13830 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013831{
13832#ifdef __linux__
13833 struct timeval tv;
13834 struct tm tm;
13835 time_t t;
13836 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013837 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013838
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013839 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013840
13841 memset(&tm, 0, sizeof(tm));
13842 val = get_param(cmd, "seconds");
13843 if (val)
13844 tm.tm_sec = atoi(val);
13845 val = get_param(cmd, "minutes");
13846 if (val)
13847 tm.tm_min = atoi(val);
13848 val = get_param(cmd, "hours");
13849 if (val)
13850 tm.tm_hour = atoi(val);
13851 val = get_param(cmd, "date");
13852 if (val)
13853 tm.tm_mday = atoi(val);
13854 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013855 if (val) {
13856 v = atoi(val);
13857 if (v < 1 || v > 12) {
13858 send_resp(dut, conn, SIGMA_INVALID,
13859 "errorCode,Invalid month");
13860 return 0;
13861 }
13862 tm.tm_mon = v - 1;
13863 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013864 val = get_param(cmd, "year");
13865 if (val) {
13866 int year = atoi(val);
13867#ifdef ANDROID
13868 if (year > 2035)
13869 year = 2035; /* years beyond 2035 not supported */
13870#endif /* ANDROID */
13871 tm.tm_year = year - 1900;
13872 }
13873 t = mktime(&tm);
13874 if (t == (time_t) -1) {
13875 send_resp(dut, conn, SIGMA_ERROR,
13876 "errorCode,Invalid date or time");
13877 return 0;
13878 }
13879
13880 memset(&tv, 0, sizeof(tv));
13881 tv.tv_sec = t;
13882
13883 if (settimeofday(&tv, NULL) < 0) {
13884 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
13885 strerror(errno));
13886 send_resp(dut, conn, SIGMA_ERROR,
13887 "errorCode,Failed to set time");
13888 return 0;
13889 }
13890
13891 return 1;
13892#endif /* __linux__ */
13893
13894 return -1;
13895}
13896
13897
Jouni Malinenf7222712019-06-13 01:50:21 +030013898static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
13899 struct sigma_conn *conn,
13900 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013901{
13902 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013903 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013904 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013905 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013906 int res;
13907 struct wpa_ctrl *ctrl;
13908
13909 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013910 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013911
13912 val = get_param(cmd, "ProdESSAssoc");
13913 if (val)
13914 prod_ess_assoc = atoi(val);
13915
13916 kill_dhcp_client(dut, intf);
13917 if (start_dhcp_client(dut, intf) < 0)
13918 return -2;
13919
13920 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
13921 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13922 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013923 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013924 prod_ess_assoc ? "" : "-N",
13925 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013926 name ? "'" : "",
13927 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
13928 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013929
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053013930 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013931 if (run_hs20_osu(dut, buf) < 0) {
13932 FILE *f;
13933
13934 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
13935
13936 f = fopen("hs20-osu-client.res", "r");
13937 if (f) {
13938 char resp[400], res[300], *pos;
13939 if (!fgets(res, sizeof(res), f))
13940 res[0] = '\0';
13941 pos = strchr(res, '\n');
13942 if (pos)
13943 *pos = '\0';
13944 fclose(f);
13945 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
13946 res);
13947 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
13948 if (system(resp) != 0) {
13949 }
13950 snprintf(resp, sizeof(resp),
13951 "SSID,,BSSID,,failureReason,%s", res);
13952 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13953 return 0;
13954 }
13955
13956 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13957 return 0;
13958 }
13959
13960 if (!prod_ess_assoc)
13961 goto report;
13962
13963 ctrl = open_wpa_mon(intf);
13964 if (ctrl == NULL) {
13965 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13966 "wpa_supplicant monitor connection");
13967 return -1;
13968 }
13969
13970 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13971 buf, sizeof(buf));
13972
13973 wpa_ctrl_detach(ctrl);
13974 wpa_ctrl_close(ctrl);
13975
13976 if (res < 0) {
13977 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
13978 "network after OSU");
13979 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13980 return 0;
13981 }
13982
13983report:
13984 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13985 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13986 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
13987 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13988 return 0;
13989 }
13990
13991 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
13992 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013993 return 0;
13994}
13995
13996
Jouni Malinenf7222712019-06-13 01:50:21 +030013997static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
13998 struct sigma_conn *conn,
13999 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014000{
14001 const char *val;
14002 int timeout = 120;
14003
14004 val = get_param(cmd, "PolicyUpdate");
14005 if (val == NULL || atoi(val) == 0)
14006 return 1; /* No operation requested */
14007
14008 val = get_param(cmd, "Timeout");
14009 if (val)
14010 timeout = atoi(val);
14011
14012 if (timeout) {
14013 /* TODO: time out the command and return
14014 * PolicyUpdateStatus,TIMEOUT if needed. */
14015 }
14016
14017 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
14018 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
14019 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
14020 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
14021 return 0;
14022 }
14023
14024 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
14025 return 0;
14026}
14027
14028
Jouni Malinenf7222712019-06-13 01:50:21 +030014029static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
14030 struct sigma_conn *conn,
14031 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014032{
14033 struct wpa_ctrl *ctrl;
14034 const char *intf = get_param(cmd, "Interface");
14035 const char *bssid = get_param(cmd, "Bssid");
14036 const char *ssid = get_param(cmd, "SSID");
14037 const char *security = get_param(cmd, "Security");
14038 const char *passphrase = get_param(cmd, "Passphrase");
14039 const char *pin = get_param(cmd, "PIN");
14040 char buf[1000];
14041 char ssid_hex[200], passphrase_hex[200];
14042 const char *keymgmt, *cipher;
14043
14044 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014045 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014046
14047 if (!bssid) {
14048 send_resp(dut, conn, SIGMA_ERROR,
14049 "ErrorCode,Missing Bssid argument");
14050 return 0;
14051 }
14052
14053 if (!ssid) {
14054 send_resp(dut, conn, SIGMA_ERROR,
14055 "ErrorCode,Missing SSID argument");
14056 return 0;
14057 }
14058
14059 if (!security) {
14060 send_resp(dut, conn, SIGMA_ERROR,
14061 "ErrorCode,Missing Security argument");
14062 return 0;
14063 }
14064
14065 if (!passphrase) {
14066 send_resp(dut, conn, SIGMA_ERROR,
14067 "ErrorCode,Missing Passphrase argument");
14068 return 0;
14069 }
14070
14071 if (!pin) {
14072 send_resp(dut, conn, SIGMA_ERROR,
14073 "ErrorCode,Missing PIN argument");
14074 return 0;
14075 }
14076
vamsi krishna8c9c1562017-05-12 15:51:46 +053014077 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
14078 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014079 send_resp(dut, conn, SIGMA_ERROR,
14080 "ErrorCode,Too long SSID/passphrase");
14081 return 0;
14082 }
14083
14084 ctrl = open_wpa_mon(intf);
14085 if (ctrl == NULL) {
14086 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14087 "wpa_supplicant monitor connection");
14088 return -2;
14089 }
14090
14091 if (strcasecmp(security, "wpa2-psk") == 0) {
14092 keymgmt = "WPA2PSK";
14093 cipher = "CCMP";
14094 } else {
14095 wpa_ctrl_detach(ctrl);
14096 wpa_ctrl_close(ctrl);
14097 send_resp(dut, conn, SIGMA_ERROR,
14098 "ErrorCode,Unsupported Security value");
14099 return 0;
14100 }
14101
14102 ascii2hexstr(ssid, ssid_hex);
14103 ascii2hexstr(passphrase, passphrase_hex);
14104 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
14105 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
14106
14107 if (wpa_command(intf, buf) < 0) {
14108 wpa_ctrl_detach(ctrl);
14109 wpa_ctrl_close(ctrl);
14110 send_resp(dut, conn, SIGMA_ERROR,
14111 "ErrorCode,Failed to start registrar");
14112 return 0;
14113 }
14114
14115 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
14116 dut->er_oper_performed = 1;
14117
14118 return wps_connection_event(dut, conn, ctrl, intf, 0);
14119}
14120
14121
Jouni Malinenf7222712019-06-13 01:50:21 +030014122static enum sigma_cmd_result
14123cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
14124 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014125{
14126 struct wpa_ctrl *ctrl;
14127 const char *intf = get_param(cmd, "Interface");
14128 const char *bssid = get_param(cmd, "Bssid");
14129 char buf[100];
14130
14131 if (!bssid) {
14132 send_resp(dut, conn, SIGMA_ERROR,
14133 "ErrorCode,Missing Bssid argument");
14134 return 0;
14135 }
14136
14137 ctrl = open_wpa_mon(intf);
14138 if (ctrl == NULL) {
14139 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14140 "wpa_supplicant monitor connection");
14141 return -2;
14142 }
14143
14144 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
14145
14146 if (wpa_command(intf, buf) < 0) {
14147 wpa_ctrl_detach(ctrl);
14148 wpa_ctrl_close(ctrl);
14149 send_resp(dut, conn, SIGMA_ERROR,
14150 "ErrorCode,Failed to start registrar");
14151 return 0;
14152 }
14153
14154 return wps_connection_event(dut, conn, ctrl, intf, 0);
14155}
14156
14157
Jouni Malinenf7222712019-06-13 01:50:21 +030014158static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
14159 struct sigma_conn *conn,
14160 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053014161{
14162 struct wpa_ctrl *ctrl;
14163 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014164 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014165 const char *config_method = get_param(cmd, "WPSConfigMethod");
14166 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053014167 int res;
14168 char buf[256];
14169 const char *events[] = {
14170 "CTRL-EVENT-CONNECTED",
14171 "WPS-OVERLAP-DETECTED",
14172 "WPS-TIMEOUT",
14173 "WPS-FAIL",
14174 NULL
14175 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014176 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053014177
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014178 /* 60G WPS tests do not pass Interface parameter */
14179 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014180 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014181
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014182 if (dut->mode == SIGMA_MODE_AP)
14183 return ap_wps_registration(dut, conn, cmd);
14184
14185 if (config_method) {
14186 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
14187 * sta_wps_enter_pin before calling start_wps_registration. */
14188 if (strcasecmp(config_method, "PBC") == 0)
14189 dut->wps_method = WFA_CS_WPS_PBC;
14190 }
14191 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
14192 send_resp(dut, conn, SIGMA_ERROR,
14193 "ErrorCode,WPS parameters not yet set");
14194 return STATUS_SENT;
14195 }
14196
14197 /* Make sure WPS is enabled (also for STA mode) */
14198 dut->wps_disable = 0;
14199
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014200 if (dut->band == WPS_BAND_60G && network_mode &&
14201 strcasecmp(network_mode, "PBSS") == 0) {
14202 sigma_dut_print(dut, DUT_MSG_DEBUG,
14203 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014204 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014205 return -2;
14206 }
14207
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020014208 if (dut->force_rsn_ie) {
14209 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
14210 dut->force_rsn_ie);
14211 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
14212 sigma_dut_print(dut, DUT_MSG_INFO,
14213 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014214 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020014215 }
14216 }
14217
vamsi krishna9b144002017-09-20 13:28:13 +053014218 ctrl = open_wpa_mon(intf);
14219 if (!ctrl) {
14220 sigma_dut_print(dut, DUT_MSG_ERROR,
14221 "Failed to open wpa_supplicant monitor connection");
14222 return -2;
14223 }
14224
14225 role = get_param(cmd, "WpsRole");
14226 if (!role) {
14227 send_resp(dut, conn, SIGMA_INVALID,
14228 "ErrorCode,WpsRole not provided");
14229 goto fail;
14230 }
14231
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014232 if (strcasecmp(role, "Enrollee") != 0) {
14233 /* Registrar role for STA not supported */
14234 send_resp(dut, conn, SIGMA_ERROR,
14235 "ErrorCode,Unsupported WpsRole value");
14236 goto fail;
14237 }
14238
14239 if (is_60g_sigma_dut(dut)) {
14240 if (dut->wps_method == WFA_CS_WPS_PBC)
14241 snprintf(buf, sizeof(buf), "WPS_PBC");
14242 else /* WFA_CS_WPS_PIN_KEYPAD */
14243 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
14244 dut->wps_pin);
14245 if (wpa_command(intf, buf) < 0) {
14246 send_resp(dut, conn, SIGMA_ERROR,
14247 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053014248 goto fail;
14249 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014250 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
14251 if (res < 0) {
14252 send_resp(dut, conn, SIGMA_ERROR,
14253 "ErrorCode,WPS connection did not complete");
14254 goto fail;
14255 }
14256 if (strstr(buf, "WPS-TIMEOUT")) {
14257 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
14258 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
14259 send_resp(dut, conn, SIGMA_COMPLETE,
14260 "WpsState,OverlapSession");
14261 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
14262 send_resp(dut, conn, SIGMA_COMPLETE,
14263 "WpsState,Successful");
14264 } else {
14265 send_resp(dut, conn, SIGMA_COMPLETE,
14266 "WpsState,Failure");
14267 }
14268 } else {
14269 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053014270 if (wpa_command(intf, "WPS_PBC") < 0) {
14271 send_resp(dut, conn, SIGMA_ERROR,
14272 "ErrorCode,Failed to enable PBC");
14273 goto fail;
14274 }
14275 } else {
14276 /* TODO: PIN method */
14277 send_resp(dut, conn, SIGMA_ERROR,
14278 "ErrorCode,Unsupported WpsConfigMethod value");
14279 goto fail;
14280 }
14281 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
14282 if (res < 0) {
14283 send_resp(dut, conn, SIGMA_ERROR,
14284 "ErrorCode,WPS connection did not complete");
14285 goto fail;
14286 }
14287 if (strstr(buf, "WPS-TIMEOUT")) {
14288 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
14289 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
14290 send_resp(dut, conn, SIGMA_ERROR,
14291 "ErrorCode,OverlapSession");
14292 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
14293 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
14294 } else {
14295 send_resp(dut, conn, SIGMA_ERROR,
14296 "ErrorCode,WPS operation failed");
14297 }
vamsi krishna9b144002017-09-20 13:28:13 +053014298 }
14299
14300fail:
14301 wpa_ctrl_detach(ctrl);
14302 wpa_ctrl_close(ctrl);
14303 return 0;
14304}
14305
14306
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014307static int req_intf(struct sigma_cmd *cmd)
14308{
14309 return get_param(cmd, "interface") == NULL ? -1 : 0;
14310}
14311
14312
14313void sta_register_cmds(void)
14314{
14315 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
14316 cmd_sta_get_ip_config);
14317 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
14318 cmd_sta_set_ip_config);
14319 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
14320 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
14321 cmd_sta_get_mac_address);
14322 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
14323 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
14324 cmd_sta_verify_ip_connection);
14325 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
14326 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
14327 cmd_sta_set_encryption);
14328 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
14329 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
14330 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
14331 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
14332 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
14333 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
14334 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
14335 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
14336 cmd_sta_set_eapakaprime);
14337 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
14338 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
14339 /* TODO: sta_set_ibss */
14340 /* TODO: sta_set_mode */
14341 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
14342 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
14343 /* TODO: sta_up_load */
14344 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
14345 cmd_sta_preset_testparameters);
14346 /* TODO: sta_set_system */
14347 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
14348 /* TODO: sta_set_rifs_test */
14349 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
14350 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
14351 /* TODO: sta_send_coexist_mgmt */
14352 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
14353 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
14354 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
14355 sigma_dut_reg_cmd("sta_reset_default", req_intf,
14356 cmd_sta_reset_default);
14357 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
14358 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
14359 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
14360 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
14361 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014362 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014363 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
14364 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
14365 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
14366 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
14367 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030014368 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
14369 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014370 sigma_dut_reg_cmd("sta_add_credential", req_intf,
14371 cmd_sta_add_credential);
14372 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020014373 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014374 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
14375 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
14376 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
14377 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
14378 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
14379 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030014380 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014381 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
14382 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014383 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053014384 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014385}