blob: 6a8b1d5b522ef050d3109fb0e5a8a80fe10db1d9 [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 Malinen8e3f8812020-10-05 10:02:03 +03002971static enum sigma_cmd_result sta_set_owe(struct sigma_dut *dut,
2972 struct sigma_conn *conn,
2973 struct sigma_cmd *cmd)
Jouni Malinen47dcc952017-10-09 16:43:24 +03002974{
2975 const char *intf = get_param(cmd, "Interface");
2976 const char *ifname, *val;
2977 int id;
2978
2979 if (intf == NULL)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03002980 return INVALID_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03002981
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002982 if (strcmp(intf, get_main_ifname(dut)) == 0)
2983 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002984 else
2985 ifname = intf;
2986
2987 id = set_wpa_common(dut, conn, ifname, cmd);
2988 if (id < 0)
2989 return id;
2990
2991 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03002992 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03002993
Hu Wangdd5eed22020-07-16 12:18:03 +08002994 if (dut->owe_ptk_workaround &&
2995 set_network(ifname, id, "owe_ptk_workaround", "1") < 0) {
2996 sigma_dut_print(dut, DUT_MSG_ERROR,
2997 "Failed to set owe_ptk_workaround to 1");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03002998 return ERROR_SEND_STATUS;
Hu Wangdd5eed22020-07-16 12:18:03 +08002999 }
3000
Jouni Malinen47dcc952017-10-09 16:43:24 +03003001 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003002 if (val && strcmp(val, "0") == 0) {
3003 if (wpa_command(ifname,
3004 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
3005 sigma_dut_print(dut, DUT_MSG_ERROR,
3006 "Failed to set OWE DH Param element override");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003007 return ERROR_SEND_STATUS;
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003008 }
Hu Wangdd5eed22020-07-16 12:18:03 +08003009 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003010 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003011 "Failed to set owe_group");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003012 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003013 }
3014
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003015 return SUCCESS_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003016}
3017
3018
Jouni Malinenf7222712019-06-13 01:50:21 +03003019static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3020 struct sigma_conn *conn,
3021 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003022{
3023 const char *type = get_param(cmd, "Type");
3024
3025 if (type == NULL) {
3026 send_resp(dut, conn, SIGMA_ERROR,
3027 "ErrorCode,Missing Type argument");
3028 return 0;
3029 }
3030
3031 if (strcasecmp(type, "OPEN") == 0)
3032 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003033 if (strcasecmp(type, "OWE") == 0)
3034 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003035 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003036 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003037 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003038 return cmd_sta_set_psk(dut, conn, cmd);
3039 if (strcasecmp(type, "EAPTLS") == 0)
3040 return cmd_sta_set_eaptls(dut, conn, cmd);
3041 if (strcasecmp(type, "EAPTTLS") == 0)
3042 return cmd_sta_set_eapttls(dut, conn, cmd);
3043 if (strcasecmp(type, "EAPPEAP") == 0)
3044 return cmd_sta_set_peap(dut, conn, cmd);
3045 if (strcasecmp(type, "EAPSIM") == 0)
3046 return cmd_sta_set_eapsim(dut, conn, cmd);
3047 if (strcasecmp(type, "EAPFAST") == 0)
3048 return cmd_sta_set_eapfast(dut, conn, cmd);
3049 if (strcasecmp(type, "EAPAKA") == 0)
3050 return cmd_sta_set_eapaka(dut, conn, cmd);
3051 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3052 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003053 if (strcasecmp(type, "wep") == 0)
3054 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003055
3056 send_resp(dut, conn, SIGMA_ERROR,
3057 "ErrorCode,Unsupported Type value");
3058 return 0;
3059}
3060
3061
3062int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3063{
3064#ifdef __linux__
3065 /* special handling for ath6kl */
3066 char path[128], fname[128], *pos;
3067 ssize_t res;
3068 FILE *f;
3069
Jouni Malinene39cd562019-05-29 23:39:56 +03003070 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3071 intf);
3072 if (res < 0 || res >= sizeof(fname))
3073 return 0;
3074 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003075 if (res < 0)
3076 return 0; /* not ath6kl */
3077
3078 if (res >= (int) sizeof(path))
3079 res = sizeof(path) - 1;
3080 path[res] = '\0';
3081 pos = strrchr(path, '/');
3082 if (pos == NULL)
3083 pos = path;
3084 else
3085 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003086 res = snprintf(fname, sizeof(fname),
3087 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3088 "create_qos", pos);
3089 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003090 return 0; /* not ath6kl */
3091
3092 if (uapsd) {
3093 f = fopen(fname, "w");
3094 if (f == NULL)
3095 return -1;
3096
3097 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3098 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3099 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3100 "20000 0\n");
3101 fclose(f);
3102 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003103 res = snprintf(fname, sizeof(fname),
3104 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3105 "delete_qos", pos);
3106 if (res < 0 || res >= sizeof(fname))
3107 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003108
3109 f = fopen(fname, "w");
3110 if (f == NULL)
3111 return -1;
3112
3113 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3114 fprintf(f, "2 4\n");
3115 fclose(f);
3116 }
3117#endif /* __linux__ */
3118
3119 return 0;
3120}
3121
3122
Jouni Malinenf7222712019-06-13 01:50:21 +03003123static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3124 struct sigma_conn *conn,
3125 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003126{
3127 const char *intf = get_param(cmd, "Interface");
3128 /* const char *ssid = get_param(cmd, "ssid"); */
3129 const char *val;
3130 int max_sp_len = 4;
3131 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3132 char buf[100];
3133 int ret1, ret2;
3134
3135 val = get_param(cmd, "maxSPLength");
3136 if (val) {
3137 max_sp_len = atoi(val);
3138 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3139 max_sp_len != 4)
3140 return -1;
3141 }
3142
3143 val = get_param(cmd, "acBE");
3144 if (val)
3145 ac_be = atoi(val);
3146
3147 val = get_param(cmd, "acBK");
3148 if (val)
3149 ac_bk = atoi(val);
3150
3151 val = get_param(cmd, "acVI");
3152 if (val)
3153 ac_vi = atoi(val);
3154
3155 val = get_param(cmd, "acVO");
3156 if (val)
3157 ac_vo = atoi(val);
3158
3159 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3160
3161 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3162 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3163 ret1 = wpa_command(intf, buf);
3164
3165 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3166 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3167 ret2 = wpa_command(intf, buf);
3168
3169 if (ret1 && ret2) {
3170 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3171 "UAPSD parameters.");
3172 return -2;
3173 }
3174
3175 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3176 send_resp(dut, conn, SIGMA_ERROR,
3177 "ErrorCode,Failed to set ath6kl QoS parameters");
3178 return 0;
3179 }
3180
3181 return 1;
3182}
3183
3184
Jouni Malinenf7222712019-06-13 01:50:21 +03003185static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3186 struct sigma_conn *conn,
3187 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003188{
3189 char buf[1000];
3190 const char *intf = get_param(cmd, "Interface");
3191 const char *grp = get_param(cmd, "Group");
3192 const char *act = get_param(cmd, "Action");
3193 const char *tid = get_param(cmd, "Tid");
3194 const char *dir = get_param(cmd, "Direction");
3195 const char *psb = get_param(cmd, "Psb");
3196 const char *up = get_param(cmd, "Up");
3197 const char *fixed = get_param(cmd, "Fixed");
3198 const char *size = get_param(cmd, "Size");
3199 const char *msize = get_param(cmd, "Maxsize");
3200 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3201 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3202 const char *inact = get_param(cmd, "Inactivity");
3203 const char *sus = get_param(cmd, "Suspension");
3204 const char *mindr = get_param(cmd, "Mindatarate");
3205 const char *meandr = get_param(cmd, "Meandatarate");
3206 const char *peakdr = get_param(cmd, "Peakdatarate");
3207 const char *phyrate = get_param(cmd, "Phyrate");
3208 const char *burstsize = get_param(cmd, "Burstsize");
3209 const char *sba = get_param(cmd, "Sba");
3210 int direction;
3211 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003212 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003213 int fixed_int;
3214 int psb_ts;
3215
3216 if (intf == NULL || grp == NULL || act == NULL )
3217 return -1;
3218
3219 if (strcasecmp(act, "addts") == 0) {
3220 if (tid == NULL || dir == NULL || psb == NULL ||
3221 up == NULL || fixed == NULL || size == NULL)
3222 return -1;
3223
3224 /*
3225 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3226 * possible values, but WMM-AC and V-E test scripts use "UP,
3227 * "DOWN", and "BIDI".
3228 */
3229 if (strcasecmp(dir, "uplink") == 0 ||
3230 strcasecmp(dir, "up") == 0) {
3231 direction = 0;
3232 } else if (strcasecmp(dir, "downlink") == 0 ||
3233 strcasecmp(dir, "down") == 0) {
3234 direction = 1;
3235 } else if (strcasecmp(dir, "bidi") == 0) {
3236 direction = 2;
3237 } else {
3238 sigma_dut_print(dut, DUT_MSG_ERROR,
3239 "Direction %s not supported", dir);
3240 return -1;
3241 }
3242
3243 if (strcasecmp(psb, "legacy") == 0) {
3244 psb_ts = 0;
3245 } else if (strcasecmp(psb, "uapsd") == 0) {
3246 psb_ts = 1;
3247 } else {
3248 sigma_dut_print(dut, DUT_MSG_ERROR,
3249 "PSB %s not supported", psb);
3250 return -1;
3251 }
3252
3253 if (atoi(tid) < 0 || atoi(tid) > 7) {
3254 sigma_dut_print(dut, DUT_MSG_ERROR,
3255 "TID %s not supported", tid);
3256 return -1;
3257 }
3258
3259 if (strcasecmp(fixed, "true") == 0) {
3260 fixed_int = 1;
3261 } else {
3262 fixed_int = 0;
3263 }
3264
Peng Xu93319622017-10-04 17:58:16 -07003265 if (sba)
3266 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003267
3268 dut->dialog_token++;
3269 handle = 7000 + dut->dialog_token;
3270
3271 /*
3272 * size: convert to hex
3273 * maxsi: convert to hex
3274 * mindr: convert to hex
3275 * meandr: convert to hex
3276 * peakdr: convert to hex
3277 * burstsize: convert to hex
3278 * phyrate: convert to hex
3279 * sba: convert to hex with modification
3280 * minsi: convert to integer
3281 * sus: convert to integer
3282 * inact: convert to integer
3283 * maxsi: convert to integer
3284 */
3285
3286 /*
3287 * The Nominal MSDU Size field is 2 octets long and contains an
3288 * unsigned integer that specifies the nominal size, in octets,
3289 * of MSDUs belonging to the traffic under this traffic
3290 * specification and is defined in Figure 16. If the Fixed
3291 * subfield is set to 1, then the size of the MSDU is fixed and
3292 * is indicated by the Size Subfield. If the Fixed subfield is
3293 * set to 0, then the size of the MSDU might not be fixed and
3294 * the Size indicates the nominal MSDU size.
3295 *
3296 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3297 * and specifies the excess allocation of time (and bandwidth)
3298 * over and above the stated rates required to transport an MSDU
3299 * belonging to the traffic in this TSPEC. This field is
3300 * represented as an unsigned binary number with an implicit
3301 * binary point after the leftmost 3 bits. For example, an SBA
3302 * of 1.75 is represented as 0x3800. This field is included to
3303 * account for retransmissions. As such, the value of this field
3304 * must be greater than unity.
3305 */
3306
3307 snprintf(buf, sizeof(buf),
3308 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3309 " 0x%X 0x%X 0x%X"
3310 " 0x%X 0x%X 0x%X"
3311 " 0x%X %d %d %d %d"
3312 " %d %d",
3313 intf, handle, tid, direction, psb_ts, up,
3314 (unsigned int) ((fixed_int << 15) | atoi(size)),
3315 msize ? atoi(msize) : 0,
3316 mindr ? atoi(mindr) : 0,
3317 meandr ? atoi(meandr) : 0,
3318 peakdr ? atoi(peakdr) : 0,
3319 burstsize ? atoi(burstsize) : 0,
3320 phyrate ? atoi(phyrate) : 0,
3321 sba ? ((unsigned int) (((int) sba_fv << 13) |
3322 (int)((sba_fv - (int) sba_fv) *
3323 8192))) : 0,
3324 minsi ? atoi(minsi) : 0,
3325 sus ? atoi(sus) : 0,
3326 0, 0,
3327 inact ? atoi(inact) : 0,
3328 maxsi ? atoi(maxsi) : 0);
3329
3330 if (system(buf) != 0) {
3331 sigma_dut_print(dut, DUT_MSG_ERROR,
3332 "iwpriv addtspec request failed");
3333 send_resp(dut, conn, SIGMA_ERROR,
3334 "errorCode,Failed to execute addTspec command");
3335 return 0;
3336 }
3337
3338 sigma_dut_print(dut, DUT_MSG_INFO,
3339 "iwpriv addtspec request send");
3340
3341 /* Mapping handle to a TID */
3342 dut->tid_to_handle[atoi(tid)] = handle;
3343 } else if (strcasecmp(act, "delts") == 0) {
3344 if (tid == NULL)
3345 return -1;
3346
3347 if (atoi(tid) < 0 || atoi(tid) > 7) {
3348 sigma_dut_print(dut, DUT_MSG_ERROR,
3349 "TID %s not supported", tid);
3350 send_resp(dut, conn, SIGMA_ERROR,
3351 "errorCode,Unsupported TID");
3352 return 0;
3353 }
3354
3355 handle = dut->tid_to_handle[atoi(tid)];
3356
3357 if (handle < 7000 || handle > 7255) {
3358 /* Invalid handle ie no mapping for that TID */
3359 sigma_dut_print(dut, DUT_MSG_ERROR,
3360 "handle-> %d not found", handle);
3361 }
3362
3363 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3364 intf, handle);
3365
3366 if (system(buf) != 0) {
3367 sigma_dut_print(dut, DUT_MSG_ERROR,
3368 "iwpriv deltspec request failed");
3369 send_resp(dut, conn, SIGMA_ERROR,
3370 "errorCode,Failed to execute delTspec command");
3371 return 0;
3372 }
3373
3374 sigma_dut_print(dut, DUT_MSG_INFO,
3375 "iwpriv deltspec request send");
3376
3377 dut->tid_to_handle[atoi(tid)] = 0;
3378 } else {
3379 sigma_dut_print(dut, DUT_MSG_ERROR,
3380 "Action type %s not supported", act);
3381 send_resp(dut, conn, SIGMA_ERROR,
3382 "errorCode,Unsupported Action");
3383 return 0;
3384 }
3385
3386 return 1;
3387}
3388
3389
vamsi krishna52e16f92017-08-29 12:37:34 +05303390static int find_network(struct sigma_dut *dut, const char *ssid)
3391{
3392 char list[4096];
3393 char *pos;
3394
3395 sigma_dut_print(dut, DUT_MSG_DEBUG,
3396 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003397 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303398 list, sizeof(list)) < 0)
3399 return -1;
3400 pos = strstr(list, ssid);
3401 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3402 return -1;
3403
3404 while (pos > list && pos[-1] != '\n')
3405 pos--;
3406 dut->infra_network_id = atoi(pos);
3407 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3408 return 0;
3409}
3410
3411
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303412/**
3413 * enum qca_sta_helper_config_params - This helper enum defines the config
3414 * parameters which can be delivered to sta.
3415 */
3416enum qca_sta_helper_config_params {
3417 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE */
3418 STA_SET_RSNIE,
3419
3420 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC */
3421 STA_SET_LDPC,
3422
3423 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC */
3424 STA_SET_TX_STBC,
3425
3426 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC */
3427 STA_SET_RX_STBC,
3428
3429 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION */
3430 STA_SET_TX_MSDU,
3431
3432 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION */
3433 STA_SET_RX_MSDU,
3434};
3435
3436
3437static int sta_config_params(struct sigma_dut *dut, const char *intf,
3438 enum qca_sta_helper_config_params config_cmd,
3439 int value)
Sunil Dutt44595082018-02-12 19:41:45 +05303440{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303441#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05303442 struct nl_msg *msg;
3443 int ret;
3444 struct nlattr *params;
3445 int ifindex;
3446
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303447 ifindex = if_nametoindex(intf);
3448 if (ifindex == 0) {
3449 sigma_dut_print(dut, DUT_MSG_ERROR,
3450 "%s: Interface %s does not exist",
3451 __func__, intf);
3452 return -1;
3453 }
3454
Sunil Dutt44595082018-02-12 19:41:45 +05303455 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3456 NL80211_CMD_VENDOR)) ||
3457 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3458 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3459 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3460 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303461 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)))
3462 goto fail;
3463
3464 switch (config_cmd) {
3465 case STA_SET_RSNIE:
3466 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, value))
3467 goto fail;
3468 break;
3469 case STA_SET_LDPC:
3470 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC, value))
3471 goto fail;
3472 break;
3473 case STA_SET_TX_STBC:
3474 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC, value))
3475 goto fail;
3476 break;
3477 case STA_SET_RX_STBC:
3478 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC, value))
3479 goto fail;
3480 break;
3481 case STA_SET_TX_MSDU:
3482 if (nla_put_u8(msg,
3483 QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION,
3484 value))
3485 goto fail;
3486 break;
3487 case STA_SET_RX_MSDU:
3488 if (nla_put_u8(msg,
3489 QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION,
3490 value))
3491 goto fail;
3492 break;
Sunil Dutt44595082018-02-12 19:41:45 +05303493 }
3494 nla_nest_end(msg, params);
3495
3496 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3497 if (ret) {
3498 sigma_dut_print(dut, DUT_MSG_ERROR,
3499 "%s: err in send_and_recv_msgs, ret=%d",
3500 __func__, ret);
3501 return ret;
3502 }
3503
3504 return 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303505
3506fail:
3507 sigma_dut_print(dut, DUT_MSG_ERROR,
3508 "%s: err in adding vendor_cmd and vendor_data",
3509 __func__);
3510 nlmsg_free(msg);
Sunil Dutt44595082018-02-12 19:41:45 +05303511#endif /* NL80211_SUPPORT */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303512 return -1;
3513}
Sunil Dutt44595082018-02-12 19:41:45 +05303514
3515
Jouni Malinenf7222712019-06-13 01:50:21 +03003516static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3517 struct sigma_conn *conn,
3518 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003519{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303520#ifdef NL80211_SUPPORT
3521 const char *intf = get_param(cmd, "Interface");
3522#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003523 const char *ssid = get_param(cmd, "ssid");
3524 const char *wps_param = get_param(cmd, "WPS");
3525 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003526 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003527 const char *network_mode = get_param(cmd, "network_mode");
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303528 const char *ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003529 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003530 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003531 int e;
3532 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3533 struct wpa_ctrl *ctrl = NULL;
3534 int num_network_not_found = 0;
3535 int num_disconnected = 0;
3536 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003537
3538 if (ssid == NULL)
3539 return -1;
3540
Jouni Malinen37d5c692019-08-19 16:56:55 +03003541 dut->server_cert_tod = 0;
3542
Jouni Malinen3c367e82017-06-23 17:01:47 +03003543 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303544#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003545 if (get_driver_type(dut) == DRIVER_WCN) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303546 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Sunil Dutt44595082018-02-12 19:41:45 +05303547 dut->config_rsnie = 1;
3548 }
3549#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003550 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3551 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003552 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03003553 send_resp(dut, conn, SIGMA_ERROR,
3554 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3555 return 0;
3556 }
3557 }
3558
Jouni Malinen68143132017-09-02 02:34:08 +03003559 if (dut->sae_commit_override) {
3560 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3561 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003562 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03003563 send_resp(dut, conn, SIGMA_ERROR,
3564 "ErrorCode,Failed to set SAE commit override");
3565 return 0;
3566 }
3567 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303568#ifdef ANDROID
3569 if (dut->fils_hlp)
3570 process_fils_hlp(dut);
3571#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003572
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003573 if (wps_param &&
3574 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3575 wps = 1;
3576
Vamsi Krishnac1633d22020-05-06 18:31:21 +05303577 if (dut->ocvc &&
3578 set_network(get_station_ifname(dut), dut->infra_network_id,
3579 "ocv", "1") < 0)
3580 return ERROR_SEND_STATUS;
3581
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003582 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003583 if (dut->program == PROGRAM_60GHZ && network_mode &&
3584 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003585 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003586 "pbss", "1") < 0)
3587 return -2;
3588
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003589 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3590 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3591 "parameters not yet set");
3592 return 0;
3593 }
3594 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003595 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003596 return -2;
3597 } else {
3598 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3599 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003600 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003601 return -2;
3602 }
3603 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303604 if (strcmp(ssid, dut->infra_ssid) == 0) {
3605 sigma_dut_print(dut, DUT_MSG_DEBUG,
3606 "sta_associate for the most recently added network");
3607 } else if (find_network(dut, ssid) < 0) {
3608 sigma_dut_print(dut, DUT_MSG_DEBUG,
3609 "sta_associate for a previously stored network profile");
3610 send_resp(dut, conn, SIGMA_ERROR,
3611 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003612 return 0;
3613 }
3614
3615 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003616 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003617 "bssid", bssid) < 0) {
3618 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3619 "Invalid bssid argument");
3620 return 0;
3621 }
3622
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303623 if ((dut->program == PROGRAM_WPA3 &&
3624 dut->sta_associate_wait_connect) ||
3625 dut->program == PROGRAM_QM) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003626 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003627 if (!ctrl)
3628 return ERROR_SEND_STATUS;
3629 }
3630
Jouni Malinen46a19b62017-06-23 14:31:27 +03003631 extra[0] = '\0';
3632 if (chan)
3633 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003634 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003635 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3636 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003637 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003638 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3639 "network id %d on %s",
3640 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003641 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003642 ret = ERROR_SEND_STATUS;
3643 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003644 }
3645 }
3646
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003647 if (!ctrl)
3648 return SUCCESS_SEND_STATUS;
3649
3650 /* Wait for connection result to be able to store server certificate
3651 * hash for trust root override testing
3652 * (dev_exec_action,ServerCertTrust). */
3653
3654 for (e = 0; e < 20; e++) {
3655 const char *events[] = {
3656 "CTRL-EVENT-EAP-PEER-CERT",
3657 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3658 "CTRL-EVENT-DISCONNECTED",
3659 "CTRL-EVENT-CONNECTED",
3660 "CTRL-EVENT-NETWORK-NOT-FOUND",
3661 NULL
3662 };
3663 char buf[1024];
3664 int res;
3665
3666 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3667 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02003668 send_resp(dut, conn, SIGMA_COMPLETE,
3669 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003670 ret = STATUS_SENT_ERROR;
3671 break;
3672 }
3673 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3674 buf);
3675
3676 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3677 strstr(buf, " depth=0")) {
3678 char *pos = strstr(buf, " hash=");
3679
3680 if (pos) {
3681 char *end;
3682
Jouni Malinen34b19cb2019-08-16 16:37:17 +03003683 if (strstr(buf, " tod=1"))
3684 tod = 1;
3685 else if (strstr(buf, " tod=2"))
3686 tod = 2;
3687 else
3688 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003689 sigma_dut_print(dut, DUT_MSG_DEBUG,
3690 "Server certificate TOD policy: %d",
3691 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03003692 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003693
3694 pos += 6;
3695 end = strchr(pos, ' ');
3696 if (end)
3697 *end = '\0';
3698 strlcpy(dut->server_cert_hash, pos,
3699 sizeof(dut->server_cert_hash));
3700 sigma_dut_print(dut, DUT_MSG_DEBUG,
3701 "Server certificate hash: %s",
3702 dut->server_cert_hash);
3703 }
3704 }
3705
3706 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3707 send_resp(dut, conn, SIGMA_COMPLETE,
3708 "Result,TLS server certificate validation failed");
3709 ret = STATUS_SENT_ERROR;
3710 break;
3711 }
3712
3713 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3714 num_network_not_found++;
3715
3716 if (num_network_not_found > 2) {
3717 send_resp(dut, conn, SIGMA_COMPLETE,
3718 "Result,Network not found");
3719 ret = STATUS_SENT_ERROR;
3720 break;
3721 }
3722 }
3723
3724 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3725 num_disconnected++;
3726
3727 if (num_disconnected > 2) {
3728 send_resp(dut, conn, SIGMA_COMPLETE,
3729 "Result,Connection failed");
3730 ret = STATUS_SENT_ERROR;
3731 break;
3732 }
3733 }
3734
3735 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3736 if (tod >= 0) {
3737 sigma_dut_print(dut, DUT_MSG_DEBUG,
3738 "Network profile TOD policy update: %d -> %d",
3739 dut->sta_tod_policy, tod);
3740 dut->sta_tod_policy = tod;
3741 }
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303742 if (dut->program == PROGRAM_QM) {
3743 unsigned char iface_mac_addr[ETH_ALEN];
3744 char ipv6[100];
3745
3746 if (get_hwaddr(ifname, iface_mac_addr) < 0) {
3747 sigma_dut_print(dut, DUT_MSG_ERROR,
3748 "%s: get_hwaddr %s failed",
3749 __func__, ifname);
3750 ret = ERROR_SEND_STATUS;
3751 break;
3752 }
3753
3754 convert_mac_addr_to_ipv6_lladdr(iface_mac_addr,
3755 ipv6,
3756 sizeof(ipv6));
3757
3758 if (set_ipv6_addr(dut, ipv6, "64", ifname) !=
3759 0) {
3760 ret = ERROR_SEND_STATUS;
3761 break;
3762 }
3763 }
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003764 break;
3765 }
3766 }
3767done:
3768 if (ctrl) {
3769 wpa_ctrl_detach(ctrl);
3770 wpa_ctrl_close(ctrl);
3771 }
3772 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003773}
3774
3775
3776static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3777{
3778 char buf[500], cmd[200];
3779 int res;
3780
3781 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3782 * default path */
3783 res = snprintf(cmd, sizeof(cmd),
3784 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3785 file_exists("./hs20-osu-client") ?
3786 "./hs20-osu-client" : "hs20-osu-client",
3787 sigma_wpas_ctrl,
3788 dut->summary_log ? "-s " : "",
3789 dut->summary_log ? dut->summary_log : "");
3790 if (res < 0 || res >= (int) sizeof(cmd))
3791 return -1;
3792
3793 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3794 if (res < 0 || res >= (int) sizeof(buf))
3795 return -1;
3796 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3797
3798 if (system(buf) != 0) {
3799 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3800 return -1;
3801 }
3802 sigma_dut_print(dut, DUT_MSG_DEBUG,
3803 "Completed hs20-osu-client operation");
3804
3805 return 0;
3806}
3807
3808
3809static int download_ppsmo(struct sigma_dut *dut,
3810 struct sigma_conn *conn,
3811 const char *intf,
3812 struct sigma_cmd *cmd)
3813{
3814 const char *name, *path, *val;
3815 char url[500], buf[600], fbuf[100];
3816 char *fqdn = NULL;
3817
3818 name = get_param(cmd, "FileName");
3819 path = get_param(cmd, "FilePath");
3820 if (name == NULL || path == NULL)
3821 return -1;
3822
3823 if (strcasecmp(path, "VendorSpecific") == 0) {
3824 snprintf(url, sizeof(url), "PPS/%s", name);
3825 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3826 "from the device (%s)", url);
3827 if (!file_exists(url)) {
3828 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3829 "PPS MO file does not exist");
3830 return 0;
3831 }
3832 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3833 if (system(buf) != 0) {
3834 send_resp(dut, conn, SIGMA_ERROR,
3835 "errorCode,Failed to copy PPS MO");
3836 return 0;
3837 }
3838 } else if (strncasecmp(path, "http:", 5) != 0 &&
3839 strncasecmp(path, "https:", 6) != 0) {
3840 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3841 "Unsupported FilePath value");
3842 return 0;
3843 } else {
3844 snprintf(url, sizeof(url), "%s/%s", path, name);
3845 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3846 url);
3847 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3848 remove("pps-tnds.xml");
3849 if (system(buf) != 0) {
3850 send_resp(dut, conn, SIGMA_ERROR,
3851 "errorCode,Failed to download PPS MO");
3852 return 0;
3853 }
3854 }
3855
3856 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3857 send_resp(dut, conn, SIGMA_ERROR,
3858 "errorCode,Failed to parse downloaded PPSMO");
3859 return 0;
3860 }
3861 unlink("pps-tnds.xml");
3862
3863 val = get_param(cmd, "managementTreeURI");
3864 if (val) {
3865 const char *pos, *end;
3866 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3867 val);
3868 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3869 send_resp(dut, conn, SIGMA_ERROR,
3870 "errorCode,Invalid managementTreeURI prefix");
3871 return 0;
3872 }
3873 pos = val + 8;
3874 end = strchr(pos, '/');
3875 if (end == NULL ||
3876 strcmp(end, "/PerProviderSubscription") != 0) {
3877 send_resp(dut, conn, SIGMA_ERROR,
3878 "errorCode,Invalid managementTreeURI postfix");
3879 return 0;
3880 }
3881 if (end - pos >= (int) sizeof(fbuf)) {
3882 send_resp(dut, conn, SIGMA_ERROR,
3883 "errorCode,Too long FQDN in managementTreeURI");
3884 return 0;
3885 }
3886 memcpy(fbuf, pos, end - pos);
3887 fbuf[end - pos] = '\0';
3888 fqdn = fbuf;
3889 sigma_dut_print(dut, DUT_MSG_INFO,
3890 "FQDN from managementTreeURI: %s", fqdn);
3891 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3892 FILE *f = fopen("pps-fqdn", "r");
3893 if (f) {
3894 if (fgets(fbuf, sizeof(fbuf), f)) {
3895 fbuf[sizeof(fbuf) - 1] = '\0';
3896 fqdn = fbuf;
3897 sigma_dut_print(dut, DUT_MSG_DEBUG,
3898 "Use FQDN %s", fqdn);
3899 }
3900 fclose(f);
3901 }
3902 }
3903
3904 if (fqdn == NULL) {
3905 send_resp(dut, conn, SIGMA_ERROR,
3906 "errorCode,No FQDN specified");
3907 return 0;
3908 }
3909
3910 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3911 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3912 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3913
3914 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3915 if (rename("pps.xml", buf) < 0) {
3916 send_resp(dut, conn, SIGMA_ERROR,
3917 "errorCode,Could not move PPS MO");
3918 return 0;
3919 }
3920
3921 if (strcasecmp(path, "VendorSpecific") == 0) {
3922 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3923 fqdn);
3924 if (system(buf)) {
3925 send_resp(dut, conn, SIGMA_ERROR,
3926 "errorCode,Failed to copy OSU CA cert");
3927 return 0;
3928 }
3929
3930 snprintf(buf, sizeof(buf),
3931 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3932 fqdn);
3933 if (system(buf)) {
3934 send_resp(dut, conn, SIGMA_ERROR,
3935 "errorCode,Failed to copy AAA CA cert");
3936 return 0;
3937 }
3938 } else {
3939 snprintf(buf, sizeof(buf),
3940 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3941 fqdn, fqdn);
3942 if (run_hs20_osu(dut, buf) < 0) {
3943 send_resp(dut, conn, SIGMA_ERROR,
3944 "errorCode,Failed to download OSU CA cert");
3945 return 0;
3946 }
3947
3948 snprintf(buf, sizeof(buf),
3949 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3950 fqdn, fqdn);
3951 if (run_hs20_osu(dut, buf) < 0) {
3952 sigma_dut_print(dut, DUT_MSG_INFO,
3953 "Failed to download AAA CA cert");
3954 }
3955 }
3956
3957 if (file_exists("next-client-cert.pem")) {
3958 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3959 if (rename("next-client-cert.pem", buf) < 0) {
3960 send_resp(dut, conn, SIGMA_ERROR,
3961 "errorCode,Could not move client certificate");
3962 return 0;
3963 }
3964 }
3965
3966 if (file_exists("next-client-key.pem")) {
3967 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3968 if (rename("next-client-key.pem", buf) < 0) {
3969 send_resp(dut, conn, SIGMA_ERROR,
3970 "errorCode,Could not move client key");
3971 return 0;
3972 }
3973 }
3974
3975 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3976 if (run_hs20_osu(dut, buf) < 0) {
3977 send_resp(dut, conn, SIGMA_ERROR,
3978 "errorCode,Failed to configure credential from "
3979 "PPSMO");
3980 return 0;
3981 }
3982
3983 return 1;
3984}
3985
3986
3987static int download_cert(struct sigma_dut *dut,
3988 struct sigma_conn *conn,
3989 const char *intf,
3990 struct sigma_cmd *cmd)
3991{
3992 const char *name, *path;
3993 char url[500], buf[600];
3994
3995 name = get_param(cmd, "FileName");
3996 path = get_param(cmd, "FilePath");
3997 if (name == NULL || path == NULL)
3998 return -1;
3999
4000 if (strcasecmp(path, "VendorSpecific") == 0) {
4001 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
4002 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4003 "certificate from the device (%s)", url);
4004 if (!file_exists(url)) {
4005 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4006 "certificate file does not exist");
4007 return 0;
4008 }
4009 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
4010 if (system(buf) != 0) {
4011 send_resp(dut, conn, SIGMA_ERROR,
4012 "errorCode,Failed to copy client "
4013 "certificate");
4014 return 0;
4015 }
4016
4017 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
4018 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4019 "private key from the device (%s)", url);
4020 if (!file_exists(url)) {
4021 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4022 "private key file does not exist");
4023 return 0;
4024 }
4025 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
4026 if (system(buf) != 0) {
4027 send_resp(dut, conn, SIGMA_ERROR,
4028 "errorCode,Failed to copy client key");
4029 return 0;
4030 }
4031 } else if (strncasecmp(path, "http:", 5) != 0 &&
4032 strncasecmp(path, "https:", 6) != 0) {
4033 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4034 "Unsupported FilePath value");
4035 return 0;
4036 } else {
4037 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
4038 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
4039 "certificate/key from %s", url);
4040 snprintf(buf, sizeof(buf),
4041 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
4042 if (system(buf) != 0) {
4043 send_resp(dut, conn, SIGMA_ERROR,
4044 "errorCode,Failed to download client "
4045 "certificate");
4046 return 0;
4047 }
4048
4049 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
4050 {
4051 send_resp(dut, conn, SIGMA_ERROR,
4052 "errorCode,Failed to copy client key");
4053 return 0;
4054 }
4055 }
4056
4057 return 1;
4058}
4059
4060
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004061static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
4062 struct sigma_conn *conn,
4063 struct sigma_cmd *cmd)
4064{
4065 const char *val;
4066 const char *intf = get_param(cmd, "interface");
4067
4068 if (!intf)
4069 return -1;
4070
4071 val = get_param(cmd, "WscIEFragment");
4072 if (val && strcasecmp(val, "enable") == 0) {
4073 sigma_dut_print(dut, DUT_MSG_DEBUG,
4074 "Enable WSC IE fragmentation");
4075
4076 dut->wsc_fragment = 1;
4077 /* set long attributes to force fragmentation */
4078 if (wpa_command(intf, "SET device_name "
4079 WPS_LONG_DEVICE_NAME) < 0)
4080 return -2;
4081 if (wpa_command(intf, "SET manufacturer "
4082 WPS_LONG_MANUFACTURER) < 0)
4083 return -2;
4084 if (wpa_command(intf, "SET model_name "
4085 WPS_LONG_MODEL_NAME) < 0)
4086 return -2;
4087 if (wpa_command(intf, "SET model_number "
4088 WPS_LONG_MODEL_NUMBER) < 0)
4089 return -2;
4090 if (wpa_command(intf, "SET serial_number "
4091 WPS_LONG_SERIAL_NUMBER) < 0)
4092 return -2;
4093 }
4094
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02004095 val = get_param(cmd, "RSN_IE");
4096 if (val) {
4097 if (strcasecmp(val, "disable") == 0)
4098 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
4099 else if (strcasecmp(val, "enable") == 0)
4100 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
4101 }
4102
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004103 val = get_param(cmd, "WpsVersion");
4104 if (val)
4105 dut->wps_forced_version = get_wps_forced_version(dut, val);
4106
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004107 val = get_param(cmd, "WscEAPFragment");
4108 if (val && strcasecmp(val, "enable") == 0)
4109 dut->eap_fragment = 1;
4110
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004111 return 1;
4112}
4113
4114
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004115static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4116 struct sigma_conn *conn,
4117 const char *intf,
4118 struct sigma_cmd *cmd)
4119{
4120 const char *val;
4121
4122 val = get_param(cmd, "FileType");
4123 if (val && strcasecmp(val, "PPSMO") == 0)
4124 return download_ppsmo(dut, conn, intf, cmd);
4125 if (val && strcasecmp(val, "CERT") == 0)
4126 return download_cert(dut, conn, intf, cmd);
4127 if (val) {
4128 send_resp(dut, conn, SIGMA_ERROR,
4129 "ErrorCode,Unsupported FileType");
4130 return 0;
4131 }
4132
4133 return 1;
4134}
4135
4136
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304137static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4138 struct sigma_conn *conn,
4139 const char *intf,
4140 struct sigma_cmd *cmd)
4141{
4142 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304143 char buf[1000];
4144 char text[20];
4145 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304146
4147 val = get_param(cmd, "OCESupport");
4148 if (val && strcasecmp(val, "Disable") == 0) {
4149 if (wpa_command(intf, "SET oce 0") < 0) {
4150 send_resp(dut, conn, SIGMA_ERROR,
4151 "ErrorCode,Failed to disable OCE");
4152 return 0;
4153 }
4154 } else if (val && strcasecmp(val, "Enable") == 0) {
4155 if (wpa_command(intf, "SET oce 1") < 0) {
4156 send_resp(dut, conn, SIGMA_ERROR,
4157 "ErrorCode,Failed to enable OCE");
4158 return 0;
4159 }
4160 }
4161
vamsi krishnaa2799492017-12-05 14:28:01 +05304162 val = get_param(cmd, "FILScap");
4163 if (val && (atoi(val) == 1)) {
4164 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4165 send_resp(dut, conn, SIGMA_ERROR,
4166 "ErrorCode,Failed to enable FILS");
4167 return 0;
4168 }
4169 } else if (val && (atoi(val) == 0)) {
4170 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4171 send_resp(dut, conn, SIGMA_ERROR,
4172 "ErrorCode,Failed to disable FILS");
4173 return 0;
4174 }
4175 }
4176
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304177 val = get_param(cmd, "FILSHLP");
4178 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004179 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304180 sizeof(text)) < 0)
4181 return -2;
4182 hwaddr_aton(text, addr);
4183 snprintf(buf, sizeof(buf),
4184 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4185 "080045100140000040004011399e00000000ffffffff00440043"
4186 "012cb30001010600fd4f46410000000000000000000000000000"
4187 "000000000000"
4188 "%02x%02x%02x%02x%02x%02x"
4189 "0000000000000000000000000000000000000000000000000000"
4190 "0000000000000000000000000000000000000000000000000000"
4191 "0000000000000000000000000000000000000000000000000000"
4192 "0000000000000000000000000000000000000000000000000000"
4193 "0000000000000000000000000000000000000000000000000000"
4194 "0000000000000000000000000000000000000000000000000000"
4195 "0000000000000000000000000000000000000000000000000000"
4196 "0000000000000000000000000000000000000000638253633501"
4197 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4198 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4199 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4200 if (wpa_command(intf, buf)) {
4201 send_resp(dut, conn, SIGMA_ERROR,
4202 "ErrorCode,Failed to add HLP");
4203 return 0;
4204 }
4205 dut->fils_hlp = 1;
4206 }
4207
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304208 return 1;
4209}
4210
4211
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004212static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4213 const char *val)
4214{
4215 int counter = 0;
4216 char token[50];
4217 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304218 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004219
Peng Xub8fc5cc2017-05-10 17:27:28 -07004220 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004221 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304222 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004223 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004224 if (strcmp(result, "disable") == 0)
4225 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4226 else
4227 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304228 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004229 counter++;
4230 }
4231}
4232
4233
4234static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4235 const char *val)
4236{
4237 char buf[100];
4238
4239 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4240 if (system(buf) != 0) {
4241 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4242 }
4243}
4244
4245
4246static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4247 const char *val)
4248{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004249 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004250 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004251 }
4252}
4253
4254
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004255static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4256 const char *val)
4257{
4258#ifdef NL80211_SUPPORT
4259 struct nl_msg *msg;
4260 int ret = 0;
4261 struct nlattr *params;
4262 int ifindex;
4263 int wmmenable = 1;
4264
4265 if (val &&
4266 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4267 wmmenable = 0;
4268
4269 ifindex = if_nametoindex(intf);
4270 if (ifindex == 0) {
4271 sigma_dut_print(dut, DUT_MSG_ERROR,
4272 "%s: Index for interface %s failed",
4273 __func__, intf);
4274 return -1;
4275 }
4276
4277 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4278 NL80211_CMD_VENDOR)) ||
4279 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4280 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4281 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4282 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4283 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4284 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4285 wmmenable)) {
4286 sigma_dut_print(dut, DUT_MSG_ERROR,
4287 "%s: err in adding vendor_cmd and vendor_data",
4288 __func__);
4289 nlmsg_free(msg);
4290 return -1;
4291 }
4292 nla_nest_end(msg, params);
4293
4294 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4295 if (ret) {
4296 sigma_dut_print(dut, DUT_MSG_ERROR,
4297 "%s: err in send_and_recv_msgs, ret=%d",
4298 __func__, ret);
4299 }
4300 return ret;
4301#else /* NL80211_SUPPORT */
4302 sigma_dut_print(dut, DUT_MSG_ERROR,
4303 "WMM cannot be changed without NL80211_SUPPORT defined");
4304 return -1;
4305#endif /* NL80211_SUPPORT */
4306}
4307
4308
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004309static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4310 const char *val)
4311{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004312 int sgi20;
4313
4314 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4315
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004316 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004317}
4318
4319
4320static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4321 const char *val)
4322{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304323 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004324
4325 /* Disable Tx Beam forming when using a fixed rate */
4326 ath_disable_txbf(dut, intf);
4327
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304328 v = atoi(val);
4329 if (v < 0 || v > 32) {
4330 sigma_dut_print(dut, DUT_MSG_ERROR,
4331 "Invalid Fixed MCS rate: %d", v);
4332 return;
4333 }
4334 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004335
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004336 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004337
4338 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004339 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004340}
4341
4342
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004343static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4344 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004345{
4346 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304347 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004348
4349 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4350 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4351 else
4352 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4353
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304354 ret = system(buf);
4355#ifdef NL80211_SUPPORT
4356 if (ret) {
4357 int value = (strcasecmp(val, "Enable") == 0) ? 2 : 1;
4358
4359 ret = sta_config_params(dut, intf, STA_SET_TX_MSDU, value);
4360 ret |= sta_config_params(dut, intf, STA_SET_RX_MSDU, value);
4361 }
4362#endif /* NL80211_SUPPORT */
4363 if (ret)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004364 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4365}
4366
4367
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004368static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4369 int ampdu)
4370{
4371 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004372 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004373
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004374 if (ampdu)
4375 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004376 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4377 if (system(buf) != 0) {
4378 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4379 return -1;
4380 }
4381
4382 return 0;
4383}
4384
4385
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004386static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4387 const char *val)
4388{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004389 run_iwpriv(dut, intf, "tx_stbc %s", val);
4390 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004391}
4392
4393
4394static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4395 const char *val)
4396{
4397 char buf[60];
4398
Peng Xucc317ed2017-05-18 16:44:37 -07004399 if (strcmp(val, "160") == 0) {
4400 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4401 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004402 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4403 } else if (strcmp(val, "40") == 0) {
4404 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4405 } else if (strcmp(val, "20") == 0) {
4406 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4407 } else if (strcasecmp(val, "Auto") == 0) {
4408 buf[0] = '\0';
4409 } else {
4410 sigma_dut_print(dut, DUT_MSG_ERROR,
4411 "WIDTH/CTS_WIDTH value not supported");
4412 return -1;
4413 }
4414
4415 if (buf[0] != '\0' && system(buf) != 0) {
4416 sigma_dut_print(dut, DUT_MSG_ERROR,
4417 "Failed to set WIDTH/CTS_WIDTH");
4418 return -1;
4419 }
4420
4421 return 0;
4422}
4423
4424
4425int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4426 const char *intf, const char *val)
4427{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004428 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004429 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004430 dut->chwidth = 0;
4431 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004432 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004433 dut->chwidth = 0;
4434 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004435 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004436 dut->chwidth = 1;
4437 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004438 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004439 dut->chwidth = 2;
4440 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004441 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004442 dut->chwidth = 3;
4443 } else {
4444 send_resp(dut, conn, SIGMA_ERROR,
4445 "ErrorCode,WIDTH not supported");
4446 return -1;
4447 }
4448
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004449 return 0;
4450}
4451
4452
4453static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4454 const char *val)
4455{
4456 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004457 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004458
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004459 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004460 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004461 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004462 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004463 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004464 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004465 } else {
4466 sigma_dut_print(dut, DUT_MSG_ERROR,
4467 "SP_STREAM value not supported");
4468 return -1;
4469 }
4470
4471 if (system(buf) != 0) {
4472 sigma_dut_print(dut, DUT_MSG_ERROR,
4473 "Failed to set SP_STREAM");
4474 return -1;
4475 }
4476
Arif Hussainac6c5112018-05-25 17:34:00 -07004477 dut->sta_nss = sta_nss;
4478
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004479 return 0;
4480}
4481
4482
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304483static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4484 const char *val)
4485{
4486 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304487 int ret;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304488
4489 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304490 ret = system(buf);
4491#ifdef NL80211_SUPPORT
4492 if (ret)
4493 ret = sta_config_params(dut, intf, STA_SET_TX_STBC,
4494 strcmp(val, "0") == 0 ? 0 : 1);
4495#endif /* NL80211_SUPPORT */
4496 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304497 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4498
4499 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304500 ret = system(buf);
4501#ifdef NL80211_SUPPORT
4502 if (ret)
4503 ret = sta_config_params(dut, intf, STA_SET_RX_STBC,
4504 strcmp(val, "0") == 0 ? 0 : 1);
4505#endif /* NL80211_SUPPORT */
4506 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304507 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4508}
4509
4510
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304511static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4512 struct sigma_conn *conn,
4513 const char *intf, int capa)
4514{
4515 char buf[32];
4516
4517 if (capa > 0 && capa < 4) {
4518 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4519 if (wpa_command(intf, buf) < 0) {
4520 send_resp(dut, conn, SIGMA_ERROR,
4521 "ErrorCode, Failed to set cellular data capability");
4522 return 0;
4523 }
4524 return 1;
4525 }
4526
4527 sigma_dut_print(dut, DUT_MSG_ERROR,
4528 "Invalid Cellular data capability: %d", capa);
4529 send_resp(dut, conn, SIGMA_INVALID,
4530 "ErrorCode,Invalid cellular data capability");
4531 return 0;
4532}
4533
4534
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304535static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4536 const char *intf, const char *val)
4537{
4538 if (strcasecmp(val, "Disable") == 0) {
4539 if (wpa_command(intf, "SET roaming 0") < 0) {
4540 send_resp(dut, conn, SIGMA_ERROR,
4541 "ErrorCode,Failed to disable roaming");
4542 return 0;
4543 }
4544 return 1;
4545 }
4546
4547 if (strcasecmp(val, "Enable") == 0) {
4548 if (wpa_command(intf, "SET roaming 1") < 0) {
4549 send_resp(dut, conn, SIGMA_ERROR,
4550 "ErrorCode,Failed to enable roaming");
4551 return 0;
4552 }
4553 return 1;
4554 }
4555
4556 sigma_dut_print(dut, DUT_MSG_ERROR,
4557 "Invalid value provided for roaming: %s", val);
4558 send_resp(dut, conn, SIGMA_INVALID,
4559 "ErrorCode,Unknown value provided for Roaming");
4560 return 0;
4561}
4562
4563
Ashwini Patila75de5a2017-04-13 16:35:05 +05304564static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4565 struct sigma_conn *conn,
4566 const char *intf, const char *val)
4567{
4568 if (strcasecmp(val, "Disable") == 0) {
4569 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4570 send_resp(dut, conn, SIGMA_ERROR,
4571 "ErrorCode,Failed to disable Assoc_disallow");
4572 return 0;
4573 }
4574 return 1;
4575 }
4576
4577 if (strcasecmp(val, "Enable") == 0) {
4578 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4579 send_resp(dut, conn, SIGMA_ERROR,
4580 "ErrorCode,Failed to enable Assoc_disallow");
4581 return 0;
4582 }
4583 return 1;
4584 }
4585
4586 sigma_dut_print(dut, DUT_MSG_ERROR,
4587 "Invalid value provided for Assoc_disallow: %s", val);
4588 send_resp(dut, conn, SIGMA_INVALID,
4589 "ErrorCode,Unknown value provided for Assoc_disallow");
4590 return 0;
4591}
4592
4593
Ashwini Patilc63161e2017-04-13 16:30:23 +05304594static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4595 const char *intf, const char *val)
4596{
4597 if (strcasecmp(val, "Reject") == 0) {
4598 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4599 send_resp(dut, conn, SIGMA_ERROR,
4600 "ErrorCode,Failed to Reject BTM Request");
4601 return 0;
4602 }
4603 return 1;
4604 }
4605
4606 if (strcasecmp(val, "Accept") == 0) {
4607 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4608 send_resp(dut, conn, SIGMA_ERROR,
4609 "ErrorCode,Failed to Accept BTM Request");
4610 return 0;
4611 }
4612 return 1;
4613 }
4614
4615 sigma_dut_print(dut, DUT_MSG_ERROR,
4616 "Invalid value provided for BSS_Transition: %s", val);
4617 send_resp(dut, conn, SIGMA_INVALID,
4618 "ErrorCode,Unknown value provided for BSS_Transition");
4619 return 0;
4620}
4621
4622
Ashwini Patil00402582017-04-13 12:29:39 +05304623static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4624 struct sigma_conn *conn,
4625 const char *intf,
4626 struct sigma_cmd *cmd)
4627{
4628 const char *ch, *pref, *op_class, *reason;
4629 char buf[120];
4630 int len, ret;
4631
4632 pref = get_param(cmd, "Ch_Pref");
4633 if (!pref)
4634 return 1;
4635
4636 if (strcasecmp(pref, "clear") == 0) {
4637 free(dut->non_pref_ch_list);
4638 dut->non_pref_ch_list = NULL;
4639 } else {
4640 op_class = get_param(cmd, "Ch_Op_Class");
4641 if (!op_class) {
4642 send_resp(dut, conn, SIGMA_INVALID,
4643 "ErrorCode,Ch_Op_Class not provided");
4644 return 0;
4645 }
4646
4647 ch = get_param(cmd, "Ch_Pref_Num");
4648 if (!ch) {
4649 send_resp(dut, conn, SIGMA_INVALID,
4650 "ErrorCode,Ch_Pref_Num not provided");
4651 return 0;
4652 }
4653
4654 reason = get_param(cmd, "Ch_Reason_Code");
4655 if (!reason) {
4656 send_resp(dut, conn, SIGMA_INVALID,
4657 "ErrorCode,Ch_Reason_Code not provided");
4658 return 0;
4659 }
4660
4661 if (!dut->non_pref_ch_list) {
4662 dut->non_pref_ch_list =
4663 calloc(1, NON_PREF_CH_LIST_SIZE);
4664 if (!dut->non_pref_ch_list) {
4665 send_resp(dut, conn, SIGMA_ERROR,
4666 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4667 return 0;
4668 }
4669 }
4670 len = strlen(dut->non_pref_ch_list);
4671 ret = snprintf(dut->non_pref_ch_list + len,
4672 NON_PREF_CH_LIST_SIZE - len,
4673 " %s:%s:%s:%s", op_class, ch, pref, reason);
4674 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4675 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4676 dut->non_pref_ch_list);
4677 } else {
4678 sigma_dut_print(dut, DUT_MSG_ERROR,
4679 "snprintf failed for non_pref_list, ret = %d",
4680 ret);
4681 send_resp(dut, conn, SIGMA_ERROR,
4682 "ErrorCode,snprintf failed");
4683 free(dut->non_pref_ch_list);
4684 dut->non_pref_ch_list = NULL;
4685 return 0;
4686 }
4687 }
4688
4689 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4690 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4691 if (ret < 0 || ret >= (int) sizeof(buf)) {
4692 sigma_dut_print(dut, DUT_MSG_DEBUG,
4693 "snprintf failed for set non_pref_chan, ret: %d",
4694 ret);
4695 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4696 return 0;
4697 }
4698
4699 if (wpa_command(intf, buf) < 0) {
4700 send_resp(dut, conn, SIGMA_ERROR,
4701 "ErrorCode,Failed to set non-preferred channel list");
4702 return 0;
4703 }
4704
4705 return 1;
4706}
4707
4708
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004709#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004710
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004711static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4712 uint8_t cfg)
4713{
4714 struct nl_msg *msg;
4715 int ret = 0;
4716 struct nlattr *params;
4717 int ifindex;
4718
4719 ifindex = if_nametoindex(intf);
4720 if (ifindex == 0) {
4721 sigma_dut_print(dut, DUT_MSG_ERROR,
4722 "%s: Index for interface %s failed",
4723 __func__, intf);
4724 return -1;
4725 }
4726
4727 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4728 NL80211_CMD_VENDOR)) ||
4729 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4730 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4731 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4732 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4733 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4734 nla_put_u8(msg,
4735 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4736 cfg)) {
4737 sigma_dut_print(dut, DUT_MSG_ERROR,
4738 "%s: err in adding vendor_cmd and vendor_data",
4739 __func__);
4740 nlmsg_free(msg);
4741 return -1;
4742 }
4743 nla_nest_end(msg, params);
4744
4745 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4746 if (ret) {
4747 sigma_dut_print(dut, DUT_MSG_ERROR,
4748 "%s: err in send_and_recv_msgs, ret=%d",
4749 __func__, ret);
4750 }
4751 return ret;
4752}
4753
4754
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004755static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4756 enum he_fragmentation_val frag)
4757{
4758 struct nl_msg *msg;
4759 int ret = 0;
4760 struct nlattr *params;
4761 int ifindex;
4762
4763 ifindex = if_nametoindex(intf);
4764 if (ifindex == 0) {
4765 sigma_dut_print(dut, DUT_MSG_ERROR,
4766 "%s: Index for interface %s failed",
4767 __func__, intf);
4768 return -1;
4769 }
4770
4771 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4772 NL80211_CMD_VENDOR)) ||
4773 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4774 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4775 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4776 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4777 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4778 nla_put_u8(msg,
4779 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
4780 frag)) {
4781 sigma_dut_print(dut, DUT_MSG_ERROR,
4782 "%s: err in adding vendor_cmd and vendor_data",
4783 __func__);
4784 nlmsg_free(msg);
4785 return -1;
4786 }
4787 nla_nest_end(msg, params);
4788
4789 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4790 if (ret) {
4791 sigma_dut_print(dut, DUT_MSG_ERROR,
4792 "%s: err in send_and_recv_msgs, ret=%d",
4793 __func__, ret);
4794 }
4795 return ret;
4796}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004797
4798
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08004799int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
4800 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004801{
4802 struct nl_msg *msg;
4803 int ret = 0;
4804 struct nlattr *params;
4805 int ifindex;
4806
4807 ifindex = if_nametoindex(intf);
4808 if (ifindex == 0) {
4809 sigma_dut_print(dut, DUT_MSG_ERROR,
4810 "%s: Index for interface %s failed",
4811 __func__, intf);
4812 return -1;
4813 }
4814
4815 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4816 NL80211_CMD_VENDOR)) ||
4817 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4818 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4819 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4820 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4821 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4822 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
4823 ltf)) {
4824 sigma_dut_print(dut, DUT_MSG_ERROR,
4825 "%s: err in adding vendor_cmd and vendor_data",
4826 __func__);
4827 nlmsg_free(msg);
4828 return -1;
4829 }
4830 nla_nest_end(msg, params);
4831
4832 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4833 if (ret) {
4834 sigma_dut_print(dut, DUT_MSG_ERROR,
4835 "%s: err in send_and_recv_msgs, ret=%d",
4836 __func__, ret);
4837 }
4838 return ret;
4839}
4840
4841
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004842static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4843 int noack, enum qca_wlan_ac_type ac)
4844{
4845 struct nl_msg *msg;
4846 int ret = 0;
4847 struct nlattr *params;
4848 int ifindex;
4849
4850 ifindex = if_nametoindex(intf);
4851 if (ifindex == 0) {
4852 sigma_dut_print(dut, DUT_MSG_ERROR,
4853 "%s: Index for interface %s failed",
4854 __func__, intf);
4855 return -1;
4856 }
4857
4858 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4859 NL80211_CMD_VENDOR)) ||
4860 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4861 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4862 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4863 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4864 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4865 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4866 noack) ||
4867 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4868 ac)) {
4869 sigma_dut_print(dut, DUT_MSG_ERROR,
4870 "%s: err in adding vendor_cmd and vendor_data",
4871 __func__);
4872 nlmsg_free(msg);
4873 return -1;
4874 }
4875 nla_nest_end(msg, params);
4876
4877 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4878 if (ret) {
4879 sigma_dut_print(dut, DUT_MSG_ERROR,
4880 "%s: err in send_and_recv_msgs, ret=%d",
4881 __func__, ret);
4882 }
4883 return ret;
4884}
4885
4886
4887static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4888 const char *val)
4889{
4890 int noack, ret;
4891 char token[100];
4892 char *result;
4893 char *saveptr;
4894 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4895
4896 strlcpy(token, val, sizeof(token));
4897 token[sizeof(token) - 1] = '\0';
4898 result = strtok_r(token, ":", &saveptr);
4899 while (result) {
4900 noack = strcasecmp(result, "Disable") != 0;
4901 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4902 if (ret) {
4903 sigma_dut_print(dut, DUT_MSG_ERROR,
4904 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4905 ac, ret);
4906 }
4907 result = strtok_r(NULL, ":", &saveptr);
4908 ac++;
4909 }
4910}
4911
Vinita S. Maloo7462e812020-05-22 15:16:04 +05304912
4913static int nlvendor_sta_set_phymode(struct sigma_dut *dut, const char *intf,
4914 enum qca_wlan_vendor_phy_mode val)
4915{
4916 struct nl_msg *msg;
4917 struct nlattr *params;
4918 int ifindex, ret;
4919
4920 ifindex = if_nametoindex(intf);
4921 if (ifindex == 0) {
4922 sigma_dut_print(dut, DUT_MSG_ERROR,
4923 "%s: Index for interface %s not found",
4924 __func__, intf);
4925 return -1;
4926 }
4927
4928 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4929 NL80211_CMD_VENDOR);
4930 if (!msg) {
4931 sigma_dut_print(dut, DUT_MSG_ERROR,
4932 "%s: err in adding vendor_cmd", __func__);
4933 return -1;
4934 }
4935
4936 if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4937 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4938 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) {
4939 sigma_dut_print(dut, DUT_MSG_ERROR,
4940 "%s: err in adding vendor_attr", __func__);
4941 nlmsg_free(msg);
4942 return -1;
4943 }
4944
4945 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
4946 if (!params || nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_PHY_MODE,
4947 val)) {
4948 sigma_dut_print(dut, DUT_MSG_ERROR,
4949 "%s: err in adding vendor_data", __func__);
4950 nlmsg_free(msg);
4951 return -1;
4952 }
4953
4954 nla_nest_end(msg, params);
4955 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4956 if (ret) {
4957 sigma_dut_print(dut, DUT_MSG_ERROR,
4958 "%s: err in send_and_recv_msgs, ret=%d (%s)",
4959 __func__, ret, strerror(-ret));
4960 return ret;
4961 }
4962
4963 return 0;
4964}
4965
4966
4967static enum qca_wlan_vendor_phy_mode get_qca_vendor_phymode(const char *val)
4968{
4969 if (strcmp(val, "11a") == 0) {
4970 /* IEEE80211_MODE_11A */
4971 return QCA_WLAN_VENDOR_PHY_MODE_11A;
4972 }
4973
4974 if (strcmp(val, "11g") == 0) {
4975 /* IEEE80211_MODE_11G */
4976 return QCA_WLAN_VENDOR_PHY_MODE_11G;
4977 }
4978
4979 if (strcmp(val, "11b") == 0) {
4980 /* IEEE80211_MODE_11B */
4981 return QCA_WLAN_VENDOR_PHY_MODE_11B;
4982 }
4983
4984 if (strcmp(val, "11n") == 0 ||
4985 strcmp(val, "11nl") == 0 ||
4986 strcmp(val, "11nl(nabg)") == 0) {
4987 /* IEEE80211_MODE_11AGN */
4988 return QCA_WLAN_VENDOR_PHY_MODE_11AGN;
4989 }
4990
4991 if (strcmp(val, "11ng") == 0) {
4992 /* IEEE80211_MODE_11NG_HT40 */
4993 return QCA_WLAN_VENDOR_PHY_MODE_11NG_HT40;
4994 }
4995
4996 if (strcmp(val, "AC") == 0 ||
4997 strcasecmp(val, "11AC") == 0) {
4998 /* IEEE80211_MODE_11AC_VHT80 */
4999 return QCA_WLAN_VENDOR_PHY_MODE_11AC_VHT80;
5000 }
5001
5002 if (strcmp(val, "11na") == 0 ||
5003 strcasecmp(val, "11an") == 0) {
5004 /* IEEE80211_MODE_11NA_HT40 */
5005 return QCA_WLAN_VENDOR_PHY_MODE_11NA_HT40;
5006 }
5007
5008 if (strcmp(val, "11ax") == 0 ||
5009 strcmp(val, "auto") == 0) {
5010 /* IEEE80211_MODE_AUTO */
5011 return QCA_WLAN_VENDOR_PHY_MODE_AUTO;
5012 }
5013
5014 return -1;
5015}
5016
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005017#endif /* NL80211_SUPPORT */
5018
5019
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305020static int get_phymode(const char *val)
5021{
5022 if (strcmp(val, "11a") == 0)
5023 return 1; /* IEEE80211_MODE_11A */
5024 if (strcmp(val, "11g") == 0)
5025 return 3; /* IEEE80211_MODE_11G */
5026 if (strcmp(val, "11b") == 0)
5027 return 2; /* IEEE80211_MODE_11B */
5028 if (strcmp(val, "11n") == 0 ||
5029 strcmp(val, "11nl") == 0 ||
5030 strcmp(val, "11nl(nabg)") == 0)
5031 return 22; /* IEEE80211_MODE_11AGN */
5032 if (strcmp(val, "11ng") == 0)
5033 return 13; /* IEEE80211_MODE_11NG_HT40 */
5034 if (strcmp(val, "AC") == 0 ||
5035 strcasecmp(val, "11AC") == 0)
5036 return 19; /* IEEE80211_MODE_11AC_VHT80 */
5037 if (strcmp(val, "11na") == 0 ||
5038 strcasecmp(val, "11an") == 0)
5039 return 14; /* IEEE80211_MODE_11NA_HT40 */
5040 if (strcmp(val, "11ax") == 0 ||
5041 strcmp(val, "auto") == 0)
5042 return 0; /* IEEE80211_MODE_AUTO */
5043 return -1;
5044}
5045
5046
5047static void sta_set_phymode(struct sigma_dut *dut, const char *intf,
5048 const char *val)
5049{
5050 char buf[100];
5051 int len, phymode;
Vinita S. Maloo7462e812020-05-22 15:16:04 +05305052#ifdef NL80211_SUPPORT
5053 enum qca_wlan_vendor_phy_mode qca_phymode;
5054
5055 qca_phymode = get_qca_vendor_phymode(val);
5056 if (qca_phymode == -1) {
5057 sigma_dut_print(dut, DUT_MSG_DEBUG,
5058 "Ignoring mode change for mode: %s",
5059 val);
5060 return;
5061 }
5062
5063 if (nlvendor_sta_set_phymode(dut, intf, qca_phymode) == 0)
5064 return;
5065#endif /* NL80211_SUPPORT */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305066
5067 phymode = get_phymode(val);
5068 if (phymode == -1) {
5069 sigma_dut_print(dut, DUT_MSG_DEBUG,
5070 "Ignoring mode change for mode: %s",
5071 val);
5072 return;
5073 }
5074
5075 len = snprintf(buf, sizeof(buf), "iwpriv %s setphymode %d", intf,
5076 phymode);
5077 if (len < 0 || len >= sizeof(buf)) {
5078 sigma_dut_print(dut, DUT_MSG_ERROR,
5079 "Failed to set phymode");
5080 return;
5081 }
5082
5083 if (system(buf) != 0)
5084 sigma_dut_print(dut, DUT_MSG_ERROR,
5085 "iwpriv setting of phymode failed");
5086}
5087
5088
Jouni Malinenf7222712019-06-13 01:50:21 +03005089static enum sigma_cmd_result
5090cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
5091 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005092{
5093 const char *intf = get_param(cmd, "Interface");
5094 const char *val;
5095
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03005096 val = get_param(cmd, "FT_DS");
5097 if (val) {
5098 if (strcasecmp(val, "Enable") == 0) {
5099 dut->sta_ft_ds = 1;
5100 } else if (strcasecmp(val, "Disable") == 0) {
5101 dut->sta_ft_ds = 0;
5102 } else {
5103 send_resp(dut, conn, SIGMA_ERROR,
5104 "errorCode,Unsupported value for FT_DS");
5105 return STATUS_SENT_ERROR;
5106 }
5107 }
5108
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005109 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03005110 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
5111 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005112 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
5113 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005114
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005115 if (val && strcasecmp(val, "LOC") == 0)
5116 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02005117 if (val && strcasecmp(val, "60GHZ") == 0) {
5118 val = get_param(cmd, "WPS");
5119 if (val && strcasecmp(val, "disable") == 0) {
5120 dut->wps_disable = 1;
5121 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
5122 } else {
5123 /* wps_disable can have other value from the previous
5124 * test, so make sure it has the correct value.
5125 */
5126 dut->wps_disable = 0;
5127 }
5128
5129 val = get_param(cmd, "P2P");
5130 if (val && strcasecmp(val, "disable") == 0)
5131 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
5132 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005133
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02005134 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
5135 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
5136
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005137#ifdef ANDROID_NAN
5138 if (val && strcasecmp(val, "NAN") == 0)
5139 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
5140#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005141#ifdef MIRACAST
5142 if (val && (strcasecmp(val, "WFD") == 0 ||
5143 strcasecmp(val, "DisplayR2") == 0))
5144 return miracast_preset_testparameters(dut, conn, cmd);
5145#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005146
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07005147 if (val &&
5148 (strcasecmp(val, "MBO") == 0 || strcasecmp(val, "HE") == 0)) {
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305149 val = get_param(cmd, "Cellular_Data_Cap");
5150 if (val &&
5151 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
5152 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05305153
5154 val = get_param(cmd, "Ch_Pref");
5155 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
5156 return 0;
5157
Ashwini Patilc63161e2017-04-13 16:30:23 +05305158 val = get_param(cmd, "BSS_Transition");
5159 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
5160 return 0;
5161
Ashwini Patila75de5a2017-04-13 16:35:05 +05305162 val = get_param(cmd, "Assoc_Disallow");
5163 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
5164 return 0;
5165
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305166 val = get_param(cmd, "Roaming");
5167 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
5168 return 0;
5169
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305170 return 1;
5171 }
5172
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305173 if (val && strcasecmp(val, "OCE") == 0)
5174 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
5175
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005176#if 0
5177 val = get_param(cmd, "Supplicant");
5178 if (val && strcasecmp(val, "Default") != 0) {
5179 send_resp(dut, conn, SIGMA_ERROR,
5180 "ErrorCode,Only default(Vendor) supplicant "
5181 "supported");
5182 return 0;
5183 }
5184#endif
5185
5186 val = get_param(cmd, "RTS");
5187 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005188 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005189 case DRIVER_ATHEROS:
5190 ath_sta_set_rts(dut, intf, val);
5191 break;
5192 default:
5193#if 0
5194 send_resp(dut, conn, SIGMA_ERROR,
5195 "ErrorCode,Setting RTS not supported");
5196 return 0;
5197#else
5198 sigma_dut_print(dut, DUT_MSG_DEBUG,
5199 "Setting RTS not supported");
5200 break;
5201#endif
5202 }
5203 }
5204
5205#if 0
5206 val = get_param(cmd, "FRGMNT");
5207 if (val) {
5208 /* TODO */
5209 send_resp(dut, conn, SIGMA_ERROR,
5210 "ErrorCode,Setting FRGMNT not supported");
5211 return 0;
5212 }
5213#endif
5214
5215#if 0
5216 val = get_param(cmd, "Preamble");
5217 if (val) {
5218 /* TODO: Long/Short */
5219 send_resp(dut, conn, SIGMA_ERROR,
5220 "ErrorCode,Setting Preamble not supported");
5221 return 0;
5222 }
5223#endif
5224
5225 val = get_param(cmd, "Mode");
5226 if (val) {
5227 if (strcmp(val, "11b") == 0 ||
5228 strcmp(val, "11g") == 0 ||
5229 strcmp(val, "11a") == 0 ||
5230 strcmp(val, "11n") == 0 ||
5231 strcmp(val, "11ng") == 0 ||
5232 strcmp(val, "11nl") == 0 ||
5233 strcmp(val, "11nl(nabg)") == 0 ||
5234 strcmp(val, "AC") == 0 ||
5235 strcmp(val, "11AC") == 0 ||
5236 strcmp(val, "11ac") == 0 ||
5237 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08005238 strcmp(val, "11an") == 0 ||
5239 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005240 /* STA supports all modes by default */
5241 } else {
5242 send_resp(dut, conn, SIGMA_ERROR,
5243 "ErrorCode,Setting Mode not supported");
5244 return 0;
5245 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005246
5247 /* Change the mode only in case of testbed for HE program
5248 * and for 11a and 11g modes only. */
5249 if (dut->program == PROGRAM_HE &&
5250 dut->device_type == STA_testbed) {
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305251 sta_set_phymode(dut, intf, val);
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005252 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005253 }
5254
5255 val = get_param(cmd, "wmm");
5256 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005257 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005258 case DRIVER_ATHEROS:
5259 ath_sta_set_wmm(dut, intf, val);
5260 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005261 case DRIVER_WCN:
5262 wcn_sta_set_wmm(dut, intf, val);
5263 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005264 default:
5265 sigma_dut_print(dut, DUT_MSG_DEBUG,
5266 "Setting wmm not supported");
5267 break;
5268 }
5269 }
5270
5271 val = get_param(cmd, "Powersave");
5272 if (val) {
5273 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005274 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305275 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005276 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005277 }
5278
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005279 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005280 "P2P_SET ps 0") < 0)
5281 return -2;
5282 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005283 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5284 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005285 } else if (strcmp(val, "1") == 0 ||
5286 strcasecmp(val, "PSPoll") == 0 ||
5287 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005288 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305289 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005290 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005291 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005292 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005293 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005294 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005295 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005296 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005297 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005298 "P2P_SET ps 99") < 0)
5299 return -2;
5300 } else if (strcmp(val, "2") == 0 ||
5301 strcasecmp(val, "Fast") == 0) {
5302 /* TODO */
5303 send_resp(dut, conn, SIGMA_ERROR,
5304 "ErrorCode,Powersave=Fast not supported");
5305 return 0;
5306 } else if (strcmp(val, "3") == 0 ||
5307 strcasecmp(val, "PSNonPoll") == 0) {
5308 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005309 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5310 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005311
5312 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005313 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005314 "P2P_SET ps 1") < 0)
5315 return -2;
5316 } else
5317 return -1;
5318 }
5319
5320 val = get_param(cmd, "NoAck");
5321 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005322 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005323 case DRIVER_ATHEROS:
5324 ath_sta_set_noack(dut, intf, val);
5325 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005326#ifdef NL80211_SUPPORT
5327 case DRIVER_WCN:
5328 wcn_sta_set_noack(dut, intf, val);
5329 break;
5330#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005331 default:
5332 send_resp(dut, conn, SIGMA_ERROR,
5333 "ErrorCode,Setting NoAck not supported");
5334 return 0;
5335 }
5336 }
5337
5338 val = get_param(cmd, "IgnoreChswitchProhibit");
5339 if (val) {
5340 /* TODO: Enabled/disabled */
5341 if (strcasecmp(val, "Enabled") == 0) {
5342 send_resp(dut, conn, SIGMA_ERROR,
5343 "ErrorCode,Enabling IgnoreChswitchProhibit "
5344 "not supported");
5345 return 0;
5346 }
5347 }
5348
5349 val = get_param(cmd, "TDLS");
5350 if (val) {
5351 if (strcasecmp(val, "Disabled") == 0) {
5352 if (wpa_command(intf, "SET tdls_disabled 1")) {
5353 send_resp(dut, conn, SIGMA_ERROR,
5354 "ErrorCode,Failed to disable TDLS");
5355 return 0;
5356 }
5357 } else if (strcasecmp(val, "Enabled") == 0) {
5358 if (wpa_command(intf, "SET tdls_disabled 0")) {
5359 send_resp(dut, conn, SIGMA_ERROR,
5360 "ErrorCode,Failed to enable TDLS");
5361 return 0;
5362 }
5363 } else {
5364 send_resp(dut, conn, SIGMA_ERROR,
5365 "ErrorCode,Unsupported TDLS value");
5366 return 0;
5367 }
5368 }
5369
5370 val = get_param(cmd, "TDLSmode");
5371 if (val) {
5372 if (strcasecmp(val, "Default") == 0) {
5373 wpa_command(intf, "SET tdls_testing 0");
5374 } else if (strcasecmp(val, "APProhibit") == 0) {
5375 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5376 send_resp(dut, conn, SIGMA_ERROR,
5377 "ErrorCode,Failed to enable ignore "
5378 "APProhibit TDLS mode");
5379 return 0;
5380 }
5381 } else if (strcasecmp(val, "HiLoMac") == 0) {
5382 /* STA should respond with TDLS setup req for a TDLS
5383 * setup req */
5384 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5385 send_resp(dut, conn, SIGMA_ERROR,
5386 "ErrorCode,Failed to enable HiLoMac "
5387 "TDLS mode");
5388 return 0;
5389 }
5390 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5391 /*
5392 * Since all security modes are enabled by default when
5393 * Sigma control is used, there is no need to do
5394 * anything here.
5395 */
5396 } else if (strcasecmp(val, "ExistLink") == 0) {
5397 /*
5398 * Since we allow new TDLS Setup Request even if there
5399 * is an existing link, nothing needs to be done for
5400 * this.
5401 */
5402 } else {
5403 /* TODO:
5404 * ExistLink: STA should send TDLS setup req even if
5405 * direct link already exists
5406 */
5407 send_resp(dut, conn, SIGMA_ERROR,
5408 "ErrorCode,Unsupported TDLSmode value");
5409 return 0;
5410 }
5411 }
5412
5413 val = get_param(cmd, "FakePubKey");
5414 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5415 send_resp(dut, conn, SIGMA_ERROR,
5416 "ErrorCode,Failed to enable FakePubKey");
5417 return 0;
5418 }
5419
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005420#ifdef NL80211_SUPPORT
5421 val = get_param(cmd, "FrgmntSupport");
5422 if (val) {
5423 if (strcasecmp(val, "Enable") == 0) {
5424 if (sta_set_he_fragmentation(dut, intf,
5425 HE_FRAG_LEVEL1)) {
5426 send_resp(dut, conn, SIGMA_ERROR,
5427 "ErrorCode,Failed to enable HE Fragmentation");
5428 return 0;
5429 }
5430 } else if (strcasecmp(val, "Disable") == 0) {
5431 if (sta_set_he_fragmentation(dut, intf,
5432 HE_FRAG_DISABLE)) {
5433 send_resp(dut, conn, SIGMA_ERROR,
5434 "ErrorCode,Failed to disable HE Fragmentation");
5435 return 0;
5436 }
5437 }
5438 }
5439#endif /* NL80211_SUPPORT */
5440
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305441 val = get_param(cmd, "IncludeMSCSDescriptor");
5442 if (val && strcasecmp(val, "1") == 0) {
5443 char buf[128];
5444 int len;
5445
5446 len = snprintf(buf, sizeof(buf),
Veerendranath Jakkam62cde372020-08-19 18:03:06 +05305447 "MSCS add up_bitmap=F0 up_limit=7 stream_timeout=60000 frame_classifier=045F%032x",
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305448 0);
5449
5450 if (len < 0 || len >= sizeof(buf)) {
5451 sigma_dut_print(dut, DUT_MSG_ERROR,
5452 "Failed to build MSCS Descriptor IE");
5453 return ERROR_SEND_STATUS;
5454 }
5455
5456 if (wpa_command(intf, buf) != 0) {
5457 send_resp(dut, conn, SIGMA_ERROR,
5458 "ErrorCode,Failed to include MSCS descriptor");
5459 return STATUS_SENT_ERROR;
5460 }
5461 }
5462
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005463 return 1;
5464}
5465
5466
5467static const char * ath_get_radio_name(const char *radio_name)
5468{
5469 if (radio_name == NULL)
5470 return "wifi0";
5471 if (strcmp(radio_name, "wifi1") == 0)
5472 return "wifi1";
5473 if (strcmp(radio_name, "wifi2") == 0)
5474 return "wifi2";
5475 return "wifi0";
5476}
5477
5478
5479static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5480 const char *val)
5481{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005482 unsigned int vht_mcsmap = 0;
5483 int txchainmask = 0;
5484 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5485
5486 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5487 if (dut->testbed_flag_txsp == 1) {
5488 vht_mcsmap = 0xfffc;
5489 dut->testbed_flag_txsp = 0;
5490 } else {
5491 vht_mcsmap = 0xfffe;
5492 }
5493 txchainmask = 1;
5494 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5495 if (dut->testbed_flag_txsp == 1) {
5496 vht_mcsmap = 0xfff0;
5497 dut->testbed_flag_txsp = 0;
5498 } else {
5499 vht_mcsmap = 0xfffa;
5500 }
5501 txchainmask = 3;
5502 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5503 if (dut->testbed_flag_txsp == 1) {
5504 vht_mcsmap = 0xffc0;
5505 dut->testbed_flag_txsp = 0;
5506 } else {
5507 vht_mcsmap = 0xffea;
5508 }
5509 txchainmask = 7;
5510 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5511 if (dut->testbed_flag_txsp == 1) {
5512 vht_mcsmap = 0xff00;
5513 dut->testbed_flag_txsp = 0;
5514 } else {
5515 vht_mcsmap = 0xffaa;
5516 }
5517 txchainmask = 15;
5518 } else {
5519 if (dut->testbed_flag_txsp == 1) {
5520 vht_mcsmap = 0xffc0;
5521 dut->testbed_flag_txsp = 0;
5522 } else {
5523 vht_mcsmap = 0xffea;
5524 }
5525 }
5526
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005527 if (txchainmask)
5528 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005529
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005530 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005531}
5532
5533
5534static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5535 const char *val)
5536{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005537 unsigned int vht_mcsmap = 0;
5538 int rxchainmask = 0;
5539 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5540
5541 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5542 if (dut->testbed_flag_rxsp == 1) {
5543 vht_mcsmap = 0xfffc;
5544 dut->testbed_flag_rxsp = 0;
5545 } else {
5546 vht_mcsmap = 0xfffe;
5547 }
5548 rxchainmask = 1;
5549 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5550 if (dut->testbed_flag_rxsp == 1) {
5551 vht_mcsmap = 0xfff0;
5552 dut->testbed_flag_rxsp = 0;
5553 } else {
5554 vht_mcsmap = 0xfffa;
5555 }
5556 rxchainmask = 3;
5557 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5558 if (dut->testbed_flag_rxsp == 1) {
5559 vht_mcsmap = 0xffc0;
5560 dut->testbed_flag_rxsp = 0;
5561 } else {
5562 vht_mcsmap = 0xffea;
5563 }
5564 rxchainmask = 7;
5565 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5566 if (dut->testbed_flag_rxsp == 1) {
5567 vht_mcsmap = 0xff00;
5568 dut->testbed_flag_rxsp = 0;
5569 } else {
5570 vht_mcsmap = 0xffaa;
5571 }
5572 rxchainmask = 15;
5573 } else {
5574 if (dut->testbed_flag_rxsp == 1) {
5575 vht_mcsmap = 0xffc0;
5576 dut->testbed_flag_rxsp = 0;
5577 } else {
5578 vht_mcsmap = 0xffea;
5579 }
5580 }
5581
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005582 if (rxchainmask)
5583 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005584
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005585 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005586}
5587
5588
5589void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5590{
5591 if (strcasecmp(val, "enable") == 0) {
5592 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5593 != 0) {
5594 sigma_dut_print(dut, DUT_MSG_ERROR,
5595 "Disable BB_VHTSIGB_CRC_CALC failed");
5596 }
5597
5598 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5599 != 0) {
5600 sigma_dut_print(dut, DUT_MSG_ERROR,
5601 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5602 }
5603 } else {
5604 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5605 != 0) {
5606 sigma_dut_print(dut, DUT_MSG_ERROR,
5607 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5608 }
5609
5610 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5611 != 0) {
5612 sigma_dut_print(dut, DUT_MSG_ERROR,
5613 "Enable BB_VHTSIGB_CRC_CALC failed");
5614 }
5615 }
5616}
5617
5618
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005619static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5620 const char *val)
5621{
5622 char buf[60];
5623
5624 if (strcmp(val, "20") == 0) {
5625 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5626 dut->chwidth = 0;
5627 } else if (strcmp(val, "40") == 0) {
5628 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5629 dut->chwidth = 1;
5630 } else if (strcmp(val, "80") == 0) {
5631 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5632 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305633 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005634 buf[0] = '\0';
5635 } else {
5636 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5637 val);
5638 return -1;
5639 }
5640
5641 if (buf[0] != '\0' && system(buf) != 0) {
5642 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5643 return -1;
5644 }
5645
5646 return 0;
5647}
5648
5649
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005650static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5651 const char *intf, int addbareject)
5652{
5653#ifdef NL80211_SUPPORT
5654 struct nl_msg *msg;
5655 int ret = 0;
5656 struct nlattr *params;
5657 int ifindex;
5658
5659 ifindex = if_nametoindex(intf);
5660 if (ifindex == 0) {
5661 sigma_dut_print(dut, DUT_MSG_ERROR,
5662 "%s: Index for interface %s failed",
5663 __func__, intf);
5664 return -1;
5665 }
5666
5667 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5668 NL80211_CMD_VENDOR)) ||
5669 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5670 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5671 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5672 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5673 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5674 nla_put_u8(msg,
5675 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5676 !addbareject)) {
5677 sigma_dut_print(dut, DUT_MSG_ERROR,
5678 "%s: err in adding vendor_cmd and vendor_data",
5679 __func__);
5680 nlmsg_free(msg);
5681 return -1;
5682 }
5683 nla_nest_end(msg, params);
5684
5685 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5686 if (ret) {
5687 sigma_dut_print(dut, DUT_MSG_ERROR,
5688 "%s: err in send_and_recv_msgs, ret=%d",
5689 __func__, ret);
5690 }
5691 return ret;
5692#else /* NL80211_SUPPORT */
5693 sigma_dut_print(dut, DUT_MSG_ERROR,
5694 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5695 return -1;
5696#endif /* NL80211_SUPPORT */
5697}
5698
5699
5700static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5701 int addbareject)
5702{
5703 int ret;
5704
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005705 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005706 case DRIVER_WCN:
5707 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5708 if (ret) {
5709 sigma_dut_print(dut, DUT_MSG_ERROR,
5710 "nlvendor_sta_set_addba_reject failed, ret:%d",
5711 ret);
5712 return ret;
5713 }
5714 break;
5715 default:
5716 sigma_dut_print(dut, DUT_MSG_ERROR,
5717 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5718 ret = -1;
5719 break;
5720 }
5721
5722 return ret;
5723}
5724
5725
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005726static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5727 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005728{
5729#ifdef NL80211_SUPPORT
5730 struct nl_msg *msg;
5731 int ret = 0;
5732 struct nlattr *params;
5733 int ifindex;
5734
5735 ifindex = if_nametoindex(intf);
5736 if (ifindex == 0) {
5737 sigma_dut_print(dut, DUT_MSG_ERROR,
5738 "%s: Index for interface %s failed",
5739 __func__, intf);
5740 return -1;
5741 }
5742
5743 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5744 NL80211_CMD_VENDOR)) ||
5745 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5746 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5747 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5748 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5749 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5750 nla_put_u8(msg,
5751 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005752 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005753 sigma_dut_print(dut, DUT_MSG_ERROR,
5754 "%s: err in adding vendor_cmd and vendor_data",
5755 __func__);
5756 nlmsg_free(msg);
5757 return -1;
5758 }
5759 nla_nest_end(msg, params);
5760
5761 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5762 if (ret) {
5763 sigma_dut_print(dut, DUT_MSG_ERROR,
5764 "%s: err in send_and_recv_msgs, ret=%d",
5765 __func__, ret);
5766 }
5767 return ret;
5768#else /* NL80211_SUPPORT */
5769 sigma_dut_print(dut, DUT_MSG_ERROR,
5770 "Disable addba not possible without NL80211_SUPPORT defined");
5771 return -1;
5772#endif /* NL80211_SUPPORT */
5773}
5774
5775
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305776#ifdef NL80211_SUPPORT
5777static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5778{
5779 struct nl_msg *msg;
5780 int ret = 0;
5781 int ifindex;
5782
5783 ifindex = if_nametoindex(intf);
5784 if (ifindex == 0) {
5785 sigma_dut_print(dut, DUT_MSG_ERROR,
5786 "%s: Index for interface %s failed",
5787 __func__, intf);
5788 return -1;
5789 }
5790
5791 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5792 NL80211_CMD_SET_WIPHY)) ||
5793 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5794 sigma_dut_print(dut, DUT_MSG_ERROR,
5795 "%s: err in adding RTS threshold",
5796 __func__);
5797 nlmsg_free(msg);
5798 return -1;
5799 }
5800
5801 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5802 if (ret) {
5803 sigma_dut_print(dut, DUT_MSG_ERROR,
5804 "%s: err in send_and_recv_msgs, ret=%d",
5805 __func__, ret);
5806 }
5807 return ret;
5808}
5809#endif /* NL80211_SUPPORT */
5810
5811
5812static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5813{
5814 char buf[100];
5815
5816#ifdef NL80211_SUPPORT
5817 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5818 return 0;
5819 sigma_dut_print(dut, DUT_MSG_DEBUG,
5820 "Fall back to using iwconfig for setting RTS threshold");
5821#endif /* NL80211_SUPPORT */
5822
5823 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5824 if (system(buf) != 0) {
5825 sigma_dut_print(dut, DUT_MSG_ERROR,
5826 "Failed to set RTS threshold %d", val);
5827 return -1;
5828 }
5829 return 0;
5830}
5831
5832
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005833static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5834 struct sigma_conn *conn,
5835 struct sigma_cmd *cmd)
5836{
5837 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005838 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005839 char buf[128];
5840 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005841
5842 val = get_param(cmd, "40_INTOLERANT");
5843 if (val) {
5844 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5845 /* TODO: iwpriv ht40intol through wpa_supplicant */
5846 send_resp(dut, conn, SIGMA_ERROR,
5847 "ErrorCode,40_INTOLERANT not supported");
5848 return 0;
5849 }
5850 }
5851
5852 val = get_param(cmd, "ADDBA_REJECT");
5853 if (val) {
5854 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5855 /* reject any ADDBA with status "decline" */
5856 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005857 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005858 } else {
5859 /* accept ADDBA */
5860 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005861 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005862 }
5863 }
5864
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005865 if (addbareject >= 0 &&
5866 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5867 send_resp(dut, conn, SIGMA_ERROR,
5868 "ErrorCode,set addba_reject failed");
5869 return 0;
5870 }
5871
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005872 val = get_param(cmd, "AMPDU");
5873 if (val) {
5874 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5875 /* enable AMPDU Aggregation */
5876 if (ampdu == 0) {
5877 send_resp(dut, conn, SIGMA_ERROR,
5878 "ErrorCode,Mismatch in "
5879 "addba_reject/ampdu - "
5880 "not supported");
5881 return 0;
5882 }
5883 ampdu = 1;
5884 } else {
5885 /* disable AMPDU Aggregation */
5886 if (ampdu == 1) {
5887 send_resp(dut, conn, SIGMA_ERROR,
5888 "ErrorCode,Mismatch in "
5889 "addba_reject/ampdu - "
5890 "not supported");
5891 return 0;
5892 }
5893 ampdu = 0;
5894 }
5895 }
5896
5897 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005898 int ret;
5899
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005900 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5901 ampdu ? "Enabling" : "Disabling");
5902 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005903 if (wpa_command(intf, buf) < 0 &&
5904 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005905 send_resp(dut, conn, SIGMA_ERROR,
5906 "ErrorCode,set aggr failed");
5907 return 0;
5908 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005909
5910 if (ampdu == 0) {
5911 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005912 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005913 if (ret) {
5914 sigma_dut_print(dut, DUT_MSG_ERROR,
5915 "Failed to disable addba, ret:%d",
5916 ret);
5917 }
5918 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005919 }
5920
5921 val = get_param(cmd, "AMSDU");
5922 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005923 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005924 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005925 case DRIVER_WCN:
5926 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005927 break;
5928 default:
5929 if (strcmp(val, "1") == 0 ||
5930 strcasecmp(val, "Enable") == 0) {
5931 /* Enable AMSDU Aggregation */
5932 send_resp(dut, conn, SIGMA_ERROR,
5933 "ErrorCode,AMSDU aggregation not supported");
5934 return 0;
5935 }
5936 break;
5937 }
5938 }
5939
5940 val = get_param(cmd, "STBC_RX");
5941 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005942 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005943 case DRIVER_ATHEROS:
5944 ath_sta_set_stbc(dut, intf, val);
5945 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305946 case DRIVER_WCN:
5947 wcn_sta_set_stbc(dut, intf, val);
5948 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005949 default:
5950 send_resp(dut, conn, SIGMA_ERROR,
5951 "ErrorCode,STBC_RX not supported");
5952 return 0;
5953 }
5954 }
5955
5956 val = get_param(cmd, "WIDTH");
5957 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005958 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005959 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005960 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005961 send_resp(dut, conn, SIGMA_ERROR,
5962 "ErrorCode,Failed to set WIDTH");
5963 return 0;
5964 }
5965 break;
5966 case DRIVER_ATHEROS:
5967 if (ath_set_width(dut, conn, intf, val) < 0)
5968 return 0;
5969 break;
5970 default:
5971 sigma_dut_print(dut, DUT_MSG_ERROR,
5972 "Setting WIDTH not supported");
5973 break;
5974 }
5975 }
5976
5977 val = get_param(cmd, "SMPS");
5978 if (val) {
5979 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5980 send_resp(dut, conn, SIGMA_ERROR,
5981 "ErrorCode,SMPS not supported");
5982 return 0;
5983 }
5984
5985 val = get_param(cmd, "TXSP_STREAM");
5986 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005987 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005988 case DRIVER_WCN:
5989 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5990 send_resp(dut, conn, SIGMA_ERROR,
5991 "ErrorCode,Failed to set TXSP_STREAM");
5992 return 0;
5993 }
5994 break;
5995 case DRIVER_ATHEROS:
5996 ath_sta_set_txsp_stream(dut, intf, val);
5997 break;
5998 default:
5999 sigma_dut_print(dut, DUT_MSG_ERROR,
6000 "Setting TXSP_STREAM not supported");
6001 break;
6002 }
6003 }
6004
6005 val = get_param(cmd, "RXSP_STREAM");
6006 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006007 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006008 case DRIVER_WCN:
6009 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
6010 send_resp(dut, conn, SIGMA_ERROR,
6011 "ErrorCode,Failed to set RXSP_STREAM");
6012 return 0;
6013 }
6014 break;
6015 case DRIVER_ATHEROS:
6016 ath_sta_set_rxsp_stream(dut, intf, val);
6017 break;
6018 default:
6019 sigma_dut_print(dut, DUT_MSG_ERROR,
6020 "Setting RXSP_STREAM not supported");
6021 break;
6022 }
6023 }
6024
6025 val = get_param(cmd, "DYN_BW_SGNL");
6026 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006027 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006028 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08006029 if (strcasecmp(val, "enable") == 0) {
6030 snprintf(buf, sizeof(buf),
6031 "iwpriv %s cwmenable 1", intf);
6032 if (system(buf) != 0) {
6033 sigma_dut_print(dut, DUT_MSG_ERROR,
6034 "iwpriv cwmenable 1 failed");
6035 return 0;
6036 }
6037 } else if (strcasecmp(val, "disable") == 0) {
6038 snprintf(buf, sizeof(buf),
6039 "iwpriv %s cwmenable 0", intf);
6040 if (system(buf) != 0) {
6041 sigma_dut_print(dut, DUT_MSG_ERROR,
6042 "iwpriv cwmenable 0 failed");
6043 return 0;
6044 }
6045 } else {
6046 sigma_dut_print(dut, DUT_MSG_ERROR,
6047 "Unsupported DYN_BW_SGL");
6048 }
6049
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006050 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
6051 if (system(buf) != 0) {
6052 sigma_dut_print(dut, DUT_MSG_ERROR,
6053 "Failed to set cts_cbw in DYN_BW_SGNL");
6054 return 0;
6055 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006056 break;
6057 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006058 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006059 ath_config_dyn_bw_sig(dut, intf, val);
6060 break;
6061 default:
6062 sigma_dut_print(dut, DUT_MSG_ERROR,
6063 "Failed to set DYN_BW_SGNL");
6064 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006065 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006066 }
6067
6068 val = get_param(cmd, "RTS_FORCE");
6069 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006070 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006071 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306072 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006073 sigma_dut_print(dut, DUT_MSG_ERROR,
6074 "Failed to set RTS_FORCE 64");
6075 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03006076 res = snprintf(buf, sizeof(buf),
6077 "wifitool %s beeliner_fw_test 100 1",
6078 intf);
6079 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08006080 sigma_dut_print(dut, DUT_MSG_ERROR,
6081 "wifitool beeliner_fw_test 100 1 failed");
6082 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006083 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306084 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006085 sigma_dut_print(dut, DUT_MSG_ERROR,
6086 "Failed to set RTS_FORCE 2347");
6087 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006088 } else {
6089 send_resp(dut, conn, SIGMA_ERROR,
6090 "ErrorCode,RTS_FORCE value not supported");
6091 return 0;
6092 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006093 }
6094
6095 val = get_param(cmd, "CTS_WIDTH");
6096 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006097 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006098 case DRIVER_WCN:
6099 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
6100 send_resp(dut, conn, SIGMA_ERROR,
6101 "ErrorCode,Failed to set CTS_WIDTH");
6102 return 0;
6103 }
6104 break;
6105 case DRIVER_ATHEROS:
6106 ath_set_cts_width(dut, intf, val);
6107 break;
6108 default:
6109 sigma_dut_print(dut, DUT_MSG_ERROR,
6110 "Setting CTS_WIDTH not supported");
6111 break;
6112 }
6113 }
6114
6115 val = get_param(cmd, "BW_SGNL");
6116 if (val) {
6117 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006118 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006119 } else if (strcasecmp(val, "Disable") == 0) {
6120 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006121 } else {
6122 send_resp(dut, conn, SIGMA_ERROR,
6123 "ErrorCode,BW_SGNL value not supported");
6124 return 0;
6125 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006126 }
6127
6128 val = get_param(cmd, "Band");
6129 if (val) {
6130 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
6131 /* STA supports all bands by default */
6132 } else {
6133 send_resp(dut, conn, SIGMA_ERROR,
6134 "ErrorCode,Unsupported Band");
6135 return 0;
6136 }
6137 }
6138
6139 val = get_param(cmd, "zero_crc");
6140 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006141 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006142 case DRIVER_ATHEROS:
6143 ath_set_zero_crc(dut, val);
6144 break;
6145 default:
6146 break;
6147 }
6148 }
6149
6150 return 1;
6151}
6152
6153
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006154static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
6155{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006156 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006157#ifdef __linux__
6158 case DRIVER_WIL6210:
6159 return wil6210_set_force_mcs(dut, force, mcs);
6160#endif /* __linux__ */
6161 default:
6162 sigma_dut_print(dut, DUT_MSG_ERROR,
6163 "Unsupported sta_set_force_mcs with the current driver");
6164 return -1;
6165 }
6166}
6167
6168
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006169static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
6170{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006171 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006172#ifdef __linux__
6173 case DRIVER_WIL6210:
6174 return wil6210_force_rsn_ie(dut, state);
6175#endif /* __linux__ */
6176 default:
6177 sigma_dut_print(dut, DUT_MSG_ERROR,
6178 "Unsupported sta_60g_force_rsn_ie with the current driver");
6179 return -1;
6180 }
6181}
6182
6183
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006184static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
6185 struct sigma_cmd *cmd)
6186{
6187 const char *val;
6188 char buf[100];
6189
6190 val = get_param(cmd, "MSDUSize");
6191 if (val) {
6192 int mtu;
6193
6194 dut->amsdu_size = atoi(val);
6195 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
6196 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
6197 sigma_dut_print(dut, DUT_MSG_ERROR,
6198 "MSDUSize %d is above max %d or below min %d",
6199 dut->amsdu_size,
6200 IEEE80211_MAX_DATA_LEN_DMG,
6201 IEEE80211_SNAP_LEN_DMG);
6202 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006203 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006204 }
6205
6206 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
6207 sigma_dut_print(dut, DUT_MSG_DEBUG,
6208 "Setting amsdu_size to %d", mtu);
6209 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006210 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006211
6212 if (system(buf) != 0) {
6213 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
6214 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006215 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006216 }
6217 }
6218
6219 val = get_param(cmd, "BAckRcvBuf");
6220 if (val) {
6221 dut->back_rcv_buf = atoi(val);
6222 if (dut->back_rcv_buf == 0) {
6223 sigma_dut_print(dut, DUT_MSG_ERROR,
6224 "Failed to convert %s or value is 0",
6225 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006226 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006227 }
6228
6229 sigma_dut_print(dut, DUT_MSG_DEBUG,
6230 "Setting BAckRcvBuf to %s", val);
6231 }
6232
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006233 val = get_param(cmd, "MCS_FixedRate");
6234 if (val) {
6235 if (sta_set_force_mcs(dut, 1, atoi(val))) {
6236 sigma_dut_print(dut, DUT_MSG_ERROR,
6237 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006238 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006239 }
6240 }
6241
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006242 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006243}
6244
6245
6246static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
6247 struct sigma_cmd *cmd)
6248{
6249 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006250 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006251 const char *val;
6252 char buf[100];
6253
6254 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006255 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006256 if (wpa_command(ifname, "PING") != 0) {
6257 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006258 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006259 }
6260
6261 wpa_command(ifname, "FLUSH");
6262 net_id = add_network_common(dut, conn, ifname, cmd);
6263 if (net_id < 0) {
6264 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
6265 return net_id;
6266 }
6267
6268 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
6269 if (set_network(ifname, net_id, "mode", "2") < 0) {
6270 sigma_dut_print(dut, DUT_MSG_ERROR,
6271 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006272 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006273 }
6274
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006275 if (set_network(ifname, net_id, "pbss", "1") < 0)
6276 return -2;
6277
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006278 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006279 "Supplicant set network with mode 2. network_id %d",
6280 net_id);
6281
6282 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6283 sigma_dut_print(dut, DUT_MSG_INFO,
6284 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006285 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006286 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006287
6288 val = get_param(cmd, "Security");
6289 if (val && strcasecmp(val, "OPEN") == 0) {
6290 dut->ap_key_mgmt = AP_OPEN;
6291 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6292 sigma_dut_print(dut, DUT_MSG_ERROR,
6293 "Failed to set supplicant to %s security",
6294 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006295 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006296 }
6297 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6298 dut->ap_key_mgmt = AP_WPA2_PSK;
6299 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6300 sigma_dut_print(dut, DUT_MSG_ERROR,
6301 "Failed to set supplicant to %s security",
6302 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006303 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006304 }
6305
6306 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6307 sigma_dut_print(dut, DUT_MSG_ERROR,
6308 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006309 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006310 }
6311 } else if (val) {
6312 sigma_dut_print(dut, DUT_MSG_ERROR,
6313 "Requested Security %s is not supported on 60GHz",
6314 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006315 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006316 }
6317
6318 val = get_param(cmd, "Encrypt");
6319 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6320 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6321 sigma_dut_print(dut, DUT_MSG_ERROR,
6322 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006323 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006324 }
6325 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6326 sigma_dut_print(dut, DUT_MSG_ERROR,
6327 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006328 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006329 }
6330 } else if (val) {
6331 sigma_dut_print(dut, DUT_MSG_ERROR,
6332 "Requested Encrypt %s is not supported on 60 GHz",
6333 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006334 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006335 }
6336
6337 val = get_param(cmd, "PSK");
6338 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6339 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6340 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006341 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006342 }
6343
6344 /* Convert 60G channel to freq */
6345 switch (dut->ap_channel) {
6346 case 1:
6347 val = "58320";
6348 break;
6349 case 2:
6350 val = "60480";
6351 break;
6352 case 3:
6353 val = "62640";
6354 break;
6355 default:
6356 sigma_dut_print(dut, DUT_MSG_ERROR,
6357 "Failed to configure channel %d. Not supported",
6358 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006359 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006360 }
6361
6362 if (set_network(ifname, net_id, "frequency", val) < 0) {
6363 sigma_dut_print(dut, DUT_MSG_ERROR,
6364 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006365 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006366 }
6367
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006368 if (dut->eap_fragment) {
6369 sigma_dut_print(dut, DUT_MSG_DEBUG,
6370 "Set EAP fragment size to 128 bytes.");
6371 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6372 return ERROR_SEND_STATUS;
6373 }
6374
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006375 sigma_dut_print(dut, DUT_MSG_DEBUG,
6376 "Supplicant set network with frequency");
6377
6378 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6379 if (wpa_command(ifname, buf) < 0) {
6380 sigma_dut_print(dut, DUT_MSG_INFO,
6381 "Failed to select network id %d on %s",
6382 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006383 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006384 }
6385
6386 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6387
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006388 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006389}
6390
6391
Lior David67543f52017-01-03 19:04:22 +02006392static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6393{
6394 char buf[128], fname[128];
6395 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006396 int res;
Lior David67543f52017-01-03 19:04:22 +02006397
6398 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6399 sigma_dut_print(dut, DUT_MSG_ERROR,
6400 "failed to get wil6210 debugfs dir");
6401 return -1;
6402 }
6403
Jouni Malinen3aa72862019-05-29 23:14:51 +03006404 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6405 if (res < 0 || res >= sizeof(fname))
6406 return -1;
Lior David67543f52017-01-03 19:04:22 +02006407 f = fopen(fname, "w");
6408 if (!f) {
6409 sigma_dut_print(dut, DUT_MSG_ERROR,
6410 "failed to open: %s", fname);
6411 return -1;
6412 }
6413
6414 fprintf(f, "%d\n", abft_len);
6415 fclose(f);
6416
6417 return 0;
6418}
6419
6420
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006421int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6422 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006423{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006424 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006425 case DRIVER_WIL6210:
6426 return wil6210_set_abft_len(dut, abft_len);
6427 default:
6428 sigma_dut_print(dut, DUT_MSG_ERROR,
6429 "set abft_len not supported");
6430 return -1;
6431 }
6432}
6433
6434
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006435static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6436 struct sigma_cmd *cmd)
6437{
6438 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006439 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006440
6441 if (dut->dev_role != DEVROLE_PCP) {
6442 send_resp(dut, conn, SIGMA_INVALID,
6443 "ErrorCode,Invalid DevRole");
6444 return 0;
6445 }
6446
6447 val = get_param(cmd, "SSID");
6448 if (val) {
6449 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6450 send_resp(dut, conn, SIGMA_INVALID,
6451 "ErrorCode,Invalid SSID");
6452 return -1;
6453 }
6454
Peng Xub8fc5cc2017-05-10 17:27:28 -07006455 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006456 }
6457
6458 val = get_param(cmd, "CHANNEL");
6459 if (val) {
6460 const char *pos;
6461
6462 dut->ap_channel = atoi(val);
6463 pos = strchr(val, ';');
6464 if (pos) {
6465 pos++;
6466 dut->ap_channel_1 = atoi(pos);
6467 }
6468 }
6469
6470 switch (dut->ap_channel) {
6471 case 1:
6472 case 2:
6473 case 3:
6474 break;
6475 default:
6476 sigma_dut_print(dut, DUT_MSG_ERROR,
6477 "Channel %d is not supported", dut->ap_channel);
6478 send_resp(dut, conn, SIGMA_ERROR,
6479 "Requested channel is not supported");
6480 return -1;
6481 }
6482
6483 val = get_param(cmd, "BCNINT");
6484 if (val)
6485 dut->ap_bcnint = atoi(val);
6486
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006487 val = get_param(cmd, "AllocType");
6488 if (val) {
6489 send_resp(dut, conn, SIGMA_ERROR,
6490 "ErrorCode,AllocType is not supported yet");
6491 return -1;
6492 }
6493
6494 val = get_param(cmd, "PercentBI");
6495 if (val) {
6496 send_resp(dut, conn, SIGMA_ERROR,
6497 "ErrorCode,PercentBI is not supported yet");
6498 return -1;
6499 }
6500
6501 val = get_param(cmd, "CBAPOnly");
6502 if (val) {
6503 send_resp(dut, conn, SIGMA_ERROR,
6504 "ErrorCode,CBAPOnly is not supported yet");
6505 return -1;
6506 }
6507
6508 val = get_param(cmd, "AMPDU");
6509 if (val) {
6510 if (strcasecmp(val, "Enable") == 0)
6511 dut->ap_ampdu = 1;
6512 else if (strcasecmp(val, "Disable") == 0)
6513 dut->ap_ampdu = 2;
6514 else {
6515 send_resp(dut, conn, SIGMA_ERROR,
6516 "ErrorCode,AMPDU value is not Enable nor Disabled");
6517 return -1;
6518 }
6519 }
6520
6521 val = get_param(cmd, "AMSDU");
6522 if (val) {
6523 if (strcasecmp(val, "Enable") == 0)
6524 dut->ap_amsdu = 1;
6525 else if (strcasecmp(val, "Disable") == 0)
6526 dut->ap_amsdu = 2;
6527 }
6528
6529 val = get_param(cmd, "NumMSDU");
6530 if (val) {
6531 send_resp(dut, conn, SIGMA_ERROR,
6532 "ErrorCode, NumMSDU is not supported yet");
6533 return -1;
6534 }
6535
6536 val = get_param(cmd, "ABFTLRang");
6537 if (val) {
6538 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006539 "ABFTLRang parameter %s", val);
6540 if (strcmp(val, "Gt1") == 0)
6541 abft_len = 2; /* 2 slots in this case */
6542 }
6543
6544 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6545 send_resp(dut, conn, SIGMA_ERROR,
6546 "ErrorCode, Can't set ABFT length");
6547 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006548 }
6549
6550 if (sta_pcp_start(dut, conn, cmd) < 0) {
6551 send_resp(dut, conn, SIGMA_ERROR,
6552 "ErrorCode, Can't start PCP role");
6553 return -1;
6554 }
6555
6556 return sta_set_60g_common(dut, conn, cmd);
6557}
6558
6559
6560static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6561 struct sigma_cmd *cmd)
6562{
6563 const char *val = get_param(cmd, "DiscoveryMode");
6564
6565 if (dut->dev_role != DEVROLE_STA) {
6566 send_resp(dut, conn, SIGMA_INVALID,
6567 "ErrorCode,Invalid DevRole");
6568 return 0;
6569 }
6570
6571 if (val) {
6572 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6573 /* Ignore Discovery mode till Driver expose API. */
6574#if 0
6575 if (strcasecmp(val, "1") == 0) {
6576 send_resp(dut, conn, SIGMA_INVALID,
6577 "ErrorCode,DiscoveryMode 1 not supported");
6578 return 0;
6579 }
6580
6581 if (strcasecmp(val, "0") == 0) {
6582 /* OK */
6583 } else {
6584 send_resp(dut, conn, SIGMA_INVALID,
6585 "ErrorCode,DiscoveryMode not supported");
6586 return 0;
6587 }
6588#endif
6589 }
6590
6591 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006592 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006593 return sta_set_60g_common(dut, conn, cmd);
6594}
6595
6596
Jouni Malinenf7222712019-06-13 01:50:21 +03006597static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6598 struct sigma_conn *conn,
6599 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006600{
6601 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006602 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306603
Jouni Malinened77e672018-01-10 16:45:13 +02006604 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006605 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006606 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306607 wpa_command(intf, "DISCONNECT");
6608 return 1;
6609 }
6610
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006611 disconnect_station(dut);
6612 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6613 * due to cached results. */
6614 wpa_command(intf, "SET ignore_old_scan_res 1");
6615 wpa_command(intf, "BSS_FLUSH");
6616 return 1;
6617}
6618
6619
Jouni Malinenf7222712019-06-13 01:50:21 +03006620static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6621 struct sigma_conn *conn,
6622 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006623{
6624 const char *intf = get_param(cmd, "Interface");
6625 const char *bssid = get_param(cmd, "bssid");
6626 const char *val = get_param(cmd, "CHANNEL");
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006627 const char *freq_val = get_param(cmd, "ChnlFreq");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006628 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306629 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306630 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006631 int res;
6632 int chan = 0;
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006633 int freq = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006634 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306635 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006636 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006637
6638 if (bssid == NULL) {
6639 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6640 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006641 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006642 }
6643
6644 if (val)
6645 chan = atoi(val);
6646
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006647 if (freq_val)
6648 freq = atoi(freq_val);
6649
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006650 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6651 /* The current network may be from sta_associate or
6652 * sta_hs2_associate
6653 */
6654 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6655 0 ||
6656 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006657 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006658 }
6659
6660 ctrl = open_wpa_mon(intf);
6661 if (ctrl == NULL) {
6662 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6663 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006664 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006665 }
6666
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006667 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05306668 sizeof(result)) < 0 ||
6669 strncmp(result, "COMPLETED", 9) != 0) {
6670 sigma_dut_print(dut, DUT_MSG_DEBUG,
6671 "sta_reassoc: Not connected");
6672 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006673 } else if (dut->sta_ft_ds) {
6674 sigma_dut_print(dut, DUT_MSG_DEBUG,
6675 "sta_reassoc: Use FT-over-DS");
6676 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306677 }
6678
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306679 if (dut->rsne_override) {
6680#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006681 if (get_driver_type(dut) == DRIVER_WCN &&
6682 dut->config_rsnie == 0) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05306683 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306684 dut->config_rsnie = 1;
6685 }
6686#endif /* NL80211_SUPPORT */
6687 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6688 dut->rsne_override);
6689 if (wpa_command(intf, buf) < 0) {
6690 send_resp(dut, conn, SIGMA_ERROR,
6691 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6692 return 0;
6693 }
6694 }
6695
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006696 if (ft_ds) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006697 if (chan || freq) {
6698 if (!freq)
6699 freq = channel_to_freq(dut, chan);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006700 if (!freq) {
6701 sigma_dut_print(dut, DUT_MSG_ERROR,
6702 "Invalid channel number provided: %d",
6703 chan);
6704 send_resp(dut, conn, SIGMA_INVALID,
6705 "ErrorCode,Invalid channel number");
6706 goto close_mon_conn;
6707 }
6708 res = snprintf(buf, sizeof(buf),
6709 "SCAN TYPE=ONLY freq=%d", freq);
6710 } else {
6711 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6712 }
6713 if (res < 0 || res >= (int) sizeof(buf)) {
6714 send_resp(dut, conn, SIGMA_ERROR,
6715 "ErrorCode,snprintf failed");
6716 goto close_mon_conn;
6717 }
6718 if (wpa_command(intf, buf) < 0) {
6719 sigma_dut_print(dut, DUT_MSG_INFO,
6720 "Failed to start scan");
6721 send_resp(dut, conn, SIGMA_ERROR,
6722 "ErrorCode,scan failed");
6723 goto close_mon_conn;
6724 }
6725
6726 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6727 buf, sizeof(buf));
6728 if (res < 0) {
6729 sigma_dut_print(dut, DUT_MSG_INFO,
6730 "Scan did not complete");
6731 send_resp(dut, conn, SIGMA_ERROR,
6732 "ErrorCode,scan did not complete");
6733 goto close_mon_conn;
6734 }
6735
6736 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6737 if (res > 0 && res < (int) sizeof(buf))
6738 res = wpa_command(intf, buf);
6739
6740 if (res < 0 || res >= (int) sizeof(buf)) {
6741 send_resp(dut, conn, SIGMA_ERROR,
6742 "errorCode,FT_DS command failed");
6743 status = STATUS_SENT_ERROR;
6744 goto close_mon_conn;
6745 }
6746 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006747 if (chan || freq) {
6748 if (!freq)
6749 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306750 if (!freq) {
6751 sigma_dut_print(dut, DUT_MSG_ERROR,
6752 "Invalid channel number provided: %d",
6753 chan);
6754 send_resp(dut, conn, SIGMA_INVALID,
6755 "ErrorCode,Invalid channel number");
6756 goto close_mon_conn;
6757 }
6758 res = snprintf(buf, sizeof(buf),
6759 "SCAN TYPE=ONLY freq=%d", freq);
6760 } else {
6761 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6762 }
6763 if (res < 0 || res >= (int) sizeof(buf)) {
6764 send_resp(dut, conn, SIGMA_ERROR,
6765 "ErrorCode,snprintf failed");
6766 goto close_mon_conn;
6767 }
6768 if (wpa_command(intf, buf) < 0) {
6769 sigma_dut_print(dut, DUT_MSG_INFO,
6770 "Failed to start scan");
6771 send_resp(dut, conn, SIGMA_ERROR,
6772 "ErrorCode,scan failed");
6773 goto close_mon_conn;
6774 }
6775
6776 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6777 buf, sizeof(buf));
6778 if (res < 0) {
6779 sigma_dut_print(dut, DUT_MSG_INFO,
6780 "Scan did not complete");
6781 send_resp(dut, conn, SIGMA_ERROR,
6782 "ErrorCode,scan did not complete");
6783 goto close_mon_conn;
6784 }
6785
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006786 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6787 < 0) {
6788 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6789 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006790 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306791 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006792 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306793 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006794 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306795 if (res < 0 || res >= (int) sizeof(buf) ||
6796 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006797 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306798 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306799 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006800 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006801 sigma_dut_print(dut, DUT_MSG_INFO,
6802 "sta_reassoc: Run %s successful", buf);
6803 } else if (wpa_command(intf, "REASSOCIATE")) {
6804 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6805 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306806 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006807 }
6808
6809 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6810 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306811 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006812 send_resp(dut, conn, SIGMA_ERROR,
6813 "errorCode,Connection did not complete");
6814 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306815 goto close_mon_conn;
6816 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006817 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006818
Ashwini Patil467efef2017-05-25 12:18:27 +05306819close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006820 wpa_ctrl_detach(ctrl);
6821 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306822 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006823}
6824
6825
6826static void hs2_clear_credentials(const char *intf)
6827{
6828 wpa_command(intf, "REMOVE_CRED all");
6829}
6830
6831
Lior Davidcc88b562017-01-03 18:52:09 +02006832#ifdef __linux__
6833static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6834 unsigned int *aid)
6835{
Lior David0fe101e2017-03-09 16:09:50 +02006836 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006837
Lior David0fe101e2017-03-09 16:09:50 +02006838 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006839}
6840#endif /* __linux__ */
6841
6842
6843static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6844 unsigned int *aid)
6845{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006846 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02006847#ifdef __linux__
6848 case DRIVER_WIL6210:
6849 return wil6210_get_aid(dut, bssid, aid);
6850#endif /* __linux__ */
6851 default:
6852 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6853 return -1;
6854 }
6855}
6856
6857
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006858static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6859 struct sigma_cmd *cmd)
6860{
6861 char buf[MAX_CMD_LEN];
6862 char bss_list[MAX_CMD_LEN];
6863 const char *parameter = get_param(cmd, "Parameter");
6864
6865 if (parameter == NULL)
6866 return -1;
6867
Lior Davidcc88b562017-01-03 18:52:09 +02006868 if (strcasecmp(parameter, "AID") == 0) {
6869 unsigned int aid = 0;
6870 char bssid[20];
6871
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006872 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02006873 bssid, sizeof(bssid)) < 0) {
6874 sigma_dut_print(dut, DUT_MSG_ERROR,
6875 "could not get bssid");
6876 return -2;
6877 }
6878
6879 if (sta_get_aid_60g(dut, bssid, &aid))
6880 return -2;
6881
6882 snprintf(buf, sizeof(buf), "aid,%d", aid);
6883 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6884 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6885 return 0;
6886 }
6887
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006888 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6889 char *bss_line;
6890 char *bss_id = NULL;
6891 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306892 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006893
6894 if (ifname == NULL) {
6895 sigma_dut_print(dut, DUT_MSG_INFO,
6896 "For get DiscoveredDevList need Interface name.");
6897 return -1;
6898 }
6899
6900 /*
6901 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6902 * of BSSIDs in "bssid=<BSSID>\n"
6903 */
6904 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6905 bss_list,
6906 sizeof(bss_list)) < 0) {
6907 sigma_dut_print(dut, DUT_MSG_ERROR,
6908 "Failed to get bss list");
6909 return -1;
6910 }
6911
6912 sigma_dut_print(dut, DUT_MSG_DEBUG,
6913 "bss list for ifname:%s is:%s",
6914 ifname, bss_list);
6915
6916 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306917 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006918 while (bss_line) {
6919 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6920 bss_id) {
6921 int len;
6922
6923 len = snprintf(buf + strlen(buf),
6924 sizeof(buf) - strlen(buf),
6925 ",%s", bss_id);
6926 free(bss_id);
6927 bss_id = NULL;
6928 if (len < 0) {
6929 sigma_dut_print(dut,
6930 DUT_MSG_ERROR,
6931 "Failed to read BSSID");
6932 send_resp(dut, conn, SIGMA_ERROR,
6933 "ErrorCode,Failed to read BSS ID");
6934 return 0;
6935 }
6936
6937 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6938 sigma_dut_print(dut,
6939 DUT_MSG_ERROR,
6940 "Response buf too small for list");
6941 send_resp(dut, conn,
6942 SIGMA_ERROR,
6943 "ErrorCode,Response buf too small for list");
6944 return 0;
6945 }
6946 }
6947
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306948 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006949 }
6950
6951 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6952 buf);
6953 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6954 return 0;
6955 }
6956
6957 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6958 return 0;
6959}
6960
6961
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006962static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6963 struct sigma_cmd *cmd)
6964{
6965 char buf[MAX_CMD_LEN];
6966 const char *parameter = get_param(cmd, "Parameter");
6967
6968 if (!parameter)
6969 return -1;
6970
6971 if (strcasecmp(parameter, "RSSI") == 0) {
6972 char rssi[10];
6973
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006974 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006975 rssi, sizeof(rssi)) < 0) {
6976 sigma_dut_print(dut, DUT_MSG_ERROR,
6977 "Could not get RSSI");
6978 return -2;
6979 }
6980
6981 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6982 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6983 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6984 return 0;
6985 }
6986
6987 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6988 return 0;
6989}
6990
6991
Jouni Malinenca0abd32020-02-09 20:18:10 +02006992static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
6993 struct sigma_conn *conn,
6994 struct sigma_cmd *cmd)
6995{
6996 const char *intf = get_param(cmd, "Interface");
6997 char buf[4096], bssid[20], resp[200], *pos, *tmp;
6998
6999 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
7000 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
7001 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
7002 send_resp(dut, conn, SIGMA_ERROR,
7003 "ErrorCode,PMKSA_GET not supported");
7004 return STATUS_SENT_ERROR;
7005 }
7006
7007 if (strncmp(buf, "FAIL", 4) == 0 ||
7008 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
7009 send_resp(dut, conn, SIGMA_ERROR,
7010 "ErrorCode,Could not find current network");
7011 return STATUS_SENT_ERROR;
7012 }
7013
7014 pos = buf;
7015 while (pos) {
7016 if (strncmp(pos, bssid, 17) == 0) {
7017 pos = strchr(pos, ' ');
7018 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307019 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007020 pos++;
7021 pos = strchr(pos, ' ');
7022 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307023 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007024 pos++;
7025 tmp = strchr(pos, ' ');
7026 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307027 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007028 *tmp = '\0';
7029 break;
7030 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02007031 pos = strchr(pos, '\n');
7032 if (pos)
7033 pos++;
7034 }
7035
7036 if (!pos) {
7037 send_resp(dut, conn, SIGMA_ERROR,
7038 "ErrorCode,PMK not available");
7039 return STATUS_SENT_ERROR;
7040 }
7041
7042 snprintf(resp, sizeof(resp), "PMK,%s", pos);
7043 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7044 return STATUS_SENT;
7045}
7046
7047
Jouni Malinenf7222712019-06-13 01:50:21 +03007048static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
7049 struct sigma_conn *conn,
7050 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007051{
7052 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02007053 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007054
Jouni Malinenca0abd32020-02-09 20:18:10 +02007055 if (!parameter)
7056 return INVALID_SEND_STATUS;
7057
7058 if (strcasecmp(parameter, "PMK") == 0)
7059 return sta_get_pmk(dut, conn, cmd);
7060
7061 if (!program)
7062 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007063
7064 if (strcasecmp(program, "P2PNFC") == 0)
7065 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
7066
7067 if (strcasecmp(program, "60ghz") == 0)
7068 return sta_get_parameter_60g(dut, conn, cmd);
7069
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007070 if (strcasecmp(program, "he") == 0)
7071 return sta_get_parameter_he(dut, conn, cmd);
7072
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007073#ifdef ANDROID_NAN
7074 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07007075 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007076#endif /* ANDROID_NAN */
7077
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007078#ifdef MIRACAST
7079 if (strcasecmp(program, "WFD") == 0 ||
7080 strcasecmp(program, "DisplayR2") == 0)
7081 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
7082#endif /* MIRACAST */
7083
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007084 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7085 return 0;
7086}
7087
7088
7089static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
7090 const char *type)
7091{
7092 char buf[100];
7093
7094 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007095 run_iwpriv(dut, intf, "chwidth 2");
7096 run_iwpriv(dut, intf, "mode 11ACVHT80");
7097 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007098 }
7099
7100 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007101 run_iwpriv(dut, intf, "chwidth 0");
7102 run_iwpriv(dut, intf, "mode 11naht40");
7103 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007104 }
7105
7106 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007107 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007108
7109 /* Reset CTS width */
7110 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
7111 intf);
7112 if (system(buf) != 0) {
7113 sigma_dut_print(dut, DUT_MSG_ERROR,
7114 "wifitool %s beeliner_fw_test 54 0 failed",
7115 intf);
7116 }
7117
7118 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007119 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007120
7121 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
7122 if (system(buf) != 0) {
7123 sigma_dut_print(dut, DUT_MSG_ERROR,
7124 "iwpriv rts failed");
7125 }
7126 }
7127
7128 if (type && strcasecmp(type, "Testbed") == 0) {
7129 dut->testbed_flag_txsp = 1;
7130 dut->testbed_flag_rxsp = 1;
7131 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007132 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007133
7134 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007135 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007136
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007137 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007138
7139 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007140 run_iwpriv(dut, intf, "tx_stbc 0");
7141 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007142
7143 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007144 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007145 }
7146
7147 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007148 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07007149 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007150
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007151 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007152 }
7153}
7154
7155
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007156#ifdef NL80211_SUPPORT
7157static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
7158 enum he_mcs_config mcs)
7159{
7160 struct nl_msg *msg;
7161 int ret = 0;
7162 struct nlattr *params;
7163 int ifindex;
7164
7165 ifindex = if_nametoindex(intf);
7166 if (ifindex == 0) {
7167 sigma_dut_print(dut, DUT_MSG_ERROR,
7168 "%s: Index for interface %s failed",
7169 __func__, intf);
7170 return -1;
7171 }
7172
7173 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7174 NL80211_CMD_VENDOR)) ||
7175 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7176 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7177 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7178 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7179 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7180 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
7181 mcs)) {
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}
7198#endif /* NL80211_SUPPORT */
7199
7200
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007201static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
7202 const char *intf, int enable)
7203{
7204#ifdef NL80211_SUPPORT
7205 struct nl_msg *msg;
7206 int ret = 0;
7207 struct nlattr *params;
7208 int ifindex;
7209
7210 ifindex = if_nametoindex(intf);
7211 if (ifindex == 0) {
7212 sigma_dut_print(dut, DUT_MSG_ERROR,
7213 "%s: Index for interface %s failed",
7214 __func__, intf);
7215 return -1;
7216 }
7217
7218 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7219 NL80211_CMD_VENDOR)) ||
7220 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7221 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7222 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7223 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7224 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7225 nla_put_u8(msg,
7226 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
7227 enable)) {
7228 sigma_dut_print(dut, DUT_MSG_ERROR,
7229 "%s: err in adding vendor_cmd and vendor_data",
7230 __func__);
7231 nlmsg_free(msg);
7232 return -1;
7233 }
7234 nla_nest_end(msg, params);
7235
7236 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7237 if (ret) {
7238 sigma_dut_print(dut, DUT_MSG_ERROR,
7239 "%s: err in send_and_recv_msgs, ret=%d",
7240 __func__, ret);
7241 }
7242 return ret;
7243#else /* NL80211_SUPPORT */
7244 sigma_dut_print(dut, DUT_MSG_ERROR,
7245 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
7246 return -1;
7247#endif /* NL80211_SUPPORT */
7248}
7249
7250
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007251static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
7252 const char *intf, int enable)
7253{
7254#ifdef NL80211_SUPPORT
7255 struct nl_msg *msg;
7256 int ret = 0;
7257 struct nlattr *params;
7258 int ifindex;
7259
7260 ifindex = if_nametoindex(intf);
7261 if (ifindex == 0) {
7262 sigma_dut_print(dut, DUT_MSG_ERROR,
7263 "%s: Index for interface %s failed",
7264 __func__, intf);
7265 return -1;
7266 }
7267
7268 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7269 NL80211_CMD_VENDOR)) ||
7270 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7271 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7272 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7273 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7274 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7275 nla_put_u8(msg,
7276 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7277 enable)) {
7278 sigma_dut_print(dut, DUT_MSG_ERROR,
7279 "%s: err in adding vendor_cmd and vendor_data",
7280 __func__);
7281 nlmsg_free(msg);
7282 return -1;
7283 }
7284 nla_nest_end(msg, params);
7285
7286 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7287 if (ret) {
7288 sigma_dut_print(dut, DUT_MSG_ERROR,
7289 "%s: err in send_and_recv_msgs, ret=%d",
7290 __func__, ret);
7291 }
7292 return ret;
7293#else /* NL80211_SUPPORT */
7294 sigma_dut_print(dut, DUT_MSG_ERROR,
7295 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7296 return -1;
7297#endif /* NL80211_SUPPORT */
7298}
7299
7300
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007301#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007302
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007303static int sta_set_he_testbed_def(struct sigma_dut *dut,
7304 const char *intf, int cfg)
7305{
7306 struct nl_msg *msg;
7307 int ret = 0;
7308 struct nlattr *params;
7309 int ifindex;
7310
7311 ifindex = if_nametoindex(intf);
7312 if (ifindex == 0) {
7313 sigma_dut_print(dut, DUT_MSG_ERROR,
7314 "%s: Index for interface %s failed",
7315 __func__, intf);
7316 return -1;
7317 }
7318
7319 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7320 NL80211_CMD_VENDOR)) ||
7321 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7322 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7323 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7324 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7325 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7326 nla_put_u8(msg,
7327 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7328 cfg)) {
7329 sigma_dut_print(dut, DUT_MSG_ERROR,
7330 "%s: err in adding vendor_cmd and vendor_data",
7331 __func__);
7332 nlmsg_free(msg);
7333 return -1;
7334 }
7335 nla_nest_end(msg, params);
7336
7337 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7338 if (ret) {
7339 sigma_dut_print(dut, DUT_MSG_ERROR,
7340 "%s: err in send_and_recv_msgs, ret=%d",
7341 __func__, ret);
7342 }
7343 return ret;
7344}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007345
7346
7347static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7348{
7349 struct nl_msg *msg;
7350 int ret = 0;
7351 struct nlattr *params;
7352 int ifindex;
7353
7354 ifindex = if_nametoindex(intf);
7355 if (ifindex == 0) {
7356 sigma_dut_print(dut, DUT_MSG_ERROR,
7357 "%s: Index for interface %s failed",
7358 __func__, intf);
7359 return -1;
7360 }
7361
7362 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7363 NL80211_CMD_VENDOR)) ||
7364 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7365 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7366 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7367 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7368 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7369 nla_put_u8(msg,
7370 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7371 cfg)) {
7372 sigma_dut_print(dut, DUT_MSG_ERROR,
7373 "%s: err in adding vendor_cmd and vendor_data",
7374 __func__);
7375 nlmsg_free(msg);
7376 return -1;
7377 }
7378 nla_nest_end(msg, params);
7379
7380 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7381 if (ret) {
7382 sigma_dut_print(dut, DUT_MSG_ERROR,
7383 "%s: err in send_and_recv_msgs, ret=%d",
7384 __func__, ret);
7385 }
7386 return ret;
7387}
7388
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007389#endif /* NL80211_SUPPORT */
7390
7391
Qiwei Caib6806972020-01-15 13:52:11 +08007392int sta_set_addba_buf_size(struct sigma_dut *dut,
7393 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007394{
7395#ifdef NL80211_SUPPORT
7396 struct nl_msg *msg;
7397 int ret = 0;
7398 struct nlattr *params;
7399 int ifindex;
7400
7401 ifindex = if_nametoindex(intf);
7402 if (ifindex == 0) {
7403 sigma_dut_print(dut, DUT_MSG_ERROR,
7404 "%s: Index for interface %s failed",
7405 __func__, intf);
7406 return -1;
7407 }
7408
7409 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7410 NL80211_CMD_VENDOR)) ||
7411 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7412 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7413 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7414 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7415 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07007416 nla_put_u16(msg,
7417 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
7418 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007419 sigma_dut_print(dut, DUT_MSG_ERROR,
7420 "%s: err in adding vendor_cmd and vendor_data",
7421 __func__);
7422 nlmsg_free(msg);
7423 return -1;
7424 }
7425 nla_nest_end(msg, params);
7426
7427 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7428 if (ret) {
7429 sigma_dut_print(dut, DUT_MSG_ERROR,
7430 "%s: err in send_and_recv_msgs, ret=%d",
7431 __func__, ret);
7432 }
7433 return ret;
7434#else /* NL80211_SUPPORT */
7435 sigma_dut_print(dut, DUT_MSG_ERROR,
7436 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7437 return -1;
7438#endif /* NL80211_SUPPORT */
7439}
7440
7441
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007442static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
7443 int enable)
7444{
7445#ifdef NL80211_SUPPORT
7446 struct nl_msg *msg;
7447 int ret = 0;
7448 struct nlattr *params;
7449 int ifindex;
7450
7451 ifindex = if_nametoindex(intf);
7452 if (ifindex == 0) {
7453 sigma_dut_print(dut, DUT_MSG_ERROR,
7454 "%s: Index for interface %s failed",
7455 __func__, intf);
7456 return -1;
7457 }
7458
7459 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7460 NL80211_CMD_VENDOR)) ||
7461 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7462 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7463 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7464 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7465 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7466 nla_put_u8(msg,
7467 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7468 enable)) {
7469 sigma_dut_print(dut, DUT_MSG_ERROR,
7470 "%s: err in adding vendor_cmd and vendor_data",
7471 __func__);
7472 nlmsg_free(msg);
7473 return -1;
7474 }
7475 nla_nest_end(msg, params);
7476
7477 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7478 if (ret) {
7479 sigma_dut_print(dut, DUT_MSG_ERROR,
7480 "%s: err in send_and_recv_msgs, ret=%d",
7481 __func__, ret);
7482 }
7483 return ret;
7484#else /* NL80211_SUPPORT */
7485 sigma_dut_print(dut, DUT_MSG_ERROR,
7486 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7487 return -1;
7488#endif /* NL80211_SUPPORT */
7489}
7490
7491
Arif Hussain9765f7d2018-07-03 08:28:26 -07007492static int sta_set_beamformee_sts(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_BEAMFORMEE_NSTS,
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 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7537 return -1;
7538#endif /* NL80211_SUPPORT */
7539}
7540
7541
Arif Hussain68d23f52018-07-11 13:39:08 -07007542#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007543static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7544 enum qca_wlan_he_mac_padding_dur val)
7545{
Arif Hussain68d23f52018-07-11 13:39:08 -07007546 struct nl_msg *msg;
7547 int ret = 0;
7548 struct nlattr *params;
7549 int ifindex;
7550
7551 ifindex = if_nametoindex(intf);
7552 if (ifindex == 0) {
7553 sigma_dut_print(dut, DUT_MSG_ERROR,
7554 "%s: Index for interface %s failed, val:%d",
7555 __func__, intf, val);
7556 return -1;
7557 }
7558
7559 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7560 NL80211_CMD_VENDOR)) ||
7561 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7562 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7563 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7564 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7565 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7566 nla_put_u8(msg,
7567 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
7568 val)) {
7569 sigma_dut_print(dut, DUT_MSG_ERROR,
7570 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7571 __func__, val);
7572 nlmsg_free(msg);
7573 return -1;
7574 }
7575 nla_nest_end(msg, params);
7576
7577 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7578 if (ret) {
7579 sigma_dut_print(dut, DUT_MSG_ERROR,
7580 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7581 __func__, ret, val);
7582 }
7583 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07007584}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007585#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007586
7587
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007588static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7589 int val)
7590{
7591#ifdef NL80211_SUPPORT
7592 struct nl_msg *msg;
7593 int ret = 0;
7594 struct nlattr *params;
7595 int ifindex;
7596
7597 ifindex = if_nametoindex(intf);
7598 if (ifindex == 0) {
7599 sigma_dut_print(dut, DUT_MSG_ERROR,
7600 "%s: Index for interface %s failed, val:%d",
7601 __func__, intf, val);
7602 return -1;
7603 }
7604
7605 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7606 NL80211_CMD_VENDOR)) ||
7607 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7608 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7609 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7610 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7611 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7612 nla_put_u8(msg,
7613 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7614 val)) {
7615 sigma_dut_print(dut, DUT_MSG_ERROR,
7616 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7617 __func__, val);
7618 nlmsg_free(msg);
7619 return -1;
7620 }
7621 nla_nest_end(msg, params);
7622
7623 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7624 if (ret) {
7625 sigma_dut_print(dut, DUT_MSG_ERROR,
7626 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7627 __func__, ret, val);
7628 }
7629 return ret;
7630#else /* NL80211_SUPPORT */
7631 sigma_dut_print(dut, DUT_MSG_ERROR,
7632 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7633 return -1;
7634#endif /* NL80211_SUPPORT */
7635}
7636
7637
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007638#ifdef NL80211_SUPPORT
7639static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7640{
7641 struct nl_msg *msg;
7642 int ret = 0;
7643 struct nlattr *params;
7644 int ifindex;
7645
7646 ifindex = if_nametoindex(intf);
7647 if (ifindex == 0) {
7648 sigma_dut_print(dut, DUT_MSG_ERROR,
7649 "%s: Index for interface %s failed",
7650 __func__, intf);
7651 return -1;
7652 }
7653
7654 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7655 NL80211_CMD_VENDOR)) ||
7656 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7657 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7658 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7659 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7660 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7661 nla_put_flag(msg,
7662 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
7663 sigma_dut_print(dut, DUT_MSG_ERROR,
7664 "%s: err in adding vendor_cmd and vendor_data",
7665 __func__);
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",
7675 __func__, ret);
7676 }
7677 return ret;
7678}
7679#endif /* NL80211_SUPPORT */
7680
7681
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007682static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7683 int val)
7684{
7685#ifdef NL80211_SUPPORT
7686 struct nl_msg *msg;
7687 int ret = 0;
7688 struct nlattr *params;
7689 int ifindex;
7690
7691 ifindex = if_nametoindex(intf);
7692 if (ifindex == 0) {
7693 sigma_dut_print(dut, DUT_MSG_ERROR,
7694 "%s: Index for interface %s failed, val:%d",
7695 __func__, intf, val);
7696 return -1;
7697 }
7698
7699 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7700 NL80211_CMD_VENDOR)) ||
7701 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7702 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7703 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7704 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7705 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7706 nla_put_u8(msg,
7707 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
7708 val)) {
7709 sigma_dut_print(dut, DUT_MSG_ERROR,
7710 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7711 __func__, val);
7712 nlmsg_free(msg);
7713 return -1;
7714 }
7715 nla_nest_end(msg, params);
7716
7717 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7718 if (ret) {
7719 sigma_dut_print(dut, DUT_MSG_ERROR,
7720 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7721 __func__, ret, val);
7722 }
7723 return ret;
7724#else /* NL80211_SUPPORT */
7725 sigma_dut_print(dut, DUT_MSG_ERROR,
7726 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7727 return -1;
7728#endif /* NL80211_SUPPORT */
7729}
7730
7731
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007732static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7733 int val)
7734{
7735#ifdef NL80211_SUPPORT
7736 struct nl_msg *msg;
7737 int ret = 0;
7738 struct nlattr *params;
7739 int ifindex;
7740
7741 ifindex = if_nametoindex(intf);
7742 if (ifindex == 0) {
7743 sigma_dut_print(dut, DUT_MSG_ERROR,
7744 "%s: Index for interface %s failed, val:%d",
7745 __func__, intf, val);
7746 return -1;
7747 }
7748
7749 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7750 NL80211_CMD_VENDOR)) ||
7751 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7752 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7753 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7754 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7755 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7756 nla_put_u8(msg,
7757 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
7758 val)) {
7759 sigma_dut_print(dut, DUT_MSG_ERROR,
7760 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7761 __func__, val);
7762 nlmsg_free(msg);
7763 return -1;
7764 }
7765 nla_nest_end(msg, params);
7766
7767 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7768 if (ret) {
7769 sigma_dut_print(dut, DUT_MSG_ERROR,
7770 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7771 __func__, ret, val);
7772 }
7773 return ret;
7774#else /* NL80211_SUPPORT */
7775 sigma_dut_print(dut, DUT_MSG_ERROR,
7776 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7777 return -1;
7778#endif /* NL80211_SUPPORT */
7779}
7780
7781
Arif Hussain480d5f42019-03-12 14:40:42 -07007782static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7783 int val)
7784{
7785#ifdef NL80211_SUPPORT
7786 struct nl_msg *msg;
7787 int ret;
7788 struct nlattr *params;
7789 int ifindex;
7790
7791 ifindex = if_nametoindex(intf);
7792 if (ifindex == 0) {
7793 sigma_dut_print(dut, DUT_MSG_ERROR,
7794 "%s: Index for interface %s failed, val:%d",
7795 __func__, intf, val);
7796 return -1;
7797 }
7798
7799 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7800 NL80211_CMD_VENDOR)) ||
7801 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7802 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7803 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7804 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7805 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7806 nla_put_u8(msg,
7807 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT,
7808 val)) {
7809 sigma_dut_print(dut, DUT_MSG_ERROR,
7810 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7811 __func__, val);
7812 nlmsg_free(msg);
7813 return -1;
7814 }
7815 nla_nest_end(msg, params);
7816
7817 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7818 if (ret) {
7819 sigma_dut_print(dut, DUT_MSG_ERROR,
7820 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7821 __func__, ret, val);
7822 }
7823 return ret;
7824#else /* NL80211_SUPPORT */
7825 sigma_dut_print(dut, DUT_MSG_ERROR,
7826 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7827 return -1;
7828#endif /* NL80211_SUPPORT */
7829}
7830
7831
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007832static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7833 const char *type)
7834{
7835 char buf[60];
7836
7837 if (dut->program == PROGRAM_HE) {
7838 /* resetting phymode to auto in case of HE program */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05307839 sta_set_phymode(dut, intf, "auto");
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007840
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007841 /* reset the rate to Auto rate */
7842 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7843 intf);
7844 if (system(buf) != 0) {
7845 sigma_dut_print(dut, DUT_MSG_ERROR,
7846 "iwpriv %s set_11ax_rate 0xff failed",
7847 intf);
7848 }
7849
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007850 /* reset the LDPC setting */
7851 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7852 if (system(buf) != 0) {
7853 sigma_dut_print(dut, DUT_MSG_ERROR,
7854 "iwpriv %s ldpc 1 failed", intf);
7855 }
7856
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007857 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05307858 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007859
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007860 /* remove all network profiles */
7861 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007862
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007863 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7864 sta_set_addba_buf_size(dut, intf, 64);
7865
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007866#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007867 /* Reset the device HE capabilities to its default supported
7868 * configuration. */
7869 sta_set_he_testbed_def(dut, intf, 0);
7870
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007871 /* Disable noackpolicy for all AC */
7872 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7873 sigma_dut_print(dut, DUT_MSG_ERROR,
7874 "Disable of noackpolicy for all AC failed");
7875 }
7876#endif /* NL80211_SUPPORT */
7877
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007878 /* Enable WMM by default */
7879 if (wcn_sta_set_wmm(dut, intf, "on")) {
7880 sigma_dut_print(dut, DUT_MSG_ERROR,
7881 "Enable of WMM in sta_reset_default_wcn failed");
7882 }
7883
7884 /* Disable ADDBA_REJECT by default */
7885 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7886 sigma_dut_print(dut, DUT_MSG_ERROR,
7887 "Disable of addba_reject in sta_reset_default_wcn failed");
7888 }
7889
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007890 /* Enable sending of ADDBA by default */
7891 if (nlvendor_config_send_addba(dut, intf, 1)) {
7892 sigma_dut_print(dut, DUT_MSG_ERROR,
7893 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7894 }
7895
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007896 /* Enable AMPDU by default */
7897 iwpriv_sta_set_ampdu(dut, intf, 1);
7898
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007899#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08007900 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007901 sigma_dut_print(dut, DUT_MSG_ERROR,
7902 "Set LTF config to default in sta_reset_default_wcn failed");
7903 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007904
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007905 /* set the beamformee NSTS(maximum number of
7906 * space-time streams) to default DUT config
7907 */
7908 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007909 sigma_dut_print(dut, DUT_MSG_ERROR,
7910 "Failed to set BeamformeeSTS");
7911 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007912
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007913 if (sta_set_mac_padding_duration(
7914 dut, intf,
7915 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007916 sigma_dut_print(dut, DUT_MSG_ERROR,
7917 "Failed to set MAC padding duration");
7918 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007919
7920 if (sta_set_mu_edca_override(dut, intf, 0)) {
7921 sigma_dut_print(dut, DUT_MSG_ERROR,
7922 "ErrorCode,Failed to set MU EDCA override disable");
7923 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007924
7925 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7926 sigma_dut_print(dut, DUT_MSG_ERROR,
7927 "Failed to set OM ctrl supp");
7928 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007929
7930 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7931 sigma_dut_print(dut, DUT_MSG_ERROR,
7932 "Failed to set Tx SU PPDU enable");
7933 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007934
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007935 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7936 sigma_dut_print(dut, DUT_MSG_ERROR,
7937 "failed to send TB PPDU Tx cfg");
7938 }
7939
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007940 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7941 sigma_dut_print(dut, DUT_MSG_ERROR,
7942 "Failed to set OM ctrl reset");
7943 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007944
7945 /* +HTC-HE support default on */
7946 if (sta_set_he_htc_supp(dut, intf, 1)) {
7947 sigma_dut_print(dut, DUT_MSG_ERROR,
7948 "Setting of +HTC-HE support failed");
7949 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007950#endif /* NL80211_SUPPORT */
7951
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007952 if (sta_set_tx_beamformee(dut, intf, 1)) {
7953 sigma_dut_print(dut, DUT_MSG_ERROR,
7954 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7955 }
7956
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007957 wpa_command(intf, "SET oce 1");
7958
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007959 /* Set nss to 1 and MCS 0-7 in case of testbed */
7960 if (type && strcasecmp(type, "Testbed") == 0) {
7961#ifdef NL80211_SUPPORT
7962 int ret;
7963#endif /* NL80211_SUPPORT */
7964
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007965 wpa_command(intf, "SET oce 0");
7966
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007967 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7968 if (system(buf) != 0) {
7969 sigma_dut_print(dut, DUT_MSG_ERROR,
7970 "iwpriv %s nss failed", intf);
7971 }
7972
7973#ifdef NL80211_SUPPORT
7974 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7975 if (ret) {
7976 sigma_dut_print(dut, DUT_MSG_ERROR,
7977 "Setting of MCS failed, ret:%d",
7978 ret);
7979 }
7980#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007981
7982 /* Disable STBC as default */
7983 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007984
7985 /* Disable AMSDU as default */
7986 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007987
7988#ifdef NL80211_SUPPORT
7989 /* HE fragmentation default off */
7990 if (sta_set_he_fragmentation(dut, intf,
7991 HE_FRAG_DISABLE)) {
7992 sigma_dut_print(dut, DUT_MSG_ERROR,
7993 "Setting of HE fragmentation failed");
7994 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007995
7996 /* set the beamformee NSTS(maximum number of
7997 * space-time streams) to default testbed config
7998 */
7999 if (sta_set_beamformee_sts(dut, intf, 3)) {
8000 sigma_dut_print(dut, DUT_MSG_ERROR,
8001 "Failed to set BeamformeeSTS");
8002 }
8003
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08008004 /* +HTC-HE support default off */
8005 if (sta_set_he_htc_supp(dut, intf, 0)) {
8006 sigma_dut_print(dut, DUT_MSG_ERROR,
8007 "Setting of +HTC-HE support failed");
8008 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008009
8010 /* Set device HE capabilities to testbed default
8011 * configuration. */
8012 if (sta_set_he_testbed_def(dut, intf, 1)) {
8013 sigma_dut_print(dut, DUT_MSG_DEBUG,
8014 "Failed to set HE defaults");
8015 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08008016
8017 /* Disable VHT support in 2.4 GHz for testbed */
8018 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08008019#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08008020
8021 /* Enable WEP/TKIP with HE capability in testbed */
8022 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
8023 sigma_dut_print(dut, DUT_MSG_ERROR,
8024 "Enabling HE config with WEP/TKIP failed");
8025 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008026 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008027
8028 /* Defaults in case of DUT */
8029 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07008030 /* Enable STBC by default */
8031 wcn_sta_set_stbc(dut, intf, "1");
8032
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008033 /* set nss to 2 */
8034 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
8035 if (system(buf) != 0) {
8036 sigma_dut_print(dut, DUT_MSG_ERROR,
8037 "iwpriv %s nss 2 failed", intf);
8038 }
Arif Hussainac6c5112018-05-25 17:34:00 -07008039 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008040
8041#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07008042 /* Set HE_MCS to 0-11 */
8043 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008044 sigma_dut_print(dut, DUT_MSG_ERROR,
8045 "Setting of MCS failed");
8046 }
8047#endif /* NL80211_SUPPORT */
8048
8049 /* Disable WEP/TKIP with HE capability in DUT */
8050 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
8051 sigma_dut_print(dut, DUT_MSG_ERROR,
8052 "Enabling HE config with WEP/TKIP failed");
8053 }
8054 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008055 }
8056}
8057
8058
Jouni Malinenf7222712019-06-13 01:50:21 +03008059static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
8060 struct sigma_conn *conn,
8061 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008062{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008063 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008064 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008065 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008066 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308067 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008068
Jouni Malinenb21f0542019-11-04 17:53:38 +02008069 if (dut->station_ifname_2g &&
8070 strcmp(dut->station_ifname_2g, intf) == 0)
8071 dut->use_5g = 0;
8072 else if (dut->station_ifname_5g &&
8073 strcmp(dut->station_ifname_5g, intf) == 0)
8074 dut->use_5g = 1;
8075
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008076 if (!program)
8077 program = get_param(cmd, "prog");
8078 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008079 dut->device_type = STA_unknown;
8080 type = get_param(cmd, "type");
8081 if (type && strcasecmp(type, "Testbed") == 0)
8082 dut->device_type = STA_testbed;
8083 if (type && strcasecmp(type, "DUT") == 0)
8084 dut->device_type = STA_dut;
8085
8086 if (dut->program == PROGRAM_TDLS) {
8087 /* Clear TDLS testing mode */
8088 wpa_command(intf, "SET tdls_disabled 0");
8089 wpa_command(intf, "SET tdls_testing 0");
8090 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008091 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05308092 /* Enable the WCN driver in TDLS Explicit trigger mode
8093 */
8094 wpa_command(intf, "SET tdls_external_control 0");
8095 wpa_command(intf, "SET tdls_trigger_control 0");
8096 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008097 }
8098
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008099#ifdef MIRACAST
8100 if (dut->program == PROGRAM_WFD ||
8101 dut->program == PROGRAM_DISPLAYR2)
8102 miracast_sta_reset_default(dut, conn, cmd);
8103#endif /* MIRACAST */
8104
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008105 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008106 case DRIVER_ATHEROS:
8107 sta_reset_default_ath(dut, intf, type);
8108 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008109 case DRIVER_WCN:
8110 sta_reset_default_wcn(dut, intf, type);
8111 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008112 default:
8113 break;
8114 }
8115
8116#ifdef ANDROID_NAN
8117 if (dut->program == PROGRAM_NAN)
8118 nan_cmd_sta_reset_default(dut, conn, cmd);
8119#endif /* ANDROID_NAN */
8120
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05308121 if (dut->program == PROGRAM_LOC &&
8122 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
8123 return ERROR_SEND_STATUS;
8124
Jouni Malinenba630452018-06-22 11:49:59 +03008125 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008126 unlink("SP/wi-fi.org/pps.xml");
8127 if (system("rm -r SP/*") != 0) {
8128 }
8129 unlink("next-client-cert.pem");
8130 unlink("next-client-key.pem");
8131 }
8132
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008133 /* For WPS program of the 60 GHz band the band type needs to be saved */
8134 if (dut->program == PROGRAM_WPS) {
8135 if (band && strcasecmp(band, "60GHz") == 0) {
8136 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008137 /* For 60 GHz enable WPS for WPS TCs */
8138 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008139 } else {
8140 dut->band = WPS_BAND_NON_60G;
8141 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008142 } else if (dut->program == PROGRAM_60GHZ) {
8143 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
8144 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008145 }
8146
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02008147 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008148 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008149 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008150
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008151 sigma_dut_print(dut, DUT_MSG_INFO,
8152 "WPS 60 GHz program, wps_disable = %d",
8153 dut->wps_disable);
8154
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008155 if (!dev_role) {
8156 send_resp(dut, conn, SIGMA_ERROR,
8157 "errorCode,Missing DevRole argument");
8158 return 0;
8159 }
8160
8161 if (strcasecmp(dev_role, "STA") == 0)
8162 dut->dev_role = DEVROLE_STA;
8163 else if (strcasecmp(dev_role, "PCP") == 0)
8164 dut->dev_role = DEVROLE_PCP;
8165 else {
8166 send_resp(dut, conn, SIGMA_ERROR,
8167 "errorCode,Unknown DevRole");
8168 return 0;
8169 }
8170
8171 if (dut->device_type == STA_unknown) {
8172 sigma_dut_print(dut, DUT_MSG_ERROR,
8173 "Device type is not STA testbed or DUT");
8174 send_resp(dut, conn, SIGMA_ERROR,
8175 "errorCode,Unknown device type");
8176 return 0;
8177 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008178
8179 sigma_dut_print(dut, DUT_MSG_DEBUG,
8180 "Setting msdu_size to MAX: 7912");
8181 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008182 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008183
8184 if (system(buf) != 0) {
8185 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
8186 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008187 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008188 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008189
8190 if (sta_set_force_mcs(dut, 0, 1)) {
8191 sigma_dut_print(dut, DUT_MSG_ERROR,
8192 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008193 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008194 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008195 }
8196
8197 wpa_command(intf, "WPS_ER_STOP");
8198 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05308199 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008200 wpa_command(intf, "SET radio_disabled 0");
8201
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02008202 dut->wps_forced_version = 0;
8203
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008204 if (dut->wsc_fragment) {
8205 dut->wsc_fragment = 0;
8206 wpa_command(intf, "SET device_name Test client");
8207 wpa_command(intf, "SET manufacturer ");
8208 wpa_command(intf, "SET model_name ");
8209 wpa_command(intf, "SET model_number ");
8210 wpa_command(intf, "SET serial_number ");
8211 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02008212 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
8213 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
8214 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
8215 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008216
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008217 if (dut->tmp_mac_addr && dut->set_macaddr) {
8218 dut->tmp_mac_addr = 0;
8219 if (system(dut->set_macaddr) != 0) {
8220 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
8221 "temporary MAC address");
8222 }
8223 }
8224
8225 set_ps(intf, dut, 0);
8226
Jouni Malinenba630452018-06-22 11:49:59 +03008227 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
8228 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008229 wpa_command(intf, "SET interworking 1");
8230 wpa_command(intf, "SET hs20 1");
8231 }
8232
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008233 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03008234 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008235 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008236 wpa_command(intf, "SET pmf 1");
8237 } else {
8238 wpa_command(intf, "SET pmf 0");
8239 }
8240
8241 hs2_clear_credentials(intf);
8242 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
8243 wpa_command(intf, "SET access_network_type 15");
8244
8245 static_ip_file(0, NULL, NULL, NULL);
8246 kill_dhcp_client(dut, intf);
8247 clear_ip_addr(dut, intf);
8248
8249 dut->er_oper_performed = 0;
8250 dut->er_oper_bssid[0] = '\0';
8251
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008252 if (dut->program == PROGRAM_LOC) {
8253 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008254 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008255 }
8256
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07008257 if (dut->program == PROGRAM_MBO || dut->program == PROGRAM_HE) {
Ashwini Patil00402582017-04-13 12:29:39 +05308258 free(dut->non_pref_ch_list);
8259 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05308260 free(dut->btm_query_cand_list);
8261 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05308262 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05308263 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05308264 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05308265 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05308266 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05308267 }
8268
Jouni Malinen3c367e82017-06-23 17:01:47 +03008269 free(dut->rsne_override);
8270 dut->rsne_override = NULL;
8271
Jouni Malinen68143132017-09-02 02:34:08 +03008272 free(dut->sae_commit_override);
8273 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03008274 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02008275 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03008276
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008277 dut->sta_associate_wait_connect = 0;
8278 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03008279 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008280 dut->sta_tod_policy = 0;
8281
Jouni Malinend86e5822017-08-29 03:55:32 +03008282 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02008283 free(dut->dpp_peer_uri);
8284 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02008285 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02008286 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03008287 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03008288
Jouni Malinenfac9cad2017-10-10 18:35:55 +03008289 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
8290
vamsi krishnaa2799492017-12-05 14:28:01 +05308291 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308292 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05308293 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05308294 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
8295 dut->fils_hlp = 0;
8296#ifdef ANDROID
8297 hlp_thread_cleanup(dut);
8298#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05308299 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308300
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308301 if (dut->program == PROGRAM_QM)
8302 wpa_command(intf, "SET interworking 1");
8303
Jouni Malinen8179fee2019-03-28 03:19:47 +02008304 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03008305 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02008306
Sunil Dutt076081f2018-02-05 19:45:50 +05308307#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008308 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05308309 dut->config_rsnie == 1) {
8310 dut->config_rsnie = 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308311 sta_config_params(dut, intf, STA_SET_RSNIE, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05308312 }
8313#endif /* NL80211_SUPPORT */
8314
Sunil Duttfebf8a82018-02-09 18:50:13 +05308315 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
8316 dut->dev_role = DEVROLE_STA_CFON;
8317 return sta_cfon_reset_default(dut, conn, cmd);
8318 }
8319
Jouni Malinen439352d2018-09-13 03:42:23 +03008320 wpa_command(intf, "SET setband AUTO");
8321
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308322 dut->ocvc = 0;
Jouni Malinen67433fc2020-06-26 22:50:33 +03008323 dut->client_privacy = 0;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05308324 dut->saquery_oci_freq = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308325
Sunil Duttfebf8a82018-02-09 18:50:13 +05308326 if (dut->program != PROGRAM_VHT)
8327 return cmd_sta_p2p_reset(dut, conn, cmd);
8328
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08008329 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008330}
8331
8332
Jouni Malinenf7222712019-06-13 01:50:21 +03008333static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
8334 struct sigma_conn *conn,
8335 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008336{
8337 const char *program = get_param(cmd, "Program");
8338
8339 if (program == NULL)
8340 return -1;
8341#ifdef ANDROID_NAN
8342 if (strcasecmp(program, "NAN") == 0)
8343 return nan_cmd_sta_get_events(dut, conn, cmd);
8344#endif /* ANDROID_NAN */
8345 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8346 return 0;
8347}
8348
8349
Jouni Malinen82905202018-04-29 17:20:10 +03008350static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
8351 struct sigma_cmd *cmd)
8352{
8353 const char *url = get_param(cmd, "url");
8354 const char *method = get_param(cmd, "method");
8355 pid_t pid;
8356 int status;
8357
8358 if (!url || !method)
8359 return -1;
8360
8361 /* TODO: Add support for method,post */
8362 if (strcasecmp(method, "get") != 0) {
8363 send_resp(dut, conn, SIGMA_ERROR,
8364 "ErrorCode,Unsupported method");
8365 return 0;
8366 }
8367
8368 pid = fork();
8369 if (pid < 0) {
8370 perror("fork");
8371 return -1;
8372 }
8373
8374 if (pid == 0) {
8375 char * argv[5] = { "wget", "-O", "/dev/null",
8376 (char *) url, NULL };
8377
8378 execv("/usr/bin/wget", argv);
8379 perror("execv");
8380 exit(0);
8381 return -1;
8382 }
8383
8384 if (waitpid(pid, &status, 0) < 0) {
8385 perror("waitpid");
8386 return -1;
8387 }
8388
8389 if (WIFEXITED(status)) {
8390 const char *errmsg;
8391
8392 if (WEXITSTATUS(status) == 0)
8393 return 1;
8394 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
8395 WEXITSTATUS(status));
8396 switch (WEXITSTATUS(status)) {
8397 case 4:
8398 errmsg = "errmsg,Network failure";
8399 break;
8400 case 8:
8401 errmsg = "errmsg,Server issued an error response";
8402 break;
8403 default:
8404 errmsg = "errmsg,Unknown failure from wget";
8405 break;
8406 }
8407 send_resp(dut, conn, SIGMA_ERROR, errmsg);
8408 return 0;
8409 }
8410
8411 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
8412 return 0;
8413}
8414
8415
Jouni Malinenf7222712019-06-13 01:50:21 +03008416static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
8417 struct sigma_conn *conn,
8418 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008419{
8420 const char *program = get_param(cmd, "Prog");
8421
Jouni Malinen82905202018-04-29 17:20:10 +03008422 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008423 return -1;
8424#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03008425 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008426 return nan_cmd_sta_exec_action(dut, conn, cmd);
8427#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03008428
8429 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07008430 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03008431
8432 if (get_param(cmd, "url"))
8433 return sta_exec_action_url(dut, conn, cmd);
8434
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008435 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8436 return 0;
8437}
8438
8439
Jouni Malinenf7222712019-06-13 01:50:21 +03008440static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
8441 struct sigma_conn *conn,
8442 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008443{
8444 const char *intf = get_param(cmd, "Interface");
8445 const char *val, *mcs32, *rate;
8446
8447 val = get_param(cmd, "GREENFIELD");
8448 if (val) {
8449 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
8450 /* Enable GD */
8451 send_resp(dut, conn, SIGMA_ERROR,
8452 "ErrorCode,GF not supported");
8453 return 0;
8454 }
8455 }
8456
8457 val = get_param(cmd, "SGI20");
8458 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008459 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008460 case DRIVER_ATHEROS:
8461 ath_sta_set_sgi(dut, intf, val);
8462 break;
8463 default:
8464 send_resp(dut, conn, SIGMA_ERROR,
8465 "ErrorCode,SGI20 not supported");
8466 return 0;
8467 }
8468 }
8469
8470 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
8471 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
8472 if (mcs32 && rate) {
8473 /* TODO */
8474 send_resp(dut, conn, SIGMA_ERROR,
8475 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
8476 return 0;
8477 } else if (mcs32 && !rate) {
8478 /* TODO */
8479 send_resp(dut, conn, SIGMA_ERROR,
8480 "ErrorCode,MCS32 not supported");
8481 return 0;
8482 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008483 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008484 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008485 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008486 ath_sta_set_11nrates(dut, intf, rate);
8487 break;
8488 default:
8489 send_resp(dut, conn, SIGMA_ERROR,
8490 "ErrorCode,MCS32_FIXEDRATE not supported");
8491 return 0;
8492 }
8493 }
8494
8495 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8496}
8497
8498
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008499static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8500 int mcs_config)
8501{
8502#ifdef NL80211_SUPPORT
8503 int ret;
8504
8505 switch (mcs_config) {
8506 case HE_80_MCS0_7:
8507 case HE_80_MCS0_9:
8508 case HE_80_MCS0_11:
8509 ret = sta_set_he_mcs(dut, intf, mcs_config);
8510 if (ret) {
8511 sigma_dut_print(dut, DUT_MSG_ERROR,
8512 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8513 mcs_config, ret);
8514 }
8515 break;
8516 default:
8517 sigma_dut_print(dut, DUT_MSG_ERROR,
8518 "cmd_set_max_he_mcs: Invalid mcs %d",
8519 mcs_config);
8520 break;
8521 }
8522#else /* NL80211_SUPPORT */
8523 sigma_dut_print(dut, DUT_MSG_ERROR,
8524 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8525#endif /* NL80211_SUPPORT */
8526}
8527
8528
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008529#define TWT_REQUEST_CMD 0
8530#define TWT_SUGGEST_CMD 1
8531#define TWT_DEMAND_CMD 2
8532
Arif Hussain480d5f42019-03-12 14:40:42 -07008533static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8534 struct sigma_cmd *cmd)
8535{
8536#ifdef NL80211_SUPPORT
8537 struct nlattr *params;
8538 struct nlattr *attr;
8539 struct nlattr *attr1;
8540 struct nl_msg *msg;
8541 int ifindex, ret;
8542 const char *val;
8543 const char *intf = get_param(cmd, "Interface");
8544 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8545 wake_interval_mantissa = 512;
8546 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008547 protection = 0, cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
Arif Hussain480d5f42019-03-12 14:40:42 -07008548
8549 ifindex = if_nametoindex(intf);
8550 if (ifindex == 0) {
8551 sigma_dut_print(dut, DUT_MSG_ERROR,
8552 "%s: Index for interface %s failed",
8553 __func__, intf);
8554 return -1;
8555 }
8556
8557 val = get_param(cmd, "FlowType");
8558 if (val) {
8559 flow_type = atoi(val);
8560 if (flow_type != 0 && flow_type != 1) {
8561 sigma_dut_print(dut, DUT_MSG_ERROR,
8562 "TWT: Invalid FlowType %d", flow_type);
8563 return -1;
8564 }
8565 }
8566
8567 val = get_param(cmd, "TWT_Trigger");
8568 if (val) {
8569 twt_trigger = atoi(val);
8570 if (twt_trigger != 0 && twt_trigger != 1) {
8571 sigma_dut_print(dut, DUT_MSG_ERROR,
8572 "TWT: Invalid TWT_Trigger %d",
8573 twt_trigger);
8574 return -1;
8575 }
8576 }
8577
8578 val = get_param(cmd, "Protection");
8579 if (val) {
8580 protection = atoi(val);
8581 if (protection != 0 && protection != 1) {
8582 sigma_dut_print(dut, DUT_MSG_ERROR,
8583 "TWT: Invalid Protection %d",
8584 protection);
8585 return -1;
8586 }
8587 }
8588
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008589 val = get_param(cmd, "SetupCommand");
8590 if (val) {
8591 cmd_type = atoi(val);
8592 if (cmd_type == TWT_REQUEST_CMD)
8593 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_REQUEST;
8594 else if (cmd_type == TWT_SUGGEST_CMD)
8595 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
8596 else if (cmd_type == TWT_DEMAND_CMD)
8597 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_DEMAND;
8598 else
8599 sigma_dut_print(dut, DUT_MSG_ERROR,
8600 "Default suggest is used for cmd %d",
8601 cmd_type);
8602 }
8603
Arif Hussain480d5f42019-03-12 14:40:42 -07008604 val = get_param(cmd, "TargetWakeTime");
8605 if (val)
8606 target_wake_time = atoi(val);
8607
8608 val = get_param(cmd, "WakeIntervalMantissa");
8609 if (val)
8610 wake_interval_mantissa = atoi(val);
8611
8612 val = get_param(cmd, "WakeIntervalExp");
8613 if (val)
8614 wake_interval_exp = atoi(val);
8615
8616 val = get_param(cmd, "NominalMinWakeDur");
8617 if (val)
8618 nominal_min_wake_dur = atoi(val);
8619
8620 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8621 NL80211_CMD_VENDOR)) ||
8622 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8623 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8624 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8625 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8626 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8627 !(params = nla_nest_start(
8628 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
8629 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8630 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8631 wake_interval_exp) ||
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008632 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, cmd_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008633 (twt_trigger &&
8634 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008635 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8636 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008637 (protection &&
8638 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008639 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8640 target_wake_time) ||
8641 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8642 nominal_min_wake_dur) ||
8643 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8644 wake_interval_mantissa)) {
8645 sigma_dut_print(dut, DUT_MSG_ERROR,
8646 "%s: err in adding vendor_cmd and vendor_data",
8647 __func__);
8648 nlmsg_free(msg);
8649 return -1;
8650 }
8651 nla_nest_end(msg, attr1);
8652 nla_nest_end(msg, params);
8653 nla_nest_end(msg, attr);
8654
8655 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8656 if (ret) {
8657 sigma_dut_print(dut, DUT_MSG_ERROR,
8658 "%s: err in send_and_recv_msgs, ret=%d",
8659 __func__, ret);
8660 }
8661
8662 return ret;
8663#else /* NL80211_SUPPORT */
8664 sigma_dut_print(dut, DUT_MSG_ERROR,
8665 "TWT request cannot be done without NL80211_SUPPORT defined");
8666 return -1;
8667#endif /* NL80211_SUPPORT */
8668}
8669
8670
8671static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8672 struct sigma_cmd *cmd)
8673{
8674 #ifdef NL80211_SUPPORT
8675 struct nlattr *params;
8676 struct nlattr *attr;
8677 struct nlattr *attr1;
8678 int ifindex, ret;
8679 struct nl_msg *msg;
8680 const char *intf = get_param(cmd, "Interface");
8681
8682 ifindex = if_nametoindex(intf);
8683 if (ifindex == 0) {
8684 sigma_dut_print(dut, DUT_MSG_ERROR,
8685 "%s: Index for interface %s failed",
8686 __func__, intf);
8687 return -1;
8688 }
8689
8690 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8691 NL80211_CMD_VENDOR)) ||
8692 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8693 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8694 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8695 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8696 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8697 !(params = nla_nest_start(
8698 msg,
8699 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8700 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8701 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8702 sigma_dut_print(dut, DUT_MSG_ERROR,
8703 "%s: err in adding vendor_cmd and vendor_data",
8704 __func__);
8705 nlmsg_free(msg);
8706 return -1;
8707 }
8708 nla_nest_end(msg, attr1);
8709 nla_nest_end(msg, params);
8710 nla_nest_end(msg, attr);
8711
8712 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8713 if (ret) {
8714 sigma_dut_print(dut, DUT_MSG_ERROR,
8715 "%s: err in send_and_recv_msgs, ret=%d",
8716 __func__, ret);
8717 }
8718
8719 return ret;
8720#else /* NL80211_SUPPORT */
8721 sigma_dut_print(dut, DUT_MSG_ERROR,
8722 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8723 return -1;
8724#endif /* NL80211_SUPPORT */
8725}
8726
8727
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008728static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8729 struct sigma_cmd *cmd)
8730{
8731#ifdef NL80211_SUPPORT
8732 struct nlattr *params;
8733 struct nlattr *attr;
8734 struct nlattr *attr1;
8735 struct nl_msg *msg;
8736 int ifindex, ret;
8737 const char *val;
8738 const char *intf = get_param(cmd, "Interface");
8739 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8740 ulmu_data_dis = 0;
8741
8742 ifindex = if_nametoindex(intf);
8743 if (ifindex == 0) {
8744 sigma_dut_print(dut, DUT_MSG_ERROR,
8745 "%s: Index for interface %s failed",
8746 __func__, intf);
8747 return -1;
8748 }
8749 val = get_param(cmd, "OMCtrl_RxNSS");
8750 if (val)
8751 rx_nss = atoi(val);
8752
8753 val = get_param(cmd, "OMCtrl_ChnlWidth");
8754 if (val)
8755 ch_bw = atoi(val);
8756
8757 val = get_param(cmd, "OMCtrl_ULMUDisable");
8758 if (val)
8759 ulmu_dis = atoi(val);
8760
8761 val = get_param(cmd, "OMCtrl_TxNSTS");
8762 if (val)
8763 tx_nsts = atoi(val);
8764
8765 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8766 if (val)
8767 ulmu_data_dis = atoi(val);
8768
8769 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8770 NL80211_CMD_VENDOR)) ||
8771 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8772 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8773 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8774 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8775 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8776 !(params = nla_nest_start(
8777 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8778 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8779 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8780 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8781 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8782 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8783 ulmu_data_dis) ||
8784 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8785 ulmu_dis)) {
8786 sigma_dut_print(dut, DUT_MSG_ERROR,
8787 "%s: err in adding vendor_cmd and vendor_data",
8788 __func__);
8789 nlmsg_free(msg);
8790 return -1;
8791 }
8792 nla_nest_end(msg, attr1);
8793 nla_nest_end(msg, params);
8794 nla_nest_end(msg, attr);
8795
8796 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8797 if (ret) {
8798 sigma_dut_print(dut, DUT_MSG_ERROR,
8799 "%s: err in send_and_recv_msgs, ret=%d",
8800 __func__, ret);
8801 }
8802
8803 return ret;
8804#else /* NL80211_SUPPORT */
8805 sigma_dut_print(dut, DUT_MSG_ERROR,
8806 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8807 return -1;
8808#endif /* NL80211_SUPPORT */
8809}
8810
8811
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008812static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8813 struct sigma_conn *conn,
8814 struct sigma_cmd *cmd)
8815{
8816 const char *intf = get_param(cmd, "Interface");
8817 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008818 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008819 int tkip = -1;
8820 int wep = -1;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308821 int iwpriv_status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008822
Arif Hussaina37e9552018-06-20 17:05:59 -07008823 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008824 val = get_param(cmd, "SGI80");
8825 if (val) {
8826 int sgi80;
8827
8828 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008829 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008830 }
8831
8832 val = get_param(cmd, "TxBF");
8833 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008834 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008835 case DRIVER_WCN:
8836 if (sta_set_tx_beamformee(dut, intf, 1)) {
8837 send_resp(dut, conn, SIGMA_ERROR,
8838 "ErrorCode,Failed to set TX beamformee enable");
8839 return 0;
8840 }
8841 break;
8842 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008843 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008844 send_resp(dut, conn, SIGMA_ERROR,
8845 "ErrorCode,Setting vhtsubfee failed");
8846 return 0;
8847 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008848 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008849 send_resp(dut, conn, SIGMA_ERROR,
8850 "ErrorCode,Setting vhtsubfer failed");
8851 return 0;
8852 }
8853 break;
8854 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008855 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008856 "Unsupported driver type");
8857 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008858 }
8859 }
8860
8861 val = get_param(cmd, "MU_TxBF");
8862 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008863 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008864 case DRIVER_ATHEROS:
8865 ath_sta_set_txsp_stream(dut, intf, "1SS");
8866 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008867 run_iwpriv(dut, intf, "vhtmubfee 1");
8868 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308869 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008870 case DRIVER_WCN:
8871 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8872 send_resp(dut, conn, SIGMA_ERROR,
8873 "ErrorCode,Failed to set RX/TXSP_STREAM");
8874 return 0;
8875 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308876 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008877 default:
8878 sigma_dut_print(dut, DUT_MSG_ERROR,
8879 "Setting SP_STREAM not supported");
8880 break;
8881 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008882 }
8883
8884 val = get_param(cmd, "LDPC");
8885 if (val) {
8886 int ldpc;
8887
8888 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308889 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", ldpc);
8890 if (iwpriv_status)
8891 sta_config_params(dut, intf, STA_SET_LDPC, ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008892 }
8893
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008894 val = get_param(cmd, "BCC");
8895 if (val) {
8896 int bcc;
8897
8898 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8899 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8900 * is mutually exclusive to bcc */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308901 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", !bcc);
8902 if (iwpriv_status)
8903 sta_config_params(dut, intf, STA_SET_LDPC, !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008904 }
8905
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008906 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8907 if (val && dut->sta_nss == 1)
8908 cmd_set_max_he_mcs(dut, intf, atoi(val));
8909
8910 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8911 if (val && dut->sta_nss == 2)
8912 cmd_set_max_he_mcs(dut, intf, atoi(val));
8913
Arif Hussainac6c5112018-05-25 17:34:00 -07008914 val = get_param(cmd, "MCS_FixedRate");
8915 if (val) {
8916#ifdef NL80211_SUPPORT
8917 int mcs, ratecode = 0;
8918 enum he_mcs_config mcs_config;
8919 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008920 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008921
8922 ratecode = (0x07 & dut->sta_nss) << 5;
8923 mcs = atoi(val);
8924 /* Add the MCS to the ratecode */
8925 if (mcs >= 0 && mcs <= 11) {
8926 ratecode += mcs;
8927 if (dut->device_type == STA_testbed &&
8928 mcs > 7 && mcs <= 11) {
8929 if (mcs <= 9)
8930 mcs_config = HE_80_MCS0_9;
8931 else
8932 mcs_config = HE_80_MCS0_11;
8933 ret = sta_set_he_mcs(dut, intf, mcs_config);
8934 if (ret) {
8935 sigma_dut_print(dut, DUT_MSG_ERROR,
8936 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8937 mcs, mcs_config, ret);
8938 }
8939 }
8940 snprintf(buf, sizeof(buf),
8941 "iwpriv %s set_11ax_rate 0x%03x",
8942 intf, ratecode);
8943 if (system(buf) != 0) {
8944 sigma_dut_print(dut, DUT_MSG_ERROR,
8945 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8946 ratecode);
8947 }
8948 } else {
8949 sigma_dut_print(dut, DUT_MSG_ERROR,
8950 "MCS_FixedRate: HE MCS %d not supported",
8951 mcs);
8952 }
8953#else /* NL80211_SUPPORT */
8954 sigma_dut_print(dut, DUT_MSG_ERROR,
8955 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8956#endif /* NL80211_SUPPORT */
8957 }
8958
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008959 val = get_param(cmd, "opt_md_notif_ie");
8960 if (val) {
8961 char *result = NULL;
8962 char delim[] = ";";
8963 char token[30];
8964 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308965 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008966
Peng Xub8fc5cc2017-05-10 17:27:28 -07008967 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308968 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008969
8970 /* Extract the NSS information */
8971 if (result) {
8972 value = atoi(result);
8973 switch (value) {
8974 case 1:
8975 config_val = 1;
8976 break;
8977 case 2:
8978 config_val = 3;
8979 break;
8980 case 3:
8981 config_val = 7;
8982 break;
8983 case 4:
8984 config_val = 15;
8985 break;
8986 default:
8987 config_val = 3;
8988 break;
8989 }
8990
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008991 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8992 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008993
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008994 }
8995
8996 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308997 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008998 if (result) {
8999 value = atoi(result);
9000 switch (value) {
9001 case 20:
9002 config_val = 0;
9003 break;
9004 case 40:
9005 config_val = 1;
9006 break;
9007 case 80:
9008 config_val = 2;
9009 break;
9010 case 160:
9011 config_val = 3;
9012 break;
9013 default:
9014 config_val = 2;
9015 break;
9016 }
9017
9018 dut->chwidth = config_val;
9019
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009020 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009021 }
9022
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009023 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009024 }
9025
9026 val = get_param(cmd, "nss_mcs_cap");
9027 if (val) {
9028 int nss, mcs;
9029 char token[20];
9030 char *result = NULL;
9031 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309032 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009033
Peng Xub8fc5cc2017-05-10 17:27:28 -07009034 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309035 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309036 if (!result) {
9037 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009038 "NSS not specified");
9039 send_resp(dut, conn, SIGMA_ERROR,
9040 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309041 return 0;
9042 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009043 nss = atoi(result);
9044
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009045 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07009046 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009047
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309048 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009049 if (result == NULL) {
9050 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009051 "MCS not specified");
9052 send_resp(dut, conn, SIGMA_ERROR,
9053 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009054 return 0;
9055 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309056 result = strtok_r(result, "-", &saveptr);
9057 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309058 if (!result) {
9059 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009060 "MCS not specified");
9061 send_resp(dut, conn, SIGMA_ERROR,
9062 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309063 return 0;
9064 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009065 mcs = atoi(result);
9066
Arif Hussaina37e9552018-06-20 17:05:59 -07009067 if (program && strcasecmp(program, "HE") == 0) {
9068#ifdef NL80211_SUPPORT
9069 enum he_mcs_config mcs_config;
9070 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009071
Arif Hussaina37e9552018-06-20 17:05:59 -07009072 if (mcs >= 0 && mcs <= 7) {
9073 mcs_config = HE_80_MCS0_7;
9074 } else if (mcs > 7 && mcs <= 9) {
9075 mcs_config = HE_80_MCS0_9;
9076 } else if (mcs > 9 && mcs <= 11) {
9077 mcs_config = HE_80_MCS0_11;
9078 } else {
9079 sigma_dut_print(dut, DUT_MSG_ERROR,
9080 "nss_mcs_cap: HE: Invalid mcs: %d",
9081 mcs);
9082 send_resp(dut, conn, SIGMA_ERROR,
9083 "errorCode,Invalid MCS");
9084 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009085 }
Arif Hussaina37e9552018-06-20 17:05:59 -07009086
9087 ret = sta_set_he_mcs(dut, intf, mcs_config);
9088 if (ret) {
9089 sigma_dut_print(dut, DUT_MSG_ERROR,
9090 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
9091 mcs_config, ret);
9092 send_resp(dut, conn, SIGMA_ERROR,
9093 "errorCode,Failed to set MCS");
9094 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009095 }
Arif Hussaina37e9552018-06-20 17:05:59 -07009096#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009097 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009098 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
9099#endif /* NL80211_SUPPORT */
9100 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009101 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07009102
9103 switch (nss) {
9104 case 1:
9105 switch (mcs) {
9106 case 7:
9107 vht_mcsmap = 0xfffc;
9108 break;
9109 case 8:
9110 vht_mcsmap = 0xfffd;
9111 break;
9112 case 9:
9113 vht_mcsmap = 0xfffe;
9114 break;
9115 default:
9116 vht_mcsmap = 0xfffe;
9117 break;
9118 }
9119 break;
9120 case 2:
9121 switch (mcs) {
9122 case 7:
9123 vht_mcsmap = 0xfff0;
9124 break;
9125 case 8:
9126 vht_mcsmap = 0xfff5;
9127 break;
9128 case 9:
9129 vht_mcsmap = 0xfffa;
9130 break;
9131 default:
9132 vht_mcsmap = 0xfffa;
9133 break;
9134 }
9135 break;
9136 case 3:
9137 switch (mcs) {
9138 case 7:
9139 vht_mcsmap = 0xffc0;
9140 break;
9141 case 8:
9142 vht_mcsmap = 0xffd5;
9143 break;
9144 case 9:
9145 vht_mcsmap = 0xffea;
9146 break;
9147 default:
9148 vht_mcsmap = 0xffea;
9149 break;
9150 }
9151 break;
9152 default:
9153 vht_mcsmap = 0xffea;
9154 break;
9155 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009156 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009157 }
9158 }
9159
9160 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
9161
9162 val = get_param(cmd, "Vht_tkip");
9163 if (val)
9164 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9165
9166 val = get_param(cmd, "Vht_wep");
9167 if (val)
9168 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9169
9170 if (tkip != -1 || wep != -1) {
9171 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009172 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009173 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009174 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009175 } else {
9176 sigma_dut_print(dut, DUT_MSG_ERROR,
9177 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
9178 return 0;
9179 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009180 }
9181
Arif Hussain55f00da2018-07-03 08:28:26 -07009182 val = get_param(cmd, "txBandwidth");
9183 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009184 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07009185 case DRIVER_WCN:
9186 if (wcn_sta_set_width(dut, intf, val) < 0) {
9187 send_resp(dut, conn, SIGMA_ERROR,
9188 "ErrorCode,Failed to set txBandwidth");
9189 return 0;
9190 }
9191 break;
9192 case DRIVER_ATHEROS:
9193 if (ath_set_width(dut, conn, intf, val) < 0) {
9194 send_resp(dut, conn, SIGMA_ERROR,
9195 "ErrorCode,Failed to set txBandwidth");
9196 return 0;
9197 }
9198 break;
9199 default:
9200 sigma_dut_print(dut, DUT_MSG_ERROR,
9201 "Setting txBandwidth not supported");
9202 break;
9203 }
9204 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009205
Arif Hussain9765f7d2018-07-03 08:28:26 -07009206 val = get_param(cmd, "BeamformeeSTS");
9207 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07009208 if (sta_set_tx_beamformee(dut, intf, 1)) {
9209 send_resp(dut, conn, SIGMA_ERROR,
9210 "ErrorCode,Failed to set TX beamformee enable");
9211 return 0;
9212 }
9213
Arif Hussain9765f7d2018-07-03 08:28:26 -07009214 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
9215 send_resp(dut, conn, SIGMA_ERROR,
9216 "ErrorCode,Failed to set BeamformeeSTS");
9217 return 0;
9218 }
9219 }
9220
Arif Hussain68d23f52018-07-11 13:39:08 -07009221 val = get_param(cmd, "Trig_MAC_Padding_Dur");
9222 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07009223#ifdef NL80211_SUPPORT
9224 enum qca_wlan_he_mac_padding_dur set_val;
9225
9226 switch (atoi(val)) {
9227 case 16:
9228 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
9229 break;
9230 case 8:
9231 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
9232 break;
9233 default:
9234 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
9235 break;
9236 }
9237 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07009238 send_resp(dut, conn, SIGMA_ERROR,
9239 "ErrorCode,Failed to set MAC padding duration");
9240 return 0;
9241 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07009242#else /* NL80211_SUPPORT */
9243 sigma_dut_print(dut, DUT_MSG_ERROR,
9244 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
9245#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07009246 }
9247
Arif Hussain480d5f42019-03-12 14:40:42 -07009248 val = get_param(cmd, "TWT_ReqSupport");
9249 if (val) {
9250 int set_val;
9251
9252 if (strcasecmp(val, "Enable") == 0) {
9253 set_val = 1;
9254 } else if (strcasecmp(val, "Disable") == 0) {
9255 set_val = 0;
9256 } else {
9257 send_resp(dut, conn, SIGMA_ERROR,
9258 "ErrorCode,Invalid TWT_ReqSupport");
9259 return STATUS_SENT;
9260 }
9261
9262 if (sta_set_twt_req_support(dut, intf, set_val)) {
9263 sigma_dut_print(dut, DUT_MSG_ERROR,
9264 "Failed to set TWT req support %d",
9265 set_val);
9266 send_resp(dut, conn, SIGMA_ERROR,
9267 "ErrorCode,Failed to set TWT_ReqSupport");
9268 return STATUS_SENT;
9269 }
9270 }
9271
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07009272 val = get_param(cmd, "MU_EDCA");
9273 if (val && (strcasecmp(val, "Override") == 0)) {
9274 if (sta_set_mu_edca_override(dut, intf, 1)) {
9275 send_resp(dut, conn, SIGMA_ERROR,
9276 "ErrorCode,Failed to set MU EDCA override");
9277 return 0;
9278 }
9279 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009280
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07009281 val = get_param(cmd, "OMControl");
9282 if (val) {
9283 int set_val = 1;
9284
9285 if (strcasecmp(val, "Enable") == 0)
9286 set_val = 1;
9287 else if (strcasecmp(val, "Disable") == 0)
9288 set_val = 0;
9289
9290 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
9291 send_resp(dut, conn, SIGMA_ERROR,
9292 "ErrorCode,Failed to set OM ctrl supp");
9293 return 0;
9294 }
9295 }
9296
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009297 val = get_param(cmd, "ADDBAResp_BufSize");
9298 if (val) {
9299 int buf_size;
9300
9301 if (strcasecmp(val, "gt64") == 0)
9302 buf_size = 256;
9303 else
9304 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009305 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009306 sta_set_addba_buf_size(dut, intf, buf_size)) {
9307 send_resp(dut, conn, SIGMA_ERROR,
9308 "ErrorCode,set addbaresp_buff_size failed");
9309 return 0;
9310 }
9311 }
9312
9313 val = get_param(cmd, "ADDBAReq_BufSize");
9314 if (val) {
9315 int buf_size;
9316
9317 if (strcasecmp(val, "gt64") == 0)
9318 buf_size = 256;
9319 else
9320 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009321 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009322 sta_set_addba_buf_size(dut, intf, buf_size)) {
9323 send_resp(dut, conn, SIGMA_ERROR,
9324 "ErrorCode,set addbareq_buff_size failed");
9325 return 0;
9326 }
9327 }
9328
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009329 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9330}
9331
9332
9333static int sta_set_wireless_60g(struct sigma_dut *dut,
9334 struct sigma_conn *conn,
9335 struct sigma_cmd *cmd)
9336{
9337 const char *dev_role = get_param(cmd, "DevRole");
9338
9339 if (!dev_role) {
9340 send_resp(dut, conn, SIGMA_INVALID,
9341 "ErrorCode,DevRole not specified");
9342 return 0;
9343 }
9344
9345 if (strcasecmp(dev_role, "PCP") == 0)
9346 return sta_set_60g_pcp(dut, conn, cmd);
9347 if (strcasecmp(dev_role, "STA") == 0)
9348 return sta_set_60g_sta(dut, conn, cmd);
9349 send_resp(dut, conn, SIGMA_INVALID,
9350 "ErrorCode,DevRole not supported");
9351 return 0;
9352}
9353
9354
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309355static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
9356 struct sigma_cmd *cmd)
9357{
9358 int status;
9359 const char *intf = get_param(cmd, "Interface");
9360 const char *val = get_param(cmd, "DevRole");
9361
9362 if (val && strcasecmp(val, "STA-CFON") == 0) {
9363 status = sta_cfon_set_wireless(dut, conn, cmd);
9364 if (status)
9365 return status;
9366 }
9367 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9368}
9369
9370
Jouni Malinen67433fc2020-06-26 22:50:33 +03009371static enum sigma_cmd_result
9372sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
9373 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309374{
9375 const char *intf = get_param(cmd, "Interface");
9376 const char *val;
9377
9378 val = get_param(cmd, "ocvc");
9379 if (val)
9380 dut->ocvc = atoi(val);
9381
Jouni Malinen67433fc2020-06-26 22:50:33 +03009382 val = get_param(cmd, "ClientPrivacy");
9383 if (val) {
9384 dut->client_privacy = atoi(val);
9385 if (dut->client_privacy &&
9386 (wpa_command(intf, "SET mac_addr 1") < 0 ||
9387 wpa_command(intf, "SET rand_addr_lifetime 1") < 0 ||
9388 wpa_command(intf, "SET preassoc_mac_addr 1") < 0 ||
9389 wpa_command(intf, "SET gas_rand_mac_addr 1") < 0 ||
9390 wpa_command(intf, "SET gas_rand_addr_lifetime 1") < 0)) {
9391 send_resp(dut, conn, SIGMA_ERROR,
9392 "errorCode,Failed to enable random MAC address use");
9393 return STATUS_SENT_ERROR;
9394 }
9395 }
9396
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309397 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9398}
9399
9400
Jouni Malinenf7222712019-06-13 01:50:21 +03009401static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
9402 struct sigma_conn *conn,
9403 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009404{
9405 const char *val;
9406
9407 val = get_param(cmd, "Program");
9408 if (val) {
9409 if (strcasecmp(val, "11n") == 0)
9410 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08009411 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009412 return cmd_sta_set_wireless_vht(dut, conn, cmd);
9413 if (strcasecmp(val, "60ghz") == 0)
9414 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309415 if (strcasecmp(val, "OCE") == 0)
9416 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02009417 /* sta_set_wireless in WPS program is only used for 60G */
9418 if (is_60g_sigma_dut(dut))
9419 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309420 if (strcasecmp(val, "WPA3") == 0)
9421 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009422 send_resp(dut, conn, SIGMA_ERROR,
9423 "ErrorCode,Program value not supported");
9424 } else {
9425 send_resp(dut, conn, SIGMA_ERROR,
9426 "ErrorCode,Program argument not available");
9427 }
9428
9429 return 0;
9430}
9431
9432
9433static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
9434 int tid)
9435{
9436 char buf[100];
9437 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
9438
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05309439 if (tid < 0 ||
9440 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
9441 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
9442 return;
9443 }
9444
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009445 /*
9446 * Two ways to ensure that addba request with a
9447 * non zero TID could be sent out. EV 117296
9448 */
9449 snprintf(buf, sizeof(buf),
9450 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
9451 tid);
9452 if (system(buf) != 0) {
9453 sigma_dut_print(dut, DUT_MSG_ERROR,
9454 "Ping did not send out");
9455 }
9456
9457 snprintf(buf, sizeof(buf),
9458 "iwconfig %s | grep Access | awk '{print $6}' > %s",
9459 intf, VI_QOS_TMP_FILE);
9460 if (system(buf) != 0)
9461 return;
9462
9463 snprintf(buf, sizeof(buf),
9464 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
9465 intf, VI_QOS_TMP_FILE);
9466 if (system(buf) != 0)
9467 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
9468
9469 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
9470 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
9471 if (system(buf) != 0) {
9472 sigma_dut_print(dut, DUT_MSG_ERROR,
9473 "VI_QOS_TEMP_FILE generation error failed");
9474 }
9475 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9476 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9477 if (system(buf) != 0) {
9478 sigma_dut_print(dut, DUT_MSG_ERROR,
9479 "VI_QOS_FILE generation failed");
9480 }
9481
9482 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9483 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9484 if (system(buf) != 0) {
9485 sigma_dut_print(dut, DUT_MSG_ERROR,
9486 "VI_QOS_FILE generation failed");
9487 }
9488
9489 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
9490 if (system(buf) != 0) {
9491 }
9492}
9493
9494
9495static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9496 struct sigma_cmd *cmd)
9497{
9498 const char *intf = get_param(cmd, "Interface");
9499 const char *val;
9500 int tid = 0;
9501 char buf[100];
9502
9503 val = get_param(cmd, "TID");
9504 if (val) {
9505 tid = atoi(val);
9506 if (tid)
9507 ath_sta_inject_frame(dut, intf, tid);
9508 }
9509
9510 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009511 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009512
9513 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
9514 if (system(buf) != 0) {
9515 sigma_dut_print(dut, DUT_MSG_ERROR,
9516 "wifitool senddelba failed");
9517 }
9518
9519 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
9520 if (system(buf) != 0) {
9521 sigma_dut_print(dut, DUT_MSG_ERROR,
9522 "wifitool sendaddba failed");
9523 }
9524
9525 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9526
9527 return 1;
9528}
9529
9530
Lior David9981b512017-01-20 13:16:40 +02009531#ifdef __linux__
9532
9533static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
9534 int agg_size)
9535{
9536 char dir[128], buf[128];
9537 FILE *f;
9538 regex_t re;
9539 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03009540 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02009541
9542 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
9543 sigma_dut_print(dut, DUT_MSG_ERROR,
9544 "failed to get wil6210 debugfs dir");
9545 return -1;
9546 }
9547
Jouni Malinen3aa72862019-05-29 23:14:51 +03009548 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
9549 if (res < 0 || res >= sizeof(buf))
9550 return -1;
Lior David9981b512017-01-20 13:16:40 +02009551 f = fopen(buf, "r");
9552 if (!f) {
9553 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009554 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009555 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9556 if (res < 0 || res >= sizeof(buf))
9557 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009558 f = fopen(buf, "r");
9559 if (!f) {
9560 sigma_dut_print(dut, DUT_MSG_ERROR,
9561 "failed to open: %s", buf);
9562 return -1;
9563 }
Lior David9981b512017-01-20 13:16:40 +02009564 }
9565
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009566 /* can be either VRING tx... or RING... */
9567 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009568 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9569 goto out;
9570 }
9571
9572 /* find TX VRING for the mac address */
9573 found = 0;
9574 while (fgets(buf, sizeof(buf), f)) {
9575 if (strcasestr(buf, dest_mac)) {
9576 found = 1;
9577 break;
9578 }
9579 }
9580
9581 if (!found) {
9582 sigma_dut_print(dut, DUT_MSG_ERROR,
9583 "no TX VRING for %s", dest_mac);
9584 goto out;
9585 }
9586
9587 /* extract VRING ID, "VRING tx_<id> = {" */
9588 if (!fgets(buf, sizeof(buf), f)) {
9589 sigma_dut_print(dut, DUT_MSG_ERROR,
9590 "no VRING start line for %s", dest_mac);
9591 goto out;
9592 }
9593
9594 rc = regexec(&re, buf, 2, m, 0);
9595 regfree(&re);
9596 if (rc || m[1].rm_so < 0) {
9597 sigma_dut_print(dut, DUT_MSG_ERROR,
9598 "no VRING TX ID for %s", dest_mac);
9599 goto out;
9600 }
9601 buf[m[1].rm_eo] = 0;
9602 vring_id = atoi(&buf[m[1].rm_so]);
9603
9604 /* send the addba command */
9605 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009606 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9607 if (res < 0 || res >= sizeof(buf))
9608 return -1;
Lior David9981b512017-01-20 13:16:40 +02009609 f = fopen(buf, "w");
9610 if (!f) {
9611 sigma_dut_print(dut, DUT_MSG_ERROR,
9612 "failed to open: %s", buf);
9613 return -1;
9614 }
9615
9616 fprintf(f, "add %d %d\n", vring_id, agg_size);
9617
9618 ret = 0;
9619
9620out:
9621 fclose(f);
9622
9623 return ret;
9624}
9625
9626
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009627int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9628 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009629{
9630 const char *val;
9631 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009632
9633 val = get_param(cmd, "TID");
9634 if (val) {
9635 tid = atoi(val);
9636 if (tid != 0) {
9637 sigma_dut_print(dut, DUT_MSG_ERROR,
9638 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9639 tid);
9640 }
9641 }
9642
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009643 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009644 if (!val) {
9645 sigma_dut_print(dut, DUT_MSG_ERROR,
9646 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009647 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009648 }
9649
Lior David9981b512017-01-20 13:16:40 +02009650 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009651 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009652
9653 return 1;
9654}
9655
Lior David9981b512017-01-20 13:16:40 +02009656#endif /* __linux__ */
9657
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009658
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009659static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9660 struct sigma_cmd *cmd)
9661{
9662#ifdef NL80211_SUPPORT
9663 const char *intf = get_param(cmd, "Interface");
9664 const char *val;
9665 int tid = -1;
9666 int bufsize = 64;
9667 struct nl_msg *msg;
9668 int ret = 0;
9669 struct nlattr *params;
9670 int ifindex;
9671
9672 val = get_param(cmd, "TID");
9673 if (val)
9674 tid = atoi(val);
9675
9676 if (tid == -1) {
9677 send_resp(dut, conn, SIGMA_ERROR,
9678 "ErrorCode,sta_send_addba tid invalid");
9679 return 0;
9680 }
9681
9682 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9683
9684 ifindex = if_nametoindex(intf);
9685 if (ifindex == 0) {
9686 sigma_dut_print(dut, DUT_MSG_ERROR,
9687 "%s: Index for interface %s failed",
9688 __func__, intf);
9689 send_resp(dut, conn, SIGMA_ERROR,
9690 "ErrorCode,sta_send_addba interface invalid");
9691 return 0;
9692 }
9693
9694 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9695 NL80211_CMD_VENDOR)) ||
9696 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9697 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9698 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9699 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9700 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9701 nla_put_u8(msg,
9702 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9703 QCA_WLAN_ADD_BA) ||
9704 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9705 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009706 nla_put_u16(msg,
9707 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9708 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009709 sigma_dut_print(dut, DUT_MSG_ERROR,
9710 "%s: err in adding vendor_cmd and vendor_data",
9711 __func__);
9712 nlmsg_free(msg);
9713 send_resp(dut, conn, SIGMA_ERROR,
9714 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9715 return 0;
9716 }
9717 nla_nest_end(msg, params);
9718
9719 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9720 if (ret) {
9721 sigma_dut_print(dut, DUT_MSG_ERROR,
9722 "%s: err in send_and_recv_msgs, ret=%d",
9723 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309724 if (ret == -EOPNOTSUPP)
9725 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009726 send_resp(dut, conn, SIGMA_ERROR,
9727 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9728 return 0;
9729 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009730#else /* NL80211_SUPPORT */
9731 sigma_dut_print(dut, DUT_MSG_ERROR,
9732 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009733#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309734
9735 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009736}
9737
9738
Jouni Malinenf7222712019-06-13 01:50:21 +03009739static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9740 struct sigma_conn *conn,
9741 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009742{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009743 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009744 case DRIVER_ATHEROS:
9745 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009746 case DRIVER_WCN:
9747 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009748#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009749 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009750 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009751#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009752 default:
9753 /*
9754 * There is no driver specific implementation for other drivers.
9755 * Ignore the command and report COMPLETE since the following
9756 * throughput test operation will end up sending ADDBA anyway.
9757 */
9758 return 1;
9759 }
9760}
9761
9762
9763int inject_eth_frame(int s, const void *data, size_t len,
9764 unsigned short ethtype, char *dst, char *src)
9765{
9766 struct iovec iov[4] = {
9767 {
9768 .iov_base = dst,
9769 .iov_len = ETH_ALEN,
9770 },
9771 {
9772 .iov_base = src,
9773 .iov_len = ETH_ALEN,
9774 },
9775 {
9776 .iov_base = &ethtype,
9777 .iov_len = sizeof(unsigned short),
9778 },
9779 {
9780 .iov_base = (void *) data,
9781 .iov_len = len,
9782 }
9783 };
9784 struct msghdr msg = {
9785 .msg_name = NULL,
9786 .msg_namelen = 0,
9787 .msg_iov = iov,
9788 .msg_iovlen = 4,
9789 .msg_control = NULL,
9790 .msg_controllen = 0,
9791 .msg_flags = 0,
9792 };
9793
9794 return sendmsg(s, &msg, 0);
9795}
9796
9797#if defined(__linux__) || defined(__QNXNTO__)
9798
9799int inject_frame(int s, const void *data, size_t len, int encrypt)
9800{
9801#define IEEE80211_RADIOTAP_F_WEP 0x04
9802#define IEEE80211_RADIOTAP_F_FRAG 0x08
9803 unsigned char rtap_hdr[] = {
9804 0x00, 0x00, /* radiotap version */
9805 0x0e, 0x00, /* radiotap length */
9806 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9807 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9808 0x00, /* padding */
9809 0x00, 0x00, /* RX and TX flags to indicate that */
9810 0x00, 0x00, /* this is the injected frame directly */
9811 };
9812 struct iovec iov[2] = {
9813 {
9814 .iov_base = &rtap_hdr,
9815 .iov_len = sizeof(rtap_hdr),
9816 },
9817 {
9818 .iov_base = (void *) data,
9819 .iov_len = len,
9820 }
9821 };
9822 struct msghdr msg = {
9823 .msg_name = NULL,
9824 .msg_namelen = 0,
9825 .msg_iov = iov,
9826 .msg_iovlen = 2,
9827 .msg_control = NULL,
9828 .msg_controllen = 0,
9829 .msg_flags = 0,
9830 };
9831
9832 if (encrypt)
9833 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9834
9835 return sendmsg(s, &msg, 0);
9836}
9837
9838
9839int open_monitor(const char *ifname)
9840{
9841#ifdef __QNXNTO__
9842 struct sockaddr_dl ll;
9843 int s;
9844
9845 memset(&ll, 0, sizeof(ll));
9846 ll.sdl_family = AF_LINK;
9847 ll.sdl_index = if_nametoindex(ifname);
9848 if (ll.sdl_index == 0) {
9849 perror("if_nametoindex");
9850 return -1;
9851 }
9852 s = socket(PF_INET, SOCK_RAW, 0);
9853#else /* __QNXNTO__ */
9854 struct sockaddr_ll ll;
9855 int s;
9856
9857 memset(&ll, 0, sizeof(ll));
9858 ll.sll_family = AF_PACKET;
9859 ll.sll_ifindex = if_nametoindex(ifname);
9860 if (ll.sll_ifindex == 0) {
9861 perror("if_nametoindex");
9862 return -1;
9863 }
9864 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9865#endif /* __QNXNTO__ */
9866 if (s < 0) {
9867 perror("socket[PF_PACKET,SOCK_RAW]");
9868 return -1;
9869 }
9870
9871 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9872 perror("monitor socket bind");
9873 close(s);
9874 return -1;
9875 }
9876
9877 return s;
9878}
9879
9880
9881static int hex2num(char c)
9882{
9883 if (c >= '0' && c <= '9')
9884 return c - '0';
9885 if (c >= 'a' && c <= 'f')
9886 return c - 'a' + 10;
9887 if (c >= 'A' && c <= 'F')
9888 return c - 'A' + 10;
9889 return -1;
9890}
9891
9892
9893int hwaddr_aton(const char *txt, unsigned char *addr)
9894{
9895 int i;
9896
9897 for (i = 0; i < 6; i++) {
9898 int a, b;
9899
9900 a = hex2num(*txt++);
9901 if (a < 0)
9902 return -1;
9903 b = hex2num(*txt++);
9904 if (b < 0)
9905 return -1;
9906 *addr++ = (a << 4) | b;
9907 if (i < 5 && *txt++ != ':')
9908 return -1;
9909 }
9910
9911 return 0;
9912}
9913
9914#endif /* defined(__linux__) || defined(__QNXNTO__) */
9915
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309916
9917#ifdef NL80211_SUPPORT
9918static int nl80211_send_frame_cmd(struct sigma_dut *dut, const char *intf,
9919 const u8 *data, size_t data_len, int freq)
9920{
9921 struct nl_msg *msg;
9922 int ret = 0;
9923 int ifindex;
9924
9925 ifindex = if_nametoindex(intf);
9926 if (ifindex == 0) {
9927 sigma_dut_print(dut, DUT_MSG_ERROR,
9928 "%s: Index for interface %s failed",
9929 __func__, intf);
9930 return -1;
9931 }
9932
9933 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9934 NL80211_CMD_FRAME)) ||
9935 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
9936 nla_put(msg, NL80211_ATTR_FRAME, data_len, data)) {
9937 sigma_dut_print(dut, DUT_MSG_ERROR,
9938 "%s: Error in adding NL80211_CMD_FRAME",
9939 __func__);
9940 nlmsg_free(msg);
9941 return -1;
9942 }
9943
9944 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9945 if (ret) {
9946 sigma_dut_print(dut, DUT_MSG_ERROR,
9947 "nl80211: Frame command failed: ret=%d (%s) req=%u",
9948 ret, strerror(-ret), freq);
9949 return -1;
9950 }
9951
9952 return 0;
9953}
9954#endif /* NL80211_SUPPORT */
9955
9956
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009957enum send_frame_type {
9958 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9959};
9960enum send_frame_protection {
9961 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9962};
9963
9964
9965static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309966 const char *intf, enum send_frame_type frame,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009967 enum send_frame_protection protected,
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309968 const char *dest, int use_monitor)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009969{
9970#ifdef __linux__
9971 unsigned char buf[1000], *pos;
9972 int s, res;
9973 char bssid[20], addr[20];
9974 char result[32], ssid[100];
9975 size_t ssid_len;
9976
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009977 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009978 sizeof(result)) < 0 ||
9979 strncmp(result, "COMPLETED", 9) != 0) {
9980 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9981 return 0;
9982 }
9983
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009984 if (get_wpa_status(get_station_ifname(dut), "bssid",
9985 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009986 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9987 "current BSSID");
9988 return 0;
9989 }
9990
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009991 if (get_wpa_status(get_station_ifname(dut), "address",
9992 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009993 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9994 "own MAC address");
9995 return 0;
9996 }
9997
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009998 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009999 < 0) {
10000 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
10001 "current SSID");
10002 return 0;
10003 }
10004 ssid_len = strlen(ssid);
10005
10006 pos = buf;
10007
10008 /* Frame Control */
10009 switch (frame) {
10010 case DISASSOC:
10011 *pos++ = 0xa0;
10012 break;
10013 case DEAUTH:
10014 *pos++ = 0xc0;
10015 break;
10016 case SAQUERY:
10017 *pos++ = 0xd0;
10018 break;
10019 case AUTH:
10020 *pos++ = 0xb0;
10021 break;
10022 case ASSOCREQ:
10023 *pos++ = 0x00;
10024 break;
10025 case REASSOCREQ:
10026 *pos++ = 0x20;
10027 break;
10028 case DLS_REQ:
10029 *pos++ = 0xd0;
10030 break;
10031 }
10032
10033 if (protected == INCORRECT_KEY)
10034 *pos++ = 0x40; /* Set Protected field to 1 */
10035 else
10036 *pos++ = 0x00;
10037
10038 /* Duration */
10039 *pos++ = 0x00;
10040 *pos++ = 0x00;
10041
10042 /* addr1 = DA (current AP) */
10043 hwaddr_aton(bssid, pos);
10044 pos += 6;
10045 /* addr2 = SA (own address) */
10046 hwaddr_aton(addr, pos);
10047 pos += 6;
10048 /* addr3 = BSSID (current AP) */
10049 hwaddr_aton(bssid, pos);
10050 pos += 6;
10051
10052 /* Seq# (to be filled by driver/mac80211) */
10053 *pos++ = 0x00;
10054 *pos++ = 0x00;
10055
10056 if (protected == INCORRECT_KEY) {
10057 /* CCMP parameters */
10058 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
10059 pos += 8;
10060 }
10061
10062 if (protected == INCORRECT_KEY) {
10063 switch (frame) {
10064 case DEAUTH:
10065 /* Reason code (encrypted) */
10066 memcpy(pos, "\xa7\x39", 2);
10067 pos += 2;
10068 break;
10069 case DISASSOC:
10070 /* Reason code (encrypted) */
10071 memcpy(pos, "\xa7\x39", 2);
10072 pos += 2;
10073 break;
10074 case SAQUERY:
10075 /* Category|Action|TransID (encrypted) */
10076 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
10077 pos += 4;
10078 break;
10079 default:
10080 return -1;
10081 }
10082
10083 /* CCMP MIC */
10084 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
10085 pos += 8;
10086 } else {
10087 switch (frame) {
10088 case DEAUTH:
10089 /* reason code = 8 */
10090 *pos++ = 0x08;
10091 *pos++ = 0x00;
10092 break;
10093 case DISASSOC:
10094 /* reason code = 8 */
10095 *pos++ = 0x08;
10096 *pos++ = 0x00;
10097 break;
10098 case SAQUERY:
10099 /* Category - SA Query */
10100 *pos++ = 0x08;
10101 /* SA query Action - Request */
10102 *pos++ = 0x00;
10103 /* Transaction ID */
10104 *pos++ = 0x12;
10105 *pos++ = 0x34;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053010106 if (dut->saquery_oci_freq) {
10107 /* OCI IE - Extended ID */
10108 *pos++ = 0xFF;
10109 *pos++ = 0x04;
10110 *pos++ = 0x36;
10111 /* Operating Class */
10112 *pos++ = 0x74;
10113 /* Primary Channel */
10114 *pos++ = freq_to_channel(dut->saquery_oci_freq);
10115 /* Frequency Segment 1 Channel Number */
10116 *pos++ = 0x00;
10117 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010118 break;
10119 case AUTH:
10120 /* Auth Alg (Open) */
10121 *pos++ = 0x00;
10122 *pos++ = 0x00;
10123 /* Seq# */
10124 *pos++ = 0x01;
10125 *pos++ = 0x00;
10126 /* Status code */
10127 *pos++ = 0x00;
10128 *pos++ = 0x00;
10129 break;
10130 case ASSOCREQ:
10131 /* Capability Information */
10132 *pos++ = 0x31;
10133 *pos++ = 0x04;
10134 /* Listen Interval */
10135 *pos++ = 0x0a;
10136 *pos++ = 0x00;
10137 /* SSID */
10138 *pos++ = 0x00;
10139 *pos++ = ssid_len;
10140 memcpy(pos, ssid, ssid_len);
10141 pos += ssid_len;
10142 /* Supported Rates */
10143 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
10144 10);
10145 pos += 10;
10146 /* Extended Supported Rates */
10147 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
10148 pos += 6;
10149 /* RSN */
10150 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
10151 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
10152 "\x00\x00\x00\x00\x0f\xac\x06", 28);
10153 pos += 28;
10154 break;
10155 case REASSOCREQ:
10156 /* Capability Information */
10157 *pos++ = 0x31;
10158 *pos++ = 0x04;
10159 /* Listen Interval */
10160 *pos++ = 0x0a;
10161 *pos++ = 0x00;
10162 /* Current AP */
10163 hwaddr_aton(bssid, pos);
10164 pos += 6;
10165 /* SSID */
10166 *pos++ = 0x00;
10167 *pos++ = ssid_len;
10168 memcpy(pos, ssid, ssid_len);
10169 pos += ssid_len;
10170 /* Supported Rates */
10171 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
10172 10);
10173 pos += 10;
10174 /* Extended Supported Rates */
10175 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
10176 pos += 6;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053010177 /* RSNE - Group and Pairwise ciphers */
10178 memcpy(pos,
10179 "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04",
10180 14);
10181 pos += 14;
10182 /* RSNE - AKM Suite count */
10183 *pos++ = 0x01;
10184 *pos++ = 0x00;
10185 /* RSNE - AKM Suites */
10186 if (dut->program == PROGRAM_WPA3)
10187 memcpy(pos, "\x00\x0f\xac\x08", 4);
10188 else
10189 memcpy(pos, "\x00\x0f\xac\x02", 4);
10190 pos += 4;
10191 /* RSNE - Capabilities */
10192 *pos++ = 0xc0;
10193 if (dut->ocvc)
10194 *pos++ = 0x40;
10195 else
10196 *pos++ = 0x00;
10197 /* RSNE - PMKID list and Group Management Ciphers */
10198 memcpy(pos, "\x00\x00\x00\x0f\xac\x06", 6);
10199 pos += 6;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010200 break;
10201 case DLS_REQ:
10202 /* Category - DLS */
10203 *pos++ = 0x02;
10204 /* DLS Action - Request */
10205 *pos++ = 0x00;
10206 /* Destination MACAddress */
10207 if (dest)
10208 hwaddr_aton(dest, pos);
10209 else
10210 memset(pos, 0, 6);
10211 pos += 6;
10212 /* Source MACAddress */
10213 hwaddr_aton(addr, pos);
10214 pos += 6;
10215 /* Capability Information */
10216 *pos++ = 0x10; /* Privacy */
10217 *pos++ = 0x06; /* QoS */
10218 /* DLS Timeout Value */
10219 *pos++ = 0x00;
10220 *pos++ = 0x01;
10221 /* Supported rates */
10222 *pos++ = 0x01;
10223 *pos++ = 0x08;
10224 *pos++ = 0x0c; /* 6 Mbps */
10225 *pos++ = 0x12; /* 9 Mbps */
10226 *pos++ = 0x18; /* 12 Mbps */
10227 *pos++ = 0x24; /* 18 Mbps */
10228 *pos++ = 0x30; /* 24 Mbps */
10229 *pos++ = 0x48; /* 36 Mbps */
10230 *pos++ = 0x60; /* 48 Mbps */
10231 *pos++ = 0x6c; /* 54 Mbps */
10232 /* TODO: Extended Supported Rates */
10233 /* TODO: HT Capabilities */
10234 break;
10235 }
10236 }
10237
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010238 if (use_monitor) {
10239 s = open_monitor("sigmadut");
10240 if (s < 0) {
10241 send_resp(dut, conn, SIGMA_ERROR,
10242 "errorCode,Failed to open monitor socket");
10243 return 0;
10244 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010245
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010246 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
10247 if (res < 0) {
10248 send_resp(dut, conn, SIGMA_ERROR,
10249 "errorCode,Failed to inject frame");
10250 close(s);
10251 return 0;
10252 }
10253 if (res < pos - buf) {
10254 send_resp(dut, conn, SIGMA_ERROR,
10255 "errorCode,Only partial frame sent");
10256 close(s);
10257 return 0;
10258 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010259
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010260 close(s);
10261 } else {
10262#ifdef NL80211_SUPPORT
10263 int freq;
10264 char freq_str[10];
10265
10266 if (get_wpa_status(get_station_ifname(dut), "freq",
10267 freq_str, sizeof(freq_str)) < 0) {
10268 send_resp(dut, conn, SIGMA_ERROR,
10269 "errorCode,Could not get current operating frequency");
10270 return 0;
10271 }
10272 freq = atoi(freq_str);
10273
10274 if (nl80211_send_frame_cmd(dut, intf, buf, pos - buf, freq)) {
10275 send_resp(dut, conn, SIGMA_ERROR,
10276 "errorCode,Failed to inject frame");
10277 return 0;
10278 }
10279#else /* NL80211_SUPPORT */
10280 send_resp(dut, conn, SIGMA_ERROR,
10281 "errorCode,Failed to inject frame (no NL80211_SUPPORT)");
10282 return 0;
10283#endif /* NL80211_SUPPORT */
10284 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010285
10286 return 1;
10287#else /* __linux__ */
10288 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
10289 "yet supported");
10290 return 0;
10291#endif /* __linux__ */
10292}
10293
10294
10295static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
10296 struct sigma_conn *conn,
10297 struct sigma_cmd *cmd)
10298{
10299 const char *intf = get_param(cmd, "Interface");
10300 const char *sta, *val;
10301 unsigned char addr[ETH_ALEN];
10302 char buf[100];
10303
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010304 if (!intf)
10305 return -1;
10306
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010307 sta = get_param(cmd, "peer");
10308 if (sta == NULL)
10309 sta = get_param(cmd, "station");
10310 if (sta == NULL) {
10311 send_resp(dut, conn, SIGMA_ERROR,
10312 "ErrorCode,Missing peer address");
10313 return 0;
10314 }
10315 if (hwaddr_aton(sta, addr) < 0) {
10316 send_resp(dut, conn, SIGMA_ERROR,
10317 "ErrorCode,Invalid peer address");
10318 return 0;
10319 }
10320
10321 val = get_param(cmd, "type");
10322 if (val == NULL)
10323 return -1;
10324
10325 if (strcasecmp(val, "DISCOVERY") == 0) {
10326 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
10327 if (wpa_command(intf, buf) < 0) {
10328 send_resp(dut, conn, SIGMA_ERROR,
10329 "ErrorCode,Failed to send TDLS discovery");
10330 return 0;
10331 }
10332 return 1;
10333 }
10334
10335 if (strcasecmp(val, "SETUP") == 0) {
10336 int status = 0, timeout = 0;
10337
10338 val = get_param(cmd, "Status");
10339 if (val)
10340 status = atoi(val);
10341
10342 val = get_param(cmd, "Timeout");
10343 if (val)
10344 timeout = atoi(val);
10345
10346 if (status != 0 && status != 37) {
10347 send_resp(dut, conn, SIGMA_ERROR,
10348 "ErrorCode,Unsupported status value");
10349 return 0;
10350 }
10351
10352 if (timeout != 0 && timeout != 301) {
10353 send_resp(dut, conn, SIGMA_ERROR,
10354 "ErrorCode,Unsupported timeout value");
10355 return 0;
10356 }
10357
10358 if (status && timeout) {
10359 send_resp(dut, conn, SIGMA_ERROR,
10360 "ErrorCode,Unsupported timeout+status "
10361 "combination");
10362 return 0;
10363 }
10364
10365 if (status == 37 &&
10366 wpa_command(intf, "SET tdls_testing 0x200")) {
10367 send_resp(dut, conn, SIGMA_ERROR,
10368 "ErrorCode,Failed to enable "
10369 "decline setup response test mode");
10370 return 0;
10371 }
10372
10373 if (timeout == 301) {
10374 int res;
10375 if (dut->no_tpk_expiration)
10376 res = wpa_command(intf,
10377 "SET tdls_testing 0x108");
10378 else
10379 res = wpa_command(intf,
10380 "SET tdls_testing 0x8");
10381 if (res) {
10382 send_resp(dut, conn, SIGMA_ERROR,
10383 "ErrorCode,Failed to set short TPK "
10384 "lifetime");
10385 return 0;
10386 }
10387 }
10388
10389 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
10390 if (wpa_command(intf, buf) < 0) {
10391 send_resp(dut, conn, SIGMA_ERROR,
10392 "ErrorCode,Failed to send TDLS setup");
10393 return 0;
10394 }
10395 return 1;
10396 }
10397
10398 if (strcasecmp(val, "TEARDOWN") == 0) {
10399 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
10400 if (wpa_command(intf, buf) < 0) {
10401 send_resp(dut, conn, SIGMA_ERROR,
10402 "ErrorCode,Failed to send TDLS teardown");
10403 return 0;
10404 }
10405 return 1;
10406 }
10407
10408 send_resp(dut, conn, SIGMA_ERROR,
10409 "ErrorCode,Unsupported TDLS frame");
10410 return 0;
10411}
10412
10413
10414static int sta_ap_known(const char *ifname, const char *bssid)
10415{
10416 char buf[4096];
10417
Jouni Malinendd32f192018-09-15 02:55:19 +030010418 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010419 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
10420 return 0;
10421 if (strncmp(buf, "id=", 3) != 0)
10422 return 0;
10423 return 1;
10424}
10425
10426
10427static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
10428 const char *bssid)
10429{
10430 int res;
10431 struct wpa_ctrl *ctrl;
10432 char buf[256];
10433
10434 if (sta_ap_known(ifname, bssid))
10435 return 0;
10436 sigma_dut_print(dut, DUT_MSG_DEBUG,
10437 "AP not in BSS table - start scan");
10438
10439 ctrl = open_wpa_mon(ifname);
10440 if (ctrl == NULL) {
10441 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10442 "wpa_supplicant monitor connection");
10443 return -1;
10444 }
10445
10446 if (wpa_command(ifname, "SCAN") < 0) {
10447 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
10448 wpa_ctrl_detach(ctrl);
10449 wpa_ctrl_close(ctrl);
10450 return -1;
10451 }
10452
10453 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
10454 buf, sizeof(buf));
10455
10456 wpa_ctrl_detach(ctrl);
10457 wpa_ctrl_close(ctrl);
10458
10459 if (res < 0) {
10460 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
10461 return -1;
10462 }
10463
10464 if (sta_ap_known(ifname, bssid))
10465 return 0;
10466 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
10467 return -1;
10468}
10469
10470
10471static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
10472 struct sigma_conn *conn,
10473 struct sigma_cmd *cmd,
10474 const char *intf)
10475{
10476 char buf[200];
10477
10478 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
10479 if (system(buf) != 0) {
10480 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
10481 "ndsend");
10482 return 0;
10483 }
10484
10485 return 1;
10486}
10487
10488
10489static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
10490 struct sigma_conn *conn,
10491 struct sigma_cmd *cmd,
10492 const char *intf)
10493{
10494 char buf[200];
10495 const char *ip = get_param(cmd, "SenderIP");
10496
Peng Xu26b356d2017-10-04 17:58:16 -070010497 if (!ip)
10498 return 0;
10499
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010500 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
10501 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10502 if (system(buf) == 0) {
10503 sigma_dut_print(dut, DUT_MSG_INFO,
10504 "Neighbor Solicitation got a response "
10505 "for %s@%s", ip, intf);
10506 }
10507
10508 return 1;
10509}
10510
10511
10512static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
10513 struct sigma_conn *conn,
10514 struct sigma_cmd *cmd,
10515 const char *ifname)
10516{
10517 char buf[200];
10518 const char *ip = get_param(cmd, "SenderIP");
10519
10520 if (ip == NULL) {
10521 send_resp(dut, conn, SIGMA_ERROR,
10522 "ErrorCode,Missing SenderIP parameter");
10523 return 0;
10524 }
10525 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
10526 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10527 if (system(buf) != 0) {
10528 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
10529 "for %s@%s", ip, ifname);
10530 }
10531
10532 return 1;
10533}
10534
10535
10536static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
10537 struct sigma_conn *conn,
10538 struct sigma_cmd *cmd,
10539 const char *ifname)
10540{
10541 char buf[200];
10542 char ip[16];
10543 int s;
Peng Xub3756882017-10-04 14:39:09 -070010544 struct ifreq ifr;
10545 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010546
10547 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070010548 if (s < 0) {
10549 perror("socket");
10550 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010551 }
10552
Peng Xub3756882017-10-04 14:39:09 -070010553 memset(&ifr, 0, sizeof(ifr));
10554 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
10555 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
10556 sigma_dut_print(dut, DUT_MSG_INFO,
10557 "Failed to get %s IP address: %s",
10558 ifname, strerror(errno));
10559 close(s);
10560 return -1;
10561 }
10562 close(s);
10563
10564 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
10565 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
10566
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010567 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
10568 ip);
10569 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10570 if (system(buf) != 0) {
10571 }
10572
10573 return 1;
10574}
10575
10576
10577static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
10578 struct sigma_conn *conn,
10579 struct sigma_cmd *cmd,
10580 const char *ifname)
10581{
10582 char buf[200], addr[20];
10583 char dst[ETH_ALEN], src[ETH_ALEN];
10584 short ethtype = htons(ETH_P_ARP);
10585 char *pos;
10586 int s, res;
10587 const char *val;
10588 struct sockaddr_in taddr;
10589
10590 val = get_param(cmd, "dest");
10591 if (val)
10592 hwaddr_aton(val, (unsigned char *) dst);
10593
10594 val = get_param(cmd, "DestIP");
10595 if (val)
10596 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070010597 else
10598 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010599
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010600 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010601 sizeof(addr)) < 0)
10602 return -2;
10603 hwaddr_aton(addr, (unsigned char *) src);
10604
10605 pos = buf;
10606 *pos++ = 0x00;
10607 *pos++ = 0x01;
10608 *pos++ = 0x08;
10609 *pos++ = 0x00;
10610 *pos++ = 0x06;
10611 *pos++ = 0x04;
10612 *pos++ = 0x00;
10613 *pos++ = 0x02;
10614 memcpy(pos, src, ETH_ALEN);
10615 pos += ETH_ALEN;
10616 memcpy(pos, &taddr.sin_addr, 4);
10617 pos += 4;
10618 memcpy(pos, dst, ETH_ALEN);
10619 pos += ETH_ALEN;
10620 memcpy(pos, &taddr.sin_addr, 4);
10621 pos += 4;
10622
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010623 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010624 if (s < 0) {
10625 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
10626 "monitor socket");
10627 return 0;
10628 }
10629
10630 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
10631 if (res < 0) {
10632 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
10633 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053010634 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010635 return 0;
10636 }
10637
10638 close(s);
10639
10640 return 1;
10641}
10642
10643
10644static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
10645 struct sigma_conn *conn,
10646 struct sigma_cmd *cmd,
10647 const char *intf, const char *dest)
10648{
10649 char buf[100];
10650
10651 if (if_nametoindex("sigmadut") == 0) {
10652 snprintf(buf, sizeof(buf),
10653 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010654 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010655 if (system(buf) != 0 ||
10656 if_nametoindex("sigmadut") == 0) {
10657 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10658 "monitor interface with '%s'", buf);
10659 return -2;
10660 }
10661 }
10662
10663 if (system("ifconfig sigmadut up") != 0) {
10664 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10665 "monitor interface up");
10666 return -2;
10667 }
10668
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010669 return sta_inject_frame(dut, conn, intf, DLS_REQ, UNPROTECTED, dest, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010670}
10671
10672
10673static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10674 struct sigma_conn *conn,
10675 struct sigma_cmd *cmd)
10676{
10677 const char *intf = get_param(cmd, "Interface");
10678 const char *dest = get_param(cmd, "Dest");
10679 const char *type = get_param(cmd, "FrameName");
10680 const char *val;
10681 char buf[200], *pos, *end;
10682 int count, count2;
10683
10684 if (type == NULL)
10685 type = get_param(cmd, "Type");
10686
10687 if (intf == NULL || dest == NULL || type == NULL)
10688 return -1;
10689
10690 if (strcasecmp(type, "NeighAdv") == 0)
10691 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10692
10693 if (strcasecmp(type, "NeighSolicitReq") == 0)
10694 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10695
10696 if (strcasecmp(type, "ARPProbe") == 0)
10697 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10698
10699 if (strcasecmp(type, "ARPAnnounce") == 0)
10700 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10701
10702 if (strcasecmp(type, "ARPReply") == 0)
10703 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10704
10705 if (strcasecmp(type, "DLS-request") == 0 ||
10706 strcasecmp(type, "DLSrequest") == 0)
10707 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10708 dest);
10709
10710 if (strcasecmp(type, "ANQPQuery") != 0 &&
10711 strcasecmp(type, "Query") != 0) {
10712 send_resp(dut, conn, SIGMA_ERROR,
10713 "ErrorCode,Unsupported HS 2.0 send frame type");
10714 return 0;
10715 }
10716
10717 if (sta_scan_ap(dut, intf, dest) < 0) {
10718 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10719 "the requested AP");
10720 return 0;
10721 }
10722
10723 pos = buf;
10724 end = buf + sizeof(buf);
10725 count = 0;
10726 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10727
10728 val = get_param(cmd, "ANQP_CAP_LIST");
10729 if (val && atoi(val)) {
10730 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10731 count++;
10732 }
10733
10734 val = get_param(cmd, "VENUE_NAME");
10735 if (val && atoi(val)) {
10736 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10737 count++;
10738 }
10739
10740 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10741 if (val && atoi(val)) {
10742 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10743 count++;
10744 }
10745
10746 val = get_param(cmd, "ROAMING_CONS");
10747 if (val && atoi(val)) {
10748 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10749 count++;
10750 }
10751
10752 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10753 if (val && atoi(val)) {
10754 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10755 count++;
10756 }
10757
10758 val = get_param(cmd, "NAI_REALM_LIST");
10759 if (val && atoi(val)) {
10760 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10761 count++;
10762 }
10763
10764 val = get_param(cmd, "3GPP_INFO");
10765 if (val && atoi(val)) {
10766 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10767 count++;
10768 }
10769
10770 val = get_param(cmd, "DOMAIN_LIST");
10771 if (val && atoi(val)) {
10772 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10773 count++;
10774 }
10775
Jouni Malinen34cf9532018-04-29 19:26:33 +030010776 val = get_param(cmd, "Venue_URL");
10777 if (val && atoi(val)) {
10778 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10779 count++;
10780 }
10781
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010782 val = get_param(cmd, "Advice_Of_Charge");
10783 if (val && atoi(val)) {
10784 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10785 count++;
10786 }
10787
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010788 if (count && wpa_command(intf, buf)) {
10789 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10790 return 0;
10791 }
10792
10793 pos = buf;
10794 end = buf + sizeof(buf);
10795 count2 = 0;
10796 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
10797
10798 val = get_param(cmd, "HS_CAP_LIST");
10799 if (val && atoi(val)) {
10800 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
10801 count2++;
10802 }
10803
10804 val = get_param(cmd, "OPER_NAME");
10805 if (val && atoi(val)) {
10806 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
10807 count2++;
10808 }
10809
10810 val = get_param(cmd, "WAN_METRICS");
10811 if (!val)
10812 val = get_param(cmd, "WAN_MAT");
10813 if (!val)
10814 val = get_param(cmd, "WAN_MET");
10815 if (val && atoi(val)) {
10816 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10817 count2++;
10818 }
10819
10820 val = get_param(cmd, "CONNECTION_CAPABILITY");
10821 if (val && atoi(val)) {
10822 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10823 count2++;
10824 }
10825
10826 val = get_param(cmd, "OP_CLASS");
10827 if (val && atoi(val)) {
10828 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10829 count2++;
10830 }
10831
10832 val = get_param(cmd, "OSU_PROVIDER_LIST");
10833 if (val && atoi(val)) {
10834 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10835 count2++;
10836 }
10837
Jouni Malinenf67afec2018-04-29 19:24:58 +030010838 val = get_param(cmd, "OPER_ICON_METADATA");
10839 if (!val)
10840 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10841 if (val && atoi(val)) {
10842 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10843 count2++;
10844 }
10845
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010846 if (count && count2) {
10847 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10848 "second query");
10849 sleep(1);
10850 }
10851
10852 if (count2 && wpa_command(intf, buf)) {
10853 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10854 "failed");
10855 return 0;
10856 }
10857
10858 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10859 if (val) {
10860 if (count || count2) {
10861 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10862 "sending out second query");
10863 sleep(1);
10864 }
10865
10866 if (strcmp(val, "1") == 0)
10867 val = "mail.example.com";
10868 snprintf(buf, end - pos,
10869 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10870 dest, val);
10871 if (wpa_command(intf, buf)) {
10872 send_resp(dut, conn, SIGMA_ERROR,
10873 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10874 "failed");
10875 return 0;
10876 }
10877 }
10878
10879 val = get_param(cmd, "ICON_REQUEST");
10880 if (val) {
10881 if (count || count2) {
10882 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10883 "sending out second query");
10884 sleep(1);
10885 }
10886
10887 snprintf(buf, end - pos,
10888 "HS20_ICON_REQUEST %s %s", dest, val);
10889 if (wpa_command(intf, buf)) {
10890 send_resp(dut, conn, SIGMA_ERROR,
10891 "ErrorCode,HS20_ICON_REQUEST failed");
10892 return 0;
10893 }
10894 }
10895
10896 return 1;
10897}
10898
10899
10900static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10901 struct sigma_conn *conn,
10902 struct sigma_cmd *cmd)
10903{
10904 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010905 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010906 int chwidth, nss;
10907
10908 val = get_param(cmd, "framename");
10909 if (!val)
10910 return -1;
10911 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10912
10913 /* Command sequence to generate Op mode notification */
10914 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010915 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010916
10917 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010918 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010919
10920 /* Extract Channel width */
10921 val = get_param(cmd, "Channel_width");
10922 if (val) {
10923 switch (atoi(val)) {
10924 case 20:
10925 chwidth = 0;
10926 break;
10927 case 40:
10928 chwidth = 1;
10929 break;
10930 case 80:
10931 chwidth = 2;
10932 break;
10933 case 160:
10934 chwidth = 3;
10935 break;
10936 default:
10937 chwidth = 2;
10938 break;
10939 }
10940
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010941 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010942 }
10943
10944 /* Extract NSS */
10945 val = get_param(cmd, "NSS");
10946 if (val) {
10947 switch (atoi(val)) {
10948 case 1:
10949 nss = 1;
10950 break;
10951 case 2:
10952 nss = 3;
10953 break;
10954 case 3:
10955 nss = 7;
10956 break;
10957 default:
10958 /* We do not support NSS > 3 */
10959 nss = 3;
10960 break;
10961 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010962 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010963 }
10964
10965 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010966 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010967 }
10968
10969 return 1;
10970}
10971
10972
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010973static int wcn_sta_set_pmf_config(struct sigma_dut *dut, const char *intf,
10974 enum send_frame_protection protected)
10975{
10976#ifdef NL80211_SUPPORT
10977 struct nl_msg *msg;
10978 int ret = 0;
10979 struct nlattr *params;
10980 int ifindex;
10981
10982 ifindex = if_nametoindex(intf);
10983 if (ifindex == 0) {
10984 sigma_dut_print(dut, DUT_MSG_ERROR,
10985 "%s: Index for interface %s failed",
10986 __func__, intf);
10987 return -1;
10988 }
10989
10990 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10991 NL80211_CMD_VENDOR)) ||
10992 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
10993 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10994 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10995 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
10996 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10997 nla_put_u8(msg,
10998 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PMF_PROTECTION,
10999 protected)) {
11000 sigma_dut_print(dut, DUT_MSG_ERROR,
11001 "%s: err in adding vendor_cmd and vendor_data",
11002 __func__);
11003 nlmsg_free(msg);
11004 return -1;
11005 }
11006 nla_nest_end(msg, params);
11007
11008 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
11009 if (ret) {
11010 sigma_dut_print(dut, DUT_MSG_ERROR,
11011 "%s: err in send_and_recv_msgs, ret=%d",
11012 __func__, ret);
11013 }
11014 return ret;
11015#else /* NL80211_SUPPORT */
11016 sigma_dut_print(dut, DUT_MSG_ERROR,
11017 "PMF config cannot be set without NL80211_SUPPORT defined");
11018 return -1;
11019#endif /* NL80211_SUPPORT */
11020}
11021
11022
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011023static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
11024 struct sigma_conn *conn,
11025 struct sigma_cmd *cmd)
11026{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011027 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011028 case DRIVER_ATHEROS:
11029 return ath_sta_send_frame_vht(dut, conn, cmd);
11030 default:
11031 send_resp(dut, conn, SIGMA_ERROR,
11032 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
11033 return 0;
11034 }
11035}
11036
11037
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011038static int wcn_sta_send_disassoc(struct sigma_dut *dut, const char *intf)
11039{
11040#ifdef NL80211_SUPPORT
11041 struct nl_msg *msg;
11042 int ret = 0;
11043 struct nlattr *params;
11044 int ifindex;
11045
11046 ifindex = if_nametoindex(intf);
11047 if (ifindex == 0) {
11048 sigma_dut_print(dut, DUT_MSG_ERROR,
11049 "%s: Index for interface %s failed",
11050 __func__, intf);
11051 return -1;
11052 }
11053
11054 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
11055 NL80211_CMD_VENDOR)) ||
11056 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
11057 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
11058 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
11059 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
11060 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
11061 nla_put_flag(msg,
11062 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISASSOC_TX)) {
11063 sigma_dut_print(dut, DUT_MSG_ERROR,
11064 "%s: err in adding vendor_cmd and vendor_data",
11065 __func__);
11066 nlmsg_free(msg);
11067 return -1;
11068 }
11069 nla_nest_end(msg, params);
11070
11071 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
11072 if (ret) {
11073 sigma_dut_print(dut, DUT_MSG_ERROR,
11074 "%s: err in send_and_recv_msgs, ret=%d",
11075 __func__, ret);
11076 }
11077 return ret;
11078#else /* NL80211_SUPPORT */
11079 sigma_dut_print(dut, DUT_MSG_ERROR,
11080 "Disassoc Tx cannot be done without NL80211_SUPPORT defined");
11081 return -1;
11082#endif /* NL80211_SUPPORT */
11083}
11084
11085
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011086static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
11087 struct sigma_cmd *cmd)
11088{
11089 const char *val;
11090 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011091 enum send_frame_protection protected;
11092 const char *pmf;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011093
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011094 if (!intf)
11095 return -1;
11096
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011097 val = get_param(cmd, "framename");
11098 if (!val)
11099 return -1;
11100 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
11101
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011102 pmf = get_param(cmd, "PMFProtected");
11103 if (!pmf)
11104 pmf = get_param(cmd, "Protected");
11105 if (pmf) {
11106 if (strcasecmp(pmf, "Correct-key") == 0 ||
11107 strcasecmp(pmf, "CorrectKey") == 0) {
11108 protected = CORRECT_KEY;
11109 } else if (strcasecmp(pmf, "IncorrectKey") == 0) {
11110 protected = INCORRECT_KEY;
11111 } else if (strcasecmp(pmf, "Unprotected") == 0) {
11112 protected = UNPROTECTED;
11113 } else {
11114 send_resp(dut, conn, SIGMA_ERROR,
11115 "errorCode,Unsupported PMFProtected");
11116 return STATUS_SENT_ERROR;
11117 }
11118 sigma_dut_print(dut, DUT_MSG_DEBUG, "Config PMF protection %d",
11119 protected);
11120 wcn_sta_set_pmf_config(dut, intf, protected);
11121 }
11122
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011123 /* Command sequence to generate Op mode notification */
11124 if (val && strcasecmp(val, "action") == 0) {
11125 val = get_param(cmd, "PPDUTxType");
11126 if (val && strcasecmp(val, "TB") == 0) {
11127 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
11128 sigma_dut_print(dut, DUT_MSG_ERROR,
11129 "failed to send TB PPDU Tx cfg");
11130 send_resp(dut, conn, SIGMA_ERROR,
11131 "ErrorCode,set TB PPDU Tx cfg failed");
11132 return 0;
11133 }
11134 return 1;
11135 }
11136
11137 sigma_dut_print(dut, DUT_MSG_ERROR,
11138 "Action Tx type is not defined");
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011139
11140 return SUCCESS_SEND_STATUS;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011141 }
11142
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011143 if (strcasecmp(val, "disassoc") == 0)
11144 wcn_sta_send_disassoc(dut, intf);
11145
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011146 return 1;
11147}
11148
11149
11150static int cmd_sta_send_frame_he(struct sigma_dut *dut,
11151 struct sigma_conn *conn,
11152 struct sigma_cmd *cmd)
11153{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011154 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011155 case DRIVER_WCN:
11156 return wcn_sta_send_frame_he(dut, conn, cmd);
11157 default:
11158 send_resp(dut, conn, SIGMA_ERROR,
11159 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
11160 return 0;
11161 }
11162}
11163
11164
Lior David0fe101e2017-03-09 16:09:50 +020011165#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011166
11167static int
11168wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
11169 const char *frame_name, const char *dest_mac)
11170{
11171 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
11172 const char *ssid = get_param(cmd, "ssid");
11173 const char *countstr = get_param(cmd, "count");
11174 const char *channelstr = get_param(cmd, "channel");
11175 const char *group_id = get_param(cmd, "groupid");
11176 const char *client_id = get_param(cmd, "clientmac");
11177 int count, channel, freq, i;
11178 const char *fname;
11179 char frame[1024], src_mac[20], group_id_attr[25],
11180 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
11181 const char *group_ssid;
11182 const int group_ssid_prefix_len = 9;
11183 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
11184 size_t framelen = sizeof(frame);
11185 struct template_frame_tag tags[2];
11186 size_t tags_total = ARRAY_SIZE(tags);
11187 int tag_index, len, dst_len;
11188
11189 if (!countstr || !channelstr) {
11190 sigma_dut_print(dut, DUT_MSG_ERROR,
11191 "Missing argument: count, channel");
11192 return -1;
11193 }
11194 if (isprobereq && !ssid) {
11195 sigma_dut_print(dut, DUT_MSG_ERROR,
11196 "Missing argument: ssid");
11197 return -1;
11198 }
11199 if (!isprobereq && (!group_id || !client_id)) {
11200 sigma_dut_print(dut, DUT_MSG_ERROR,
11201 "Missing argument: group_id, client_id");
11202 return -1;
11203 }
11204
11205 count = atoi(countstr);
11206 channel = atoi(channelstr);
11207 freq = channel_to_freq(dut, channel);
11208
11209 if (!freq) {
11210 sigma_dut_print(dut, DUT_MSG_ERROR,
11211 "invalid channel: %s", channelstr);
11212 return -1;
11213 }
11214
11215 if (isprobereq) {
11216 if (strcasecmp(ssid, "wildcard") == 0) {
11217 fname = "probe_req_wildcard.txt";
11218 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
11219 fname = "probe_req_P2P_Wildcard.txt";
11220 } else {
11221 sigma_dut_print(dut, DUT_MSG_ERROR,
11222 "invalid probe request type");
11223 return -1;
11224 }
11225 } else {
11226 fname = "P2P_device_discovery_req.txt";
11227 }
11228
11229 if (parse_template_frame_file(dut, fname, frame, &framelen,
11230 tags, &tags_total)) {
11231 sigma_dut_print(dut, DUT_MSG_ERROR,
11232 "invalid frame template: %s", fname);
11233 return -1;
11234 }
11235
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011236 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011237 src_mac, sizeof(src_mac)) < 0 ||
11238 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
11239 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
11240 return -1;
11241 /* Use wildcard BSSID, since we are in PBSS */
11242 memset(&hdr->addr3, 0xFF, ETH_ALEN);
11243
11244 if (!isprobereq) {
11245 tag_index = find_template_frame_tag(tags, tags_total, 1);
11246 if (tag_index < 0) {
11247 sigma_dut_print(dut, DUT_MSG_ERROR,
11248 "can't find device id attribute");
11249 return -1;
11250 }
11251 if (parse_mac_address(dut, client_id,
11252 (unsigned char *) client_mac)) {
11253 sigma_dut_print(dut, DUT_MSG_ERROR,
11254 "invalid client_id: %s", client_id);
11255 return -1;
11256 }
11257 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11258 framelen - tags[tag_index].offset,
11259 IEEE80211_P2P_ATTR_DEVICE_ID,
11260 client_mac, ETH_ALEN)) {
11261 sigma_dut_print(dut, DUT_MSG_ERROR,
11262 "fail to replace device id attribute");
11263 return -1;
11264 }
11265
11266 /*
11267 * group_id arg contains device MAC address followed by
11268 * space and SSID (DIRECT-somessid).
11269 * group id attribute contains device address (6 bytes)
11270 * followed by SSID prefix DIRECT-XX (9 bytes)
11271 */
11272 if (strlen(group_id) < sizeof(device_macstr)) {
11273 sigma_dut_print(dut, DUT_MSG_ERROR,
11274 "group_id arg too short");
11275 return -1;
11276 }
11277 memcpy(device_macstr, group_id, sizeof(device_macstr));
11278 device_macstr[sizeof(device_macstr) - 1] = '\0';
11279 if (parse_mac_address(dut, device_macstr,
11280 (unsigned char *) group_id_attr)) {
11281 sigma_dut_print(dut, DUT_MSG_ERROR,
11282 "fail to parse device address from group_id");
11283 return -1;
11284 }
11285 group_ssid = strchr(group_id, ' ');
11286 if (!group_ssid) {
11287 sigma_dut_print(dut, DUT_MSG_ERROR,
11288 "invalid group_id arg, no ssid");
11289 return -1;
11290 }
11291 group_ssid++;
11292 len = strlen(group_ssid);
11293 if (len < group_ssid_prefix_len) {
11294 sigma_dut_print(dut, DUT_MSG_ERROR,
11295 "group_id SSID too short");
11296 return -1;
11297 }
11298 dst_len = sizeof(group_id_attr) - ETH_ALEN;
11299 if (len > dst_len) {
11300 sigma_dut_print(dut, DUT_MSG_ERROR,
11301 "group_id SSID (%s) too long",
11302 group_ssid);
11303 return -1;
11304 }
11305
11306 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
11307 tag_index = find_template_frame_tag(tags, tags_total, 2);
11308 if (tag_index < 0) {
11309 sigma_dut_print(dut, DUT_MSG_ERROR,
11310 "can't find group id attribute");
11311 return -1;
11312 }
11313 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11314 framelen - tags[tag_index].offset,
11315 IEEE80211_P2P_ATTR_GROUP_ID,
11316 group_id_attr,
11317 sizeof(group_id_attr))) {
11318 sigma_dut_print(dut, DUT_MSG_ERROR,
11319 "fail to replace group id attribute");
11320 return -1;
11321 }
11322 }
11323
11324 for (i = 0; i < count; i++) {
11325 if (wil6210_transmit_frame(dut, freq,
11326 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
11327 frame, framelen)) {
11328 sigma_dut_print(dut, DUT_MSG_ERROR,
11329 "fail to transmit probe request frame");
11330 return -1;
11331 }
11332 }
11333
11334 return 0;
11335}
11336
11337
Lior David0fe101e2017-03-09 16:09:50 +020011338int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
11339 struct sigma_cmd *cmd)
11340{
11341 const char *frame_name = get_param(cmd, "framename");
11342 const char *mac = get_param(cmd, "dest_mac");
11343
11344 if (!frame_name || !mac) {
11345 sigma_dut_print(dut, DUT_MSG_ERROR,
11346 "framename and dest_mac must be provided");
11347 return -1;
11348 }
11349
11350 if (strcasecmp(frame_name, "brp") == 0) {
11351 const char *l_rx = get_param(cmd, "L-RX");
11352 int l_rx_i;
11353
11354 if (!l_rx) {
11355 sigma_dut_print(dut, DUT_MSG_ERROR,
11356 "L-RX must be provided");
11357 return -1;
11358 }
11359 l_rx_i = atoi(l_rx);
11360
11361 sigma_dut_print(dut, DUT_MSG_INFO,
11362 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
11363 mac, l_rx);
11364 if (l_rx_i != 16) {
11365 sigma_dut_print(dut, DUT_MSG_ERROR,
11366 "unsupported L-RX: %s", l_rx);
11367 return -1;
11368 }
11369
11370 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
11371 return -1;
11372 } else if (strcasecmp(frame_name, "ssw") == 0) {
11373 sigma_dut_print(dut, DUT_MSG_INFO,
11374 "dev_send_frame: SLS, dest_mac %s", mac);
11375 if (wil6210_send_sls(dut, mac))
11376 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011377 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
11378 (strcasecmp(frame_name, "devdiscreq") == 0)) {
11379 sigma_dut_print(dut, DUT_MSG_INFO,
11380 "dev_send_frame: %s, dest_mac %s", frame_name,
11381 mac);
11382 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
11383 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020011384 } else {
11385 sigma_dut_print(dut, DUT_MSG_ERROR,
11386 "unsupported frame type: %s", frame_name);
11387 return -1;
11388 }
11389
11390 return 1;
11391}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011392
Lior David0fe101e2017-03-09 16:09:50 +020011393#endif /* __linux__ */
11394
11395
11396static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
11397 struct sigma_conn *conn,
11398 struct sigma_cmd *cmd)
11399{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011400 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020011401#ifdef __linux__
11402 case DRIVER_WIL6210:
11403 return wil6210_send_frame_60g(dut, conn, cmd);
11404#endif /* __linux__ */
11405 default:
11406 send_resp(dut, conn, SIGMA_ERROR,
11407 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
11408 return 0;
11409 }
11410}
11411
11412
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011413static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
11414 const char *intf, struct sigma_cmd *cmd)
11415{
11416 const char *val, *addr;
11417 char buf[100];
11418
11419 addr = get_param(cmd, "DestMac");
11420 if (!addr) {
11421 send_resp(dut, conn, SIGMA_INVALID,
11422 "ErrorCode,AP MAC address is missing");
11423 return 0;
11424 }
11425
11426 val = get_param(cmd, "ANQPQuery_ID");
11427 if (!val) {
11428 send_resp(dut, conn, SIGMA_INVALID,
11429 "ErrorCode,Missing ANQPQuery_ID");
11430 return 0;
11431 }
11432
11433 if (strcasecmp(val, "NeighborReportReq") == 0) {
11434 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
11435 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
11436 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
11437 } else {
11438 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
11439 val);
11440 send_resp(dut, conn, SIGMA_INVALID,
11441 "ErrorCode,Invalid ANQPQuery_ID");
11442 return 0;
11443 }
11444
Ashwini Patild174f2c2017-04-13 16:49:46 +053011445 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
11446 * (Address3 = Wildcard BSSID when sent to not-associated AP;
11447 * if associated, AP BSSID).
11448 */
11449 if (wpa_command(intf, "SET gas_address3 1") < 0) {
11450 send_resp(dut, conn, SIGMA_ERROR,
11451 "ErrorCode,Failed to set gas_address3");
11452 return 0;
11453 }
11454
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011455 if (wpa_command(intf, buf) < 0) {
11456 send_resp(dut, conn, SIGMA_ERROR,
11457 "ErrorCode,Failed to send ANQP query");
11458 return 0;
11459 }
11460
11461 return 1;
11462}
11463
11464
11465static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
11466 struct sigma_conn *conn,
11467 const char *intf,
11468 struct sigma_cmd *cmd)
11469{
11470 const char *val = get_param(cmd, "FrameName");
11471
11472 if (val && strcasecmp(val, "ANQPQuery") == 0)
11473 return mbo_send_anqp_query(dut, conn, intf, cmd);
11474
11475 return 2;
11476}
11477
11478
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011479static enum sigma_cmd_result cmd_sta_send_frame_wpa3(struct sigma_dut *dut,
11480 struct sigma_conn *conn,
11481 const char *intf,
11482 struct sigma_cmd *cmd)
11483{
11484 const char *val = get_param(cmd, "framename");
11485
11486 if (!val)
11487 return INVALID_SEND_STATUS;
11488
11489 if (strcasecmp(val, "SAQueryReq") == 0) {
11490 val = get_param(cmd, "OCIChannel");
11491
11492 if (!val) {
11493 send_resp(dut, conn, SIGMA_ERROR,
11494 "errorCode,OCIChannel not present");
11495 return STATUS_SENT_ERROR;
11496 }
11497
11498 dut->saquery_oci_freq = channel_to_freq(dut, atoi(val));
11499 if (!dut->saquery_oci_freq) {
11500 send_resp(dut, conn, SIGMA_ERROR,
11501 "errorCode,Invalid OCIChannel number");
11502 return STATUS_SENT_ERROR;
11503 }
11504
11505 return sta_inject_frame(dut, conn, intf, SAQUERY, CORRECT_KEY,
11506 NULL, 0);
11507 }
11508
11509 if (strcasecmp(val, "reassocreq") == 0)
11510 return sta_inject_frame(dut, conn, intf, REASSOCREQ,
11511 CORRECT_KEY, NULL, 0);
11512
11513 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported framename");
11514 return STATUS_SENT_ERROR;
11515}
11516
11517
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011518static enum sigma_cmd_result
11519cmd_sta_send_frame_mscs(struct sigma_dut *dut, struct sigma_conn *conn,
11520 const char *intf, struct sigma_cmd *cmd)
11521{
11522 char buf[128], *pos;
11523 const char *val, *classifier_type = "04", *type;
11524 int len, rem_len;
11525 u8 up_bitmap;
11526
11527 val = get_param(cmd, "FrameName");
11528 type = get_param(cmd, "Request_Type");
11529 if (!val || !type || strcasecmp(val, "MSCSReq") != 0) {
11530 sigma_dut_print(dut, DUT_MSG_ERROR,
11531 "%s: frame name or type not valid", __func__);
11532 return INVALID_SEND_STATUS;
11533 }
11534
11535 rem_len = sizeof(buf);
11536 pos = buf;
11537 if (strcasecmp(type, "add") == 0) {
11538 len = snprintf(pos, rem_len, "MSCS add");
11539 } else if (strcasecmp(type, "update") == 0) {
11540 len = snprintf(pos, rem_len, "MSCS change");
11541 } else if (strcasecmp(type, "remove") == 0) {
11542 if (wpa_command(intf, "MSCS remove") != 0) {
11543 send_resp(dut, conn, SIGMA_ERROR,
11544 "ErrorCode,Failed to send MSCS frame req");
11545 return STATUS_SENT_ERROR;
11546 }
11547 return SUCCESS_SEND_STATUS;
11548 } else {
11549 sigma_dut_print(dut, DUT_MSG_ERROR,
11550 "%s: request type invalid", __func__);
11551 return INVALID_SEND_STATUS;
11552 }
11553
11554 if (len < 0 || len >= rem_len)
11555 goto fail;
11556
11557 pos += len;
11558 rem_len -= len;
11559
11560 val = get_param(cmd, "User_Priority_Bitmap");
11561 if (!val) {
11562 sigma_dut_print(dut, DUT_MSG_ERROR,
11563 "%s: user priority bitmap empty", __func__);
11564 return INVALID_SEND_STATUS;
11565 }
11566
11567 switch (atoi(val)) {
11568 case 0:
11569 up_bitmap = 0x00;
11570 break;
11571 case 1:
11572 up_bitmap = 0xF0;
11573 break;
11574 case 2:
11575 up_bitmap = 0xF6;
11576 break;
11577 default:
11578 sigma_dut_print(dut, DUT_MSG_ERROR,
11579 "%s: Unknown User_Priority_Bitmap value %d",
11580 __func__, atoi(val));
11581 return INVALID_SEND_STATUS;
11582 }
11583
11584 len = snprintf(pos, rem_len, " up_bitmap=%02x", up_bitmap);
11585 if (len < 0 || len >= rem_len)
11586 goto fail;
11587
11588 pos += len;
11589 rem_len -= len;
11590
11591 val = get_param(cmd, "User_Priority_Limit");
11592 if (!val) {
11593 sigma_dut_print(dut, DUT_MSG_ERROR,
11594 "%s: invalid user priority limit", __func__);
11595 return INVALID_SEND_STATUS;
11596 }
11597
11598 len = snprintf(pos, rem_len, " up_limit=%s", val);
11599 if (len < 0 || len >= rem_len)
11600 goto fail;
11601
11602 pos += len;
11603 rem_len -= len;
11604
11605 val = get_param(cmd, "Stream_Timeout");
11606 if (!val)
11607 val = get_param(cmd, "Stream_Timtout");
11608 if (!val) {
11609 sigma_dut_print(dut, DUT_MSG_ERROR,
11610 "%s: invalid stream timeout", __func__);
11611 return INVALID_SEND_STATUS;
11612 }
11613
11614 len = snprintf(pos, rem_len, " stream_timeout=%s", val);
11615 if (len < 0 || len >= rem_len)
11616 goto fail;
11617
11618 pos += len;
11619 rem_len -= len;
11620
11621 val = get_param(cmd, "TCLAS_Mask");
11622 if (!val) {
11623 sigma_dut_print(dut, DUT_MSG_ERROR,
11624 "%s: invalid tclas mask", __func__);
11625 return INVALID_SEND_STATUS;
11626 }
11627
11628 len = snprintf(pos, rem_len, " frame_classifier=%s%lx%032x",
11629 classifier_type, strtol(val, NULL, 2), 0);
11630 if (len < 0 || len >= rem_len)
11631 goto fail;
11632
11633 if (wpa_command(intf, buf) != 0) {
11634 send_resp(dut, conn, SIGMA_ERROR,
11635 "ErrorCode,Failed to send MSCS frame req");
11636 return STATUS_SENT_ERROR;
11637 }
11638
11639 sigma_dut_print(dut, DUT_MSG_DEBUG,
11640 "MSCS frame request sent: %s", buf);
11641
11642 return SUCCESS_SEND_STATUS;
11643fail:
11644 sigma_dut_print(dut, DUT_MSG_ERROR,
11645 "Failed to create MSCS frame req");
11646 return ERROR_SEND_STATUS;
11647}
11648
11649
Jouni Malinenf7222712019-06-13 01:50:21 +030011650enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
11651 struct sigma_conn *conn,
11652 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011653{
11654 const char *intf = get_param(cmd, "Interface");
11655 const char *val;
11656 enum send_frame_type frame;
11657 enum send_frame_protection protected;
11658 char buf[100];
11659 unsigned char addr[ETH_ALEN];
11660 int res;
11661
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011662 if (!intf)
11663 return -1;
11664
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011665 val = get_param(cmd, "program");
11666 if (val == NULL)
11667 val = get_param(cmd, "frame");
11668 if (val && strcasecmp(val, "TDLS") == 0)
11669 return cmd_sta_send_frame_tdls(dut, conn, cmd);
11670 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011671 strcasecmp(val, "HS2-R2") == 0 ||
11672 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011673 return cmd_sta_send_frame_hs2(dut, conn, cmd);
11674 if (val && strcasecmp(val, "VHT") == 0)
11675 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011676 if (val && strcasecmp(val, "HE") == 0)
11677 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070011678 if (val && strcasecmp(val, "LOC") == 0)
11679 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020011680 if (val && strcasecmp(val, "60GHz") == 0)
11681 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011682 if (val && strcasecmp(val, "MBO") == 0) {
11683 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
11684 if (res != 2)
11685 return res;
11686 }
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011687 if (val && strcasecmp(val, "WPA3") == 0)
11688 return cmd_sta_send_frame_wpa3(dut, conn, intf, cmd);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011689 if (val && strcasecmp(val, "QM") == 0)
11690 return cmd_sta_send_frame_mscs(dut, conn, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011691
11692 val = get_param(cmd, "TD_DISC");
11693 if (val) {
11694 if (hwaddr_aton(val, addr) < 0)
11695 return -1;
11696 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
11697 if (wpa_command(intf, buf) < 0) {
11698 send_resp(dut, conn, SIGMA_ERROR,
11699 "ErrorCode,Failed to send TDLS discovery");
11700 return 0;
11701 }
11702 return 1;
11703 }
11704
11705 val = get_param(cmd, "TD_Setup");
11706 if (val) {
11707 if (hwaddr_aton(val, addr) < 0)
11708 return -1;
11709 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
11710 if (wpa_command(intf, buf) < 0) {
11711 send_resp(dut, conn, SIGMA_ERROR,
11712 "ErrorCode,Failed to start TDLS setup");
11713 return 0;
11714 }
11715 return 1;
11716 }
11717
11718 val = get_param(cmd, "TD_TearDown");
11719 if (val) {
11720 if (hwaddr_aton(val, addr) < 0)
11721 return -1;
11722 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
11723 if (wpa_command(intf, buf) < 0) {
11724 send_resp(dut, conn, SIGMA_ERROR,
11725 "ErrorCode,Failed to tear down TDLS link");
11726 return 0;
11727 }
11728 return 1;
11729 }
11730
11731 val = get_param(cmd, "TD_ChannelSwitch");
11732 if (val) {
11733 /* TODO */
11734 send_resp(dut, conn, SIGMA_ERROR,
11735 "ErrorCode,TD_ChannelSwitch not yet supported");
11736 return 0;
11737 }
11738
11739 val = get_param(cmd, "TD_NF");
11740 if (val) {
11741 /* TODO */
11742 send_resp(dut, conn, SIGMA_ERROR,
11743 "ErrorCode,TD_NF not yet supported");
11744 return 0;
11745 }
11746
11747 val = get_param(cmd, "PMFFrameType");
11748 if (val == NULL)
11749 val = get_param(cmd, "FrameName");
11750 if (val == NULL)
11751 val = get_param(cmd, "Type");
11752 if (val == NULL)
11753 return -1;
11754 if (strcasecmp(val, "disassoc") == 0)
11755 frame = DISASSOC;
11756 else if (strcasecmp(val, "deauth") == 0)
11757 frame = DEAUTH;
11758 else if (strcasecmp(val, "saquery") == 0)
11759 frame = SAQUERY;
11760 else if (strcasecmp(val, "auth") == 0)
11761 frame = AUTH;
11762 else if (strcasecmp(val, "assocreq") == 0)
11763 frame = ASSOCREQ;
11764 else if (strcasecmp(val, "reassocreq") == 0)
11765 frame = REASSOCREQ;
11766 else if (strcasecmp(val, "neigreq") == 0) {
11767 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
11768
11769 val = get_param(cmd, "ssid");
11770 if (val == NULL)
11771 return -1;
11772
11773 res = send_neighbor_request(dut, intf, val);
11774 if (res) {
11775 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11776 "Failed to send neighbor report request");
11777 return 0;
11778 }
11779
11780 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053011781 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
11782 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011783 sigma_dut_print(dut, DUT_MSG_DEBUG,
11784 "Got Transition Management Query");
11785
Ashwini Patil5acd7382017-04-13 15:55:04 +053011786 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011787 if (res) {
11788 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11789 "Failed to send Transition Management Query");
11790 return 0;
11791 }
11792
11793 return 1;
11794 } else {
11795 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11796 "PMFFrameType");
11797 return 0;
11798 }
11799
11800 val = get_param(cmd, "PMFProtected");
11801 if (val == NULL)
11802 val = get_param(cmd, "Protected");
11803 if (val == NULL)
11804 return -1;
11805 if (strcasecmp(val, "Correct-key") == 0 ||
11806 strcasecmp(val, "CorrectKey") == 0)
11807 protected = CORRECT_KEY;
11808 else if (strcasecmp(val, "IncorrectKey") == 0)
11809 protected = INCORRECT_KEY;
11810 else if (strcasecmp(val, "Unprotected") == 0)
11811 protected = UNPROTECTED;
11812 else {
11813 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11814 "PMFProtected");
11815 return 0;
11816 }
11817
11818 if (protected != UNPROTECTED &&
11819 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
11820 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
11821 "PMFProtected for auth/assocreq/reassocreq");
11822 return 0;
11823 }
11824
11825 if (if_nametoindex("sigmadut") == 0) {
11826 snprintf(buf, sizeof(buf),
11827 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011828 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011829 if (system(buf) != 0 ||
11830 if_nametoindex("sigmadut") == 0) {
11831 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11832 "monitor interface with '%s'", buf);
11833 return -2;
11834 }
11835 }
11836
11837 if (system("ifconfig sigmadut up") != 0) {
11838 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11839 "monitor interface up");
11840 return -2;
11841 }
11842
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011843 return sta_inject_frame(dut, conn, intf, frame, protected, NULL, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011844}
11845
11846
11847static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
11848 struct sigma_conn *conn,
11849 struct sigma_cmd *cmd,
11850 const char *ifname)
11851{
11852 char buf[200];
11853 const char *val;
11854
11855 val = get_param(cmd, "ClearARP");
11856 if (val && atoi(val) == 1) {
11857 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
11858 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11859 if (system(buf) != 0) {
11860 send_resp(dut, conn, SIGMA_ERROR,
11861 "errorCode,Failed to clear ARP cache");
11862 return 0;
11863 }
11864 }
11865
11866 return 1;
11867}
11868
11869
11870int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
11871 struct sigma_cmd *cmd)
11872{
11873 const char *intf = get_param(cmd, "Interface");
11874 const char *val;
11875
11876 if (intf == NULL)
11877 return -1;
11878
11879 val = get_param(cmd, "program");
11880 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011881 strcasecmp(val, "HS2-R2") == 0 ||
11882 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011883 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
11884
11885 return -1;
11886}
11887
11888
Jouni Malinenf7222712019-06-13 01:50:21 +030011889static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
11890 struct sigma_conn *conn,
11891 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011892{
11893 const char *intf = get_param(cmd, "Interface");
11894 const char *mac = get_param(cmd, "MAC");
11895
11896 if (intf == NULL || mac == NULL)
11897 return -1;
11898
11899 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
11900 "interface %s to %s", intf, mac);
11901
11902 if (dut->set_macaddr) {
11903 char buf[128];
11904 int res;
11905 if (strcasecmp(mac, "default") == 0) {
11906 res = snprintf(buf, sizeof(buf), "%s",
11907 dut->set_macaddr);
11908 dut->tmp_mac_addr = 0;
11909 } else {
11910 res = snprintf(buf, sizeof(buf), "%s %s",
11911 dut->set_macaddr, mac);
11912 dut->tmp_mac_addr = 1;
11913 }
11914 if (res < 0 || res >= (int) sizeof(buf))
11915 return -1;
11916 if (system(buf) != 0) {
11917 send_resp(dut, conn, SIGMA_ERROR,
11918 "errorCode,Failed to set MAC "
11919 "address");
11920 return 0;
11921 }
11922 return 1;
11923 }
11924
11925 if (strcasecmp(mac, "default") == 0)
11926 return 1;
11927
11928 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11929 "command");
11930 return 0;
11931}
11932
11933
11934static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
11935 struct sigma_conn *conn, const char *intf,
11936 int val)
11937{
11938 char buf[200];
11939 int res;
11940
11941 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
11942 intf, val);
11943 if (res < 0 || res >= (int) sizeof(buf))
11944 return -1;
11945 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11946 if (system(buf) != 0) {
11947 send_resp(dut, conn, SIGMA_ERROR,
11948 "errorCode,Failed to configure offchannel mode");
11949 return 0;
11950 }
11951
11952 return 1;
11953}
11954
11955
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011956static int off_chan_val(enum sec_ch_offset off)
11957{
11958 switch (off) {
11959 case SEC_CH_NO:
11960 return 0;
11961 case SEC_CH_40ABOVE:
11962 return 40;
11963 case SEC_CH_40BELOW:
11964 return -40;
11965 }
11966
11967 return 0;
11968}
11969
11970
11971static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
11972 const char *intf, int off_ch_num,
11973 enum sec_ch_offset sec)
11974{
11975 char buf[200];
11976 int res;
11977
11978 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
11979 intf, off_ch_num);
11980 if (res < 0 || res >= (int) sizeof(buf))
11981 return -1;
11982 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11983 if (system(buf) != 0) {
11984 send_resp(dut, conn, SIGMA_ERROR,
11985 "errorCode,Failed to set offchan");
11986 return 0;
11987 }
11988
11989 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
11990 intf, off_chan_val(sec));
11991 if (res < 0 || res >= (int) sizeof(buf))
11992 return -1;
11993 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11994 if (system(buf) != 0) {
11995 send_resp(dut, conn, SIGMA_ERROR,
11996 "errorCode,Failed to set sec chan offset");
11997 return 0;
11998 }
11999
12000 return 1;
12001}
12002
12003
12004static int tdls_set_offchannel_offset(struct sigma_dut *dut,
12005 struct sigma_conn *conn,
12006 const char *intf, int off_ch_num,
12007 enum sec_ch_offset sec)
12008{
12009 char buf[200];
12010 int res;
12011
12012 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
12013 off_ch_num);
12014 if (res < 0 || res >= (int) sizeof(buf))
12015 return -1;
12016 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12017
12018 if (wpa_command(intf, buf) < 0) {
12019 send_resp(dut, conn, SIGMA_ERROR,
12020 "ErrorCode,Failed to set offchan");
12021 return 0;
12022 }
12023 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
12024 off_chan_val(sec));
12025 if (res < 0 || res >= (int) sizeof(buf))
12026 return -1;
12027
12028 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12029
12030 if (wpa_command(intf, buf) < 0) {
12031 send_resp(dut, conn, SIGMA_ERROR,
12032 "ErrorCode,Failed to set sec chan offset");
12033 return 0;
12034 }
12035
12036 return 1;
12037}
12038
12039
12040static int tdls_set_offchannel_mode(struct sigma_dut *dut,
12041 struct sigma_conn *conn,
12042 const char *intf, int val)
12043{
12044 char buf[200];
12045 int res;
12046
12047 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
12048 val);
12049 if (res < 0 || res >= (int) sizeof(buf))
12050 return -1;
12051 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12052
12053 if (wpa_command(intf, buf) < 0) {
12054 send_resp(dut, conn, SIGMA_ERROR,
12055 "ErrorCode,Failed to configure offchannel mode");
12056 return 0;
12057 }
12058
12059 return 1;
12060}
12061
12062
12063static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
12064 struct sigma_conn *conn,
12065 struct sigma_cmd *cmd)
12066{
12067 const char *val;
12068 enum {
12069 CHSM_NOT_SET,
12070 CHSM_ENABLE,
12071 CHSM_DISABLE,
12072 CHSM_REJREQ,
12073 CHSM_UNSOLRESP
12074 } chsm = CHSM_NOT_SET;
12075 int off_ch_num = -1;
12076 enum sec_ch_offset sec_ch = SEC_CH_NO;
12077 int res;
12078
12079 val = get_param(cmd, "Uapsd");
12080 if (val) {
12081 char buf[100];
12082 if (strcasecmp(val, "Enable") == 0)
12083 snprintf(buf, sizeof(buf), "SET ps 99");
12084 else if (strcasecmp(val, "Disable") == 0)
12085 snprintf(buf, sizeof(buf), "SET ps 98");
12086 else {
12087 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
12088 "Unsupported uapsd parameter value");
12089 return 0;
12090 }
12091 if (wpa_command(intf, buf)) {
12092 send_resp(dut, conn, SIGMA_ERROR,
12093 "ErrorCode,Failed to change U-APSD "
12094 "powersave mode");
12095 return 0;
12096 }
12097 }
12098
12099 val = get_param(cmd, "TPKTIMER");
12100 if (val && strcasecmp(val, "DISABLE") == 0) {
12101 if (wpa_command(intf, "SET tdls_testing 0x100")) {
12102 send_resp(dut, conn, SIGMA_ERROR,
12103 "ErrorCode,Failed to enable no TPK "
12104 "expiration test mode");
12105 return 0;
12106 }
12107 dut->no_tpk_expiration = 1;
12108 }
12109
12110 val = get_param(cmd, "ChSwitchMode");
12111 if (val) {
12112 if (strcasecmp(val, "Enable") == 0 ||
12113 strcasecmp(val, "Initiate") == 0)
12114 chsm = CHSM_ENABLE;
12115 else if (strcasecmp(val, "Disable") == 0 ||
12116 strcasecmp(val, "passive") == 0)
12117 chsm = CHSM_DISABLE;
12118 else if (strcasecmp(val, "RejReq") == 0)
12119 chsm = CHSM_REJREQ;
12120 else if (strcasecmp(val, "UnSolResp") == 0)
12121 chsm = CHSM_UNSOLRESP;
12122 else {
12123 send_resp(dut, conn, SIGMA_ERROR,
12124 "ErrorCode,Unknown ChSwitchMode value");
12125 return 0;
12126 }
12127 }
12128
12129 val = get_param(cmd, "OffChNum");
12130 if (val) {
12131 off_ch_num = atoi(val);
12132 if (off_ch_num == 0) {
12133 send_resp(dut, conn, SIGMA_ERROR,
12134 "ErrorCode,Invalid OffChNum");
12135 return 0;
12136 }
12137 }
12138
12139 val = get_param(cmd, "SecChOffset");
12140 if (val) {
12141 if (strcmp(val, "20") == 0)
12142 sec_ch = SEC_CH_NO;
12143 else if (strcasecmp(val, "40above") == 0)
12144 sec_ch = SEC_CH_40ABOVE;
12145 else if (strcasecmp(val, "40below") == 0)
12146 sec_ch = SEC_CH_40BELOW;
12147 else {
12148 send_resp(dut, conn, SIGMA_ERROR,
12149 "ErrorCode,Unknown SecChOffset value");
12150 return 0;
12151 }
12152 }
12153
12154 if (chsm == CHSM_NOT_SET) {
12155 /* no offchannel changes requested */
12156 return 1;
12157 }
12158
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012159 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
12160 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012161 send_resp(dut, conn, SIGMA_ERROR,
12162 "ErrorCode,Unknown interface");
12163 return 0;
12164 }
12165
12166 switch (chsm) {
12167 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030012168 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012169 break;
12170 case CHSM_ENABLE:
12171 if (off_ch_num < 0) {
12172 send_resp(dut, conn, SIGMA_ERROR,
12173 "ErrorCode,Missing OffChNum argument");
12174 return 0;
12175 }
12176 if (wifi_chip_type == DRIVER_WCN) {
12177 res = tdls_set_offchannel_offset(dut, conn, intf,
12178 off_ch_num, sec_ch);
12179 } else {
12180 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
12181 sec_ch);
12182 }
12183 if (res != 1)
12184 return res;
12185 if (wifi_chip_type == DRIVER_WCN)
12186 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
12187 else
12188 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
12189 break;
12190 case CHSM_DISABLE:
12191 if (wifi_chip_type == DRIVER_WCN)
12192 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
12193 else
12194 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
12195 break;
12196 case CHSM_REJREQ:
12197 if (wifi_chip_type == DRIVER_WCN)
12198 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
12199 else
12200 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
12201 break;
12202 case CHSM_UNSOLRESP:
12203 if (off_ch_num < 0) {
12204 send_resp(dut, conn, SIGMA_ERROR,
12205 "ErrorCode,Missing OffChNum argument");
12206 return 0;
12207 }
12208 if (wifi_chip_type == DRIVER_WCN) {
12209 res = tdls_set_offchannel_offset(dut, conn, intf,
12210 off_ch_num, sec_ch);
12211 } else {
12212 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
12213 sec_ch);
12214 }
12215 if (res != 1)
12216 return res;
12217 if (wifi_chip_type == DRIVER_WCN)
12218 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
12219 else
12220 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
12221 break;
12222 }
12223
12224 return res;
12225}
12226
12227
12228static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
12229 struct sigma_conn *conn,
12230 struct sigma_cmd *cmd)
12231{
12232 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053012233 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012234
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070012235 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080012236
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012237 val = get_param(cmd, "nss_mcs_opt");
12238 if (val) {
12239 /* String (nss_operating_mode; mcs_operating_mode) */
12240 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012241 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012242
12243 token = strdup(val);
12244 if (!token)
12245 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012246 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053012247 if (!result) {
12248 sigma_dut_print(dut, DUT_MSG_ERROR,
12249 "VHT NSS not specified");
12250 goto failed;
12251 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012252 if (strcasecmp(result, "def") != 0) {
12253 nss = atoi(result);
12254 if (nss == 4)
12255 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012256 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012257 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012258
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012259 }
12260
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012261 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053012262 if (!result) {
12263 sigma_dut_print(dut, DUT_MSG_ERROR,
12264 "VHT MCS not specified");
12265 goto failed;
12266 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012267 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012268 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012269 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012270 } else {
12271 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012272 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012273 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012274 }
12275 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012276 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012277 }
12278
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053012279 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012280 return 1;
12281failed:
12282 free(token);
12283 return 0;
12284}
12285
12286
12287static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
12288 struct sigma_conn *conn,
12289 struct sigma_cmd *cmd)
12290{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012291 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012292 case DRIVER_ATHEROS:
12293 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
12294 default:
12295 send_resp(dut, conn, SIGMA_ERROR,
12296 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
12297 return 0;
12298 }
12299}
12300
12301
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012302static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12303 struct sigma_conn *conn,
12304 struct sigma_cmd *cmd)
12305{
12306 const char *val;
12307 char *token = NULL, *result;
12308 char buf[60];
12309
12310 val = get_param(cmd, "nss_mcs_opt");
12311 if (val) {
12312 /* String (nss_operating_mode; mcs_operating_mode) */
12313 int nss, mcs, ratecode;
12314 char *saveptr;
12315
12316 token = strdup(val);
12317 if (!token)
12318 return -2;
12319
12320 result = strtok_r(token, ";", &saveptr);
12321 if (!result) {
12322 sigma_dut_print(dut, DUT_MSG_ERROR,
12323 "HE NSS not specified");
12324 goto failed;
12325 }
12326 nss = 1;
12327 if (strcasecmp(result, "def") != 0)
12328 nss = atoi(result);
12329
12330 result = strtok_r(NULL, ";", &saveptr);
12331 if (!result) {
12332 sigma_dut_print(dut, DUT_MSG_ERROR,
12333 "HE MCS not specified");
12334 goto failed;
12335 }
12336 mcs = 7;
12337 if (strcasecmp(result, "def") != 0)
12338 mcs = atoi(result);
12339
Arif Hussain557bf412018-05-25 17:29:36 -070012340 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012341 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070012342 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012343 } else if (nss > 2) {
12344 sigma_dut_print(dut, DUT_MSG_ERROR,
12345 "HE NSS %d not supported", nss);
12346 goto failed;
12347 }
12348
Arif Hussain557bf412018-05-25 17:29:36 -070012349 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
12350 if (system(buf) != 0) {
12351 sigma_dut_print(dut, DUT_MSG_ERROR,
12352 "nss_mcs_opt: iwpriv %s nss %d failed",
12353 intf, nss);
12354 goto failed;
12355 }
Arif Hussainac6c5112018-05-25 17:34:00 -070012356 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070012357
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012358 /* Add the MCS to the ratecode */
12359 if (mcs >= 0 && mcs <= 11) {
12360 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070012361#ifdef NL80211_SUPPORT
12362 if (dut->device_type == STA_testbed) {
12363 enum he_mcs_config mcs_config;
12364 int ret;
12365
12366 if (mcs <= 7)
12367 mcs_config = HE_80_MCS0_7;
12368 else if (mcs <= 9)
12369 mcs_config = HE_80_MCS0_9;
12370 else
12371 mcs_config = HE_80_MCS0_11;
12372 ret = sta_set_he_mcs(dut, intf, mcs_config);
12373 if (ret) {
12374 sigma_dut_print(dut, DUT_MSG_ERROR,
12375 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
12376 mcs, mcs_config, ret);
12377 goto failed;
12378 }
12379 }
12380#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012381 } else {
12382 sigma_dut_print(dut, DUT_MSG_ERROR,
12383 "HE MCS %d not supported", mcs);
12384 goto failed;
12385 }
12386 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
12387 intf, ratecode);
12388 if (system(buf) != 0) {
12389 sigma_dut_print(dut, DUT_MSG_ERROR,
12390 "iwpriv setting of 11ax rates failed");
12391 goto failed;
12392 }
12393 free(token);
12394 }
12395
12396 val = get_param(cmd, "GI");
12397 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012398 int fix_rate_sgi;
12399
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012400 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012401 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012402 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012403 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012404 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
12405 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012406 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012407 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012408 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
12409 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012410 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012411 } else {
12412 send_resp(dut, conn, SIGMA_ERROR,
12413 "errorCode,GI value not supported");
12414 return 0;
12415 }
12416 if (system(buf) != 0) {
12417 send_resp(dut, conn, SIGMA_ERROR,
12418 "errorCode,Failed to set shortgi");
12419 return 0;
12420 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012421 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
12422 intf, fix_rate_sgi);
12423 if (system(buf) != 0) {
12424 send_resp(dut, conn, SIGMA_ERROR,
12425 "errorCode,Failed to set fix rate shortgi");
12426 return STATUS_SENT;
12427 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012428 }
12429
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012430 val = get_param(cmd, "LTF");
12431 if (val) {
12432#ifdef NL80211_SUPPORT
12433 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012434 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012435 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012436 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012437 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012438 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012439 } else {
12440 send_resp(dut, conn, SIGMA_ERROR,
12441 "errorCode, LTF value not supported");
12442 return 0;
12443 }
12444#else /* NL80211_SUPPORT */
12445 sigma_dut_print(dut, DUT_MSG_ERROR,
12446 "LTF cannot be set without NL80211_SUPPORT defined");
12447 return -2;
12448#endif /* NL80211_SUPPORT */
12449 }
12450
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070012451 val = get_param(cmd, "TxSUPPDU");
12452 if (val) {
12453 int set_val = 1;
12454
12455 if (strcasecmp(val, "Enable") == 0)
12456 set_val = 1;
12457 else if (strcasecmp(val, "Disable") == 0)
12458 set_val = 0;
12459
12460 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
12461 send_resp(dut, conn, SIGMA_ERROR,
12462 "ErrorCode,Failed to set Tx SU PPDU config");
12463 return 0;
12464 }
12465 }
12466
Arif Hussain480d5f42019-03-12 14:40:42 -070012467 val = get_param(cmd, "TWT_Setup");
12468 if (val) {
12469 if (strcasecmp(val, "Request") == 0) {
12470 if (sta_twt_request(dut, conn, cmd)) {
12471 send_resp(dut, conn, SIGMA_ERROR,
12472 "ErrorCode,sta_twt_request failed");
12473 return STATUS_SENT;
12474 }
12475 } else if (strcasecmp(val, "Teardown") == 0) {
12476 if (sta_twt_teardown(dut, conn, cmd)) {
12477 send_resp(dut, conn, SIGMA_ERROR,
12478 "ErrorCode,sta_twt_teardown failed");
12479 return STATUS_SENT;
12480 }
12481 }
12482 }
12483
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080012484 val = get_param(cmd, "transmitOMI");
12485 if (val && sta_transmit_omi(dut, conn, cmd)) {
12486 send_resp(dut, conn, SIGMA_ERROR,
12487 "ErrorCode,sta_transmit_omi failed");
12488 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070012489 }
12490
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012491 val = get_param(cmd, "Powersave");
12492 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012493 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012494
12495 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012496 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012497 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012498 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012499 } else {
12500 sigma_dut_print(dut, DUT_MSG_ERROR,
12501 "Unsupported Powersave value '%s'",
12502 val);
12503 return -1;
12504 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012505 if (set_power_save_wcn(dut, intf, ps) < 0)
12506 return 0;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012507 }
12508
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080012509 val = get_param(cmd, "MU_EDCA");
12510 if (val) {
12511 if (strcasecmp(val, "Override") == 0) {
12512 if (sta_set_mu_edca_override(dut, intf, 1)) {
12513 send_resp(dut, conn, SIGMA_ERROR,
12514 "errorCode,MU EDCA override set failed");
12515 return STATUS_SENT;
12516 }
12517 } else if (strcasecmp(val, "Disable") == 0) {
12518 if (sta_set_mu_edca_override(dut, intf, 0)) {
12519 send_resp(dut, conn, SIGMA_ERROR,
12520 "errorCode,MU EDCA override disable failed");
12521 return STATUS_SENT;
12522 }
12523 }
12524 }
12525
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -070012526 val = get_param(cmd, "Ch_Pref");
12527 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12528 return STATUS_SENT;
12529
12530 val = get_param(cmd, "Cellular_Data_Cap");
12531 if (val && mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12532 return STATUS_SENT;
12533
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012534 return 1;
12535
12536failed:
12537 free(token);
12538 return -2;
12539}
12540
12541
12542static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12543 struct sigma_conn *conn,
12544 struct sigma_cmd *cmd)
12545{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012546 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012547 case DRIVER_WCN:
12548 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
12549 default:
12550 send_resp(dut, conn, SIGMA_ERROR,
12551 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
12552 return 0;
12553 }
12554}
12555
12556
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012557static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
12558 struct sigma_conn *conn,
12559 struct sigma_cmd *cmd)
12560{
12561 const char *val;
12562
12563 val = get_param(cmd, "powersave");
12564 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012565 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012566
12567 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012568 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012569 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012570 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012571 } else {
12572 sigma_dut_print(dut, DUT_MSG_ERROR,
12573 "Unsupported power save config");
12574 return -1;
12575 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012576 if (set_power_save_wcn(dut, intf, ps) < 0)
12577 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012578 return 1;
12579 }
12580
12581 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
12582
12583 return 0;
12584}
12585
12586
Ashwini Patil5acd7382017-04-13 15:55:04 +053012587static int btm_query_candidate_list(struct sigma_dut *dut,
12588 struct sigma_conn *conn,
12589 struct sigma_cmd *cmd)
12590{
12591 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
12592 int len, ret;
12593 char buf[10];
12594
12595 /*
12596 * Neighbor Report elements format:
12597 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
12598 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
12599 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
12600 */
12601
12602 bssid = get_param(cmd, "Nebor_BSSID");
12603 if (!bssid) {
12604 send_resp(dut, conn, SIGMA_INVALID,
12605 "errorCode,Nebor_BSSID is missing");
12606 return 0;
12607 }
12608
12609 info = get_param(cmd, "Nebor_Bssid_Info");
12610 if (!info) {
12611 sigma_dut_print(dut, DUT_MSG_INFO,
12612 "Using default value for Nebor_Bssid_Info: %s",
12613 DEFAULT_NEIGHBOR_BSSID_INFO);
12614 info = DEFAULT_NEIGHBOR_BSSID_INFO;
12615 }
12616
12617 op_class = get_param(cmd, "Nebor_Op_Class");
12618 if (!op_class) {
12619 send_resp(dut, conn, SIGMA_INVALID,
12620 "errorCode,Nebor_Op_Class is missing");
12621 return 0;
12622 }
12623
12624 ch = get_param(cmd, "Nebor_Op_Ch");
12625 if (!ch) {
12626 send_resp(dut, conn, SIGMA_INVALID,
12627 "errorCode,Nebor_Op_Ch is missing");
12628 return 0;
12629 }
12630
12631 phy_type = get_param(cmd, "Nebor_Phy_Type");
12632 if (!phy_type) {
12633 sigma_dut_print(dut, DUT_MSG_INFO,
12634 "Using default value for Nebor_Phy_Type: %s",
12635 DEFAULT_NEIGHBOR_PHY_TYPE);
12636 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
12637 }
12638
12639 /* Parse optional subelements */
12640 buf[0] = '\0';
12641 pref = get_param(cmd, "Nebor_Pref");
12642 if (pref) {
12643 /* hexdump for preferrence subelement */
12644 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
12645 if (ret < 0 || ret >= (int) sizeof(buf)) {
12646 sigma_dut_print(dut, DUT_MSG_ERROR,
12647 "snprintf failed for optional subelement ret: %d",
12648 ret);
12649 send_resp(dut, conn, SIGMA_ERROR,
12650 "errorCode,snprintf failed for subelement");
12651 return 0;
12652 }
12653 }
12654
12655 if (!dut->btm_query_cand_list) {
12656 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
12657 if (!dut->btm_query_cand_list) {
12658 send_resp(dut, conn, SIGMA_ERROR,
12659 "errorCode,Failed to allocate memory for btm_query_cand_list");
12660 return 0;
12661 }
12662 }
12663
12664 len = strlen(dut->btm_query_cand_list);
12665 ret = snprintf(dut->btm_query_cand_list + len,
12666 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
12667 bssid, info, op_class, ch, phy_type, buf);
12668 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
12669 sigma_dut_print(dut, DUT_MSG_ERROR,
12670 "snprintf failed for neighbor report list ret: %d",
12671 ret);
12672 send_resp(dut, conn, SIGMA_ERROR,
12673 "errorCode,snprintf failed for neighbor report");
12674 free(dut->btm_query_cand_list);
12675 dut->btm_query_cand_list = NULL;
12676 return 0;
12677 }
12678
12679 return 1;
12680}
12681
12682
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012683int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
12684 struct sigma_ese_alloc *allocs, int *allocs_size)
12685{
12686 int max_count = *allocs_size;
12687 int count = 0, i;
12688 const char *val;
12689
12690 do {
12691 val = get_param_indexed(cmd, "AllocID", count);
12692 if (val)
12693 count++;
12694 } while (val);
12695
12696 if (count == 0 || count > max_count) {
12697 sigma_dut_print(dut, DUT_MSG_ERROR,
12698 "Invalid number of allocations(%d)", count);
12699 return -1;
12700 }
12701
12702 for (i = 0; i < count; i++) {
12703 val = get_param_indexed(cmd, "PercentBI", i);
12704 if (!val) {
12705 sigma_dut_print(dut, DUT_MSG_ERROR,
12706 "Missing PercentBI parameter at index %d",
12707 i);
12708 return -1;
12709 }
12710 allocs[i].percent_bi = atoi(val);
12711
12712 val = get_param_indexed(cmd, "SrcAID", i);
12713 if (val)
12714 allocs[i].src_aid = strtol(val, NULL, 0);
12715 else
12716 allocs[i].src_aid = ESE_BCAST_AID;
12717
12718 val = get_param_indexed(cmd, "DestAID", i);
12719 if (val)
12720 allocs[i].dst_aid = strtol(val, NULL, 0);
12721 else
12722 allocs[i].dst_aid = ESE_BCAST_AID;
12723
12724 allocs[i].type = ESE_CBAP;
12725 sigma_dut_print(dut, DUT_MSG_INFO,
12726 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
12727 i, allocs[i].percent_bi, allocs[i].src_aid,
12728 allocs[i].dst_aid);
12729 }
12730
12731 *allocs_size = count;
12732 return 0;
12733}
12734
12735
12736static int sta_set_60g_ese(struct sigma_dut *dut, int count,
12737 struct sigma_ese_alloc *allocs)
12738{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012739 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012740#ifdef __linux__
12741 case DRIVER_WIL6210:
12742 if (wil6210_set_ese(dut, count, allocs))
12743 return -1;
12744 return 1;
12745#endif /* __linux__ */
12746 default:
12747 sigma_dut_print(dut, DUT_MSG_ERROR,
12748 "Unsupported sta_set_60g_ese with the current driver");
12749 return -1;
12750 }
12751}
12752
12753
12754static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
12755 struct sigma_conn *conn,
12756 struct sigma_cmd *cmd)
12757{
12758 const char *val;
12759
12760 val = get_param(cmd, "ExtSchIE");
12761 if (val && !strcasecmp(val, "Enable")) {
12762 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
12763 int count = MAX_ESE_ALLOCS;
12764
12765 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
12766 return -1;
12767 return sta_set_60g_ese(dut, count, allocs);
12768 }
12769
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012770 val = get_param(cmd, "MCS_FixedRate");
12771 if (val) {
12772 int sta_mcs = atoi(val);
12773
12774 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
12775 sta_mcs);
12776 wil6210_set_force_mcs(dut, 1, sta_mcs);
12777
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012778 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012779 }
12780
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012781 send_resp(dut, conn, SIGMA_ERROR,
12782 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012783 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012784}
12785
12786
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012787static int wcn_sta_override_oci(struct sigma_dut *dut, const char *intf,
12788 const char *oci_frametype, uint32_t oci_freq)
12789{
12790#ifdef NL80211_SUPPORT
12791 struct nl_msg *msg;
12792 int ret = 0;
12793 struct nlattr *params;
12794 struct nlattr *attr;
12795 int ifindex;
12796 u8 frame_type;
12797
12798 ifindex = if_nametoindex(intf);
12799 if (ifindex == 0) {
12800 sigma_dut_print(dut, DUT_MSG_ERROR,
12801 "%s: Index for interface %s failed",
12802 __func__, intf);
12803 return -1;
12804 }
12805
12806 if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12807 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_REQ;
12808 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12809 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_RESP;
12810 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
12811 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_FT_REASSOC_REQ;
12812 } else {
12813 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: Unknown frametype %s",
12814 __func__, oci_frametype);
12815 return -1;
12816 }
12817
12818
12819 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
12820 NL80211_CMD_VENDOR)) ||
12821 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
12822 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
12823 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
12824 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
12825 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
12826 !(params = nla_nest_start(
12827 msg,
12828 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OCI_OVERRIDE)) ||
12829 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FRAME_TYPE,
12830 frame_type) ||
12831 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FREQUENCY,
12832 oci_freq)) {
12833 sigma_dut_print(dut, DUT_MSG_ERROR,
12834 "%s: err in adding vendor_cmd and vendor_data",
12835 __func__);
12836 nlmsg_free(msg);
12837 return -1;
12838 }
12839 nla_nest_end(msg, params);
12840 nla_nest_end(msg, attr);
12841
12842 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
12843 if (ret) {
12844 sigma_dut_print(dut, DUT_MSG_ERROR,
12845 "%s: err in send_and_recv_msgs, ret=%d",
12846 __func__, ret);
12847 }
12848 return ret;
12849#else /* NL80211_SUPPORT */
12850 sigma_dut_print(dut, DUT_MSG_ERROR,
12851 "OCI override not possible without NL80211_SUPPORT defined");
12852 return -1;
12853#endif /* NL80211_SUPPORT */
12854}
12855
12856
Jouni Malinen6250cb02020-04-15 13:54:45 +030012857static enum sigma_cmd_result
12858cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
12859 struct sigma_conn *conn,
12860 struct sigma_cmd *cmd)
12861{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012862 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030012863
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053012864 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030012865 if (val && atoi(val) == 1) {
12866 if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
12867 send_resp(dut, conn, SIGMA_ERROR,
12868 "errorCode,Failed to set ft_rsnxe_used");
12869 return STATUS_SENT_ERROR;
12870 }
12871 return SUCCESS_SEND_STATUS;
12872 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012873
12874 oci_chan = get_param(cmd, "OCIChannel");
12875 oci_frametype = get_param(cmd, "OCIFrameType");
12876 if (oci_chan && oci_frametype) {
12877 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
12878 char buf[100];
12879
12880 if (!oci_freq) {
12881 send_resp(dut, conn, SIGMA_ERROR,
12882 "errorCode,Invalid OCIChannel number");
12883 return STATUS_SENT_ERROR;
12884 }
12885
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012886 if (wifi_chip_type == DRIVER_WCN &&
12887 (strcasecmp(oci_frametype, "SAQueryReq") == 0 ||
12888 strcasecmp(oci_frametype, "SAQueryResp") == 0 ||
12889 strcasecmp(oci_frametype, "Reassocreq") == 0)) {
12890 if (wcn_sta_override_oci(dut, intf, oci_frametype,
12891 oci_freq)) {
12892 send_resp(dut, conn, SIGMA_ERROR,
12893 "errorCode,Failed to override OCI");
12894 return STATUS_SENT_ERROR;
12895 }
12896 return SUCCESS_SEND_STATUS;
12897 }
12898
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012899 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
12900 snprintf(buf, sizeof(buf),
12901 "SET oci_freq_override_eapol %d", oci_freq);
12902 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12903 snprintf(buf, sizeof(buf),
12904 "SET oci_freq_override_saquery_req %d",
12905 oci_freq);
12906 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12907 snprintf(buf, sizeof(buf),
12908 "SET oci_freq_override_saquery_resp %d",
12909 oci_freq);
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012910 } else if (strcasecmp(oci_frametype, "GrpKeyM2") == 0) {
12911 snprintf(buf, sizeof(buf),
12912 "SET oci_freq_override_eapol_g2 %d",
12913 oci_freq);
12914 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
12915 snprintf(buf, sizeof(buf),
12916 "SET oci_freq_override_ft_assoc %d",
12917 oci_freq);
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012918 } else {
12919 send_resp(dut, conn, SIGMA_ERROR,
12920 "errorCode,Unsupported OCIFrameType");
12921 return STATUS_SENT_ERROR;
12922 }
12923 if (wpa_command(intf, buf) < 0) {
12924 send_resp(dut, conn, SIGMA_ERROR,
12925 "errorCode,Failed to set oci_freq_override");
12926 return STATUS_SENT_ERROR;
12927 }
12928 return SUCCESS_SEND_STATUS;
12929 }
12930
Jouni Malinen6250cb02020-04-15 13:54:45 +030012931 send_resp(dut, conn, SIGMA_ERROR,
12932 "errorCode,Unsupported WPA3 rfeature");
12933 return STATUS_SENT_ERROR;
12934}
12935
12936
Jouni Malinenf7222712019-06-13 01:50:21 +030012937static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
12938 struct sigma_conn *conn,
12939 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012940{
12941 const char *intf = get_param(cmd, "Interface");
12942 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012943 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012944
12945 if (intf == NULL || prog == NULL)
12946 return -1;
12947
Ashwini Patil5acd7382017-04-13 15:55:04 +053012948 /* BSS Transition candidate list for BTM query */
12949 val = get_param(cmd, "Nebor_BSSID");
12950 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
12951 return 0;
12952
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012953 if (strcasecmp(prog, "TDLS") == 0)
12954 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
12955
12956 if (strcasecmp(prog, "VHT") == 0)
12957 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
12958
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012959 if (strcasecmp(prog, "HE") == 0)
12960 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
12961
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012962 if (strcasecmp(prog, "MBO") == 0) {
12963 val = get_param(cmd, "Cellular_Data_Cap");
12964 if (val &&
12965 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12966 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053012967
12968 val = get_param(cmd, "Ch_Pref");
12969 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12970 return 0;
12971
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012972 return 1;
12973 }
12974
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012975 if (strcasecmp(prog, "60GHz") == 0)
12976 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
12977
Jouni Malinen6250cb02020-04-15 13:54:45 +030012978 if (strcasecmp(prog, "WPA3") == 0)
12979 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
12980
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012981 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
12982 return 0;
12983}
12984
12985
Jouni Malinenf7222712019-06-13 01:50:21 +030012986static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
12987 struct sigma_conn *conn,
12988 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012989{
12990 const char *intf = get_param(cmd, "Interface");
12991 const char *mode = get_param(cmd, "Mode");
12992 int res;
12993
12994 if (intf == NULL || mode == NULL)
12995 return -1;
12996
12997 if (strcasecmp(mode, "On") == 0)
12998 res = wpa_command(intf, "SET radio_disabled 0");
12999 else if (strcasecmp(mode, "Off") == 0)
13000 res = wpa_command(intf, "SET radio_disabled 1");
13001 else
13002 return -1;
13003
13004 if (res) {
13005 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
13006 "radio mode");
13007 return 0;
13008 }
13009
13010 return 1;
13011}
13012
13013
Jouni Malinenf7222712019-06-13 01:50:21 +030013014static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
13015 struct sigma_conn *conn,
13016 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013017{
13018 const char *intf = get_param(cmd, "Interface");
13019 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013020 const char *prog = get_param(cmd, "program");
13021 const char *powersave = get_param(cmd, "powersave");
13022 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013023
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013024 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013025 return -1;
13026
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013027 if (prog && strcasecmp(prog, "60GHz") == 0) {
13028 /*
13029 * The CAPI mode parameter does not exist in 60G
13030 * unscheduled PS.
13031 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080013032 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013033 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013034 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020013035 strcasecmp(prog, "HE") == 0) {
13036 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013037 } else {
13038 if (mode == NULL)
13039 return -1;
13040
13041 if (strcasecmp(mode, "On") == 0)
13042 res = set_ps(intf, dut, 1);
13043 else if (strcasecmp(mode, "Off") == 0)
13044 res = set_ps(intf, dut, 0);
13045 else
13046 return -1;
13047 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013048
13049 if (res) {
13050 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
13051 "power save mode");
13052 return 0;
13053 }
13054
13055 return 1;
13056}
13057
13058
Jouni Malinenf7222712019-06-13 01:50:21 +030013059static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
13060 struct sigma_conn *conn,
13061 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013062{
13063 const char *intf = get_param(cmd, "Interface");
13064 const char *val, *bssid;
13065 int res;
13066 char *buf;
13067 size_t buf_len;
13068
13069 val = get_param(cmd, "BSSID_FILTER");
13070 if (val == NULL)
13071 return -1;
13072
13073 bssid = get_param(cmd, "BSSID_List");
13074 if (atoi(val) == 0 || bssid == NULL) {
13075 /* Disable BSSID filter */
13076 if (wpa_command(intf, "SET bssid_filter ")) {
13077 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
13078 "to disable BSSID filter");
13079 return 0;
13080 }
13081
13082 return 1;
13083 }
13084
13085 buf_len = 100 + strlen(bssid);
13086 buf = malloc(buf_len);
13087 if (buf == NULL)
13088 return -1;
13089
13090 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
13091 res = wpa_command(intf, buf);
13092 free(buf);
13093 if (res) {
13094 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
13095 "BSSID filter");
13096 return 0;
13097 }
13098
13099 return 1;
13100}
13101
13102
Jouni Malinenf7222712019-06-13 01:50:21 +030013103static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
13104 struct sigma_conn *conn,
13105 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013106{
13107 const char *intf = get_param(cmd, "Interface");
13108 const char *val;
13109
13110 /* TODO: ARP */
13111
13112 val = get_param(cmd, "HS2_CACHE_PROFILE");
13113 if (val && strcasecmp(val, "All") == 0)
13114 hs2_clear_credentials(intf);
13115
13116 return 1;
13117}
13118
13119
Jouni Malinenf7222712019-06-13 01:50:21 +030013120static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
13121 struct sigma_conn *conn,
13122 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013123{
13124 const char *intf = get_param(cmd, "Interface");
13125 const char *key_type = get_param(cmd, "KeyType");
13126 char buf[100], resp[200];
13127
13128 if (key_type == NULL)
13129 return -1;
13130
13131 if (strcasecmp(key_type, "GTK") == 0) {
13132 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
13133 strncmp(buf, "FAIL", 4) == 0) {
13134 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13135 "not fetch current GTK");
13136 return 0;
13137 }
13138 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
13139 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13140 return 0;
13141 } else {
13142 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13143 "KeyType");
13144 return 0;
13145 }
13146
13147 return 1;
13148}
13149
13150
13151static int hs2_set_policy(struct sigma_dut *dut)
13152{
13153#ifdef ANDROID
13154 system("ip rule del prio 23000");
13155 if (system("ip rule add from all lookup main prio 23000") != 0) {
13156 sigma_dut_print(dut, DUT_MSG_ERROR,
13157 "Failed to run:ip rule add from all lookup main prio");
13158 return -1;
13159 }
13160 if (system("ip route flush cache") != 0) {
13161 sigma_dut_print(dut, DUT_MSG_ERROR,
13162 "Failed to run ip route flush cache");
13163 return -1;
13164 }
13165 return 1;
13166#else /* ANDROID */
13167 return 0;
13168#endif /* ANDROID */
13169}
13170
13171
Jouni Malinenf7222712019-06-13 01:50:21 +030013172static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
13173 struct sigma_conn *conn,
13174 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013175{
13176 const char *intf = get_param(cmd, "Interface");
13177 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030013178 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013179 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030013180 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013181 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
13182 int tries = 0;
13183 int ignore_blacklist = 0;
13184 const char *events[] = {
13185 "CTRL-EVENT-CONNECTED",
13186 "INTERWORKING-BLACKLISTED",
13187 "INTERWORKING-NO-MATCH",
13188 NULL
13189 };
13190
13191 start_sta_mode(dut);
13192
Jouni Malinen439352d2018-09-13 03:42:23 +030013193 if (band) {
13194 if (strcmp(band, "2.4") == 0) {
13195 wpa_command(intf, "SET setband 2G");
13196 } else if (strcmp(band, "5") == 0) {
13197 wpa_command(intf, "SET setband 5G");
13198 } else {
13199 send_resp(dut, conn, SIGMA_ERROR,
13200 "errorCode,Unsupported band");
13201 return 0;
13202 }
13203 }
13204
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013205 blacklisted[0] = '\0';
13206 if (val && atoi(val))
13207 ignore_blacklist = 1;
13208
13209try_again:
13210 ctrl = open_wpa_mon(intf);
13211 if (ctrl == NULL) {
13212 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13213 "wpa_supplicant monitor connection");
13214 return -2;
13215 }
13216
13217 tries++;
13218 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
13219 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
13220 "Interworking connection");
13221 wpa_ctrl_detach(ctrl);
13222 wpa_ctrl_close(ctrl);
13223 return 0;
13224 }
13225
13226 buf[0] = '\0';
13227 while (1) {
13228 char *pos;
13229 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13230 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
13231 if (!pos)
13232 break;
13233 pos += 25;
13234 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
13235 pos);
13236 if (!blacklisted[0])
13237 memcpy(blacklisted, pos, strlen(pos) + 1);
13238 }
13239
13240 if (ignore_blacklist && blacklisted[0]) {
13241 char *end;
13242 end = strchr(blacklisted, ' ');
13243 if (end)
13244 *end = '\0';
13245 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
13246 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030013247 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
13248 blacklisted);
13249 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013250 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
13251 wpa_ctrl_detach(ctrl);
13252 wpa_ctrl_close(ctrl);
13253 return 0;
13254 }
13255 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13256 buf, sizeof(buf));
13257 }
13258
13259 wpa_ctrl_detach(ctrl);
13260 wpa_ctrl_close(ctrl);
13261
13262 if (res < 0) {
13263 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
13264 "connect");
13265 return 0;
13266 }
13267
13268 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
13269 strstr(buf, "INTERWORKING-BLACKLISTED")) {
13270 if (tries < 2) {
13271 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
13272 goto try_again;
13273 }
13274 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
13275 "matching credentials found");
13276 return 0;
13277 }
13278
13279 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13280 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13281 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
13282 "get current BSSID/SSID");
13283 return 0;
13284 }
13285
13286 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
13287 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13288 hs2_set_policy(dut);
13289 return 0;
13290}
13291
13292
Jouni Malinenf7222712019-06-13 01:50:21 +030013293static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
13294 struct sigma_conn *conn,
13295 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013296{
13297 const char *intf = get_param(cmd, "Interface");
13298 const char *display = get_param(cmd, "Display");
13299 struct wpa_ctrl *ctrl;
13300 char buf[300], params[400], *pos;
13301 char bssid[20];
13302 int info_avail = 0;
13303 unsigned int old_timeout;
13304 int res;
13305
13306 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
13307 send_resp(dut, conn, SIGMA_ERROR,
13308 "ErrorCode,Could not get current BSSID");
13309 return 0;
13310 }
13311 ctrl = open_wpa_mon(intf);
13312 if (!ctrl) {
13313 sigma_dut_print(dut, DUT_MSG_ERROR,
13314 "Failed to open wpa_supplicant monitor connection");
13315 return -2;
13316 }
13317
13318 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
13319 wpa_command(intf, buf);
13320
13321 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
13322 if (res < 0) {
13323 send_resp(dut, conn, SIGMA_ERROR,
13324 "ErrorCode,Could not complete GAS query");
13325 goto fail;
13326 }
13327
13328 old_timeout = dut->default_timeout;
13329 dut->default_timeout = 2;
13330 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
13331 dut->default_timeout = old_timeout;
13332 if (res < 0)
13333 goto done;
13334 pos = strchr(buf, ' ');
13335 if (!pos)
13336 goto done;
13337 pos++;
13338 pos = strchr(pos, ' ');
13339 if (!pos)
13340 goto done;
13341 pos++;
13342 info_avail = 1;
13343 snprintf(params, sizeof(params), "browser %s", pos);
13344
13345 if (display && strcasecmp(display, "Yes") == 0) {
13346 pid_t pid;
13347
13348 pid = fork();
13349 if (pid < 0) {
13350 perror("fork");
13351 return -1;
13352 }
13353
13354 if (pid == 0) {
13355 run_hs20_osu(dut, params);
13356 exit(0);
13357 }
13358 }
13359
13360done:
13361 snprintf(buf, sizeof(buf), "Info_available,%s",
13362 info_avail ? "Yes" : "No");
13363 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13364fail:
13365 wpa_ctrl_detach(ctrl);
13366 wpa_ctrl_close(ctrl);
13367 return 0;
13368}
13369
13370
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013371static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
13372 struct sigma_conn *conn,
13373 const char *ifname,
13374 struct sigma_cmd *cmd)
13375{
13376 const char *val;
13377 int id;
13378
13379 id = add_cred(ifname);
13380 if (id < 0)
13381 return -2;
13382 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13383
13384 val = get_param(cmd, "prefer");
13385 if (val && atoi(val) > 0)
13386 set_cred(ifname, id, "priority", "1");
13387
13388 val = get_param(cmd, "REALM");
13389 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13390 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13391 "realm");
13392 return 0;
13393 }
13394
13395 val = get_param(cmd, "HOME_FQDN");
13396 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13397 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13398 "home_fqdn");
13399 return 0;
13400 }
13401
13402 val = get_param(cmd, "Username");
13403 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13404 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13405 "username");
13406 return 0;
13407 }
13408
13409 val = get_param(cmd, "Password");
13410 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
13411 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13412 "password");
13413 return 0;
13414 }
13415
13416 val = get_param(cmd, "ROOT_CA");
13417 if (val) {
13418 char fname[200];
13419 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13420#ifdef __linux__
13421 if (!file_exists(fname)) {
13422 char msg[300];
13423 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13424 "file (%s) not found", fname);
13425 send_resp(dut, conn, SIGMA_ERROR, msg);
13426 return 0;
13427 }
13428#endif /* __linux__ */
13429 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13430 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13431 "not set root CA");
13432 return 0;
13433 }
13434 }
13435
13436 return 1;
13437}
13438
13439
13440static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
13441{
13442 FILE *in, *out;
13443 char buf[500];
13444 int found = 0;
13445
13446 in = fopen("devdetail.xml", "r");
13447 if (in == NULL)
13448 return -1;
13449 out = fopen("devdetail.xml.tmp", "w");
13450 if (out == NULL) {
13451 fclose(in);
13452 return -1;
13453 }
13454
13455 while (fgets(buf, sizeof(buf), in)) {
13456 char *pos = strstr(buf, "<IMSI>");
13457 if (pos) {
13458 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
13459 imsi);
13460 pos += 6;
13461 *pos = '\0';
13462 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
13463 found++;
13464 } else {
13465 fprintf(out, "%s", buf);
13466 }
13467 }
13468
13469 fclose(out);
13470 fclose(in);
13471 if (found)
13472 rename("devdetail.xml.tmp", "devdetail.xml");
13473 else
13474 unlink("devdetail.xml.tmp");
13475
13476 return 0;
13477}
13478
13479
13480static int sta_add_credential_sim(struct sigma_dut *dut,
13481 struct sigma_conn *conn,
13482 const char *ifname, struct sigma_cmd *cmd)
13483{
13484 const char *val, *imsi = NULL;
13485 int id;
13486 char buf[200];
13487 int res;
13488 const char *pos;
13489 size_t mnc_len;
13490 char plmn_mcc[4];
13491 char plmn_mnc[4];
13492
13493 id = add_cred(ifname);
13494 if (id < 0)
13495 return -2;
13496 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13497
13498 val = get_param(cmd, "prefer");
13499 if (val && atoi(val) > 0)
13500 set_cred(ifname, id, "priority", "1");
13501
13502 val = get_param(cmd, "PLMN_MCC");
13503 if (val == NULL) {
13504 send_resp(dut, conn, SIGMA_ERROR,
13505 "errorCode,Missing PLMN_MCC");
13506 return 0;
13507 }
13508 if (strlen(val) != 3) {
13509 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
13510 return 0;
13511 }
13512 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
13513
13514 val = get_param(cmd, "PLMN_MNC");
13515 if (val == NULL) {
13516 send_resp(dut, conn, SIGMA_ERROR,
13517 "errorCode,Missing PLMN_MNC");
13518 return 0;
13519 }
13520 if (strlen(val) != 2 && strlen(val) != 3) {
13521 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
13522 return 0;
13523 }
13524 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
13525
13526 val = get_param(cmd, "IMSI");
13527 if (val == NULL) {
13528 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
13529 "IMSI");
13530 return 0;
13531 }
13532
13533 imsi = pos = val;
13534
13535 if (strncmp(plmn_mcc, pos, 3) != 0) {
13536 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
13537 return 0;
13538 }
13539 pos += 3;
13540
13541 mnc_len = strlen(plmn_mnc);
13542 if (mnc_len < 2) {
13543 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
13544 return 0;
13545 }
13546
13547 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
13548 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
13549 return 0;
13550 }
13551 pos += mnc_len;
13552
13553 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
13554 if (res < 0 || res >= (int) sizeof(buf))
13555 return -1;
13556 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
13557 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13558 "not set IMSI");
13559 return 0;
13560 }
13561
13562 val = get_param(cmd, "Password");
13563 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
13564 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13565 "not set password");
13566 return 0;
13567 }
13568
Jouni Malinenba630452018-06-22 11:49:59 +030013569 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013570 /*
13571 * Set provisioning_sp for the test cases where SIM/USIM
13572 * provisioning is used.
13573 */
13574 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
13575 "wi-fi.org") < 0) {
13576 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13577 "not set provisioning_sp");
13578 return 0;
13579 }
13580
13581 update_devdetail_imsi(dut, imsi);
13582 }
13583
13584 return 1;
13585}
13586
13587
13588static int sta_add_credential_cert(struct sigma_dut *dut,
13589 struct sigma_conn *conn,
13590 const char *ifname,
13591 struct sigma_cmd *cmd)
13592{
13593 const char *val;
13594 int id;
13595
13596 id = add_cred(ifname);
13597 if (id < 0)
13598 return -2;
13599 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13600
13601 val = get_param(cmd, "prefer");
13602 if (val && atoi(val) > 0)
13603 set_cred(ifname, id, "priority", "1");
13604
13605 val = get_param(cmd, "REALM");
13606 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13607 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13608 "realm");
13609 return 0;
13610 }
13611
13612 val = get_param(cmd, "HOME_FQDN");
13613 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13614 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13615 "home_fqdn");
13616 return 0;
13617 }
13618
13619 val = get_param(cmd, "Username");
13620 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13621 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13622 "username");
13623 return 0;
13624 }
13625
13626 val = get_param(cmd, "clientCertificate");
13627 if (val) {
13628 char fname[200];
13629 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13630#ifdef __linux__
13631 if (!file_exists(fname)) {
13632 char msg[300];
13633 snprintf(msg, sizeof(msg),
13634 "ErrorCode,clientCertificate "
13635 "file (%s) not found", fname);
13636 send_resp(dut, conn, SIGMA_ERROR, msg);
13637 return 0;
13638 }
13639#endif /* __linux__ */
13640 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
13641 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13642 "not set client_cert");
13643 return 0;
13644 }
13645 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
13646 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13647 "not set private_key");
13648 return 0;
13649 }
13650 }
13651
13652 val = get_param(cmd, "ROOT_CA");
13653 if (val) {
13654 char fname[200];
13655 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13656#ifdef __linux__
13657 if (!file_exists(fname)) {
13658 char msg[300];
13659 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13660 "file (%s) not found", fname);
13661 send_resp(dut, conn, SIGMA_ERROR, msg);
13662 return 0;
13663 }
13664#endif /* __linux__ */
13665 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13666 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13667 "not set root CA");
13668 return 0;
13669 }
13670 }
13671
13672 return 1;
13673}
13674
13675
Jouni Malinenf7222712019-06-13 01:50:21 +030013676static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
13677 struct sigma_conn *conn,
13678 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013679{
13680 const char *intf = get_param(cmd, "Interface");
13681 const char *type;
13682
13683 start_sta_mode(dut);
13684
13685 type = get_param(cmd, "Type");
13686 if (!type)
13687 return -1;
13688
13689 if (strcasecmp(type, "uname_pwd") == 0)
13690 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
13691
13692 if (strcasecmp(type, "sim") == 0)
13693 return sta_add_credential_sim(dut, conn, intf, cmd);
13694
13695 if (strcasecmp(type, "cert") == 0)
13696 return sta_add_credential_cert(dut, conn, intf, cmd);
13697
13698 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
13699 "type");
13700 return 0;
13701}
13702
13703
Jouni Malinenf7222712019-06-13 01:50:21 +030013704static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
13705 struct sigma_conn *conn,
13706 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013707{
13708 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013709 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Arif Hussain66a4af02019-02-07 15:04:51 -080013710 char buf[4096];
vamsi krishna89ad8c62017-09-19 12:51:18 +053013711 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013712 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013713 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013714 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013715 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013716
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020013717 start_sta_mode(dut);
13718
Arif Hussain66a4af02019-02-07 15:04:51 -080013719 val = get_param(cmd, "GetParameter");
13720 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013721 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080013722 buf, sizeof(buf)) < 0) {
13723 sigma_dut_print(dut, DUT_MSG_ERROR,
13724 "Could not get ssid bssid");
13725 return ERROR_SEND_STATUS;
13726 }
13727
13728 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
13729 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13730 return STATUS_SENT;
13731 }
13732
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013733 val = get_param(cmd, "HESSID");
13734 if (val) {
13735 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
13736 if (res < 0 || res >= (int) sizeof(buf))
13737 return -1;
13738 wpa_command(intf, buf);
13739 }
13740
13741 val = get_param(cmd, "ACCS_NET_TYPE");
13742 if (val) {
13743 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
13744 val);
13745 if (res < 0 || res >= (int) sizeof(buf))
13746 return -1;
13747 wpa_command(intf, buf);
13748 }
13749
vamsi krishna89ad8c62017-09-19 12:51:18 +053013750 bssid = get_param(cmd, "Bssid");
13751 ssid = get_param(cmd, "Ssid");
13752
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013753 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
13754 dut->device_type == STA_testbed) {
13755 ssid = NULL;
13756 wildcard_ssid = 1;
13757 }
13758
vamsi krishna89ad8c62017-09-19 12:51:18 +053013759 if (ssid) {
13760 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
13761 send_resp(dut, conn, SIGMA_ERROR,
13762 "ErrorCode,Too long SSID");
13763 return 0;
13764 }
13765 ascii2hexstr(ssid, ssid_hex);
13766 }
13767
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013768 short_ssid = get_param(cmd, "ShortSSID");
13769 if (short_ssid) {
13770 uint32_t short_ssid_hex;
13771
13772 short_ssid_hex = strtoul(short_ssid, NULL, 16);
13773 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
13774 (((short_ssid_hex >> 8) & 0xFF) << 16) |
13775 (((short_ssid_hex >> 16) & 0xFF) << 8) |
13776 ((short_ssid_hex >> 24) & 0xFF);
13777
13778 res = snprintf(buf, sizeof(buf),
13779 "VENDOR_ELEM_ADD 14 ff053a%08x",
13780 short_ssid_hex);
13781 if (res < 0 || res >= (int) sizeof(buf) ||
13782 wpa_command(intf, buf)) {
13783 send_resp(dut, conn, SIGMA_ERROR,
13784 "errorCode,Failed to add short SSID");
13785 return STATUS_SENT_ERROR;
13786 }
13787 }
13788
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013789 scan_freq = get_param(cmd, "ChnlFreq");
13790
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013791 val = get_param(cmd, "WaitCompletion");
13792 if (val && atoi(val) == 1) {
13793 ctrl = open_wpa_mon(intf);
13794 if (!ctrl) {
13795 send_resp(dut, conn, SIGMA_ERROR,
13796 "errorCode,Failed to open monitor socket");
13797 return STATUS_SENT_ERROR;
13798 }
13799 }
13800
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013801 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053013802 bssid ? " bssid=": "",
13803 bssid ? bssid : "",
13804 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013805 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013806 wildcard_ssid ? " wildcard_ssid=1" : "",
13807 scan_freq ? " freq=" : "",
13808 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013809 if (res < 0 || res >= (int) sizeof(buf)) {
13810 send_resp(dut, conn, SIGMA_ERROR,
13811 "errorCode,Could not build scan command");
13812 status = STATUS_SENT_ERROR;
13813 goto remove_s_ssid;
13814 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053013815
13816 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013817 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
13818 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013819 status = STATUS_SENT_ERROR;
13820 } else {
13821 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013822 }
13823
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013824remove_s_ssid:
13825 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
13826 sigma_dut_print(dut, DUT_MSG_ERROR,
13827 "Failed to delete vendor element");
13828
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013829 if (ctrl) {
13830 if (status == SUCCESS_SEND_STATUS) {
13831 res = get_wpa_cli_event(dut, ctrl,
13832 "CTRL-EVENT-SCAN-RESULTS",
13833 buf, sizeof(buf));
13834 if (res < 0) {
13835 send_resp(dut, conn, SIGMA_ERROR,
13836 "ErrorCode,scan did not complete");
13837 status = STATUS_SENT_ERROR;
13838 }
13839 }
13840
13841 wpa_ctrl_detach(ctrl);
13842 wpa_ctrl_close(ctrl);
13843 }
13844
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013845 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013846}
13847
13848
Jouni Malinenf7222712019-06-13 01:50:21 +030013849static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
13850 struct sigma_conn *conn,
13851 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013852{
13853 const char *intf = get_param(cmd, "Interface");
13854 const char *bssid;
13855 char buf[4096], *pos;
13856 int freq, chan;
13857 char *ssid;
13858 char resp[100];
13859 int res;
13860 struct wpa_ctrl *ctrl;
13861
13862 bssid = get_param(cmd, "BSSID");
13863 if (!bssid) {
13864 send_resp(dut, conn, SIGMA_INVALID,
13865 "errorCode,BSSID argument is missing");
13866 return 0;
13867 }
13868
13869 ctrl = open_wpa_mon(intf);
13870 if (!ctrl) {
13871 sigma_dut_print(dut, DUT_MSG_ERROR,
13872 "Failed to open wpa_supplicant monitor connection");
13873 return -1;
13874 }
13875
13876 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
13877 send_resp(dut, conn, SIGMA_ERROR,
13878 "errorCode,Could not start scan");
13879 wpa_ctrl_detach(ctrl);
13880 wpa_ctrl_close(ctrl);
13881 return 0;
13882 }
13883
13884 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
13885 buf, sizeof(buf));
13886
13887 wpa_ctrl_detach(ctrl);
13888 wpa_ctrl_close(ctrl);
13889
13890 if (res < 0) {
13891 send_resp(dut, conn, SIGMA_ERROR,
13892 "errorCode,Scan did not complete");
13893 return 0;
13894 }
13895
13896 snprintf(buf, sizeof(buf), "BSS %s", bssid);
13897 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
13898 strncmp(buf, "id=", 3) != 0) {
13899 send_resp(dut, conn, SIGMA_ERROR,
13900 "errorCode,Specified BSSID not found");
13901 return 0;
13902 }
13903
13904 pos = strstr(buf, "\nfreq=");
13905 if (!pos) {
13906 send_resp(dut, conn, SIGMA_ERROR,
13907 "errorCode,Channel not found");
13908 return 0;
13909 }
13910 freq = atoi(pos + 6);
13911 chan = freq_to_channel(freq);
13912
13913 pos = strstr(buf, "\nssid=");
13914 if (!pos) {
13915 send_resp(dut, conn, SIGMA_ERROR,
13916 "errorCode,SSID not found");
13917 return 0;
13918 }
13919 ssid = pos + 6;
13920 pos = strchr(ssid, '\n');
13921 if (pos)
13922 *pos = '\0';
13923 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
13924 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13925 return 0;
13926}
13927
13928
Jouni Malinenf7222712019-06-13 01:50:21 +030013929static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
13930 struct sigma_conn *conn,
13931 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013932{
13933#ifdef __linux__
13934 struct timeval tv;
13935 struct tm tm;
13936 time_t t;
13937 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013938 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013939
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013940 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013941
13942 memset(&tm, 0, sizeof(tm));
13943 val = get_param(cmd, "seconds");
13944 if (val)
13945 tm.tm_sec = atoi(val);
13946 val = get_param(cmd, "minutes");
13947 if (val)
13948 tm.tm_min = atoi(val);
13949 val = get_param(cmd, "hours");
13950 if (val)
13951 tm.tm_hour = atoi(val);
13952 val = get_param(cmd, "date");
13953 if (val)
13954 tm.tm_mday = atoi(val);
13955 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013956 if (val) {
13957 v = atoi(val);
13958 if (v < 1 || v > 12) {
13959 send_resp(dut, conn, SIGMA_INVALID,
13960 "errorCode,Invalid month");
13961 return 0;
13962 }
13963 tm.tm_mon = v - 1;
13964 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013965 val = get_param(cmd, "year");
13966 if (val) {
13967 int year = atoi(val);
13968#ifdef ANDROID
13969 if (year > 2035)
13970 year = 2035; /* years beyond 2035 not supported */
13971#endif /* ANDROID */
13972 tm.tm_year = year - 1900;
13973 }
13974 t = mktime(&tm);
13975 if (t == (time_t) -1) {
13976 send_resp(dut, conn, SIGMA_ERROR,
13977 "errorCode,Invalid date or time");
13978 return 0;
13979 }
13980
13981 memset(&tv, 0, sizeof(tv));
13982 tv.tv_sec = t;
13983
13984 if (settimeofday(&tv, NULL) < 0) {
13985 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
13986 strerror(errno));
13987 send_resp(dut, conn, SIGMA_ERROR,
13988 "errorCode,Failed to set time");
13989 return 0;
13990 }
13991
13992 return 1;
13993#endif /* __linux__ */
13994
13995 return -1;
13996}
13997
13998
Jouni Malinenf7222712019-06-13 01:50:21 +030013999static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
14000 struct sigma_conn *conn,
14001 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014002{
14003 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014004 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014005 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014006 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014007 int res;
14008 struct wpa_ctrl *ctrl;
14009
14010 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014011 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014012
14013 val = get_param(cmd, "ProdESSAssoc");
14014 if (val)
14015 prod_ess_assoc = atoi(val);
14016
14017 kill_dhcp_client(dut, intf);
14018 if (start_dhcp_client(dut, intf) < 0)
14019 return -2;
14020
14021 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
14022 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
14023 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014024 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014025 prod_ess_assoc ? "" : "-N",
14026 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014027 name ? "'" : "",
14028 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
14029 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014030
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053014031 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014032 if (run_hs20_osu(dut, buf) < 0) {
14033 FILE *f;
14034
14035 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
14036
14037 f = fopen("hs20-osu-client.res", "r");
14038 if (f) {
14039 char resp[400], res[300], *pos;
14040 if (!fgets(res, sizeof(res), f))
14041 res[0] = '\0';
14042 pos = strchr(res, '\n');
14043 if (pos)
14044 *pos = '\0';
14045 fclose(f);
14046 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
14047 res);
14048 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
14049 if (system(resp) != 0) {
14050 }
14051 snprintf(resp, sizeof(resp),
14052 "SSID,,BSSID,,failureReason,%s", res);
14053 send_resp(dut, conn, SIGMA_COMPLETE, resp);
14054 return 0;
14055 }
14056
14057 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
14058 return 0;
14059 }
14060
14061 if (!prod_ess_assoc)
14062 goto report;
14063
14064 ctrl = open_wpa_mon(intf);
14065 if (ctrl == NULL) {
14066 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14067 "wpa_supplicant monitor connection");
14068 return -1;
14069 }
14070
14071 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
14072 buf, sizeof(buf));
14073
14074 wpa_ctrl_detach(ctrl);
14075 wpa_ctrl_close(ctrl);
14076
14077 if (res < 0) {
14078 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
14079 "network after OSU");
14080 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
14081 return 0;
14082 }
14083
14084report:
14085 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
14086 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
14087 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
14088 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
14089 return 0;
14090 }
14091
14092 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
14093 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014094 return 0;
14095}
14096
14097
Jouni Malinenf7222712019-06-13 01:50:21 +030014098static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
14099 struct sigma_conn *conn,
14100 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014101{
14102 const char *val;
14103 int timeout = 120;
14104
14105 val = get_param(cmd, "PolicyUpdate");
14106 if (val == NULL || atoi(val) == 0)
14107 return 1; /* No operation requested */
14108
14109 val = get_param(cmd, "Timeout");
14110 if (val)
14111 timeout = atoi(val);
14112
14113 if (timeout) {
14114 /* TODO: time out the command and return
14115 * PolicyUpdateStatus,TIMEOUT if needed. */
14116 }
14117
14118 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
14119 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
14120 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
14121 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
14122 return 0;
14123 }
14124
14125 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
14126 return 0;
14127}
14128
14129
Jouni Malinenf7222712019-06-13 01:50:21 +030014130static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
14131 struct sigma_conn *conn,
14132 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014133{
14134 struct wpa_ctrl *ctrl;
14135 const char *intf = get_param(cmd, "Interface");
14136 const char *bssid = get_param(cmd, "Bssid");
14137 const char *ssid = get_param(cmd, "SSID");
14138 const char *security = get_param(cmd, "Security");
14139 const char *passphrase = get_param(cmd, "Passphrase");
14140 const char *pin = get_param(cmd, "PIN");
14141 char buf[1000];
14142 char ssid_hex[200], passphrase_hex[200];
14143 const char *keymgmt, *cipher;
14144
14145 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014146 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014147
14148 if (!bssid) {
14149 send_resp(dut, conn, SIGMA_ERROR,
14150 "ErrorCode,Missing Bssid argument");
14151 return 0;
14152 }
14153
14154 if (!ssid) {
14155 send_resp(dut, conn, SIGMA_ERROR,
14156 "ErrorCode,Missing SSID argument");
14157 return 0;
14158 }
14159
14160 if (!security) {
14161 send_resp(dut, conn, SIGMA_ERROR,
14162 "ErrorCode,Missing Security argument");
14163 return 0;
14164 }
14165
14166 if (!passphrase) {
14167 send_resp(dut, conn, SIGMA_ERROR,
14168 "ErrorCode,Missing Passphrase argument");
14169 return 0;
14170 }
14171
14172 if (!pin) {
14173 send_resp(dut, conn, SIGMA_ERROR,
14174 "ErrorCode,Missing PIN argument");
14175 return 0;
14176 }
14177
vamsi krishna8c9c1562017-05-12 15:51:46 +053014178 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
14179 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014180 send_resp(dut, conn, SIGMA_ERROR,
14181 "ErrorCode,Too long SSID/passphrase");
14182 return 0;
14183 }
14184
14185 ctrl = open_wpa_mon(intf);
14186 if (ctrl == NULL) {
14187 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14188 "wpa_supplicant monitor connection");
14189 return -2;
14190 }
14191
14192 if (strcasecmp(security, "wpa2-psk") == 0) {
14193 keymgmt = "WPA2PSK";
14194 cipher = "CCMP";
14195 } else {
14196 wpa_ctrl_detach(ctrl);
14197 wpa_ctrl_close(ctrl);
14198 send_resp(dut, conn, SIGMA_ERROR,
14199 "ErrorCode,Unsupported Security value");
14200 return 0;
14201 }
14202
14203 ascii2hexstr(ssid, ssid_hex);
14204 ascii2hexstr(passphrase, passphrase_hex);
14205 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
14206 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
14207
14208 if (wpa_command(intf, buf) < 0) {
14209 wpa_ctrl_detach(ctrl);
14210 wpa_ctrl_close(ctrl);
14211 send_resp(dut, conn, SIGMA_ERROR,
14212 "ErrorCode,Failed to start registrar");
14213 return 0;
14214 }
14215
14216 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
14217 dut->er_oper_performed = 1;
14218
14219 return wps_connection_event(dut, conn, ctrl, intf, 0);
14220}
14221
14222
Jouni Malinenf7222712019-06-13 01:50:21 +030014223static enum sigma_cmd_result
14224cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
14225 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014226{
14227 struct wpa_ctrl *ctrl;
14228 const char *intf = get_param(cmd, "Interface");
14229 const char *bssid = get_param(cmd, "Bssid");
14230 char buf[100];
14231
14232 if (!bssid) {
14233 send_resp(dut, conn, SIGMA_ERROR,
14234 "ErrorCode,Missing Bssid argument");
14235 return 0;
14236 }
14237
14238 ctrl = open_wpa_mon(intf);
14239 if (ctrl == NULL) {
14240 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14241 "wpa_supplicant monitor connection");
14242 return -2;
14243 }
14244
14245 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
14246
14247 if (wpa_command(intf, buf) < 0) {
14248 wpa_ctrl_detach(ctrl);
14249 wpa_ctrl_close(ctrl);
14250 send_resp(dut, conn, SIGMA_ERROR,
14251 "ErrorCode,Failed to start registrar");
14252 return 0;
14253 }
14254
14255 return wps_connection_event(dut, conn, ctrl, intf, 0);
14256}
14257
14258
Jouni Malinenf7222712019-06-13 01:50:21 +030014259static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
14260 struct sigma_conn *conn,
14261 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053014262{
14263 struct wpa_ctrl *ctrl;
14264 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014265 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014266 const char *config_method = get_param(cmd, "WPSConfigMethod");
14267 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053014268 int res;
14269 char buf[256];
14270 const char *events[] = {
14271 "CTRL-EVENT-CONNECTED",
14272 "WPS-OVERLAP-DETECTED",
14273 "WPS-TIMEOUT",
14274 "WPS-FAIL",
14275 NULL
14276 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014277 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053014278
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014279 /* 60G WPS tests do not pass Interface parameter */
14280 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014281 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014282
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014283 if (dut->mode == SIGMA_MODE_AP)
14284 return ap_wps_registration(dut, conn, cmd);
14285
14286 if (config_method) {
14287 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
14288 * sta_wps_enter_pin before calling start_wps_registration. */
14289 if (strcasecmp(config_method, "PBC") == 0)
14290 dut->wps_method = WFA_CS_WPS_PBC;
14291 }
14292 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
14293 send_resp(dut, conn, SIGMA_ERROR,
14294 "ErrorCode,WPS parameters not yet set");
14295 return STATUS_SENT;
14296 }
14297
14298 /* Make sure WPS is enabled (also for STA mode) */
14299 dut->wps_disable = 0;
14300
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014301 if (dut->band == WPS_BAND_60G && network_mode &&
14302 strcasecmp(network_mode, "PBSS") == 0) {
14303 sigma_dut_print(dut, DUT_MSG_DEBUG,
14304 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014305 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014306 return -2;
14307 }
14308
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020014309 if (dut->force_rsn_ie) {
14310 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
14311 dut->force_rsn_ie);
14312 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
14313 sigma_dut_print(dut, DUT_MSG_INFO,
14314 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014315 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020014316 }
14317 }
14318
vamsi krishna9b144002017-09-20 13:28:13 +053014319 ctrl = open_wpa_mon(intf);
14320 if (!ctrl) {
14321 sigma_dut_print(dut, DUT_MSG_ERROR,
14322 "Failed to open wpa_supplicant monitor connection");
14323 return -2;
14324 }
14325
14326 role = get_param(cmd, "WpsRole");
14327 if (!role) {
14328 send_resp(dut, conn, SIGMA_INVALID,
14329 "ErrorCode,WpsRole not provided");
14330 goto fail;
14331 }
14332
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014333 if (strcasecmp(role, "Enrollee") != 0) {
14334 /* Registrar role for STA not supported */
14335 send_resp(dut, conn, SIGMA_ERROR,
14336 "ErrorCode,Unsupported WpsRole value");
14337 goto fail;
14338 }
14339
14340 if (is_60g_sigma_dut(dut)) {
14341 if (dut->wps_method == WFA_CS_WPS_PBC)
14342 snprintf(buf, sizeof(buf), "WPS_PBC");
14343 else /* WFA_CS_WPS_PIN_KEYPAD */
14344 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
14345 dut->wps_pin);
14346 if (wpa_command(intf, buf) < 0) {
14347 send_resp(dut, conn, SIGMA_ERROR,
14348 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053014349 goto fail;
14350 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014351 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
14352 if (res < 0) {
14353 send_resp(dut, conn, SIGMA_ERROR,
14354 "ErrorCode,WPS connection did not complete");
14355 goto fail;
14356 }
14357 if (strstr(buf, "WPS-TIMEOUT")) {
14358 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
14359 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
14360 send_resp(dut, conn, SIGMA_COMPLETE,
14361 "WpsState,OverlapSession");
14362 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
14363 send_resp(dut, conn, SIGMA_COMPLETE,
14364 "WpsState,Successful");
14365 } else {
14366 send_resp(dut, conn, SIGMA_COMPLETE,
14367 "WpsState,Failure");
14368 }
14369 } else {
14370 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053014371 if (wpa_command(intf, "WPS_PBC") < 0) {
14372 send_resp(dut, conn, SIGMA_ERROR,
14373 "ErrorCode,Failed to enable PBC");
14374 goto fail;
14375 }
14376 } else {
14377 /* TODO: PIN method */
14378 send_resp(dut, conn, SIGMA_ERROR,
14379 "ErrorCode,Unsupported WpsConfigMethod value");
14380 goto fail;
14381 }
14382 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
14383 if (res < 0) {
14384 send_resp(dut, conn, SIGMA_ERROR,
14385 "ErrorCode,WPS connection did not complete");
14386 goto fail;
14387 }
14388 if (strstr(buf, "WPS-TIMEOUT")) {
14389 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
14390 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
14391 send_resp(dut, conn, SIGMA_ERROR,
14392 "ErrorCode,OverlapSession");
14393 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
14394 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
14395 } else {
14396 send_resp(dut, conn, SIGMA_ERROR,
14397 "ErrorCode,WPS operation failed");
14398 }
vamsi krishna9b144002017-09-20 13:28:13 +053014399 }
14400
14401fail:
14402 wpa_ctrl_detach(ctrl);
14403 wpa_ctrl_close(ctrl);
14404 return 0;
14405}
14406
14407
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014408static int req_intf(struct sigma_cmd *cmd)
14409{
14410 return get_param(cmd, "interface") == NULL ? -1 : 0;
14411}
14412
14413
14414void sta_register_cmds(void)
14415{
14416 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
14417 cmd_sta_get_ip_config);
14418 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
14419 cmd_sta_set_ip_config);
14420 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
14421 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
14422 cmd_sta_get_mac_address);
14423 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
14424 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
14425 cmd_sta_verify_ip_connection);
14426 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
14427 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
14428 cmd_sta_set_encryption);
14429 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
14430 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
14431 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
14432 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
14433 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
14434 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
14435 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
14436 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
14437 cmd_sta_set_eapakaprime);
14438 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
14439 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
14440 /* TODO: sta_set_ibss */
14441 /* TODO: sta_set_mode */
14442 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
14443 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
14444 /* TODO: sta_up_load */
14445 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
14446 cmd_sta_preset_testparameters);
14447 /* TODO: sta_set_system */
14448 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
14449 /* TODO: sta_set_rifs_test */
14450 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
14451 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
14452 /* TODO: sta_send_coexist_mgmt */
14453 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
14454 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
14455 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
14456 sigma_dut_reg_cmd("sta_reset_default", req_intf,
14457 cmd_sta_reset_default);
14458 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
14459 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
14460 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
14461 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
14462 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014463 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014464 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
14465 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
14466 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
14467 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
14468 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030014469 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
14470 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014471 sigma_dut_reg_cmd("sta_add_credential", req_intf,
14472 cmd_sta_add_credential);
14473 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020014474 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014475 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
14476 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
14477 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
14478 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
14479 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
14480 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030014481 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014482 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
14483 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014484 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053014485 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014486}