blob: 6312dbd009e505a372dbeef987cfa95ed9377ee9 [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
Veerendranath Jakkama9177042020-08-10 00:14:03 +05302309 val = get_param(cmd, "sae_pk_only");
2310 if (val && strcmp(val, "1") == 0 &&
2311 set_network(ifname, id, "sae_pk", "1") < 0)
2312 return ERROR_SEND_STATUS;
2313
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002314 if (dut->program == PROGRAM_60GHZ && network_mode &&
2315 strcasecmp(network_mode, "PBSS") == 0 &&
2316 set_network(ifname, id, "pbss", "1") < 0)
2317 return -2;
2318
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002319 return 1;
2320}
2321
2322
Jouni Malinen8ac93452019-08-14 15:19:13 +03002323static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2324 struct sigma_conn *conn,
2325 const char *ifname, int id)
2326{
2327 char buf[200];
2328
2329 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2330 if (!file_exists(buf))
2331 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2332 if (!file_exists(buf))
2333 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2334 if (!file_exists(buf)) {
2335 char msg[300];
2336
2337 snprintf(msg, sizeof(msg),
2338 "ErrorCode,trustedRootCA system store (%s) not found",
2339 buf);
2340 send_resp(dut, conn, SIGMA_ERROR, msg);
2341 return STATUS_SENT_ERROR;
2342 }
2343
2344 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2345 return ERROR_SEND_STATUS;
2346
2347 return SUCCESS_SEND_STATUS;
2348}
2349
2350
2351static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2352 struct sigma_conn *conn,
2353 const char *ifname, int id,
2354 const char *val)
2355{
2356 char buf[200];
2357#ifdef ANDROID
2358 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2359 int length;
2360#endif /* ANDROID */
2361
2362 if (strcmp(val, "DEFAULT") == 0)
2363 return set_trust_root_system(dut, conn, ifname, id);
2364
2365#ifdef ANDROID
2366 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2367 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2368 if (length > 0) {
2369 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2370 buf);
2371 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2372 goto ca_cert_selected;
2373 }
2374#endif /* ANDROID */
2375
2376 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2377#ifdef __linux__
2378 if (!file_exists(buf)) {
2379 char msg[300];
2380
2381 snprintf(msg, sizeof(msg),
2382 "ErrorCode,trustedRootCA file (%s) not found", buf);
2383 send_resp(dut, conn, SIGMA_ERROR, msg);
2384 return STATUS_SENT_ERROR;
2385 }
2386#endif /* __linux__ */
2387#ifdef ANDROID
2388ca_cert_selected:
2389#endif /* ANDROID */
2390 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2391 return ERROR_SEND_STATUS;
2392
2393 return SUCCESS_SEND_STATUS;
2394}
2395
2396
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002397static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302398 const char *ifname, int username_identity,
2399 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002400{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002401 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002402 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002403 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002404 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002405 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002406
2407 id = set_wpa_common(dut, conn, ifname, cmd);
2408 if (id < 0)
2409 return id;
2410
2411 val = get_param(cmd, "keyMgmtType");
2412 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302413 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002414 trust_root = get_param(cmd, "trustedRootCA");
2415 domain = get_param(cmd, "Domain");
2416 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002417
Jouni Malinenad395a22017-09-01 21:13:46 +03002418 if (val && strcasecmp(val, "SuiteB") == 0) {
2419 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2420 0)
2421 return -2;
2422 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002423 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2424 return -2;
2425 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2426 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2427 return -2;
2428 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2429 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2430 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002431 } else if (!akm &&
2432 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2433 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002434 if (set_network(ifname, id, "key_mgmt",
2435 "WPA-EAP WPA-EAP-SHA256") < 0)
2436 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302437 } else if (akm && atoi(akm) == 14) {
2438 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2439 dut->sta_pmf == STA_PMF_REQUIRED) {
2440 if (set_network(ifname, id, "key_mgmt",
2441 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2442 return -2;
2443 } else {
2444 if (set_network(ifname, id, "key_mgmt",
2445 "WPA-EAP FILS-SHA256") < 0)
2446 return -2;
2447 }
2448
Jouni Malinen8179fee2019-03-28 03:19:47 +02002449 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302450 } else if (akm && atoi(akm) == 15) {
2451 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2452 dut->sta_pmf == STA_PMF_REQUIRED) {
2453 if (set_network(ifname, id, "key_mgmt",
2454 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2455 return -2;
2456 } else {
2457 if (set_network(ifname, id, "key_mgmt",
2458 "WPA-EAP FILS-SHA384") < 0)
2459 return -2;
2460 }
2461
Jouni Malinen8179fee2019-03-28 03:19:47 +02002462 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002463 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002464 if (set_network(ifname, id, "key_mgmt",
2465 "WPA-EAP WPA-EAP-SHA256") < 0)
2466 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002467 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002468 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2469 return -2;
2470 }
2471
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002472 if (trust_root) {
2473 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2474 !domain_suffix) {
2475 send_resp(dut, conn, SIGMA_ERROR,
2476 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2477 return STATUS_SENT_ERROR;
2478 }
2479 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002480 if (res != SUCCESS_SEND_STATUS)
2481 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002482 }
2483
Jouni Malinen53264f62019-05-03 13:04:40 +03002484 val = get_param(cmd, "ServerCert");
2485 if (val) {
2486 FILE *f;
2487 char *result = NULL, *pos;
2488
2489 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2490 val);
2491 f = fopen(buf, "r");
2492 if (f) {
2493 result = fgets(buf, sizeof(buf), f);
2494 fclose(f);
2495 }
2496 if (!result) {
2497 snprintf(buf2, sizeof(buf2),
2498 "ErrorCode,ServerCert hash could not be read from %s",
2499 buf);
2500 send_resp(dut, conn, SIGMA_ERROR, buf2);
2501 return STATUS_SENT_ERROR;
2502 }
2503 pos = strchr(buf, '\n');
2504 if (pos)
2505 *pos = '\0';
Jouni Malinen0572a742020-10-08 13:53:25 +03002506 pos = strchr(buf, '\r');
2507 if (pos)
2508 *pos = '\0';
Jouni Malinen53264f62019-05-03 13:04:40 +03002509 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2510 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2511 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002512
2513 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2514 if (file_exists(buf)) {
2515 sigma_dut_print(dut, DUT_MSG_DEBUG,
2516 "TOD policy enabled for the configured ServerCert hash");
2517 dut->sta_tod_policy = 1;
2518 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002519 }
2520
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002521 if (domain &&
2522 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002523 return ERROR_SEND_STATUS;
2524
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002525 if (domain_suffix &&
2526 set_network_quoted(ifname, id, "domain_suffix_match",
2527 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002528 return ERROR_SEND_STATUS;
2529
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302530 if (username_identity) {
2531 val = get_param(cmd, "username");
2532 if (val) {
2533 if (set_network_quoted(ifname, id, "identity", val) < 0)
2534 return -2;
2535 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002536
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302537 val = get_param(cmd, "password");
2538 if (val) {
2539 if (set_network_quoted(ifname, id, "password", val) < 0)
2540 return -2;
2541 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002542 }
2543
Jouni Malinen8179fee2019-03-28 03:19:47 +02002544 if (dut->akm_values &
2545 ((1 << AKM_FILS_SHA256) |
2546 (1 << AKM_FILS_SHA384) |
2547 (1 << AKM_FT_FILS_SHA256) |
2548 (1 << AKM_FT_FILS_SHA384)))
2549 erp = 1;
2550 if (erp && set_network(ifname, id, "erp", "1") < 0)
2551 return ERROR_SEND_STATUS;
2552
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002553 dut->sta_associate_wait_connect = 1;
2554
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002555 return id;
2556}
2557
2558
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002559static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2560{
2561 const char *val;
2562
2563 if (!cipher)
2564 return 0;
2565
2566 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2567 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2568 else if (strcasecmp(cipher,
2569 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2570 val = "ECDHE-RSA-AES256-GCM-SHA384";
2571 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2572 val = "DHE-RSA-AES256-GCM-SHA384";
2573 else if (strcasecmp(cipher,
2574 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2575 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2576 else
2577 return -1;
2578
2579 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2580 set_network_quoted(ifname, id, "phase1", "");
2581
2582 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2583}
2584
2585
Jouni Malinenf7222712019-06-13 01:50:21 +03002586static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2587 struct sigma_conn *conn,
2588 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002589{
2590 const char *intf = get_param(cmd, "Interface");
2591 const char *ifname, *val;
2592 int id;
2593 char buf[200];
2594#ifdef ANDROID
2595 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2596 int length;
2597 int jb_or_newer = 0;
2598 char prop[PROPERTY_VALUE_MAX];
2599#endif /* ANDROID */
2600
2601 if (intf == NULL)
2602 return -1;
2603
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002604 if (strcmp(intf, get_main_ifname(dut)) == 0)
2605 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002606 else
2607 ifname = intf;
2608
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302609 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002610 if (id < 0)
2611 return id;
2612
2613 if (set_network(ifname, id, "eap", "TLS") < 0)
2614 return -2;
2615
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302616 if (!get_param(cmd, "username") &&
2617 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002618 "wifi-user@wifilabs.local") < 0)
2619 return -2;
2620
2621 val = get_param(cmd, "clientCertificate");
2622 if (val == NULL)
2623 return -1;
2624#ifdef ANDROID
2625 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2626 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2627 if (length < 0) {
2628 /*
2629 * JB started reporting keystore type mismatches, so retry with
2630 * the GET_PUBKEY command if the generic GET fails.
2631 */
2632 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2633 buf, kvalue);
2634 }
2635
2636 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2637 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2638 if (strncmp(prop, "4.0", 3) != 0)
2639 jb_or_newer = 1;
2640 } else
2641 jb_or_newer = 1; /* assume newer */
2642
2643 if (jb_or_newer && length > 0) {
2644 sigma_dut_print(dut, DUT_MSG_INFO,
2645 "Use Android keystore [%s]", buf);
2646 if (set_network(ifname, id, "engine", "1") < 0)
2647 return -2;
2648 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2649 return -2;
2650 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2651 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2652 return -2;
2653 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2654 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2655 return -2;
2656 return 1;
2657 } else if (length > 0) {
2658 sigma_dut_print(dut, DUT_MSG_INFO,
2659 "Use Android keystore [%s]", buf);
2660 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2661 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2662 return -2;
2663 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2664 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2665 return -2;
2666 return 1;
2667 }
2668#endif /* ANDROID */
2669
2670 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2671#ifdef __linux__
2672 if (!file_exists(buf)) {
2673 char msg[300];
2674 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2675 "(%s) not found", buf);
2676 send_resp(dut, conn, SIGMA_ERROR, msg);
2677 return -3;
2678 }
2679#endif /* __linux__ */
2680 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2681 return -2;
2682 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2683 return -2;
2684
2685 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2686 return -2;
2687
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002688 val = get_param(cmd, "keyMgmtType");
2689 if (val && strcasecmp(val, "SuiteB") == 0) {
2690 val = get_param(cmd, "CertType");
2691 if (val && strcasecmp(val, "RSA") == 0) {
2692 if (set_network_quoted(ifname, id, "phase1",
2693 "tls_suiteb=1") < 0)
2694 return -2;
2695 } else {
2696 if (set_network_quoted(ifname, id, "openssl_ciphers",
2697 "SUITEB192") < 0)
2698 return -2;
2699 }
2700
2701 val = get_param(cmd, "TLSCipher");
2702 if (set_tls_cipher(ifname, id, val) < 0) {
2703 send_resp(dut, conn, SIGMA_ERROR,
2704 "ErrorCode,Unsupported TLSCipher value");
2705 return -3;
2706 }
2707 }
2708
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002709 return 1;
2710}
2711
2712
Jouni Malinenf7222712019-06-13 01:50:21 +03002713static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2714 struct sigma_conn *conn,
2715 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002716{
2717 const char *intf = get_param(cmd, "Interface");
2718 const char *ifname;
2719 int id;
2720
2721 if (intf == NULL)
2722 return -1;
2723
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002724 if (strcmp(intf, get_main_ifname(dut)) == 0)
2725 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002726 else
2727 ifname = intf;
2728
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302729 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002730 if (id < 0)
2731 return id;
2732
2733 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2734 send_resp(dut, conn, SIGMA_ERROR,
2735 "errorCode,Failed to set TTLS method");
2736 return 0;
2737 }
2738
2739 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2740 send_resp(dut, conn, SIGMA_ERROR,
2741 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2742 return 0;
2743 }
2744
2745 return 1;
2746}
2747
2748
Jouni Malinenf7222712019-06-13 01:50:21 +03002749static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2750 struct sigma_conn *conn,
2751 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002752{
2753 const char *intf = get_param(cmd, "Interface");
2754 const char *ifname;
2755 int id;
2756
2757 if (intf == NULL)
2758 return -1;
2759
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002760 if (strcmp(intf, get_main_ifname(dut)) == 0)
2761 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002762 else
2763 ifname = intf;
2764
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302765 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002766 if (id < 0)
2767 return id;
2768
2769 if (set_network(ifname, id, "eap", "SIM") < 0)
2770 return -2;
2771
2772 return 1;
2773}
2774
2775
Jouni Malinenf7222712019-06-13 01:50:21 +03002776static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2777 struct sigma_conn *conn,
2778 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002779{
2780 const char *intf = get_param(cmd, "Interface");
2781 const char *ifname, *val;
2782 int id;
2783 char buf[100];
2784
2785 if (intf == NULL)
2786 return -1;
2787
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002788 if (strcmp(intf, get_main_ifname(dut)) == 0)
2789 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002790 else
2791 ifname = intf;
2792
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302793 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002794 if (id < 0)
2795 return id;
2796
2797 if (set_network(ifname, id, "eap", "PEAP") < 0)
2798 return -2;
2799
2800 val = get_param(cmd, "innerEAP");
2801 if (val) {
2802 if (strcasecmp(val, "MSCHAPv2") == 0) {
2803 if (set_network_quoted(ifname, id, "phase2",
2804 "auth=MSCHAPV2") < 0)
2805 return -2;
2806 } else if (strcasecmp(val, "GTC") == 0) {
2807 if (set_network_quoted(ifname, id, "phase2",
2808 "auth=GTC") < 0)
2809 return -2;
2810 } else
2811 return -1;
2812 }
2813
2814 val = get_param(cmd, "peapVersion");
2815 if (val) {
2816 int ver = atoi(val);
2817 if (ver < 0 || ver > 1)
2818 return -1;
2819 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2820 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2821 return -2;
2822 }
2823
2824 return 1;
2825}
2826
2827
Jouni Malinenf7222712019-06-13 01:50:21 +03002828static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2829 struct sigma_conn *conn,
2830 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002831{
2832 const char *intf = get_param(cmd, "Interface");
2833 const char *ifname, *val;
2834 int id;
2835 char buf[100];
2836
2837 if (intf == NULL)
2838 return -1;
2839
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002840 if (strcmp(intf, get_main_ifname(dut)) == 0)
2841 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002842 else
2843 ifname = intf;
2844
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302845 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002846 if (id < 0)
2847 return id;
2848
2849 if (set_network(ifname, id, "eap", "FAST") < 0)
2850 return -2;
2851
2852 val = get_param(cmd, "innerEAP");
2853 if (val) {
2854 if (strcasecmp(val, "MSCHAPV2") == 0) {
2855 if (set_network_quoted(ifname, id, "phase2",
2856 "auth=MSCHAPV2") < 0)
2857 return -2;
2858 } else if (strcasecmp(val, "GTC") == 0) {
2859 if (set_network_quoted(ifname, id, "phase2",
2860 "auth=GTC") < 0)
2861 return -2;
2862 } else
2863 return -1;
2864 }
2865
2866 val = get_param(cmd, "validateServer");
2867 if (val) {
2868 /* TODO */
2869 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2870 "validateServer=%s", val);
2871 }
2872
2873 val = get_param(cmd, "pacFile");
2874 if (val) {
2875 snprintf(buf, sizeof(buf), "blob://%s", val);
2876 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2877 return -2;
2878 }
2879
2880 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2881 0)
2882 return -2;
2883
2884 return 1;
2885}
2886
2887
Jouni Malinenf7222712019-06-13 01:50:21 +03002888static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2889 struct sigma_conn *conn,
2890 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002891{
2892 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302893 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002894 const char *ifname;
2895 int id;
2896
2897 if (intf == NULL)
2898 return -1;
2899
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002900 if (strcmp(intf, get_main_ifname(dut)) == 0)
2901 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002902 else
2903 ifname = intf;
2904
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302905 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002906 if (id < 0)
2907 return id;
2908
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302909 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2910 * hexadecimal).
2911 */
2912 if (username && username[0] == '6') {
2913 if (set_network(ifname, id, "eap", "AKA'") < 0)
2914 return -2;
2915 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002916 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302917 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002918
2919 return 1;
2920}
2921
2922
Jouni Malinenf7222712019-06-13 01:50:21 +03002923static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2924 struct sigma_conn *conn,
2925 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002926{
2927 const char *intf = get_param(cmd, "Interface");
2928 const char *ifname;
2929 int id;
2930
2931 if (intf == NULL)
2932 return -1;
2933
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002934 if (strcmp(intf, get_main_ifname(dut)) == 0)
2935 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002936 else
2937 ifname = intf;
2938
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302939 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002940 if (id < 0)
2941 return id;
2942
2943 if (set_network(ifname, id, "eap", "AKA'") < 0)
2944 return -2;
2945
2946 return 1;
2947}
2948
2949
2950static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2951 struct sigma_cmd *cmd)
2952{
2953 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002954 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002955 const char *ifname;
2956 int id;
2957
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002958 if (strcmp(intf, get_main_ifname(dut)) == 0)
2959 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002960 else
2961 ifname = intf;
2962
2963 id = add_network_common(dut, conn, ifname, cmd);
2964 if (id < 0)
2965 return id;
2966
2967 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2968 return -2;
2969
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002970 if (dut->program == PROGRAM_60GHZ && network_mode &&
2971 strcasecmp(network_mode, "PBSS") == 0 &&
2972 set_network(ifname, id, "pbss", "1") < 0)
2973 return -2;
2974
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002975 return 1;
2976}
2977
2978
Jouni Malinen8e3f8812020-10-05 10:02:03 +03002979static enum sigma_cmd_result sta_set_owe(struct sigma_dut *dut,
2980 struct sigma_conn *conn,
2981 struct sigma_cmd *cmd)
Jouni Malinen47dcc952017-10-09 16:43:24 +03002982{
2983 const char *intf = get_param(cmd, "Interface");
2984 const char *ifname, *val;
2985 int id;
2986
2987 if (intf == NULL)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03002988 return INVALID_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03002989
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002990 if (strcmp(intf, get_main_ifname(dut)) == 0)
2991 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002992 else
2993 ifname = intf;
2994
2995 id = set_wpa_common(dut, conn, ifname, cmd);
2996 if (id < 0)
2997 return id;
2998
2999 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003000 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003001
Hu Wangdd5eed22020-07-16 12:18:03 +08003002 if (dut->owe_ptk_workaround &&
3003 set_network(ifname, id, "owe_ptk_workaround", "1") < 0) {
3004 sigma_dut_print(dut, DUT_MSG_ERROR,
3005 "Failed to set owe_ptk_workaround to 1");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003006 return ERROR_SEND_STATUS;
Hu Wangdd5eed22020-07-16 12:18:03 +08003007 }
3008
Jouni Malinen47dcc952017-10-09 16:43:24 +03003009 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003010 if (val && strcmp(val, "0") == 0) {
3011 if (wpa_command(ifname,
3012 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
3013 sigma_dut_print(dut, DUT_MSG_ERROR,
3014 "Failed to set OWE DH Param element override");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003015 return ERROR_SEND_STATUS;
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003016 }
Hu Wangdd5eed22020-07-16 12:18:03 +08003017 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003018 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003019 "Failed to set owe_group");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003020 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003021 }
3022
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003023 return SUCCESS_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003024}
3025
3026
Jouni Malinenf7222712019-06-13 01:50:21 +03003027static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3028 struct sigma_conn *conn,
3029 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003030{
3031 const char *type = get_param(cmd, "Type");
3032
3033 if (type == NULL) {
3034 send_resp(dut, conn, SIGMA_ERROR,
3035 "ErrorCode,Missing Type argument");
3036 return 0;
3037 }
3038
3039 if (strcasecmp(type, "OPEN") == 0)
3040 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003041 if (strcasecmp(type, "OWE") == 0)
3042 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003043 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003044 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003045 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003046 return cmd_sta_set_psk(dut, conn, cmd);
3047 if (strcasecmp(type, "EAPTLS") == 0)
3048 return cmd_sta_set_eaptls(dut, conn, cmd);
3049 if (strcasecmp(type, "EAPTTLS") == 0)
3050 return cmd_sta_set_eapttls(dut, conn, cmd);
3051 if (strcasecmp(type, "EAPPEAP") == 0)
3052 return cmd_sta_set_peap(dut, conn, cmd);
3053 if (strcasecmp(type, "EAPSIM") == 0)
3054 return cmd_sta_set_eapsim(dut, conn, cmd);
3055 if (strcasecmp(type, "EAPFAST") == 0)
3056 return cmd_sta_set_eapfast(dut, conn, cmd);
3057 if (strcasecmp(type, "EAPAKA") == 0)
3058 return cmd_sta_set_eapaka(dut, conn, cmd);
3059 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3060 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003061 if (strcasecmp(type, "wep") == 0)
3062 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003063
3064 send_resp(dut, conn, SIGMA_ERROR,
3065 "ErrorCode,Unsupported Type value");
3066 return 0;
3067}
3068
3069
3070int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3071{
3072#ifdef __linux__
3073 /* special handling for ath6kl */
3074 char path[128], fname[128], *pos;
3075 ssize_t res;
3076 FILE *f;
3077
Jouni Malinene39cd562019-05-29 23:39:56 +03003078 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3079 intf);
3080 if (res < 0 || res >= sizeof(fname))
3081 return 0;
3082 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003083 if (res < 0)
3084 return 0; /* not ath6kl */
3085
3086 if (res >= (int) sizeof(path))
3087 res = sizeof(path) - 1;
3088 path[res] = '\0';
3089 pos = strrchr(path, '/');
3090 if (pos == NULL)
3091 pos = path;
3092 else
3093 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003094 res = snprintf(fname, sizeof(fname),
3095 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3096 "create_qos", pos);
3097 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003098 return 0; /* not ath6kl */
3099
3100 if (uapsd) {
3101 f = fopen(fname, "w");
3102 if (f == NULL)
3103 return -1;
3104
3105 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3106 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3107 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3108 "20000 0\n");
3109 fclose(f);
3110 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003111 res = snprintf(fname, sizeof(fname),
3112 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3113 "delete_qos", pos);
3114 if (res < 0 || res >= sizeof(fname))
3115 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003116
3117 f = fopen(fname, "w");
3118 if (f == NULL)
3119 return -1;
3120
3121 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3122 fprintf(f, "2 4\n");
3123 fclose(f);
3124 }
3125#endif /* __linux__ */
3126
3127 return 0;
3128}
3129
3130
Jouni Malinenf7222712019-06-13 01:50:21 +03003131static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3132 struct sigma_conn *conn,
3133 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003134{
3135 const char *intf = get_param(cmd, "Interface");
3136 /* const char *ssid = get_param(cmd, "ssid"); */
3137 const char *val;
3138 int max_sp_len = 4;
3139 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3140 char buf[100];
3141 int ret1, ret2;
3142
3143 val = get_param(cmd, "maxSPLength");
3144 if (val) {
3145 max_sp_len = atoi(val);
3146 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3147 max_sp_len != 4)
3148 return -1;
3149 }
3150
3151 val = get_param(cmd, "acBE");
3152 if (val)
3153 ac_be = atoi(val);
3154
3155 val = get_param(cmd, "acBK");
3156 if (val)
3157 ac_bk = atoi(val);
3158
3159 val = get_param(cmd, "acVI");
3160 if (val)
3161 ac_vi = atoi(val);
3162
3163 val = get_param(cmd, "acVO");
3164 if (val)
3165 ac_vo = atoi(val);
3166
3167 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3168
3169 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3170 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3171 ret1 = wpa_command(intf, buf);
3172
3173 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3174 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3175 ret2 = wpa_command(intf, buf);
3176
3177 if (ret1 && ret2) {
3178 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3179 "UAPSD parameters.");
3180 return -2;
3181 }
3182
3183 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3184 send_resp(dut, conn, SIGMA_ERROR,
3185 "ErrorCode,Failed to set ath6kl QoS parameters");
3186 return 0;
3187 }
3188
3189 return 1;
3190}
3191
3192
Jouni Malinenf7222712019-06-13 01:50:21 +03003193static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3194 struct sigma_conn *conn,
3195 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003196{
3197 char buf[1000];
3198 const char *intf = get_param(cmd, "Interface");
3199 const char *grp = get_param(cmd, "Group");
3200 const char *act = get_param(cmd, "Action");
3201 const char *tid = get_param(cmd, "Tid");
3202 const char *dir = get_param(cmd, "Direction");
3203 const char *psb = get_param(cmd, "Psb");
3204 const char *up = get_param(cmd, "Up");
3205 const char *fixed = get_param(cmd, "Fixed");
3206 const char *size = get_param(cmd, "Size");
3207 const char *msize = get_param(cmd, "Maxsize");
3208 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3209 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3210 const char *inact = get_param(cmd, "Inactivity");
3211 const char *sus = get_param(cmd, "Suspension");
3212 const char *mindr = get_param(cmd, "Mindatarate");
3213 const char *meandr = get_param(cmd, "Meandatarate");
3214 const char *peakdr = get_param(cmd, "Peakdatarate");
3215 const char *phyrate = get_param(cmd, "Phyrate");
3216 const char *burstsize = get_param(cmd, "Burstsize");
3217 const char *sba = get_param(cmd, "Sba");
3218 int direction;
3219 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003220 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003221 int fixed_int;
3222 int psb_ts;
3223
3224 if (intf == NULL || grp == NULL || act == NULL )
3225 return -1;
3226
3227 if (strcasecmp(act, "addts") == 0) {
3228 if (tid == NULL || dir == NULL || psb == NULL ||
3229 up == NULL || fixed == NULL || size == NULL)
3230 return -1;
3231
3232 /*
3233 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3234 * possible values, but WMM-AC and V-E test scripts use "UP,
3235 * "DOWN", and "BIDI".
3236 */
3237 if (strcasecmp(dir, "uplink") == 0 ||
3238 strcasecmp(dir, "up") == 0) {
3239 direction = 0;
3240 } else if (strcasecmp(dir, "downlink") == 0 ||
3241 strcasecmp(dir, "down") == 0) {
3242 direction = 1;
3243 } else if (strcasecmp(dir, "bidi") == 0) {
3244 direction = 2;
3245 } else {
3246 sigma_dut_print(dut, DUT_MSG_ERROR,
3247 "Direction %s not supported", dir);
3248 return -1;
3249 }
3250
3251 if (strcasecmp(psb, "legacy") == 0) {
3252 psb_ts = 0;
3253 } else if (strcasecmp(psb, "uapsd") == 0) {
3254 psb_ts = 1;
3255 } else {
3256 sigma_dut_print(dut, DUT_MSG_ERROR,
3257 "PSB %s not supported", psb);
3258 return -1;
3259 }
3260
3261 if (atoi(tid) < 0 || atoi(tid) > 7) {
3262 sigma_dut_print(dut, DUT_MSG_ERROR,
3263 "TID %s not supported", tid);
3264 return -1;
3265 }
3266
3267 if (strcasecmp(fixed, "true") == 0) {
3268 fixed_int = 1;
3269 } else {
3270 fixed_int = 0;
3271 }
3272
Peng Xu93319622017-10-04 17:58:16 -07003273 if (sba)
3274 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003275
3276 dut->dialog_token++;
3277 handle = 7000 + dut->dialog_token;
3278
3279 /*
3280 * size: convert to hex
3281 * maxsi: convert to hex
3282 * mindr: convert to hex
3283 * meandr: convert to hex
3284 * peakdr: convert to hex
3285 * burstsize: convert to hex
3286 * phyrate: convert to hex
3287 * sba: convert to hex with modification
3288 * minsi: convert to integer
3289 * sus: convert to integer
3290 * inact: convert to integer
3291 * maxsi: convert to integer
3292 */
3293
3294 /*
3295 * The Nominal MSDU Size field is 2 octets long and contains an
3296 * unsigned integer that specifies the nominal size, in octets,
3297 * of MSDUs belonging to the traffic under this traffic
3298 * specification and is defined in Figure 16. If the Fixed
3299 * subfield is set to 1, then the size of the MSDU is fixed and
3300 * is indicated by the Size Subfield. If the Fixed subfield is
3301 * set to 0, then the size of the MSDU might not be fixed and
3302 * the Size indicates the nominal MSDU size.
3303 *
3304 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3305 * and specifies the excess allocation of time (and bandwidth)
3306 * over and above the stated rates required to transport an MSDU
3307 * belonging to the traffic in this TSPEC. This field is
3308 * represented as an unsigned binary number with an implicit
3309 * binary point after the leftmost 3 bits. For example, an SBA
3310 * of 1.75 is represented as 0x3800. This field is included to
3311 * account for retransmissions. As such, the value of this field
3312 * must be greater than unity.
3313 */
3314
3315 snprintf(buf, sizeof(buf),
3316 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3317 " 0x%X 0x%X 0x%X"
3318 " 0x%X 0x%X 0x%X"
3319 " 0x%X %d %d %d %d"
3320 " %d %d",
3321 intf, handle, tid, direction, psb_ts, up,
3322 (unsigned int) ((fixed_int << 15) | atoi(size)),
3323 msize ? atoi(msize) : 0,
3324 mindr ? atoi(mindr) : 0,
3325 meandr ? atoi(meandr) : 0,
3326 peakdr ? atoi(peakdr) : 0,
3327 burstsize ? atoi(burstsize) : 0,
3328 phyrate ? atoi(phyrate) : 0,
3329 sba ? ((unsigned int) (((int) sba_fv << 13) |
3330 (int)((sba_fv - (int) sba_fv) *
3331 8192))) : 0,
3332 minsi ? atoi(minsi) : 0,
3333 sus ? atoi(sus) : 0,
3334 0, 0,
3335 inact ? atoi(inact) : 0,
3336 maxsi ? atoi(maxsi) : 0);
3337
3338 if (system(buf) != 0) {
3339 sigma_dut_print(dut, DUT_MSG_ERROR,
3340 "iwpriv addtspec request failed");
3341 send_resp(dut, conn, SIGMA_ERROR,
3342 "errorCode,Failed to execute addTspec command");
3343 return 0;
3344 }
3345
3346 sigma_dut_print(dut, DUT_MSG_INFO,
3347 "iwpriv addtspec request send");
3348
3349 /* Mapping handle to a TID */
3350 dut->tid_to_handle[atoi(tid)] = handle;
3351 } else if (strcasecmp(act, "delts") == 0) {
3352 if (tid == NULL)
3353 return -1;
3354
3355 if (atoi(tid) < 0 || atoi(tid) > 7) {
3356 sigma_dut_print(dut, DUT_MSG_ERROR,
3357 "TID %s not supported", tid);
3358 send_resp(dut, conn, SIGMA_ERROR,
3359 "errorCode,Unsupported TID");
3360 return 0;
3361 }
3362
3363 handle = dut->tid_to_handle[atoi(tid)];
3364
3365 if (handle < 7000 || handle > 7255) {
3366 /* Invalid handle ie no mapping for that TID */
3367 sigma_dut_print(dut, DUT_MSG_ERROR,
3368 "handle-> %d not found", handle);
3369 }
3370
3371 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3372 intf, handle);
3373
3374 if (system(buf) != 0) {
3375 sigma_dut_print(dut, DUT_MSG_ERROR,
3376 "iwpriv deltspec request failed");
3377 send_resp(dut, conn, SIGMA_ERROR,
3378 "errorCode,Failed to execute delTspec command");
3379 return 0;
3380 }
3381
3382 sigma_dut_print(dut, DUT_MSG_INFO,
3383 "iwpriv deltspec request send");
3384
3385 dut->tid_to_handle[atoi(tid)] = 0;
3386 } else {
3387 sigma_dut_print(dut, DUT_MSG_ERROR,
3388 "Action type %s not supported", act);
3389 send_resp(dut, conn, SIGMA_ERROR,
3390 "errorCode,Unsupported Action");
3391 return 0;
3392 }
3393
3394 return 1;
3395}
3396
3397
vamsi krishna52e16f92017-08-29 12:37:34 +05303398static int find_network(struct sigma_dut *dut, const char *ssid)
3399{
3400 char list[4096];
3401 char *pos;
3402
3403 sigma_dut_print(dut, DUT_MSG_DEBUG,
3404 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003405 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303406 list, sizeof(list)) < 0)
3407 return -1;
3408 pos = strstr(list, ssid);
3409 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3410 return -1;
3411
3412 while (pos > list && pos[-1] != '\n')
3413 pos--;
3414 dut->infra_network_id = atoi(pos);
3415 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3416 return 0;
3417}
3418
3419
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303420/**
3421 * enum qca_sta_helper_config_params - This helper enum defines the config
3422 * parameters which can be delivered to sta.
3423 */
3424enum qca_sta_helper_config_params {
3425 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE */
3426 STA_SET_RSNIE,
3427
3428 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC */
3429 STA_SET_LDPC,
3430
3431 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC */
3432 STA_SET_TX_STBC,
3433
3434 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC */
3435 STA_SET_RX_STBC,
3436
3437 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION */
3438 STA_SET_TX_MSDU,
3439
3440 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION */
3441 STA_SET_RX_MSDU,
3442};
3443
3444
3445static int sta_config_params(struct sigma_dut *dut, const char *intf,
3446 enum qca_sta_helper_config_params config_cmd,
3447 int value)
Sunil Dutt44595082018-02-12 19:41:45 +05303448{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303449#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05303450 struct nl_msg *msg;
3451 int ret;
3452 struct nlattr *params;
3453 int ifindex;
3454
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303455 ifindex = if_nametoindex(intf);
3456 if (ifindex == 0) {
3457 sigma_dut_print(dut, DUT_MSG_ERROR,
3458 "%s: Interface %s does not exist",
3459 __func__, intf);
3460 return -1;
3461 }
3462
Sunil Dutt44595082018-02-12 19:41:45 +05303463 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3464 NL80211_CMD_VENDOR)) ||
3465 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3466 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3467 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3468 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303469 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)))
3470 goto fail;
3471
3472 switch (config_cmd) {
3473 case STA_SET_RSNIE:
3474 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, value))
3475 goto fail;
3476 break;
3477 case STA_SET_LDPC:
3478 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC, value))
3479 goto fail;
3480 break;
3481 case STA_SET_TX_STBC:
3482 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC, value))
3483 goto fail;
3484 break;
3485 case STA_SET_RX_STBC:
3486 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC, value))
3487 goto fail;
3488 break;
3489 case STA_SET_TX_MSDU:
3490 if (nla_put_u8(msg,
3491 QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION,
3492 value))
3493 goto fail;
3494 break;
3495 case STA_SET_RX_MSDU:
3496 if (nla_put_u8(msg,
3497 QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION,
3498 value))
3499 goto fail;
3500 break;
Sunil Dutt44595082018-02-12 19:41:45 +05303501 }
3502 nla_nest_end(msg, params);
3503
3504 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3505 if (ret) {
3506 sigma_dut_print(dut, DUT_MSG_ERROR,
3507 "%s: err in send_and_recv_msgs, ret=%d",
3508 __func__, ret);
3509 return ret;
3510 }
3511
3512 return 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303513
3514fail:
3515 sigma_dut_print(dut, DUT_MSG_ERROR,
3516 "%s: err in adding vendor_cmd and vendor_data",
3517 __func__);
3518 nlmsg_free(msg);
Sunil Dutt44595082018-02-12 19:41:45 +05303519#endif /* NL80211_SUPPORT */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303520 return -1;
3521}
Sunil Dutt44595082018-02-12 19:41:45 +05303522
3523
Jouni Malinenf7222712019-06-13 01:50:21 +03003524static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3525 struct sigma_conn *conn,
3526 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003527{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303528#ifdef NL80211_SUPPORT
3529 const char *intf = get_param(cmd, "Interface");
3530#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003531 const char *ssid = get_param(cmd, "ssid");
3532 const char *wps_param = get_param(cmd, "WPS");
3533 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003534 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003535 const char *network_mode = get_param(cmd, "network_mode");
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303536 const char *ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003537 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003538 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003539 int e;
3540 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3541 struct wpa_ctrl *ctrl = NULL;
3542 int num_network_not_found = 0;
3543 int num_disconnected = 0;
3544 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003545
3546 if (ssid == NULL)
3547 return -1;
3548
Jouni Malinen37d5c692019-08-19 16:56:55 +03003549 dut->server_cert_tod = 0;
3550
Jouni Malinen3c367e82017-06-23 17:01:47 +03003551 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303552#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003553 if (get_driver_type(dut) == DRIVER_WCN) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303554 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Sunil Dutt44595082018-02-12 19:41:45 +05303555 dut->config_rsnie = 1;
3556 }
3557#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003558 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3559 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003560 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03003561 send_resp(dut, conn, SIGMA_ERROR,
3562 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3563 return 0;
3564 }
3565 }
3566
Jouni Malinen68143132017-09-02 02:34:08 +03003567 if (dut->sae_commit_override) {
3568 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3569 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003570 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03003571 send_resp(dut, conn, SIGMA_ERROR,
3572 "ErrorCode,Failed to set SAE commit override");
3573 return 0;
3574 }
3575 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303576#ifdef ANDROID
3577 if (dut->fils_hlp)
3578 process_fils_hlp(dut);
3579#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003580
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003581 if (wps_param &&
3582 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3583 wps = 1;
3584
Vamsi Krishnac1633d22020-05-06 18:31:21 +05303585 if (dut->ocvc &&
3586 set_network(get_station_ifname(dut), dut->infra_network_id,
3587 "ocv", "1") < 0)
3588 return ERROR_SEND_STATUS;
3589
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003590 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003591 if (dut->program == PROGRAM_60GHZ && network_mode &&
3592 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003593 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003594 "pbss", "1") < 0)
3595 return -2;
3596
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003597 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3598 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3599 "parameters not yet set");
3600 return 0;
3601 }
3602 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003603 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003604 return -2;
3605 } else {
3606 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3607 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003608 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003609 return -2;
3610 }
3611 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303612 if (strcmp(ssid, dut->infra_ssid) == 0) {
3613 sigma_dut_print(dut, DUT_MSG_DEBUG,
3614 "sta_associate for the most recently added network");
3615 } else if (find_network(dut, ssid) < 0) {
3616 sigma_dut_print(dut, DUT_MSG_DEBUG,
3617 "sta_associate for a previously stored network profile");
3618 send_resp(dut, conn, SIGMA_ERROR,
3619 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003620 return 0;
3621 }
3622
3623 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003624 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003625 "bssid", bssid) < 0) {
3626 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3627 "Invalid bssid argument");
3628 return 0;
3629 }
3630
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303631 if ((dut->program == PROGRAM_WPA3 &&
3632 dut->sta_associate_wait_connect) ||
3633 dut->program == PROGRAM_QM) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003634 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003635 if (!ctrl)
3636 return ERROR_SEND_STATUS;
3637 }
3638
Jouni Malinen46a19b62017-06-23 14:31:27 +03003639 extra[0] = '\0';
3640 if (chan)
3641 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003642 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003643 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3644 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003645 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003646 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3647 "network id %d on %s",
3648 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003649 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003650 ret = ERROR_SEND_STATUS;
3651 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003652 }
3653 }
3654
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003655 if (!ctrl)
3656 return SUCCESS_SEND_STATUS;
3657
3658 /* Wait for connection result to be able to store server certificate
3659 * hash for trust root override testing
3660 * (dev_exec_action,ServerCertTrust). */
3661
3662 for (e = 0; e < 20; e++) {
3663 const char *events[] = {
3664 "CTRL-EVENT-EAP-PEER-CERT",
3665 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3666 "CTRL-EVENT-DISCONNECTED",
3667 "CTRL-EVENT-CONNECTED",
3668 "CTRL-EVENT-NETWORK-NOT-FOUND",
3669 NULL
3670 };
3671 char buf[1024];
3672 int res;
3673
3674 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3675 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02003676 send_resp(dut, conn, SIGMA_COMPLETE,
3677 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003678 ret = STATUS_SENT_ERROR;
3679 break;
3680 }
3681 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3682 buf);
3683
3684 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3685 strstr(buf, " depth=0")) {
3686 char *pos = strstr(buf, " hash=");
3687
3688 if (pos) {
3689 char *end;
3690
Jouni Malinen34b19cb2019-08-16 16:37:17 +03003691 if (strstr(buf, " tod=1"))
3692 tod = 1;
3693 else if (strstr(buf, " tod=2"))
3694 tod = 2;
3695 else
3696 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003697 sigma_dut_print(dut, DUT_MSG_DEBUG,
3698 "Server certificate TOD policy: %d",
3699 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03003700 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003701
3702 pos += 6;
3703 end = strchr(pos, ' ');
3704 if (end)
3705 *end = '\0';
3706 strlcpy(dut->server_cert_hash, pos,
3707 sizeof(dut->server_cert_hash));
3708 sigma_dut_print(dut, DUT_MSG_DEBUG,
3709 "Server certificate hash: %s",
3710 dut->server_cert_hash);
3711 }
3712 }
3713
3714 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3715 send_resp(dut, conn, SIGMA_COMPLETE,
3716 "Result,TLS server certificate validation failed");
3717 ret = STATUS_SENT_ERROR;
3718 break;
3719 }
3720
3721 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3722 num_network_not_found++;
3723
3724 if (num_network_not_found > 2) {
3725 send_resp(dut, conn, SIGMA_COMPLETE,
3726 "Result,Network not found");
3727 ret = STATUS_SENT_ERROR;
3728 break;
3729 }
3730 }
3731
3732 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3733 num_disconnected++;
3734
3735 if (num_disconnected > 2) {
3736 send_resp(dut, conn, SIGMA_COMPLETE,
3737 "Result,Connection failed");
3738 ret = STATUS_SENT_ERROR;
3739 break;
3740 }
3741 }
3742
3743 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3744 if (tod >= 0) {
3745 sigma_dut_print(dut, DUT_MSG_DEBUG,
3746 "Network profile TOD policy update: %d -> %d",
3747 dut->sta_tod_policy, tod);
3748 dut->sta_tod_policy = tod;
3749 }
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303750 if (dut->program == PROGRAM_QM) {
3751 unsigned char iface_mac_addr[ETH_ALEN];
3752 char ipv6[100];
3753
3754 if (get_hwaddr(ifname, iface_mac_addr) < 0) {
3755 sigma_dut_print(dut, DUT_MSG_ERROR,
3756 "%s: get_hwaddr %s failed",
3757 __func__, ifname);
3758 ret = ERROR_SEND_STATUS;
3759 break;
3760 }
3761
3762 convert_mac_addr_to_ipv6_lladdr(iface_mac_addr,
3763 ipv6,
3764 sizeof(ipv6));
3765
3766 if (set_ipv6_addr(dut, ipv6, "64", ifname) !=
3767 0) {
3768 ret = ERROR_SEND_STATUS;
3769 break;
3770 }
3771 }
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003772 break;
3773 }
3774 }
3775done:
3776 if (ctrl) {
3777 wpa_ctrl_detach(ctrl);
3778 wpa_ctrl_close(ctrl);
3779 }
3780 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003781}
3782
3783
3784static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3785{
3786 char buf[500], cmd[200];
3787 int res;
3788
3789 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3790 * default path */
3791 res = snprintf(cmd, sizeof(cmd),
3792 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3793 file_exists("./hs20-osu-client") ?
3794 "./hs20-osu-client" : "hs20-osu-client",
3795 sigma_wpas_ctrl,
3796 dut->summary_log ? "-s " : "",
3797 dut->summary_log ? dut->summary_log : "");
3798 if (res < 0 || res >= (int) sizeof(cmd))
3799 return -1;
3800
3801 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3802 if (res < 0 || res >= (int) sizeof(buf))
3803 return -1;
3804 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3805
3806 if (system(buf) != 0) {
3807 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3808 return -1;
3809 }
3810 sigma_dut_print(dut, DUT_MSG_DEBUG,
3811 "Completed hs20-osu-client operation");
3812
3813 return 0;
3814}
3815
3816
3817static int download_ppsmo(struct sigma_dut *dut,
3818 struct sigma_conn *conn,
3819 const char *intf,
3820 struct sigma_cmd *cmd)
3821{
3822 const char *name, *path, *val;
3823 char url[500], buf[600], fbuf[100];
3824 char *fqdn = NULL;
3825
3826 name = get_param(cmd, "FileName");
3827 path = get_param(cmd, "FilePath");
3828 if (name == NULL || path == NULL)
3829 return -1;
3830
3831 if (strcasecmp(path, "VendorSpecific") == 0) {
3832 snprintf(url, sizeof(url), "PPS/%s", name);
3833 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3834 "from the device (%s)", url);
3835 if (!file_exists(url)) {
3836 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3837 "PPS MO file does not exist");
3838 return 0;
3839 }
3840 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3841 if (system(buf) != 0) {
3842 send_resp(dut, conn, SIGMA_ERROR,
3843 "errorCode,Failed to copy PPS MO");
3844 return 0;
3845 }
3846 } else if (strncasecmp(path, "http:", 5) != 0 &&
3847 strncasecmp(path, "https:", 6) != 0) {
3848 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3849 "Unsupported FilePath value");
3850 return 0;
3851 } else {
3852 snprintf(url, sizeof(url), "%s/%s", path, name);
3853 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3854 url);
3855 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3856 remove("pps-tnds.xml");
3857 if (system(buf) != 0) {
3858 send_resp(dut, conn, SIGMA_ERROR,
3859 "errorCode,Failed to download PPS MO");
3860 return 0;
3861 }
3862 }
3863
3864 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3865 send_resp(dut, conn, SIGMA_ERROR,
3866 "errorCode,Failed to parse downloaded PPSMO");
3867 return 0;
3868 }
3869 unlink("pps-tnds.xml");
3870
3871 val = get_param(cmd, "managementTreeURI");
3872 if (val) {
3873 const char *pos, *end;
3874 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3875 val);
3876 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3877 send_resp(dut, conn, SIGMA_ERROR,
3878 "errorCode,Invalid managementTreeURI prefix");
3879 return 0;
3880 }
3881 pos = val + 8;
3882 end = strchr(pos, '/');
3883 if (end == NULL ||
3884 strcmp(end, "/PerProviderSubscription") != 0) {
3885 send_resp(dut, conn, SIGMA_ERROR,
3886 "errorCode,Invalid managementTreeURI postfix");
3887 return 0;
3888 }
3889 if (end - pos >= (int) sizeof(fbuf)) {
3890 send_resp(dut, conn, SIGMA_ERROR,
3891 "errorCode,Too long FQDN in managementTreeURI");
3892 return 0;
3893 }
3894 memcpy(fbuf, pos, end - pos);
3895 fbuf[end - pos] = '\0';
3896 fqdn = fbuf;
3897 sigma_dut_print(dut, DUT_MSG_INFO,
3898 "FQDN from managementTreeURI: %s", fqdn);
3899 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3900 FILE *f = fopen("pps-fqdn", "r");
3901 if (f) {
3902 if (fgets(fbuf, sizeof(fbuf), f)) {
3903 fbuf[sizeof(fbuf) - 1] = '\0';
3904 fqdn = fbuf;
3905 sigma_dut_print(dut, DUT_MSG_DEBUG,
3906 "Use FQDN %s", fqdn);
3907 }
3908 fclose(f);
3909 }
3910 }
3911
3912 if (fqdn == NULL) {
3913 send_resp(dut, conn, SIGMA_ERROR,
3914 "errorCode,No FQDN specified");
3915 return 0;
3916 }
3917
3918 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3919 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3920 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3921
3922 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3923 if (rename("pps.xml", buf) < 0) {
3924 send_resp(dut, conn, SIGMA_ERROR,
3925 "errorCode,Could not move PPS MO");
3926 return 0;
3927 }
3928
3929 if (strcasecmp(path, "VendorSpecific") == 0) {
3930 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3931 fqdn);
3932 if (system(buf)) {
3933 send_resp(dut, conn, SIGMA_ERROR,
3934 "errorCode,Failed to copy OSU CA cert");
3935 return 0;
3936 }
3937
3938 snprintf(buf, sizeof(buf),
3939 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3940 fqdn);
3941 if (system(buf)) {
3942 send_resp(dut, conn, SIGMA_ERROR,
3943 "errorCode,Failed to copy AAA CA cert");
3944 return 0;
3945 }
3946 } else {
3947 snprintf(buf, sizeof(buf),
3948 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3949 fqdn, fqdn);
3950 if (run_hs20_osu(dut, buf) < 0) {
3951 send_resp(dut, conn, SIGMA_ERROR,
3952 "errorCode,Failed to download OSU CA cert");
3953 return 0;
3954 }
3955
3956 snprintf(buf, sizeof(buf),
3957 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3958 fqdn, fqdn);
3959 if (run_hs20_osu(dut, buf) < 0) {
3960 sigma_dut_print(dut, DUT_MSG_INFO,
3961 "Failed to download AAA CA cert");
3962 }
3963 }
3964
3965 if (file_exists("next-client-cert.pem")) {
3966 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3967 if (rename("next-client-cert.pem", buf) < 0) {
3968 send_resp(dut, conn, SIGMA_ERROR,
3969 "errorCode,Could not move client certificate");
3970 return 0;
3971 }
3972 }
3973
3974 if (file_exists("next-client-key.pem")) {
3975 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3976 if (rename("next-client-key.pem", buf) < 0) {
3977 send_resp(dut, conn, SIGMA_ERROR,
3978 "errorCode,Could not move client key");
3979 return 0;
3980 }
3981 }
3982
3983 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3984 if (run_hs20_osu(dut, buf) < 0) {
3985 send_resp(dut, conn, SIGMA_ERROR,
3986 "errorCode,Failed to configure credential from "
3987 "PPSMO");
3988 return 0;
3989 }
3990
3991 return 1;
3992}
3993
3994
3995static int download_cert(struct sigma_dut *dut,
3996 struct sigma_conn *conn,
3997 const char *intf,
3998 struct sigma_cmd *cmd)
3999{
4000 const char *name, *path;
4001 char url[500], buf[600];
4002
4003 name = get_param(cmd, "FileName");
4004 path = get_param(cmd, "FilePath");
4005 if (name == NULL || path == NULL)
4006 return -1;
4007
4008 if (strcasecmp(path, "VendorSpecific") == 0) {
4009 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
4010 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4011 "certificate from the device (%s)", url);
4012 if (!file_exists(url)) {
4013 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4014 "certificate file does not exist");
4015 return 0;
4016 }
4017 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
4018 if (system(buf) != 0) {
4019 send_resp(dut, conn, SIGMA_ERROR,
4020 "errorCode,Failed to copy client "
4021 "certificate");
4022 return 0;
4023 }
4024
4025 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
4026 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4027 "private key from the device (%s)", url);
4028 if (!file_exists(url)) {
4029 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4030 "private key file does not exist");
4031 return 0;
4032 }
4033 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
4034 if (system(buf) != 0) {
4035 send_resp(dut, conn, SIGMA_ERROR,
4036 "errorCode,Failed to copy client key");
4037 return 0;
4038 }
4039 } else if (strncasecmp(path, "http:", 5) != 0 &&
4040 strncasecmp(path, "https:", 6) != 0) {
4041 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4042 "Unsupported FilePath value");
4043 return 0;
4044 } else {
4045 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
4046 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
4047 "certificate/key from %s", url);
4048 snprintf(buf, sizeof(buf),
4049 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
4050 if (system(buf) != 0) {
4051 send_resp(dut, conn, SIGMA_ERROR,
4052 "errorCode,Failed to download client "
4053 "certificate");
4054 return 0;
4055 }
4056
4057 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
4058 {
4059 send_resp(dut, conn, SIGMA_ERROR,
4060 "errorCode,Failed to copy client key");
4061 return 0;
4062 }
4063 }
4064
4065 return 1;
4066}
4067
4068
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004069static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
4070 struct sigma_conn *conn,
4071 struct sigma_cmd *cmd)
4072{
4073 const char *val;
4074 const char *intf = get_param(cmd, "interface");
4075
4076 if (!intf)
4077 return -1;
4078
4079 val = get_param(cmd, "WscIEFragment");
4080 if (val && strcasecmp(val, "enable") == 0) {
4081 sigma_dut_print(dut, DUT_MSG_DEBUG,
4082 "Enable WSC IE fragmentation");
4083
4084 dut->wsc_fragment = 1;
4085 /* set long attributes to force fragmentation */
4086 if (wpa_command(intf, "SET device_name "
4087 WPS_LONG_DEVICE_NAME) < 0)
4088 return -2;
4089 if (wpa_command(intf, "SET manufacturer "
4090 WPS_LONG_MANUFACTURER) < 0)
4091 return -2;
4092 if (wpa_command(intf, "SET model_name "
4093 WPS_LONG_MODEL_NAME) < 0)
4094 return -2;
4095 if (wpa_command(intf, "SET model_number "
4096 WPS_LONG_MODEL_NUMBER) < 0)
4097 return -2;
4098 if (wpa_command(intf, "SET serial_number "
4099 WPS_LONG_SERIAL_NUMBER) < 0)
4100 return -2;
4101 }
4102
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02004103 val = get_param(cmd, "RSN_IE");
4104 if (val) {
4105 if (strcasecmp(val, "disable") == 0)
4106 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
4107 else if (strcasecmp(val, "enable") == 0)
4108 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
4109 }
4110
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004111 val = get_param(cmd, "WpsVersion");
4112 if (val)
4113 dut->wps_forced_version = get_wps_forced_version(dut, val);
4114
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004115 val = get_param(cmd, "WscEAPFragment");
4116 if (val && strcasecmp(val, "enable") == 0)
4117 dut->eap_fragment = 1;
4118
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004119 return 1;
4120}
4121
4122
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004123static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4124 struct sigma_conn *conn,
4125 const char *intf,
4126 struct sigma_cmd *cmd)
4127{
4128 const char *val;
4129
4130 val = get_param(cmd, "FileType");
4131 if (val && strcasecmp(val, "PPSMO") == 0)
4132 return download_ppsmo(dut, conn, intf, cmd);
4133 if (val && strcasecmp(val, "CERT") == 0)
4134 return download_cert(dut, conn, intf, cmd);
4135 if (val) {
4136 send_resp(dut, conn, SIGMA_ERROR,
4137 "ErrorCode,Unsupported FileType");
4138 return 0;
4139 }
4140
4141 return 1;
4142}
4143
4144
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304145static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4146 struct sigma_conn *conn,
4147 const char *intf,
4148 struct sigma_cmd *cmd)
4149{
4150 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304151 char buf[1000];
4152 char text[20];
4153 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304154
4155 val = get_param(cmd, "OCESupport");
4156 if (val && strcasecmp(val, "Disable") == 0) {
4157 if (wpa_command(intf, "SET oce 0") < 0) {
4158 send_resp(dut, conn, SIGMA_ERROR,
4159 "ErrorCode,Failed to disable OCE");
4160 return 0;
4161 }
4162 } else if (val && strcasecmp(val, "Enable") == 0) {
4163 if (wpa_command(intf, "SET oce 1") < 0) {
4164 send_resp(dut, conn, SIGMA_ERROR,
4165 "ErrorCode,Failed to enable OCE");
4166 return 0;
4167 }
4168 }
4169
vamsi krishnaa2799492017-12-05 14:28:01 +05304170 val = get_param(cmd, "FILScap");
4171 if (val && (atoi(val) == 1)) {
4172 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4173 send_resp(dut, conn, SIGMA_ERROR,
4174 "ErrorCode,Failed to enable FILS");
4175 return 0;
4176 }
4177 } else if (val && (atoi(val) == 0)) {
4178 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4179 send_resp(dut, conn, SIGMA_ERROR,
4180 "ErrorCode,Failed to disable FILS");
4181 return 0;
4182 }
4183 }
4184
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304185 val = get_param(cmd, "FILSHLP");
4186 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004187 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304188 sizeof(text)) < 0)
4189 return -2;
4190 hwaddr_aton(text, addr);
4191 snprintf(buf, sizeof(buf),
4192 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4193 "080045100140000040004011399e00000000ffffffff00440043"
4194 "012cb30001010600fd4f46410000000000000000000000000000"
4195 "000000000000"
4196 "%02x%02x%02x%02x%02x%02x"
4197 "0000000000000000000000000000000000000000000000000000"
4198 "0000000000000000000000000000000000000000000000000000"
4199 "0000000000000000000000000000000000000000000000000000"
4200 "0000000000000000000000000000000000000000000000000000"
4201 "0000000000000000000000000000000000000000000000000000"
4202 "0000000000000000000000000000000000000000000000000000"
4203 "0000000000000000000000000000000000000000000000000000"
4204 "0000000000000000000000000000000000000000638253633501"
4205 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4206 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4207 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4208 if (wpa_command(intf, buf)) {
4209 send_resp(dut, conn, SIGMA_ERROR,
4210 "ErrorCode,Failed to add HLP");
4211 return 0;
4212 }
4213 dut->fils_hlp = 1;
4214 }
4215
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304216 return 1;
4217}
4218
4219
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004220static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4221 const char *val)
4222{
4223 int counter = 0;
4224 char token[50];
4225 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304226 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004227
Peng Xub8fc5cc2017-05-10 17:27:28 -07004228 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004229 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304230 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004231 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004232 if (strcmp(result, "disable") == 0)
4233 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4234 else
4235 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304236 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004237 counter++;
4238 }
4239}
4240
4241
4242static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4243 const char *val)
4244{
4245 char buf[100];
4246
4247 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4248 if (system(buf) != 0) {
4249 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4250 }
4251}
4252
4253
4254static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4255 const char *val)
4256{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004257 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004258 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004259 }
4260}
4261
4262
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004263static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4264 const char *val)
4265{
4266#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004267 int wmmenable = 1;
4268
4269 if (val &&
4270 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4271 wmmenable = 0;
4272
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304273 return wcn_wifi_test_config_set_u8(
4274 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4275 wmmenable);
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004276#else /* NL80211_SUPPORT */
4277 sigma_dut_print(dut, DUT_MSG_ERROR,
4278 "WMM cannot be changed without NL80211_SUPPORT defined");
4279 return -1;
4280#endif /* NL80211_SUPPORT */
4281}
4282
4283
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004284static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4285 const char *val)
4286{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004287 int sgi20;
4288
4289 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4290
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004291 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004292}
4293
4294
4295static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4296 const char *val)
4297{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304298 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004299
4300 /* Disable Tx Beam forming when using a fixed rate */
4301 ath_disable_txbf(dut, intf);
4302
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304303 v = atoi(val);
4304 if (v < 0 || v > 32) {
4305 sigma_dut_print(dut, DUT_MSG_ERROR,
4306 "Invalid Fixed MCS rate: %d", v);
4307 return;
4308 }
4309 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004310
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004311 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004312
4313 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004314 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004315}
4316
4317
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004318static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4319 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004320{
4321 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304322 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004323
4324 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4325 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4326 else
4327 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4328
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304329 ret = system(buf);
4330#ifdef NL80211_SUPPORT
4331 if (ret) {
4332 int value = (strcasecmp(val, "Enable") == 0) ? 2 : 1;
4333
4334 ret = sta_config_params(dut, intf, STA_SET_TX_MSDU, value);
4335 ret |= sta_config_params(dut, intf, STA_SET_RX_MSDU, value);
4336 }
4337#endif /* NL80211_SUPPORT */
4338 if (ret)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004339 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4340}
4341
4342
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004343static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4344 int ampdu)
4345{
4346 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004347 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004348
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004349 if (ampdu)
4350 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004351 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4352 if (system(buf) != 0) {
4353 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4354 return -1;
4355 }
4356
4357 return 0;
4358}
4359
4360
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004361static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4362 const char *val)
4363{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004364 run_iwpriv(dut, intf, "tx_stbc %s", val);
4365 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004366}
4367
4368
4369static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4370 const char *val)
4371{
4372 char buf[60];
4373
Peng Xucc317ed2017-05-18 16:44:37 -07004374 if (strcmp(val, "160") == 0) {
4375 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4376 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004377 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4378 } else if (strcmp(val, "40") == 0) {
4379 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4380 } else if (strcmp(val, "20") == 0) {
4381 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4382 } else if (strcasecmp(val, "Auto") == 0) {
4383 buf[0] = '\0';
4384 } else {
4385 sigma_dut_print(dut, DUT_MSG_ERROR,
4386 "WIDTH/CTS_WIDTH value not supported");
4387 return -1;
4388 }
4389
4390 if (buf[0] != '\0' && system(buf) != 0) {
4391 sigma_dut_print(dut, DUT_MSG_ERROR,
4392 "Failed to set WIDTH/CTS_WIDTH");
4393 return -1;
4394 }
4395
4396 return 0;
4397}
4398
4399
4400int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4401 const char *intf, const char *val)
4402{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004403 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004404 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004405 dut->chwidth = 0;
4406 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004407 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004408 dut->chwidth = 0;
4409 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004410 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004411 dut->chwidth = 1;
4412 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004413 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004414 dut->chwidth = 2;
4415 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004416 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004417 dut->chwidth = 3;
4418 } else {
4419 send_resp(dut, conn, SIGMA_ERROR,
4420 "ErrorCode,WIDTH not supported");
4421 return -1;
4422 }
4423
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004424 return 0;
4425}
4426
4427
4428static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4429 const char *val)
4430{
4431 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004432 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004433
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004434 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004435 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004436 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004437 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004438 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004439 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004440 } else {
4441 sigma_dut_print(dut, DUT_MSG_ERROR,
4442 "SP_STREAM value not supported");
4443 return -1;
4444 }
4445
4446 if (system(buf) != 0) {
4447 sigma_dut_print(dut, DUT_MSG_ERROR,
4448 "Failed to set SP_STREAM");
4449 return -1;
4450 }
4451
Arif Hussainac6c5112018-05-25 17:34:00 -07004452 dut->sta_nss = sta_nss;
4453
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004454 return 0;
4455}
4456
4457
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304458static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4459 const char *val)
4460{
4461 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304462 int ret;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304463
4464 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304465 ret = system(buf);
4466#ifdef NL80211_SUPPORT
4467 if (ret)
4468 ret = sta_config_params(dut, intf, STA_SET_TX_STBC,
4469 strcmp(val, "0") == 0 ? 0 : 1);
4470#endif /* NL80211_SUPPORT */
4471 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304472 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4473
4474 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304475 ret = system(buf);
4476#ifdef NL80211_SUPPORT
4477 if (ret)
4478 ret = sta_config_params(dut, intf, STA_SET_RX_STBC,
4479 strcmp(val, "0") == 0 ? 0 : 1);
4480#endif /* NL80211_SUPPORT */
4481 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304482 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4483}
4484
4485
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304486static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4487 struct sigma_conn *conn,
4488 const char *intf, int capa)
4489{
4490 char buf[32];
4491
4492 if (capa > 0 && capa < 4) {
4493 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4494 if (wpa_command(intf, buf) < 0) {
4495 send_resp(dut, conn, SIGMA_ERROR,
4496 "ErrorCode, Failed to set cellular data capability");
4497 return 0;
4498 }
4499 return 1;
4500 }
4501
4502 sigma_dut_print(dut, DUT_MSG_ERROR,
4503 "Invalid Cellular data capability: %d", capa);
4504 send_resp(dut, conn, SIGMA_INVALID,
4505 "ErrorCode,Invalid cellular data capability");
4506 return 0;
4507}
4508
4509
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304510static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4511 const char *intf, const char *val)
4512{
4513 if (strcasecmp(val, "Disable") == 0) {
4514 if (wpa_command(intf, "SET roaming 0") < 0) {
4515 send_resp(dut, conn, SIGMA_ERROR,
4516 "ErrorCode,Failed to disable roaming");
4517 return 0;
4518 }
4519 return 1;
4520 }
4521
4522 if (strcasecmp(val, "Enable") == 0) {
4523 if (wpa_command(intf, "SET roaming 1") < 0) {
4524 send_resp(dut, conn, SIGMA_ERROR,
4525 "ErrorCode,Failed to enable roaming");
4526 return 0;
4527 }
4528 return 1;
4529 }
4530
4531 sigma_dut_print(dut, DUT_MSG_ERROR,
4532 "Invalid value provided for roaming: %s", val);
4533 send_resp(dut, conn, SIGMA_INVALID,
4534 "ErrorCode,Unknown value provided for Roaming");
4535 return 0;
4536}
4537
4538
Ashwini Patila75de5a2017-04-13 16:35:05 +05304539static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4540 struct sigma_conn *conn,
4541 const char *intf, const char *val)
4542{
4543 if (strcasecmp(val, "Disable") == 0) {
4544 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4545 send_resp(dut, conn, SIGMA_ERROR,
4546 "ErrorCode,Failed to disable Assoc_disallow");
4547 return 0;
4548 }
4549 return 1;
4550 }
4551
4552 if (strcasecmp(val, "Enable") == 0) {
4553 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4554 send_resp(dut, conn, SIGMA_ERROR,
4555 "ErrorCode,Failed to enable Assoc_disallow");
4556 return 0;
4557 }
4558 return 1;
4559 }
4560
4561 sigma_dut_print(dut, DUT_MSG_ERROR,
4562 "Invalid value provided for Assoc_disallow: %s", val);
4563 send_resp(dut, conn, SIGMA_INVALID,
4564 "ErrorCode,Unknown value provided for Assoc_disallow");
4565 return 0;
4566}
4567
4568
Ashwini Patilc63161e2017-04-13 16:30:23 +05304569static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4570 const char *intf, const char *val)
4571{
4572 if (strcasecmp(val, "Reject") == 0) {
4573 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4574 send_resp(dut, conn, SIGMA_ERROR,
4575 "ErrorCode,Failed to Reject BTM Request");
4576 return 0;
4577 }
4578 return 1;
4579 }
4580
4581 if (strcasecmp(val, "Accept") == 0) {
4582 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4583 send_resp(dut, conn, SIGMA_ERROR,
4584 "ErrorCode,Failed to Accept BTM Request");
4585 return 0;
4586 }
4587 return 1;
4588 }
4589
4590 sigma_dut_print(dut, DUT_MSG_ERROR,
4591 "Invalid value provided for BSS_Transition: %s", val);
4592 send_resp(dut, conn, SIGMA_INVALID,
4593 "ErrorCode,Unknown value provided for BSS_Transition");
4594 return 0;
4595}
4596
4597
Ashwini Patil00402582017-04-13 12:29:39 +05304598static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4599 struct sigma_conn *conn,
4600 const char *intf,
4601 struct sigma_cmd *cmd)
4602{
4603 const char *ch, *pref, *op_class, *reason;
4604 char buf[120];
4605 int len, ret;
4606
4607 pref = get_param(cmd, "Ch_Pref");
4608 if (!pref)
4609 return 1;
4610
4611 if (strcasecmp(pref, "clear") == 0) {
4612 free(dut->non_pref_ch_list);
4613 dut->non_pref_ch_list = NULL;
4614 } else {
4615 op_class = get_param(cmd, "Ch_Op_Class");
4616 if (!op_class) {
4617 send_resp(dut, conn, SIGMA_INVALID,
4618 "ErrorCode,Ch_Op_Class not provided");
4619 return 0;
4620 }
4621
4622 ch = get_param(cmd, "Ch_Pref_Num");
4623 if (!ch) {
4624 send_resp(dut, conn, SIGMA_INVALID,
4625 "ErrorCode,Ch_Pref_Num not provided");
4626 return 0;
4627 }
4628
4629 reason = get_param(cmd, "Ch_Reason_Code");
4630 if (!reason) {
4631 send_resp(dut, conn, SIGMA_INVALID,
4632 "ErrorCode,Ch_Reason_Code not provided");
4633 return 0;
4634 }
4635
4636 if (!dut->non_pref_ch_list) {
4637 dut->non_pref_ch_list =
4638 calloc(1, NON_PREF_CH_LIST_SIZE);
4639 if (!dut->non_pref_ch_list) {
4640 send_resp(dut, conn, SIGMA_ERROR,
4641 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4642 return 0;
4643 }
4644 }
4645 len = strlen(dut->non_pref_ch_list);
4646 ret = snprintf(dut->non_pref_ch_list + len,
4647 NON_PREF_CH_LIST_SIZE - len,
4648 " %s:%s:%s:%s", op_class, ch, pref, reason);
4649 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4650 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4651 dut->non_pref_ch_list);
4652 } else {
4653 sigma_dut_print(dut, DUT_MSG_ERROR,
4654 "snprintf failed for non_pref_list, ret = %d",
4655 ret);
4656 send_resp(dut, conn, SIGMA_ERROR,
4657 "ErrorCode,snprintf failed");
4658 free(dut->non_pref_ch_list);
4659 dut->non_pref_ch_list = NULL;
4660 return 0;
4661 }
4662 }
4663
4664 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4665 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4666 if (ret < 0 || ret >= (int) sizeof(buf)) {
4667 sigma_dut_print(dut, DUT_MSG_DEBUG,
4668 "snprintf failed for set non_pref_chan, ret: %d",
4669 ret);
4670 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4671 return 0;
4672 }
4673
4674 if (wpa_command(intf, buf) < 0) {
4675 send_resp(dut, conn, SIGMA_ERROR,
4676 "ErrorCode,Failed to set non-preferred channel list");
4677 return 0;
4678 }
4679
4680 return 1;
4681}
4682
4683
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004684#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004685
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004686static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4687 uint8_t cfg)
4688{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304689 return wcn_wifi_test_config_set_u8(
4690 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4691 cfg);
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004692}
4693
4694
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004695static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4696 enum he_fragmentation_val frag)
4697{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304698 return wcn_wifi_test_config_set_u8(
4699 dut, intf,
4700 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION, frag);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004701}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004702
4703
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08004704int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
4705 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004706{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304707 return wcn_wifi_test_config_set_u8(
4708 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF, ltf);
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004709}
4710
4711
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004712static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4713 int noack, enum qca_wlan_ac_type ac)
4714{
4715 struct nl_msg *msg;
4716 int ret = 0;
4717 struct nlattr *params;
4718 int ifindex;
4719
4720 ifindex = if_nametoindex(intf);
4721 if (ifindex == 0) {
4722 sigma_dut_print(dut, DUT_MSG_ERROR,
4723 "%s: Index for interface %s failed",
4724 __func__, intf);
4725 return -1;
4726 }
4727
4728 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4729 NL80211_CMD_VENDOR)) ||
4730 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4731 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4732 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4733 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4734 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4735 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4736 noack) ||
4737 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4738 ac)) {
4739 sigma_dut_print(dut, DUT_MSG_ERROR,
4740 "%s: err in adding vendor_cmd and vendor_data",
4741 __func__);
4742 nlmsg_free(msg);
4743 return -1;
4744 }
4745 nla_nest_end(msg, params);
4746
4747 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4748 if (ret) {
4749 sigma_dut_print(dut, DUT_MSG_ERROR,
4750 "%s: err in send_and_recv_msgs, ret=%d",
4751 __func__, ret);
4752 }
4753 return ret;
4754}
4755
4756
4757static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4758 const char *val)
4759{
4760 int noack, ret;
4761 char token[100];
4762 char *result;
4763 char *saveptr;
4764 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4765
4766 strlcpy(token, val, sizeof(token));
4767 token[sizeof(token) - 1] = '\0';
4768 result = strtok_r(token, ":", &saveptr);
4769 while (result) {
4770 noack = strcasecmp(result, "Disable") != 0;
4771 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4772 if (ret) {
4773 sigma_dut_print(dut, DUT_MSG_ERROR,
4774 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4775 ac, ret);
4776 }
4777 result = strtok_r(NULL, ":", &saveptr);
4778 ac++;
4779 }
4780}
4781
Vinita S. Maloo7462e812020-05-22 15:16:04 +05304782
4783static int nlvendor_sta_set_phymode(struct sigma_dut *dut, const char *intf,
4784 enum qca_wlan_vendor_phy_mode val)
4785{
4786 struct nl_msg *msg;
4787 struct nlattr *params;
4788 int ifindex, ret;
4789
4790 ifindex = if_nametoindex(intf);
4791 if (ifindex == 0) {
4792 sigma_dut_print(dut, DUT_MSG_ERROR,
4793 "%s: Index for interface %s not found",
4794 __func__, intf);
4795 return -1;
4796 }
4797
4798 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4799 NL80211_CMD_VENDOR);
4800 if (!msg) {
4801 sigma_dut_print(dut, DUT_MSG_ERROR,
4802 "%s: err in adding vendor_cmd", __func__);
4803 return -1;
4804 }
4805
4806 if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4807 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4808 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) {
4809 sigma_dut_print(dut, DUT_MSG_ERROR,
4810 "%s: err in adding vendor_attr", __func__);
4811 nlmsg_free(msg);
4812 return -1;
4813 }
4814
4815 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
4816 if (!params || nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_PHY_MODE,
4817 val)) {
4818 sigma_dut_print(dut, DUT_MSG_ERROR,
4819 "%s: err in adding vendor_data", __func__);
4820 nlmsg_free(msg);
4821 return -1;
4822 }
4823
4824 nla_nest_end(msg, params);
4825 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4826 if (ret) {
4827 sigma_dut_print(dut, DUT_MSG_ERROR,
4828 "%s: err in send_and_recv_msgs, ret=%d (%s)",
4829 __func__, ret, strerror(-ret));
4830 return ret;
4831 }
4832
4833 return 0;
4834}
4835
4836
4837static enum qca_wlan_vendor_phy_mode get_qca_vendor_phymode(const char *val)
4838{
4839 if (strcmp(val, "11a") == 0) {
4840 /* IEEE80211_MODE_11A */
4841 return QCA_WLAN_VENDOR_PHY_MODE_11A;
4842 }
4843
4844 if (strcmp(val, "11g") == 0) {
4845 /* IEEE80211_MODE_11G */
4846 return QCA_WLAN_VENDOR_PHY_MODE_11G;
4847 }
4848
4849 if (strcmp(val, "11b") == 0) {
4850 /* IEEE80211_MODE_11B */
4851 return QCA_WLAN_VENDOR_PHY_MODE_11B;
4852 }
4853
4854 if (strcmp(val, "11n") == 0 ||
4855 strcmp(val, "11nl") == 0 ||
4856 strcmp(val, "11nl(nabg)") == 0) {
4857 /* IEEE80211_MODE_11AGN */
4858 return QCA_WLAN_VENDOR_PHY_MODE_11AGN;
4859 }
4860
4861 if (strcmp(val, "11ng") == 0) {
4862 /* IEEE80211_MODE_11NG_HT40 */
4863 return QCA_WLAN_VENDOR_PHY_MODE_11NG_HT40;
4864 }
4865
4866 if (strcmp(val, "AC") == 0 ||
4867 strcasecmp(val, "11AC") == 0) {
4868 /* IEEE80211_MODE_11AC_VHT80 */
4869 return QCA_WLAN_VENDOR_PHY_MODE_11AC_VHT80;
4870 }
4871
4872 if (strcmp(val, "11na") == 0 ||
4873 strcasecmp(val, "11an") == 0) {
4874 /* IEEE80211_MODE_11NA_HT40 */
4875 return QCA_WLAN_VENDOR_PHY_MODE_11NA_HT40;
4876 }
4877
4878 if (strcmp(val, "11ax") == 0 ||
4879 strcmp(val, "auto") == 0) {
4880 /* IEEE80211_MODE_AUTO */
4881 return QCA_WLAN_VENDOR_PHY_MODE_AUTO;
4882 }
4883
4884 return -1;
4885}
4886
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004887#endif /* NL80211_SUPPORT */
4888
4889
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05304890static int get_phymode(const char *val)
4891{
4892 if (strcmp(val, "11a") == 0)
4893 return 1; /* IEEE80211_MODE_11A */
4894 if (strcmp(val, "11g") == 0)
4895 return 3; /* IEEE80211_MODE_11G */
4896 if (strcmp(val, "11b") == 0)
4897 return 2; /* IEEE80211_MODE_11B */
4898 if (strcmp(val, "11n") == 0 ||
4899 strcmp(val, "11nl") == 0 ||
4900 strcmp(val, "11nl(nabg)") == 0)
4901 return 22; /* IEEE80211_MODE_11AGN */
4902 if (strcmp(val, "11ng") == 0)
4903 return 13; /* IEEE80211_MODE_11NG_HT40 */
4904 if (strcmp(val, "AC") == 0 ||
4905 strcasecmp(val, "11AC") == 0)
4906 return 19; /* IEEE80211_MODE_11AC_VHT80 */
4907 if (strcmp(val, "11na") == 0 ||
4908 strcasecmp(val, "11an") == 0)
4909 return 14; /* IEEE80211_MODE_11NA_HT40 */
4910 if (strcmp(val, "11ax") == 0 ||
4911 strcmp(val, "auto") == 0)
4912 return 0; /* IEEE80211_MODE_AUTO */
4913 return -1;
4914}
4915
4916
4917static void sta_set_phymode(struct sigma_dut *dut, const char *intf,
4918 const char *val)
4919{
4920 char buf[100];
4921 int len, phymode;
Vinita S. Maloo7462e812020-05-22 15:16:04 +05304922#ifdef NL80211_SUPPORT
4923 enum qca_wlan_vendor_phy_mode qca_phymode;
4924
4925 qca_phymode = get_qca_vendor_phymode(val);
4926 if (qca_phymode == -1) {
4927 sigma_dut_print(dut, DUT_MSG_DEBUG,
4928 "Ignoring mode change for mode: %s",
4929 val);
4930 return;
4931 }
4932
4933 if (nlvendor_sta_set_phymode(dut, intf, qca_phymode) == 0)
4934 return;
4935#endif /* NL80211_SUPPORT */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05304936
4937 phymode = get_phymode(val);
4938 if (phymode == -1) {
4939 sigma_dut_print(dut, DUT_MSG_DEBUG,
4940 "Ignoring mode change for mode: %s",
4941 val);
4942 return;
4943 }
4944
4945 len = snprintf(buf, sizeof(buf), "iwpriv %s setphymode %d", intf,
4946 phymode);
4947 if (len < 0 || len >= sizeof(buf)) {
4948 sigma_dut_print(dut, DUT_MSG_ERROR,
4949 "Failed to set phymode");
4950 return;
4951 }
4952
4953 if (system(buf) != 0)
4954 sigma_dut_print(dut, DUT_MSG_ERROR,
4955 "iwpriv setting of phymode failed");
4956}
4957
4958
Jouni Malinenf7222712019-06-13 01:50:21 +03004959static enum sigma_cmd_result
4960cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
4961 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004962{
4963 const char *intf = get_param(cmd, "Interface");
4964 const char *val;
4965
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03004966 val = get_param(cmd, "FT_DS");
4967 if (val) {
4968 if (strcasecmp(val, "Enable") == 0) {
4969 dut->sta_ft_ds = 1;
4970 } else if (strcasecmp(val, "Disable") == 0) {
4971 dut->sta_ft_ds = 0;
4972 } else {
4973 send_resp(dut, conn, SIGMA_ERROR,
4974 "errorCode,Unsupported value for FT_DS");
4975 return STATUS_SENT_ERROR;
4976 }
4977 }
4978
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004979 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03004980 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
4981 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004982 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
4983 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004984
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004985 if (val && strcasecmp(val, "LOC") == 0)
4986 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02004987 if (val && strcasecmp(val, "60GHZ") == 0) {
4988 val = get_param(cmd, "WPS");
4989 if (val && strcasecmp(val, "disable") == 0) {
4990 dut->wps_disable = 1;
4991 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
4992 } else {
4993 /* wps_disable can have other value from the previous
4994 * test, so make sure it has the correct value.
4995 */
4996 dut->wps_disable = 0;
4997 }
4998
4999 val = get_param(cmd, "P2P");
5000 if (val && strcasecmp(val, "disable") == 0)
5001 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
5002 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005003
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02005004 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
5005 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
5006
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005007#ifdef ANDROID_NAN
5008 if (val && strcasecmp(val, "NAN") == 0)
5009 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
5010#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005011#ifdef MIRACAST
5012 if (val && (strcasecmp(val, "WFD") == 0 ||
5013 strcasecmp(val, "DisplayR2") == 0))
5014 return miracast_preset_testparameters(dut, conn, cmd);
5015#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005016
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07005017 if (val &&
5018 (strcasecmp(val, "MBO") == 0 || strcasecmp(val, "HE") == 0)) {
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305019 val = get_param(cmd, "Cellular_Data_Cap");
5020 if (val &&
5021 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
5022 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05305023
5024 val = get_param(cmd, "Ch_Pref");
5025 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
5026 return 0;
5027
Ashwini Patilc63161e2017-04-13 16:30:23 +05305028 val = get_param(cmd, "BSS_Transition");
5029 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
5030 return 0;
5031
Ashwini Patila75de5a2017-04-13 16:35:05 +05305032 val = get_param(cmd, "Assoc_Disallow");
5033 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
5034 return 0;
5035
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305036 val = get_param(cmd, "Roaming");
5037 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
5038 return 0;
5039
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305040 return 1;
5041 }
5042
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305043 if (val && strcasecmp(val, "OCE") == 0)
5044 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
5045
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005046#if 0
5047 val = get_param(cmd, "Supplicant");
5048 if (val && strcasecmp(val, "Default") != 0) {
5049 send_resp(dut, conn, SIGMA_ERROR,
5050 "ErrorCode,Only default(Vendor) supplicant "
5051 "supported");
5052 return 0;
5053 }
5054#endif
5055
5056 val = get_param(cmd, "RTS");
5057 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005058 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005059 case DRIVER_ATHEROS:
5060 ath_sta_set_rts(dut, intf, val);
5061 break;
5062 default:
5063#if 0
5064 send_resp(dut, conn, SIGMA_ERROR,
5065 "ErrorCode,Setting RTS not supported");
5066 return 0;
5067#else
5068 sigma_dut_print(dut, DUT_MSG_DEBUG,
5069 "Setting RTS not supported");
5070 break;
5071#endif
5072 }
5073 }
5074
5075#if 0
5076 val = get_param(cmd, "FRGMNT");
5077 if (val) {
5078 /* TODO */
5079 send_resp(dut, conn, SIGMA_ERROR,
5080 "ErrorCode,Setting FRGMNT not supported");
5081 return 0;
5082 }
5083#endif
5084
5085#if 0
5086 val = get_param(cmd, "Preamble");
5087 if (val) {
5088 /* TODO: Long/Short */
5089 send_resp(dut, conn, SIGMA_ERROR,
5090 "ErrorCode,Setting Preamble not supported");
5091 return 0;
5092 }
5093#endif
5094
5095 val = get_param(cmd, "Mode");
5096 if (val) {
5097 if (strcmp(val, "11b") == 0 ||
5098 strcmp(val, "11g") == 0 ||
5099 strcmp(val, "11a") == 0 ||
5100 strcmp(val, "11n") == 0 ||
5101 strcmp(val, "11ng") == 0 ||
5102 strcmp(val, "11nl") == 0 ||
5103 strcmp(val, "11nl(nabg)") == 0 ||
5104 strcmp(val, "AC") == 0 ||
5105 strcmp(val, "11AC") == 0 ||
5106 strcmp(val, "11ac") == 0 ||
5107 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08005108 strcmp(val, "11an") == 0 ||
5109 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005110 /* STA supports all modes by default */
5111 } else {
5112 send_resp(dut, conn, SIGMA_ERROR,
5113 "ErrorCode,Setting Mode not supported");
5114 return 0;
5115 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005116
5117 /* Change the mode only in case of testbed for HE program
5118 * and for 11a and 11g modes only. */
5119 if (dut->program == PROGRAM_HE &&
5120 dut->device_type == STA_testbed) {
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305121 sta_set_phymode(dut, intf, val);
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005122 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005123 }
5124
5125 val = get_param(cmd, "wmm");
5126 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005127 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005128 case DRIVER_ATHEROS:
5129 ath_sta_set_wmm(dut, intf, val);
5130 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005131 case DRIVER_WCN:
5132 wcn_sta_set_wmm(dut, intf, val);
5133 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005134 default:
5135 sigma_dut_print(dut, DUT_MSG_DEBUG,
5136 "Setting wmm not supported");
5137 break;
5138 }
5139 }
5140
5141 val = get_param(cmd, "Powersave");
5142 if (val) {
5143 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005144 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305145 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005146 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005147 }
5148
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005149 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005150 "P2P_SET ps 0") < 0)
5151 return -2;
5152 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005153 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5154 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005155 } else if (strcmp(val, "1") == 0 ||
5156 strcasecmp(val, "PSPoll") == 0 ||
5157 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005158 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305159 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005160 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005161 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005162 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005163 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005164 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005165 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005166 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005167 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005168 "P2P_SET ps 99") < 0)
5169 return -2;
5170 } else if (strcmp(val, "2") == 0 ||
5171 strcasecmp(val, "Fast") == 0) {
5172 /* TODO */
5173 send_resp(dut, conn, SIGMA_ERROR,
5174 "ErrorCode,Powersave=Fast not supported");
5175 return 0;
5176 } else if (strcmp(val, "3") == 0 ||
5177 strcasecmp(val, "PSNonPoll") == 0) {
5178 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005179 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5180 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005181
5182 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005183 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005184 "P2P_SET ps 1") < 0)
5185 return -2;
5186 } else
5187 return -1;
5188 }
5189
5190 val = get_param(cmd, "NoAck");
5191 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005192 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005193 case DRIVER_ATHEROS:
5194 ath_sta_set_noack(dut, intf, val);
5195 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005196#ifdef NL80211_SUPPORT
5197 case DRIVER_WCN:
5198 wcn_sta_set_noack(dut, intf, val);
5199 break;
5200#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005201 default:
5202 send_resp(dut, conn, SIGMA_ERROR,
5203 "ErrorCode,Setting NoAck not supported");
5204 return 0;
5205 }
5206 }
5207
5208 val = get_param(cmd, "IgnoreChswitchProhibit");
5209 if (val) {
5210 /* TODO: Enabled/disabled */
5211 if (strcasecmp(val, "Enabled") == 0) {
5212 send_resp(dut, conn, SIGMA_ERROR,
5213 "ErrorCode,Enabling IgnoreChswitchProhibit "
5214 "not supported");
5215 return 0;
5216 }
5217 }
5218
5219 val = get_param(cmd, "TDLS");
5220 if (val) {
5221 if (strcasecmp(val, "Disabled") == 0) {
5222 if (wpa_command(intf, "SET tdls_disabled 1")) {
5223 send_resp(dut, conn, SIGMA_ERROR,
5224 "ErrorCode,Failed to disable TDLS");
5225 return 0;
5226 }
5227 } else if (strcasecmp(val, "Enabled") == 0) {
5228 if (wpa_command(intf, "SET tdls_disabled 0")) {
5229 send_resp(dut, conn, SIGMA_ERROR,
5230 "ErrorCode,Failed to enable TDLS");
5231 return 0;
5232 }
5233 } else {
5234 send_resp(dut, conn, SIGMA_ERROR,
5235 "ErrorCode,Unsupported TDLS value");
5236 return 0;
5237 }
5238 }
5239
5240 val = get_param(cmd, "TDLSmode");
5241 if (val) {
5242 if (strcasecmp(val, "Default") == 0) {
5243 wpa_command(intf, "SET tdls_testing 0");
5244 } else if (strcasecmp(val, "APProhibit") == 0) {
5245 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5246 send_resp(dut, conn, SIGMA_ERROR,
5247 "ErrorCode,Failed to enable ignore "
5248 "APProhibit TDLS mode");
5249 return 0;
5250 }
5251 } else if (strcasecmp(val, "HiLoMac") == 0) {
5252 /* STA should respond with TDLS setup req for a TDLS
5253 * setup req */
5254 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5255 send_resp(dut, conn, SIGMA_ERROR,
5256 "ErrorCode,Failed to enable HiLoMac "
5257 "TDLS mode");
5258 return 0;
5259 }
5260 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5261 /*
5262 * Since all security modes are enabled by default when
5263 * Sigma control is used, there is no need to do
5264 * anything here.
5265 */
5266 } else if (strcasecmp(val, "ExistLink") == 0) {
5267 /*
5268 * Since we allow new TDLS Setup Request even if there
5269 * is an existing link, nothing needs to be done for
5270 * this.
5271 */
5272 } else {
5273 /* TODO:
5274 * ExistLink: STA should send TDLS setup req even if
5275 * direct link already exists
5276 */
5277 send_resp(dut, conn, SIGMA_ERROR,
5278 "ErrorCode,Unsupported TDLSmode value");
5279 return 0;
5280 }
5281 }
5282
5283 val = get_param(cmd, "FakePubKey");
5284 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5285 send_resp(dut, conn, SIGMA_ERROR,
5286 "ErrorCode,Failed to enable FakePubKey");
5287 return 0;
5288 }
5289
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005290#ifdef NL80211_SUPPORT
5291 val = get_param(cmd, "FrgmntSupport");
5292 if (val) {
5293 if (strcasecmp(val, "Enable") == 0) {
5294 if (sta_set_he_fragmentation(dut, intf,
5295 HE_FRAG_LEVEL1)) {
5296 send_resp(dut, conn, SIGMA_ERROR,
5297 "ErrorCode,Failed to enable HE Fragmentation");
5298 return 0;
5299 }
5300 } else if (strcasecmp(val, "Disable") == 0) {
5301 if (sta_set_he_fragmentation(dut, intf,
5302 HE_FRAG_DISABLE)) {
5303 send_resp(dut, conn, SIGMA_ERROR,
5304 "ErrorCode,Failed to disable HE Fragmentation");
5305 return 0;
5306 }
5307 }
5308 }
5309#endif /* NL80211_SUPPORT */
5310
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305311 val = get_param(cmd, "IncludeMSCSDescriptor");
5312 if (val && strcasecmp(val, "1") == 0) {
5313 char buf[128];
5314 int len;
5315
5316 len = snprintf(buf, sizeof(buf),
Veerendranath Jakkam62cde372020-08-19 18:03:06 +05305317 "MSCS add up_bitmap=F0 up_limit=7 stream_timeout=60000 frame_classifier=045F%032x",
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305318 0);
5319
5320 if (len < 0 || len >= sizeof(buf)) {
5321 sigma_dut_print(dut, DUT_MSG_ERROR,
5322 "Failed to build MSCS Descriptor IE");
5323 return ERROR_SEND_STATUS;
5324 }
5325
5326 if (wpa_command(intf, buf) != 0) {
5327 send_resp(dut, conn, SIGMA_ERROR,
5328 "ErrorCode,Failed to include MSCS descriptor");
5329 return STATUS_SENT_ERROR;
5330 }
5331 }
5332
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005333 return 1;
5334}
5335
5336
5337static const char * ath_get_radio_name(const char *radio_name)
5338{
5339 if (radio_name == NULL)
5340 return "wifi0";
5341 if (strcmp(radio_name, "wifi1") == 0)
5342 return "wifi1";
5343 if (strcmp(radio_name, "wifi2") == 0)
5344 return "wifi2";
5345 return "wifi0";
5346}
5347
5348
5349static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5350 const char *val)
5351{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005352 unsigned int vht_mcsmap = 0;
5353 int txchainmask = 0;
5354 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5355
5356 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5357 if (dut->testbed_flag_txsp == 1) {
5358 vht_mcsmap = 0xfffc;
5359 dut->testbed_flag_txsp = 0;
5360 } else {
5361 vht_mcsmap = 0xfffe;
5362 }
5363 txchainmask = 1;
5364 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5365 if (dut->testbed_flag_txsp == 1) {
5366 vht_mcsmap = 0xfff0;
5367 dut->testbed_flag_txsp = 0;
5368 } else {
5369 vht_mcsmap = 0xfffa;
5370 }
5371 txchainmask = 3;
5372 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5373 if (dut->testbed_flag_txsp == 1) {
5374 vht_mcsmap = 0xffc0;
5375 dut->testbed_flag_txsp = 0;
5376 } else {
5377 vht_mcsmap = 0xffea;
5378 }
5379 txchainmask = 7;
5380 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5381 if (dut->testbed_flag_txsp == 1) {
5382 vht_mcsmap = 0xff00;
5383 dut->testbed_flag_txsp = 0;
5384 } else {
5385 vht_mcsmap = 0xffaa;
5386 }
5387 txchainmask = 15;
5388 } else {
5389 if (dut->testbed_flag_txsp == 1) {
5390 vht_mcsmap = 0xffc0;
5391 dut->testbed_flag_txsp = 0;
5392 } else {
5393 vht_mcsmap = 0xffea;
5394 }
5395 }
5396
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005397 if (txchainmask)
5398 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005399
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005400 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005401}
5402
5403
5404static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5405 const char *val)
5406{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005407 unsigned int vht_mcsmap = 0;
5408 int rxchainmask = 0;
5409 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5410
5411 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5412 if (dut->testbed_flag_rxsp == 1) {
5413 vht_mcsmap = 0xfffc;
5414 dut->testbed_flag_rxsp = 0;
5415 } else {
5416 vht_mcsmap = 0xfffe;
5417 }
5418 rxchainmask = 1;
5419 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5420 if (dut->testbed_flag_rxsp == 1) {
5421 vht_mcsmap = 0xfff0;
5422 dut->testbed_flag_rxsp = 0;
5423 } else {
5424 vht_mcsmap = 0xfffa;
5425 }
5426 rxchainmask = 3;
5427 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5428 if (dut->testbed_flag_rxsp == 1) {
5429 vht_mcsmap = 0xffc0;
5430 dut->testbed_flag_rxsp = 0;
5431 } else {
5432 vht_mcsmap = 0xffea;
5433 }
5434 rxchainmask = 7;
5435 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5436 if (dut->testbed_flag_rxsp == 1) {
5437 vht_mcsmap = 0xff00;
5438 dut->testbed_flag_rxsp = 0;
5439 } else {
5440 vht_mcsmap = 0xffaa;
5441 }
5442 rxchainmask = 15;
5443 } else {
5444 if (dut->testbed_flag_rxsp == 1) {
5445 vht_mcsmap = 0xffc0;
5446 dut->testbed_flag_rxsp = 0;
5447 } else {
5448 vht_mcsmap = 0xffea;
5449 }
5450 }
5451
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005452 if (rxchainmask)
5453 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005454
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005455 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005456}
5457
5458
5459void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5460{
5461 if (strcasecmp(val, "enable") == 0) {
5462 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5463 != 0) {
5464 sigma_dut_print(dut, DUT_MSG_ERROR,
5465 "Disable BB_VHTSIGB_CRC_CALC failed");
5466 }
5467
5468 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5469 != 0) {
5470 sigma_dut_print(dut, DUT_MSG_ERROR,
5471 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5472 }
5473 } else {
5474 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5475 != 0) {
5476 sigma_dut_print(dut, DUT_MSG_ERROR,
5477 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5478 }
5479
5480 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5481 != 0) {
5482 sigma_dut_print(dut, DUT_MSG_ERROR,
5483 "Enable BB_VHTSIGB_CRC_CALC failed");
5484 }
5485 }
5486}
5487
5488
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005489static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5490 const char *val)
5491{
5492 char buf[60];
5493
5494 if (strcmp(val, "20") == 0) {
5495 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5496 dut->chwidth = 0;
5497 } else if (strcmp(val, "40") == 0) {
5498 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5499 dut->chwidth = 1;
5500 } else if (strcmp(val, "80") == 0) {
5501 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5502 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305503 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005504 buf[0] = '\0';
5505 } else {
5506 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5507 val);
5508 return -1;
5509 }
5510
5511 if (buf[0] != '\0' && system(buf) != 0) {
5512 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5513 return -1;
5514 }
5515
5516 return 0;
5517}
5518
5519
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005520static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5521 const char *intf, int addbareject)
5522{
5523#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305524 return wcn_wifi_test_config_set_u8(
5525 dut, intf,
5526 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5527 !addbareject);
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005528#else /* NL80211_SUPPORT */
5529 sigma_dut_print(dut, DUT_MSG_ERROR,
5530 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5531 return -1;
5532#endif /* NL80211_SUPPORT */
5533}
5534
5535
5536static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5537 int addbareject)
5538{
5539 int ret;
5540
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005541 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005542 case DRIVER_WCN:
5543 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5544 if (ret) {
5545 sigma_dut_print(dut, DUT_MSG_ERROR,
5546 "nlvendor_sta_set_addba_reject failed, ret:%d",
5547 ret);
5548 return ret;
5549 }
5550 break;
5551 default:
5552 sigma_dut_print(dut, DUT_MSG_ERROR,
5553 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5554 ret = -1;
5555 break;
5556 }
5557
5558 return ret;
5559}
5560
5561
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005562static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5563 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005564{
5565#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305566 return wcn_wifi_test_config_set_u8(
5567 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
5568 enable);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005569#else /* NL80211_SUPPORT */
5570 sigma_dut_print(dut, DUT_MSG_ERROR,
5571 "Disable addba not possible without NL80211_SUPPORT defined");
5572 return -1;
5573#endif /* NL80211_SUPPORT */
5574}
5575
5576
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305577#ifdef NL80211_SUPPORT
5578static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5579{
5580 struct nl_msg *msg;
5581 int ret = 0;
5582 int ifindex;
5583
5584 ifindex = if_nametoindex(intf);
5585 if (ifindex == 0) {
5586 sigma_dut_print(dut, DUT_MSG_ERROR,
5587 "%s: Index for interface %s failed",
5588 __func__, intf);
5589 return -1;
5590 }
5591
5592 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5593 NL80211_CMD_SET_WIPHY)) ||
5594 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5595 sigma_dut_print(dut, DUT_MSG_ERROR,
5596 "%s: err in adding RTS threshold",
5597 __func__);
5598 nlmsg_free(msg);
5599 return -1;
5600 }
5601
5602 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5603 if (ret) {
5604 sigma_dut_print(dut, DUT_MSG_ERROR,
5605 "%s: err in send_and_recv_msgs, ret=%d",
5606 __func__, ret);
5607 }
5608 return ret;
5609}
5610#endif /* NL80211_SUPPORT */
5611
5612
5613static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5614{
5615 char buf[100];
5616
5617#ifdef NL80211_SUPPORT
5618 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5619 return 0;
5620 sigma_dut_print(dut, DUT_MSG_DEBUG,
5621 "Fall back to using iwconfig for setting RTS threshold");
5622#endif /* NL80211_SUPPORT */
5623
5624 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5625 if (system(buf) != 0) {
5626 sigma_dut_print(dut, DUT_MSG_ERROR,
5627 "Failed to set RTS threshold %d", val);
5628 return -1;
5629 }
5630 return 0;
5631}
5632
5633
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005634static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5635 struct sigma_conn *conn,
5636 struct sigma_cmd *cmd)
5637{
5638 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005639 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005640 char buf[128];
5641 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005642
5643 val = get_param(cmd, "40_INTOLERANT");
5644 if (val) {
5645 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5646 /* TODO: iwpriv ht40intol through wpa_supplicant */
5647 send_resp(dut, conn, SIGMA_ERROR,
5648 "ErrorCode,40_INTOLERANT not supported");
5649 return 0;
5650 }
5651 }
5652
5653 val = get_param(cmd, "ADDBA_REJECT");
5654 if (val) {
5655 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5656 /* reject any ADDBA with status "decline" */
5657 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005658 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005659 } else {
5660 /* accept ADDBA */
5661 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005662 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005663 }
5664 }
5665
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005666 if (addbareject >= 0 &&
5667 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5668 send_resp(dut, conn, SIGMA_ERROR,
5669 "ErrorCode,set addba_reject failed");
5670 return 0;
5671 }
5672
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005673 val = get_param(cmd, "AMPDU");
5674 if (val) {
5675 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5676 /* enable AMPDU Aggregation */
5677 if (ampdu == 0) {
5678 send_resp(dut, conn, SIGMA_ERROR,
5679 "ErrorCode,Mismatch in "
5680 "addba_reject/ampdu - "
5681 "not supported");
5682 return 0;
5683 }
5684 ampdu = 1;
5685 } else {
5686 /* disable AMPDU Aggregation */
5687 if (ampdu == 1) {
5688 send_resp(dut, conn, SIGMA_ERROR,
5689 "ErrorCode,Mismatch in "
5690 "addba_reject/ampdu - "
5691 "not supported");
5692 return 0;
5693 }
5694 ampdu = 0;
5695 }
5696 }
5697
5698 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005699 int ret;
5700
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005701 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5702 ampdu ? "Enabling" : "Disabling");
5703 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005704 if (wpa_command(intf, buf) < 0 &&
5705 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005706 send_resp(dut, conn, SIGMA_ERROR,
5707 "ErrorCode,set aggr failed");
5708 return 0;
5709 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005710
5711 if (ampdu == 0) {
5712 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005713 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005714 if (ret) {
5715 sigma_dut_print(dut, DUT_MSG_ERROR,
5716 "Failed to disable addba, ret:%d",
5717 ret);
5718 }
5719 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005720 }
5721
5722 val = get_param(cmd, "AMSDU");
5723 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005724 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005725 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005726 case DRIVER_WCN:
5727 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005728 break;
5729 default:
5730 if (strcmp(val, "1") == 0 ||
5731 strcasecmp(val, "Enable") == 0) {
5732 /* Enable AMSDU Aggregation */
5733 send_resp(dut, conn, SIGMA_ERROR,
5734 "ErrorCode,AMSDU aggregation not supported");
5735 return 0;
5736 }
5737 break;
5738 }
5739 }
5740
5741 val = get_param(cmd, "STBC_RX");
5742 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005743 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005744 case DRIVER_ATHEROS:
5745 ath_sta_set_stbc(dut, intf, val);
5746 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305747 case DRIVER_WCN:
5748 wcn_sta_set_stbc(dut, intf, val);
5749 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005750 default:
5751 send_resp(dut, conn, SIGMA_ERROR,
5752 "ErrorCode,STBC_RX not supported");
5753 return 0;
5754 }
5755 }
5756
5757 val = get_param(cmd, "WIDTH");
5758 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005759 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005760 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005761 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005762 send_resp(dut, conn, SIGMA_ERROR,
5763 "ErrorCode,Failed to set WIDTH");
5764 return 0;
5765 }
5766 break;
5767 case DRIVER_ATHEROS:
5768 if (ath_set_width(dut, conn, intf, val) < 0)
5769 return 0;
5770 break;
5771 default:
5772 sigma_dut_print(dut, DUT_MSG_ERROR,
5773 "Setting WIDTH not supported");
5774 break;
5775 }
5776 }
5777
5778 val = get_param(cmd, "SMPS");
5779 if (val) {
5780 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5781 send_resp(dut, conn, SIGMA_ERROR,
5782 "ErrorCode,SMPS not supported");
5783 return 0;
5784 }
5785
5786 val = get_param(cmd, "TXSP_STREAM");
5787 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005788 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005789 case DRIVER_WCN:
5790 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5791 send_resp(dut, conn, SIGMA_ERROR,
5792 "ErrorCode,Failed to set TXSP_STREAM");
5793 return 0;
5794 }
5795 break;
5796 case DRIVER_ATHEROS:
5797 ath_sta_set_txsp_stream(dut, intf, val);
5798 break;
5799 default:
5800 sigma_dut_print(dut, DUT_MSG_ERROR,
5801 "Setting TXSP_STREAM not supported");
5802 break;
5803 }
5804 }
5805
5806 val = get_param(cmd, "RXSP_STREAM");
5807 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005808 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005809 case DRIVER_WCN:
5810 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5811 send_resp(dut, conn, SIGMA_ERROR,
5812 "ErrorCode,Failed to set RXSP_STREAM");
5813 return 0;
5814 }
5815 break;
5816 case DRIVER_ATHEROS:
5817 ath_sta_set_rxsp_stream(dut, intf, val);
5818 break;
5819 default:
5820 sigma_dut_print(dut, DUT_MSG_ERROR,
5821 "Setting RXSP_STREAM not supported");
5822 break;
5823 }
5824 }
5825
5826 val = get_param(cmd, "DYN_BW_SGNL");
5827 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005828 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005829 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08005830 if (strcasecmp(val, "enable") == 0) {
5831 snprintf(buf, sizeof(buf),
5832 "iwpriv %s cwmenable 1", intf);
5833 if (system(buf) != 0) {
5834 sigma_dut_print(dut, DUT_MSG_ERROR,
5835 "iwpriv cwmenable 1 failed");
5836 return 0;
5837 }
5838 } else if (strcasecmp(val, "disable") == 0) {
5839 snprintf(buf, sizeof(buf),
5840 "iwpriv %s cwmenable 0", intf);
5841 if (system(buf) != 0) {
5842 sigma_dut_print(dut, DUT_MSG_ERROR,
5843 "iwpriv cwmenable 0 failed");
5844 return 0;
5845 }
5846 } else {
5847 sigma_dut_print(dut, DUT_MSG_ERROR,
5848 "Unsupported DYN_BW_SGL");
5849 }
5850
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005851 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5852 if (system(buf) != 0) {
5853 sigma_dut_print(dut, DUT_MSG_ERROR,
5854 "Failed to set cts_cbw in DYN_BW_SGNL");
5855 return 0;
5856 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005857 break;
5858 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005859 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005860 ath_config_dyn_bw_sig(dut, intf, val);
5861 break;
5862 default:
5863 sigma_dut_print(dut, DUT_MSG_ERROR,
5864 "Failed to set DYN_BW_SGNL");
5865 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005866 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005867 }
5868
5869 val = get_param(cmd, "RTS_FORCE");
5870 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005871 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005872 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305873 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005874 sigma_dut_print(dut, DUT_MSG_ERROR,
5875 "Failed to set RTS_FORCE 64");
5876 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03005877 res = snprintf(buf, sizeof(buf),
5878 "wifitool %s beeliner_fw_test 100 1",
5879 intf);
5880 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08005881 sigma_dut_print(dut, DUT_MSG_ERROR,
5882 "wifitool beeliner_fw_test 100 1 failed");
5883 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005884 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305885 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005886 sigma_dut_print(dut, DUT_MSG_ERROR,
5887 "Failed to set RTS_FORCE 2347");
5888 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005889 } else {
5890 send_resp(dut, conn, SIGMA_ERROR,
5891 "ErrorCode,RTS_FORCE value not supported");
5892 return 0;
5893 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005894 }
5895
5896 val = get_param(cmd, "CTS_WIDTH");
5897 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005898 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005899 case DRIVER_WCN:
5900 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
5901 send_resp(dut, conn, SIGMA_ERROR,
5902 "ErrorCode,Failed to set CTS_WIDTH");
5903 return 0;
5904 }
5905 break;
5906 case DRIVER_ATHEROS:
5907 ath_set_cts_width(dut, intf, val);
5908 break;
5909 default:
5910 sigma_dut_print(dut, DUT_MSG_ERROR,
5911 "Setting CTS_WIDTH not supported");
5912 break;
5913 }
5914 }
5915
5916 val = get_param(cmd, "BW_SGNL");
5917 if (val) {
5918 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005919 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005920 } else if (strcasecmp(val, "Disable") == 0) {
5921 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005922 } else {
5923 send_resp(dut, conn, SIGMA_ERROR,
5924 "ErrorCode,BW_SGNL value not supported");
5925 return 0;
5926 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005927 }
5928
5929 val = get_param(cmd, "Band");
5930 if (val) {
5931 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
5932 /* STA supports all bands by default */
5933 } else {
5934 send_resp(dut, conn, SIGMA_ERROR,
5935 "ErrorCode,Unsupported Band");
5936 return 0;
5937 }
5938 }
5939
5940 val = get_param(cmd, "zero_crc");
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_set_zero_crc(dut, val);
5945 break;
5946 default:
5947 break;
5948 }
5949 }
5950
5951 return 1;
5952}
5953
5954
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005955static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
5956{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005957 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005958#ifdef __linux__
5959 case DRIVER_WIL6210:
5960 return wil6210_set_force_mcs(dut, force, mcs);
5961#endif /* __linux__ */
5962 default:
5963 sigma_dut_print(dut, DUT_MSG_ERROR,
5964 "Unsupported sta_set_force_mcs with the current driver");
5965 return -1;
5966 }
5967}
5968
5969
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005970static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
5971{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005972 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005973#ifdef __linux__
5974 case DRIVER_WIL6210:
5975 return wil6210_force_rsn_ie(dut, state);
5976#endif /* __linux__ */
5977 default:
5978 sigma_dut_print(dut, DUT_MSG_ERROR,
5979 "Unsupported sta_60g_force_rsn_ie with the current driver");
5980 return -1;
5981 }
5982}
5983
5984
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005985static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
5986 struct sigma_cmd *cmd)
5987{
5988 const char *val;
5989 char buf[100];
5990
5991 val = get_param(cmd, "MSDUSize");
5992 if (val) {
5993 int mtu;
5994
5995 dut->amsdu_size = atoi(val);
5996 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
5997 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
5998 sigma_dut_print(dut, DUT_MSG_ERROR,
5999 "MSDUSize %d is above max %d or below min %d",
6000 dut->amsdu_size,
6001 IEEE80211_MAX_DATA_LEN_DMG,
6002 IEEE80211_SNAP_LEN_DMG);
6003 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006004 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006005 }
6006
6007 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
6008 sigma_dut_print(dut, DUT_MSG_DEBUG,
6009 "Setting amsdu_size to %d", mtu);
6010 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006011 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006012
6013 if (system(buf) != 0) {
6014 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
6015 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006016 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006017 }
6018 }
6019
6020 val = get_param(cmd, "BAckRcvBuf");
6021 if (val) {
6022 dut->back_rcv_buf = atoi(val);
6023 if (dut->back_rcv_buf == 0) {
6024 sigma_dut_print(dut, DUT_MSG_ERROR,
6025 "Failed to convert %s or value is 0",
6026 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006027 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006028 }
6029
6030 sigma_dut_print(dut, DUT_MSG_DEBUG,
6031 "Setting BAckRcvBuf to %s", val);
6032 }
6033
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006034 val = get_param(cmd, "MCS_FixedRate");
6035 if (val) {
6036 if (sta_set_force_mcs(dut, 1, atoi(val))) {
6037 sigma_dut_print(dut, DUT_MSG_ERROR,
6038 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006039 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006040 }
6041 }
6042
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006043 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006044}
6045
6046
6047static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
6048 struct sigma_cmd *cmd)
6049{
6050 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006051 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006052 const char *val;
6053 char buf[100];
6054
6055 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006056 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006057 if (wpa_command(ifname, "PING") != 0) {
6058 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006059 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006060 }
6061
6062 wpa_command(ifname, "FLUSH");
6063 net_id = add_network_common(dut, conn, ifname, cmd);
6064 if (net_id < 0) {
6065 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
6066 return net_id;
6067 }
6068
6069 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
6070 if (set_network(ifname, net_id, "mode", "2") < 0) {
6071 sigma_dut_print(dut, DUT_MSG_ERROR,
6072 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006073 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006074 }
6075
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006076 if (set_network(ifname, net_id, "pbss", "1") < 0)
6077 return -2;
6078
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006079 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006080 "Supplicant set network with mode 2. network_id %d",
6081 net_id);
6082
6083 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6084 sigma_dut_print(dut, DUT_MSG_INFO,
6085 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006086 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006087 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006088
6089 val = get_param(cmd, "Security");
6090 if (val && strcasecmp(val, "OPEN") == 0) {
6091 dut->ap_key_mgmt = AP_OPEN;
6092 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6093 sigma_dut_print(dut, DUT_MSG_ERROR,
6094 "Failed to set supplicant to %s security",
6095 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006096 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006097 }
6098 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6099 dut->ap_key_mgmt = AP_WPA2_PSK;
6100 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6101 sigma_dut_print(dut, DUT_MSG_ERROR,
6102 "Failed to set supplicant to %s security",
6103 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006104 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006105 }
6106
6107 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6108 sigma_dut_print(dut, DUT_MSG_ERROR,
6109 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006110 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006111 }
6112 } else if (val) {
6113 sigma_dut_print(dut, DUT_MSG_ERROR,
6114 "Requested Security %s is not supported on 60GHz",
6115 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006116 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006117 }
6118
6119 val = get_param(cmd, "Encrypt");
6120 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6121 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6122 sigma_dut_print(dut, DUT_MSG_ERROR,
6123 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006124 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006125 }
6126 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6127 sigma_dut_print(dut, DUT_MSG_ERROR,
6128 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006129 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006130 }
6131 } else if (val) {
6132 sigma_dut_print(dut, DUT_MSG_ERROR,
6133 "Requested Encrypt %s is not supported on 60 GHz",
6134 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006135 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006136 }
6137
6138 val = get_param(cmd, "PSK");
6139 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6140 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6141 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006142 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006143 }
6144
6145 /* Convert 60G channel to freq */
6146 switch (dut->ap_channel) {
6147 case 1:
6148 val = "58320";
6149 break;
6150 case 2:
6151 val = "60480";
6152 break;
6153 case 3:
6154 val = "62640";
6155 break;
6156 default:
6157 sigma_dut_print(dut, DUT_MSG_ERROR,
6158 "Failed to configure channel %d. Not supported",
6159 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006160 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006161 }
6162
6163 if (set_network(ifname, net_id, "frequency", val) < 0) {
6164 sigma_dut_print(dut, DUT_MSG_ERROR,
6165 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006166 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006167 }
6168
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006169 if (dut->eap_fragment) {
6170 sigma_dut_print(dut, DUT_MSG_DEBUG,
6171 "Set EAP fragment size to 128 bytes.");
6172 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6173 return ERROR_SEND_STATUS;
6174 }
6175
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006176 sigma_dut_print(dut, DUT_MSG_DEBUG,
6177 "Supplicant set network with frequency");
6178
6179 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6180 if (wpa_command(ifname, buf) < 0) {
6181 sigma_dut_print(dut, DUT_MSG_INFO,
6182 "Failed to select network id %d on %s",
6183 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006184 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006185 }
6186
6187 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6188
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006189 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006190}
6191
6192
Lior David67543f52017-01-03 19:04:22 +02006193static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6194{
6195 char buf[128], fname[128];
6196 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006197 int res;
Lior David67543f52017-01-03 19:04:22 +02006198
6199 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6200 sigma_dut_print(dut, DUT_MSG_ERROR,
6201 "failed to get wil6210 debugfs dir");
6202 return -1;
6203 }
6204
Jouni Malinen3aa72862019-05-29 23:14:51 +03006205 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6206 if (res < 0 || res >= sizeof(fname))
6207 return -1;
Lior David67543f52017-01-03 19:04:22 +02006208 f = fopen(fname, "w");
6209 if (!f) {
6210 sigma_dut_print(dut, DUT_MSG_ERROR,
6211 "failed to open: %s", fname);
6212 return -1;
6213 }
6214
6215 fprintf(f, "%d\n", abft_len);
6216 fclose(f);
6217
6218 return 0;
6219}
6220
6221
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006222int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6223 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006224{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006225 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006226 case DRIVER_WIL6210:
6227 return wil6210_set_abft_len(dut, abft_len);
6228 default:
6229 sigma_dut_print(dut, DUT_MSG_ERROR,
6230 "set abft_len not supported");
6231 return -1;
6232 }
6233}
6234
6235
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006236static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6237 struct sigma_cmd *cmd)
6238{
6239 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006240 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006241
6242 if (dut->dev_role != DEVROLE_PCP) {
6243 send_resp(dut, conn, SIGMA_INVALID,
6244 "ErrorCode,Invalid DevRole");
6245 return 0;
6246 }
6247
6248 val = get_param(cmd, "SSID");
6249 if (val) {
6250 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6251 send_resp(dut, conn, SIGMA_INVALID,
6252 "ErrorCode,Invalid SSID");
6253 return -1;
6254 }
6255
Peng Xub8fc5cc2017-05-10 17:27:28 -07006256 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006257 }
6258
6259 val = get_param(cmd, "CHANNEL");
6260 if (val) {
6261 const char *pos;
6262
6263 dut->ap_channel = atoi(val);
6264 pos = strchr(val, ';');
6265 if (pos) {
6266 pos++;
6267 dut->ap_channel_1 = atoi(pos);
6268 }
6269 }
6270
6271 switch (dut->ap_channel) {
6272 case 1:
6273 case 2:
6274 case 3:
6275 break;
6276 default:
6277 sigma_dut_print(dut, DUT_MSG_ERROR,
6278 "Channel %d is not supported", dut->ap_channel);
6279 send_resp(dut, conn, SIGMA_ERROR,
6280 "Requested channel is not supported");
6281 return -1;
6282 }
6283
6284 val = get_param(cmd, "BCNINT");
6285 if (val)
6286 dut->ap_bcnint = atoi(val);
6287
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006288 val = get_param(cmd, "AllocType");
6289 if (val) {
6290 send_resp(dut, conn, SIGMA_ERROR,
6291 "ErrorCode,AllocType is not supported yet");
6292 return -1;
6293 }
6294
6295 val = get_param(cmd, "PercentBI");
6296 if (val) {
6297 send_resp(dut, conn, SIGMA_ERROR,
6298 "ErrorCode,PercentBI is not supported yet");
6299 return -1;
6300 }
6301
6302 val = get_param(cmd, "CBAPOnly");
6303 if (val) {
6304 send_resp(dut, conn, SIGMA_ERROR,
6305 "ErrorCode,CBAPOnly is not supported yet");
6306 return -1;
6307 }
6308
6309 val = get_param(cmd, "AMPDU");
6310 if (val) {
6311 if (strcasecmp(val, "Enable") == 0)
6312 dut->ap_ampdu = 1;
6313 else if (strcasecmp(val, "Disable") == 0)
6314 dut->ap_ampdu = 2;
6315 else {
6316 send_resp(dut, conn, SIGMA_ERROR,
6317 "ErrorCode,AMPDU value is not Enable nor Disabled");
6318 return -1;
6319 }
6320 }
6321
6322 val = get_param(cmd, "AMSDU");
6323 if (val) {
6324 if (strcasecmp(val, "Enable") == 0)
6325 dut->ap_amsdu = 1;
6326 else if (strcasecmp(val, "Disable") == 0)
6327 dut->ap_amsdu = 2;
6328 }
6329
6330 val = get_param(cmd, "NumMSDU");
6331 if (val) {
6332 send_resp(dut, conn, SIGMA_ERROR,
6333 "ErrorCode, NumMSDU is not supported yet");
6334 return -1;
6335 }
6336
6337 val = get_param(cmd, "ABFTLRang");
6338 if (val) {
6339 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006340 "ABFTLRang parameter %s", val);
6341 if (strcmp(val, "Gt1") == 0)
6342 abft_len = 2; /* 2 slots in this case */
6343 }
6344
6345 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6346 send_resp(dut, conn, SIGMA_ERROR,
6347 "ErrorCode, Can't set ABFT length");
6348 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006349 }
6350
6351 if (sta_pcp_start(dut, conn, cmd) < 0) {
6352 send_resp(dut, conn, SIGMA_ERROR,
6353 "ErrorCode, Can't start PCP role");
6354 return -1;
6355 }
6356
6357 return sta_set_60g_common(dut, conn, cmd);
6358}
6359
6360
6361static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6362 struct sigma_cmd *cmd)
6363{
6364 const char *val = get_param(cmd, "DiscoveryMode");
6365
6366 if (dut->dev_role != DEVROLE_STA) {
6367 send_resp(dut, conn, SIGMA_INVALID,
6368 "ErrorCode,Invalid DevRole");
6369 return 0;
6370 }
6371
6372 if (val) {
6373 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6374 /* Ignore Discovery mode till Driver expose API. */
6375#if 0
6376 if (strcasecmp(val, "1") == 0) {
6377 send_resp(dut, conn, SIGMA_INVALID,
6378 "ErrorCode,DiscoveryMode 1 not supported");
6379 return 0;
6380 }
6381
6382 if (strcasecmp(val, "0") == 0) {
6383 /* OK */
6384 } else {
6385 send_resp(dut, conn, SIGMA_INVALID,
6386 "ErrorCode,DiscoveryMode not supported");
6387 return 0;
6388 }
6389#endif
6390 }
6391
6392 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006393 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006394 return sta_set_60g_common(dut, conn, cmd);
6395}
6396
6397
Jouni Malinenf7222712019-06-13 01:50:21 +03006398static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6399 struct sigma_conn *conn,
6400 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006401{
6402 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006403 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306404
Jouni Malinened77e672018-01-10 16:45:13 +02006405 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006406 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006407 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306408 wpa_command(intf, "DISCONNECT");
6409 return 1;
6410 }
6411
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006412 disconnect_station(dut);
6413 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6414 * due to cached results. */
6415 wpa_command(intf, "SET ignore_old_scan_res 1");
6416 wpa_command(intf, "BSS_FLUSH");
6417 return 1;
6418}
6419
6420
Jouni Malinenf7222712019-06-13 01:50:21 +03006421static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6422 struct sigma_conn *conn,
6423 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006424{
6425 const char *intf = get_param(cmd, "Interface");
6426 const char *bssid = get_param(cmd, "bssid");
6427 const char *val = get_param(cmd, "CHANNEL");
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006428 const char *freq_val = get_param(cmd, "ChnlFreq");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006429 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306430 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306431 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006432 int res;
6433 int chan = 0;
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006434 int freq = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006435 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306436 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006437 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006438
6439 if (bssid == NULL) {
6440 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6441 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006442 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006443 }
6444
6445 if (val)
6446 chan = atoi(val);
6447
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006448 if (freq_val)
6449 freq = atoi(freq_val);
6450
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006451 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6452 /* The current network may be from sta_associate or
6453 * sta_hs2_associate
6454 */
6455 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6456 0 ||
6457 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006458 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006459 }
6460
6461 ctrl = open_wpa_mon(intf);
6462 if (ctrl == NULL) {
6463 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6464 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006465 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006466 }
6467
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006468 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05306469 sizeof(result)) < 0 ||
6470 strncmp(result, "COMPLETED", 9) != 0) {
6471 sigma_dut_print(dut, DUT_MSG_DEBUG,
6472 "sta_reassoc: Not connected");
6473 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006474 } else if (dut->sta_ft_ds) {
6475 sigma_dut_print(dut, DUT_MSG_DEBUG,
6476 "sta_reassoc: Use FT-over-DS");
6477 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306478 }
6479
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306480 if (dut->rsne_override) {
6481#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006482 if (get_driver_type(dut) == DRIVER_WCN &&
6483 dut->config_rsnie == 0) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05306484 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306485 dut->config_rsnie = 1;
6486 }
6487#endif /* NL80211_SUPPORT */
6488 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6489 dut->rsne_override);
6490 if (wpa_command(intf, buf) < 0) {
6491 send_resp(dut, conn, SIGMA_ERROR,
6492 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6493 return 0;
6494 }
6495 }
6496
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006497 if (ft_ds) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006498 if (chan || freq) {
6499 if (!freq)
6500 freq = channel_to_freq(dut, chan);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006501 if (!freq) {
6502 sigma_dut_print(dut, DUT_MSG_ERROR,
6503 "Invalid channel number provided: %d",
6504 chan);
6505 send_resp(dut, conn, SIGMA_INVALID,
6506 "ErrorCode,Invalid channel number");
6507 goto close_mon_conn;
6508 }
6509 res = snprintf(buf, sizeof(buf),
6510 "SCAN TYPE=ONLY freq=%d", freq);
6511 } else {
6512 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6513 }
6514 if (res < 0 || res >= (int) sizeof(buf)) {
6515 send_resp(dut, conn, SIGMA_ERROR,
6516 "ErrorCode,snprintf failed");
6517 goto close_mon_conn;
6518 }
6519 if (wpa_command(intf, buf) < 0) {
6520 sigma_dut_print(dut, DUT_MSG_INFO,
6521 "Failed to start scan");
6522 send_resp(dut, conn, SIGMA_ERROR,
6523 "ErrorCode,scan failed");
6524 goto close_mon_conn;
6525 }
6526
6527 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6528 buf, sizeof(buf));
6529 if (res < 0) {
6530 sigma_dut_print(dut, DUT_MSG_INFO,
6531 "Scan did not complete");
6532 send_resp(dut, conn, SIGMA_ERROR,
6533 "ErrorCode,scan did not complete");
6534 goto close_mon_conn;
6535 }
6536
6537 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6538 if (res > 0 && res < (int) sizeof(buf))
6539 res = wpa_command(intf, buf);
6540
6541 if (res < 0 || res >= (int) sizeof(buf)) {
6542 send_resp(dut, conn, SIGMA_ERROR,
6543 "errorCode,FT_DS command failed");
6544 status = STATUS_SENT_ERROR;
6545 goto close_mon_conn;
6546 }
6547 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006548 if (chan || freq) {
6549 if (!freq)
6550 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306551 if (!freq) {
6552 sigma_dut_print(dut, DUT_MSG_ERROR,
6553 "Invalid channel number provided: %d",
6554 chan);
6555 send_resp(dut, conn, SIGMA_INVALID,
6556 "ErrorCode,Invalid channel number");
6557 goto close_mon_conn;
6558 }
6559 res = snprintf(buf, sizeof(buf),
6560 "SCAN TYPE=ONLY freq=%d", freq);
6561 } else {
6562 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6563 }
6564 if (res < 0 || res >= (int) sizeof(buf)) {
6565 send_resp(dut, conn, SIGMA_ERROR,
6566 "ErrorCode,snprintf failed");
6567 goto close_mon_conn;
6568 }
6569 if (wpa_command(intf, buf) < 0) {
6570 sigma_dut_print(dut, DUT_MSG_INFO,
6571 "Failed to start scan");
6572 send_resp(dut, conn, SIGMA_ERROR,
6573 "ErrorCode,scan failed");
6574 goto close_mon_conn;
6575 }
6576
6577 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6578 buf, sizeof(buf));
6579 if (res < 0) {
6580 sigma_dut_print(dut, DUT_MSG_INFO,
6581 "Scan did not complete");
6582 send_resp(dut, conn, SIGMA_ERROR,
6583 "ErrorCode,scan did not complete");
6584 goto close_mon_conn;
6585 }
6586
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006587 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6588 < 0) {
6589 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6590 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006591 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306592 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006593 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306594 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006595 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306596 if (res < 0 || res >= (int) sizeof(buf) ||
6597 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006598 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306599 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306600 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006601 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006602 sigma_dut_print(dut, DUT_MSG_INFO,
6603 "sta_reassoc: Run %s successful", buf);
6604 } else if (wpa_command(intf, "REASSOCIATE")) {
6605 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6606 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306607 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006608 }
6609
6610 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6611 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306612 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006613 send_resp(dut, conn, SIGMA_ERROR,
6614 "errorCode,Connection did not complete");
6615 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306616 goto close_mon_conn;
6617 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006618 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006619
Ashwini Patil467efef2017-05-25 12:18:27 +05306620close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006621 wpa_ctrl_detach(ctrl);
6622 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306623 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006624}
6625
6626
6627static void hs2_clear_credentials(const char *intf)
6628{
6629 wpa_command(intf, "REMOVE_CRED all");
6630}
6631
6632
Lior Davidcc88b562017-01-03 18:52:09 +02006633#ifdef __linux__
6634static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6635 unsigned int *aid)
6636{
Lior David0fe101e2017-03-09 16:09:50 +02006637 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006638
Lior David0fe101e2017-03-09 16:09:50 +02006639 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006640}
6641#endif /* __linux__ */
6642
6643
6644static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6645 unsigned int *aid)
6646{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006647 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02006648#ifdef __linux__
6649 case DRIVER_WIL6210:
6650 return wil6210_get_aid(dut, bssid, aid);
6651#endif /* __linux__ */
6652 default:
6653 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6654 return -1;
6655 }
6656}
6657
6658
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006659static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6660 struct sigma_cmd *cmd)
6661{
6662 char buf[MAX_CMD_LEN];
6663 char bss_list[MAX_CMD_LEN];
6664 const char *parameter = get_param(cmd, "Parameter");
6665
6666 if (parameter == NULL)
6667 return -1;
6668
Lior Davidcc88b562017-01-03 18:52:09 +02006669 if (strcasecmp(parameter, "AID") == 0) {
6670 unsigned int aid = 0;
6671 char bssid[20];
6672
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006673 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02006674 bssid, sizeof(bssid)) < 0) {
6675 sigma_dut_print(dut, DUT_MSG_ERROR,
6676 "could not get bssid");
6677 return -2;
6678 }
6679
6680 if (sta_get_aid_60g(dut, bssid, &aid))
6681 return -2;
6682
6683 snprintf(buf, sizeof(buf), "aid,%d", aid);
6684 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6685 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6686 return 0;
6687 }
6688
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006689 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6690 char *bss_line;
6691 char *bss_id = NULL;
6692 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306693 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006694
6695 if (ifname == NULL) {
6696 sigma_dut_print(dut, DUT_MSG_INFO,
6697 "For get DiscoveredDevList need Interface name.");
6698 return -1;
6699 }
6700
6701 /*
6702 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6703 * of BSSIDs in "bssid=<BSSID>\n"
6704 */
6705 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6706 bss_list,
6707 sizeof(bss_list)) < 0) {
6708 sigma_dut_print(dut, DUT_MSG_ERROR,
6709 "Failed to get bss list");
6710 return -1;
6711 }
6712
6713 sigma_dut_print(dut, DUT_MSG_DEBUG,
6714 "bss list for ifname:%s is:%s",
6715 ifname, bss_list);
6716
6717 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306718 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006719 while (bss_line) {
6720 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6721 bss_id) {
6722 int len;
6723
6724 len = snprintf(buf + strlen(buf),
6725 sizeof(buf) - strlen(buf),
6726 ",%s", bss_id);
6727 free(bss_id);
6728 bss_id = NULL;
6729 if (len < 0) {
6730 sigma_dut_print(dut,
6731 DUT_MSG_ERROR,
6732 "Failed to read BSSID");
6733 send_resp(dut, conn, SIGMA_ERROR,
6734 "ErrorCode,Failed to read BSS ID");
6735 return 0;
6736 }
6737
6738 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6739 sigma_dut_print(dut,
6740 DUT_MSG_ERROR,
6741 "Response buf too small for list");
6742 send_resp(dut, conn,
6743 SIGMA_ERROR,
6744 "ErrorCode,Response buf too small for list");
6745 return 0;
6746 }
6747 }
6748
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306749 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006750 }
6751
6752 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6753 buf);
6754 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6755 return 0;
6756 }
6757
6758 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6759 return 0;
6760}
6761
6762
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006763static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6764 struct sigma_cmd *cmd)
6765{
6766 char buf[MAX_CMD_LEN];
6767 const char *parameter = get_param(cmd, "Parameter");
6768
6769 if (!parameter)
6770 return -1;
6771
6772 if (strcasecmp(parameter, "RSSI") == 0) {
6773 char rssi[10];
6774
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006775 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006776 rssi, sizeof(rssi)) < 0) {
6777 sigma_dut_print(dut, DUT_MSG_ERROR,
6778 "Could not get RSSI");
6779 return -2;
6780 }
6781
6782 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6783 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6784 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6785 return 0;
6786 }
6787
6788 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6789 return 0;
6790}
6791
6792
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05306793#ifdef NL80211_SUPPORT
6794
6795struct station_info {
6796 uint64_t filled;
6797 uint32_t beacon_mic_error_count;
6798 uint32_t beacon_replay_count;
6799};
6800
6801
6802static int qca_get_sta_info_handler(struct nl_msg *msg, void *arg)
6803{
6804 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6805 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6806 struct station_info *data = arg;
6807 struct nlattr *info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1];
6808 static struct nla_policy info_policy[
6809 QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1] = {
6810 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT] = {
6811 .type = NLA_U32
6812 },
6813 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT] = {
6814 .type = NLA_U32
6815 },
6816 };
6817
6818 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6819 genlmsg_attrlen(gnlh, 0), NULL);
6820
6821 if (!tb[NL80211_ATTR_VENDOR_DATA])
6822 return NL_SKIP;
6823
6824 if (nla_parse_nested(info, QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX,
6825 tb[NL80211_ATTR_VENDOR_DATA], info_policy)) {
6826 return NL_SKIP;
6827 }
6828
6829 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]) {
6830 data->filled |=
6831 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT);
6832 data->beacon_mic_error_count =
6833 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]);
6834 }
6835
6836 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]) {
6837 data->filled |=
6838 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT);
6839 data->beacon_replay_count =
6840 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]);
6841 }
6842
6843 return NL_SKIP;
6844}
6845
6846
6847static int qca_nl80211_get_sta_info(struct sigma_dut *dut, const char *intf,
6848 struct station_info *sta_data)
6849{
6850 struct nl_msg *msg;
6851 int ifindex, ret;
6852
6853 ifindex = if_nametoindex(intf);
6854 if (ifindex == 0) {
6855 sigma_dut_print(dut, DUT_MSG_ERROR,
6856 "%s: Index for interface %s not found",
6857 __func__, intf);
6858 return -1;
6859 }
6860
6861 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6862 NL80211_CMD_VENDOR)) ||
6863 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6864 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6865 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6866 QCA_NL80211_VENDOR_SUBCMD_GET_STA_INFO)) {
6867 sigma_dut_print(dut, DUT_MSG_ERROR,
6868 "%s: err in adding vendor_cmd", __func__);
6869 nlmsg_free(msg);
6870 return -1;
6871 }
6872
6873 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg,
6874 qca_get_sta_info_handler, sta_data);
6875 if (ret) {
6876 sigma_dut_print(dut, DUT_MSG_ERROR,
6877 "%s: err in send_and_recv_msgs, ret=%d",
6878 __func__, ret);
6879 }
6880 return ret;
6881}
6882#endif /* NL80211_SUPPORT */
6883
6884
6885static int get_bip_mic_error_count(struct sigma_dut *dut,
6886 const char *ifname,
6887 unsigned int *count)
6888{
6889#ifdef NL80211_SUPPORT
6890 struct station_info sta_data;
6891#endif /* NL80211_SUPPORT */
6892
6893 if (get_driver_type(dut) != DRIVER_WCN) {
6894 sigma_dut_print(dut, DUT_MSG_ERROR,
6895 "BIP MIC error count not supported");
6896 return -1;
6897 }
6898
6899#ifdef NL80211_SUPPORT
6900 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
6901 !(sta_data.filled &
6902 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT))) {
6903 sigma_dut_print(dut, DUT_MSG_ERROR,
6904 "BIP MIC error count fetching failed");
6905 return -1;
6906 }
6907
6908 *count = sta_data.beacon_mic_error_count;
6909 return 0;
6910#else /* NL80211_SUPPORT */
6911 sigma_dut_print(dut, DUT_MSG_ERROR,
6912 "BIP MIC error count cannot be fetched without NL80211_SUPPORT defined");
6913 return -1;
6914#endif /* NL80211_SUPPORT */
6915}
6916
6917
6918static int get_cmac_replay_count(struct sigma_dut *dut, const char *ifname,
6919 unsigned int *count)
6920{
6921#ifdef NL80211_SUPPORT
6922 struct station_info sta_data;
6923#endif /* NL80211_SUPPORT */
6924
6925 if (get_driver_type(dut) != DRIVER_WCN) {
6926 sigma_dut_print(dut, DUT_MSG_ERROR,
6927 "CMAC reply count not supported");
6928 return -1;
6929 }
6930
6931#ifdef NL80211_SUPPORT
6932 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
6933 !(sta_data.filled &
6934 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT))) {
6935 sigma_dut_print(dut, DUT_MSG_ERROR,
6936 "CMAC replay count fetching failed");
6937 return -1;
6938 }
6939
6940 *count = sta_data.beacon_replay_count;
6941 return 0;
6942#else /* NL80211_SUPPORT */
6943 sigma_dut_print(dut, DUT_MSG_ERROR,
6944 "CMAC replay count cannot be fetched without NL80211_SUPPORT defined");
6945 return -1;
6946#endif /* NL80211_SUPPORT */
6947}
6948
6949
6950static enum sigma_cmd_result sta_get_parameter_wpa3(struct sigma_dut *dut,
6951 struct sigma_conn *conn,
6952 struct sigma_cmd *cmd)
6953{
6954 char buf[MAX_CMD_LEN];
6955 const char *ifname = get_param(cmd, "interface");
6956 const char *parameter = get_param(cmd, "Parameter");
6957 unsigned int val;
6958
6959 if (!ifname || !parameter)
6960 return INVALID_SEND_STATUS;
6961
6962 if (strcasecmp(parameter, "BIPMICErrors") == 0) {
6963 if (get_bip_mic_error_count(dut, ifname, &val)) {
6964 send_resp(dut, conn, SIGMA_ERROR,
6965 "ErrorCode,Failed to get BIPMICErrors");
6966 return STATUS_SENT_ERROR;
6967 }
6968 snprintf(buf, sizeof(buf), "BIPMICErrors,%d", val);
6969 sigma_dut_print(dut, DUT_MSG_INFO, "BIPMICErrors %s", buf);
6970 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6971 return STATUS_SENT;
6972 }
6973
6974 if (strcasecmp(parameter, "CMACReplays") == 0) {
6975 if (get_cmac_replay_count(dut, ifname, &val)) {
6976 send_resp(dut, conn, SIGMA_ERROR,
6977 "ErrorCode,Failed to get CMACReplays");
6978 return STATUS_SENT_ERROR;
6979 }
6980 snprintf(buf, sizeof(buf), "CMACReplays,%d", val);
6981 sigma_dut_print(dut, DUT_MSG_INFO, "CMACReplays %s", buf);
6982 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6983 return STATUS_SENT;
6984 }
6985
6986 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6987 return STATUS_SENT_ERROR;
6988}
6989
6990
Jouni Malinenca0abd32020-02-09 20:18:10 +02006991static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
6992 struct sigma_conn *conn,
6993 struct sigma_cmd *cmd)
6994{
6995 const char *intf = get_param(cmd, "Interface");
6996 char buf[4096], bssid[20], resp[200], *pos, *tmp;
6997
6998 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
6999 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
7000 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
7001 send_resp(dut, conn, SIGMA_ERROR,
7002 "ErrorCode,PMKSA_GET not supported");
7003 return STATUS_SENT_ERROR;
7004 }
7005
7006 if (strncmp(buf, "FAIL", 4) == 0 ||
7007 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
7008 send_resp(dut, conn, SIGMA_ERROR,
7009 "ErrorCode,Could not find current network");
7010 return STATUS_SENT_ERROR;
7011 }
7012
7013 pos = buf;
7014 while (pos) {
7015 if (strncmp(pos, bssid, 17) == 0) {
7016 pos = strchr(pos, ' ');
7017 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307018 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007019 pos++;
7020 pos = strchr(pos, ' ');
7021 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307022 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007023 pos++;
7024 tmp = strchr(pos, ' ');
7025 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307026 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007027 *tmp = '\0';
7028 break;
7029 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02007030 pos = strchr(pos, '\n');
7031 if (pos)
7032 pos++;
7033 }
7034
7035 if (!pos) {
7036 send_resp(dut, conn, SIGMA_ERROR,
7037 "ErrorCode,PMK not available");
7038 return STATUS_SENT_ERROR;
7039 }
7040
7041 snprintf(resp, sizeof(resp), "PMK,%s", pos);
7042 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7043 return STATUS_SENT;
7044}
7045
7046
Jouni Malinenf7222712019-06-13 01:50:21 +03007047static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
7048 struct sigma_conn *conn,
7049 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007050{
7051 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02007052 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007053
Jouni Malinenca0abd32020-02-09 20:18:10 +02007054 if (!parameter)
7055 return INVALID_SEND_STATUS;
7056
7057 if (strcasecmp(parameter, "PMK") == 0)
7058 return sta_get_pmk(dut, conn, cmd);
7059
7060 if (!program)
7061 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007062
7063 if (strcasecmp(program, "P2PNFC") == 0)
7064 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
7065
7066 if (strcasecmp(program, "60ghz") == 0)
7067 return sta_get_parameter_60g(dut, conn, cmd);
7068
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007069 if (strcasecmp(program, "he") == 0)
7070 return sta_get_parameter_he(dut, conn, cmd);
7071
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007072#ifdef ANDROID_NAN
7073 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07007074 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007075#endif /* ANDROID_NAN */
7076
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007077#ifdef MIRACAST
7078 if (strcasecmp(program, "WFD") == 0 ||
7079 strcasecmp(program, "DisplayR2") == 0)
7080 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
7081#endif /* MIRACAST */
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05307082 if (strcasecmp(program, "WPA3") == 0)
7083 return sta_get_parameter_wpa3(dut, conn, cmd);
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007084
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007085 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7086 return 0;
7087}
7088
7089
7090static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
7091 const char *type)
7092{
7093 char buf[100];
7094
7095 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007096 run_iwpriv(dut, intf, "chwidth 2");
7097 run_iwpriv(dut, intf, "mode 11ACVHT80");
7098 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007099 }
7100
7101 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007102 run_iwpriv(dut, intf, "chwidth 0");
7103 run_iwpriv(dut, intf, "mode 11naht40");
7104 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007105 }
7106
7107 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007108 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007109
7110 /* Reset CTS width */
7111 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
7112 intf);
7113 if (system(buf) != 0) {
7114 sigma_dut_print(dut, DUT_MSG_ERROR,
7115 "wifitool %s beeliner_fw_test 54 0 failed",
7116 intf);
7117 }
7118
7119 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007120 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007121
7122 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
7123 if (system(buf) != 0) {
7124 sigma_dut_print(dut, DUT_MSG_ERROR,
7125 "iwpriv rts failed");
7126 }
7127 }
7128
7129 if (type && strcasecmp(type, "Testbed") == 0) {
7130 dut->testbed_flag_txsp = 1;
7131 dut->testbed_flag_rxsp = 1;
7132 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007133 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007134
7135 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007136 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007137
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007138 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007139
7140 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007141 run_iwpriv(dut, intf, "tx_stbc 0");
7142 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007143
7144 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007145 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007146 }
7147
7148 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007149 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07007150 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007151
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007152 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007153 }
7154}
7155
7156
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007157#ifdef NL80211_SUPPORT
7158static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
7159 enum he_mcs_config mcs)
7160{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307161 return wcn_wifi_test_config_set_u8(
7162 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS, mcs);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007163}
7164#endif /* NL80211_SUPPORT */
7165
7166
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007167static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
7168 const char *intf, int enable)
7169{
7170#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307171 return wcn_wifi_test_config_set_u8(
7172 dut, intf,
7173 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
7174 enable);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007175#else /* NL80211_SUPPORT */
7176 sigma_dut_print(dut, DUT_MSG_ERROR,
7177 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
7178 return -1;
7179#endif /* NL80211_SUPPORT */
7180}
7181
7182
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007183static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
7184 const char *intf, int enable)
7185{
7186#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307187 return wcn_wifi_test_config_set_u8(
7188 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7189 enable);
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007190#else /* NL80211_SUPPORT */
7191 sigma_dut_print(dut, DUT_MSG_ERROR,
7192 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7193 return -1;
7194#endif /* NL80211_SUPPORT */
7195}
7196
7197
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007198#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007199
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007200static int sta_set_he_testbed_def(struct sigma_dut *dut,
7201 const char *intf, int cfg)
7202{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307203 return wcn_wifi_test_config_set_u8(
7204 dut, intf,
7205 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7206 cfg);
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007207}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007208
7209
7210static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7211{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307212 return wcn_wifi_test_config_set_u8(
7213 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7214 cfg);
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007215}
7216
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007217#endif /* NL80211_SUPPORT */
7218
7219
Qiwei Caib6806972020-01-15 13:52:11 +08007220int sta_set_addba_buf_size(struct sigma_dut *dut,
7221 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007222{
7223#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307224 return wcn_wifi_test_config_set_u16(
7225 dut, intf,
7226 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE, bufsize);
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007227#else /* NL80211_SUPPORT */
7228 sigma_dut_print(dut, DUT_MSG_ERROR,
7229 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7230 return -1;
7231#endif /* NL80211_SUPPORT */
7232}
7233
7234
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007235static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
7236 int enable)
7237{
7238#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307239 return wcn_wifi_test_config_set_u8(
7240 dut, intf,
7241 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7242 enable);
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007243#else /* NL80211_SUPPORT */
7244 sigma_dut_print(dut, DUT_MSG_ERROR,
7245 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7246 return -1;
7247#endif /* NL80211_SUPPORT */
7248}
7249
7250
Arif Hussain9765f7d2018-07-03 08:28:26 -07007251static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7252 int val)
7253{
7254#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307255 return wcn_wifi_test_config_set_u8(
7256 dut, intf,
7257 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7258 val);
Arif Hussain9765f7d2018-07-03 08:28:26 -07007259#else /* NL80211_SUPPORT */
7260 sigma_dut_print(dut, DUT_MSG_ERROR,
7261 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7262 return -1;
7263#endif /* NL80211_SUPPORT */
7264}
7265
7266
Arif Hussain68d23f52018-07-11 13:39:08 -07007267#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007268static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7269 enum qca_wlan_he_mac_padding_dur val)
7270{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307271 return wcn_wifi_test_config_set_u8(
7272 dut, intf,
7273 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR, val);
Arif Hussain68d23f52018-07-11 13:39:08 -07007274}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007275#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007276
7277
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007278static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7279 int val)
7280{
7281#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307282 return wcn_wifi_test_config_set_u8(
7283 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7284 val);
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007285#else /* NL80211_SUPPORT */
7286 sigma_dut_print(dut, DUT_MSG_ERROR,
7287 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7288 return -1;
7289#endif /* NL80211_SUPPORT */
7290}
7291
7292
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007293#ifdef NL80211_SUPPORT
7294static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7295{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307296 return wcn_wifi_test_config_set_flag(
7297 dut, intf,
7298 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG);
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007299}
7300#endif /* NL80211_SUPPORT */
7301
7302
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007303static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7304 int val)
7305{
7306#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307307 return wcn_wifi_test_config_set_u8(
7308 dut, intf,
7309 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA, val);
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007310#else /* NL80211_SUPPORT */
7311 sigma_dut_print(dut, DUT_MSG_ERROR,
7312 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7313 return -1;
7314#endif /* NL80211_SUPPORT */
7315}
7316
7317
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007318static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7319 int val)
7320{
7321#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307322 return wcn_wifi_test_config_set_u8(
7323 dut, intf,
7324 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP, val);
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007325#else /* NL80211_SUPPORT */
7326 sigma_dut_print(dut, DUT_MSG_ERROR,
7327 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7328 return -1;
7329#endif /* NL80211_SUPPORT */
7330}
7331
7332
Arif Hussain480d5f42019-03-12 14:40:42 -07007333static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7334 int val)
7335{
7336#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307337 return wcn_wifi_test_config_set_u8(
7338 dut, intf,
7339 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT, val);
Arif Hussain480d5f42019-03-12 14:40:42 -07007340#else /* NL80211_SUPPORT */
7341 sigma_dut_print(dut, DUT_MSG_ERROR,
7342 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7343 return -1;
7344#endif /* NL80211_SUPPORT */
7345}
7346
7347
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007348static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7349 const char *type)
7350{
7351 char buf[60];
7352
7353 if (dut->program == PROGRAM_HE) {
7354 /* resetting phymode to auto in case of HE program */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05307355 sta_set_phymode(dut, intf, "auto");
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007356
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007357 /* reset the rate to Auto rate */
7358 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7359 intf);
7360 if (system(buf) != 0) {
7361 sigma_dut_print(dut, DUT_MSG_ERROR,
7362 "iwpriv %s set_11ax_rate 0xff failed",
7363 intf);
7364 }
7365
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007366 /* reset the LDPC setting */
7367 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7368 if (system(buf) != 0) {
7369 sigma_dut_print(dut, DUT_MSG_ERROR,
7370 "iwpriv %s ldpc 1 failed", intf);
7371 }
7372
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007373 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05307374 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007375
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007376 /* remove all network profiles */
7377 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007378
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007379 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7380 sta_set_addba_buf_size(dut, intf, 64);
7381
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007382#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007383 /* Reset the device HE capabilities to its default supported
7384 * configuration. */
7385 sta_set_he_testbed_def(dut, intf, 0);
7386
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007387 /* Disable noackpolicy for all AC */
7388 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7389 sigma_dut_print(dut, DUT_MSG_ERROR,
7390 "Disable of noackpolicy for all AC failed");
7391 }
7392#endif /* NL80211_SUPPORT */
7393
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007394 /* Enable WMM by default */
7395 if (wcn_sta_set_wmm(dut, intf, "on")) {
7396 sigma_dut_print(dut, DUT_MSG_ERROR,
7397 "Enable of WMM in sta_reset_default_wcn failed");
7398 }
7399
7400 /* Disable ADDBA_REJECT by default */
7401 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7402 sigma_dut_print(dut, DUT_MSG_ERROR,
7403 "Disable of addba_reject in sta_reset_default_wcn failed");
7404 }
7405
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007406 /* Enable sending of ADDBA by default */
7407 if (nlvendor_config_send_addba(dut, intf, 1)) {
7408 sigma_dut_print(dut, DUT_MSG_ERROR,
7409 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7410 }
7411
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007412 /* Enable AMPDU by default */
7413 iwpriv_sta_set_ampdu(dut, intf, 1);
7414
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007415#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08007416 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007417 sigma_dut_print(dut, DUT_MSG_ERROR,
7418 "Set LTF config to default in sta_reset_default_wcn failed");
7419 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007420
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007421 /* set the beamformee NSTS(maximum number of
7422 * space-time streams) to default DUT config
7423 */
7424 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007425 sigma_dut_print(dut, DUT_MSG_ERROR,
7426 "Failed to set BeamformeeSTS");
7427 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007428
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007429 if (sta_set_mac_padding_duration(
7430 dut, intf,
7431 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007432 sigma_dut_print(dut, DUT_MSG_ERROR,
7433 "Failed to set MAC padding duration");
7434 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007435
7436 if (sta_set_mu_edca_override(dut, intf, 0)) {
7437 sigma_dut_print(dut, DUT_MSG_ERROR,
7438 "ErrorCode,Failed to set MU EDCA override disable");
7439 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007440
7441 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7442 sigma_dut_print(dut, DUT_MSG_ERROR,
7443 "Failed to set OM ctrl supp");
7444 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007445
7446 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7447 sigma_dut_print(dut, DUT_MSG_ERROR,
7448 "Failed to set Tx SU PPDU enable");
7449 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007450
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007451 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7452 sigma_dut_print(dut, DUT_MSG_ERROR,
7453 "failed to send TB PPDU Tx cfg");
7454 }
7455
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007456 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7457 sigma_dut_print(dut, DUT_MSG_ERROR,
7458 "Failed to set OM ctrl reset");
7459 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007460
7461 /* +HTC-HE support default on */
7462 if (sta_set_he_htc_supp(dut, intf, 1)) {
7463 sigma_dut_print(dut, DUT_MSG_ERROR,
7464 "Setting of +HTC-HE support failed");
7465 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007466#endif /* NL80211_SUPPORT */
7467
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007468 if (sta_set_tx_beamformee(dut, intf, 1)) {
7469 sigma_dut_print(dut, DUT_MSG_ERROR,
7470 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7471 }
7472
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007473 wpa_command(intf, "SET oce 1");
7474
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007475 /* Set nss to 1 and MCS 0-7 in case of testbed */
7476 if (type && strcasecmp(type, "Testbed") == 0) {
7477#ifdef NL80211_SUPPORT
7478 int ret;
7479#endif /* NL80211_SUPPORT */
7480
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007481 wpa_command(intf, "SET oce 0");
7482
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007483 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7484 if (system(buf) != 0) {
7485 sigma_dut_print(dut, DUT_MSG_ERROR,
7486 "iwpriv %s nss failed", intf);
7487 }
7488
7489#ifdef NL80211_SUPPORT
7490 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7491 if (ret) {
7492 sigma_dut_print(dut, DUT_MSG_ERROR,
7493 "Setting of MCS failed, ret:%d",
7494 ret);
7495 }
7496#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007497
7498 /* Disable STBC as default */
7499 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007500
7501 /* Disable AMSDU as default */
7502 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007503
7504#ifdef NL80211_SUPPORT
7505 /* HE fragmentation default off */
7506 if (sta_set_he_fragmentation(dut, intf,
7507 HE_FRAG_DISABLE)) {
7508 sigma_dut_print(dut, DUT_MSG_ERROR,
7509 "Setting of HE fragmentation failed");
7510 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007511
7512 /* set the beamformee NSTS(maximum number of
7513 * space-time streams) to default testbed config
7514 */
7515 if (sta_set_beamformee_sts(dut, intf, 3)) {
7516 sigma_dut_print(dut, DUT_MSG_ERROR,
7517 "Failed to set BeamformeeSTS");
7518 }
7519
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007520 /* +HTC-HE support default off */
7521 if (sta_set_he_htc_supp(dut, intf, 0)) {
7522 sigma_dut_print(dut, DUT_MSG_ERROR,
7523 "Setting of +HTC-HE support failed");
7524 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007525
7526 /* Set device HE capabilities to testbed default
7527 * configuration. */
7528 if (sta_set_he_testbed_def(dut, intf, 1)) {
7529 sigma_dut_print(dut, DUT_MSG_DEBUG,
7530 "Failed to set HE defaults");
7531 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007532
7533 /* Disable VHT support in 2.4 GHz for testbed */
7534 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007535#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007536
7537 /* Enable WEP/TKIP with HE capability in testbed */
7538 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
7539 sigma_dut_print(dut, DUT_MSG_ERROR,
7540 "Enabling HE config with WEP/TKIP failed");
7541 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007542 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007543
7544 /* Defaults in case of DUT */
7545 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07007546 /* Enable STBC by default */
7547 wcn_sta_set_stbc(dut, intf, "1");
7548
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007549 /* set nss to 2 */
7550 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
7551 if (system(buf) != 0) {
7552 sigma_dut_print(dut, DUT_MSG_ERROR,
7553 "iwpriv %s nss 2 failed", intf);
7554 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007555 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007556
7557#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07007558 /* Set HE_MCS to 0-11 */
7559 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007560 sigma_dut_print(dut, DUT_MSG_ERROR,
7561 "Setting of MCS failed");
7562 }
7563#endif /* NL80211_SUPPORT */
7564
7565 /* Disable WEP/TKIP with HE capability in DUT */
7566 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
7567 sigma_dut_print(dut, DUT_MSG_ERROR,
7568 "Enabling HE config with WEP/TKIP failed");
7569 }
7570 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007571 }
7572}
7573
7574
Jouni Malinenf7222712019-06-13 01:50:21 +03007575static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
7576 struct sigma_conn *conn,
7577 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007578{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007579 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007580 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007581 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007582 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307583 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007584
Jouni Malinenb21f0542019-11-04 17:53:38 +02007585 if (dut->station_ifname_2g &&
7586 strcmp(dut->station_ifname_2g, intf) == 0)
7587 dut->use_5g = 0;
7588 else if (dut->station_ifname_5g &&
7589 strcmp(dut->station_ifname_5g, intf) == 0)
7590 dut->use_5g = 1;
7591
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007592 if (!program)
7593 program = get_param(cmd, "prog");
7594 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007595 dut->device_type = STA_unknown;
7596 type = get_param(cmd, "type");
7597 if (type && strcasecmp(type, "Testbed") == 0)
7598 dut->device_type = STA_testbed;
7599 if (type && strcasecmp(type, "DUT") == 0)
7600 dut->device_type = STA_dut;
7601
7602 if (dut->program == PROGRAM_TDLS) {
7603 /* Clear TDLS testing mode */
7604 wpa_command(intf, "SET tdls_disabled 0");
7605 wpa_command(intf, "SET tdls_testing 0");
7606 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007607 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05307608 /* Enable the WCN driver in TDLS Explicit trigger mode
7609 */
7610 wpa_command(intf, "SET tdls_external_control 0");
7611 wpa_command(intf, "SET tdls_trigger_control 0");
7612 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007613 }
7614
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007615#ifdef MIRACAST
7616 if (dut->program == PROGRAM_WFD ||
7617 dut->program == PROGRAM_DISPLAYR2)
7618 miracast_sta_reset_default(dut, conn, cmd);
7619#endif /* MIRACAST */
7620
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007621 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007622 case DRIVER_ATHEROS:
7623 sta_reset_default_ath(dut, intf, type);
7624 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007625 case DRIVER_WCN:
7626 sta_reset_default_wcn(dut, intf, type);
7627 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007628 default:
7629 break;
7630 }
7631
7632#ifdef ANDROID_NAN
7633 if (dut->program == PROGRAM_NAN)
7634 nan_cmd_sta_reset_default(dut, conn, cmd);
7635#endif /* ANDROID_NAN */
7636
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05307637 if (dut->program == PROGRAM_LOC &&
7638 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
7639 return ERROR_SEND_STATUS;
7640
Jouni Malinenba630452018-06-22 11:49:59 +03007641 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007642 unlink("SP/wi-fi.org/pps.xml");
7643 if (system("rm -r SP/*") != 0) {
7644 }
7645 unlink("next-client-cert.pem");
7646 unlink("next-client-key.pem");
7647 }
7648
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007649 /* For WPS program of the 60 GHz band the band type needs to be saved */
7650 if (dut->program == PROGRAM_WPS) {
7651 if (band && strcasecmp(band, "60GHz") == 0) {
7652 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007653 /* For 60 GHz enable WPS for WPS TCs */
7654 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007655 } else {
7656 dut->band = WPS_BAND_NON_60G;
7657 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007658 } else if (dut->program == PROGRAM_60GHZ) {
7659 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
7660 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007661 }
7662
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02007663 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007664 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007665 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007666
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007667 sigma_dut_print(dut, DUT_MSG_INFO,
7668 "WPS 60 GHz program, wps_disable = %d",
7669 dut->wps_disable);
7670
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007671 if (!dev_role) {
7672 send_resp(dut, conn, SIGMA_ERROR,
7673 "errorCode,Missing DevRole argument");
7674 return 0;
7675 }
7676
7677 if (strcasecmp(dev_role, "STA") == 0)
7678 dut->dev_role = DEVROLE_STA;
7679 else if (strcasecmp(dev_role, "PCP") == 0)
7680 dut->dev_role = DEVROLE_PCP;
7681 else {
7682 send_resp(dut, conn, SIGMA_ERROR,
7683 "errorCode,Unknown DevRole");
7684 return 0;
7685 }
7686
7687 if (dut->device_type == STA_unknown) {
7688 sigma_dut_print(dut, DUT_MSG_ERROR,
7689 "Device type is not STA testbed or DUT");
7690 send_resp(dut, conn, SIGMA_ERROR,
7691 "errorCode,Unknown device type");
7692 return 0;
7693 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007694
7695 sigma_dut_print(dut, DUT_MSG_DEBUG,
7696 "Setting msdu_size to MAX: 7912");
7697 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007698 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007699
7700 if (system(buf) != 0) {
7701 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
7702 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007703 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007704 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007705
7706 if (sta_set_force_mcs(dut, 0, 1)) {
7707 sigma_dut_print(dut, DUT_MSG_ERROR,
7708 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007709 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007710 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007711 }
7712
7713 wpa_command(intf, "WPS_ER_STOP");
7714 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05307715 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007716 wpa_command(intf, "SET radio_disabled 0");
7717
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007718 dut->wps_forced_version = 0;
7719
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007720 if (dut->wsc_fragment) {
7721 dut->wsc_fragment = 0;
7722 wpa_command(intf, "SET device_name Test client");
7723 wpa_command(intf, "SET manufacturer ");
7724 wpa_command(intf, "SET model_name ");
7725 wpa_command(intf, "SET model_number ");
7726 wpa_command(intf, "SET serial_number ");
7727 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02007728 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
7729 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
7730 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
7731 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007732
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007733 if (dut->tmp_mac_addr && dut->set_macaddr) {
7734 dut->tmp_mac_addr = 0;
7735 if (system(dut->set_macaddr) != 0) {
7736 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
7737 "temporary MAC address");
7738 }
7739 }
7740
7741 set_ps(intf, dut, 0);
7742
Jouni Malinenba630452018-06-22 11:49:59 +03007743 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
7744 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007745 wpa_command(intf, "SET interworking 1");
7746 wpa_command(intf, "SET hs20 1");
7747 }
7748
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007749 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007750 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007751 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007752 wpa_command(intf, "SET pmf 1");
7753 } else {
7754 wpa_command(intf, "SET pmf 0");
7755 }
7756
7757 hs2_clear_credentials(intf);
7758 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
7759 wpa_command(intf, "SET access_network_type 15");
7760
7761 static_ip_file(0, NULL, NULL, NULL);
7762 kill_dhcp_client(dut, intf);
7763 clear_ip_addr(dut, intf);
7764
7765 dut->er_oper_performed = 0;
7766 dut->er_oper_bssid[0] = '\0';
7767
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007768 if (dut->program == PROGRAM_LOC) {
7769 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007770 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007771 }
7772
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07007773 if (dut->program == PROGRAM_MBO || dut->program == PROGRAM_HE) {
Ashwini Patil00402582017-04-13 12:29:39 +05307774 free(dut->non_pref_ch_list);
7775 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05307776 free(dut->btm_query_cand_list);
7777 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05307778 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05307779 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05307780 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05307781 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05307782 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05307783 }
7784
Jouni Malinen3c367e82017-06-23 17:01:47 +03007785 free(dut->rsne_override);
7786 dut->rsne_override = NULL;
7787
Jouni Malinen68143132017-09-02 02:34:08 +03007788 free(dut->sae_commit_override);
7789 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03007790 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02007791 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03007792
Jouni Malinen134fe3c2019-06-12 04:16:49 +03007793 dut->sta_associate_wait_connect = 0;
7794 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03007795 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03007796 dut->sta_tod_policy = 0;
7797
Jouni Malinend86e5822017-08-29 03:55:32 +03007798 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02007799 free(dut->dpp_peer_uri);
7800 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02007801 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02007802 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03007803 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03007804
Jouni Malinenfac9cad2017-10-10 18:35:55 +03007805 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
7806
vamsi krishnaa2799492017-12-05 14:28:01 +05307807 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307808 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05307809 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05307810 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
7811 dut->fils_hlp = 0;
7812#ifdef ANDROID
7813 hlp_thread_cleanup(dut);
7814#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05307815 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307816
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05307817 if (dut->program == PROGRAM_QM)
7818 wpa_command(intf, "SET interworking 1");
7819
Jouni Malinen8179fee2019-03-28 03:19:47 +02007820 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007821 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02007822
Sunil Dutt076081f2018-02-05 19:45:50 +05307823#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007824 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05307825 dut->config_rsnie == 1) {
7826 dut->config_rsnie = 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05307827 sta_config_params(dut, intf, STA_SET_RSNIE, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05307828 }
7829#endif /* NL80211_SUPPORT */
7830
Sunil Duttfebf8a82018-02-09 18:50:13 +05307831 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
7832 dut->dev_role = DEVROLE_STA_CFON;
7833 return sta_cfon_reset_default(dut, conn, cmd);
7834 }
7835
Jouni Malinen439352d2018-09-13 03:42:23 +03007836 wpa_command(intf, "SET setband AUTO");
7837
Vamsi Krishnac1633d22020-05-06 18:31:21 +05307838 dut->ocvc = 0;
Jouni Malinen67433fc2020-06-26 22:50:33 +03007839 dut->client_privacy = 0;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05307840 dut->saquery_oci_freq = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05307841
Sunil Duttfebf8a82018-02-09 18:50:13 +05307842 if (dut->program != PROGRAM_VHT)
7843 return cmd_sta_p2p_reset(dut, conn, cmd);
7844
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08007845 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007846}
7847
7848
Jouni Malinenf7222712019-06-13 01:50:21 +03007849static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
7850 struct sigma_conn *conn,
7851 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007852{
7853 const char *program = get_param(cmd, "Program");
7854
7855 if (program == NULL)
7856 return -1;
7857#ifdef ANDROID_NAN
7858 if (strcasecmp(program, "NAN") == 0)
7859 return nan_cmd_sta_get_events(dut, conn, cmd);
7860#endif /* ANDROID_NAN */
7861 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7862 return 0;
7863}
7864
7865
Jouni Malinen82905202018-04-29 17:20:10 +03007866static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
7867 struct sigma_cmd *cmd)
7868{
7869 const char *url = get_param(cmd, "url");
7870 const char *method = get_param(cmd, "method");
7871 pid_t pid;
7872 int status;
7873
7874 if (!url || !method)
7875 return -1;
7876
7877 /* TODO: Add support for method,post */
7878 if (strcasecmp(method, "get") != 0) {
7879 send_resp(dut, conn, SIGMA_ERROR,
7880 "ErrorCode,Unsupported method");
7881 return 0;
7882 }
7883
7884 pid = fork();
7885 if (pid < 0) {
7886 perror("fork");
7887 return -1;
7888 }
7889
7890 if (pid == 0) {
7891 char * argv[5] = { "wget", "-O", "/dev/null",
7892 (char *) url, NULL };
7893
7894 execv("/usr/bin/wget", argv);
7895 perror("execv");
7896 exit(0);
7897 return -1;
7898 }
7899
7900 if (waitpid(pid, &status, 0) < 0) {
7901 perror("waitpid");
7902 return -1;
7903 }
7904
7905 if (WIFEXITED(status)) {
7906 const char *errmsg;
7907
7908 if (WEXITSTATUS(status) == 0)
7909 return 1;
7910 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
7911 WEXITSTATUS(status));
7912 switch (WEXITSTATUS(status)) {
7913 case 4:
7914 errmsg = "errmsg,Network failure";
7915 break;
7916 case 8:
7917 errmsg = "errmsg,Server issued an error response";
7918 break;
7919 default:
7920 errmsg = "errmsg,Unknown failure from wget";
7921 break;
7922 }
7923 send_resp(dut, conn, SIGMA_ERROR, errmsg);
7924 return 0;
7925 }
7926
7927 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
7928 return 0;
7929}
7930
7931
Jouni Malinenf7222712019-06-13 01:50:21 +03007932static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
7933 struct sigma_conn *conn,
7934 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007935{
7936 const char *program = get_param(cmd, "Prog");
7937
Jouni Malinen82905202018-04-29 17:20:10 +03007938 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007939 return -1;
7940#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03007941 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007942 return nan_cmd_sta_exec_action(dut, conn, cmd);
7943#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03007944
7945 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07007946 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03007947
7948 if (get_param(cmd, "url"))
7949 return sta_exec_action_url(dut, conn, cmd);
7950
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007951 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7952 return 0;
7953}
7954
7955
Jouni Malinenf7222712019-06-13 01:50:21 +03007956static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
7957 struct sigma_conn *conn,
7958 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007959{
7960 const char *intf = get_param(cmd, "Interface");
7961 const char *val, *mcs32, *rate;
7962
7963 val = get_param(cmd, "GREENFIELD");
7964 if (val) {
7965 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
7966 /* Enable GD */
7967 send_resp(dut, conn, SIGMA_ERROR,
7968 "ErrorCode,GF not supported");
7969 return 0;
7970 }
7971 }
7972
7973 val = get_param(cmd, "SGI20");
7974 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007975 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007976 case DRIVER_ATHEROS:
7977 ath_sta_set_sgi(dut, intf, val);
7978 break;
7979 default:
7980 send_resp(dut, conn, SIGMA_ERROR,
7981 "ErrorCode,SGI20 not supported");
7982 return 0;
7983 }
7984 }
7985
7986 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
7987 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
7988 if (mcs32 && rate) {
7989 /* TODO */
7990 send_resp(dut, conn, SIGMA_ERROR,
7991 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
7992 return 0;
7993 } else if (mcs32 && !rate) {
7994 /* TODO */
7995 send_resp(dut, conn, SIGMA_ERROR,
7996 "ErrorCode,MCS32 not supported");
7997 return 0;
7998 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007999 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008000 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008001 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008002 ath_sta_set_11nrates(dut, intf, rate);
8003 break;
8004 default:
8005 send_resp(dut, conn, SIGMA_ERROR,
8006 "ErrorCode,MCS32_FIXEDRATE not supported");
8007 return 0;
8008 }
8009 }
8010
8011 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8012}
8013
8014
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008015static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8016 int mcs_config)
8017{
8018#ifdef NL80211_SUPPORT
8019 int ret;
8020
8021 switch (mcs_config) {
8022 case HE_80_MCS0_7:
8023 case HE_80_MCS0_9:
8024 case HE_80_MCS0_11:
8025 ret = sta_set_he_mcs(dut, intf, mcs_config);
8026 if (ret) {
8027 sigma_dut_print(dut, DUT_MSG_ERROR,
8028 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8029 mcs_config, ret);
8030 }
8031 break;
8032 default:
8033 sigma_dut_print(dut, DUT_MSG_ERROR,
8034 "cmd_set_max_he_mcs: Invalid mcs %d",
8035 mcs_config);
8036 break;
8037 }
8038#else /* NL80211_SUPPORT */
8039 sigma_dut_print(dut, DUT_MSG_ERROR,
8040 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8041#endif /* NL80211_SUPPORT */
8042}
8043
8044
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008045#define TWT_REQUEST_CMD 0
8046#define TWT_SUGGEST_CMD 1
8047#define TWT_DEMAND_CMD 2
8048
Arif Hussain480d5f42019-03-12 14:40:42 -07008049static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8050 struct sigma_cmd *cmd)
8051{
8052#ifdef NL80211_SUPPORT
8053 struct nlattr *params;
8054 struct nlattr *attr;
8055 struct nlattr *attr1;
8056 struct nl_msg *msg;
8057 int ifindex, ret;
8058 const char *val;
8059 const char *intf = get_param(cmd, "Interface");
8060 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8061 wake_interval_mantissa = 512;
8062 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008063 protection = 0, cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
Arif Hussain480d5f42019-03-12 14:40:42 -07008064
8065 ifindex = if_nametoindex(intf);
8066 if (ifindex == 0) {
8067 sigma_dut_print(dut, DUT_MSG_ERROR,
8068 "%s: Index for interface %s failed",
8069 __func__, intf);
8070 return -1;
8071 }
8072
8073 val = get_param(cmd, "FlowType");
8074 if (val) {
8075 flow_type = atoi(val);
8076 if (flow_type != 0 && flow_type != 1) {
8077 sigma_dut_print(dut, DUT_MSG_ERROR,
8078 "TWT: Invalid FlowType %d", flow_type);
8079 return -1;
8080 }
8081 }
8082
8083 val = get_param(cmd, "TWT_Trigger");
8084 if (val) {
8085 twt_trigger = atoi(val);
8086 if (twt_trigger != 0 && twt_trigger != 1) {
8087 sigma_dut_print(dut, DUT_MSG_ERROR,
8088 "TWT: Invalid TWT_Trigger %d",
8089 twt_trigger);
8090 return -1;
8091 }
8092 }
8093
8094 val = get_param(cmd, "Protection");
8095 if (val) {
8096 protection = atoi(val);
8097 if (protection != 0 && protection != 1) {
8098 sigma_dut_print(dut, DUT_MSG_ERROR,
8099 "TWT: Invalid Protection %d",
8100 protection);
8101 return -1;
8102 }
8103 }
8104
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008105 val = get_param(cmd, "SetupCommand");
8106 if (val) {
8107 cmd_type = atoi(val);
8108 if (cmd_type == TWT_REQUEST_CMD)
8109 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_REQUEST;
8110 else if (cmd_type == TWT_SUGGEST_CMD)
8111 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
8112 else if (cmd_type == TWT_DEMAND_CMD)
8113 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_DEMAND;
8114 else
8115 sigma_dut_print(dut, DUT_MSG_ERROR,
8116 "Default suggest is used for cmd %d",
8117 cmd_type);
8118 }
8119
Arif Hussain480d5f42019-03-12 14:40:42 -07008120 val = get_param(cmd, "TargetWakeTime");
8121 if (val)
8122 target_wake_time = atoi(val);
8123
8124 val = get_param(cmd, "WakeIntervalMantissa");
8125 if (val)
8126 wake_interval_mantissa = atoi(val);
8127
8128 val = get_param(cmd, "WakeIntervalExp");
8129 if (val)
8130 wake_interval_exp = atoi(val);
8131
8132 val = get_param(cmd, "NominalMinWakeDur");
8133 if (val)
8134 nominal_min_wake_dur = atoi(val);
8135
8136 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8137 NL80211_CMD_VENDOR)) ||
8138 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8139 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8140 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8141 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8142 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8143 !(params = nla_nest_start(
8144 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
8145 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8146 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8147 wake_interval_exp) ||
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008148 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, cmd_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008149 (twt_trigger &&
8150 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008151 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8152 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008153 (protection &&
8154 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008155 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8156 target_wake_time) ||
8157 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8158 nominal_min_wake_dur) ||
8159 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8160 wake_interval_mantissa)) {
8161 sigma_dut_print(dut, DUT_MSG_ERROR,
8162 "%s: err in adding vendor_cmd and vendor_data",
8163 __func__);
8164 nlmsg_free(msg);
8165 return -1;
8166 }
8167 nla_nest_end(msg, attr1);
8168 nla_nest_end(msg, params);
8169 nla_nest_end(msg, attr);
8170
8171 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8172 if (ret) {
8173 sigma_dut_print(dut, DUT_MSG_ERROR,
8174 "%s: err in send_and_recv_msgs, ret=%d",
8175 __func__, ret);
8176 }
8177
8178 return ret;
8179#else /* NL80211_SUPPORT */
8180 sigma_dut_print(dut, DUT_MSG_ERROR,
8181 "TWT request cannot be done without NL80211_SUPPORT defined");
8182 return -1;
8183#endif /* NL80211_SUPPORT */
8184}
8185
8186
8187static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8188 struct sigma_cmd *cmd)
8189{
8190 #ifdef NL80211_SUPPORT
8191 struct nlattr *params;
8192 struct nlattr *attr;
8193 struct nlattr *attr1;
8194 int ifindex, ret;
8195 struct nl_msg *msg;
8196 const char *intf = get_param(cmd, "Interface");
8197
8198 ifindex = if_nametoindex(intf);
8199 if (ifindex == 0) {
8200 sigma_dut_print(dut, DUT_MSG_ERROR,
8201 "%s: Index for interface %s failed",
8202 __func__, intf);
8203 return -1;
8204 }
8205
8206 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8207 NL80211_CMD_VENDOR)) ||
8208 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8209 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8210 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8211 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8212 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8213 !(params = nla_nest_start(
8214 msg,
8215 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8216 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8217 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8218 sigma_dut_print(dut, DUT_MSG_ERROR,
8219 "%s: err in adding vendor_cmd and vendor_data",
8220 __func__);
8221 nlmsg_free(msg);
8222 return -1;
8223 }
8224 nla_nest_end(msg, attr1);
8225 nla_nest_end(msg, params);
8226 nla_nest_end(msg, attr);
8227
8228 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8229 if (ret) {
8230 sigma_dut_print(dut, DUT_MSG_ERROR,
8231 "%s: err in send_and_recv_msgs, ret=%d",
8232 __func__, ret);
8233 }
8234
8235 return ret;
8236#else /* NL80211_SUPPORT */
8237 sigma_dut_print(dut, DUT_MSG_ERROR,
8238 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8239 return -1;
8240#endif /* NL80211_SUPPORT */
8241}
8242
8243
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008244static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8245 struct sigma_cmd *cmd)
8246{
8247#ifdef NL80211_SUPPORT
8248 struct nlattr *params;
8249 struct nlattr *attr;
8250 struct nlattr *attr1;
8251 struct nl_msg *msg;
8252 int ifindex, ret;
8253 const char *val;
8254 const char *intf = get_param(cmd, "Interface");
8255 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8256 ulmu_data_dis = 0;
8257
8258 ifindex = if_nametoindex(intf);
8259 if (ifindex == 0) {
8260 sigma_dut_print(dut, DUT_MSG_ERROR,
8261 "%s: Index for interface %s failed",
8262 __func__, intf);
8263 return -1;
8264 }
8265 val = get_param(cmd, "OMCtrl_RxNSS");
8266 if (val)
8267 rx_nss = atoi(val);
8268
8269 val = get_param(cmd, "OMCtrl_ChnlWidth");
8270 if (val)
8271 ch_bw = atoi(val);
8272
8273 val = get_param(cmd, "OMCtrl_ULMUDisable");
8274 if (val)
8275 ulmu_dis = atoi(val);
8276
8277 val = get_param(cmd, "OMCtrl_TxNSTS");
8278 if (val)
8279 tx_nsts = atoi(val);
8280
8281 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8282 if (val)
8283 ulmu_data_dis = atoi(val);
8284
8285 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8286 NL80211_CMD_VENDOR)) ||
8287 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8288 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8289 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8290 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8291 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8292 !(params = nla_nest_start(
8293 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8294 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8295 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8296 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8297 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8298 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8299 ulmu_data_dis) ||
8300 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8301 ulmu_dis)) {
8302 sigma_dut_print(dut, DUT_MSG_ERROR,
8303 "%s: err in adding vendor_cmd and vendor_data",
8304 __func__);
8305 nlmsg_free(msg);
8306 return -1;
8307 }
8308 nla_nest_end(msg, attr1);
8309 nla_nest_end(msg, params);
8310 nla_nest_end(msg, attr);
8311
8312 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8313 if (ret) {
8314 sigma_dut_print(dut, DUT_MSG_ERROR,
8315 "%s: err in send_and_recv_msgs, ret=%d",
8316 __func__, ret);
8317 }
8318
8319 return ret;
8320#else /* NL80211_SUPPORT */
8321 sigma_dut_print(dut, DUT_MSG_ERROR,
8322 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8323 return -1;
8324#endif /* NL80211_SUPPORT */
8325}
8326
8327
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008328static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8329 struct sigma_conn *conn,
8330 struct sigma_cmd *cmd)
8331{
8332 const char *intf = get_param(cmd, "Interface");
8333 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008334 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008335 int tkip = -1;
8336 int wep = -1;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308337 int iwpriv_status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008338
Arif Hussaina37e9552018-06-20 17:05:59 -07008339 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008340 val = get_param(cmd, "SGI80");
8341 if (val) {
8342 int sgi80;
8343
8344 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008345 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008346 }
8347
8348 val = get_param(cmd, "TxBF");
8349 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008350 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008351 case DRIVER_WCN:
8352 if (sta_set_tx_beamformee(dut, intf, 1)) {
8353 send_resp(dut, conn, SIGMA_ERROR,
8354 "ErrorCode,Failed to set TX beamformee enable");
8355 return 0;
8356 }
8357 break;
8358 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008359 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008360 send_resp(dut, conn, SIGMA_ERROR,
8361 "ErrorCode,Setting vhtsubfee failed");
8362 return 0;
8363 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008364 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008365 send_resp(dut, conn, SIGMA_ERROR,
8366 "ErrorCode,Setting vhtsubfer failed");
8367 return 0;
8368 }
8369 break;
8370 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008371 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008372 "Unsupported driver type");
8373 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008374 }
8375 }
8376
8377 val = get_param(cmd, "MU_TxBF");
8378 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008379 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008380 case DRIVER_ATHEROS:
8381 ath_sta_set_txsp_stream(dut, intf, "1SS");
8382 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008383 run_iwpriv(dut, intf, "vhtmubfee 1");
8384 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308385 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008386 case DRIVER_WCN:
8387 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8388 send_resp(dut, conn, SIGMA_ERROR,
8389 "ErrorCode,Failed to set RX/TXSP_STREAM");
8390 return 0;
8391 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308392 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008393 default:
8394 sigma_dut_print(dut, DUT_MSG_ERROR,
8395 "Setting SP_STREAM not supported");
8396 break;
8397 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008398 }
8399
8400 val = get_param(cmd, "LDPC");
8401 if (val) {
8402 int ldpc;
8403
8404 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308405 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", ldpc);
8406 if (iwpriv_status)
8407 sta_config_params(dut, intf, STA_SET_LDPC, ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008408 }
8409
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008410 val = get_param(cmd, "BCC");
8411 if (val) {
8412 int bcc;
8413
8414 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8415 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8416 * is mutually exclusive to bcc */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308417 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", !bcc);
8418 if (iwpriv_status)
8419 sta_config_params(dut, intf, STA_SET_LDPC, !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008420 }
8421
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008422 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8423 if (val && dut->sta_nss == 1)
8424 cmd_set_max_he_mcs(dut, intf, atoi(val));
8425
8426 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8427 if (val && dut->sta_nss == 2)
8428 cmd_set_max_he_mcs(dut, intf, atoi(val));
8429
Arif Hussainac6c5112018-05-25 17:34:00 -07008430 val = get_param(cmd, "MCS_FixedRate");
8431 if (val) {
8432#ifdef NL80211_SUPPORT
8433 int mcs, ratecode = 0;
8434 enum he_mcs_config mcs_config;
8435 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008436 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008437
8438 ratecode = (0x07 & dut->sta_nss) << 5;
8439 mcs = atoi(val);
8440 /* Add the MCS to the ratecode */
8441 if (mcs >= 0 && mcs <= 11) {
8442 ratecode += mcs;
8443 if (dut->device_type == STA_testbed &&
8444 mcs > 7 && mcs <= 11) {
8445 if (mcs <= 9)
8446 mcs_config = HE_80_MCS0_9;
8447 else
8448 mcs_config = HE_80_MCS0_11;
8449 ret = sta_set_he_mcs(dut, intf, mcs_config);
8450 if (ret) {
8451 sigma_dut_print(dut, DUT_MSG_ERROR,
8452 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8453 mcs, mcs_config, ret);
8454 }
8455 }
8456 snprintf(buf, sizeof(buf),
8457 "iwpriv %s set_11ax_rate 0x%03x",
8458 intf, ratecode);
8459 if (system(buf) != 0) {
8460 sigma_dut_print(dut, DUT_MSG_ERROR,
8461 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8462 ratecode);
8463 }
8464 } else {
8465 sigma_dut_print(dut, DUT_MSG_ERROR,
8466 "MCS_FixedRate: HE MCS %d not supported",
8467 mcs);
8468 }
8469#else /* NL80211_SUPPORT */
8470 sigma_dut_print(dut, DUT_MSG_ERROR,
8471 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8472#endif /* NL80211_SUPPORT */
8473 }
8474
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008475 val = get_param(cmd, "opt_md_notif_ie");
8476 if (val) {
8477 char *result = NULL;
8478 char delim[] = ";";
8479 char token[30];
8480 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308481 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008482
Peng Xub8fc5cc2017-05-10 17:27:28 -07008483 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308484 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008485
8486 /* Extract the NSS information */
8487 if (result) {
8488 value = atoi(result);
8489 switch (value) {
8490 case 1:
8491 config_val = 1;
8492 break;
8493 case 2:
8494 config_val = 3;
8495 break;
8496 case 3:
8497 config_val = 7;
8498 break;
8499 case 4:
8500 config_val = 15;
8501 break;
8502 default:
8503 config_val = 3;
8504 break;
8505 }
8506
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008507 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8508 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008509
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008510 }
8511
8512 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308513 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008514 if (result) {
8515 value = atoi(result);
8516 switch (value) {
8517 case 20:
8518 config_val = 0;
8519 break;
8520 case 40:
8521 config_val = 1;
8522 break;
8523 case 80:
8524 config_val = 2;
8525 break;
8526 case 160:
8527 config_val = 3;
8528 break;
8529 default:
8530 config_val = 2;
8531 break;
8532 }
8533
8534 dut->chwidth = config_val;
8535
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008536 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008537 }
8538
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008539 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008540 }
8541
8542 val = get_param(cmd, "nss_mcs_cap");
8543 if (val) {
8544 int nss, mcs;
8545 char token[20];
8546 char *result = NULL;
8547 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308548 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008549
Peng Xub8fc5cc2017-05-10 17:27:28 -07008550 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308551 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308552 if (!result) {
8553 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008554 "NSS not specified");
8555 send_resp(dut, conn, SIGMA_ERROR,
8556 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308557 return 0;
8558 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008559 nss = atoi(result);
8560
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008561 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07008562 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008563
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308564 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008565 if (result == NULL) {
8566 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008567 "MCS not specified");
8568 send_resp(dut, conn, SIGMA_ERROR,
8569 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008570 return 0;
8571 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308572 result = strtok_r(result, "-", &saveptr);
8573 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308574 if (!result) {
8575 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008576 "MCS not specified");
8577 send_resp(dut, conn, SIGMA_ERROR,
8578 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308579 return 0;
8580 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008581 mcs = atoi(result);
8582
Arif Hussaina37e9552018-06-20 17:05:59 -07008583 if (program && strcasecmp(program, "HE") == 0) {
8584#ifdef NL80211_SUPPORT
8585 enum he_mcs_config mcs_config;
8586 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008587
Arif Hussaina37e9552018-06-20 17:05:59 -07008588 if (mcs >= 0 && mcs <= 7) {
8589 mcs_config = HE_80_MCS0_7;
8590 } else if (mcs > 7 && mcs <= 9) {
8591 mcs_config = HE_80_MCS0_9;
8592 } else if (mcs > 9 && mcs <= 11) {
8593 mcs_config = HE_80_MCS0_11;
8594 } else {
8595 sigma_dut_print(dut, DUT_MSG_ERROR,
8596 "nss_mcs_cap: HE: Invalid mcs: %d",
8597 mcs);
8598 send_resp(dut, conn, SIGMA_ERROR,
8599 "errorCode,Invalid MCS");
8600 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008601 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008602
8603 ret = sta_set_he_mcs(dut, intf, mcs_config);
8604 if (ret) {
8605 sigma_dut_print(dut, DUT_MSG_ERROR,
8606 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
8607 mcs_config, ret);
8608 send_resp(dut, conn, SIGMA_ERROR,
8609 "errorCode,Failed to set MCS");
8610 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008611 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008612#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008613 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008614 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
8615#endif /* NL80211_SUPPORT */
8616 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008617 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07008618
8619 switch (nss) {
8620 case 1:
8621 switch (mcs) {
8622 case 7:
8623 vht_mcsmap = 0xfffc;
8624 break;
8625 case 8:
8626 vht_mcsmap = 0xfffd;
8627 break;
8628 case 9:
8629 vht_mcsmap = 0xfffe;
8630 break;
8631 default:
8632 vht_mcsmap = 0xfffe;
8633 break;
8634 }
8635 break;
8636 case 2:
8637 switch (mcs) {
8638 case 7:
8639 vht_mcsmap = 0xfff0;
8640 break;
8641 case 8:
8642 vht_mcsmap = 0xfff5;
8643 break;
8644 case 9:
8645 vht_mcsmap = 0xfffa;
8646 break;
8647 default:
8648 vht_mcsmap = 0xfffa;
8649 break;
8650 }
8651 break;
8652 case 3:
8653 switch (mcs) {
8654 case 7:
8655 vht_mcsmap = 0xffc0;
8656 break;
8657 case 8:
8658 vht_mcsmap = 0xffd5;
8659 break;
8660 case 9:
8661 vht_mcsmap = 0xffea;
8662 break;
8663 default:
8664 vht_mcsmap = 0xffea;
8665 break;
8666 }
8667 break;
8668 default:
8669 vht_mcsmap = 0xffea;
8670 break;
8671 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008672 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008673 }
8674 }
8675
8676 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
8677
8678 val = get_param(cmd, "Vht_tkip");
8679 if (val)
8680 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8681
8682 val = get_param(cmd, "Vht_wep");
8683 if (val)
8684 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8685
8686 if (tkip != -1 || wep != -1) {
8687 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008688 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008689 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008690 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008691 } else {
8692 sigma_dut_print(dut, DUT_MSG_ERROR,
8693 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
8694 return 0;
8695 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008696 }
8697
Arif Hussain55f00da2018-07-03 08:28:26 -07008698 val = get_param(cmd, "txBandwidth");
8699 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008700 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07008701 case DRIVER_WCN:
8702 if (wcn_sta_set_width(dut, intf, val) < 0) {
8703 send_resp(dut, conn, SIGMA_ERROR,
8704 "ErrorCode,Failed to set txBandwidth");
8705 return 0;
8706 }
8707 break;
8708 case DRIVER_ATHEROS:
8709 if (ath_set_width(dut, conn, intf, val) < 0) {
8710 send_resp(dut, conn, SIGMA_ERROR,
8711 "ErrorCode,Failed to set txBandwidth");
8712 return 0;
8713 }
8714 break;
8715 default:
8716 sigma_dut_print(dut, DUT_MSG_ERROR,
8717 "Setting txBandwidth not supported");
8718 break;
8719 }
8720 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008721
Arif Hussain9765f7d2018-07-03 08:28:26 -07008722 val = get_param(cmd, "BeamformeeSTS");
8723 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07008724 if (sta_set_tx_beamformee(dut, intf, 1)) {
8725 send_resp(dut, conn, SIGMA_ERROR,
8726 "ErrorCode,Failed to set TX beamformee enable");
8727 return 0;
8728 }
8729
Arif Hussain9765f7d2018-07-03 08:28:26 -07008730 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
8731 send_resp(dut, conn, SIGMA_ERROR,
8732 "ErrorCode,Failed to set BeamformeeSTS");
8733 return 0;
8734 }
8735 }
8736
Arif Hussain68d23f52018-07-11 13:39:08 -07008737 val = get_param(cmd, "Trig_MAC_Padding_Dur");
8738 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008739#ifdef NL80211_SUPPORT
8740 enum qca_wlan_he_mac_padding_dur set_val;
8741
8742 switch (atoi(val)) {
8743 case 16:
8744 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
8745 break;
8746 case 8:
8747 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
8748 break;
8749 default:
8750 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
8751 break;
8752 }
8753 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008754 send_resp(dut, conn, SIGMA_ERROR,
8755 "ErrorCode,Failed to set MAC padding duration");
8756 return 0;
8757 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008758#else /* NL80211_SUPPORT */
8759 sigma_dut_print(dut, DUT_MSG_ERROR,
8760 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
8761#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008762 }
8763
Arif Hussain480d5f42019-03-12 14:40:42 -07008764 val = get_param(cmd, "TWT_ReqSupport");
8765 if (val) {
8766 int set_val;
8767
8768 if (strcasecmp(val, "Enable") == 0) {
8769 set_val = 1;
8770 } else if (strcasecmp(val, "Disable") == 0) {
8771 set_val = 0;
8772 } else {
8773 send_resp(dut, conn, SIGMA_ERROR,
8774 "ErrorCode,Invalid TWT_ReqSupport");
8775 return STATUS_SENT;
8776 }
8777
8778 if (sta_set_twt_req_support(dut, intf, set_val)) {
8779 sigma_dut_print(dut, DUT_MSG_ERROR,
8780 "Failed to set TWT req support %d",
8781 set_val);
8782 send_resp(dut, conn, SIGMA_ERROR,
8783 "ErrorCode,Failed to set TWT_ReqSupport");
8784 return STATUS_SENT;
8785 }
8786 }
8787
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008788 val = get_param(cmd, "MU_EDCA");
8789 if (val && (strcasecmp(val, "Override") == 0)) {
8790 if (sta_set_mu_edca_override(dut, intf, 1)) {
8791 send_resp(dut, conn, SIGMA_ERROR,
8792 "ErrorCode,Failed to set MU EDCA override");
8793 return 0;
8794 }
8795 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008796
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008797 val = get_param(cmd, "OMControl");
8798 if (val) {
8799 int set_val = 1;
8800
8801 if (strcasecmp(val, "Enable") == 0)
8802 set_val = 1;
8803 else if (strcasecmp(val, "Disable") == 0)
8804 set_val = 0;
8805
8806 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
8807 send_resp(dut, conn, SIGMA_ERROR,
8808 "ErrorCode,Failed to set OM ctrl supp");
8809 return 0;
8810 }
8811 }
8812
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008813 val = get_param(cmd, "ADDBAResp_BufSize");
8814 if (val) {
8815 int buf_size;
8816
8817 if (strcasecmp(val, "gt64") == 0)
8818 buf_size = 256;
8819 else
8820 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008821 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008822 sta_set_addba_buf_size(dut, intf, buf_size)) {
8823 send_resp(dut, conn, SIGMA_ERROR,
8824 "ErrorCode,set addbaresp_buff_size failed");
8825 return 0;
8826 }
8827 }
8828
8829 val = get_param(cmd, "ADDBAReq_BufSize");
8830 if (val) {
8831 int buf_size;
8832
8833 if (strcasecmp(val, "gt64") == 0)
8834 buf_size = 256;
8835 else
8836 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008837 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008838 sta_set_addba_buf_size(dut, intf, buf_size)) {
8839 send_resp(dut, conn, SIGMA_ERROR,
8840 "ErrorCode,set addbareq_buff_size failed");
8841 return 0;
8842 }
8843 }
8844
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008845 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8846}
8847
8848
8849static int sta_set_wireless_60g(struct sigma_dut *dut,
8850 struct sigma_conn *conn,
8851 struct sigma_cmd *cmd)
8852{
8853 const char *dev_role = get_param(cmd, "DevRole");
8854
8855 if (!dev_role) {
8856 send_resp(dut, conn, SIGMA_INVALID,
8857 "ErrorCode,DevRole not specified");
8858 return 0;
8859 }
8860
8861 if (strcasecmp(dev_role, "PCP") == 0)
8862 return sta_set_60g_pcp(dut, conn, cmd);
8863 if (strcasecmp(dev_role, "STA") == 0)
8864 return sta_set_60g_sta(dut, conn, cmd);
8865 send_resp(dut, conn, SIGMA_INVALID,
8866 "ErrorCode,DevRole not supported");
8867 return 0;
8868}
8869
8870
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308871static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
8872 struct sigma_cmd *cmd)
8873{
8874 int status;
8875 const char *intf = get_param(cmd, "Interface");
8876 const char *val = get_param(cmd, "DevRole");
8877
8878 if (val && strcasecmp(val, "STA-CFON") == 0) {
8879 status = sta_cfon_set_wireless(dut, conn, cmd);
8880 if (status)
8881 return status;
8882 }
8883 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8884}
8885
8886
Jouni Malinen67433fc2020-06-26 22:50:33 +03008887static enum sigma_cmd_result
8888sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
8889 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308890{
8891 const char *intf = get_param(cmd, "Interface");
8892 const char *val;
8893
8894 val = get_param(cmd, "ocvc");
8895 if (val)
8896 dut->ocvc = atoi(val);
8897
Jouni Malinen67433fc2020-06-26 22:50:33 +03008898 val = get_param(cmd, "ClientPrivacy");
8899 if (val) {
8900 dut->client_privacy = atoi(val);
8901 if (dut->client_privacy &&
8902 (wpa_command(intf, "SET mac_addr 1") < 0 ||
8903 wpa_command(intf, "SET rand_addr_lifetime 1") < 0 ||
8904 wpa_command(intf, "SET preassoc_mac_addr 1") < 0 ||
8905 wpa_command(intf, "SET gas_rand_mac_addr 1") < 0 ||
8906 wpa_command(intf, "SET gas_rand_addr_lifetime 1") < 0)) {
8907 send_resp(dut, conn, SIGMA_ERROR,
8908 "errorCode,Failed to enable random MAC address use");
8909 return STATUS_SENT_ERROR;
8910 }
8911 }
8912
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308913 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8914}
8915
8916
Jouni Malinenf7222712019-06-13 01:50:21 +03008917static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
8918 struct sigma_conn *conn,
8919 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008920{
8921 const char *val;
8922
8923 val = get_param(cmd, "Program");
8924 if (val) {
8925 if (strcasecmp(val, "11n") == 0)
8926 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08008927 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008928 return cmd_sta_set_wireless_vht(dut, conn, cmd);
8929 if (strcasecmp(val, "60ghz") == 0)
8930 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308931 if (strcasecmp(val, "OCE") == 0)
8932 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02008933 /* sta_set_wireless in WPS program is only used for 60G */
8934 if (is_60g_sigma_dut(dut))
8935 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308936 if (strcasecmp(val, "WPA3") == 0)
8937 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008938 send_resp(dut, conn, SIGMA_ERROR,
8939 "ErrorCode,Program value not supported");
8940 } else {
8941 send_resp(dut, conn, SIGMA_ERROR,
8942 "ErrorCode,Program argument not available");
8943 }
8944
8945 return 0;
8946}
8947
8948
8949static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
8950 int tid)
8951{
8952 char buf[100];
8953 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
8954
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05308955 if (tid < 0 ||
8956 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
8957 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
8958 return;
8959 }
8960
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008961 /*
8962 * Two ways to ensure that addba request with a
8963 * non zero TID could be sent out. EV 117296
8964 */
8965 snprintf(buf, sizeof(buf),
8966 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
8967 tid);
8968 if (system(buf) != 0) {
8969 sigma_dut_print(dut, DUT_MSG_ERROR,
8970 "Ping did not send out");
8971 }
8972
8973 snprintf(buf, sizeof(buf),
8974 "iwconfig %s | grep Access | awk '{print $6}' > %s",
8975 intf, VI_QOS_TMP_FILE);
8976 if (system(buf) != 0)
8977 return;
8978
8979 snprintf(buf, sizeof(buf),
8980 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
8981 intf, VI_QOS_TMP_FILE);
8982 if (system(buf) != 0)
8983 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
8984
8985 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
8986 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
8987 if (system(buf) != 0) {
8988 sigma_dut_print(dut, DUT_MSG_ERROR,
8989 "VI_QOS_TEMP_FILE generation error failed");
8990 }
8991 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
8992 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
8993 if (system(buf) != 0) {
8994 sigma_dut_print(dut, DUT_MSG_ERROR,
8995 "VI_QOS_FILE generation failed");
8996 }
8997
8998 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
8999 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9000 if (system(buf) != 0) {
9001 sigma_dut_print(dut, DUT_MSG_ERROR,
9002 "VI_QOS_FILE generation failed");
9003 }
9004
9005 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
9006 if (system(buf) != 0) {
9007 }
9008}
9009
9010
9011static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9012 struct sigma_cmd *cmd)
9013{
9014 const char *intf = get_param(cmd, "Interface");
9015 const char *val;
9016 int tid = 0;
9017 char buf[100];
9018
9019 val = get_param(cmd, "TID");
9020 if (val) {
9021 tid = atoi(val);
9022 if (tid)
9023 ath_sta_inject_frame(dut, intf, tid);
9024 }
9025
9026 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009027 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009028
9029 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
9030 if (system(buf) != 0) {
9031 sigma_dut_print(dut, DUT_MSG_ERROR,
9032 "wifitool senddelba failed");
9033 }
9034
9035 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
9036 if (system(buf) != 0) {
9037 sigma_dut_print(dut, DUT_MSG_ERROR,
9038 "wifitool sendaddba failed");
9039 }
9040
9041 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9042
9043 return 1;
9044}
9045
9046
Lior David9981b512017-01-20 13:16:40 +02009047#ifdef __linux__
9048
9049static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
9050 int agg_size)
9051{
9052 char dir[128], buf[128];
9053 FILE *f;
9054 regex_t re;
9055 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03009056 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02009057
9058 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
9059 sigma_dut_print(dut, DUT_MSG_ERROR,
9060 "failed to get wil6210 debugfs dir");
9061 return -1;
9062 }
9063
Jouni Malinen3aa72862019-05-29 23:14:51 +03009064 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
9065 if (res < 0 || res >= sizeof(buf))
9066 return -1;
Lior David9981b512017-01-20 13:16:40 +02009067 f = fopen(buf, "r");
9068 if (!f) {
9069 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009070 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009071 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9072 if (res < 0 || res >= sizeof(buf))
9073 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009074 f = fopen(buf, "r");
9075 if (!f) {
9076 sigma_dut_print(dut, DUT_MSG_ERROR,
9077 "failed to open: %s", buf);
9078 return -1;
9079 }
Lior David9981b512017-01-20 13:16:40 +02009080 }
9081
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009082 /* can be either VRING tx... or RING... */
9083 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009084 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9085 goto out;
9086 }
9087
9088 /* find TX VRING for the mac address */
9089 found = 0;
9090 while (fgets(buf, sizeof(buf), f)) {
9091 if (strcasestr(buf, dest_mac)) {
9092 found = 1;
9093 break;
9094 }
9095 }
9096
9097 if (!found) {
9098 sigma_dut_print(dut, DUT_MSG_ERROR,
9099 "no TX VRING for %s", dest_mac);
9100 goto out;
9101 }
9102
9103 /* extract VRING ID, "VRING tx_<id> = {" */
9104 if (!fgets(buf, sizeof(buf), f)) {
9105 sigma_dut_print(dut, DUT_MSG_ERROR,
9106 "no VRING start line for %s", dest_mac);
9107 goto out;
9108 }
9109
9110 rc = regexec(&re, buf, 2, m, 0);
9111 regfree(&re);
9112 if (rc || m[1].rm_so < 0) {
9113 sigma_dut_print(dut, DUT_MSG_ERROR,
9114 "no VRING TX ID for %s", dest_mac);
9115 goto out;
9116 }
9117 buf[m[1].rm_eo] = 0;
9118 vring_id = atoi(&buf[m[1].rm_so]);
9119
9120 /* send the addba command */
9121 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009122 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9123 if (res < 0 || res >= sizeof(buf))
9124 return -1;
Lior David9981b512017-01-20 13:16:40 +02009125 f = fopen(buf, "w");
9126 if (!f) {
9127 sigma_dut_print(dut, DUT_MSG_ERROR,
9128 "failed to open: %s", buf);
9129 return -1;
9130 }
9131
9132 fprintf(f, "add %d %d\n", vring_id, agg_size);
9133
9134 ret = 0;
9135
9136out:
9137 fclose(f);
9138
9139 return ret;
9140}
9141
9142
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009143int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9144 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009145{
9146 const char *val;
9147 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009148
9149 val = get_param(cmd, "TID");
9150 if (val) {
9151 tid = atoi(val);
9152 if (tid != 0) {
9153 sigma_dut_print(dut, DUT_MSG_ERROR,
9154 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9155 tid);
9156 }
9157 }
9158
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009159 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009160 if (!val) {
9161 sigma_dut_print(dut, DUT_MSG_ERROR,
9162 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009163 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009164 }
9165
Lior David9981b512017-01-20 13:16:40 +02009166 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009167 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009168
9169 return 1;
9170}
9171
Lior David9981b512017-01-20 13:16:40 +02009172#endif /* __linux__ */
9173
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009174
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009175static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9176 struct sigma_cmd *cmd)
9177{
9178#ifdef NL80211_SUPPORT
9179 const char *intf = get_param(cmd, "Interface");
9180 const char *val;
9181 int tid = -1;
9182 int bufsize = 64;
9183 struct nl_msg *msg;
9184 int ret = 0;
9185 struct nlattr *params;
9186 int ifindex;
9187
9188 val = get_param(cmd, "TID");
9189 if (val)
9190 tid = atoi(val);
9191
9192 if (tid == -1) {
9193 send_resp(dut, conn, SIGMA_ERROR,
9194 "ErrorCode,sta_send_addba tid invalid");
9195 return 0;
9196 }
9197
9198 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9199
9200 ifindex = if_nametoindex(intf);
9201 if (ifindex == 0) {
9202 sigma_dut_print(dut, DUT_MSG_ERROR,
9203 "%s: Index for interface %s failed",
9204 __func__, intf);
9205 send_resp(dut, conn, SIGMA_ERROR,
9206 "ErrorCode,sta_send_addba interface invalid");
9207 return 0;
9208 }
9209
9210 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9211 NL80211_CMD_VENDOR)) ||
9212 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9213 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9214 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9215 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9216 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9217 nla_put_u8(msg,
9218 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9219 QCA_WLAN_ADD_BA) ||
9220 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9221 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009222 nla_put_u16(msg,
9223 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9224 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009225 sigma_dut_print(dut, DUT_MSG_ERROR,
9226 "%s: err in adding vendor_cmd and vendor_data",
9227 __func__);
9228 nlmsg_free(msg);
9229 send_resp(dut, conn, SIGMA_ERROR,
9230 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9231 return 0;
9232 }
9233 nla_nest_end(msg, params);
9234
9235 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9236 if (ret) {
9237 sigma_dut_print(dut, DUT_MSG_ERROR,
9238 "%s: err in send_and_recv_msgs, ret=%d",
9239 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309240 if (ret == -EOPNOTSUPP)
9241 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009242 send_resp(dut, conn, SIGMA_ERROR,
9243 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9244 return 0;
9245 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009246#else /* NL80211_SUPPORT */
9247 sigma_dut_print(dut, DUT_MSG_ERROR,
9248 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009249#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309250
9251 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009252}
9253
9254
Jouni Malinenf7222712019-06-13 01:50:21 +03009255static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9256 struct sigma_conn *conn,
9257 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009258{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009259 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009260 case DRIVER_ATHEROS:
9261 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009262 case DRIVER_WCN:
9263 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009264#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009265 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009266 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009267#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009268 default:
9269 /*
9270 * There is no driver specific implementation for other drivers.
9271 * Ignore the command and report COMPLETE since the following
9272 * throughput test operation will end up sending ADDBA anyway.
9273 */
9274 return 1;
9275 }
9276}
9277
9278
9279int inject_eth_frame(int s, const void *data, size_t len,
9280 unsigned short ethtype, char *dst, char *src)
9281{
9282 struct iovec iov[4] = {
9283 {
9284 .iov_base = dst,
9285 .iov_len = ETH_ALEN,
9286 },
9287 {
9288 .iov_base = src,
9289 .iov_len = ETH_ALEN,
9290 },
9291 {
9292 .iov_base = &ethtype,
9293 .iov_len = sizeof(unsigned short),
9294 },
9295 {
9296 .iov_base = (void *) data,
9297 .iov_len = len,
9298 }
9299 };
9300 struct msghdr msg = {
9301 .msg_name = NULL,
9302 .msg_namelen = 0,
9303 .msg_iov = iov,
9304 .msg_iovlen = 4,
9305 .msg_control = NULL,
9306 .msg_controllen = 0,
9307 .msg_flags = 0,
9308 };
9309
9310 return sendmsg(s, &msg, 0);
9311}
9312
9313#if defined(__linux__) || defined(__QNXNTO__)
9314
9315int inject_frame(int s, const void *data, size_t len, int encrypt)
9316{
9317#define IEEE80211_RADIOTAP_F_WEP 0x04
9318#define IEEE80211_RADIOTAP_F_FRAG 0x08
9319 unsigned char rtap_hdr[] = {
9320 0x00, 0x00, /* radiotap version */
9321 0x0e, 0x00, /* radiotap length */
9322 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9323 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9324 0x00, /* padding */
9325 0x00, 0x00, /* RX and TX flags to indicate that */
9326 0x00, 0x00, /* this is the injected frame directly */
9327 };
9328 struct iovec iov[2] = {
9329 {
9330 .iov_base = &rtap_hdr,
9331 .iov_len = sizeof(rtap_hdr),
9332 },
9333 {
9334 .iov_base = (void *) data,
9335 .iov_len = len,
9336 }
9337 };
9338 struct msghdr msg = {
9339 .msg_name = NULL,
9340 .msg_namelen = 0,
9341 .msg_iov = iov,
9342 .msg_iovlen = 2,
9343 .msg_control = NULL,
9344 .msg_controllen = 0,
9345 .msg_flags = 0,
9346 };
9347
9348 if (encrypt)
9349 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9350
9351 return sendmsg(s, &msg, 0);
9352}
9353
9354
9355int open_monitor(const char *ifname)
9356{
9357#ifdef __QNXNTO__
9358 struct sockaddr_dl ll;
9359 int s;
9360
9361 memset(&ll, 0, sizeof(ll));
9362 ll.sdl_family = AF_LINK;
9363 ll.sdl_index = if_nametoindex(ifname);
9364 if (ll.sdl_index == 0) {
9365 perror("if_nametoindex");
9366 return -1;
9367 }
9368 s = socket(PF_INET, SOCK_RAW, 0);
9369#else /* __QNXNTO__ */
9370 struct sockaddr_ll ll;
9371 int s;
9372
9373 memset(&ll, 0, sizeof(ll));
9374 ll.sll_family = AF_PACKET;
9375 ll.sll_ifindex = if_nametoindex(ifname);
9376 if (ll.sll_ifindex == 0) {
9377 perror("if_nametoindex");
9378 return -1;
9379 }
9380 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9381#endif /* __QNXNTO__ */
9382 if (s < 0) {
9383 perror("socket[PF_PACKET,SOCK_RAW]");
9384 return -1;
9385 }
9386
9387 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9388 perror("monitor socket bind");
9389 close(s);
9390 return -1;
9391 }
9392
9393 return s;
9394}
9395
9396
9397static int hex2num(char c)
9398{
9399 if (c >= '0' && c <= '9')
9400 return c - '0';
9401 if (c >= 'a' && c <= 'f')
9402 return c - 'a' + 10;
9403 if (c >= 'A' && c <= 'F')
9404 return c - 'A' + 10;
9405 return -1;
9406}
9407
9408
9409int hwaddr_aton(const char *txt, unsigned char *addr)
9410{
9411 int i;
9412
9413 for (i = 0; i < 6; i++) {
9414 int a, b;
9415
9416 a = hex2num(*txt++);
9417 if (a < 0)
9418 return -1;
9419 b = hex2num(*txt++);
9420 if (b < 0)
9421 return -1;
9422 *addr++ = (a << 4) | b;
9423 if (i < 5 && *txt++ != ':')
9424 return -1;
9425 }
9426
9427 return 0;
9428}
9429
9430#endif /* defined(__linux__) || defined(__QNXNTO__) */
9431
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309432
9433#ifdef NL80211_SUPPORT
9434static int nl80211_send_frame_cmd(struct sigma_dut *dut, const char *intf,
9435 const u8 *data, size_t data_len, int freq)
9436{
9437 struct nl_msg *msg;
9438 int ret = 0;
9439 int ifindex;
9440
9441 ifindex = if_nametoindex(intf);
9442 if (ifindex == 0) {
9443 sigma_dut_print(dut, DUT_MSG_ERROR,
9444 "%s: Index for interface %s failed",
9445 __func__, intf);
9446 return -1;
9447 }
9448
9449 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9450 NL80211_CMD_FRAME)) ||
9451 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
9452 nla_put(msg, NL80211_ATTR_FRAME, data_len, data)) {
9453 sigma_dut_print(dut, DUT_MSG_ERROR,
9454 "%s: Error in adding NL80211_CMD_FRAME",
9455 __func__);
9456 nlmsg_free(msg);
9457 return -1;
9458 }
9459
9460 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9461 if (ret) {
9462 sigma_dut_print(dut, DUT_MSG_ERROR,
9463 "nl80211: Frame command failed: ret=%d (%s) req=%u",
9464 ret, strerror(-ret), freq);
9465 return -1;
9466 }
9467
9468 return 0;
9469}
9470#endif /* NL80211_SUPPORT */
9471
9472
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009473enum send_frame_type {
9474 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9475};
9476enum send_frame_protection {
9477 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9478};
9479
9480
9481static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309482 const char *intf, enum send_frame_type frame,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009483 enum send_frame_protection protected,
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309484 const char *dest, int use_monitor)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009485{
9486#ifdef __linux__
9487 unsigned char buf[1000], *pos;
9488 int s, res;
9489 char bssid[20], addr[20];
9490 char result[32], ssid[100];
9491 size_t ssid_len;
9492
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009493 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009494 sizeof(result)) < 0 ||
9495 strncmp(result, "COMPLETED", 9) != 0) {
9496 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9497 return 0;
9498 }
9499
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009500 if (get_wpa_status(get_station_ifname(dut), "bssid",
9501 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009502 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9503 "current BSSID");
9504 return 0;
9505 }
9506
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009507 if (get_wpa_status(get_station_ifname(dut), "address",
9508 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009509 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9510 "own MAC address");
9511 return 0;
9512 }
9513
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009514 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009515 < 0) {
9516 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9517 "current SSID");
9518 return 0;
9519 }
9520 ssid_len = strlen(ssid);
9521
9522 pos = buf;
9523
9524 /* Frame Control */
9525 switch (frame) {
9526 case DISASSOC:
9527 *pos++ = 0xa0;
9528 break;
9529 case DEAUTH:
9530 *pos++ = 0xc0;
9531 break;
9532 case SAQUERY:
9533 *pos++ = 0xd0;
9534 break;
9535 case AUTH:
9536 *pos++ = 0xb0;
9537 break;
9538 case ASSOCREQ:
9539 *pos++ = 0x00;
9540 break;
9541 case REASSOCREQ:
9542 *pos++ = 0x20;
9543 break;
9544 case DLS_REQ:
9545 *pos++ = 0xd0;
9546 break;
9547 }
9548
9549 if (protected == INCORRECT_KEY)
9550 *pos++ = 0x40; /* Set Protected field to 1 */
9551 else
9552 *pos++ = 0x00;
9553
9554 /* Duration */
9555 *pos++ = 0x00;
9556 *pos++ = 0x00;
9557
9558 /* addr1 = DA (current AP) */
9559 hwaddr_aton(bssid, pos);
9560 pos += 6;
9561 /* addr2 = SA (own address) */
9562 hwaddr_aton(addr, pos);
9563 pos += 6;
9564 /* addr3 = BSSID (current AP) */
9565 hwaddr_aton(bssid, pos);
9566 pos += 6;
9567
9568 /* Seq# (to be filled by driver/mac80211) */
9569 *pos++ = 0x00;
9570 *pos++ = 0x00;
9571
9572 if (protected == INCORRECT_KEY) {
9573 /* CCMP parameters */
9574 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9575 pos += 8;
9576 }
9577
9578 if (protected == INCORRECT_KEY) {
9579 switch (frame) {
9580 case DEAUTH:
9581 /* Reason code (encrypted) */
9582 memcpy(pos, "\xa7\x39", 2);
9583 pos += 2;
9584 break;
9585 case DISASSOC:
9586 /* Reason code (encrypted) */
9587 memcpy(pos, "\xa7\x39", 2);
9588 pos += 2;
9589 break;
9590 case SAQUERY:
9591 /* Category|Action|TransID (encrypted) */
9592 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9593 pos += 4;
9594 break;
9595 default:
9596 return -1;
9597 }
9598
9599 /* CCMP MIC */
9600 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9601 pos += 8;
9602 } else {
9603 switch (frame) {
9604 case DEAUTH:
9605 /* reason code = 8 */
9606 *pos++ = 0x08;
9607 *pos++ = 0x00;
9608 break;
9609 case DISASSOC:
9610 /* reason code = 8 */
9611 *pos++ = 0x08;
9612 *pos++ = 0x00;
9613 break;
9614 case SAQUERY:
9615 /* Category - SA Query */
9616 *pos++ = 0x08;
9617 /* SA query Action - Request */
9618 *pos++ = 0x00;
9619 /* Transaction ID */
9620 *pos++ = 0x12;
9621 *pos++ = 0x34;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05309622 if (dut->saquery_oci_freq) {
9623 /* OCI IE - Extended ID */
9624 *pos++ = 0xFF;
9625 *pos++ = 0x04;
9626 *pos++ = 0x36;
9627 /* Operating Class */
9628 *pos++ = 0x74;
9629 /* Primary Channel */
9630 *pos++ = freq_to_channel(dut->saquery_oci_freq);
9631 /* Frequency Segment 1 Channel Number */
9632 *pos++ = 0x00;
9633 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009634 break;
9635 case AUTH:
9636 /* Auth Alg (Open) */
9637 *pos++ = 0x00;
9638 *pos++ = 0x00;
9639 /* Seq# */
9640 *pos++ = 0x01;
9641 *pos++ = 0x00;
9642 /* Status code */
9643 *pos++ = 0x00;
9644 *pos++ = 0x00;
9645 break;
9646 case ASSOCREQ:
9647 /* Capability Information */
9648 *pos++ = 0x31;
9649 *pos++ = 0x04;
9650 /* Listen Interval */
9651 *pos++ = 0x0a;
9652 *pos++ = 0x00;
9653 /* SSID */
9654 *pos++ = 0x00;
9655 *pos++ = ssid_len;
9656 memcpy(pos, ssid, ssid_len);
9657 pos += ssid_len;
9658 /* Supported Rates */
9659 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9660 10);
9661 pos += 10;
9662 /* Extended Supported Rates */
9663 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9664 pos += 6;
9665 /* RSN */
9666 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9667 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9668 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9669 pos += 28;
9670 break;
9671 case REASSOCREQ:
9672 /* Capability Information */
9673 *pos++ = 0x31;
9674 *pos++ = 0x04;
9675 /* Listen Interval */
9676 *pos++ = 0x0a;
9677 *pos++ = 0x00;
9678 /* Current AP */
9679 hwaddr_aton(bssid, pos);
9680 pos += 6;
9681 /* SSID */
9682 *pos++ = 0x00;
9683 *pos++ = ssid_len;
9684 memcpy(pos, ssid, ssid_len);
9685 pos += ssid_len;
9686 /* Supported Rates */
9687 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9688 10);
9689 pos += 10;
9690 /* Extended Supported Rates */
9691 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9692 pos += 6;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05309693 /* RSNE - Group and Pairwise ciphers */
9694 memcpy(pos,
9695 "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04",
9696 14);
9697 pos += 14;
9698 /* RSNE - AKM Suite count */
9699 *pos++ = 0x01;
9700 *pos++ = 0x00;
9701 /* RSNE - AKM Suites */
9702 if (dut->program == PROGRAM_WPA3)
9703 memcpy(pos, "\x00\x0f\xac\x08", 4);
9704 else
9705 memcpy(pos, "\x00\x0f\xac\x02", 4);
9706 pos += 4;
9707 /* RSNE - Capabilities */
9708 *pos++ = 0xc0;
9709 if (dut->ocvc)
9710 *pos++ = 0x40;
9711 else
9712 *pos++ = 0x00;
9713 /* RSNE - PMKID list and Group Management Ciphers */
9714 memcpy(pos, "\x00\x00\x00\x0f\xac\x06", 6);
9715 pos += 6;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009716 break;
9717 case DLS_REQ:
9718 /* Category - DLS */
9719 *pos++ = 0x02;
9720 /* DLS Action - Request */
9721 *pos++ = 0x00;
9722 /* Destination MACAddress */
9723 if (dest)
9724 hwaddr_aton(dest, pos);
9725 else
9726 memset(pos, 0, 6);
9727 pos += 6;
9728 /* Source MACAddress */
9729 hwaddr_aton(addr, pos);
9730 pos += 6;
9731 /* Capability Information */
9732 *pos++ = 0x10; /* Privacy */
9733 *pos++ = 0x06; /* QoS */
9734 /* DLS Timeout Value */
9735 *pos++ = 0x00;
9736 *pos++ = 0x01;
9737 /* Supported rates */
9738 *pos++ = 0x01;
9739 *pos++ = 0x08;
9740 *pos++ = 0x0c; /* 6 Mbps */
9741 *pos++ = 0x12; /* 9 Mbps */
9742 *pos++ = 0x18; /* 12 Mbps */
9743 *pos++ = 0x24; /* 18 Mbps */
9744 *pos++ = 0x30; /* 24 Mbps */
9745 *pos++ = 0x48; /* 36 Mbps */
9746 *pos++ = 0x60; /* 48 Mbps */
9747 *pos++ = 0x6c; /* 54 Mbps */
9748 /* TODO: Extended Supported Rates */
9749 /* TODO: HT Capabilities */
9750 break;
9751 }
9752 }
9753
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309754 if (use_monitor) {
9755 s = open_monitor("sigmadut");
9756 if (s < 0) {
9757 send_resp(dut, conn, SIGMA_ERROR,
9758 "errorCode,Failed to open monitor socket");
9759 return 0;
9760 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009761
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309762 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
9763 if (res < 0) {
9764 send_resp(dut, conn, SIGMA_ERROR,
9765 "errorCode,Failed to inject frame");
9766 close(s);
9767 return 0;
9768 }
9769 if (res < pos - buf) {
9770 send_resp(dut, conn, SIGMA_ERROR,
9771 "errorCode,Only partial frame sent");
9772 close(s);
9773 return 0;
9774 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009775
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309776 close(s);
9777 } else {
9778#ifdef NL80211_SUPPORT
9779 int freq;
9780 char freq_str[10];
9781
9782 if (get_wpa_status(get_station_ifname(dut), "freq",
9783 freq_str, sizeof(freq_str)) < 0) {
9784 send_resp(dut, conn, SIGMA_ERROR,
9785 "errorCode,Could not get current operating frequency");
9786 return 0;
9787 }
9788 freq = atoi(freq_str);
9789
9790 if (nl80211_send_frame_cmd(dut, intf, buf, pos - buf, freq)) {
9791 send_resp(dut, conn, SIGMA_ERROR,
9792 "errorCode,Failed to inject frame");
9793 return 0;
9794 }
9795#else /* NL80211_SUPPORT */
9796 send_resp(dut, conn, SIGMA_ERROR,
9797 "errorCode,Failed to inject frame (no NL80211_SUPPORT)");
9798 return 0;
9799#endif /* NL80211_SUPPORT */
9800 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009801
9802 return 1;
9803#else /* __linux__ */
9804 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
9805 "yet supported");
9806 return 0;
9807#endif /* __linux__ */
9808}
9809
9810
9811static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
9812 struct sigma_conn *conn,
9813 struct sigma_cmd *cmd)
9814{
9815 const char *intf = get_param(cmd, "Interface");
9816 const char *sta, *val;
9817 unsigned char addr[ETH_ALEN];
9818 char buf[100];
9819
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +03009820 if (!intf)
9821 return -1;
9822
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009823 sta = get_param(cmd, "peer");
9824 if (sta == NULL)
9825 sta = get_param(cmd, "station");
9826 if (sta == NULL) {
9827 send_resp(dut, conn, SIGMA_ERROR,
9828 "ErrorCode,Missing peer address");
9829 return 0;
9830 }
9831 if (hwaddr_aton(sta, addr) < 0) {
9832 send_resp(dut, conn, SIGMA_ERROR,
9833 "ErrorCode,Invalid peer address");
9834 return 0;
9835 }
9836
9837 val = get_param(cmd, "type");
9838 if (val == NULL)
9839 return -1;
9840
9841 if (strcasecmp(val, "DISCOVERY") == 0) {
9842 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
9843 if (wpa_command(intf, buf) < 0) {
9844 send_resp(dut, conn, SIGMA_ERROR,
9845 "ErrorCode,Failed to send TDLS discovery");
9846 return 0;
9847 }
9848 return 1;
9849 }
9850
9851 if (strcasecmp(val, "SETUP") == 0) {
9852 int status = 0, timeout = 0;
9853
9854 val = get_param(cmd, "Status");
9855 if (val)
9856 status = atoi(val);
9857
9858 val = get_param(cmd, "Timeout");
9859 if (val)
9860 timeout = atoi(val);
9861
9862 if (status != 0 && status != 37) {
9863 send_resp(dut, conn, SIGMA_ERROR,
9864 "ErrorCode,Unsupported status value");
9865 return 0;
9866 }
9867
9868 if (timeout != 0 && timeout != 301) {
9869 send_resp(dut, conn, SIGMA_ERROR,
9870 "ErrorCode,Unsupported timeout value");
9871 return 0;
9872 }
9873
9874 if (status && timeout) {
9875 send_resp(dut, conn, SIGMA_ERROR,
9876 "ErrorCode,Unsupported timeout+status "
9877 "combination");
9878 return 0;
9879 }
9880
9881 if (status == 37 &&
9882 wpa_command(intf, "SET tdls_testing 0x200")) {
9883 send_resp(dut, conn, SIGMA_ERROR,
9884 "ErrorCode,Failed to enable "
9885 "decline setup response test mode");
9886 return 0;
9887 }
9888
9889 if (timeout == 301) {
9890 int res;
9891 if (dut->no_tpk_expiration)
9892 res = wpa_command(intf,
9893 "SET tdls_testing 0x108");
9894 else
9895 res = wpa_command(intf,
9896 "SET tdls_testing 0x8");
9897 if (res) {
9898 send_resp(dut, conn, SIGMA_ERROR,
9899 "ErrorCode,Failed to set short TPK "
9900 "lifetime");
9901 return 0;
9902 }
9903 }
9904
9905 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
9906 if (wpa_command(intf, buf) < 0) {
9907 send_resp(dut, conn, SIGMA_ERROR,
9908 "ErrorCode,Failed to send TDLS setup");
9909 return 0;
9910 }
9911 return 1;
9912 }
9913
9914 if (strcasecmp(val, "TEARDOWN") == 0) {
9915 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
9916 if (wpa_command(intf, buf) < 0) {
9917 send_resp(dut, conn, SIGMA_ERROR,
9918 "ErrorCode,Failed to send TDLS teardown");
9919 return 0;
9920 }
9921 return 1;
9922 }
9923
9924 send_resp(dut, conn, SIGMA_ERROR,
9925 "ErrorCode,Unsupported TDLS frame");
9926 return 0;
9927}
9928
9929
9930static int sta_ap_known(const char *ifname, const char *bssid)
9931{
9932 char buf[4096];
9933
Jouni Malinendd32f192018-09-15 02:55:19 +03009934 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009935 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
9936 return 0;
9937 if (strncmp(buf, "id=", 3) != 0)
9938 return 0;
9939 return 1;
9940}
9941
9942
9943static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
9944 const char *bssid)
9945{
9946 int res;
9947 struct wpa_ctrl *ctrl;
9948 char buf[256];
9949
9950 if (sta_ap_known(ifname, bssid))
9951 return 0;
9952 sigma_dut_print(dut, DUT_MSG_DEBUG,
9953 "AP not in BSS table - start scan");
9954
9955 ctrl = open_wpa_mon(ifname);
9956 if (ctrl == NULL) {
9957 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9958 "wpa_supplicant monitor connection");
9959 return -1;
9960 }
9961
9962 if (wpa_command(ifname, "SCAN") < 0) {
9963 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
9964 wpa_ctrl_detach(ctrl);
9965 wpa_ctrl_close(ctrl);
9966 return -1;
9967 }
9968
9969 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
9970 buf, sizeof(buf));
9971
9972 wpa_ctrl_detach(ctrl);
9973 wpa_ctrl_close(ctrl);
9974
9975 if (res < 0) {
9976 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
9977 return -1;
9978 }
9979
9980 if (sta_ap_known(ifname, bssid))
9981 return 0;
9982 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
9983 return -1;
9984}
9985
9986
9987static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
9988 struct sigma_conn *conn,
9989 struct sigma_cmd *cmd,
9990 const char *intf)
9991{
9992 char buf[200];
9993
9994 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
9995 if (system(buf) != 0) {
9996 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
9997 "ndsend");
9998 return 0;
9999 }
10000
10001 return 1;
10002}
10003
10004
10005static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
10006 struct sigma_conn *conn,
10007 struct sigma_cmd *cmd,
10008 const char *intf)
10009{
10010 char buf[200];
10011 const char *ip = get_param(cmd, "SenderIP");
10012
Peng Xu26b356d2017-10-04 17:58:16 -070010013 if (!ip)
10014 return 0;
10015
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010016 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
10017 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10018 if (system(buf) == 0) {
10019 sigma_dut_print(dut, DUT_MSG_INFO,
10020 "Neighbor Solicitation got a response "
10021 "for %s@%s", ip, intf);
10022 }
10023
10024 return 1;
10025}
10026
10027
10028static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
10029 struct sigma_conn *conn,
10030 struct sigma_cmd *cmd,
10031 const char *ifname)
10032{
10033 char buf[200];
10034 const char *ip = get_param(cmd, "SenderIP");
10035
10036 if (ip == NULL) {
10037 send_resp(dut, conn, SIGMA_ERROR,
10038 "ErrorCode,Missing SenderIP parameter");
10039 return 0;
10040 }
10041 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
10042 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10043 if (system(buf) != 0) {
10044 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
10045 "for %s@%s", ip, ifname);
10046 }
10047
10048 return 1;
10049}
10050
10051
10052static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
10053 struct sigma_conn *conn,
10054 struct sigma_cmd *cmd,
10055 const char *ifname)
10056{
10057 char buf[200];
10058 char ip[16];
10059 int s;
Peng Xub3756882017-10-04 14:39:09 -070010060 struct ifreq ifr;
10061 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010062
10063 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070010064 if (s < 0) {
10065 perror("socket");
10066 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010067 }
10068
Peng Xub3756882017-10-04 14:39:09 -070010069 memset(&ifr, 0, sizeof(ifr));
10070 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
10071 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
10072 sigma_dut_print(dut, DUT_MSG_INFO,
10073 "Failed to get %s IP address: %s",
10074 ifname, strerror(errno));
10075 close(s);
10076 return -1;
10077 }
10078 close(s);
10079
10080 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
10081 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
10082
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010083 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
10084 ip);
10085 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10086 if (system(buf) != 0) {
10087 }
10088
10089 return 1;
10090}
10091
10092
10093static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
10094 struct sigma_conn *conn,
10095 struct sigma_cmd *cmd,
10096 const char *ifname)
10097{
10098 char buf[200], addr[20];
10099 char dst[ETH_ALEN], src[ETH_ALEN];
10100 short ethtype = htons(ETH_P_ARP);
10101 char *pos;
10102 int s, res;
10103 const char *val;
10104 struct sockaddr_in taddr;
10105
10106 val = get_param(cmd, "dest");
10107 if (val)
10108 hwaddr_aton(val, (unsigned char *) dst);
10109
10110 val = get_param(cmd, "DestIP");
10111 if (val)
10112 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070010113 else
10114 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010115
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010116 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010117 sizeof(addr)) < 0)
10118 return -2;
10119 hwaddr_aton(addr, (unsigned char *) src);
10120
10121 pos = buf;
10122 *pos++ = 0x00;
10123 *pos++ = 0x01;
10124 *pos++ = 0x08;
10125 *pos++ = 0x00;
10126 *pos++ = 0x06;
10127 *pos++ = 0x04;
10128 *pos++ = 0x00;
10129 *pos++ = 0x02;
10130 memcpy(pos, src, ETH_ALEN);
10131 pos += ETH_ALEN;
10132 memcpy(pos, &taddr.sin_addr, 4);
10133 pos += 4;
10134 memcpy(pos, dst, ETH_ALEN);
10135 pos += ETH_ALEN;
10136 memcpy(pos, &taddr.sin_addr, 4);
10137 pos += 4;
10138
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010139 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010140 if (s < 0) {
10141 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
10142 "monitor socket");
10143 return 0;
10144 }
10145
10146 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
10147 if (res < 0) {
10148 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
10149 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053010150 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010151 return 0;
10152 }
10153
10154 close(s);
10155
10156 return 1;
10157}
10158
10159
10160static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
10161 struct sigma_conn *conn,
10162 struct sigma_cmd *cmd,
10163 const char *intf, const char *dest)
10164{
10165 char buf[100];
10166
10167 if (if_nametoindex("sigmadut") == 0) {
10168 snprintf(buf, sizeof(buf),
10169 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010170 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010171 if (system(buf) != 0 ||
10172 if_nametoindex("sigmadut") == 0) {
10173 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10174 "monitor interface with '%s'", buf);
10175 return -2;
10176 }
10177 }
10178
10179 if (system("ifconfig sigmadut up") != 0) {
10180 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10181 "monitor interface up");
10182 return -2;
10183 }
10184
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010185 return sta_inject_frame(dut, conn, intf, DLS_REQ, UNPROTECTED, dest, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010186}
10187
10188
10189static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10190 struct sigma_conn *conn,
10191 struct sigma_cmd *cmd)
10192{
10193 const char *intf = get_param(cmd, "Interface");
10194 const char *dest = get_param(cmd, "Dest");
10195 const char *type = get_param(cmd, "FrameName");
10196 const char *val;
10197 char buf[200], *pos, *end;
10198 int count, count2;
10199
10200 if (type == NULL)
10201 type = get_param(cmd, "Type");
10202
10203 if (intf == NULL || dest == NULL || type == NULL)
10204 return -1;
10205
10206 if (strcasecmp(type, "NeighAdv") == 0)
10207 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10208
10209 if (strcasecmp(type, "NeighSolicitReq") == 0)
10210 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10211
10212 if (strcasecmp(type, "ARPProbe") == 0)
10213 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10214
10215 if (strcasecmp(type, "ARPAnnounce") == 0)
10216 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10217
10218 if (strcasecmp(type, "ARPReply") == 0)
10219 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10220
10221 if (strcasecmp(type, "DLS-request") == 0 ||
10222 strcasecmp(type, "DLSrequest") == 0)
10223 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10224 dest);
10225
10226 if (strcasecmp(type, "ANQPQuery") != 0 &&
10227 strcasecmp(type, "Query") != 0) {
10228 send_resp(dut, conn, SIGMA_ERROR,
10229 "ErrorCode,Unsupported HS 2.0 send frame type");
10230 return 0;
10231 }
10232
10233 if (sta_scan_ap(dut, intf, dest) < 0) {
10234 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10235 "the requested AP");
10236 return 0;
10237 }
10238
10239 pos = buf;
10240 end = buf + sizeof(buf);
10241 count = 0;
10242 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10243
10244 val = get_param(cmd, "ANQP_CAP_LIST");
10245 if (val && atoi(val)) {
10246 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10247 count++;
10248 }
10249
10250 val = get_param(cmd, "VENUE_NAME");
10251 if (val && atoi(val)) {
10252 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10253 count++;
10254 }
10255
10256 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10257 if (val && atoi(val)) {
10258 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10259 count++;
10260 }
10261
10262 val = get_param(cmd, "ROAMING_CONS");
10263 if (val && atoi(val)) {
10264 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10265 count++;
10266 }
10267
10268 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10269 if (val && atoi(val)) {
10270 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10271 count++;
10272 }
10273
10274 val = get_param(cmd, "NAI_REALM_LIST");
10275 if (val && atoi(val)) {
10276 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10277 count++;
10278 }
10279
10280 val = get_param(cmd, "3GPP_INFO");
10281 if (val && atoi(val)) {
10282 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10283 count++;
10284 }
10285
10286 val = get_param(cmd, "DOMAIN_LIST");
10287 if (val && atoi(val)) {
10288 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10289 count++;
10290 }
10291
Jouni Malinen34cf9532018-04-29 19:26:33 +030010292 val = get_param(cmd, "Venue_URL");
10293 if (val && atoi(val)) {
10294 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10295 count++;
10296 }
10297
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010298 val = get_param(cmd, "Advice_Of_Charge");
10299 if (val && atoi(val)) {
10300 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10301 count++;
10302 }
10303
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010304 if (count && wpa_command(intf, buf)) {
10305 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10306 return 0;
10307 }
10308
10309 pos = buf;
10310 end = buf + sizeof(buf);
10311 count2 = 0;
10312 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
10313
10314 val = get_param(cmd, "HS_CAP_LIST");
10315 if (val && atoi(val)) {
10316 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
10317 count2++;
10318 }
10319
10320 val = get_param(cmd, "OPER_NAME");
10321 if (val && atoi(val)) {
10322 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
10323 count2++;
10324 }
10325
10326 val = get_param(cmd, "WAN_METRICS");
10327 if (!val)
10328 val = get_param(cmd, "WAN_MAT");
10329 if (!val)
10330 val = get_param(cmd, "WAN_MET");
10331 if (val && atoi(val)) {
10332 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10333 count2++;
10334 }
10335
10336 val = get_param(cmd, "CONNECTION_CAPABILITY");
10337 if (val && atoi(val)) {
10338 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10339 count2++;
10340 }
10341
10342 val = get_param(cmd, "OP_CLASS");
10343 if (val && atoi(val)) {
10344 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10345 count2++;
10346 }
10347
10348 val = get_param(cmd, "OSU_PROVIDER_LIST");
10349 if (val && atoi(val)) {
10350 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10351 count2++;
10352 }
10353
Jouni Malinenf67afec2018-04-29 19:24:58 +030010354 val = get_param(cmd, "OPER_ICON_METADATA");
10355 if (!val)
10356 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10357 if (val && atoi(val)) {
10358 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10359 count2++;
10360 }
10361
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010362 if (count && count2) {
10363 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10364 "second query");
10365 sleep(1);
10366 }
10367
10368 if (count2 && wpa_command(intf, buf)) {
10369 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10370 "failed");
10371 return 0;
10372 }
10373
10374 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10375 if (val) {
10376 if (count || count2) {
10377 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10378 "sending out second query");
10379 sleep(1);
10380 }
10381
10382 if (strcmp(val, "1") == 0)
10383 val = "mail.example.com";
10384 snprintf(buf, end - pos,
10385 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10386 dest, val);
10387 if (wpa_command(intf, buf)) {
10388 send_resp(dut, conn, SIGMA_ERROR,
10389 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10390 "failed");
10391 return 0;
10392 }
10393 }
10394
10395 val = get_param(cmd, "ICON_REQUEST");
10396 if (val) {
10397 if (count || count2) {
10398 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10399 "sending out second query");
10400 sleep(1);
10401 }
10402
10403 snprintf(buf, end - pos,
10404 "HS20_ICON_REQUEST %s %s", dest, val);
10405 if (wpa_command(intf, buf)) {
10406 send_resp(dut, conn, SIGMA_ERROR,
10407 "ErrorCode,HS20_ICON_REQUEST failed");
10408 return 0;
10409 }
10410 }
10411
10412 return 1;
10413}
10414
10415
10416static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10417 struct sigma_conn *conn,
10418 struct sigma_cmd *cmd)
10419{
10420 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010421 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010422 int chwidth, nss;
10423
10424 val = get_param(cmd, "framename");
10425 if (!val)
10426 return -1;
10427 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10428
10429 /* Command sequence to generate Op mode notification */
10430 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010431 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010432
10433 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010434 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010435
10436 /* Extract Channel width */
10437 val = get_param(cmd, "Channel_width");
10438 if (val) {
10439 switch (atoi(val)) {
10440 case 20:
10441 chwidth = 0;
10442 break;
10443 case 40:
10444 chwidth = 1;
10445 break;
10446 case 80:
10447 chwidth = 2;
10448 break;
10449 case 160:
10450 chwidth = 3;
10451 break;
10452 default:
10453 chwidth = 2;
10454 break;
10455 }
10456
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010457 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010458 }
10459
10460 /* Extract NSS */
10461 val = get_param(cmd, "NSS");
10462 if (val) {
10463 switch (atoi(val)) {
10464 case 1:
10465 nss = 1;
10466 break;
10467 case 2:
10468 nss = 3;
10469 break;
10470 case 3:
10471 nss = 7;
10472 break;
10473 default:
10474 /* We do not support NSS > 3 */
10475 nss = 3;
10476 break;
10477 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010478 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010479 }
10480
10481 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010482 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010483 }
10484
10485 return 1;
10486}
10487
10488
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010489static int wcn_sta_set_pmf_config(struct sigma_dut *dut, const char *intf,
10490 enum send_frame_protection protected)
10491{
10492#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053010493 return wcn_wifi_test_config_set_u8(
10494 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PMF_PROTECTION,
10495 protected);
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010496#else /* NL80211_SUPPORT */
10497 sigma_dut_print(dut, DUT_MSG_ERROR,
10498 "PMF config cannot be set without NL80211_SUPPORT defined");
10499 return -1;
10500#endif /* NL80211_SUPPORT */
10501}
10502
10503
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010504static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
10505 struct sigma_conn *conn,
10506 struct sigma_cmd *cmd)
10507{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010508 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010509 case DRIVER_ATHEROS:
10510 return ath_sta_send_frame_vht(dut, conn, cmd);
10511 default:
10512 send_resp(dut, conn, SIGMA_ERROR,
10513 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
10514 return 0;
10515 }
10516}
10517
10518
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010519static int wcn_sta_send_disassoc(struct sigma_dut *dut, const char *intf)
10520{
10521#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053010522 return wcn_wifi_test_config_set_flag(
10523 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISASSOC_TX);
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010524#else /* NL80211_SUPPORT */
10525 sigma_dut_print(dut, DUT_MSG_ERROR,
10526 "Disassoc Tx cannot be done without NL80211_SUPPORT defined");
10527 return -1;
10528#endif /* NL80211_SUPPORT */
10529}
10530
10531
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010532static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
10533 struct sigma_cmd *cmd)
10534{
10535 const char *val;
10536 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010537 enum send_frame_protection protected;
10538 const char *pmf;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010539
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010540 if (!intf)
10541 return -1;
10542
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010543 val = get_param(cmd, "framename");
10544 if (!val)
10545 return -1;
10546 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10547
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010548 pmf = get_param(cmd, "PMFProtected");
10549 if (!pmf)
10550 pmf = get_param(cmd, "Protected");
10551 if (pmf) {
10552 if (strcasecmp(pmf, "Correct-key") == 0 ||
10553 strcasecmp(pmf, "CorrectKey") == 0) {
10554 protected = CORRECT_KEY;
10555 } else if (strcasecmp(pmf, "IncorrectKey") == 0) {
10556 protected = INCORRECT_KEY;
10557 } else if (strcasecmp(pmf, "Unprotected") == 0) {
10558 protected = UNPROTECTED;
10559 } else {
10560 send_resp(dut, conn, SIGMA_ERROR,
10561 "errorCode,Unsupported PMFProtected");
10562 return STATUS_SENT_ERROR;
10563 }
10564 sigma_dut_print(dut, DUT_MSG_DEBUG, "Config PMF protection %d",
10565 protected);
10566 wcn_sta_set_pmf_config(dut, intf, protected);
10567 }
10568
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010569 /* Command sequence to generate Op mode notification */
10570 if (val && strcasecmp(val, "action") == 0) {
10571 val = get_param(cmd, "PPDUTxType");
10572 if (val && strcasecmp(val, "TB") == 0) {
10573 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
10574 sigma_dut_print(dut, DUT_MSG_ERROR,
10575 "failed to send TB PPDU Tx cfg");
10576 send_resp(dut, conn, SIGMA_ERROR,
10577 "ErrorCode,set TB PPDU Tx cfg failed");
10578 return 0;
10579 }
10580 return 1;
10581 }
10582
10583 sigma_dut_print(dut, DUT_MSG_ERROR,
10584 "Action Tx type is not defined");
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010585
10586 return SUCCESS_SEND_STATUS;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010587 }
10588
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010589 if (strcasecmp(val, "disassoc") == 0)
10590 wcn_sta_send_disassoc(dut, intf);
10591
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010592 return 1;
10593}
10594
10595
10596static int cmd_sta_send_frame_he(struct sigma_dut *dut,
10597 struct sigma_conn *conn,
10598 struct sigma_cmd *cmd)
10599{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010600 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010601 case DRIVER_WCN:
10602 return wcn_sta_send_frame_he(dut, conn, cmd);
10603 default:
10604 send_resp(dut, conn, SIGMA_ERROR,
10605 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
10606 return 0;
10607 }
10608}
10609
10610
Lior David0fe101e2017-03-09 16:09:50 +020010611#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010612
10613static int
10614wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
10615 const char *frame_name, const char *dest_mac)
10616{
10617 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
10618 const char *ssid = get_param(cmd, "ssid");
10619 const char *countstr = get_param(cmd, "count");
10620 const char *channelstr = get_param(cmd, "channel");
10621 const char *group_id = get_param(cmd, "groupid");
10622 const char *client_id = get_param(cmd, "clientmac");
10623 int count, channel, freq, i;
10624 const char *fname;
10625 char frame[1024], src_mac[20], group_id_attr[25],
10626 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
10627 const char *group_ssid;
10628 const int group_ssid_prefix_len = 9;
10629 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
10630 size_t framelen = sizeof(frame);
10631 struct template_frame_tag tags[2];
10632 size_t tags_total = ARRAY_SIZE(tags);
10633 int tag_index, len, dst_len;
10634
10635 if (!countstr || !channelstr) {
10636 sigma_dut_print(dut, DUT_MSG_ERROR,
10637 "Missing argument: count, channel");
10638 return -1;
10639 }
10640 if (isprobereq && !ssid) {
10641 sigma_dut_print(dut, DUT_MSG_ERROR,
10642 "Missing argument: ssid");
10643 return -1;
10644 }
10645 if (!isprobereq && (!group_id || !client_id)) {
10646 sigma_dut_print(dut, DUT_MSG_ERROR,
10647 "Missing argument: group_id, client_id");
10648 return -1;
10649 }
10650
10651 count = atoi(countstr);
10652 channel = atoi(channelstr);
10653 freq = channel_to_freq(dut, channel);
10654
10655 if (!freq) {
10656 sigma_dut_print(dut, DUT_MSG_ERROR,
10657 "invalid channel: %s", channelstr);
10658 return -1;
10659 }
10660
10661 if (isprobereq) {
10662 if (strcasecmp(ssid, "wildcard") == 0) {
10663 fname = "probe_req_wildcard.txt";
10664 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
10665 fname = "probe_req_P2P_Wildcard.txt";
10666 } else {
10667 sigma_dut_print(dut, DUT_MSG_ERROR,
10668 "invalid probe request type");
10669 return -1;
10670 }
10671 } else {
10672 fname = "P2P_device_discovery_req.txt";
10673 }
10674
10675 if (parse_template_frame_file(dut, fname, frame, &framelen,
10676 tags, &tags_total)) {
10677 sigma_dut_print(dut, DUT_MSG_ERROR,
10678 "invalid frame template: %s", fname);
10679 return -1;
10680 }
10681
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010682 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010683 src_mac, sizeof(src_mac)) < 0 ||
10684 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
10685 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
10686 return -1;
10687 /* Use wildcard BSSID, since we are in PBSS */
10688 memset(&hdr->addr3, 0xFF, ETH_ALEN);
10689
10690 if (!isprobereq) {
10691 tag_index = find_template_frame_tag(tags, tags_total, 1);
10692 if (tag_index < 0) {
10693 sigma_dut_print(dut, DUT_MSG_ERROR,
10694 "can't find device id attribute");
10695 return -1;
10696 }
10697 if (parse_mac_address(dut, client_id,
10698 (unsigned char *) client_mac)) {
10699 sigma_dut_print(dut, DUT_MSG_ERROR,
10700 "invalid client_id: %s", client_id);
10701 return -1;
10702 }
10703 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10704 framelen - tags[tag_index].offset,
10705 IEEE80211_P2P_ATTR_DEVICE_ID,
10706 client_mac, ETH_ALEN)) {
10707 sigma_dut_print(dut, DUT_MSG_ERROR,
10708 "fail to replace device id attribute");
10709 return -1;
10710 }
10711
10712 /*
10713 * group_id arg contains device MAC address followed by
10714 * space and SSID (DIRECT-somessid).
10715 * group id attribute contains device address (6 bytes)
10716 * followed by SSID prefix DIRECT-XX (9 bytes)
10717 */
10718 if (strlen(group_id) < sizeof(device_macstr)) {
10719 sigma_dut_print(dut, DUT_MSG_ERROR,
10720 "group_id arg too short");
10721 return -1;
10722 }
10723 memcpy(device_macstr, group_id, sizeof(device_macstr));
10724 device_macstr[sizeof(device_macstr) - 1] = '\0';
10725 if (parse_mac_address(dut, device_macstr,
10726 (unsigned char *) group_id_attr)) {
10727 sigma_dut_print(dut, DUT_MSG_ERROR,
10728 "fail to parse device address from group_id");
10729 return -1;
10730 }
10731 group_ssid = strchr(group_id, ' ');
10732 if (!group_ssid) {
10733 sigma_dut_print(dut, DUT_MSG_ERROR,
10734 "invalid group_id arg, no ssid");
10735 return -1;
10736 }
10737 group_ssid++;
10738 len = strlen(group_ssid);
10739 if (len < group_ssid_prefix_len) {
10740 sigma_dut_print(dut, DUT_MSG_ERROR,
10741 "group_id SSID too short");
10742 return -1;
10743 }
10744 dst_len = sizeof(group_id_attr) - ETH_ALEN;
10745 if (len > dst_len) {
10746 sigma_dut_print(dut, DUT_MSG_ERROR,
10747 "group_id SSID (%s) too long",
10748 group_ssid);
10749 return -1;
10750 }
10751
10752 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
10753 tag_index = find_template_frame_tag(tags, tags_total, 2);
10754 if (tag_index < 0) {
10755 sigma_dut_print(dut, DUT_MSG_ERROR,
10756 "can't find group id attribute");
10757 return -1;
10758 }
10759 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10760 framelen - tags[tag_index].offset,
10761 IEEE80211_P2P_ATTR_GROUP_ID,
10762 group_id_attr,
10763 sizeof(group_id_attr))) {
10764 sigma_dut_print(dut, DUT_MSG_ERROR,
10765 "fail to replace group id attribute");
10766 return -1;
10767 }
10768 }
10769
10770 for (i = 0; i < count; i++) {
10771 if (wil6210_transmit_frame(dut, freq,
10772 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
10773 frame, framelen)) {
10774 sigma_dut_print(dut, DUT_MSG_ERROR,
10775 "fail to transmit probe request frame");
10776 return -1;
10777 }
10778 }
10779
10780 return 0;
10781}
10782
10783
Lior David0fe101e2017-03-09 16:09:50 +020010784int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10785 struct sigma_cmd *cmd)
10786{
10787 const char *frame_name = get_param(cmd, "framename");
10788 const char *mac = get_param(cmd, "dest_mac");
10789
10790 if (!frame_name || !mac) {
10791 sigma_dut_print(dut, DUT_MSG_ERROR,
10792 "framename and dest_mac must be provided");
10793 return -1;
10794 }
10795
10796 if (strcasecmp(frame_name, "brp") == 0) {
10797 const char *l_rx = get_param(cmd, "L-RX");
10798 int l_rx_i;
10799
10800 if (!l_rx) {
10801 sigma_dut_print(dut, DUT_MSG_ERROR,
10802 "L-RX must be provided");
10803 return -1;
10804 }
10805 l_rx_i = atoi(l_rx);
10806
10807 sigma_dut_print(dut, DUT_MSG_INFO,
10808 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
10809 mac, l_rx);
10810 if (l_rx_i != 16) {
10811 sigma_dut_print(dut, DUT_MSG_ERROR,
10812 "unsupported L-RX: %s", l_rx);
10813 return -1;
10814 }
10815
10816 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
10817 return -1;
10818 } else if (strcasecmp(frame_name, "ssw") == 0) {
10819 sigma_dut_print(dut, DUT_MSG_INFO,
10820 "dev_send_frame: SLS, dest_mac %s", mac);
10821 if (wil6210_send_sls(dut, mac))
10822 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010823 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
10824 (strcasecmp(frame_name, "devdiscreq") == 0)) {
10825 sigma_dut_print(dut, DUT_MSG_INFO,
10826 "dev_send_frame: %s, dest_mac %s", frame_name,
10827 mac);
10828 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
10829 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020010830 } else {
10831 sigma_dut_print(dut, DUT_MSG_ERROR,
10832 "unsupported frame type: %s", frame_name);
10833 return -1;
10834 }
10835
10836 return 1;
10837}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010838
Lior David0fe101e2017-03-09 16:09:50 +020010839#endif /* __linux__ */
10840
10841
10842static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
10843 struct sigma_conn *conn,
10844 struct sigma_cmd *cmd)
10845{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010846 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020010847#ifdef __linux__
10848 case DRIVER_WIL6210:
10849 return wil6210_send_frame_60g(dut, conn, cmd);
10850#endif /* __linux__ */
10851 default:
10852 send_resp(dut, conn, SIGMA_ERROR,
10853 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
10854 return 0;
10855 }
10856}
10857
10858
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010859static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
10860 const char *intf, struct sigma_cmd *cmd)
10861{
10862 const char *val, *addr;
10863 char buf[100];
10864
10865 addr = get_param(cmd, "DestMac");
10866 if (!addr) {
10867 send_resp(dut, conn, SIGMA_INVALID,
10868 "ErrorCode,AP MAC address is missing");
10869 return 0;
10870 }
10871
10872 val = get_param(cmd, "ANQPQuery_ID");
10873 if (!val) {
10874 send_resp(dut, conn, SIGMA_INVALID,
10875 "ErrorCode,Missing ANQPQuery_ID");
10876 return 0;
10877 }
10878
10879 if (strcasecmp(val, "NeighborReportReq") == 0) {
10880 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
10881 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
10882 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
10883 } else {
10884 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
10885 val);
10886 send_resp(dut, conn, SIGMA_INVALID,
10887 "ErrorCode,Invalid ANQPQuery_ID");
10888 return 0;
10889 }
10890
Ashwini Patild174f2c2017-04-13 16:49:46 +053010891 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
10892 * (Address3 = Wildcard BSSID when sent to not-associated AP;
10893 * if associated, AP BSSID).
10894 */
10895 if (wpa_command(intf, "SET gas_address3 1") < 0) {
10896 send_resp(dut, conn, SIGMA_ERROR,
10897 "ErrorCode,Failed to set gas_address3");
10898 return 0;
10899 }
10900
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010901 if (wpa_command(intf, buf) < 0) {
10902 send_resp(dut, conn, SIGMA_ERROR,
10903 "ErrorCode,Failed to send ANQP query");
10904 return 0;
10905 }
10906
10907 return 1;
10908}
10909
10910
10911static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
10912 struct sigma_conn *conn,
10913 const char *intf,
10914 struct sigma_cmd *cmd)
10915{
10916 const char *val = get_param(cmd, "FrameName");
10917
10918 if (val && strcasecmp(val, "ANQPQuery") == 0)
10919 return mbo_send_anqp_query(dut, conn, intf, cmd);
10920
10921 return 2;
10922}
10923
10924
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053010925static enum sigma_cmd_result cmd_sta_send_frame_wpa3(struct sigma_dut *dut,
10926 struct sigma_conn *conn,
10927 const char *intf,
10928 struct sigma_cmd *cmd)
10929{
10930 const char *val = get_param(cmd, "framename");
10931
10932 if (!val)
10933 return INVALID_SEND_STATUS;
10934
10935 if (strcasecmp(val, "SAQueryReq") == 0) {
10936 val = get_param(cmd, "OCIChannel");
10937
10938 if (!val) {
10939 send_resp(dut, conn, SIGMA_ERROR,
10940 "errorCode,OCIChannel not present");
10941 return STATUS_SENT_ERROR;
10942 }
10943
10944 dut->saquery_oci_freq = channel_to_freq(dut, atoi(val));
10945 if (!dut->saquery_oci_freq) {
10946 send_resp(dut, conn, SIGMA_ERROR,
10947 "errorCode,Invalid OCIChannel number");
10948 return STATUS_SENT_ERROR;
10949 }
10950
10951 return sta_inject_frame(dut, conn, intf, SAQUERY, CORRECT_KEY,
10952 NULL, 0);
10953 }
10954
10955 if (strcasecmp(val, "reassocreq") == 0)
10956 return sta_inject_frame(dut, conn, intf, REASSOCREQ,
10957 CORRECT_KEY, NULL, 0);
10958
Veerendranath9f81dfb2020-08-10 01:21:29 -070010959 if (strcasecmp(val, "ANQPQuery") == 0) {
10960 char buf[50];
10961 const char *dest = get_param(cmd, "DestMac");
10962 const char *chan = get_param(cmd, "channel");
10963 int len, freq;
10964
10965 freq = chan ? channel_to_freq(dut, atoi(chan)) : 0;
10966 if (!dest || !freq)
10967 return INVALID_SEND_STATUS;
10968
10969 len = snprintf(buf, sizeof(buf), "ANQP_GET %s freq=%d 257",
10970 dest, freq);
10971 if (len < 0 || len >= sizeof(buf)) {
10972 sigma_dut_print(dut, DUT_MSG_ERROR,
10973 "Failed to allocate buf");
10974 return ERROR_SEND_STATUS;
10975 }
10976
10977 if (wpa_command(intf, buf) != 0) {
10978 send_resp(dut, conn, SIGMA_ERROR,
10979 "ErrorCode,Failed to send ANQP Query frame");
10980 return STATUS_SENT_ERROR;
10981 }
10982
10983 sigma_dut_print(dut, DUT_MSG_DEBUG,
10984 "ANQP Query sent: %s", buf);
10985
10986 return SUCCESS_SEND_STATUS;
10987 }
10988
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053010989 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported framename");
10990 return STATUS_SENT_ERROR;
10991}
10992
10993
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053010994static enum sigma_cmd_result
10995cmd_sta_send_frame_mscs(struct sigma_dut *dut, struct sigma_conn *conn,
10996 const char *intf, struct sigma_cmd *cmd)
10997{
10998 char buf[128], *pos;
10999 const char *val, *classifier_type = "04", *type;
11000 int len, rem_len;
11001 u8 up_bitmap;
11002
11003 val = get_param(cmd, "FrameName");
11004 type = get_param(cmd, "Request_Type");
11005 if (!val || !type || strcasecmp(val, "MSCSReq") != 0) {
11006 sigma_dut_print(dut, DUT_MSG_ERROR,
11007 "%s: frame name or type not valid", __func__);
11008 return INVALID_SEND_STATUS;
11009 }
11010
11011 rem_len = sizeof(buf);
11012 pos = buf;
11013 if (strcasecmp(type, "add") == 0) {
11014 len = snprintf(pos, rem_len, "MSCS add");
11015 } else if (strcasecmp(type, "update") == 0) {
11016 len = snprintf(pos, rem_len, "MSCS change");
11017 } else if (strcasecmp(type, "remove") == 0) {
11018 if (wpa_command(intf, "MSCS remove") != 0) {
11019 send_resp(dut, conn, SIGMA_ERROR,
11020 "ErrorCode,Failed to send MSCS frame req");
11021 return STATUS_SENT_ERROR;
11022 }
11023 return SUCCESS_SEND_STATUS;
11024 } else {
11025 sigma_dut_print(dut, DUT_MSG_ERROR,
11026 "%s: request type invalid", __func__);
11027 return INVALID_SEND_STATUS;
11028 }
11029
11030 if (len < 0 || len >= rem_len)
11031 goto fail;
11032
11033 pos += len;
11034 rem_len -= len;
11035
11036 val = get_param(cmd, "User_Priority_Bitmap");
11037 if (!val) {
11038 sigma_dut_print(dut, DUT_MSG_ERROR,
11039 "%s: user priority bitmap empty", __func__);
11040 return INVALID_SEND_STATUS;
11041 }
11042
11043 switch (atoi(val)) {
11044 case 0:
11045 up_bitmap = 0x00;
11046 break;
11047 case 1:
11048 up_bitmap = 0xF0;
11049 break;
11050 case 2:
11051 up_bitmap = 0xF6;
11052 break;
11053 default:
11054 sigma_dut_print(dut, DUT_MSG_ERROR,
11055 "%s: Unknown User_Priority_Bitmap value %d",
11056 __func__, atoi(val));
11057 return INVALID_SEND_STATUS;
11058 }
11059
11060 len = snprintf(pos, rem_len, " up_bitmap=%02x", up_bitmap);
11061 if (len < 0 || len >= rem_len)
11062 goto fail;
11063
11064 pos += len;
11065 rem_len -= len;
11066
11067 val = get_param(cmd, "User_Priority_Limit");
11068 if (!val) {
11069 sigma_dut_print(dut, DUT_MSG_ERROR,
11070 "%s: invalid user priority limit", __func__);
11071 return INVALID_SEND_STATUS;
11072 }
11073
11074 len = snprintf(pos, rem_len, " up_limit=%s", val);
11075 if (len < 0 || len >= rem_len)
11076 goto fail;
11077
11078 pos += len;
11079 rem_len -= len;
11080
11081 val = get_param(cmd, "Stream_Timeout");
11082 if (!val)
11083 val = get_param(cmd, "Stream_Timtout");
11084 if (!val) {
11085 sigma_dut_print(dut, DUT_MSG_ERROR,
11086 "%s: invalid stream timeout", __func__);
11087 return INVALID_SEND_STATUS;
11088 }
11089
11090 len = snprintf(pos, rem_len, " stream_timeout=%s", val);
11091 if (len < 0 || len >= rem_len)
11092 goto fail;
11093
11094 pos += len;
11095 rem_len -= len;
11096
11097 val = get_param(cmd, "TCLAS_Mask");
11098 if (!val) {
11099 sigma_dut_print(dut, DUT_MSG_ERROR,
11100 "%s: invalid tclas mask", __func__);
11101 return INVALID_SEND_STATUS;
11102 }
11103
11104 len = snprintf(pos, rem_len, " frame_classifier=%s%lx%032x",
11105 classifier_type, strtol(val, NULL, 2), 0);
11106 if (len < 0 || len >= rem_len)
11107 goto fail;
11108
11109 if (wpa_command(intf, buf) != 0) {
11110 send_resp(dut, conn, SIGMA_ERROR,
11111 "ErrorCode,Failed to send MSCS frame req");
11112 return STATUS_SENT_ERROR;
11113 }
11114
11115 sigma_dut_print(dut, DUT_MSG_DEBUG,
11116 "MSCS frame request sent: %s", buf);
11117
11118 return SUCCESS_SEND_STATUS;
11119fail:
11120 sigma_dut_print(dut, DUT_MSG_ERROR,
11121 "Failed to create MSCS frame req");
11122 return ERROR_SEND_STATUS;
11123}
11124
11125
Jouni Malinenf7222712019-06-13 01:50:21 +030011126enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
11127 struct sigma_conn *conn,
11128 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011129{
11130 const char *intf = get_param(cmd, "Interface");
11131 const char *val;
11132 enum send_frame_type frame;
11133 enum send_frame_protection protected;
11134 char buf[100];
11135 unsigned char addr[ETH_ALEN];
11136 int res;
11137
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011138 if (!intf)
11139 return -1;
11140
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011141 val = get_param(cmd, "program");
11142 if (val == NULL)
11143 val = get_param(cmd, "frame");
11144 if (val && strcasecmp(val, "TDLS") == 0)
11145 return cmd_sta_send_frame_tdls(dut, conn, cmd);
11146 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011147 strcasecmp(val, "HS2-R2") == 0 ||
11148 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011149 return cmd_sta_send_frame_hs2(dut, conn, cmd);
11150 if (val && strcasecmp(val, "VHT") == 0)
11151 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011152 if (val && strcasecmp(val, "HE") == 0)
11153 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070011154 if (val && strcasecmp(val, "LOC") == 0)
11155 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020011156 if (val && strcasecmp(val, "60GHz") == 0)
11157 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011158 if (val && strcasecmp(val, "MBO") == 0) {
11159 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
11160 if (res != 2)
11161 return res;
11162 }
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011163 if (val && strcasecmp(val, "WPA3") == 0)
11164 return cmd_sta_send_frame_wpa3(dut, conn, intf, cmd);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011165 if (val && strcasecmp(val, "QM") == 0)
11166 return cmd_sta_send_frame_mscs(dut, conn, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011167
11168 val = get_param(cmd, "TD_DISC");
11169 if (val) {
11170 if (hwaddr_aton(val, addr) < 0)
11171 return -1;
11172 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
11173 if (wpa_command(intf, buf) < 0) {
11174 send_resp(dut, conn, SIGMA_ERROR,
11175 "ErrorCode,Failed to send TDLS discovery");
11176 return 0;
11177 }
11178 return 1;
11179 }
11180
11181 val = get_param(cmd, "TD_Setup");
11182 if (val) {
11183 if (hwaddr_aton(val, addr) < 0)
11184 return -1;
11185 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
11186 if (wpa_command(intf, buf) < 0) {
11187 send_resp(dut, conn, SIGMA_ERROR,
11188 "ErrorCode,Failed to start TDLS setup");
11189 return 0;
11190 }
11191 return 1;
11192 }
11193
11194 val = get_param(cmd, "TD_TearDown");
11195 if (val) {
11196 if (hwaddr_aton(val, addr) < 0)
11197 return -1;
11198 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
11199 if (wpa_command(intf, buf) < 0) {
11200 send_resp(dut, conn, SIGMA_ERROR,
11201 "ErrorCode,Failed to tear down TDLS link");
11202 return 0;
11203 }
11204 return 1;
11205 }
11206
11207 val = get_param(cmd, "TD_ChannelSwitch");
11208 if (val) {
11209 /* TODO */
11210 send_resp(dut, conn, SIGMA_ERROR,
11211 "ErrorCode,TD_ChannelSwitch not yet supported");
11212 return 0;
11213 }
11214
11215 val = get_param(cmd, "TD_NF");
11216 if (val) {
11217 /* TODO */
11218 send_resp(dut, conn, SIGMA_ERROR,
11219 "ErrorCode,TD_NF not yet supported");
11220 return 0;
11221 }
11222
11223 val = get_param(cmd, "PMFFrameType");
11224 if (val == NULL)
11225 val = get_param(cmd, "FrameName");
11226 if (val == NULL)
11227 val = get_param(cmd, "Type");
11228 if (val == NULL)
11229 return -1;
11230 if (strcasecmp(val, "disassoc") == 0)
11231 frame = DISASSOC;
11232 else if (strcasecmp(val, "deauth") == 0)
11233 frame = DEAUTH;
11234 else if (strcasecmp(val, "saquery") == 0)
11235 frame = SAQUERY;
11236 else if (strcasecmp(val, "auth") == 0)
11237 frame = AUTH;
11238 else if (strcasecmp(val, "assocreq") == 0)
11239 frame = ASSOCREQ;
11240 else if (strcasecmp(val, "reassocreq") == 0)
11241 frame = REASSOCREQ;
11242 else if (strcasecmp(val, "neigreq") == 0) {
11243 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
11244
11245 val = get_param(cmd, "ssid");
11246 if (val == NULL)
11247 return -1;
11248
11249 res = send_neighbor_request(dut, intf, val);
11250 if (res) {
11251 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11252 "Failed to send neighbor report request");
11253 return 0;
11254 }
11255
11256 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053011257 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
11258 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011259 sigma_dut_print(dut, DUT_MSG_DEBUG,
11260 "Got Transition Management Query");
11261
Ashwini Patil5acd7382017-04-13 15:55:04 +053011262 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011263 if (res) {
11264 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11265 "Failed to send Transition Management Query");
11266 return 0;
11267 }
11268
11269 return 1;
11270 } else {
11271 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11272 "PMFFrameType");
11273 return 0;
11274 }
11275
11276 val = get_param(cmd, "PMFProtected");
11277 if (val == NULL)
11278 val = get_param(cmd, "Protected");
11279 if (val == NULL)
11280 return -1;
11281 if (strcasecmp(val, "Correct-key") == 0 ||
11282 strcasecmp(val, "CorrectKey") == 0)
11283 protected = CORRECT_KEY;
11284 else if (strcasecmp(val, "IncorrectKey") == 0)
11285 protected = INCORRECT_KEY;
11286 else if (strcasecmp(val, "Unprotected") == 0)
11287 protected = UNPROTECTED;
11288 else {
11289 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11290 "PMFProtected");
11291 return 0;
11292 }
11293
11294 if (protected != UNPROTECTED &&
11295 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
11296 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
11297 "PMFProtected for auth/assocreq/reassocreq");
11298 return 0;
11299 }
11300
11301 if (if_nametoindex("sigmadut") == 0) {
11302 snprintf(buf, sizeof(buf),
11303 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011304 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011305 if (system(buf) != 0 ||
11306 if_nametoindex("sigmadut") == 0) {
11307 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11308 "monitor interface with '%s'", buf);
11309 return -2;
11310 }
11311 }
11312
11313 if (system("ifconfig sigmadut up") != 0) {
11314 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11315 "monitor interface up");
11316 return -2;
11317 }
11318
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011319 return sta_inject_frame(dut, conn, intf, frame, protected, NULL, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011320}
11321
11322
11323static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
11324 struct sigma_conn *conn,
11325 struct sigma_cmd *cmd,
11326 const char *ifname)
11327{
11328 char buf[200];
11329 const char *val;
11330
11331 val = get_param(cmd, "ClearARP");
11332 if (val && atoi(val) == 1) {
11333 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
11334 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11335 if (system(buf) != 0) {
11336 send_resp(dut, conn, SIGMA_ERROR,
11337 "errorCode,Failed to clear ARP cache");
11338 return 0;
11339 }
11340 }
11341
11342 return 1;
11343}
11344
11345
11346int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
11347 struct sigma_cmd *cmd)
11348{
11349 const char *intf = get_param(cmd, "Interface");
11350 const char *val;
11351
11352 if (intf == NULL)
11353 return -1;
11354
11355 val = get_param(cmd, "program");
11356 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011357 strcasecmp(val, "HS2-R2") == 0 ||
11358 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011359 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
11360
11361 return -1;
11362}
11363
11364
Jouni Malinenf7222712019-06-13 01:50:21 +030011365static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
11366 struct sigma_conn *conn,
11367 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011368{
11369 const char *intf = get_param(cmd, "Interface");
11370 const char *mac = get_param(cmd, "MAC");
11371
11372 if (intf == NULL || mac == NULL)
11373 return -1;
11374
11375 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
11376 "interface %s to %s", intf, mac);
11377
11378 if (dut->set_macaddr) {
11379 char buf[128];
11380 int res;
11381 if (strcasecmp(mac, "default") == 0) {
11382 res = snprintf(buf, sizeof(buf), "%s",
11383 dut->set_macaddr);
11384 dut->tmp_mac_addr = 0;
11385 } else {
11386 res = snprintf(buf, sizeof(buf), "%s %s",
11387 dut->set_macaddr, mac);
11388 dut->tmp_mac_addr = 1;
11389 }
11390 if (res < 0 || res >= (int) sizeof(buf))
11391 return -1;
11392 if (system(buf) != 0) {
11393 send_resp(dut, conn, SIGMA_ERROR,
11394 "errorCode,Failed to set MAC "
11395 "address");
11396 return 0;
11397 }
11398 return 1;
11399 }
11400
11401 if (strcasecmp(mac, "default") == 0)
11402 return 1;
11403
11404 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11405 "command");
11406 return 0;
11407}
11408
11409
11410static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
11411 struct sigma_conn *conn, const char *intf,
11412 int val)
11413{
11414 char buf[200];
11415 int res;
11416
11417 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
11418 intf, val);
11419 if (res < 0 || res >= (int) sizeof(buf))
11420 return -1;
11421 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11422 if (system(buf) != 0) {
11423 send_resp(dut, conn, SIGMA_ERROR,
11424 "errorCode,Failed to configure offchannel mode");
11425 return 0;
11426 }
11427
11428 return 1;
11429}
11430
11431
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011432static int off_chan_val(enum sec_ch_offset off)
11433{
11434 switch (off) {
11435 case SEC_CH_NO:
11436 return 0;
11437 case SEC_CH_40ABOVE:
11438 return 40;
11439 case SEC_CH_40BELOW:
11440 return -40;
11441 }
11442
11443 return 0;
11444}
11445
11446
11447static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
11448 const char *intf, int off_ch_num,
11449 enum sec_ch_offset sec)
11450{
11451 char buf[200];
11452 int res;
11453
11454 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
11455 intf, off_ch_num);
11456 if (res < 0 || res >= (int) sizeof(buf))
11457 return -1;
11458 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11459 if (system(buf) != 0) {
11460 send_resp(dut, conn, SIGMA_ERROR,
11461 "errorCode,Failed to set offchan");
11462 return 0;
11463 }
11464
11465 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
11466 intf, off_chan_val(sec));
11467 if (res < 0 || res >= (int) sizeof(buf))
11468 return -1;
11469 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11470 if (system(buf) != 0) {
11471 send_resp(dut, conn, SIGMA_ERROR,
11472 "errorCode,Failed to set sec chan offset");
11473 return 0;
11474 }
11475
11476 return 1;
11477}
11478
11479
11480static int tdls_set_offchannel_offset(struct sigma_dut *dut,
11481 struct sigma_conn *conn,
11482 const char *intf, int off_ch_num,
11483 enum sec_ch_offset sec)
11484{
11485 char buf[200];
11486 int res;
11487
11488 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
11489 off_ch_num);
11490 if (res < 0 || res >= (int) sizeof(buf))
11491 return -1;
11492 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11493
11494 if (wpa_command(intf, buf) < 0) {
11495 send_resp(dut, conn, SIGMA_ERROR,
11496 "ErrorCode,Failed to set offchan");
11497 return 0;
11498 }
11499 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
11500 off_chan_val(sec));
11501 if (res < 0 || res >= (int) sizeof(buf))
11502 return -1;
11503
11504 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11505
11506 if (wpa_command(intf, buf) < 0) {
11507 send_resp(dut, conn, SIGMA_ERROR,
11508 "ErrorCode,Failed to set sec chan offset");
11509 return 0;
11510 }
11511
11512 return 1;
11513}
11514
11515
11516static int tdls_set_offchannel_mode(struct sigma_dut *dut,
11517 struct sigma_conn *conn,
11518 const char *intf, int val)
11519{
11520 char buf[200];
11521 int res;
11522
11523 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
11524 val);
11525 if (res < 0 || res >= (int) sizeof(buf))
11526 return -1;
11527 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11528
11529 if (wpa_command(intf, buf) < 0) {
11530 send_resp(dut, conn, SIGMA_ERROR,
11531 "ErrorCode,Failed to configure offchannel mode");
11532 return 0;
11533 }
11534
11535 return 1;
11536}
11537
11538
11539static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
11540 struct sigma_conn *conn,
11541 struct sigma_cmd *cmd)
11542{
11543 const char *val;
11544 enum {
11545 CHSM_NOT_SET,
11546 CHSM_ENABLE,
11547 CHSM_DISABLE,
11548 CHSM_REJREQ,
11549 CHSM_UNSOLRESP
11550 } chsm = CHSM_NOT_SET;
11551 int off_ch_num = -1;
11552 enum sec_ch_offset sec_ch = SEC_CH_NO;
11553 int res;
11554
11555 val = get_param(cmd, "Uapsd");
11556 if (val) {
11557 char buf[100];
11558 if (strcasecmp(val, "Enable") == 0)
11559 snprintf(buf, sizeof(buf), "SET ps 99");
11560 else if (strcasecmp(val, "Disable") == 0)
11561 snprintf(buf, sizeof(buf), "SET ps 98");
11562 else {
11563 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11564 "Unsupported uapsd parameter value");
11565 return 0;
11566 }
11567 if (wpa_command(intf, buf)) {
11568 send_resp(dut, conn, SIGMA_ERROR,
11569 "ErrorCode,Failed to change U-APSD "
11570 "powersave mode");
11571 return 0;
11572 }
11573 }
11574
11575 val = get_param(cmd, "TPKTIMER");
11576 if (val && strcasecmp(val, "DISABLE") == 0) {
11577 if (wpa_command(intf, "SET tdls_testing 0x100")) {
11578 send_resp(dut, conn, SIGMA_ERROR,
11579 "ErrorCode,Failed to enable no TPK "
11580 "expiration test mode");
11581 return 0;
11582 }
11583 dut->no_tpk_expiration = 1;
11584 }
11585
11586 val = get_param(cmd, "ChSwitchMode");
11587 if (val) {
11588 if (strcasecmp(val, "Enable") == 0 ||
11589 strcasecmp(val, "Initiate") == 0)
11590 chsm = CHSM_ENABLE;
11591 else if (strcasecmp(val, "Disable") == 0 ||
11592 strcasecmp(val, "passive") == 0)
11593 chsm = CHSM_DISABLE;
11594 else if (strcasecmp(val, "RejReq") == 0)
11595 chsm = CHSM_REJREQ;
11596 else if (strcasecmp(val, "UnSolResp") == 0)
11597 chsm = CHSM_UNSOLRESP;
11598 else {
11599 send_resp(dut, conn, SIGMA_ERROR,
11600 "ErrorCode,Unknown ChSwitchMode value");
11601 return 0;
11602 }
11603 }
11604
11605 val = get_param(cmd, "OffChNum");
11606 if (val) {
11607 off_ch_num = atoi(val);
11608 if (off_ch_num == 0) {
11609 send_resp(dut, conn, SIGMA_ERROR,
11610 "ErrorCode,Invalid OffChNum");
11611 return 0;
11612 }
11613 }
11614
11615 val = get_param(cmd, "SecChOffset");
11616 if (val) {
11617 if (strcmp(val, "20") == 0)
11618 sec_ch = SEC_CH_NO;
11619 else if (strcasecmp(val, "40above") == 0)
11620 sec_ch = SEC_CH_40ABOVE;
11621 else if (strcasecmp(val, "40below") == 0)
11622 sec_ch = SEC_CH_40BELOW;
11623 else {
11624 send_resp(dut, conn, SIGMA_ERROR,
11625 "ErrorCode,Unknown SecChOffset value");
11626 return 0;
11627 }
11628 }
11629
11630 if (chsm == CHSM_NOT_SET) {
11631 /* no offchannel changes requested */
11632 return 1;
11633 }
11634
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011635 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
11636 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011637 send_resp(dut, conn, SIGMA_ERROR,
11638 "ErrorCode,Unknown interface");
11639 return 0;
11640 }
11641
11642 switch (chsm) {
11643 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030011644 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011645 break;
11646 case CHSM_ENABLE:
11647 if (off_ch_num < 0) {
11648 send_resp(dut, conn, SIGMA_ERROR,
11649 "ErrorCode,Missing OffChNum argument");
11650 return 0;
11651 }
11652 if (wifi_chip_type == DRIVER_WCN) {
11653 res = tdls_set_offchannel_offset(dut, conn, intf,
11654 off_ch_num, sec_ch);
11655 } else {
11656 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11657 sec_ch);
11658 }
11659 if (res != 1)
11660 return res;
11661 if (wifi_chip_type == DRIVER_WCN)
11662 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
11663 else
11664 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
11665 break;
11666 case CHSM_DISABLE:
11667 if (wifi_chip_type == DRIVER_WCN)
11668 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
11669 else
11670 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
11671 break;
11672 case CHSM_REJREQ:
11673 if (wifi_chip_type == DRIVER_WCN)
11674 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
11675 else
11676 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
11677 break;
11678 case CHSM_UNSOLRESP:
11679 if (off_ch_num < 0) {
11680 send_resp(dut, conn, SIGMA_ERROR,
11681 "ErrorCode,Missing OffChNum argument");
11682 return 0;
11683 }
11684 if (wifi_chip_type == DRIVER_WCN) {
11685 res = tdls_set_offchannel_offset(dut, conn, intf,
11686 off_ch_num, sec_ch);
11687 } else {
11688 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11689 sec_ch);
11690 }
11691 if (res != 1)
11692 return res;
11693 if (wifi_chip_type == DRIVER_WCN)
11694 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
11695 else
11696 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
11697 break;
11698 }
11699
11700 return res;
11701}
11702
11703
11704static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11705 struct sigma_conn *conn,
11706 struct sigma_cmd *cmd)
11707{
11708 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011709 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011710
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011711 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080011712
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011713 val = get_param(cmd, "nss_mcs_opt");
11714 if (val) {
11715 /* String (nss_operating_mode; mcs_operating_mode) */
11716 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011717 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011718
11719 token = strdup(val);
11720 if (!token)
11721 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011722 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011723 if (!result) {
11724 sigma_dut_print(dut, DUT_MSG_ERROR,
11725 "VHT NSS not specified");
11726 goto failed;
11727 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011728 if (strcasecmp(result, "def") != 0) {
11729 nss = atoi(result);
11730 if (nss == 4)
11731 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011732 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011733 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011734
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011735 }
11736
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011737 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011738 if (!result) {
11739 sigma_dut_print(dut, DUT_MSG_ERROR,
11740 "VHT MCS not specified");
11741 goto failed;
11742 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011743 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011744 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011745 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011746 } else {
11747 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011748 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011749 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011750 }
11751 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011752 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011753 }
11754
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011755 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011756 return 1;
11757failed:
11758 free(token);
11759 return 0;
11760}
11761
11762
11763static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11764 struct sigma_conn *conn,
11765 struct sigma_cmd *cmd)
11766{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011767 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011768 case DRIVER_ATHEROS:
11769 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
11770 default:
11771 send_resp(dut, conn, SIGMA_ERROR,
11772 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
11773 return 0;
11774 }
11775}
11776
11777
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011778static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11779 struct sigma_conn *conn,
11780 struct sigma_cmd *cmd)
11781{
11782 const char *val;
11783 char *token = NULL, *result;
11784 char buf[60];
11785
11786 val = get_param(cmd, "nss_mcs_opt");
11787 if (val) {
11788 /* String (nss_operating_mode; mcs_operating_mode) */
11789 int nss, mcs, ratecode;
11790 char *saveptr;
11791
11792 token = strdup(val);
11793 if (!token)
11794 return -2;
11795
11796 result = strtok_r(token, ";", &saveptr);
11797 if (!result) {
11798 sigma_dut_print(dut, DUT_MSG_ERROR,
11799 "HE NSS not specified");
11800 goto failed;
11801 }
11802 nss = 1;
11803 if (strcasecmp(result, "def") != 0)
11804 nss = atoi(result);
11805
11806 result = strtok_r(NULL, ";", &saveptr);
11807 if (!result) {
11808 sigma_dut_print(dut, DUT_MSG_ERROR,
11809 "HE MCS not specified");
11810 goto failed;
11811 }
11812 mcs = 7;
11813 if (strcasecmp(result, "def") != 0)
11814 mcs = atoi(result);
11815
Arif Hussain557bf412018-05-25 17:29:36 -070011816 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011817 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070011818 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011819 } else if (nss > 2) {
11820 sigma_dut_print(dut, DUT_MSG_ERROR,
11821 "HE NSS %d not supported", nss);
11822 goto failed;
11823 }
11824
Arif Hussain557bf412018-05-25 17:29:36 -070011825 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
11826 if (system(buf) != 0) {
11827 sigma_dut_print(dut, DUT_MSG_ERROR,
11828 "nss_mcs_opt: iwpriv %s nss %d failed",
11829 intf, nss);
11830 goto failed;
11831 }
Arif Hussainac6c5112018-05-25 17:34:00 -070011832 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070011833
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011834 /* Add the MCS to the ratecode */
11835 if (mcs >= 0 && mcs <= 11) {
11836 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070011837#ifdef NL80211_SUPPORT
11838 if (dut->device_type == STA_testbed) {
11839 enum he_mcs_config mcs_config;
11840 int ret;
11841
11842 if (mcs <= 7)
11843 mcs_config = HE_80_MCS0_7;
11844 else if (mcs <= 9)
11845 mcs_config = HE_80_MCS0_9;
11846 else
11847 mcs_config = HE_80_MCS0_11;
11848 ret = sta_set_he_mcs(dut, intf, mcs_config);
11849 if (ret) {
11850 sigma_dut_print(dut, DUT_MSG_ERROR,
11851 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
11852 mcs, mcs_config, ret);
11853 goto failed;
11854 }
11855 }
11856#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011857 } else {
11858 sigma_dut_print(dut, DUT_MSG_ERROR,
11859 "HE MCS %d not supported", mcs);
11860 goto failed;
11861 }
11862 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
11863 intf, ratecode);
11864 if (system(buf) != 0) {
11865 sigma_dut_print(dut, DUT_MSG_ERROR,
11866 "iwpriv setting of 11ax rates failed");
11867 goto failed;
11868 }
11869 free(token);
11870 }
11871
11872 val = get_param(cmd, "GI");
11873 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011874 int fix_rate_sgi;
11875
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011876 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011877 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011878 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011879 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011880 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
11881 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011882 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011883 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011884 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
11885 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011886 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011887 } else {
11888 send_resp(dut, conn, SIGMA_ERROR,
11889 "errorCode,GI value not supported");
11890 return 0;
11891 }
11892 if (system(buf) != 0) {
11893 send_resp(dut, conn, SIGMA_ERROR,
11894 "errorCode,Failed to set shortgi");
11895 return 0;
11896 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011897 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
11898 intf, fix_rate_sgi);
11899 if (system(buf) != 0) {
11900 send_resp(dut, conn, SIGMA_ERROR,
11901 "errorCode,Failed to set fix rate shortgi");
11902 return STATUS_SENT;
11903 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011904 }
11905
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011906 val = get_param(cmd, "LTF");
11907 if (val) {
11908#ifdef NL80211_SUPPORT
11909 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011910 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011911 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011912 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011913 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011914 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011915 } else {
11916 send_resp(dut, conn, SIGMA_ERROR,
11917 "errorCode, LTF value not supported");
11918 return 0;
11919 }
11920#else /* NL80211_SUPPORT */
11921 sigma_dut_print(dut, DUT_MSG_ERROR,
11922 "LTF cannot be set without NL80211_SUPPORT defined");
11923 return -2;
11924#endif /* NL80211_SUPPORT */
11925 }
11926
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070011927 val = get_param(cmd, "TxSUPPDU");
11928 if (val) {
11929 int set_val = 1;
11930
11931 if (strcasecmp(val, "Enable") == 0)
11932 set_val = 1;
11933 else if (strcasecmp(val, "Disable") == 0)
11934 set_val = 0;
11935
11936 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
11937 send_resp(dut, conn, SIGMA_ERROR,
11938 "ErrorCode,Failed to set Tx SU PPDU config");
11939 return 0;
11940 }
11941 }
11942
Arif Hussain480d5f42019-03-12 14:40:42 -070011943 val = get_param(cmd, "TWT_Setup");
11944 if (val) {
11945 if (strcasecmp(val, "Request") == 0) {
11946 if (sta_twt_request(dut, conn, cmd)) {
11947 send_resp(dut, conn, SIGMA_ERROR,
11948 "ErrorCode,sta_twt_request failed");
11949 return STATUS_SENT;
11950 }
11951 } else if (strcasecmp(val, "Teardown") == 0) {
11952 if (sta_twt_teardown(dut, conn, cmd)) {
11953 send_resp(dut, conn, SIGMA_ERROR,
11954 "ErrorCode,sta_twt_teardown failed");
11955 return STATUS_SENT;
11956 }
11957 }
11958 }
11959
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080011960 val = get_param(cmd, "transmitOMI");
11961 if (val && sta_transmit_omi(dut, conn, cmd)) {
11962 send_resp(dut, conn, SIGMA_ERROR,
11963 "ErrorCode,sta_transmit_omi failed");
11964 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070011965 }
11966
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011967 val = get_param(cmd, "Powersave");
11968 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011969 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011970
11971 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011972 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011973 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011974 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011975 } else {
11976 sigma_dut_print(dut, DUT_MSG_ERROR,
11977 "Unsupported Powersave value '%s'",
11978 val);
11979 return -1;
11980 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011981 if (set_power_save_wcn(dut, intf, ps) < 0)
11982 return 0;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011983 }
11984
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080011985 val = get_param(cmd, "MU_EDCA");
11986 if (val) {
11987 if (strcasecmp(val, "Override") == 0) {
11988 if (sta_set_mu_edca_override(dut, intf, 1)) {
11989 send_resp(dut, conn, SIGMA_ERROR,
11990 "errorCode,MU EDCA override set failed");
11991 return STATUS_SENT;
11992 }
11993 } else if (strcasecmp(val, "Disable") == 0) {
11994 if (sta_set_mu_edca_override(dut, intf, 0)) {
11995 send_resp(dut, conn, SIGMA_ERROR,
11996 "errorCode,MU EDCA override disable failed");
11997 return STATUS_SENT;
11998 }
11999 }
12000 }
12001
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -070012002 val = get_param(cmd, "Ch_Pref");
12003 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12004 return STATUS_SENT;
12005
12006 val = get_param(cmd, "Cellular_Data_Cap");
12007 if (val && mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12008 return STATUS_SENT;
12009
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012010 return 1;
12011
12012failed:
12013 free(token);
12014 return -2;
12015}
12016
12017
12018static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12019 struct sigma_conn *conn,
12020 struct sigma_cmd *cmd)
12021{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012022 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012023 case DRIVER_WCN:
12024 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
12025 default:
12026 send_resp(dut, conn, SIGMA_ERROR,
12027 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
12028 return 0;
12029 }
12030}
12031
12032
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012033static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
12034 struct sigma_conn *conn,
12035 struct sigma_cmd *cmd)
12036{
12037 const char *val;
12038
12039 val = get_param(cmd, "powersave");
12040 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012041 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012042
12043 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012044 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012045 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012046 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012047 } else {
12048 sigma_dut_print(dut, DUT_MSG_ERROR,
12049 "Unsupported power save config");
12050 return -1;
12051 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012052 if (set_power_save_wcn(dut, intf, ps) < 0)
12053 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012054 return 1;
12055 }
12056
12057 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
12058
12059 return 0;
12060}
12061
12062
Ashwini Patil5acd7382017-04-13 15:55:04 +053012063static int btm_query_candidate_list(struct sigma_dut *dut,
12064 struct sigma_conn *conn,
12065 struct sigma_cmd *cmd)
12066{
12067 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
12068 int len, ret;
12069 char buf[10];
12070
12071 /*
12072 * Neighbor Report elements format:
12073 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
12074 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
12075 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
12076 */
12077
12078 bssid = get_param(cmd, "Nebor_BSSID");
12079 if (!bssid) {
12080 send_resp(dut, conn, SIGMA_INVALID,
12081 "errorCode,Nebor_BSSID is missing");
12082 return 0;
12083 }
12084
12085 info = get_param(cmd, "Nebor_Bssid_Info");
12086 if (!info) {
12087 sigma_dut_print(dut, DUT_MSG_INFO,
12088 "Using default value for Nebor_Bssid_Info: %s",
12089 DEFAULT_NEIGHBOR_BSSID_INFO);
12090 info = DEFAULT_NEIGHBOR_BSSID_INFO;
12091 }
12092
12093 op_class = get_param(cmd, "Nebor_Op_Class");
12094 if (!op_class) {
12095 send_resp(dut, conn, SIGMA_INVALID,
12096 "errorCode,Nebor_Op_Class is missing");
12097 return 0;
12098 }
12099
12100 ch = get_param(cmd, "Nebor_Op_Ch");
12101 if (!ch) {
12102 send_resp(dut, conn, SIGMA_INVALID,
12103 "errorCode,Nebor_Op_Ch is missing");
12104 return 0;
12105 }
12106
12107 phy_type = get_param(cmd, "Nebor_Phy_Type");
12108 if (!phy_type) {
12109 sigma_dut_print(dut, DUT_MSG_INFO,
12110 "Using default value for Nebor_Phy_Type: %s",
12111 DEFAULT_NEIGHBOR_PHY_TYPE);
12112 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
12113 }
12114
12115 /* Parse optional subelements */
12116 buf[0] = '\0';
12117 pref = get_param(cmd, "Nebor_Pref");
12118 if (pref) {
12119 /* hexdump for preferrence subelement */
12120 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
12121 if (ret < 0 || ret >= (int) sizeof(buf)) {
12122 sigma_dut_print(dut, DUT_MSG_ERROR,
12123 "snprintf failed for optional subelement ret: %d",
12124 ret);
12125 send_resp(dut, conn, SIGMA_ERROR,
12126 "errorCode,snprintf failed for subelement");
12127 return 0;
12128 }
12129 }
12130
12131 if (!dut->btm_query_cand_list) {
12132 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
12133 if (!dut->btm_query_cand_list) {
12134 send_resp(dut, conn, SIGMA_ERROR,
12135 "errorCode,Failed to allocate memory for btm_query_cand_list");
12136 return 0;
12137 }
12138 }
12139
12140 len = strlen(dut->btm_query_cand_list);
12141 ret = snprintf(dut->btm_query_cand_list + len,
12142 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
12143 bssid, info, op_class, ch, phy_type, buf);
12144 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
12145 sigma_dut_print(dut, DUT_MSG_ERROR,
12146 "snprintf failed for neighbor report list ret: %d",
12147 ret);
12148 send_resp(dut, conn, SIGMA_ERROR,
12149 "errorCode,snprintf failed for neighbor report");
12150 free(dut->btm_query_cand_list);
12151 dut->btm_query_cand_list = NULL;
12152 return 0;
12153 }
12154
12155 return 1;
12156}
12157
12158
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012159int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
12160 struct sigma_ese_alloc *allocs, int *allocs_size)
12161{
12162 int max_count = *allocs_size;
12163 int count = 0, i;
12164 const char *val;
12165
12166 do {
12167 val = get_param_indexed(cmd, "AllocID", count);
12168 if (val)
12169 count++;
12170 } while (val);
12171
12172 if (count == 0 || count > max_count) {
12173 sigma_dut_print(dut, DUT_MSG_ERROR,
12174 "Invalid number of allocations(%d)", count);
12175 return -1;
12176 }
12177
12178 for (i = 0; i < count; i++) {
12179 val = get_param_indexed(cmd, "PercentBI", i);
12180 if (!val) {
12181 sigma_dut_print(dut, DUT_MSG_ERROR,
12182 "Missing PercentBI parameter at index %d",
12183 i);
12184 return -1;
12185 }
12186 allocs[i].percent_bi = atoi(val);
12187
12188 val = get_param_indexed(cmd, "SrcAID", i);
12189 if (val)
12190 allocs[i].src_aid = strtol(val, NULL, 0);
12191 else
12192 allocs[i].src_aid = ESE_BCAST_AID;
12193
12194 val = get_param_indexed(cmd, "DestAID", i);
12195 if (val)
12196 allocs[i].dst_aid = strtol(val, NULL, 0);
12197 else
12198 allocs[i].dst_aid = ESE_BCAST_AID;
12199
12200 allocs[i].type = ESE_CBAP;
12201 sigma_dut_print(dut, DUT_MSG_INFO,
12202 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
12203 i, allocs[i].percent_bi, allocs[i].src_aid,
12204 allocs[i].dst_aid);
12205 }
12206
12207 *allocs_size = count;
12208 return 0;
12209}
12210
12211
12212static int sta_set_60g_ese(struct sigma_dut *dut, int count,
12213 struct sigma_ese_alloc *allocs)
12214{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012215 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012216#ifdef __linux__
12217 case DRIVER_WIL6210:
12218 if (wil6210_set_ese(dut, count, allocs))
12219 return -1;
12220 return 1;
12221#endif /* __linux__ */
12222 default:
12223 sigma_dut_print(dut, DUT_MSG_ERROR,
12224 "Unsupported sta_set_60g_ese with the current driver");
12225 return -1;
12226 }
12227}
12228
12229
12230static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
12231 struct sigma_conn *conn,
12232 struct sigma_cmd *cmd)
12233{
12234 const char *val;
12235
12236 val = get_param(cmd, "ExtSchIE");
12237 if (val && !strcasecmp(val, "Enable")) {
12238 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
12239 int count = MAX_ESE_ALLOCS;
12240
12241 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
12242 return -1;
12243 return sta_set_60g_ese(dut, count, allocs);
12244 }
12245
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012246 val = get_param(cmd, "MCS_FixedRate");
12247 if (val) {
12248 int sta_mcs = atoi(val);
12249
12250 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
12251 sta_mcs);
12252 wil6210_set_force_mcs(dut, 1, sta_mcs);
12253
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012254 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012255 }
12256
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012257 send_resp(dut, conn, SIGMA_ERROR,
12258 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012259 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012260}
12261
12262
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012263static int wcn_sta_override_oci(struct sigma_dut *dut, const char *intf,
12264 const char *oci_frametype, uint32_t oci_freq)
12265{
12266#ifdef NL80211_SUPPORT
12267 struct nl_msg *msg;
12268 int ret = 0;
12269 struct nlattr *params;
12270 struct nlattr *attr;
12271 int ifindex;
12272 u8 frame_type;
12273
12274 ifindex = if_nametoindex(intf);
12275 if (ifindex == 0) {
12276 sigma_dut_print(dut, DUT_MSG_ERROR,
12277 "%s: Index for interface %s failed",
12278 __func__, intf);
12279 return -1;
12280 }
12281
12282 if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12283 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_REQ;
12284 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12285 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_RESP;
12286 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
12287 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_FT_REASSOC_REQ;
12288 } else {
12289 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: Unknown frametype %s",
12290 __func__, oci_frametype);
12291 return -1;
12292 }
12293
12294
12295 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
12296 NL80211_CMD_VENDOR)) ||
12297 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
12298 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
12299 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
12300 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
12301 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
12302 !(params = nla_nest_start(
12303 msg,
12304 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OCI_OVERRIDE)) ||
12305 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FRAME_TYPE,
12306 frame_type) ||
12307 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FREQUENCY,
12308 oci_freq)) {
12309 sigma_dut_print(dut, DUT_MSG_ERROR,
12310 "%s: err in adding vendor_cmd and vendor_data",
12311 __func__);
12312 nlmsg_free(msg);
12313 return -1;
12314 }
12315 nla_nest_end(msg, params);
12316 nla_nest_end(msg, attr);
12317
12318 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
12319 if (ret) {
12320 sigma_dut_print(dut, DUT_MSG_ERROR,
12321 "%s: err in send_and_recv_msgs, ret=%d",
12322 __func__, ret);
12323 }
12324 return ret;
12325#else /* NL80211_SUPPORT */
12326 sigma_dut_print(dut, DUT_MSG_ERROR,
12327 "OCI override not possible without NL80211_SUPPORT defined");
12328 return -1;
12329#endif /* NL80211_SUPPORT */
12330}
12331
12332
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053012333static int wcn_sta_ignore_csa(struct sigma_dut *dut, const char *intf,
12334 uint8_t ignore_csa)
12335{
12336#ifdef NL80211_SUPPORT
12337 return wcn_wifi_test_config_set_u8(
12338 dut, intf,
12339 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_CSA, ignore_csa);
12340#else /* NL80211_SUPPORT */
12341 sigma_dut_print(dut, DUT_MSG_ERROR,
12342 "IgnoreCSA can't be set without NL80211_SUPPORT defined");
12343 return -1;
12344#endif /* NL80211_SUPPORT */
12345}
12346
12347
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053012348static int wcn_sta_set_rsnxe_used(struct sigma_dut *dut, const char *intf,
12349 uint8_t rsnxe_used)
12350{
12351#ifdef NL80211_SUPPORT
12352 return wcn_wifi_test_config_set_u8(
12353 dut, intf,
12354 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FT_REASSOCREQ_RSNXE_USED,
12355 rsnxe_used);
12356#else /* NL80211_SUPPORT */
12357 sigma_dut_print(dut, DUT_MSG_ERROR,
12358 "RSNXE_Used can't be set without NL80211_SUPPORT defined");
12359 return -1;
12360#endif /* NL80211_SUPPORT */
12361}
12362
12363
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053012364static int wcn_sta_ignore_sa_query_timeout(struct sigma_dut *dut,
12365 const char *intf,
12366 uint8_t ignore_sa_query_timeout)
12367{
12368#ifdef NL80211_SUPPORT
12369 return wcn_wifi_test_config_set_u8(
12370 dut, intf,
12371 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_SA_QUERY_TIMEOUT,
12372 ignore_sa_query_timeout);
12373#else /* NL80211_SUPPORT */
12374 sigma_dut_print(dut, DUT_MSG_ERROR,
12375 "Ignore SA Query timeout can't be set without NL80211_SUPPORT defined");
12376 return -1;
12377#endif /* NL80211_SUPPORT */
12378}
12379
12380
Jouni Malinen6250cb02020-04-15 13:54:45 +030012381static enum sigma_cmd_result
12382cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
12383 struct sigma_conn *conn,
12384 struct sigma_cmd *cmd)
12385{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012386 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030012387
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053012388 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030012389 if (val && atoi(val) == 1) {
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053012390 if (wifi_chip_type == DRIVER_WCN) {
12391 if (wcn_sta_set_rsnxe_used(dut, intf, 1)) {
12392 send_resp(dut, conn, SIGMA_ERROR,
12393 "errorCode,Failed to set ft_rsnxe_used");
12394 return STATUS_SENT_ERROR;
12395 }
12396 return SUCCESS_SEND_STATUS;
12397 } else if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
Jouni Malinen6250cb02020-04-15 13:54:45 +030012398 send_resp(dut, conn, SIGMA_ERROR,
12399 "errorCode,Failed to set ft_rsnxe_used");
12400 return STATUS_SENT_ERROR;
12401 }
12402 return SUCCESS_SEND_STATUS;
12403 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012404
12405 oci_chan = get_param(cmd, "OCIChannel");
12406 oci_frametype = get_param(cmd, "OCIFrameType");
12407 if (oci_chan && oci_frametype) {
12408 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
12409 char buf[100];
12410
12411 if (!oci_freq) {
12412 send_resp(dut, conn, SIGMA_ERROR,
12413 "errorCode,Invalid OCIChannel number");
12414 return STATUS_SENT_ERROR;
12415 }
12416
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012417 if (wifi_chip_type == DRIVER_WCN &&
12418 (strcasecmp(oci_frametype, "SAQueryReq") == 0 ||
12419 strcasecmp(oci_frametype, "SAQueryResp") == 0 ||
12420 strcasecmp(oci_frametype, "Reassocreq") == 0)) {
12421 if (wcn_sta_override_oci(dut, intf, oci_frametype,
12422 oci_freq)) {
12423 send_resp(dut, conn, SIGMA_ERROR,
12424 "errorCode,Failed to override OCI");
12425 return STATUS_SENT_ERROR;
12426 }
12427 return SUCCESS_SEND_STATUS;
12428 }
12429
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012430 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
12431 snprintf(buf, sizeof(buf),
12432 "SET oci_freq_override_eapol %d", oci_freq);
12433 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12434 snprintf(buf, sizeof(buf),
12435 "SET oci_freq_override_saquery_req %d",
12436 oci_freq);
12437 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12438 snprintf(buf, sizeof(buf),
12439 "SET oci_freq_override_saquery_resp %d",
12440 oci_freq);
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012441 } else if (strcasecmp(oci_frametype, "GrpKeyM2") == 0) {
12442 snprintf(buf, sizeof(buf),
12443 "SET oci_freq_override_eapol_g2 %d",
12444 oci_freq);
12445 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
12446 snprintf(buf, sizeof(buf),
12447 "SET oci_freq_override_ft_assoc %d",
12448 oci_freq);
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012449 } else {
12450 send_resp(dut, conn, SIGMA_ERROR,
12451 "errorCode,Unsupported OCIFrameType");
12452 return STATUS_SENT_ERROR;
12453 }
12454 if (wpa_command(intf, buf) < 0) {
12455 send_resp(dut, conn, SIGMA_ERROR,
12456 "errorCode,Failed to set oci_freq_override");
12457 return STATUS_SENT_ERROR;
12458 }
12459 return SUCCESS_SEND_STATUS;
12460 }
12461
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053012462 val = get_param(cmd, "IgnoreCSA");
12463 if (val && atoi(val) == 1) {
12464 if (wifi_chip_type == DRIVER_WCN) {
12465 if (wcn_sta_ignore_csa(dut, intf, 1)) {
12466 send_resp(dut, conn, SIGMA_ERROR,
12467 "errorCode,Failed to set ignore CSA");
12468 return STATUS_SENT_ERROR;
12469 }
12470 return SUCCESS_SEND_STATUS;
12471 }
12472 }
12473
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053012474 val = get_param(cmd, "Deauth_Per_SAQueryResp");
12475 if (val && atoi(val) == 0) {
12476 if (wifi_chip_type == DRIVER_WCN) {
12477 if (wcn_sta_ignore_sa_query_timeout(dut, intf, 1)) {
12478 send_resp(dut, conn, SIGMA_ERROR,
12479 "errorCode,Failed to set ignore SA Query timeout");
12480 return STATUS_SENT_ERROR;
12481 }
12482 return SUCCESS_SEND_STATUS;
12483 }
12484 }
12485
Jouni Malinen6250cb02020-04-15 13:54:45 +030012486 send_resp(dut, conn, SIGMA_ERROR,
12487 "errorCode,Unsupported WPA3 rfeature");
12488 return STATUS_SENT_ERROR;
12489}
12490
12491
Jouni Malinenf7222712019-06-13 01:50:21 +030012492static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
12493 struct sigma_conn *conn,
12494 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012495{
12496 const char *intf = get_param(cmd, "Interface");
12497 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012498 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012499
12500 if (intf == NULL || prog == NULL)
12501 return -1;
12502
Ashwini Patil5acd7382017-04-13 15:55:04 +053012503 /* BSS Transition candidate list for BTM query */
12504 val = get_param(cmd, "Nebor_BSSID");
12505 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
12506 return 0;
12507
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012508 if (strcasecmp(prog, "TDLS") == 0)
12509 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
12510
12511 if (strcasecmp(prog, "VHT") == 0)
12512 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
12513
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012514 if (strcasecmp(prog, "HE") == 0)
12515 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
12516
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012517 if (strcasecmp(prog, "MBO") == 0) {
12518 val = get_param(cmd, "Cellular_Data_Cap");
12519 if (val &&
12520 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12521 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053012522
12523 val = get_param(cmd, "Ch_Pref");
12524 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12525 return 0;
12526
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012527 return 1;
12528 }
12529
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012530 if (strcasecmp(prog, "60GHz") == 0)
12531 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
12532
Jouni Malinen6250cb02020-04-15 13:54:45 +030012533 if (strcasecmp(prog, "WPA3") == 0)
12534 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
12535
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012536 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
12537 return 0;
12538}
12539
12540
Jouni Malinenf7222712019-06-13 01:50:21 +030012541static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
12542 struct sigma_conn *conn,
12543 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012544{
12545 const char *intf = get_param(cmd, "Interface");
12546 const char *mode = get_param(cmd, "Mode");
12547 int res;
12548
12549 if (intf == NULL || mode == NULL)
12550 return -1;
12551
12552 if (strcasecmp(mode, "On") == 0)
12553 res = wpa_command(intf, "SET radio_disabled 0");
12554 else if (strcasecmp(mode, "Off") == 0)
12555 res = wpa_command(intf, "SET radio_disabled 1");
12556 else
12557 return -1;
12558
12559 if (res) {
12560 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12561 "radio mode");
12562 return 0;
12563 }
12564
12565 return 1;
12566}
12567
12568
Jouni Malinenf7222712019-06-13 01:50:21 +030012569static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
12570 struct sigma_conn *conn,
12571 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012572{
12573 const char *intf = get_param(cmd, "Interface");
12574 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012575 const char *prog = get_param(cmd, "program");
12576 const char *powersave = get_param(cmd, "powersave");
12577 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012578
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012579 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012580 return -1;
12581
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012582 if (prog && strcasecmp(prog, "60GHz") == 0) {
12583 /*
12584 * The CAPI mode parameter does not exist in 60G
12585 * unscheduled PS.
12586 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080012587 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012588 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012589 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020012590 strcasecmp(prog, "HE") == 0) {
12591 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012592 } else {
12593 if (mode == NULL)
12594 return -1;
12595
12596 if (strcasecmp(mode, "On") == 0)
12597 res = set_ps(intf, dut, 1);
12598 else if (strcasecmp(mode, "Off") == 0)
12599 res = set_ps(intf, dut, 0);
12600 else
12601 return -1;
12602 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012603
12604 if (res) {
12605 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12606 "power save mode");
12607 return 0;
12608 }
12609
12610 return 1;
12611}
12612
12613
Jouni Malinenf7222712019-06-13 01:50:21 +030012614static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
12615 struct sigma_conn *conn,
12616 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012617{
12618 const char *intf = get_param(cmd, "Interface");
12619 const char *val, *bssid;
12620 int res;
12621 char *buf;
12622 size_t buf_len;
12623
12624 val = get_param(cmd, "BSSID_FILTER");
12625 if (val == NULL)
12626 return -1;
12627
12628 bssid = get_param(cmd, "BSSID_List");
12629 if (atoi(val) == 0 || bssid == NULL) {
12630 /* Disable BSSID filter */
12631 if (wpa_command(intf, "SET bssid_filter ")) {
12632 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
12633 "to disable BSSID filter");
12634 return 0;
12635 }
12636
12637 return 1;
12638 }
12639
12640 buf_len = 100 + strlen(bssid);
12641 buf = malloc(buf_len);
12642 if (buf == NULL)
12643 return -1;
12644
12645 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
12646 res = wpa_command(intf, buf);
12647 free(buf);
12648 if (res) {
12649 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
12650 "BSSID filter");
12651 return 0;
12652 }
12653
12654 return 1;
12655}
12656
12657
Jouni Malinenf7222712019-06-13 01:50:21 +030012658static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
12659 struct sigma_conn *conn,
12660 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012661{
12662 const char *intf = get_param(cmd, "Interface");
12663 const char *val;
12664
12665 /* TODO: ARP */
12666
12667 val = get_param(cmd, "HS2_CACHE_PROFILE");
12668 if (val && strcasecmp(val, "All") == 0)
12669 hs2_clear_credentials(intf);
12670
12671 return 1;
12672}
12673
12674
Jouni Malinenf7222712019-06-13 01:50:21 +030012675static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
12676 struct sigma_conn *conn,
12677 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012678{
12679 const char *intf = get_param(cmd, "Interface");
12680 const char *key_type = get_param(cmd, "KeyType");
12681 char buf[100], resp[200];
12682
12683 if (key_type == NULL)
12684 return -1;
12685
12686 if (strcasecmp(key_type, "GTK") == 0) {
12687 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
12688 strncmp(buf, "FAIL", 4) == 0) {
12689 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12690 "not fetch current GTK");
12691 return 0;
12692 }
12693 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
12694 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12695 return 0;
12696 } else {
12697 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12698 "KeyType");
12699 return 0;
12700 }
12701
12702 return 1;
12703}
12704
12705
12706static int hs2_set_policy(struct sigma_dut *dut)
12707{
12708#ifdef ANDROID
12709 system("ip rule del prio 23000");
12710 if (system("ip rule add from all lookup main prio 23000") != 0) {
12711 sigma_dut_print(dut, DUT_MSG_ERROR,
12712 "Failed to run:ip rule add from all lookup main prio");
12713 return -1;
12714 }
12715 if (system("ip route flush cache") != 0) {
12716 sigma_dut_print(dut, DUT_MSG_ERROR,
12717 "Failed to run ip route flush cache");
12718 return -1;
12719 }
12720 return 1;
12721#else /* ANDROID */
12722 return 0;
12723#endif /* ANDROID */
12724}
12725
12726
Jouni Malinenf7222712019-06-13 01:50:21 +030012727static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
12728 struct sigma_conn *conn,
12729 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012730{
12731 const char *intf = get_param(cmd, "Interface");
12732 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030012733 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012734 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030012735 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012736 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
12737 int tries = 0;
12738 int ignore_blacklist = 0;
12739 const char *events[] = {
12740 "CTRL-EVENT-CONNECTED",
12741 "INTERWORKING-BLACKLISTED",
12742 "INTERWORKING-NO-MATCH",
12743 NULL
12744 };
12745
12746 start_sta_mode(dut);
12747
Jouni Malinen439352d2018-09-13 03:42:23 +030012748 if (band) {
12749 if (strcmp(band, "2.4") == 0) {
12750 wpa_command(intf, "SET setband 2G");
12751 } else if (strcmp(band, "5") == 0) {
12752 wpa_command(intf, "SET setband 5G");
12753 } else {
12754 send_resp(dut, conn, SIGMA_ERROR,
12755 "errorCode,Unsupported band");
12756 return 0;
12757 }
12758 }
12759
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012760 blacklisted[0] = '\0';
12761 if (val && atoi(val))
12762 ignore_blacklist = 1;
12763
12764try_again:
12765 ctrl = open_wpa_mon(intf);
12766 if (ctrl == NULL) {
12767 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12768 "wpa_supplicant monitor connection");
12769 return -2;
12770 }
12771
12772 tries++;
12773 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
12774 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
12775 "Interworking connection");
12776 wpa_ctrl_detach(ctrl);
12777 wpa_ctrl_close(ctrl);
12778 return 0;
12779 }
12780
12781 buf[0] = '\0';
12782 while (1) {
12783 char *pos;
12784 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
12785 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
12786 if (!pos)
12787 break;
12788 pos += 25;
12789 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
12790 pos);
12791 if (!blacklisted[0])
12792 memcpy(blacklisted, pos, strlen(pos) + 1);
12793 }
12794
12795 if (ignore_blacklist && blacklisted[0]) {
12796 char *end;
12797 end = strchr(blacklisted, ' ');
12798 if (end)
12799 *end = '\0';
12800 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
12801 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030012802 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
12803 blacklisted);
12804 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012805 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
12806 wpa_ctrl_detach(ctrl);
12807 wpa_ctrl_close(ctrl);
12808 return 0;
12809 }
12810 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
12811 buf, sizeof(buf));
12812 }
12813
12814 wpa_ctrl_detach(ctrl);
12815 wpa_ctrl_close(ctrl);
12816
12817 if (res < 0) {
12818 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12819 "connect");
12820 return 0;
12821 }
12822
12823 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
12824 strstr(buf, "INTERWORKING-BLACKLISTED")) {
12825 if (tries < 2) {
12826 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
12827 goto try_again;
12828 }
12829 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
12830 "matching credentials found");
12831 return 0;
12832 }
12833
12834 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12835 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12836 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12837 "get current BSSID/SSID");
12838 return 0;
12839 }
12840
12841 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
12842 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12843 hs2_set_policy(dut);
12844 return 0;
12845}
12846
12847
Jouni Malinenf7222712019-06-13 01:50:21 +030012848static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
12849 struct sigma_conn *conn,
12850 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030012851{
12852 const char *intf = get_param(cmd, "Interface");
12853 const char *display = get_param(cmd, "Display");
12854 struct wpa_ctrl *ctrl;
12855 char buf[300], params[400], *pos;
12856 char bssid[20];
12857 int info_avail = 0;
12858 unsigned int old_timeout;
12859 int res;
12860
12861 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
12862 send_resp(dut, conn, SIGMA_ERROR,
12863 "ErrorCode,Could not get current BSSID");
12864 return 0;
12865 }
12866 ctrl = open_wpa_mon(intf);
12867 if (!ctrl) {
12868 sigma_dut_print(dut, DUT_MSG_ERROR,
12869 "Failed to open wpa_supplicant monitor connection");
12870 return -2;
12871 }
12872
12873 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
12874 wpa_command(intf, buf);
12875
12876 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
12877 if (res < 0) {
12878 send_resp(dut, conn, SIGMA_ERROR,
12879 "ErrorCode,Could not complete GAS query");
12880 goto fail;
12881 }
12882
12883 old_timeout = dut->default_timeout;
12884 dut->default_timeout = 2;
12885 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
12886 dut->default_timeout = old_timeout;
12887 if (res < 0)
12888 goto done;
12889 pos = strchr(buf, ' ');
12890 if (!pos)
12891 goto done;
12892 pos++;
12893 pos = strchr(pos, ' ');
12894 if (!pos)
12895 goto done;
12896 pos++;
12897 info_avail = 1;
12898 snprintf(params, sizeof(params), "browser %s", pos);
12899
12900 if (display && strcasecmp(display, "Yes") == 0) {
12901 pid_t pid;
12902
12903 pid = fork();
12904 if (pid < 0) {
12905 perror("fork");
12906 return -1;
12907 }
12908
12909 if (pid == 0) {
12910 run_hs20_osu(dut, params);
12911 exit(0);
12912 }
12913 }
12914
12915done:
12916 snprintf(buf, sizeof(buf), "Info_available,%s",
12917 info_avail ? "Yes" : "No");
12918 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12919fail:
12920 wpa_ctrl_detach(ctrl);
12921 wpa_ctrl_close(ctrl);
12922 return 0;
12923}
12924
12925
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012926static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
12927 struct sigma_conn *conn,
12928 const char *ifname,
12929 struct sigma_cmd *cmd)
12930{
12931 const char *val;
12932 int id;
12933
12934 id = add_cred(ifname);
12935 if (id < 0)
12936 return -2;
12937 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12938
12939 val = get_param(cmd, "prefer");
12940 if (val && atoi(val) > 0)
12941 set_cred(ifname, id, "priority", "1");
12942
12943 val = get_param(cmd, "REALM");
12944 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12945 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12946 "realm");
12947 return 0;
12948 }
12949
12950 val = get_param(cmd, "HOME_FQDN");
12951 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12952 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12953 "home_fqdn");
12954 return 0;
12955 }
12956
12957 val = get_param(cmd, "Username");
12958 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12959 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12960 "username");
12961 return 0;
12962 }
12963
12964 val = get_param(cmd, "Password");
12965 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
12966 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12967 "password");
12968 return 0;
12969 }
12970
12971 val = get_param(cmd, "ROOT_CA");
12972 if (val) {
12973 char fname[200];
12974 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12975#ifdef __linux__
12976 if (!file_exists(fname)) {
12977 char msg[300];
12978 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12979 "file (%s) not found", fname);
12980 send_resp(dut, conn, SIGMA_ERROR, msg);
12981 return 0;
12982 }
12983#endif /* __linux__ */
12984 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12985 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12986 "not set root CA");
12987 return 0;
12988 }
12989 }
12990
12991 return 1;
12992}
12993
12994
12995static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
12996{
12997 FILE *in, *out;
12998 char buf[500];
12999 int found = 0;
13000
13001 in = fopen("devdetail.xml", "r");
13002 if (in == NULL)
13003 return -1;
13004 out = fopen("devdetail.xml.tmp", "w");
13005 if (out == NULL) {
13006 fclose(in);
13007 return -1;
13008 }
13009
13010 while (fgets(buf, sizeof(buf), in)) {
13011 char *pos = strstr(buf, "<IMSI>");
13012 if (pos) {
13013 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
13014 imsi);
13015 pos += 6;
13016 *pos = '\0';
13017 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
13018 found++;
13019 } else {
13020 fprintf(out, "%s", buf);
13021 }
13022 }
13023
13024 fclose(out);
13025 fclose(in);
13026 if (found)
13027 rename("devdetail.xml.tmp", "devdetail.xml");
13028 else
13029 unlink("devdetail.xml.tmp");
13030
13031 return 0;
13032}
13033
13034
13035static int sta_add_credential_sim(struct sigma_dut *dut,
13036 struct sigma_conn *conn,
13037 const char *ifname, struct sigma_cmd *cmd)
13038{
13039 const char *val, *imsi = NULL;
13040 int id;
13041 char buf[200];
13042 int res;
13043 const char *pos;
13044 size_t mnc_len;
13045 char plmn_mcc[4];
13046 char plmn_mnc[4];
13047
13048 id = add_cred(ifname);
13049 if (id < 0)
13050 return -2;
13051 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13052
13053 val = get_param(cmd, "prefer");
13054 if (val && atoi(val) > 0)
13055 set_cred(ifname, id, "priority", "1");
13056
13057 val = get_param(cmd, "PLMN_MCC");
13058 if (val == NULL) {
13059 send_resp(dut, conn, SIGMA_ERROR,
13060 "errorCode,Missing PLMN_MCC");
13061 return 0;
13062 }
13063 if (strlen(val) != 3) {
13064 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
13065 return 0;
13066 }
13067 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
13068
13069 val = get_param(cmd, "PLMN_MNC");
13070 if (val == NULL) {
13071 send_resp(dut, conn, SIGMA_ERROR,
13072 "errorCode,Missing PLMN_MNC");
13073 return 0;
13074 }
13075 if (strlen(val) != 2 && strlen(val) != 3) {
13076 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
13077 return 0;
13078 }
13079 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
13080
13081 val = get_param(cmd, "IMSI");
13082 if (val == NULL) {
13083 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
13084 "IMSI");
13085 return 0;
13086 }
13087
13088 imsi = pos = val;
13089
13090 if (strncmp(plmn_mcc, pos, 3) != 0) {
13091 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
13092 return 0;
13093 }
13094 pos += 3;
13095
13096 mnc_len = strlen(plmn_mnc);
13097 if (mnc_len < 2) {
13098 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
13099 return 0;
13100 }
13101
13102 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
13103 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
13104 return 0;
13105 }
13106 pos += mnc_len;
13107
13108 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
13109 if (res < 0 || res >= (int) sizeof(buf))
13110 return -1;
13111 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
13112 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13113 "not set IMSI");
13114 return 0;
13115 }
13116
13117 val = get_param(cmd, "Password");
13118 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
13119 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13120 "not set password");
13121 return 0;
13122 }
13123
Jouni Malinenba630452018-06-22 11:49:59 +030013124 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013125 /*
13126 * Set provisioning_sp for the test cases where SIM/USIM
13127 * provisioning is used.
13128 */
13129 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
13130 "wi-fi.org") < 0) {
13131 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13132 "not set provisioning_sp");
13133 return 0;
13134 }
13135
13136 update_devdetail_imsi(dut, imsi);
13137 }
13138
13139 return 1;
13140}
13141
13142
13143static int sta_add_credential_cert(struct sigma_dut *dut,
13144 struct sigma_conn *conn,
13145 const char *ifname,
13146 struct sigma_cmd *cmd)
13147{
13148 const char *val;
13149 int id;
13150
13151 id = add_cred(ifname);
13152 if (id < 0)
13153 return -2;
13154 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13155
13156 val = get_param(cmd, "prefer");
13157 if (val && atoi(val) > 0)
13158 set_cred(ifname, id, "priority", "1");
13159
13160 val = get_param(cmd, "REALM");
13161 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13162 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13163 "realm");
13164 return 0;
13165 }
13166
13167 val = get_param(cmd, "HOME_FQDN");
13168 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13169 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13170 "home_fqdn");
13171 return 0;
13172 }
13173
13174 val = get_param(cmd, "Username");
13175 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13176 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13177 "username");
13178 return 0;
13179 }
13180
13181 val = get_param(cmd, "clientCertificate");
13182 if (val) {
13183 char fname[200];
13184 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13185#ifdef __linux__
13186 if (!file_exists(fname)) {
13187 char msg[300];
13188 snprintf(msg, sizeof(msg),
13189 "ErrorCode,clientCertificate "
13190 "file (%s) not found", fname);
13191 send_resp(dut, conn, SIGMA_ERROR, msg);
13192 return 0;
13193 }
13194#endif /* __linux__ */
13195 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
13196 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13197 "not set client_cert");
13198 return 0;
13199 }
13200 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
13201 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13202 "not set private_key");
13203 return 0;
13204 }
13205 }
13206
13207 val = get_param(cmd, "ROOT_CA");
13208 if (val) {
13209 char fname[200];
13210 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13211#ifdef __linux__
13212 if (!file_exists(fname)) {
13213 char msg[300];
13214 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13215 "file (%s) not found", fname);
13216 send_resp(dut, conn, SIGMA_ERROR, msg);
13217 return 0;
13218 }
13219#endif /* __linux__ */
13220 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13221 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13222 "not set root CA");
13223 return 0;
13224 }
13225 }
13226
13227 return 1;
13228}
13229
13230
Jouni Malinenf7222712019-06-13 01:50:21 +030013231static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
13232 struct sigma_conn *conn,
13233 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013234{
13235 const char *intf = get_param(cmd, "Interface");
13236 const char *type;
13237
13238 start_sta_mode(dut);
13239
13240 type = get_param(cmd, "Type");
13241 if (!type)
13242 return -1;
13243
13244 if (strcasecmp(type, "uname_pwd") == 0)
13245 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
13246
13247 if (strcasecmp(type, "sim") == 0)
13248 return sta_add_credential_sim(dut, conn, intf, cmd);
13249
13250 if (strcasecmp(type, "cert") == 0)
13251 return sta_add_credential_cert(dut, conn, intf, cmd);
13252
13253 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
13254 "type");
13255 return 0;
13256}
13257
13258
Jouni Malinenf7222712019-06-13 01:50:21 +030013259static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
13260 struct sigma_conn *conn,
13261 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013262{
13263 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013264 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Veerendranathdc581b52020-08-10 03:29:08 -070013265 char buf[4096], scan_res[20];
vamsi krishna89ad8c62017-09-19 12:51:18 +053013266 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013267 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013268 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013269 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013270 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013271
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020013272 start_sta_mode(dut);
13273
Arif Hussain66a4af02019-02-07 15:04:51 -080013274 val = get_param(cmd, "GetParameter");
13275 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013276 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080013277 buf, sizeof(buf)) < 0) {
13278 sigma_dut_print(dut, DUT_MSG_ERROR,
13279 "Could not get ssid bssid");
13280 return ERROR_SEND_STATUS;
13281 }
13282
13283 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
13284 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13285 return STATUS_SENT;
13286 }
13287
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013288 val = get_param(cmd, "HESSID");
13289 if (val) {
13290 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
13291 if (res < 0 || res >= (int) sizeof(buf))
13292 return -1;
13293 wpa_command(intf, buf);
13294 }
13295
13296 val = get_param(cmd, "ACCS_NET_TYPE");
13297 if (val) {
13298 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
13299 val);
13300 if (res < 0 || res >= (int) sizeof(buf))
13301 return -1;
13302 wpa_command(intf, buf);
13303 }
13304
vamsi krishna89ad8c62017-09-19 12:51:18 +053013305 bssid = get_param(cmd, "Bssid");
13306 ssid = get_param(cmd, "Ssid");
13307
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013308 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
13309 dut->device_type == STA_testbed) {
13310 ssid = NULL;
13311 wildcard_ssid = 1;
13312 }
13313
vamsi krishna89ad8c62017-09-19 12:51:18 +053013314 if (ssid) {
13315 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
13316 send_resp(dut, conn, SIGMA_ERROR,
13317 "ErrorCode,Too long SSID");
13318 return 0;
13319 }
13320 ascii2hexstr(ssid, ssid_hex);
13321 }
13322
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013323 short_ssid = get_param(cmd, "ShortSSID");
13324 if (short_ssid) {
13325 uint32_t short_ssid_hex;
13326
13327 short_ssid_hex = strtoul(short_ssid, NULL, 16);
13328 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
13329 (((short_ssid_hex >> 8) & 0xFF) << 16) |
13330 (((short_ssid_hex >> 16) & 0xFF) << 8) |
13331 ((short_ssid_hex >> 24) & 0xFF);
13332
13333 res = snprintf(buf, sizeof(buf),
13334 "VENDOR_ELEM_ADD 14 ff053a%08x",
13335 short_ssid_hex);
13336 if (res < 0 || res >= (int) sizeof(buf) ||
13337 wpa_command(intf, buf)) {
13338 send_resp(dut, conn, SIGMA_ERROR,
13339 "errorCode,Failed to add short SSID");
13340 return STATUS_SENT_ERROR;
13341 }
13342 }
13343
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013344 scan_freq = get_param(cmd, "ChnlFreq");
Veerendranath Jakkam132c4b42020-08-10 00:29:03 +053013345 if (scan_freq) {
13346 if (strcasecmp(scan_freq, "2G") == 0)
13347 scan_freq = "2412-2462";
13348 else if (strcasecmp(scan_freq, "5G") == 0)
13349 scan_freq = "5180-5925";
13350 }
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013351
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013352 val = get_param(cmd, "WaitCompletion");
13353 if (val && atoi(val) == 1) {
13354 ctrl = open_wpa_mon(intf);
13355 if (!ctrl) {
13356 send_resp(dut, conn, SIGMA_ERROR,
13357 "errorCode,Failed to open monitor socket");
13358 return STATUS_SENT_ERROR;
13359 }
13360 }
13361
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013362 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053013363 bssid ? " bssid=": "",
13364 bssid ? bssid : "",
13365 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013366 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013367 wildcard_ssid ? " wildcard_ssid=1" : "",
13368 scan_freq ? " freq=" : "",
13369 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013370 if (res < 0 || res >= (int) sizeof(buf)) {
13371 send_resp(dut, conn, SIGMA_ERROR,
13372 "errorCode,Could not build scan command");
13373 status = STATUS_SENT_ERROR;
13374 goto remove_s_ssid;
13375 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053013376
Veerendranathdc581b52020-08-10 03:29:08 -070013377 res = wpa_command_resp(intf, buf, scan_res, sizeof(scan_res));
13378 if (strncmp(scan_res, "FAIL-BUSY", 9) == 0) {
13379 sigma_dut_print(dut, DUT_MSG_DEBUG,
13380 "Scan request rejected with busy status, abort ongoing scan and try again");
13381 wpa_command(intf, "ABORT_SCAN");
13382 res = wpa_command(intf, buf);
13383 }
13384
13385 if (res < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013386 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
13387 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013388 status = STATUS_SENT_ERROR;
13389 } else {
13390 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013391 }
13392
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013393remove_s_ssid:
13394 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
13395 sigma_dut_print(dut, DUT_MSG_ERROR,
13396 "Failed to delete vendor element");
13397
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013398 if (ctrl) {
13399 if (status == SUCCESS_SEND_STATUS) {
13400 res = get_wpa_cli_event(dut, ctrl,
13401 "CTRL-EVENT-SCAN-RESULTS",
13402 buf, sizeof(buf));
13403 if (res < 0) {
13404 send_resp(dut, conn, SIGMA_ERROR,
13405 "ErrorCode,scan did not complete");
13406 status = STATUS_SENT_ERROR;
13407 }
13408 }
13409
13410 wpa_ctrl_detach(ctrl);
13411 wpa_ctrl_close(ctrl);
13412 }
13413
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013414 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013415}
13416
13417
Jouni Malinenf7222712019-06-13 01:50:21 +030013418static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
13419 struct sigma_conn *conn,
13420 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013421{
13422 const char *intf = get_param(cmd, "Interface");
13423 const char *bssid;
13424 char buf[4096], *pos;
13425 int freq, chan;
13426 char *ssid;
13427 char resp[100];
13428 int res;
13429 struct wpa_ctrl *ctrl;
13430
13431 bssid = get_param(cmd, "BSSID");
13432 if (!bssid) {
13433 send_resp(dut, conn, SIGMA_INVALID,
13434 "errorCode,BSSID argument is missing");
13435 return 0;
13436 }
13437
13438 ctrl = open_wpa_mon(intf);
13439 if (!ctrl) {
13440 sigma_dut_print(dut, DUT_MSG_ERROR,
13441 "Failed to open wpa_supplicant monitor connection");
13442 return -1;
13443 }
13444
13445 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
13446 send_resp(dut, conn, SIGMA_ERROR,
13447 "errorCode,Could not start scan");
13448 wpa_ctrl_detach(ctrl);
13449 wpa_ctrl_close(ctrl);
13450 return 0;
13451 }
13452
13453 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
13454 buf, sizeof(buf));
13455
13456 wpa_ctrl_detach(ctrl);
13457 wpa_ctrl_close(ctrl);
13458
13459 if (res < 0) {
13460 send_resp(dut, conn, SIGMA_ERROR,
13461 "errorCode,Scan did not complete");
13462 return 0;
13463 }
13464
13465 snprintf(buf, sizeof(buf), "BSS %s", bssid);
13466 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
13467 strncmp(buf, "id=", 3) != 0) {
13468 send_resp(dut, conn, SIGMA_ERROR,
13469 "errorCode,Specified BSSID not found");
13470 return 0;
13471 }
13472
13473 pos = strstr(buf, "\nfreq=");
13474 if (!pos) {
13475 send_resp(dut, conn, SIGMA_ERROR,
13476 "errorCode,Channel not found");
13477 return 0;
13478 }
13479 freq = atoi(pos + 6);
13480 chan = freq_to_channel(freq);
13481
13482 pos = strstr(buf, "\nssid=");
13483 if (!pos) {
13484 send_resp(dut, conn, SIGMA_ERROR,
13485 "errorCode,SSID not found");
13486 return 0;
13487 }
13488 ssid = pos + 6;
13489 pos = strchr(ssid, '\n');
13490 if (pos)
13491 *pos = '\0';
13492 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
13493 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13494 return 0;
13495}
13496
13497
Jouni Malinenf7222712019-06-13 01:50:21 +030013498static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
13499 struct sigma_conn *conn,
13500 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013501{
13502#ifdef __linux__
13503 struct timeval tv;
13504 struct tm tm;
13505 time_t t;
13506 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013507 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013508
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013509 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013510
13511 memset(&tm, 0, sizeof(tm));
13512 val = get_param(cmd, "seconds");
13513 if (val)
13514 tm.tm_sec = atoi(val);
13515 val = get_param(cmd, "minutes");
13516 if (val)
13517 tm.tm_min = atoi(val);
13518 val = get_param(cmd, "hours");
13519 if (val)
13520 tm.tm_hour = atoi(val);
13521 val = get_param(cmd, "date");
13522 if (val)
13523 tm.tm_mday = atoi(val);
13524 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013525 if (val) {
13526 v = atoi(val);
13527 if (v < 1 || v > 12) {
13528 send_resp(dut, conn, SIGMA_INVALID,
13529 "errorCode,Invalid month");
13530 return 0;
13531 }
13532 tm.tm_mon = v - 1;
13533 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013534 val = get_param(cmd, "year");
13535 if (val) {
13536 int year = atoi(val);
13537#ifdef ANDROID
13538 if (year > 2035)
13539 year = 2035; /* years beyond 2035 not supported */
13540#endif /* ANDROID */
13541 tm.tm_year = year - 1900;
13542 }
13543 t = mktime(&tm);
13544 if (t == (time_t) -1) {
13545 send_resp(dut, conn, SIGMA_ERROR,
13546 "errorCode,Invalid date or time");
13547 return 0;
13548 }
13549
13550 memset(&tv, 0, sizeof(tv));
13551 tv.tv_sec = t;
13552
13553 if (settimeofday(&tv, NULL) < 0) {
13554 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
13555 strerror(errno));
13556 send_resp(dut, conn, SIGMA_ERROR,
13557 "errorCode,Failed to set time");
13558 return 0;
13559 }
13560
13561 return 1;
13562#endif /* __linux__ */
13563
13564 return -1;
13565}
13566
13567
Jouni Malinenf7222712019-06-13 01:50:21 +030013568static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
13569 struct sigma_conn *conn,
13570 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013571{
13572 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013573 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013574 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013575 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013576 int res;
13577 struct wpa_ctrl *ctrl;
13578
13579 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013580 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013581
13582 val = get_param(cmd, "ProdESSAssoc");
13583 if (val)
13584 prod_ess_assoc = atoi(val);
13585
13586 kill_dhcp_client(dut, intf);
13587 if (start_dhcp_client(dut, intf) < 0)
13588 return -2;
13589
13590 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
13591 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13592 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013593 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013594 prod_ess_assoc ? "" : "-N",
13595 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013596 name ? "'" : "",
13597 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
13598 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013599
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053013600 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013601 if (run_hs20_osu(dut, buf) < 0) {
13602 FILE *f;
13603
13604 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
13605
13606 f = fopen("hs20-osu-client.res", "r");
13607 if (f) {
13608 char resp[400], res[300], *pos;
13609 if (!fgets(res, sizeof(res), f))
13610 res[0] = '\0';
13611 pos = strchr(res, '\n');
13612 if (pos)
13613 *pos = '\0';
13614 fclose(f);
13615 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
13616 res);
13617 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
13618 if (system(resp) != 0) {
13619 }
13620 snprintf(resp, sizeof(resp),
13621 "SSID,,BSSID,,failureReason,%s", res);
13622 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13623 return 0;
13624 }
13625
13626 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13627 return 0;
13628 }
13629
13630 if (!prod_ess_assoc)
13631 goto report;
13632
13633 ctrl = open_wpa_mon(intf);
13634 if (ctrl == NULL) {
13635 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13636 "wpa_supplicant monitor connection");
13637 return -1;
13638 }
13639
13640 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13641 buf, sizeof(buf));
13642
13643 wpa_ctrl_detach(ctrl);
13644 wpa_ctrl_close(ctrl);
13645
13646 if (res < 0) {
13647 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
13648 "network after OSU");
13649 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13650 return 0;
13651 }
13652
13653report:
13654 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13655 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13656 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
13657 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13658 return 0;
13659 }
13660
13661 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
13662 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013663 return 0;
13664}
13665
13666
Jouni Malinenf7222712019-06-13 01:50:21 +030013667static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
13668 struct sigma_conn *conn,
13669 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013670{
13671 const char *val;
13672 int timeout = 120;
13673
13674 val = get_param(cmd, "PolicyUpdate");
13675 if (val == NULL || atoi(val) == 0)
13676 return 1; /* No operation requested */
13677
13678 val = get_param(cmd, "Timeout");
13679 if (val)
13680 timeout = atoi(val);
13681
13682 if (timeout) {
13683 /* TODO: time out the command and return
13684 * PolicyUpdateStatus,TIMEOUT if needed. */
13685 }
13686
13687 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
13688 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13689 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
13690 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
13691 return 0;
13692 }
13693
13694 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
13695 return 0;
13696}
13697
13698
Jouni Malinenf7222712019-06-13 01:50:21 +030013699static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
13700 struct sigma_conn *conn,
13701 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013702{
13703 struct wpa_ctrl *ctrl;
13704 const char *intf = get_param(cmd, "Interface");
13705 const char *bssid = get_param(cmd, "Bssid");
13706 const char *ssid = get_param(cmd, "SSID");
13707 const char *security = get_param(cmd, "Security");
13708 const char *passphrase = get_param(cmd, "Passphrase");
13709 const char *pin = get_param(cmd, "PIN");
13710 char buf[1000];
13711 char ssid_hex[200], passphrase_hex[200];
13712 const char *keymgmt, *cipher;
13713
13714 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013715 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013716
13717 if (!bssid) {
13718 send_resp(dut, conn, SIGMA_ERROR,
13719 "ErrorCode,Missing Bssid argument");
13720 return 0;
13721 }
13722
13723 if (!ssid) {
13724 send_resp(dut, conn, SIGMA_ERROR,
13725 "ErrorCode,Missing SSID argument");
13726 return 0;
13727 }
13728
13729 if (!security) {
13730 send_resp(dut, conn, SIGMA_ERROR,
13731 "ErrorCode,Missing Security argument");
13732 return 0;
13733 }
13734
13735 if (!passphrase) {
13736 send_resp(dut, conn, SIGMA_ERROR,
13737 "ErrorCode,Missing Passphrase argument");
13738 return 0;
13739 }
13740
13741 if (!pin) {
13742 send_resp(dut, conn, SIGMA_ERROR,
13743 "ErrorCode,Missing PIN argument");
13744 return 0;
13745 }
13746
vamsi krishna8c9c1562017-05-12 15:51:46 +053013747 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
13748 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013749 send_resp(dut, conn, SIGMA_ERROR,
13750 "ErrorCode,Too long SSID/passphrase");
13751 return 0;
13752 }
13753
13754 ctrl = open_wpa_mon(intf);
13755 if (ctrl == NULL) {
13756 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13757 "wpa_supplicant monitor connection");
13758 return -2;
13759 }
13760
13761 if (strcasecmp(security, "wpa2-psk") == 0) {
13762 keymgmt = "WPA2PSK";
13763 cipher = "CCMP";
13764 } else {
13765 wpa_ctrl_detach(ctrl);
13766 wpa_ctrl_close(ctrl);
13767 send_resp(dut, conn, SIGMA_ERROR,
13768 "ErrorCode,Unsupported Security value");
13769 return 0;
13770 }
13771
13772 ascii2hexstr(ssid, ssid_hex);
13773 ascii2hexstr(passphrase, passphrase_hex);
13774 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
13775 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
13776
13777 if (wpa_command(intf, buf) < 0) {
13778 wpa_ctrl_detach(ctrl);
13779 wpa_ctrl_close(ctrl);
13780 send_resp(dut, conn, SIGMA_ERROR,
13781 "ErrorCode,Failed to start registrar");
13782 return 0;
13783 }
13784
13785 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
13786 dut->er_oper_performed = 1;
13787
13788 return wps_connection_event(dut, conn, ctrl, intf, 0);
13789}
13790
13791
Jouni Malinenf7222712019-06-13 01:50:21 +030013792static enum sigma_cmd_result
13793cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
13794 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013795{
13796 struct wpa_ctrl *ctrl;
13797 const char *intf = get_param(cmd, "Interface");
13798 const char *bssid = get_param(cmd, "Bssid");
13799 char buf[100];
13800
13801 if (!bssid) {
13802 send_resp(dut, conn, SIGMA_ERROR,
13803 "ErrorCode,Missing Bssid argument");
13804 return 0;
13805 }
13806
13807 ctrl = open_wpa_mon(intf);
13808 if (ctrl == NULL) {
13809 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13810 "wpa_supplicant monitor connection");
13811 return -2;
13812 }
13813
13814 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
13815
13816 if (wpa_command(intf, buf) < 0) {
13817 wpa_ctrl_detach(ctrl);
13818 wpa_ctrl_close(ctrl);
13819 send_resp(dut, conn, SIGMA_ERROR,
13820 "ErrorCode,Failed to start registrar");
13821 return 0;
13822 }
13823
13824 return wps_connection_event(dut, conn, ctrl, intf, 0);
13825}
13826
13827
Jouni Malinenf7222712019-06-13 01:50:21 +030013828static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
13829 struct sigma_conn *conn,
13830 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053013831{
13832 struct wpa_ctrl *ctrl;
13833 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013834 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013835 const char *config_method = get_param(cmd, "WPSConfigMethod");
13836 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053013837 int res;
13838 char buf[256];
13839 const char *events[] = {
13840 "CTRL-EVENT-CONNECTED",
13841 "WPS-OVERLAP-DETECTED",
13842 "WPS-TIMEOUT",
13843 "WPS-FAIL",
13844 NULL
13845 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013846 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053013847
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013848 /* 60G WPS tests do not pass Interface parameter */
13849 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013850 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013851
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013852 if (dut->mode == SIGMA_MODE_AP)
13853 return ap_wps_registration(dut, conn, cmd);
13854
13855 if (config_method) {
13856 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
13857 * sta_wps_enter_pin before calling start_wps_registration. */
13858 if (strcasecmp(config_method, "PBC") == 0)
13859 dut->wps_method = WFA_CS_WPS_PBC;
13860 }
13861 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
13862 send_resp(dut, conn, SIGMA_ERROR,
13863 "ErrorCode,WPS parameters not yet set");
13864 return STATUS_SENT;
13865 }
13866
13867 /* Make sure WPS is enabled (also for STA mode) */
13868 dut->wps_disable = 0;
13869
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013870 if (dut->band == WPS_BAND_60G && network_mode &&
13871 strcasecmp(network_mode, "PBSS") == 0) {
13872 sigma_dut_print(dut, DUT_MSG_DEBUG,
13873 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013874 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013875 return -2;
13876 }
13877
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013878 if (dut->force_rsn_ie) {
13879 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
13880 dut->force_rsn_ie);
13881 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
13882 sigma_dut_print(dut, DUT_MSG_INFO,
13883 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020013884 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013885 }
13886 }
13887
vamsi krishna9b144002017-09-20 13:28:13 +053013888 ctrl = open_wpa_mon(intf);
13889 if (!ctrl) {
13890 sigma_dut_print(dut, DUT_MSG_ERROR,
13891 "Failed to open wpa_supplicant monitor connection");
13892 return -2;
13893 }
13894
13895 role = get_param(cmd, "WpsRole");
13896 if (!role) {
13897 send_resp(dut, conn, SIGMA_INVALID,
13898 "ErrorCode,WpsRole not provided");
13899 goto fail;
13900 }
13901
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013902 if (strcasecmp(role, "Enrollee") != 0) {
13903 /* Registrar role for STA not supported */
13904 send_resp(dut, conn, SIGMA_ERROR,
13905 "ErrorCode,Unsupported WpsRole value");
13906 goto fail;
13907 }
13908
13909 if (is_60g_sigma_dut(dut)) {
13910 if (dut->wps_method == WFA_CS_WPS_PBC)
13911 snprintf(buf, sizeof(buf), "WPS_PBC");
13912 else /* WFA_CS_WPS_PIN_KEYPAD */
13913 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
13914 dut->wps_pin);
13915 if (wpa_command(intf, buf) < 0) {
13916 send_resp(dut, conn, SIGMA_ERROR,
13917 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053013918 goto fail;
13919 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013920 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13921 if (res < 0) {
13922 send_resp(dut, conn, SIGMA_ERROR,
13923 "ErrorCode,WPS connection did not complete");
13924 goto fail;
13925 }
13926 if (strstr(buf, "WPS-TIMEOUT")) {
13927 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
13928 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13929 send_resp(dut, conn, SIGMA_COMPLETE,
13930 "WpsState,OverlapSession");
13931 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13932 send_resp(dut, conn, SIGMA_COMPLETE,
13933 "WpsState,Successful");
13934 } else {
13935 send_resp(dut, conn, SIGMA_COMPLETE,
13936 "WpsState,Failure");
13937 }
13938 } else {
13939 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053013940 if (wpa_command(intf, "WPS_PBC") < 0) {
13941 send_resp(dut, conn, SIGMA_ERROR,
13942 "ErrorCode,Failed to enable PBC");
13943 goto fail;
13944 }
13945 } else {
13946 /* TODO: PIN method */
13947 send_resp(dut, conn, SIGMA_ERROR,
13948 "ErrorCode,Unsupported WpsConfigMethod value");
13949 goto fail;
13950 }
13951 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13952 if (res < 0) {
13953 send_resp(dut, conn, SIGMA_ERROR,
13954 "ErrorCode,WPS connection did not complete");
13955 goto fail;
13956 }
13957 if (strstr(buf, "WPS-TIMEOUT")) {
13958 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
13959 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13960 send_resp(dut, conn, SIGMA_ERROR,
13961 "ErrorCode,OverlapSession");
13962 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13963 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
13964 } else {
13965 send_resp(dut, conn, SIGMA_ERROR,
13966 "ErrorCode,WPS operation failed");
13967 }
vamsi krishna9b144002017-09-20 13:28:13 +053013968 }
13969
13970fail:
13971 wpa_ctrl_detach(ctrl);
13972 wpa_ctrl_close(ctrl);
13973 return 0;
13974}
13975
13976
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013977static int req_intf(struct sigma_cmd *cmd)
13978{
13979 return get_param(cmd, "interface") == NULL ? -1 : 0;
13980}
13981
13982
13983void sta_register_cmds(void)
13984{
13985 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
13986 cmd_sta_get_ip_config);
13987 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
13988 cmd_sta_set_ip_config);
13989 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
13990 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
13991 cmd_sta_get_mac_address);
13992 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
13993 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
13994 cmd_sta_verify_ip_connection);
13995 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
13996 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
13997 cmd_sta_set_encryption);
13998 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
13999 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
14000 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
14001 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
14002 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
14003 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
14004 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
14005 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
14006 cmd_sta_set_eapakaprime);
14007 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
14008 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
14009 /* TODO: sta_set_ibss */
14010 /* TODO: sta_set_mode */
14011 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
14012 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
14013 /* TODO: sta_up_load */
14014 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
14015 cmd_sta_preset_testparameters);
14016 /* TODO: sta_set_system */
14017 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
14018 /* TODO: sta_set_rifs_test */
14019 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
14020 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
14021 /* TODO: sta_send_coexist_mgmt */
14022 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
14023 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
14024 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
14025 sigma_dut_reg_cmd("sta_reset_default", req_intf,
14026 cmd_sta_reset_default);
14027 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
14028 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
14029 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
14030 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
14031 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014032 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014033 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
14034 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
14035 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
14036 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
14037 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030014038 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
14039 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014040 sigma_dut_reg_cmd("sta_add_credential", req_intf,
14041 cmd_sta_add_credential);
14042 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020014043 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014044 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
14045 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
14046 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
14047 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
14048 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
14049 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030014050 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014051 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
14052 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014053 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053014054 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014055}