blob: 41762d3229784e050fa57e3c20e4458b101864a0 [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
4267 struct nl_msg *msg;
4268 int ret = 0;
4269 struct nlattr *params;
4270 int ifindex;
4271 int wmmenable = 1;
4272
4273 if (val &&
4274 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4275 wmmenable = 0;
4276
4277 ifindex = if_nametoindex(intf);
4278 if (ifindex == 0) {
4279 sigma_dut_print(dut, DUT_MSG_ERROR,
4280 "%s: Index for interface %s failed",
4281 __func__, intf);
4282 return -1;
4283 }
4284
4285 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4286 NL80211_CMD_VENDOR)) ||
4287 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4288 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4289 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4290 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4291 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4292 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4293 wmmenable)) {
4294 sigma_dut_print(dut, DUT_MSG_ERROR,
4295 "%s: err in adding vendor_cmd and vendor_data",
4296 __func__);
4297 nlmsg_free(msg);
4298 return -1;
4299 }
4300 nla_nest_end(msg, params);
4301
4302 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4303 if (ret) {
4304 sigma_dut_print(dut, DUT_MSG_ERROR,
4305 "%s: err in send_and_recv_msgs, ret=%d",
4306 __func__, ret);
4307 }
4308 return ret;
4309#else /* NL80211_SUPPORT */
4310 sigma_dut_print(dut, DUT_MSG_ERROR,
4311 "WMM cannot be changed without NL80211_SUPPORT defined");
4312 return -1;
4313#endif /* NL80211_SUPPORT */
4314}
4315
4316
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004317static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4318 const char *val)
4319{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004320 int sgi20;
4321
4322 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4323
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004324 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004325}
4326
4327
4328static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4329 const char *val)
4330{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304331 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004332
4333 /* Disable Tx Beam forming when using a fixed rate */
4334 ath_disable_txbf(dut, intf);
4335
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304336 v = atoi(val);
4337 if (v < 0 || v > 32) {
4338 sigma_dut_print(dut, DUT_MSG_ERROR,
4339 "Invalid Fixed MCS rate: %d", v);
4340 return;
4341 }
4342 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004343
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004344 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004345
4346 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004347 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004348}
4349
4350
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004351static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4352 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004353{
4354 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304355 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004356
4357 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4358 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4359 else
4360 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4361
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304362 ret = system(buf);
4363#ifdef NL80211_SUPPORT
4364 if (ret) {
4365 int value = (strcasecmp(val, "Enable") == 0) ? 2 : 1;
4366
4367 ret = sta_config_params(dut, intf, STA_SET_TX_MSDU, value);
4368 ret |= sta_config_params(dut, intf, STA_SET_RX_MSDU, value);
4369 }
4370#endif /* NL80211_SUPPORT */
4371 if (ret)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004372 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4373}
4374
4375
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004376static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4377 int ampdu)
4378{
4379 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004380 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004381
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004382 if (ampdu)
4383 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004384 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4385 if (system(buf) != 0) {
4386 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4387 return -1;
4388 }
4389
4390 return 0;
4391}
4392
4393
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004394static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4395 const char *val)
4396{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004397 run_iwpriv(dut, intf, "tx_stbc %s", val);
4398 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004399}
4400
4401
4402static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4403 const char *val)
4404{
4405 char buf[60];
4406
Peng Xucc317ed2017-05-18 16:44:37 -07004407 if (strcmp(val, "160") == 0) {
4408 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4409 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004410 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4411 } else if (strcmp(val, "40") == 0) {
4412 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4413 } else if (strcmp(val, "20") == 0) {
4414 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4415 } else if (strcasecmp(val, "Auto") == 0) {
4416 buf[0] = '\0';
4417 } else {
4418 sigma_dut_print(dut, DUT_MSG_ERROR,
4419 "WIDTH/CTS_WIDTH value not supported");
4420 return -1;
4421 }
4422
4423 if (buf[0] != '\0' && system(buf) != 0) {
4424 sigma_dut_print(dut, DUT_MSG_ERROR,
4425 "Failed to set WIDTH/CTS_WIDTH");
4426 return -1;
4427 }
4428
4429 return 0;
4430}
4431
4432
4433int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4434 const char *intf, const char *val)
4435{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004436 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004437 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004438 dut->chwidth = 0;
4439 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004440 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004441 dut->chwidth = 0;
4442 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004443 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004444 dut->chwidth = 1;
4445 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004446 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004447 dut->chwidth = 2;
4448 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004449 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004450 dut->chwidth = 3;
4451 } else {
4452 send_resp(dut, conn, SIGMA_ERROR,
4453 "ErrorCode,WIDTH not supported");
4454 return -1;
4455 }
4456
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004457 return 0;
4458}
4459
4460
4461static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4462 const char *val)
4463{
4464 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004465 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004466
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004467 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004468 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004469 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004470 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004471 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004472 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004473 } else {
4474 sigma_dut_print(dut, DUT_MSG_ERROR,
4475 "SP_STREAM value not supported");
4476 return -1;
4477 }
4478
4479 if (system(buf) != 0) {
4480 sigma_dut_print(dut, DUT_MSG_ERROR,
4481 "Failed to set SP_STREAM");
4482 return -1;
4483 }
4484
Arif Hussainac6c5112018-05-25 17:34:00 -07004485 dut->sta_nss = sta_nss;
4486
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004487 return 0;
4488}
4489
4490
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304491static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4492 const char *val)
4493{
4494 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304495 int ret;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304496
4497 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304498 ret = system(buf);
4499#ifdef NL80211_SUPPORT
4500 if (ret)
4501 ret = sta_config_params(dut, intf, STA_SET_TX_STBC,
4502 strcmp(val, "0") == 0 ? 0 : 1);
4503#endif /* NL80211_SUPPORT */
4504 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304505 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4506
4507 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304508 ret = system(buf);
4509#ifdef NL80211_SUPPORT
4510 if (ret)
4511 ret = sta_config_params(dut, intf, STA_SET_RX_STBC,
4512 strcmp(val, "0") == 0 ? 0 : 1);
4513#endif /* NL80211_SUPPORT */
4514 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304515 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4516}
4517
4518
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304519static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4520 struct sigma_conn *conn,
4521 const char *intf, int capa)
4522{
4523 char buf[32];
4524
4525 if (capa > 0 && capa < 4) {
4526 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4527 if (wpa_command(intf, buf) < 0) {
4528 send_resp(dut, conn, SIGMA_ERROR,
4529 "ErrorCode, Failed to set cellular data capability");
4530 return 0;
4531 }
4532 return 1;
4533 }
4534
4535 sigma_dut_print(dut, DUT_MSG_ERROR,
4536 "Invalid Cellular data capability: %d", capa);
4537 send_resp(dut, conn, SIGMA_INVALID,
4538 "ErrorCode,Invalid cellular data capability");
4539 return 0;
4540}
4541
4542
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304543static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4544 const char *intf, const char *val)
4545{
4546 if (strcasecmp(val, "Disable") == 0) {
4547 if (wpa_command(intf, "SET roaming 0") < 0) {
4548 send_resp(dut, conn, SIGMA_ERROR,
4549 "ErrorCode,Failed to disable roaming");
4550 return 0;
4551 }
4552 return 1;
4553 }
4554
4555 if (strcasecmp(val, "Enable") == 0) {
4556 if (wpa_command(intf, "SET roaming 1") < 0) {
4557 send_resp(dut, conn, SIGMA_ERROR,
4558 "ErrorCode,Failed to enable roaming");
4559 return 0;
4560 }
4561 return 1;
4562 }
4563
4564 sigma_dut_print(dut, DUT_MSG_ERROR,
4565 "Invalid value provided for roaming: %s", val);
4566 send_resp(dut, conn, SIGMA_INVALID,
4567 "ErrorCode,Unknown value provided for Roaming");
4568 return 0;
4569}
4570
4571
Ashwini Patila75de5a2017-04-13 16:35:05 +05304572static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4573 struct sigma_conn *conn,
4574 const char *intf, const char *val)
4575{
4576 if (strcasecmp(val, "Disable") == 0) {
4577 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4578 send_resp(dut, conn, SIGMA_ERROR,
4579 "ErrorCode,Failed to disable Assoc_disallow");
4580 return 0;
4581 }
4582 return 1;
4583 }
4584
4585 if (strcasecmp(val, "Enable") == 0) {
4586 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4587 send_resp(dut, conn, SIGMA_ERROR,
4588 "ErrorCode,Failed to enable Assoc_disallow");
4589 return 0;
4590 }
4591 return 1;
4592 }
4593
4594 sigma_dut_print(dut, DUT_MSG_ERROR,
4595 "Invalid value provided for Assoc_disallow: %s", val);
4596 send_resp(dut, conn, SIGMA_INVALID,
4597 "ErrorCode,Unknown value provided for Assoc_disallow");
4598 return 0;
4599}
4600
4601
Ashwini Patilc63161e2017-04-13 16:30:23 +05304602static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4603 const char *intf, const char *val)
4604{
4605 if (strcasecmp(val, "Reject") == 0) {
4606 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4607 send_resp(dut, conn, SIGMA_ERROR,
4608 "ErrorCode,Failed to Reject BTM Request");
4609 return 0;
4610 }
4611 return 1;
4612 }
4613
4614 if (strcasecmp(val, "Accept") == 0) {
4615 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4616 send_resp(dut, conn, SIGMA_ERROR,
4617 "ErrorCode,Failed to Accept BTM Request");
4618 return 0;
4619 }
4620 return 1;
4621 }
4622
4623 sigma_dut_print(dut, DUT_MSG_ERROR,
4624 "Invalid value provided for BSS_Transition: %s", val);
4625 send_resp(dut, conn, SIGMA_INVALID,
4626 "ErrorCode,Unknown value provided for BSS_Transition");
4627 return 0;
4628}
4629
4630
Ashwini Patil00402582017-04-13 12:29:39 +05304631static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4632 struct sigma_conn *conn,
4633 const char *intf,
4634 struct sigma_cmd *cmd)
4635{
4636 const char *ch, *pref, *op_class, *reason;
4637 char buf[120];
4638 int len, ret;
4639
4640 pref = get_param(cmd, "Ch_Pref");
4641 if (!pref)
4642 return 1;
4643
4644 if (strcasecmp(pref, "clear") == 0) {
4645 free(dut->non_pref_ch_list);
4646 dut->non_pref_ch_list = NULL;
4647 } else {
4648 op_class = get_param(cmd, "Ch_Op_Class");
4649 if (!op_class) {
4650 send_resp(dut, conn, SIGMA_INVALID,
4651 "ErrorCode,Ch_Op_Class not provided");
4652 return 0;
4653 }
4654
4655 ch = get_param(cmd, "Ch_Pref_Num");
4656 if (!ch) {
4657 send_resp(dut, conn, SIGMA_INVALID,
4658 "ErrorCode,Ch_Pref_Num not provided");
4659 return 0;
4660 }
4661
4662 reason = get_param(cmd, "Ch_Reason_Code");
4663 if (!reason) {
4664 send_resp(dut, conn, SIGMA_INVALID,
4665 "ErrorCode,Ch_Reason_Code not provided");
4666 return 0;
4667 }
4668
4669 if (!dut->non_pref_ch_list) {
4670 dut->non_pref_ch_list =
4671 calloc(1, NON_PREF_CH_LIST_SIZE);
4672 if (!dut->non_pref_ch_list) {
4673 send_resp(dut, conn, SIGMA_ERROR,
4674 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4675 return 0;
4676 }
4677 }
4678 len = strlen(dut->non_pref_ch_list);
4679 ret = snprintf(dut->non_pref_ch_list + len,
4680 NON_PREF_CH_LIST_SIZE - len,
4681 " %s:%s:%s:%s", op_class, ch, pref, reason);
4682 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4683 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4684 dut->non_pref_ch_list);
4685 } else {
4686 sigma_dut_print(dut, DUT_MSG_ERROR,
4687 "snprintf failed for non_pref_list, ret = %d",
4688 ret);
4689 send_resp(dut, conn, SIGMA_ERROR,
4690 "ErrorCode,snprintf failed");
4691 free(dut->non_pref_ch_list);
4692 dut->non_pref_ch_list = NULL;
4693 return 0;
4694 }
4695 }
4696
4697 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4698 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4699 if (ret < 0 || ret >= (int) sizeof(buf)) {
4700 sigma_dut_print(dut, DUT_MSG_DEBUG,
4701 "snprintf failed for set non_pref_chan, ret: %d",
4702 ret);
4703 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4704 return 0;
4705 }
4706
4707 if (wpa_command(intf, buf) < 0) {
4708 send_resp(dut, conn, SIGMA_ERROR,
4709 "ErrorCode,Failed to set non-preferred channel list");
4710 return 0;
4711 }
4712
4713 return 1;
4714}
4715
4716
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004717#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004718
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004719static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4720 uint8_t cfg)
4721{
4722 struct nl_msg *msg;
4723 int ret = 0;
4724 struct nlattr *params;
4725 int ifindex;
4726
4727 ifindex = if_nametoindex(intf);
4728 if (ifindex == 0) {
4729 sigma_dut_print(dut, DUT_MSG_ERROR,
4730 "%s: Index for interface %s failed",
4731 __func__, intf);
4732 return -1;
4733 }
4734
4735 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4736 NL80211_CMD_VENDOR)) ||
4737 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4738 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4739 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4740 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4741 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4742 nla_put_u8(msg,
4743 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4744 cfg)) {
4745 sigma_dut_print(dut, DUT_MSG_ERROR,
4746 "%s: err in adding vendor_cmd and vendor_data",
4747 __func__);
4748 nlmsg_free(msg);
4749 return -1;
4750 }
4751 nla_nest_end(msg, params);
4752
4753 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4754 if (ret) {
4755 sigma_dut_print(dut, DUT_MSG_ERROR,
4756 "%s: err in send_and_recv_msgs, ret=%d",
4757 __func__, ret);
4758 }
4759 return ret;
4760}
4761
4762
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004763static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4764 enum he_fragmentation_val frag)
4765{
4766 struct nl_msg *msg;
4767 int ret = 0;
4768 struct nlattr *params;
4769 int ifindex;
4770
4771 ifindex = if_nametoindex(intf);
4772 if (ifindex == 0) {
4773 sigma_dut_print(dut, DUT_MSG_ERROR,
4774 "%s: Index for interface %s failed",
4775 __func__, intf);
4776 return -1;
4777 }
4778
4779 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4780 NL80211_CMD_VENDOR)) ||
4781 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4782 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4783 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4784 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4785 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4786 nla_put_u8(msg,
4787 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
4788 frag)) {
4789 sigma_dut_print(dut, DUT_MSG_ERROR,
4790 "%s: err in adding vendor_cmd and vendor_data",
4791 __func__);
4792 nlmsg_free(msg);
4793 return -1;
4794 }
4795 nla_nest_end(msg, params);
4796
4797 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4798 if (ret) {
4799 sigma_dut_print(dut, DUT_MSG_ERROR,
4800 "%s: err in send_and_recv_msgs, ret=%d",
4801 __func__, ret);
4802 }
4803 return ret;
4804}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004805
4806
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08004807int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
4808 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004809{
4810 struct nl_msg *msg;
4811 int ret = 0;
4812 struct nlattr *params;
4813 int ifindex;
4814
4815 ifindex = if_nametoindex(intf);
4816 if (ifindex == 0) {
4817 sigma_dut_print(dut, DUT_MSG_ERROR,
4818 "%s: Index for interface %s failed",
4819 __func__, intf);
4820 return -1;
4821 }
4822
4823 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4824 NL80211_CMD_VENDOR)) ||
4825 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4826 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4827 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4828 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4829 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4830 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
4831 ltf)) {
4832 sigma_dut_print(dut, DUT_MSG_ERROR,
4833 "%s: err in adding vendor_cmd and vendor_data",
4834 __func__);
4835 nlmsg_free(msg);
4836 return -1;
4837 }
4838 nla_nest_end(msg, params);
4839
4840 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4841 if (ret) {
4842 sigma_dut_print(dut, DUT_MSG_ERROR,
4843 "%s: err in send_and_recv_msgs, ret=%d",
4844 __func__, ret);
4845 }
4846 return ret;
4847}
4848
4849
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004850static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4851 int noack, enum qca_wlan_ac_type ac)
4852{
4853 struct nl_msg *msg;
4854 int ret = 0;
4855 struct nlattr *params;
4856 int ifindex;
4857
4858 ifindex = if_nametoindex(intf);
4859 if (ifindex == 0) {
4860 sigma_dut_print(dut, DUT_MSG_ERROR,
4861 "%s: Index for interface %s failed",
4862 __func__, intf);
4863 return -1;
4864 }
4865
4866 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4867 NL80211_CMD_VENDOR)) ||
4868 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4869 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4870 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4871 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4872 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4873 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4874 noack) ||
4875 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4876 ac)) {
4877 sigma_dut_print(dut, DUT_MSG_ERROR,
4878 "%s: err in adding vendor_cmd and vendor_data",
4879 __func__);
4880 nlmsg_free(msg);
4881 return -1;
4882 }
4883 nla_nest_end(msg, params);
4884
4885 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4886 if (ret) {
4887 sigma_dut_print(dut, DUT_MSG_ERROR,
4888 "%s: err in send_and_recv_msgs, ret=%d",
4889 __func__, ret);
4890 }
4891 return ret;
4892}
4893
4894
4895static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4896 const char *val)
4897{
4898 int noack, ret;
4899 char token[100];
4900 char *result;
4901 char *saveptr;
4902 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4903
4904 strlcpy(token, val, sizeof(token));
4905 token[sizeof(token) - 1] = '\0';
4906 result = strtok_r(token, ":", &saveptr);
4907 while (result) {
4908 noack = strcasecmp(result, "Disable") != 0;
4909 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4910 if (ret) {
4911 sigma_dut_print(dut, DUT_MSG_ERROR,
4912 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4913 ac, ret);
4914 }
4915 result = strtok_r(NULL, ":", &saveptr);
4916 ac++;
4917 }
4918}
4919
Vinita S. Maloo7462e812020-05-22 15:16:04 +05304920
4921static int nlvendor_sta_set_phymode(struct sigma_dut *dut, const char *intf,
4922 enum qca_wlan_vendor_phy_mode val)
4923{
4924 struct nl_msg *msg;
4925 struct nlattr *params;
4926 int ifindex, ret;
4927
4928 ifindex = if_nametoindex(intf);
4929 if (ifindex == 0) {
4930 sigma_dut_print(dut, DUT_MSG_ERROR,
4931 "%s: Index for interface %s not found",
4932 __func__, intf);
4933 return -1;
4934 }
4935
4936 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4937 NL80211_CMD_VENDOR);
4938 if (!msg) {
4939 sigma_dut_print(dut, DUT_MSG_ERROR,
4940 "%s: err in adding vendor_cmd", __func__);
4941 return -1;
4942 }
4943
4944 if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4945 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4946 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) {
4947 sigma_dut_print(dut, DUT_MSG_ERROR,
4948 "%s: err in adding vendor_attr", __func__);
4949 nlmsg_free(msg);
4950 return -1;
4951 }
4952
4953 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
4954 if (!params || nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_PHY_MODE,
4955 val)) {
4956 sigma_dut_print(dut, DUT_MSG_ERROR,
4957 "%s: err in adding vendor_data", __func__);
4958 nlmsg_free(msg);
4959 return -1;
4960 }
4961
4962 nla_nest_end(msg, params);
4963 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4964 if (ret) {
4965 sigma_dut_print(dut, DUT_MSG_ERROR,
4966 "%s: err in send_and_recv_msgs, ret=%d (%s)",
4967 __func__, ret, strerror(-ret));
4968 return ret;
4969 }
4970
4971 return 0;
4972}
4973
4974
4975static enum qca_wlan_vendor_phy_mode get_qca_vendor_phymode(const char *val)
4976{
4977 if (strcmp(val, "11a") == 0) {
4978 /* IEEE80211_MODE_11A */
4979 return QCA_WLAN_VENDOR_PHY_MODE_11A;
4980 }
4981
4982 if (strcmp(val, "11g") == 0) {
4983 /* IEEE80211_MODE_11G */
4984 return QCA_WLAN_VENDOR_PHY_MODE_11G;
4985 }
4986
4987 if (strcmp(val, "11b") == 0) {
4988 /* IEEE80211_MODE_11B */
4989 return QCA_WLAN_VENDOR_PHY_MODE_11B;
4990 }
4991
4992 if (strcmp(val, "11n") == 0 ||
4993 strcmp(val, "11nl") == 0 ||
4994 strcmp(val, "11nl(nabg)") == 0) {
4995 /* IEEE80211_MODE_11AGN */
4996 return QCA_WLAN_VENDOR_PHY_MODE_11AGN;
4997 }
4998
4999 if (strcmp(val, "11ng") == 0) {
5000 /* IEEE80211_MODE_11NG_HT40 */
5001 return QCA_WLAN_VENDOR_PHY_MODE_11NG_HT40;
5002 }
5003
5004 if (strcmp(val, "AC") == 0 ||
5005 strcasecmp(val, "11AC") == 0) {
5006 /* IEEE80211_MODE_11AC_VHT80 */
5007 return QCA_WLAN_VENDOR_PHY_MODE_11AC_VHT80;
5008 }
5009
5010 if (strcmp(val, "11na") == 0 ||
5011 strcasecmp(val, "11an") == 0) {
5012 /* IEEE80211_MODE_11NA_HT40 */
5013 return QCA_WLAN_VENDOR_PHY_MODE_11NA_HT40;
5014 }
5015
5016 if (strcmp(val, "11ax") == 0 ||
5017 strcmp(val, "auto") == 0) {
5018 /* IEEE80211_MODE_AUTO */
5019 return QCA_WLAN_VENDOR_PHY_MODE_AUTO;
5020 }
5021
5022 return -1;
5023}
5024
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005025#endif /* NL80211_SUPPORT */
5026
5027
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305028static int get_phymode(const char *val)
5029{
5030 if (strcmp(val, "11a") == 0)
5031 return 1; /* IEEE80211_MODE_11A */
5032 if (strcmp(val, "11g") == 0)
5033 return 3; /* IEEE80211_MODE_11G */
5034 if (strcmp(val, "11b") == 0)
5035 return 2; /* IEEE80211_MODE_11B */
5036 if (strcmp(val, "11n") == 0 ||
5037 strcmp(val, "11nl") == 0 ||
5038 strcmp(val, "11nl(nabg)") == 0)
5039 return 22; /* IEEE80211_MODE_11AGN */
5040 if (strcmp(val, "11ng") == 0)
5041 return 13; /* IEEE80211_MODE_11NG_HT40 */
5042 if (strcmp(val, "AC") == 0 ||
5043 strcasecmp(val, "11AC") == 0)
5044 return 19; /* IEEE80211_MODE_11AC_VHT80 */
5045 if (strcmp(val, "11na") == 0 ||
5046 strcasecmp(val, "11an") == 0)
5047 return 14; /* IEEE80211_MODE_11NA_HT40 */
5048 if (strcmp(val, "11ax") == 0 ||
5049 strcmp(val, "auto") == 0)
5050 return 0; /* IEEE80211_MODE_AUTO */
5051 return -1;
5052}
5053
5054
5055static void sta_set_phymode(struct sigma_dut *dut, const char *intf,
5056 const char *val)
5057{
5058 char buf[100];
5059 int len, phymode;
Vinita S. Maloo7462e812020-05-22 15:16:04 +05305060#ifdef NL80211_SUPPORT
5061 enum qca_wlan_vendor_phy_mode qca_phymode;
5062
5063 qca_phymode = get_qca_vendor_phymode(val);
5064 if (qca_phymode == -1) {
5065 sigma_dut_print(dut, DUT_MSG_DEBUG,
5066 "Ignoring mode change for mode: %s",
5067 val);
5068 return;
5069 }
5070
5071 if (nlvendor_sta_set_phymode(dut, intf, qca_phymode) == 0)
5072 return;
5073#endif /* NL80211_SUPPORT */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305074
5075 phymode = get_phymode(val);
5076 if (phymode == -1) {
5077 sigma_dut_print(dut, DUT_MSG_DEBUG,
5078 "Ignoring mode change for mode: %s",
5079 val);
5080 return;
5081 }
5082
5083 len = snprintf(buf, sizeof(buf), "iwpriv %s setphymode %d", intf,
5084 phymode);
5085 if (len < 0 || len >= sizeof(buf)) {
5086 sigma_dut_print(dut, DUT_MSG_ERROR,
5087 "Failed to set phymode");
5088 return;
5089 }
5090
5091 if (system(buf) != 0)
5092 sigma_dut_print(dut, DUT_MSG_ERROR,
5093 "iwpriv setting of phymode failed");
5094}
5095
5096
Jouni Malinenf7222712019-06-13 01:50:21 +03005097static enum sigma_cmd_result
5098cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
5099 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005100{
5101 const char *intf = get_param(cmd, "Interface");
5102 const char *val;
5103
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03005104 val = get_param(cmd, "FT_DS");
5105 if (val) {
5106 if (strcasecmp(val, "Enable") == 0) {
5107 dut->sta_ft_ds = 1;
5108 } else if (strcasecmp(val, "Disable") == 0) {
5109 dut->sta_ft_ds = 0;
5110 } else {
5111 send_resp(dut, conn, SIGMA_ERROR,
5112 "errorCode,Unsupported value for FT_DS");
5113 return STATUS_SENT_ERROR;
5114 }
5115 }
5116
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005117 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03005118 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
5119 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005120 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
5121 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005122
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005123 if (val && strcasecmp(val, "LOC") == 0)
5124 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02005125 if (val && strcasecmp(val, "60GHZ") == 0) {
5126 val = get_param(cmd, "WPS");
5127 if (val && strcasecmp(val, "disable") == 0) {
5128 dut->wps_disable = 1;
5129 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
5130 } else {
5131 /* wps_disable can have other value from the previous
5132 * test, so make sure it has the correct value.
5133 */
5134 dut->wps_disable = 0;
5135 }
5136
5137 val = get_param(cmd, "P2P");
5138 if (val && strcasecmp(val, "disable") == 0)
5139 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
5140 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005141
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02005142 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
5143 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
5144
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005145#ifdef ANDROID_NAN
5146 if (val && strcasecmp(val, "NAN") == 0)
5147 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
5148#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005149#ifdef MIRACAST
5150 if (val && (strcasecmp(val, "WFD") == 0 ||
5151 strcasecmp(val, "DisplayR2") == 0))
5152 return miracast_preset_testparameters(dut, conn, cmd);
5153#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005154
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07005155 if (val &&
5156 (strcasecmp(val, "MBO") == 0 || strcasecmp(val, "HE") == 0)) {
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305157 val = get_param(cmd, "Cellular_Data_Cap");
5158 if (val &&
5159 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
5160 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05305161
5162 val = get_param(cmd, "Ch_Pref");
5163 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
5164 return 0;
5165
Ashwini Patilc63161e2017-04-13 16:30:23 +05305166 val = get_param(cmd, "BSS_Transition");
5167 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
5168 return 0;
5169
Ashwini Patila75de5a2017-04-13 16:35:05 +05305170 val = get_param(cmd, "Assoc_Disallow");
5171 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
5172 return 0;
5173
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305174 val = get_param(cmd, "Roaming");
5175 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
5176 return 0;
5177
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305178 return 1;
5179 }
5180
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305181 if (val && strcasecmp(val, "OCE") == 0)
5182 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
5183
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005184#if 0
5185 val = get_param(cmd, "Supplicant");
5186 if (val && strcasecmp(val, "Default") != 0) {
5187 send_resp(dut, conn, SIGMA_ERROR,
5188 "ErrorCode,Only default(Vendor) supplicant "
5189 "supported");
5190 return 0;
5191 }
5192#endif
5193
5194 val = get_param(cmd, "RTS");
5195 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005196 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005197 case DRIVER_ATHEROS:
5198 ath_sta_set_rts(dut, intf, val);
5199 break;
5200 default:
5201#if 0
5202 send_resp(dut, conn, SIGMA_ERROR,
5203 "ErrorCode,Setting RTS not supported");
5204 return 0;
5205#else
5206 sigma_dut_print(dut, DUT_MSG_DEBUG,
5207 "Setting RTS not supported");
5208 break;
5209#endif
5210 }
5211 }
5212
5213#if 0
5214 val = get_param(cmd, "FRGMNT");
5215 if (val) {
5216 /* TODO */
5217 send_resp(dut, conn, SIGMA_ERROR,
5218 "ErrorCode,Setting FRGMNT not supported");
5219 return 0;
5220 }
5221#endif
5222
5223#if 0
5224 val = get_param(cmd, "Preamble");
5225 if (val) {
5226 /* TODO: Long/Short */
5227 send_resp(dut, conn, SIGMA_ERROR,
5228 "ErrorCode,Setting Preamble not supported");
5229 return 0;
5230 }
5231#endif
5232
5233 val = get_param(cmd, "Mode");
5234 if (val) {
5235 if (strcmp(val, "11b") == 0 ||
5236 strcmp(val, "11g") == 0 ||
5237 strcmp(val, "11a") == 0 ||
5238 strcmp(val, "11n") == 0 ||
5239 strcmp(val, "11ng") == 0 ||
5240 strcmp(val, "11nl") == 0 ||
5241 strcmp(val, "11nl(nabg)") == 0 ||
5242 strcmp(val, "AC") == 0 ||
5243 strcmp(val, "11AC") == 0 ||
5244 strcmp(val, "11ac") == 0 ||
5245 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08005246 strcmp(val, "11an") == 0 ||
5247 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005248 /* STA supports all modes by default */
5249 } else {
5250 send_resp(dut, conn, SIGMA_ERROR,
5251 "ErrorCode,Setting Mode not supported");
5252 return 0;
5253 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005254
5255 /* Change the mode only in case of testbed for HE program
5256 * and for 11a and 11g modes only. */
5257 if (dut->program == PROGRAM_HE &&
5258 dut->device_type == STA_testbed) {
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305259 sta_set_phymode(dut, intf, val);
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005260 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005261 }
5262
5263 val = get_param(cmd, "wmm");
5264 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005265 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005266 case DRIVER_ATHEROS:
5267 ath_sta_set_wmm(dut, intf, val);
5268 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005269 case DRIVER_WCN:
5270 wcn_sta_set_wmm(dut, intf, val);
5271 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005272 default:
5273 sigma_dut_print(dut, DUT_MSG_DEBUG,
5274 "Setting wmm not supported");
5275 break;
5276 }
5277 }
5278
5279 val = get_param(cmd, "Powersave");
5280 if (val) {
5281 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005282 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305283 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005284 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005285 }
5286
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005287 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005288 "P2P_SET ps 0") < 0)
5289 return -2;
5290 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005291 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5292 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005293 } else if (strcmp(val, "1") == 0 ||
5294 strcasecmp(val, "PSPoll") == 0 ||
5295 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005296 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305297 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005298 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005299 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005300 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005301 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005302 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005303 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005304 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005305 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005306 "P2P_SET ps 99") < 0)
5307 return -2;
5308 } else if (strcmp(val, "2") == 0 ||
5309 strcasecmp(val, "Fast") == 0) {
5310 /* TODO */
5311 send_resp(dut, conn, SIGMA_ERROR,
5312 "ErrorCode,Powersave=Fast not supported");
5313 return 0;
5314 } else if (strcmp(val, "3") == 0 ||
5315 strcasecmp(val, "PSNonPoll") == 0) {
5316 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005317 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5318 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005319
5320 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005321 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005322 "P2P_SET ps 1") < 0)
5323 return -2;
5324 } else
5325 return -1;
5326 }
5327
5328 val = get_param(cmd, "NoAck");
5329 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005330 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005331 case DRIVER_ATHEROS:
5332 ath_sta_set_noack(dut, intf, val);
5333 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005334#ifdef NL80211_SUPPORT
5335 case DRIVER_WCN:
5336 wcn_sta_set_noack(dut, intf, val);
5337 break;
5338#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005339 default:
5340 send_resp(dut, conn, SIGMA_ERROR,
5341 "ErrorCode,Setting NoAck not supported");
5342 return 0;
5343 }
5344 }
5345
5346 val = get_param(cmd, "IgnoreChswitchProhibit");
5347 if (val) {
5348 /* TODO: Enabled/disabled */
5349 if (strcasecmp(val, "Enabled") == 0) {
5350 send_resp(dut, conn, SIGMA_ERROR,
5351 "ErrorCode,Enabling IgnoreChswitchProhibit "
5352 "not supported");
5353 return 0;
5354 }
5355 }
5356
5357 val = get_param(cmd, "TDLS");
5358 if (val) {
5359 if (strcasecmp(val, "Disabled") == 0) {
5360 if (wpa_command(intf, "SET tdls_disabled 1")) {
5361 send_resp(dut, conn, SIGMA_ERROR,
5362 "ErrorCode,Failed to disable TDLS");
5363 return 0;
5364 }
5365 } else if (strcasecmp(val, "Enabled") == 0) {
5366 if (wpa_command(intf, "SET tdls_disabled 0")) {
5367 send_resp(dut, conn, SIGMA_ERROR,
5368 "ErrorCode,Failed to enable TDLS");
5369 return 0;
5370 }
5371 } else {
5372 send_resp(dut, conn, SIGMA_ERROR,
5373 "ErrorCode,Unsupported TDLS value");
5374 return 0;
5375 }
5376 }
5377
5378 val = get_param(cmd, "TDLSmode");
5379 if (val) {
5380 if (strcasecmp(val, "Default") == 0) {
5381 wpa_command(intf, "SET tdls_testing 0");
5382 } else if (strcasecmp(val, "APProhibit") == 0) {
5383 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5384 send_resp(dut, conn, SIGMA_ERROR,
5385 "ErrorCode,Failed to enable ignore "
5386 "APProhibit TDLS mode");
5387 return 0;
5388 }
5389 } else if (strcasecmp(val, "HiLoMac") == 0) {
5390 /* STA should respond with TDLS setup req for a TDLS
5391 * setup req */
5392 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5393 send_resp(dut, conn, SIGMA_ERROR,
5394 "ErrorCode,Failed to enable HiLoMac "
5395 "TDLS mode");
5396 return 0;
5397 }
5398 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5399 /*
5400 * Since all security modes are enabled by default when
5401 * Sigma control is used, there is no need to do
5402 * anything here.
5403 */
5404 } else if (strcasecmp(val, "ExistLink") == 0) {
5405 /*
5406 * Since we allow new TDLS Setup Request even if there
5407 * is an existing link, nothing needs to be done for
5408 * this.
5409 */
5410 } else {
5411 /* TODO:
5412 * ExistLink: STA should send TDLS setup req even if
5413 * direct link already exists
5414 */
5415 send_resp(dut, conn, SIGMA_ERROR,
5416 "ErrorCode,Unsupported TDLSmode value");
5417 return 0;
5418 }
5419 }
5420
5421 val = get_param(cmd, "FakePubKey");
5422 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5423 send_resp(dut, conn, SIGMA_ERROR,
5424 "ErrorCode,Failed to enable FakePubKey");
5425 return 0;
5426 }
5427
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005428#ifdef NL80211_SUPPORT
5429 val = get_param(cmd, "FrgmntSupport");
5430 if (val) {
5431 if (strcasecmp(val, "Enable") == 0) {
5432 if (sta_set_he_fragmentation(dut, intf,
5433 HE_FRAG_LEVEL1)) {
5434 send_resp(dut, conn, SIGMA_ERROR,
5435 "ErrorCode,Failed to enable HE Fragmentation");
5436 return 0;
5437 }
5438 } else if (strcasecmp(val, "Disable") == 0) {
5439 if (sta_set_he_fragmentation(dut, intf,
5440 HE_FRAG_DISABLE)) {
5441 send_resp(dut, conn, SIGMA_ERROR,
5442 "ErrorCode,Failed to disable HE Fragmentation");
5443 return 0;
5444 }
5445 }
5446 }
5447#endif /* NL80211_SUPPORT */
5448
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305449 val = get_param(cmd, "IncludeMSCSDescriptor");
5450 if (val && strcasecmp(val, "1") == 0) {
5451 char buf[128];
5452 int len;
5453
5454 len = snprintf(buf, sizeof(buf),
Veerendranath Jakkam62cde372020-08-19 18:03:06 +05305455 "MSCS add up_bitmap=F0 up_limit=7 stream_timeout=60000 frame_classifier=045F%032x",
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305456 0);
5457
5458 if (len < 0 || len >= sizeof(buf)) {
5459 sigma_dut_print(dut, DUT_MSG_ERROR,
5460 "Failed to build MSCS Descriptor IE");
5461 return ERROR_SEND_STATUS;
5462 }
5463
5464 if (wpa_command(intf, buf) != 0) {
5465 send_resp(dut, conn, SIGMA_ERROR,
5466 "ErrorCode,Failed to include MSCS descriptor");
5467 return STATUS_SENT_ERROR;
5468 }
5469 }
5470
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005471 return 1;
5472}
5473
5474
5475static const char * ath_get_radio_name(const char *radio_name)
5476{
5477 if (radio_name == NULL)
5478 return "wifi0";
5479 if (strcmp(radio_name, "wifi1") == 0)
5480 return "wifi1";
5481 if (strcmp(radio_name, "wifi2") == 0)
5482 return "wifi2";
5483 return "wifi0";
5484}
5485
5486
5487static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5488 const char *val)
5489{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005490 unsigned int vht_mcsmap = 0;
5491 int txchainmask = 0;
5492 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5493
5494 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5495 if (dut->testbed_flag_txsp == 1) {
5496 vht_mcsmap = 0xfffc;
5497 dut->testbed_flag_txsp = 0;
5498 } else {
5499 vht_mcsmap = 0xfffe;
5500 }
5501 txchainmask = 1;
5502 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5503 if (dut->testbed_flag_txsp == 1) {
5504 vht_mcsmap = 0xfff0;
5505 dut->testbed_flag_txsp = 0;
5506 } else {
5507 vht_mcsmap = 0xfffa;
5508 }
5509 txchainmask = 3;
5510 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5511 if (dut->testbed_flag_txsp == 1) {
5512 vht_mcsmap = 0xffc0;
5513 dut->testbed_flag_txsp = 0;
5514 } else {
5515 vht_mcsmap = 0xffea;
5516 }
5517 txchainmask = 7;
5518 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5519 if (dut->testbed_flag_txsp == 1) {
5520 vht_mcsmap = 0xff00;
5521 dut->testbed_flag_txsp = 0;
5522 } else {
5523 vht_mcsmap = 0xffaa;
5524 }
5525 txchainmask = 15;
5526 } else {
5527 if (dut->testbed_flag_txsp == 1) {
5528 vht_mcsmap = 0xffc0;
5529 dut->testbed_flag_txsp = 0;
5530 } else {
5531 vht_mcsmap = 0xffea;
5532 }
5533 }
5534
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005535 if (txchainmask)
5536 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005537
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005538 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005539}
5540
5541
5542static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5543 const char *val)
5544{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005545 unsigned int vht_mcsmap = 0;
5546 int rxchainmask = 0;
5547 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5548
5549 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5550 if (dut->testbed_flag_rxsp == 1) {
5551 vht_mcsmap = 0xfffc;
5552 dut->testbed_flag_rxsp = 0;
5553 } else {
5554 vht_mcsmap = 0xfffe;
5555 }
5556 rxchainmask = 1;
5557 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5558 if (dut->testbed_flag_rxsp == 1) {
5559 vht_mcsmap = 0xfff0;
5560 dut->testbed_flag_rxsp = 0;
5561 } else {
5562 vht_mcsmap = 0xfffa;
5563 }
5564 rxchainmask = 3;
5565 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5566 if (dut->testbed_flag_rxsp == 1) {
5567 vht_mcsmap = 0xffc0;
5568 dut->testbed_flag_rxsp = 0;
5569 } else {
5570 vht_mcsmap = 0xffea;
5571 }
5572 rxchainmask = 7;
5573 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5574 if (dut->testbed_flag_rxsp == 1) {
5575 vht_mcsmap = 0xff00;
5576 dut->testbed_flag_rxsp = 0;
5577 } else {
5578 vht_mcsmap = 0xffaa;
5579 }
5580 rxchainmask = 15;
5581 } else {
5582 if (dut->testbed_flag_rxsp == 1) {
5583 vht_mcsmap = 0xffc0;
5584 dut->testbed_flag_rxsp = 0;
5585 } else {
5586 vht_mcsmap = 0xffea;
5587 }
5588 }
5589
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005590 if (rxchainmask)
5591 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005592
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005593 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005594}
5595
5596
5597void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5598{
5599 if (strcasecmp(val, "enable") == 0) {
5600 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5601 != 0) {
5602 sigma_dut_print(dut, DUT_MSG_ERROR,
5603 "Disable BB_VHTSIGB_CRC_CALC failed");
5604 }
5605
5606 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5607 != 0) {
5608 sigma_dut_print(dut, DUT_MSG_ERROR,
5609 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5610 }
5611 } else {
5612 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5613 != 0) {
5614 sigma_dut_print(dut, DUT_MSG_ERROR,
5615 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5616 }
5617
5618 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5619 != 0) {
5620 sigma_dut_print(dut, DUT_MSG_ERROR,
5621 "Enable BB_VHTSIGB_CRC_CALC failed");
5622 }
5623 }
5624}
5625
5626
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005627static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5628 const char *val)
5629{
5630 char buf[60];
5631
5632 if (strcmp(val, "20") == 0) {
5633 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5634 dut->chwidth = 0;
5635 } else if (strcmp(val, "40") == 0) {
5636 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5637 dut->chwidth = 1;
5638 } else if (strcmp(val, "80") == 0) {
5639 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5640 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305641 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005642 buf[0] = '\0';
5643 } else {
5644 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5645 val);
5646 return -1;
5647 }
5648
5649 if (buf[0] != '\0' && system(buf) != 0) {
5650 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5651 return -1;
5652 }
5653
5654 return 0;
5655}
5656
5657
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005658static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5659 const char *intf, int addbareject)
5660{
5661#ifdef NL80211_SUPPORT
5662 struct nl_msg *msg;
5663 int ret = 0;
5664 struct nlattr *params;
5665 int ifindex;
5666
5667 ifindex = if_nametoindex(intf);
5668 if (ifindex == 0) {
5669 sigma_dut_print(dut, DUT_MSG_ERROR,
5670 "%s: Index for interface %s failed",
5671 __func__, intf);
5672 return -1;
5673 }
5674
5675 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5676 NL80211_CMD_VENDOR)) ||
5677 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5678 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5679 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5680 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5681 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5682 nla_put_u8(msg,
5683 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5684 !addbareject)) {
5685 sigma_dut_print(dut, DUT_MSG_ERROR,
5686 "%s: err in adding vendor_cmd and vendor_data",
5687 __func__);
5688 nlmsg_free(msg);
5689 return -1;
5690 }
5691 nla_nest_end(msg, params);
5692
5693 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5694 if (ret) {
5695 sigma_dut_print(dut, DUT_MSG_ERROR,
5696 "%s: err in send_and_recv_msgs, ret=%d",
5697 __func__, ret);
5698 }
5699 return ret;
5700#else /* NL80211_SUPPORT */
5701 sigma_dut_print(dut, DUT_MSG_ERROR,
5702 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5703 return -1;
5704#endif /* NL80211_SUPPORT */
5705}
5706
5707
5708static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5709 int addbareject)
5710{
5711 int ret;
5712
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005713 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005714 case DRIVER_WCN:
5715 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5716 if (ret) {
5717 sigma_dut_print(dut, DUT_MSG_ERROR,
5718 "nlvendor_sta_set_addba_reject failed, ret:%d",
5719 ret);
5720 return ret;
5721 }
5722 break;
5723 default:
5724 sigma_dut_print(dut, DUT_MSG_ERROR,
5725 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5726 ret = -1;
5727 break;
5728 }
5729
5730 return ret;
5731}
5732
5733
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005734static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5735 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005736{
5737#ifdef NL80211_SUPPORT
5738 struct nl_msg *msg;
5739 int ret = 0;
5740 struct nlattr *params;
5741 int ifindex;
5742
5743 ifindex = if_nametoindex(intf);
5744 if (ifindex == 0) {
5745 sigma_dut_print(dut, DUT_MSG_ERROR,
5746 "%s: Index for interface %s failed",
5747 __func__, intf);
5748 return -1;
5749 }
5750
5751 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5752 NL80211_CMD_VENDOR)) ||
5753 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5754 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5755 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5756 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5757 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5758 nla_put_u8(msg,
5759 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005760 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005761 sigma_dut_print(dut, DUT_MSG_ERROR,
5762 "%s: err in adding vendor_cmd and vendor_data",
5763 __func__);
5764 nlmsg_free(msg);
5765 return -1;
5766 }
5767 nla_nest_end(msg, params);
5768
5769 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5770 if (ret) {
5771 sigma_dut_print(dut, DUT_MSG_ERROR,
5772 "%s: err in send_and_recv_msgs, ret=%d",
5773 __func__, ret);
5774 }
5775 return ret;
5776#else /* NL80211_SUPPORT */
5777 sigma_dut_print(dut, DUT_MSG_ERROR,
5778 "Disable addba not possible without NL80211_SUPPORT defined");
5779 return -1;
5780#endif /* NL80211_SUPPORT */
5781}
5782
5783
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305784#ifdef NL80211_SUPPORT
5785static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5786{
5787 struct nl_msg *msg;
5788 int ret = 0;
5789 int ifindex;
5790
5791 ifindex = if_nametoindex(intf);
5792 if (ifindex == 0) {
5793 sigma_dut_print(dut, DUT_MSG_ERROR,
5794 "%s: Index for interface %s failed",
5795 __func__, intf);
5796 return -1;
5797 }
5798
5799 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5800 NL80211_CMD_SET_WIPHY)) ||
5801 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5802 sigma_dut_print(dut, DUT_MSG_ERROR,
5803 "%s: err in adding RTS threshold",
5804 __func__);
5805 nlmsg_free(msg);
5806 return -1;
5807 }
5808
5809 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5810 if (ret) {
5811 sigma_dut_print(dut, DUT_MSG_ERROR,
5812 "%s: err in send_and_recv_msgs, ret=%d",
5813 __func__, ret);
5814 }
5815 return ret;
5816}
5817#endif /* NL80211_SUPPORT */
5818
5819
5820static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5821{
5822 char buf[100];
5823
5824#ifdef NL80211_SUPPORT
5825 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5826 return 0;
5827 sigma_dut_print(dut, DUT_MSG_DEBUG,
5828 "Fall back to using iwconfig for setting RTS threshold");
5829#endif /* NL80211_SUPPORT */
5830
5831 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5832 if (system(buf) != 0) {
5833 sigma_dut_print(dut, DUT_MSG_ERROR,
5834 "Failed to set RTS threshold %d", val);
5835 return -1;
5836 }
5837 return 0;
5838}
5839
5840
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005841static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5842 struct sigma_conn *conn,
5843 struct sigma_cmd *cmd)
5844{
5845 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005846 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005847 char buf[128];
5848 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005849
5850 val = get_param(cmd, "40_INTOLERANT");
5851 if (val) {
5852 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5853 /* TODO: iwpriv ht40intol through wpa_supplicant */
5854 send_resp(dut, conn, SIGMA_ERROR,
5855 "ErrorCode,40_INTOLERANT not supported");
5856 return 0;
5857 }
5858 }
5859
5860 val = get_param(cmd, "ADDBA_REJECT");
5861 if (val) {
5862 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5863 /* reject any ADDBA with status "decline" */
5864 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005865 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005866 } else {
5867 /* accept ADDBA */
5868 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005869 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005870 }
5871 }
5872
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005873 if (addbareject >= 0 &&
5874 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5875 send_resp(dut, conn, SIGMA_ERROR,
5876 "ErrorCode,set addba_reject failed");
5877 return 0;
5878 }
5879
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005880 val = get_param(cmd, "AMPDU");
5881 if (val) {
5882 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5883 /* enable AMPDU Aggregation */
5884 if (ampdu == 0) {
5885 send_resp(dut, conn, SIGMA_ERROR,
5886 "ErrorCode,Mismatch in "
5887 "addba_reject/ampdu - "
5888 "not supported");
5889 return 0;
5890 }
5891 ampdu = 1;
5892 } else {
5893 /* disable AMPDU Aggregation */
5894 if (ampdu == 1) {
5895 send_resp(dut, conn, SIGMA_ERROR,
5896 "ErrorCode,Mismatch in "
5897 "addba_reject/ampdu - "
5898 "not supported");
5899 return 0;
5900 }
5901 ampdu = 0;
5902 }
5903 }
5904
5905 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005906 int ret;
5907
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005908 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5909 ampdu ? "Enabling" : "Disabling");
5910 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005911 if (wpa_command(intf, buf) < 0 &&
5912 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005913 send_resp(dut, conn, SIGMA_ERROR,
5914 "ErrorCode,set aggr failed");
5915 return 0;
5916 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005917
5918 if (ampdu == 0) {
5919 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005920 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005921 if (ret) {
5922 sigma_dut_print(dut, DUT_MSG_ERROR,
5923 "Failed to disable addba, ret:%d",
5924 ret);
5925 }
5926 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005927 }
5928
5929 val = get_param(cmd, "AMSDU");
5930 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005931 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005932 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005933 case DRIVER_WCN:
5934 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005935 break;
5936 default:
5937 if (strcmp(val, "1") == 0 ||
5938 strcasecmp(val, "Enable") == 0) {
5939 /* Enable AMSDU Aggregation */
5940 send_resp(dut, conn, SIGMA_ERROR,
5941 "ErrorCode,AMSDU aggregation not supported");
5942 return 0;
5943 }
5944 break;
5945 }
5946 }
5947
5948 val = get_param(cmd, "STBC_RX");
5949 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005950 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005951 case DRIVER_ATHEROS:
5952 ath_sta_set_stbc(dut, intf, val);
5953 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305954 case DRIVER_WCN:
5955 wcn_sta_set_stbc(dut, intf, val);
5956 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005957 default:
5958 send_resp(dut, conn, SIGMA_ERROR,
5959 "ErrorCode,STBC_RX not supported");
5960 return 0;
5961 }
5962 }
5963
5964 val = get_param(cmd, "WIDTH");
5965 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005966 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005967 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005968 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005969 send_resp(dut, conn, SIGMA_ERROR,
5970 "ErrorCode,Failed to set WIDTH");
5971 return 0;
5972 }
5973 break;
5974 case DRIVER_ATHEROS:
5975 if (ath_set_width(dut, conn, intf, val) < 0)
5976 return 0;
5977 break;
5978 default:
5979 sigma_dut_print(dut, DUT_MSG_ERROR,
5980 "Setting WIDTH not supported");
5981 break;
5982 }
5983 }
5984
5985 val = get_param(cmd, "SMPS");
5986 if (val) {
5987 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5988 send_resp(dut, conn, SIGMA_ERROR,
5989 "ErrorCode,SMPS not supported");
5990 return 0;
5991 }
5992
5993 val = get_param(cmd, "TXSP_STREAM");
5994 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005995 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005996 case DRIVER_WCN:
5997 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5998 send_resp(dut, conn, SIGMA_ERROR,
5999 "ErrorCode,Failed to set TXSP_STREAM");
6000 return 0;
6001 }
6002 break;
6003 case DRIVER_ATHEROS:
6004 ath_sta_set_txsp_stream(dut, intf, val);
6005 break;
6006 default:
6007 sigma_dut_print(dut, DUT_MSG_ERROR,
6008 "Setting TXSP_STREAM not supported");
6009 break;
6010 }
6011 }
6012
6013 val = get_param(cmd, "RXSP_STREAM");
6014 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006015 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006016 case DRIVER_WCN:
6017 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
6018 send_resp(dut, conn, SIGMA_ERROR,
6019 "ErrorCode,Failed to set RXSP_STREAM");
6020 return 0;
6021 }
6022 break;
6023 case DRIVER_ATHEROS:
6024 ath_sta_set_rxsp_stream(dut, intf, val);
6025 break;
6026 default:
6027 sigma_dut_print(dut, DUT_MSG_ERROR,
6028 "Setting RXSP_STREAM not supported");
6029 break;
6030 }
6031 }
6032
6033 val = get_param(cmd, "DYN_BW_SGNL");
6034 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006035 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006036 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08006037 if (strcasecmp(val, "enable") == 0) {
6038 snprintf(buf, sizeof(buf),
6039 "iwpriv %s cwmenable 1", intf);
6040 if (system(buf) != 0) {
6041 sigma_dut_print(dut, DUT_MSG_ERROR,
6042 "iwpriv cwmenable 1 failed");
6043 return 0;
6044 }
6045 } else if (strcasecmp(val, "disable") == 0) {
6046 snprintf(buf, sizeof(buf),
6047 "iwpriv %s cwmenable 0", intf);
6048 if (system(buf) != 0) {
6049 sigma_dut_print(dut, DUT_MSG_ERROR,
6050 "iwpriv cwmenable 0 failed");
6051 return 0;
6052 }
6053 } else {
6054 sigma_dut_print(dut, DUT_MSG_ERROR,
6055 "Unsupported DYN_BW_SGL");
6056 }
6057
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006058 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
6059 if (system(buf) != 0) {
6060 sigma_dut_print(dut, DUT_MSG_ERROR,
6061 "Failed to set cts_cbw in DYN_BW_SGNL");
6062 return 0;
6063 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006064 break;
6065 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006066 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006067 ath_config_dyn_bw_sig(dut, intf, val);
6068 break;
6069 default:
6070 sigma_dut_print(dut, DUT_MSG_ERROR,
6071 "Failed to set DYN_BW_SGNL");
6072 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006073 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006074 }
6075
6076 val = get_param(cmd, "RTS_FORCE");
6077 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006078 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006079 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306080 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006081 sigma_dut_print(dut, DUT_MSG_ERROR,
6082 "Failed to set RTS_FORCE 64");
6083 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03006084 res = snprintf(buf, sizeof(buf),
6085 "wifitool %s beeliner_fw_test 100 1",
6086 intf);
6087 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08006088 sigma_dut_print(dut, DUT_MSG_ERROR,
6089 "wifitool beeliner_fw_test 100 1 failed");
6090 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006091 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306092 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006093 sigma_dut_print(dut, DUT_MSG_ERROR,
6094 "Failed to set RTS_FORCE 2347");
6095 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006096 } else {
6097 send_resp(dut, conn, SIGMA_ERROR,
6098 "ErrorCode,RTS_FORCE value not supported");
6099 return 0;
6100 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006101 }
6102
6103 val = get_param(cmd, "CTS_WIDTH");
6104 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006105 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006106 case DRIVER_WCN:
6107 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
6108 send_resp(dut, conn, SIGMA_ERROR,
6109 "ErrorCode,Failed to set CTS_WIDTH");
6110 return 0;
6111 }
6112 break;
6113 case DRIVER_ATHEROS:
6114 ath_set_cts_width(dut, intf, val);
6115 break;
6116 default:
6117 sigma_dut_print(dut, DUT_MSG_ERROR,
6118 "Setting CTS_WIDTH not supported");
6119 break;
6120 }
6121 }
6122
6123 val = get_param(cmd, "BW_SGNL");
6124 if (val) {
6125 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006126 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006127 } else if (strcasecmp(val, "Disable") == 0) {
6128 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006129 } else {
6130 send_resp(dut, conn, SIGMA_ERROR,
6131 "ErrorCode,BW_SGNL value not supported");
6132 return 0;
6133 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006134 }
6135
6136 val = get_param(cmd, "Band");
6137 if (val) {
6138 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
6139 /* STA supports all bands by default */
6140 } else {
6141 send_resp(dut, conn, SIGMA_ERROR,
6142 "ErrorCode,Unsupported Band");
6143 return 0;
6144 }
6145 }
6146
6147 val = get_param(cmd, "zero_crc");
6148 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006149 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006150 case DRIVER_ATHEROS:
6151 ath_set_zero_crc(dut, val);
6152 break;
6153 default:
6154 break;
6155 }
6156 }
6157
6158 return 1;
6159}
6160
6161
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006162static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
6163{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006164 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006165#ifdef __linux__
6166 case DRIVER_WIL6210:
6167 return wil6210_set_force_mcs(dut, force, mcs);
6168#endif /* __linux__ */
6169 default:
6170 sigma_dut_print(dut, DUT_MSG_ERROR,
6171 "Unsupported sta_set_force_mcs with the current driver");
6172 return -1;
6173 }
6174}
6175
6176
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006177static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
6178{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006179 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006180#ifdef __linux__
6181 case DRIVER_WIL6210:
6182 return wil6210_force_rsn_ie(dut, state);
6183#endif /* __linux__ */
6184 default:
6185 sigma_dut_print(dut, DUT_MSG_ERROR,
6186 "Unsupported sta_60g_force_rsn_ie with the current driver");
6187 return -1;
6188 }
6189}
6190
6191
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006192static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
6193 struct sigma_cmd *cmd)
6194{
6195 const char *val;
6196 char buf[100];
6197
6198 val = get_param(cmd, "MSDUSize");
6199 if (val) {
6200 int mtu;
6201
6202 dut->amsdu_size = atoi(val);
6203 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
6204 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
6205 sigma_dut_print(dut, DUT_MSG_ERROR,
6206 "MSDUSize %d is above max %d or below min %d",
6207 dut->amsdu_size,
6208 IEEE80211_MAX_DATA_LEN_DMG,
6209 IEEE80211_SNAP_LEN_DMG);
6210 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006211 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006212 }
6213
6214 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
6215 sigma_dut_print(dut, DUT_MSG_DEBUG,
6216 "Setting amsdu_size to %d", mtu);
6217 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006218 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006219
6220 if (system(buf) != 0) {
6221 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
6222 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006223 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006224 }
6225 }
6226
6227 val = get_param(cmd, "BAckRcvBuf");
6228 if (val) {
6229 dut->back_rcv_buf = atoi(val);
6230 if (dut->back_rcv_buf == 0) {
6231 sigma_dut_print(dut, DUT_MSG_ERROR,
6232 "Failed to convert %s or value is 0",
6233 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006234 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006235 }
6236
6237 sigma_dut_print(dut, DUT_MSG_DEBUG,
6238 "Setting BAckRcvBuf to %s", val);
6239 }
6240
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006241 val = get_param(cmd, "MCS_FixedRate");
6242 if (val) {
6243 if (sta_set_force_mcs(dut, 1, atoi(val))) {
6244 sigma_dut_print(dut, DUT_MSG_ERROR,
6245 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006246 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006247 }
6248 }
6249
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006250 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006251}
6252
6253
6254static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
6255 struct sigma_cmd *cmd)
6256{
6257 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006258 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006259 const char *val;
6260 char buf[100];
6261
6262 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006263 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006264 if (wpa_command(ifname, "PING") != 0) {
6265 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006266 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006267 }
6268
6269 wpa_command(ifname, "FLUSH");
6270 net_id = add_network_common(dut, conn, ifname, cmd);
6271 if (net_id < 0) {
6272 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
6273 return net_id;
6274 }
6275
6276 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
6277 if (set_network(ifname, net_id, "mode", "2") < 0) {
6278 sigma_dut_print(dut, DUT_MSG_ERROR,
6279 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006280 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006281 }
6282
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006283 if (set_network(ifname, net_id, "pbss", "1") < 0)
6284 return -2;
6285
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006286 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006287 "Supplicant set network with mode 2. network_id %d",
6288 net_id);
6289
6290 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6291 sigma_dut_print(dut, DUT_MSG_INFO,
6292 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006293 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006294 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006295
6296 val = get_param(cmd, "Security");
6297 if (val && strcasecmp(val, "OPEN") == 0) {
6298 dut->ap_key_mgmt = AP_OPEN;
6299 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6300 sigma_dut_print(dut, DUT_MSG_ERROR,
6301 "Failed to set supplicant to %s security",
6302 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006303 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006304 }
6305 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6306 dut->ap_key_mgmt = AP_WPA2_PSK;
6307 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6308 sigma_dut_print(dut, DUT_MSG_ERROR,
6309 "Failed to set supplicant to %s security",
6310 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006311 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006312 }
6313
6314 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6315 sigma_dut_print(dut, DUT_MSG_ERROR,
6316 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006317 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006318 }
6319 } else if (val) {
6320 sigma_dut_print(dut, DUT_MSG_ERROR,
6321 "Requested Security %s is not supported on 60GHz",
6322 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006323 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006324 }
6325
6326 val = get_param(cmd, "Encrypt");
6327 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6328 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6329 sigma_dut_print(dut, DUT_MSG_ERROR,
6330 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006331 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006332 }
6333 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6334 sigma_dut_print(dut, DUT_MSG_ERROR,
6335 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006336 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006337 }
6338 } else if (val) {
6339 sigma_dut_print(dut, DUT_MSG_ERROR,
6340 "Requested Encrypt %s is not supported on 60 GHz",
6341 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006342 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006343 }
6344
6345 val = get_param(cmd, "PSK");
6346 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6347 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6348 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006349 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006350 }
6351
6352 /* Convert 60G channel to freq */
6353 switch (dut->ap_channel) {
6354 case 1:
6355 val = "58320";
6356 break;
6357 case 2:
6358 val = "60480";
6359 break;
6360 case 3:
6361 val = "62640";
6362 break;
6363 default:
6364 sigma_dut_print(dut, DUT_MSG_ERROR,
6365 "Failed to configure channel %d. Not supported",
6366 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006367 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006368 }
6369
6370 if (set_network(ifname, net_id, "frequency", val) < 0) {
6371 sigma_dut_print(dut, DUT_MSG_ERROR,
6372 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006373 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006374 }
6375
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006376 if (dut->eap_fragment) {
6377 sigma_dut_print(dut, DUT_MSG_DEBUG,
6378 "Set EAP fragment size to 128 bytes.");
6379 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6380 return ERROR_SEND_STATUS;
6381 }
6382
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006383 sigma_dut_print(dut, DUT_MSG_DEBUG,
6384 "Supplicant set network with frequency");
6385
6386 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6387 if (wpa_command(ifname, buf) < 0) {
6388 sigma_dut_print(dut, DUT_MSG_INFO,
6389 "Failed to select network id %d on %s",
6390 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006391 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006392 }
6393
6394 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6395
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006396 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006397}
6398
6399
Lior David67543f52017-01-03 19:04:22 +02006400static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6401{
6402 char buf[128], fname[128];
6403 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006404 int res;
Lior David67543f52017-01-03 19:04:22 +02006405
6406 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6407 sigma_dut_print(dut, DUT_MSG_ERROR,
6408 "failed to get wil6210 debugfs dir");
6409 return -1;
6410 }
6411
Jouni Malinen3aa72862019-05-29 23:14:51 +03006412 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6413 if (res < 0 || res >= sizeof(fname))
6414 return -1;
Lior David67543f52017-01-03 19:04:22 +02006415 f = fopen(fname, "w");
6416 if (!f) {
6417 sigma_dut_print(dut, DUT_MSG_ERROR,
6418 "failed to open: %s", fname);
6419 return -1;
6420 }
6421
6422 fprintf(f, "%d\n", abft_len);
6423 fclose(f);
6424
6425 return 0;
6426}
6427
6428
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006429int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6430 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006431{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006432 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006433 case DRIVER_WIL6210:
6434 return wil6210_set_abft_len(dut, abft_len);
6435 default:
6436 sigma_dut_print(dut, DUT_MSG_ERROR,
6437 "set abft_len not supported");
6438 return -1;
6439 }
6440}
6441
6442
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006443static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6444 struct sigma_cmd *cmd)
6445{
6446 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006447 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006448
6449 if (dut->dev_role != DEVROLE_PCP) {
6450 send_resp(dut, conn, SIGMA_INVALID,
6451 "ErrorCode,Invalid DevRole");
6452 return 0;
6453 }
6454
6455 val = get_param(cmd, "SSID");
6456 if (val) {
6457 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6458 send_resp(dut, conn, SIGMA_INVALID,
6459 "ErrorCode,Invalid SSID");
6460 return -1;
6461 }
6462
Peng Xub8fc5cc2017-05-10 17:27:28 -07006463 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006464 }
6465
6466 val = get_param(cmd, "CHANNEL");
6467 if (val) {
6468 const char *pos;
6469
6470 dut->ap_channel = atoi(val);
6471 pos = strchr(val, ';');
6472 if (pos) {
6473 pos++;
6474 dut->ap_channel_1 = atoi(pos);
6475 }
6476 }
6477
6478 switch (dut->ap_channel) {
6479 case 1:
6480 case 2:
6481 case 3:
6482 break;
6483 default:
6484 sigma_dut_print(dut, DUT_MSG_ERROR,
6485 "Channel %d is not supported", dut->ap_channel);
6486 send_resp(dut, conn, SIGMA_ERROR,
6487 "Requested channel is not supported");
6488 return -1;
6489 }
6490
6491 val = get_param(cmd, "BCNINT");
6492 if (val)
6493 dut->ap_bcnint = atoi(val);
6494
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006495 val = get_param(cmd, "AllocType");
6496 if (val) {
6497 send_resp(dut, conn, SIGMA_ERROR,
6498 "ErrorCode,AllocType is not supported yet");
6499 return -1;
6500 }
6501
6502 val = get_param(cmd, "PercentBI");
6503 if (val) {
6504 send_resp(dut, conn, SIGMA_ERROR,
6505 "ErrorCode,PercentBI is not supported yet");
6506 return -1;
6507 }
6508
6509 val = get_param(cmd, "CBAPOnly");
6510 if (val) {
6511 send_resp(dut, conn, SIGMA_ERROR,
6512 "ErrorCode,CBAPOnly is not supported yet");
6513 return -1;
6514 }
6515
6516 val = get_param(cmd, "AMPDU");
6517 if (val) {
6518 if (strcasecmp(val, "Enable") == 0)
6519 dut->ap_ampdu = 1;
6520 else if (strcasecmp(val, "Disable") == 0)
6521 dut->ap_ampdu = 2;
6522 else {
6523 send_resp(dut, conn, SIGMA_ERROR,
6524 "ErrorCode,AMPDU value is not Enable nor Disabled");
6525 return -1;
6526 }
6527 }
6528
6529 val = get_param(cmd, "AMSDU");
6530 if (val) {
6531 if (strcasecmp(val, "Enable") == 0)
6532 dut->ap_amsdu = 1;
6533 else if (strcasecmp(val, "Disable") == 0)
6534 dut->ap_amsdu = 2;
6535 }
6536
6537 val = get_param(cmd, "NumMSDU");
6538 if (val) {
6539 send_resp(dut, conn, SIGMA_ERROR,
6540 "ErrorCode, NumMSDU is not supported yet");
6541 return -1;
6542 }
6543
6544 val = get_param(cmd, "ABFTLRang");
6545 if (val) {
6546 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006547 "ABFTLRang parameter %s", val);
6548 if (strcmp(val, "Gt1") == 0)
6549 abft_len = 2; /* 2 slots in this case */
6550 }
6551
6552 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6553 send_resp(dut, conn, SIGMA_ERROR,
6554 "ErrorCode, Can't set ABFT length");
6555 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006556 }
6557
6558 if (sta_pcp_start(dut, conn, cmd) < 0) {
6559 send_resp(dut, conn, SIGMA_ERROR,
6560 "ErrorCode, Can't start PCP role");
6561 return -1;
6562 }
6563
6564 return sta_set_60g_common(dut, conn, cmd);
6565}
6566
6567
6568static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6569 struct sigma_cmd *cmd)
6570{
6571 const char *val = get_param(cmd, "DiscoveryMode");
6572
6573 if (dut->dev_role != DEVROLE_STA) {
6574 send_resp(dut, conn, SIGMA_INVALID,
6575 "ErrorCode,Invalid DevRole");
6576 return 0;
6577 }
6578
6579 if (val) {
6580 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6581 /* Ignore Discovery mode till Driver expose API. */
6582#if 0
6583 if (strcasecmp(val, "1") == 0) {
6584 send_resp(dut, conn, SIGMA_INVALID,
6585 "ErrorCode,DiscoveryMode 1 not supported");
6586 return 0;
6587 }
6588
6589 if (strcasecmp(val, "0") == 0) {
6590 /* OK */
6591 } else {
6592 send_resp(dut, conn, SIGMA_INVALID,
6593 "ErrorCode,DiscoveryMode not supported");
6594 return 0;
6595 }
6596#endif
6597 }
6598
6599 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006600 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006601 return sta_set_60g_common(dut, conn, cmd);
6602}
6603
6604
Jouni Malinenf7222712019-06-13 01:50:21 +03006605static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6606 struct sigma_conn *conn,
6607 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006608{
6609 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006610 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306611
Jouni Malinened77e672018-01-10 16:45:13 +02006612 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006613 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006614 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306615 wpa_command(intf, "DISCONNECT");
6616 return 1;
6617 }
6618
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006619 disconnect_station(dut);
6620 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6621 * due to cached results. */
6622 wpa_command(intf, "SET ignore_old_scan_res 1");
6623 wpa_command(intf, "BSS_FLUSH");
6624 return 1;
6625}
6626
6627
Jouni Malinenf7222712019-06-13 01:50:21 +03006628static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6629 struct sigma_conn *conn,
6630 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006631{
6632 const char *intf = get_param(cmd, "Interface");
6633 const char *bssid = get_param(cmd, "bssid");
6634 const char *val = get_param(cmd, "CHANNEL");
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006635 const char *freq_val = get_param(cmd, "ChnlFreq");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006636 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306637 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306638 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006639 int res;
6640 int chan = 0;
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006641 int freq = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006642 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306643 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006644 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006645
6646 if (bssid == NULL) {
6647 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6648 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006649 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006650 }
6651
6652 if (val)
6653 chan = atoi(val);
6654
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006655 if (freq_val)
6656 freq = atoi(freq_val);
6657
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006658 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6659 /* The current network may be from sta_associate or
6660 * sta_hs2_associate
6661 */
6662 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6663 0 ||
6664 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006665 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006666 }
6667
6668 ctrl = open_wpa_mon(intf);
6669 if (ctrl == NULL) {
6670 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6671 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006672 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006673 }
6674
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006675 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05306676 sizeof(result)) < 0 ||
6677 strncmp(result, "COMPLETED", 9) != 0) {
6678 sigma_dut_print(dut, DUT_MSG_DEBUG,
6679 "sta_reassoc: Not connected");
6680 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006681 } else if (dut->sta_ft_ds) {
6682 sigma_dut_print(dut, DUT_MSG_DEBUG,
6683 "sta_reassoc: Use FT-over-DS");
6684 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306685 }
6686
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306687 if (dut->rsne_override) {
6688#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006689 if (get_driver_type(dut) == DRIVER_WCN &&
6690 dut->config_rsnie == 0) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05306691 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306692 dut->config_rsnie = 1;
6693 }
6694#endif /* NL80211_SUPPORT */
6695 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6696 dut->rsne_override);
6697 if (wpa_command(intf, buf) < 0) {
6698 send_resp(dut, conn, SIGMA_ERROR,
6699 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6700 return 0;
6701 }
6702 }
6703
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006704 if (ft_ds) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006705 if (chan || freq) {
6706 if (!freq)
6707 freq = channel_to_freq(dut, chan);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006708 if (!freq) {
6709 sigma_dut_print(dut, DUT_MSG_ERROR,
6710 "Invalid channel number provided: %d",
6711 chan);
6712 send_resp(dut, conn, SIGMA_INVALID,
6713 "ErrorCode,Invalid channel number");
6714 goto close_mon_conn;
6715 }
6716 res = snprintf(buf, sizeof(buf),
6717 "SCAN TYPE=ONLY freq=%d", freq);
6718 } else {
6719 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6720 }
6721 if (res < 0 || res >= (int) sizeof(buf)) {
6722 send_resp(dut, conn, SIGMA_ERROR,
6723 "ErrorCode,snprintf failed");
6724 goto close_mon_conn;
6725 }
6726 if (wpa_command(intf, buf) < 0) {
6727 sigma_dut_print(dut, DUT_MSG_INFO,
6728 "Failed to start scan");
6729 send_resp(dut, conn, SIGMA_ERROR,
6730 "ErrorCode,scan failed");
6731 goto close_mon_conn;
6732 }
6733
6734 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6735 buf, sizeof(buf));
6736 if (res < 0) {
6737 sigma_dut_print(dut, DUT_MSG_INFO,
6738 "Scan did not complete");
6739 send_resp(dut, conn, SIGMA_ERROR,
6740 "ErrorCode,scan did not complete");
6741 goto close_mon_conn;
6742 }
6743
6744 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6745 if (res > 0 && res < (int) sizeof(buf))
6746 res = wpa_command(intf, buf);
6747
6748 if (res < 0 || res >= (int) sizeof(buf)) {
6749 send_resp(dut, conn, SIGMA_ERROR,
6750 "errorCode,FT_DS command failed");
6751 status = STATUS_SENT_ERROR;
6752 goto close_mon_conn;
6753 }
6754 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006755 if (chan || freq) {
6756 if (!freq)
6757 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306758 if (!freq) {
6759 sigma_dut_print(dut, DUT_MSG_ERROR,
6760 "Invalid channel number provided: %d",
6761 chan);
6762 send_resp(dut, conn, SIGMA_INVALID,
6763 "ErrorCode,Invalid channel number");
6764 goto close_mon_conn;
6765 }
6766 res = snprintf(buf, sizeof(buf),
6767 "SCAN TYPE=ONLY freq=%d", freq);
6768 } else {
6769 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6770 }
6771 if (res < 0 || res >= (int) sizeof(buf)) {
6772 send_resp(dut, conn, SIGMA_ERROR,
6773 "ErrorCode,snprintf failed");
6774 goto close_mon_conn;
6775 }
6776 if (wpa_command(intf, buf) < 0) {
6777 sigma_dut_print(dut, DUT_MSG_INFO,
6778 "Failed to start scan");
6779 send_resp(dut, conn, SIGMA_ERROR,
6780 "ErrorCode,scan failed");
6781 goto close_mon_conn;
6782 }
6783
6784 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6785 buf, sizeof(buf));
6786 if (res < 0) {
6787 sigma_dut_print(dut, DUT_MSG_INFO,
6788 "Scan did not complete");
6789 send_resp(dut, conn, SIGMA_ERROR,
6790 "ErrorCode,scan did not complete");
6791 goto close_mon_conn;
6792 }
6793
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006794 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6795 < 0) {
6796 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6797 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006798 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306799 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006800 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306801 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006802 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306803 if (res < 0 || res >= (int) sizeof(buf) ||
6804 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006805 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306806 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306807 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006808 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006809 sigma_dut_print(dut, DUT_MSG_INFO,
6810 "sta_reassoc: Run %s successful", buf);
6811 } else if (wpa_command(intf, "REASSOCIATE")) {
6812 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6813 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306814 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006815 }
6816
6817 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6818 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306819 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006820 send_resp(dut, conn, SIGMA_ERROR,
6821 "errorCode,Connection did not complete");
6822 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306823 goto close_mon_conn;
6824 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006825 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006826
Ashwini Patil467efef2017-05-25 12:18:27 +05306827close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006828 wpa_ctrl_detach(ctrl);
6829 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306830 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006831}
6832
6833
6834static void hs2_clear_credentials(const char *intf)
6835{
6836 wpa_command(intf, "REMOVE_CRED all");
6837}
6838
6839
Lior Davidcc88b562017-01-03 18:52:09 +02006840#ifdef __linux__
6841static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6842 unsigned int *aid)
6843{
Lior David0fe101e2017-03-09 16:09:50 +02006844 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006845
Lior David0fe101e2017-03-09 16:09:50 +02006846 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006847}
6848#endif /* __linux__ */
6849
6850
6851static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6852 unsigned int *aid)
6853{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006854 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02006855#ifdef __linux__
6856 case DRIVER_WIL6210:
6857 return wil6210_get_aid(dut, bssid, aid);
6858#endif /* __linux__ */
6859 default:
6860 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6861 return -1;
6862 }
6863}
6864
6865
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006866static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6867 struct sigma_cmd *cmd)
6868{
6869 char buf[MAX_CMD_LEN];
6870 char bss_list[MAX_CMD_LEN];
6871 const char *parameter = get_param(cmd, "Parameter");
6872
6873 if (parameter == NULL)
6874 return -1;
6875
Lior Davidcc88b562017-01-03 18:52:09 +02006876 if (strcasecmp(parameter, "AID") == 0) {
6877 unsigned int aid = 0;
6878 char bssid[20];
6879
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006880 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02006881 bssid, sizeof(bssid)) < 0) {
6882 sigma_dut_print(dut, DUT_MSG_ERROR,
6883 "could not get bssid");
6884 return -2;
6885 }
6886
6887 if (sta_get_aid_60g(dut, bssid, &aid))
6888 return -2;
6889
6890 snprintf(buf, sizeof(buf), "aid,%d", aid);
6891 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6892 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6893 return 0;
6894 }
6895
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006896 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6897 char *bss_line;
6898 char *bss_id = NULL;
6899 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306900 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006901
6902 if (ifname == NULL) {
6903 sigma_dut_print(dut, DUT_MSG_INFO,
6904 "For get DiscoveredDevList need Interface name.");
6905 return -1;
6906 }
6907
6908 /*
6909 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6910 * of BSSIDs in "bssid=<BSSID>\n"
6911 */
6912 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6913 bss_list,
6914 sizeof(bss_list)) < 0) {
6915 sigma_dut_print(dut, DUT_MSG_ERROR,
6916 "Failed to get bss list");
6917 return -1;
6918 }
6919
6920 sigma_dut_print(dut, DUT_MSG_DEBUG,
6921 "bss list for ifname:%s is:%s",
6922 ifname, bss_list);
6923
6924 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306925 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006926 while (bss_line) {
6927 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6928 bss_id) {
6929 int len;
6930
6931 len = snprintf(buf + strlen(buf),
6932 sizeof(buf) - strlen(buf),
6933 ",%s", bss_id);
6934 free(bss_id);
6935 bss_id = NULL;
6936 if (len < 0) {
6937 sigma_dut_print(dut,
6938 DUT_MSG_ERROR,
6939 "Failed to read BSSID");
6940 send_resp(dut, conn, SIGMA_ERROR,
6941 "ErrorCode,Failed to read BSS ID");
6942 return 0;
6943 }
6944
6945 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6946 sigma_dut_print(dut,
6947 DUT_MSG_ERROR,
6948 "Response buf too small for list");
6949 send_resp(dut, conn,
6950 SIGMA_ERROR,
6951 "ErrorCode,Response buf too small for list");
6952 return 0;
6953 }
6954 }
6955
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306956 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006957 }
6958
6959 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6960 buf);
6961 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6962 return 0;
6963 }
6964
6965 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6966 return 0;
6967}
6968
6969
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006970static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6971 struct sigma_cmd *cmd)
6972{
6973 char buf[MAX_CMD_LEN];
6974 const char *parameter = get_param(cmd, "Parameter");
6975
6976 if (!parameter)
6977 return -1;
6978
6979 if (strcasecmp(parameter, "RSSI") == 0) {
6980 char rssi[10];
6981
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006982 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006983 rssi, sizeof(rssi)) < 0) {
6984 sigma_dut_print(dut, DUT_MSG_ERROR,
6985 "Could not get RSSI");
6986 return -2;
6987 }
6988
6989 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6990 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6991 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6992 return 0;
6993 }
6994
6995 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6996 return 0;
6997}
6998
6999
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05307000#ifdef NL80211_SUPPORT
7001
7002struct station_info {
7003 uint64_t filled;
7004 uint32_t beacon_mic_error_count;
7005 uint32_t beacon_replay_count;
7006};
7007
7008
7009static int qca_get_sta_info_handler(struct nl_msg *msg, void *arg)
7010{
7011 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7012 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7013 struct station_info *data = arg;
7014 struct nlattr *info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1];
7015 static struct nla_policy info_policy[
7016 QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1] = {
7017 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT] = {
7018 .type = NLA_U32
7019 },
7020 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT] = {
7021 .type = NLA_U32
7022 },
7023 };
7024
7025 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7026 genlmsg_attrlen(gnlh, 0), NULL);
7027
7028 if (!tb[NL80211_ATTR_VENDOR_DATA])
7029 return NL_SKIP;
7030
7031 if (nla_parse_nested(info, QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX,
7032 tb[NL80211_ATTR_VENDOR_DATA], info_policy)) {
7033 return NL_SKIP;
7034 }
7035
7036 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]) {
7037 data->filled |=
7038 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT);
7039 data->beacon_mic_error_count =
7040 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]);
7041 }
7042
7043 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]) {
7044 data->filled |=
7045 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT);
7046 data->beacon_replay_count =
7047 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]);
7048 }
7049
7050 return NL_SKIP;
7051}
7052
7053
7054static int qca_nl80211_get_sta_info(struct sigma_dut *dut, const char *intf,
7055 struct station_info *sta_data)
7056{
7057 struct nl_msg *msg;
7058 int ifindex, ret;
7059
7060 ifindex = if_nametoindex(intf);
7061 if (ifindex == 0) {
7062 sigma_dut_print(dut, DUT_MSG_ERROR,
7063 "%s: Index for interface %s not found",
7064 __func__, intf);
7065 return -1;
7066 }
7067
7068 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7069 NL80211_CMD_VENDOR)) ||
7070 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7071 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7072 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7073 QCA_NL80211_VENDOR_SUBCMD_GET_STA_INFO)) {
7074 sigma_dut_print(dut, DUT_MSG_ERROR,
7075 "%s: err in adding vendor_cmd", __func__);
7076 nlmsg_free(msg);
7077 return -1;
7078 }
7079
7080 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg,
7081 qca_get_sta_info_handler, sta_data);
7082 if (ret) {
7083 sigma_dut_print(dut, DUT_MSG_ERROR,
7084 "%s: err in send_and_recv_msgs, ret=%d",
7085 __func__, ret);
7086 }
7087 return ret;
7088}
7089#endif /* NL80211_SUPPORT */
7090
7091
7092static int get_bip_mic_error_count(struct sigma_dut *dut,
7093 const char *ifname,
7094 unsigned int *count)
7095{
7096#ifdef NL80211_SUPPORT
7097 struct station_info sta_data;
7098#endif /* NL80211_SUPPORT */
7099
7100 if (get_driver_type(dut) != DRIVER_WCN) {
7101 sigma_dut_print(dut, DUT_MSG_ERROR,
7102 "BIP MIC error count not supported");
7103 return -1;
7104 }
7105
7106#ifdef NL80211_SUPPORT
7107 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
7108 !(sta_data.filled &
7109 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT))) {
7110 sigma_dut_print(dut, DUT_MSG_ERROR,
7111 "BIP MIC error count fetching failed");
7112 return -1;
7113 }
7114
7115 *count = sta_data.beacon_mic_error_count;
7116 return 0;
7117#else /* NL80211_SUPPORT */
7118 sigma_dut_print(dut, DUT_MSG_ERROR,
7119 "BIP MIC error count cannot be fetched without NL80211_SUPPORT defined");
7120 return -1;
7121#endif /* NL80211_SUPPORT */
7122}
7123
7124
7125static int get_cmac_replay_count(struct sigma_dut *dut, const char *ifname,
7126 unsigned int *count)
7127{
7128#ifdef NL80211_SUPPORT
7129 struct station_info sta_data;
7130#endif /* NL80211_SUPPORT */
7131
7132 if (get_driver_type(dut) != DRIVER_WCN) {
7133 sigma_dut_print(dut, DUT_MSG_ERROR,
7134 "CMAC reply count not supported");
7135 return -1;
7136 }
7137
7138#ifdef NL80211_SUPPORT
7139 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
7140 !(sta_data.filled &
7141 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT))) {
7142 sigma_dut_print(dut, DUT_MSG_ERROR,
7143 "CMAC replay count fetching failed");
7144 return -1;
7145 }
7146
7147 *count = sta_data.beacon_replay_count;
7148 return 0;
7149#else /* NL80211_SUPPORT */
7150 sigma_dut_print(dut, DUT_MSG_ERROR,
7151 "CMAC replay count cannot be fetched without NL80211_SUPPORT defined");
7152 return -1;
7153#endif /* NL80211_SUPPORT */
7154}
7155
7156
7157static enum sigma_cmd_result sta_get_parameter_wpa3(struct sigma_dut *dut,
7158 struct sigma_conn *conn,
7159 struct sigma_cmd *cmd)
7160{
7161 char buf[MAX_CMD_LEN];
7162 const char *ifname = get_param(cmd, "interface");
7163 const char *parameter = get_param(cmd, "Parameter");
7164 unsigned int val;
7165
7166 if (!ifname || !parameter)
7167 return INVALID_SEND_STATUS;
7168
7169 if (strcasecmp(parameter, "BIPMICErrors") == 0) {
7170 if (get_bip_mic_error_count(dut, ifname, &val)) {
7171 send_resp(dut, conn, SIGMA_ERROR,
7172 "ErrorCode,Failed to get BIPMICErrors");
7173 return STATUS_SENT_ERROR;
7174 }
7175 snprintf(buf, sizeof(buf), "BIPMICErrors,%d", val);
7176 sigma_dut_print(dut, DUT_MSG_INFO, "BIPMICErrors %s", buf);
7177 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7178 return STATUS_SENT;
7179 }
7180
7181 if (strcasecmp(parameter, "CMACReplays") == 0) {
7182 if (get_cmac_replay_count(dut, ifname, &val)) {
7183 send_resp(dut, conn, SIGMA_ERROR,
7184 "ErrorCode,Failed to get CMACReplays");
7185 return STATUS_SENT_ERROR;
7186 }
7187 snprintf(buf, sizeof(buf), "CMACReplays,%d", val);
7188 sigma_dut_print(dut, DUT_MSG_INFO, "CMACReplays %s", buf);
7189 send_resp(dut, conn, SIGMA_COMPLETE, buf);
7190 return STATUS_SENT;
7191 }
7192
7193 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7194 return STATUS_SENT_ERROR;
7195}
7196
7197
Jouni Malinenca0abd32020-02-09 20:18:10 +02007198static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
7199 struct sigma_conn *conn,
7200 struct sigma_cmd *cmd)
7201{
7202 const char *intf = get_param(cmd, "Interface");
7203 char buf[4096], bssid[20], resp[200], *pos, *tmp;
7204
7205 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
7206 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
7207 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
7208 send_resp(dut, conn, SIGMA_ERROR,
7209 "ErrorCode,PMKSA_GET not supported");
7210 return STATUS_SENT_ERROR;
7211 }
7212
7213 if (strncmp(buf, "FAIL", 4) == 0 ||
7214 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
7215 send_resp(dut, conn, SIGMA_ERROR,
7216 "ErrorCode,Could not find current network");
7217 return STATUS_SENT_ERROR;
7218 }
7219
7220 pos = buf;
7221 while (pos) {
7222 if (strncmp(pos, bssid, 17) == 0) {
7223 pos = strchr(pos, ' ');
7224 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307225 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007226 pos++;
7227 pos = strchr(pos, ' ');
7228 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307229 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007230 pos++;
7231 tmp = strchr(pos, ' ');
7232 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307233 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007234 *tmp = '\0';
7235 break;
7236 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02007237 pos = strchr(pos, '\n');
7238 if (pos)
7239 pos++;
7240 }
7241
7242 if (!pos) {
7243 send_resp(dut, conn, SIGMA_ERROR,
7244 "ErrorCode,PMK not available");
7245 return STATUS_SENT_ERROR;
7246 }
7247
7248 snprintf(resp, sizeof(resp), "PMK,%s", pos);
7249 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7250 return STATUS_SENT;
7251}
7252
7253
Jouni Malinenf7222712019-06-13 01:50:21 +03007254static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
7255 struct sigma_conn *conn,
7256 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007257{
7258 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02007259 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007260
Jouni Malinenca0abd32020-02-09 20:18:10 +02007261 if (!parameter)
7262 return INVALID_SEND_STATUS;
7263
7264 if (strcasecmp(parameter, "PMK") == 0)
7265 return sta_get_pmk(dut, conn, cmd);
7266
7267 if (!program)
7268 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007269
7270 if (strcasecmp(program, "P2PNFC") == 0)
7271 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
7272
7273 if (strcasecmp(program, "60ghz") == 0)
7274 return sta_get_parameter_60g(dut, conn, cmd);
7275
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007276 if (strcasecmp(program, "he") == 0)
7277 return sta_get_parameter_he(dut, conn, cmd);
7278
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007279#ifdef ANDROID_NAN
7280 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07007281 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007282#endif /* ANDROID_NAN */
7283
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007284#ifdef MIRACAST
7285 if (strcasecmp(program, "WFD") == 0 ||
7286 strcasecmp(program, "DisplayR2") == 0)
7287 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
7288#endif /* MIRACAST */
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05307289 if (strcasecmp(program, "WPA3") == 0)
7290 return sta_get_parameter_wpa3(dut, conn, cmd);
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007291
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007292 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7293 return 0;
7294}
7295
7296
7297static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
7298 const char *type)
7299{
7300 char buf[100];
7301
7302 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007303 run_iwpriv(dut, intf, "chwidth 2");
7304 run_iwpriv(dut, intf, "mode 11ACVHT80");
7305 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007306 }
7307
7308 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007309 run_iwpriv(dut, intf, "chwidth 0");
7310 run_iwpriv(dut, intf, "mode 11naht40");
7311 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007312 }
7313
7314 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007315 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007316
7317 /* Reset CTS width */
7318 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
7319 intf);
7320 if (system(buf) != 0) {
7321 sigma_dut_print(dut, DUT_MSG_ERROR,
7322 "wifitool %s beeliner_fw_test 54 0 failed",
7323 intf);
7324 }
7325
7326 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007327 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007328
7329 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
7330 if (system(buf) != 0) {
7331 sigma_dut_print(dut, DUT_MSG_ERROR,
7332 "iwpriv rts failed");
7333 }
7334 }
7335
7336 if (type && strcasecmp(type, "Testbed") == 0) {
7337 dut->testbed_flag_txsp = 1;
7338 dut->testbed_flag_rxsp = 1;
7339 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007340 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007341
7342 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007343 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007344
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007345 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007346
7347 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007348 run_iwpriv(dut, intf, "tx_stbc 0");
7349 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007350
7351 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007352 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007353 }
7354
7355 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007356 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07007357 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007358
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007359 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007360 }
7361}
7362
7363
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007364#ifdef NL80211_SUPPORT
7365static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
7366 enum he_mcs_config mcs)
7367{
7368 struct nl_msg *msg;
7369 int ret = 0;
7370 struct nlattr *params;
7371 int ifindex;
7372
7373 ifindex = if_nametoindex(intf);
7374 if (ifindex == 0) {
7375 sigma_dut_print(dut, DUT_MSG_ERROR,
7376 "%s: Index for interface %s failed",
7377 __func__, intf);
7378 return -1;
7379 }
7380
7381 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7382 NL80211_CMD_VENDOR)) ||
7383 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7384 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7385 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7386 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7387 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7388 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
7389 mcs)) {
7390 sigma_dut_print(dut, DUT_MSG_ERROR,
7391 "%s: err in adding vendor_cmd and vendor_data",
7392 __func__);
7393 nlmsg_free(msg);
7394 return -1;
7395 }
7396 nla_nest_end(msg, params);
7397
7398 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7399 if (ret) {
7400 sigma_dut_print(dut, DUT_MSG_ERROR,
7401 "%s: err in send_and_recv_msgs, ret=%d",
7402 __func__, ret);
7403 }
7404 return ret;
7405}
7406#endif /* NL80211_SUPPORT */
7407
7408
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007409static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
7410 const char *intf, int enable)
7411{
7412#ifdef NL80211_SUPPORT
7413 struct nl_msg *msg;
7414 int ret = 0;
7415 struct nlattr *params;
7416 int ifindex;
7417
7418 ifindex = if_nametoindex(intf);
7419 if (ifindex == 0) {
7420 sigma_dut_print(dut, DUT_MSG_ERROR,
7421 "%s: Index for interface %s failed",
7422 __func__, intf);
7423 return -1;
7424 }
7425
7426 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7427 NL80211_CMD_VENDOR)) ||
7428 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7429 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7430 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7431 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7432 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7433 nla_put_u8(msg,
7434 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
7435 enable)) {
7436 sigma_dut_print(dut, DUT_MSG_ERROR,
7437 "%s: err in adding vendor_cmd and vendor_data",
7438 __func__);
7439 nlmsg_free(msg);
7440 return -1;
7441 }
7442 nla_nest_end(msg, params);
7443
7444 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7445 if (ret) {
7446 sigma_dut_print(dut, DUT_MSG_ERROR,
7447 "%s: err in send_and_recv_msgs, ret=%d",
7448 __func__, ret);
7449 }
7450 return ret;
7451#else /* NL80211_SUPPORT */
7452 sigma_dut_print(dut, DUT_MSG_ERROR,
7453 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
7454 return -1;
7455#endif /* NL80211_SUPPORT */
7456}
7457
7458
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007459static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
7460 const char *intf, int enable)
7461{
7462#ifdef NL80211_SUPPORT
7463 struct nl_msg *msg;
7464 int ret = 0;
7465 struct nlattr *params;
7466 int ifindex;
7467
7468 ifindex = if_nametoindex(intf);
7469 if (ifindex == 0) {
7470 sigma_dut_print(dut, DUT_MSG_ERROR,
7471 "%s: Index for interface %s failed",
7472 __func__, intf);
7473 return -1;
7474 }
7475
7476 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7477 NL80211_CMD_VENDOR)) ||
7478 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7479 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7480 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7481 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7482 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7483 nla_put_u8(msg,
7484 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7485 enable)) {
7486 sigma_dut_print(dut, DUT_MSG_ERROR,
7487 "%s: err in adding vendor_cmd and vendor_data",
7488 __func__);
7489 nlmsg_free(msg);
7490 return -1;
7491 }
7492 nla_nest_end(msg, params);
7493
7494 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7495 if (ret) {
7496 sigma_dut_print(dut, DUT_MSG_ERROR,
7497 "%s: err in send_and_recv_msgs, ret=%d",
7498 __func__, ret);
7499 }
7500 return ret;
7501#else /* NL80211_SUPPORT */
7502 sigma_dut_print(dut, DUT_MSG_ERROR,
7503 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7504 return -1;
7505#endif /* NL80211_SUPPORT */
7506}
7507
7508
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007509#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007510
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007511static int sta_set_he_testbed_def(struct sigma_dut *dut,
7512 const char *intf, int cfg)
7513{
7514 struct nl_msg *msg;
7515 int ret = 0;
7516 struct nlattr *params;
7517 int ifindex;
7518
7519 ifindex = if_nametoindex(intf);
7520 if (ifindex == 0) {
7521 sigma_dut_print(dut, DUT_MSG_ERROR,
7522 "%s: Index for interface %s failed",
7523 __func__, intf);
7524 return -1;
7525 }
7526
7527 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7528 NL80211_CMD_VENDOR)) ||
7529 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7530 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7531 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7532 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7533 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7534 nla_put_u8(msg,
7535 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7536 cfg)) {
7537 sigma_dut_print(dut, DUT_MSG_ERROR,
7538 "%s: err in adding vendor_cmd and vendor_data",
7539 __func__);
7540 nlmsg_free(msg);
7541 return -1;
7542 }
7543 nla_nest_end(msg, params);
7544
7545 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7546 if (ret) {
7547 sigma_dut_print(dut, DUT_MSG_ERROR,
7548 "%s: err in send_and_recv_msgs, ret=%d",
7549 __func__, ret);
7550 }
7551 return ret;
7552}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007553
7554
7555static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7556{
7557 struct nl_msg *msg;
7558 int ret = 0;
7559 struct nlattr *params;
7560 int ifindex;
7561
7562 ifindex = if_nametoindex(intf);
7563 if (ifindex == 0) {
7564 sigma_dut_print(dut, DUT_MSG_ERROR,
7565 "%s: Index for interface %s failed",
7566 __func__, intf);
7567 return -1;
7568 }
7569
7570 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7571 NL80211_CMD_VENDOR)) ||
7572 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7573 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7574 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7575 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7576 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7577 nla_put_u8(msg,
7578 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7579 cfg)) {
7580 sigma_dut_print(dut, DUT_MSG_ERROR,
7581 "%s: err in adding vendor_cmd and vendor_data",
7582 __func__);
7583 nlmsg_free(msg);
7584 return -1;
7585 }
7586 nla_nest_end(msg, params);
7587
7588 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7589 if (ret) {
7590 sigma_dut_print(dut, DUT_MSG_ERROR,
7591 "%s: err in send_and_recv_msgs, ret=%d",
7592 __func__, ret);
7593 }
7594 return ret;
7595}
7596
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007597#endif /* NL80211_SUPPORT */
7598
7599
Qiwei Caib6806972020-01-15 13:52:11 +08007600int sta_set_addba_buf_size(struct sigma_dut *dut,
7601 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007602{
7603#ifdef NL80211_SUPPORT
7604 struct nl_msg *msg;
7605 int ret = 0;
7606 struct nlattr *params;
7607 int ifindex;
7608
7609 ifindex = if_nametoindex(intf);
7610 if (ifindex == 0) {
7611 sigma_dut_print(dut, DUT_MSG_ERROR,
7612 "%s: Index for interface %s failed",
7613 __func__, intf);
7614 return -1;
7615 }
7616
7617 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7618 NL80211_CMD_VENDOR)) ||
7619 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7620 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7621 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7622 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7623 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07007624 nla_put_u16(msg,
7625 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
7626 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007627 sigma_dut_print(dut, DUT_MSG_ERROR,
7628 "%s: err in adding vendor_cmd and vendor_data",
7629 __func__);
7630 nlmsg_free(msg);
7631 return -1;
7632 }
7633 nla_nest_end(msg, params);
7634
7635 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7636 if (ret) {
7637 sigma_dut_print(dut, DUT_MSG_ERROR,
7638 "%s: err in send_and_recv_msgs, ret=%d",
7639 __func__, ret);
7640 }
7641 return ret;
7642#else /* NL80211_SUPPORT */
7643 sigma_dut_print(dut, DUT_MSG_ERROR,
7644 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7645 return -1;
7646#endif /* NL80211_SUPPORT */
7647}
7648
7649
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007650static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
7651 int enable)
7652{
7653#ifdef NL80211_SUPPORT
7654 struct nl_msg *msg;
7655 int ret = 0;
7656 struct nlattr *params;
7657 int ifindex;
7658
7659 ifindex = if_nametoindex(intf);
7660 if (ifindex == 0) {
7661 sigma_dut_print(dut, DUT_MSG_ERROR,
7662 "%s: Index for interface %s failed",
7663 __func__, intf);
7664 return -1;
7665 }
7666
7667 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7668 NL80211_CMD_VENDOR)) ||
7669 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7670 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7671 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7672 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7673 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7674 nla_put_u8(msg,
7675 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7676 enable)) {
7677 sigma_dut_print(dut, DUT_MSG_ERROR,
7678 "%s: err in adding vendor_cmd and vendor_data",
7679 __func__);
7680 nlmsg_free(msg);
7681 return -1;
7682 }
7683 nla_nest_end(msg, params);
7684
7685 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7686 if (ret) {
7687 sigma_dut_print(dut, DUT_MSG_ERROR,
7688 "%s: err in send_and_recv_msgs, ret=%d",
7689 __func__, ret);
7690 }
7691 return ret;
7692#else /* NL80211_SUPPORT */
7693 sigma_dut_print(dut, DUT_MSG_ERROR,
7694 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7695 return -1;
7696#endif /* NL80211_SUPPORT */
7697}
7698
7699
Arif Hussain9765f7d2018-07-03 08:28:26 -07007700static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7701 int val)
7702{
7703#ifdef NL80211_SUPPORT
7704 struct nl_msg *msg;
7705 int ret = 0;
7706 struct nlattr *params;
7707 int ifindex;
7708
7709 ifindex = if_nametoindex(intf);
7710 if (ifindex == 0) {
7711 sigma_dut_print(dut, DUT_MSG_ERROR,
7712 "%s: Index for interface %s failed, val:%d",
7713 __func__, intf, val);
7714 return -1;
7715 }
7716
7717 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7718 NL80211_CMD_VENDOR)) ||
7719 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7720 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7721 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7722 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7723 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7724 nla_put_u8(msg,
7725 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7726 val)) {
7727 sigma_dut_print(dut, DUT_MSG_ERROR,
7728 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7729 __func__, val);
7730 nlmsg_free(msg);
7731 return -1;
7732 }
7733 nla_nest_end(msg, params);
7734
7735 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7736 if (ret) {
7737 sigma_dut_print(dut, DUT_MSG_ERROR,
7738 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7739 __func__, ret, val);
7740 }
7741 return ret;
7742#else /* NL80211_SUPPORT */
7743 sigma_dut_print(dut, DUT_MSG_ERROR,
7744 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7745 return -1;
7746#endif /* NL80211_SUPPORT */
7747}
7748
7749
Arif Hussain68d23f52018-07-11 13:39:08 -07007750#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007751static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7752 enum qca_wlan_he_mac_padding_dur val)
7753{
Arif Hussain68d23f52018-07-11 13:39:08 -07007754 struct nl_msg *msg;
7755 int ret = 0;
7756 struct nlattr *params;
7757 int ifindex;
7758
7759 ifindex = if_nametoindex(intf);
7760 if (ifindex == 0) {
7761 sigma_dut_print(dut, DUT_MSG_ERROR,
7762 "%s: Index for interface %s failed, val:%d",
7763 __func__, intf, val);
7764 return -1;
7765 }
7766
7767 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7768 NL80211_CMD_VENDOR)) ||
7769 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7770 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7771 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7772 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7773 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7774 nla_put_u8(msg,
7775 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
7776 val)) {
7777 sigma_dut_print(dut, DUT_MSG_ERROR,
7778 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7779 __func__, val);
7780 nlmsg_free(msg);
7781 return -1;
7782 }
7783 nla_nest_end(msg, params);
7784
7785 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7786 if (ret) {
7787 sigma_dut_print(dut, DUT_MSG_ERROR,
7788 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7789 __func__, ret, val);
7790 }
7791 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07007792}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007793#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007794
7795
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007796static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7797 int val)
7798{
7799#ifdef NL80211_SUPPORT
7800 struct nl_msg *msg;
7801 int ret = 0;
7802 struct nlattr *params;
7803 int ifindex;
7804
7805 ifindex = if_nametoindex(intf);
7806 if (ifindex == 0) {
7807 sigma_dut_print(dut, DUT_MSG_ERROR,
7808 "%s: Index for interface %s failed, val:%d",
7809 __func__, intf, val);
7810 return -1;
7811 }
7812
7813 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7814 NL80211_CMD_VENDOR)) ||
7815 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7816 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7817 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7818 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7819 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7820 nla_put_u8(msg,
7821 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7822 val)) {
7823 sigma_dut_print(dut, DUT_MSG_ERROR,
7824 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7825 __func__, val);
7826 nlmsg_free(msg);
7827 return -1;
7828 }
7829 nla_nest_end(msg, params);
7830
7831 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7832 if (ret) {
7833 sigma_dut_print(dut, DUT_MSG_ERROR,
7834 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7835 __func__, ret, val);
7836 }
7837 return ret;
7838#else /* NL80211_SUPPORT */
7839 sigma_dut_print(dut, DUT_MSG_ERROR,
7840 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7841 return -1;
7842#endif /* NL80211_SUPPORT */
7843}
7844
7845
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007846#ifdef NL80211_SUPPORT
7847static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7848{
7849 struct nl_msg *msg;
7850 int ret = 0;
7851 struct nlattr *params;
7852 int ifindex;
7853
7854 ifindex = if_nametoindex(intf);
7855 if (ifindex == 0) {
7856 sigma_dut_print(dut, DUT_MSG_ERROR,
7857 "%s: Index for interface %s failed",
7858 __func__, intf);
7859 return -1;
7860 }
7861
7862 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7863 NL80211_CMD_VENDOR)) ||
7864 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7865 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7866 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7867 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7868 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7869 nla_put_flag(msg,
7870 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
7871 sigma_dut_print(dut, DUT_MSG_ERROR,
7872 "%s: err in adding vendor_cmd and vendor_data",
7873 __func__);
7874 nlmsg_free(msg);
7875 return -1;
7876 }
7877 nla_nest_end(msg, params);
7878
7879 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7880 if (ret) {
7881 sigma_dut_print(dut, DUT_MSG_ERROR,
7882 "%s: err in send_and_recv_msgs, ret=%d",
7883 __func__, ret);
7884 }
7885 return ret;
7886}
7887#endif /* NL80211_SUPPORT */
7888
7889
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007890static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7891 int val)
7892{
7893#ifdef NL80211_SUPPORT
7894 struct nl_msg *msg;
7895 int ret = 0;
7896 struct nlattr *params;
7897 int ifindex;
7898
7899 ifindex = if_nametoindex(intf);
7900 if (ifindex == 0) {
7901 sigma_dut_print(dut, DUT_MSG_ERROR,
7902 "%s: Index for interface %s failed, val:%d",
7903 __func__, intf, val);
7904 return -1;
7905 }
7906
7907 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7908 NL80211_CMD_VENDOR)) ||
7909 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7910 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7911 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7912 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7913 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7914 nla_put_u8(msg,
7915 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
7916 val)) {
7917 sigma_dut_print(dut, DUT_MSG_ERROR,
7918 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7919 __func__, val);
7920 nlmsg_free(msg);
7921 return -1;
7922 }
7923 nla_nest_end(msg, params);
7924
7925 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7926 if (ret) {
7927 sigma_dut_print(dut, DUT_MSG_ERROR,
7928 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7929 __func__, ret, val);
7930 }
7931 return ret;
7932#else /* NL80211_SUPPORT */
7933 sigma_dut_print(dut, DUT_MSG_ERROR,
7934 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7935 return -1;
7936#endif /* NL80211_SUPPORT */
7937}
7938
7939
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007940static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7941 int val)
7942{
7943#ifdef NL80211_SUPPORT
7944 struct nl_msg *msg;
7945 int ret = 0;
7946 struct nlattr *params;
7947 int ifindex;
7948
7949 ifindex = if_nametoindex(intf);
7950 if (ifindex == 0) {
7951 sigma_dut_print(dut, DUT_MSG_ERROR,
7952 "%s: Index for interface %s failed, val:%d",
7953 __func__, intf, val);
7954 return -1;
7955 }
7956
7957 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7958 NL80211_CMD_VENDOR)) ||
7959 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7960 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7961 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7962 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7963 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7964 nla_put_u8(msg,
7965 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
7966 val)) {
7967 sigma_dut_print(dut, DUT_MSG_ERROR,
7968 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7969 __func__, val);
7970 nlmsg_free(msg);
7971 return -1;
7972 }
7973 nla_nest_end(msg, params);
7974
7975 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7976 if (ret) {
7977 sigma_dut_print(dut, DUT_MSG_ERROR,
7978 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7979 __func__, ret, val);
7980 }
7981 return ret;
7982#else /* NL80211_SUPPORT */
7983 sigma_dut_print(dut, DUT_MSG_ERROR,
7984 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7985 return -1;
7986#endif /* NL80211_SUPPORT */
7987}
7988
7989
Arif Hussain480d5f42019-03-12 14:40:42 -07007990static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7991 int val)
7992{
7993#ifdef NL80211_SUPPORT
7994 struct nl_msg *msg;
7995 int ret;
7996 struct nlattr *params;
7997 int ifindex;
7998
7999 ifindex = if_nametoindex(intf);
8000 if (ifindex == 0) {
8001 sigma_dut_print(dut, DUT_MSG_ERROR,
8002 "%s: Index for interface %s failed, val:%d",
8003 __func__, intf, val);
8004 return -1;
8005 }
8006
8007 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8008 NL80211_CMD_VENDOR)) ||
8009 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8010 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8011 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8012 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8013 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8014 nla_put_u8(msg,
8015 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT,
8016 val)) {
8017 sigma_dut_print(dut, DUT_MSG_ERROR,
8018 "%s: err in adding vendor_cmd and vendor_data, val: %d",
8019 __func__, val);
8020 nlmsg_free(msg);
8021 return -1;
8022 }
8023 nla_nest_end(msg, params);
8024
8025 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8026 if (ret) {
8027 sigma_dut_print(dut, DUT_MSG_ERROR,
8028 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
8029 __func__, ret, val);
8030 }
8031 return ret;
8032#else /* NL80211_SUPPORT */
8033 sigma_dut_print(dut, DUT_MSG_ERROR,
8034 "TWT Request cannot be changed without NL80211_SUPPORT defined");
8035 return -1;
8036#endif /* NL80211_SUPPORT */
8037}
8038
8039
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008040static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
8041 const char *type)
8042{
8043 char buf[60];
8044
8045 if (dut->program == PROGRAM_HE) {
8046 /* resetting phymode to auto in case of HE program */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05308047 sta_set_phymode(dut, intf, "auto");
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008048
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07008049 /* reset the rate to Auto rate */
8050 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
8051 intf);
8052 if (system(buf) != 0) {
8053 sigma_dut_print(dut, DUT_MSG_ERROR,
8054 "iwpriv %s set_11ax_rate 0xff failed",
8055 intf);
8056 }
8057
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07008058 /* reset the LDPC setting */
8059 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
8060 if (system(buf) != 0) {
8061 sigma_dut_print(dut, DUT_MSG_ERROR,
8062 "iwpriv %s ldpc 1 failed", intf);
8063 }
8064
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08008065 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05308066 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08008067
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008068 /* remove all network profiles */
8069 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008070
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08008071 /* Configure ADDBA Req/Rsp buffer size to be 64 */
8072 sta_set_addba_buf_size(dut, intf, 64);
8073
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08008074#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008075 /* Reset the device HE capabilities to its default supported
8076 * configuration. */
8077 sta_set_he_testbed_def(dut, intf, 0);
8078
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08008079 /* Disable noackpolicy for all AC */
8080 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
8081 sigma_dut_print(dut, DUT_MSG_ERROR,
8082 "Disable of noackpolicy for all AC failed");
8083 }
8084#endif /* NL80211_SUPPORT */
8085
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08008086 /* Enable WMM by default */
8087 if (wcn_sta_set_wmm(dut, intf, "on")) {
8088 sigma_dut_print(dut, DUT_MSG_ERROR,
8089 "Enable of WMM in sta_reset_default_wcn failed");
8090 }
8091
8092 /* Disable ADDBA_REJECT by default */
8093 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
8094 sigma_dut_print(dut, DUT_MSG_ERROR,
8095 "Disable of addba_reject in sta_reset_default_wcn failed");
8096 }
8097
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08008098 /* Enable sending of ADDBA by default */
8099 if (nlvendor_config_send_addba(dut, intf, 1)) {
8100 sigma_dut_print(dut, DUT_MSG_ERROR,
8101 "Enable sending of ADDBA in sta_reset_default_wcn failed");
8102 }
8103
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08008104 /* Enable AMPDU by default */
8105 iwpriv_sta_set_ampdu(dut, intf, 1);
8106
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008107#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08008108 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008109 sigma_dut_print(dut, DUT_MSG_ERROR,
8110 "Set LTF config to default in sta_reset_default_wcn failed");
8111 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07008112
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08008113 /* set the beamformee NSTS(maximum number of
8114 * space-time streams) to default DUT config
8115 */
8116 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07008117 sigma_dut_print(dut, DUT_MSG_ERROR,
8118 "Failed to set BeamformeeSTS");
8119 }
Arif Hussain68d23f52018-07-11 13:39:08 -07008120
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008121 if (sta_set_mac_padding_duration(
8122 dut, intf,
8123 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008124 sigma_dut_print(dut, DUT_MSG_ERROR,
8125 "Failed to set MAC padding duration");
8126 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008127
8128 if (sta_set_mu_edca_override(dut, intf, 0)) {
8129 sigma_dut_print(dut, DUT_MSG_ERROR,
8130 "ErrorCode,Failed to set MU EDCA override disable");
8131 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008132
8133 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
8134 sigma_dut_print(dut, DUT_MSG_ERROR,
8135 "Failed to set OM ctrl supp");
8136 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07008137
8138 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
8139 sigma_dut_print(dut, DUT_MSG_ERROR,
8140 "Failed to set Tx SU PPDU enable");
8141 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008142
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07008143 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
8144 sigma_dut_print(dut, DUT_MSG_ERROR,
8145 "failed to send TB PPDU Tx cfg");
8146 }
8147
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07008148 if (sta_set_he_om_ctrl_reset(dut, intf)) {
8149 sigma_dut_print(dut, DUT_MSG_ERROR,
8150 "Failed to set OM ctrl reset");
8151 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08008152
8153 /* +HTC-HE support default on */
8154 if (sta_set_he_htc_supp(dut, intf, 1)) {
8155 sigma_dut_print(dut, DUT_MSG_ERROR,
8156 "Setting of +HTC-HE support failed");
8157 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07008158#endif /* NL80211_SUPPORT */
8159
Arif Hussain8d5b27b2018-05-14 14:31:03 -07008160 if (sta_set_tx_beamformee(dut, intf, 1)) {
8161 sigma_dut_print(dut, DUT_MSG_ERROR,
8162 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
8163 }
8164
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07008165 wpa_command(intf, "SET oce 1");
8166
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008167 /* Set nss to 1 and MCS 0-7 in case of testbed */
8168 if (type && strcasecmp(type, "Testbed") == 0) {
8169#ifdef NL80211_SUPPORT
8170 int ret;
8171#endif /* NL80211_SUPPORT */
8172
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07008173 wpa_command(intf, "SET oce 0");
8174
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008175 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
8176 if (system(buf) != 0) {
8177 sigma_dut_print(dut, DUT_MSG_ERROR,
8178 "iwpriv %s nss failed", intf);
8179 }
8180
8181#ifdef NL80211_SUPPORT
8182 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
8183 if (ret) {
8184 sigma_dut_print(dut, DUT_MSG_ERROR,
8185 "Setting of MCS failed, ret:%d",
8186 ret);
8187 }
8188#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08008189
8190 /* Disable STBC as default */
8191 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08008192
8193 /* Disable AMSDU as default */
8194 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08008195
8196#ifdef NL80211_SUPPORT
8197 /* HE fragmentation default off */
8198 if (sta_set_he_fragmentation(dut, intf,
8199 HE_FRAG_DISABLE)) {
8200 sigma_dut_print(dut, DUT_MSG_ERROR,
8201 "Setting of HE fragmentation failed");
8202 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08008203
8204 /* set the beamformee NSTS(maximum number of
8205 * space-time streams) to default testbed config
8206 */
8207 if (sta_set_beamformee_sts(dut, intf, 3)) {
8208 sigma_dut_print(dut, DUT_MSG_ERROR,
8209 "Failed to set BeamformeeSTS");
8210 }
8211
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08008212 /* +HTC-HE support default off */
8213 if (sta_set_he_htc_supp(dut, intf, 0)) {
8214 sigma_dut_print(dut, DUT_MSG_ERROR,
8215 "Setting of +HTC-HE support failed");
8216 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008217
8218 /* Set device HE capabilities to testbed default
8219 * configuration. */
8220 if (sta_set_he_testbed_def(dut, intf, 1)) {
8221 sigma_dut_print(dut, DUT_MSG_DEBUG,
8222 "Failed to set HE defaults");
8223 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08008224
8225 /* Disable VHT support in 2.4 GHz for testbed */
8226 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08008227#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08008228
8229 /* Enable WEP/TKIP with HE capability in testbed */
8230 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
8231 sigma_dut_print(dut, DUT_MSG_ERROR,
8232 "Enabling HE config with WEP/TKIP failed");
8233 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008234 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008235
8236 /* Defaults in case of DUT */
8237 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07008238 /* Enable STBC by default */
8239 wcn_sta_set_stbc(dut, intf, "1");
8240
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008241 /* set nss to 2 */
8242 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
8243 if (system(buf) != 0) {
8244 sigma_dut_print(dut, DUT_MSG_ERROR,
8245 "iwpriv %s nss 2 failed", intf);
8246 }
Arif Hussainac6c5112018-05-25 17:34:00 -07008247 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008248
8249#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07008250 /* Set HE_MCS to 0-11 */
8251 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008252 sigma_dut_print(dut, DUT_MSG_ERROR,
8253 "Setting of MCS failed");
8254 }
8255#endif /* NL80211_SUPPORT */
8256
8257 /* Disable WEP/TKIP with HE capability in DUT */
8258 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
8259 sigma_dut_print(dut, DUT_MSG_ERROR,
8260 "Enabling HE config with WEP/TKIP failed");
8261 }
8262 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008263 }
8264}
8265
8266
Jouni Malinenf7222712019-06-13 01:50:21 +03008267static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
8268 struct sigma_conn *conn,
8269 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008270{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008271 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008272 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008273 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008274 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308275 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008276
Jouni Malinenb21f0542019-11-04 17:53:38 +02008277 if (dut->station_ifname_2g &&
8278 strcmp(dut->station_ifname_2g, intf) == 0)
8279 dut->use_5g = 0;
8280 else if (dut->station_ifname_5g &&
8281 strcmp(dut->station_ifname_5g, intf) == 0)
8282 dut->use_5g = 1;
8283
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008284 if (!program)
8285 program = get_param(cmd, "prog");
8286 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008287 dut->device_type = STA_unknown;
8288 type = get_param(cmd, "type");
8289 if (type && strcasecmp(type, "Testbed") == 0)
8290 dut->device_type = STA_testbed;
8291 if (type && strcasecmp(type, "DUT") == 0)
8292 dut->device_type = STA_dut;
8293
8294 if (dut->program == PROGRAM_TDLS) {
8295 /* Clear TDLS testing mode */
8296 wpa_command(intf, "SET tdls_disabled 0");
8297 wpa_command(intf, "SET tdls_testing 0");
8298 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008299 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05308300 /* Enable the WCN driver in TDLS Explicit trigger mode
8301 */
8302 wpa_command(intf, "SET tdls_external_control 0");
8303 wpa_command(intf, "SET tdls_trigger_control 0");
8304 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008305 }
8306
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008307#ifdef MIRACAST
8308 if (dut->program == PROGRAM_WFD ||
8309 dut->program == PROGRAM_DISPLAYR2)
8310 miracast_sta_reset_default(dut, conn, cmd);
8311#endif /* MIRACAST */
8312
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008313 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008314 case DRIVER_ATHEROS:
8315 sta_reset_default_ath(dut, intf, type);
8316 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008317 case DRIVER_WCN:
8318 sta_reset_default_wcn(dut, intf, type);
8319 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008320 default:
8321 break;
8322 }
8323
8324#ifdef ANDROID_NAN
8325 if (dut->program == PROGRAM_NAN)
8326 nan_cmd_sta_reset_default(dut, conn, cmd);
8327#endif /* ANDROID_NAN */
8328
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05308329 if (dut->program == PROGRAM_LOC &&
8330 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
8331 return ERROR_SEND_STATUS;
8332
Jouni Malinenba630452018-06-22 11:49:59 +03008333 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008334 unlink("SP/wi-fi.org/pps.xml");
8335 if (system("rm -r SP/*") != 0) {
8336 }
8337 unlink("next-client-cert.pem");
8338 unlink("next-client-key.pem");
8339 }
8340
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008341 /* For WPS program of the 60 GHz band the band type needs to be saved */
8342 if (dut->program == PROGRAM_WPS) {
8343 if (band && strcasecmp(band, "60GHz") == 0) {
8344 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008345 /* For 60 GHz enable WPS for WPS TCs */
8346 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008347 } else {
8348 dut->band = WPS_BAND_NON_60G;
8349 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008350 } else if (dut->program == PROGRAM_60GHZ) {
8351 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
8352 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008353 }
8354
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02008355 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008356 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008357 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008358
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008359 sigma_dut_print(dut, DUT_MSG_INFO,
8360 "WPS 60 GHz program, wps_disable = %d",
8361 dut->wps_disable);
8362
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008363 if (!dev_role) {
8364 send_resp(dut, conn, SIGMA_ERROR,
8365 "errorCode,Missing DevRole argument");
8366 return 0;
8367 }
8368
8369 if (strcasecmp(dev_role, "STA") == 0)
8370 dut->dev_role = DEVROLE_STA;
8371 else if (strcasecmp(dev_role, "PCP") == 0)
8372 dut->dev_role = DEVROLE_PCP;
8373 else {
8374 send_resp(dut, conn, SIGMA_ERROR,
8375 "errorCode,Unknown DevRole");
8376 return 0;
8377 }
8378
8379 if (dut->device_type == STA_unknown) {
8380 sigma_dut_print(dut, DUT_MSG_ERROR,
8381 "Device type is not STA testbed or DUT");
8382 send_resp(dut, conn, SIGMA_ERROR,
8383 "errorCode,Unknown device type");
8384 return 0;
8385 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008386
8387 sigma_dut_print(dut, DUT_MSG_DEBUG,
8388 "Setting msdu_size to MAX: 7912");
8389 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008390 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008391
8392 if (system(buf) != 0) {
8393 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
8394 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008395 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008396 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008397
8398 if (sta_set_force_mcs(dut, 0, 1)) {
8399 sigma_dut_print(dut, DUT_MSG_ERROR,
8400 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008401 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008402 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008403 }
8404
8405 wpa_command(intf, "WPS_ER_STOP");
8406 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05308407 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008408 wpa_command(intf, "SET radio_disabled 0");
8409
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02008410 dut->wps_forced_version = 0;
8411
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008412 if (dut->wsc_fragment) {
8413 dut->wsc_fragment = 0;
8414 wpa_command(intf, "SET device_name Test client");
8415 wpa_command(intf, "SET manufacturer ");
8416 wpa_command(intf, "SET model_name ");
8417 wpa_command(intf, "SET model_number ");
8418 wpa_command(intf, "SET serial_number ");
8419 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02008420 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
8421 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
8422 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
8423 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008424
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008425 if (dut->tmp_mac_addr && dut->set_macaddr) {
8426 dut->tmp_mac_addr = 0;
8427 if (system(dut->set_macaddr) != 0) {
8428 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
8429 "temporary MAC address");
8430 }
8431 }
8432
8433 set_ps(intf, dut, 0);
8434
Jouni Malinenba630452018-06-22 11:49:59 +03008435 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
8436 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008437 wpa_command(intf, "SET interworking 1");
8438 wpa_command(intf, "SET hs20 1");
8439 }
8440
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008441 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03008442 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008443 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008444 wpa_command(intf, "SET pmf 1");
8445 } else {
8446 wpa_command(intf, "SET pmf 0");
8447 }
8448
8449 hs2_clear_credentials(intf);
8450 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
8451 wpa_command(intf, "SET access_network_type 15");
8452
8453 static_ip_file(0, NULL, NULL, NULL);
8454 kill_dhcp_client(dut, intf);
8455 clear_ip_addr(dut, intf);
8456
8457 dut->er_oper_performed = 0;
8458 dut->er_oper_bssid[0] = '\0';
8459
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008460 if (dut->program == PROGRAM_LOC) {
8461 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008462 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008463 }
8464
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07008465 if (dut->program == PROGRAM_MBO || dut->program == PROGRAM_HE) {
Ashwini Patil00402582017-04-13 12:29:39 +05308466 free(dut->non_pref_ch_list);
8467 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05308468 free(dut->btm_query_cand_list);
8469 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05308470 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05308471 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05308472 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05308473 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05308474 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05308475 }
8476
Jouni Malinen3c367e82017-06-23 17:01:47 +03008477 free(dut->rsne_override);
8478 dut->rsne_override = NULL;
8479
Jouni Malinen68143132017-09-02 02:34:08 +03008480 free(dut->sae_commit_override);
8481 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03008482 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02008483 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03008484
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008485 dut->sta_associate_wait_connect = 0;
8486 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03008487 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008488 dut->sta_tod_policy = 0;
8489
Jouni Malinend86e5822017-08-29 03:55:32 +03008490 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02008491 free(dut->dpp_peer_uri);
8492 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02008493 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02008494 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03008495 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03008496
Jouni Malinenfac9cad2017-10-10 18:35:55 +03008497 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
8498
vamsi krishnaa2799492017-12-05 14:28:01 +05308499 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308500 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05308501 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05308502 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
8503 dut->fils_hlp = 0;
8504#ifdef ANDROID
8505 hlp_thread_cleanup(dut);
8506#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05308507 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308508
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308509 if (dut->program == PROGRAM_QM)
8510 wpa_command(intf, "SET interworking 1");
8511
Jouni Malinen8179fee2019-03-28 03:19:47 +02008512 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03008513 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02008514
Sunil Dutt076081f2018-02-05 19:45:50 +05308515#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008516 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05308517 dut->config_rsnie == 1) {
8518 dut->config_rsnie = 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308519 sta_config_params(dut, intf, STA_SET_RSNIE, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05308520 }
8521#endif /* NL80211_SUPPORT */
8522
Sunil Duttfebf8a82018-02-09 18:50:13 +05308523 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
8524 dut->dev_role = DEVROLE_STA_CFON;
8525 return sta_cfon_reset_default(dut, conn, cmd);
8526 }
8527
Jouni Malinen439352d2018-09-13 03:42:23 +03008528 wpa_command(intf, "SET setband AUTO");
8529
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308530 dut->ocvc = 0;
Jouni Malinen67433fc2020-06-26 22:50:33 +03008531 dut->client_privacy = 0;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05308532 dut->saquery_oci_freq = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308533
Sunil Duttfebf8a82018-02-09 18:50:13 +05308534 if (dut->program != PROGRAM_VHT)
8535 return cmd_sta_p2p_reset(dut, conn, cmd);
8536
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08008537 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008538}
8539
8540
Jouni Malinenf7222712019-06-13 01:50:21 +03008541static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
8542 struct sigma_conn *conn,
8543 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008544{
8545 const char *program = get_param(cmd, "Program");
8546
8547 if (program == NULL)
8548 return -1;
8549#ifdef ANDROID_NAN
8550 if (strcasecmp(program, "NAN") == 0)
8551 return nan_cmd_sta_get_events(dut, conn, cmd);
8552#endif /* ANDROID_NAN */
8553 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8554 return 0;
8555}
8556
8557
Jouni Malinen82905202018-04-29 17:20:10 +03008558static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
8559 struct sigma_cmd *cmd)
8560{
8561 const char *url = get_param(cmd, "url");
8562 const char *method = get_param(cmd, "method");
8563 pid_t pid;
8564 int status;
8565
8566 if (!url || !method)
8567 return -1;
8568
8569 /* TODO: Add support for method,post */
8570 if (strcasecmp(method, "get") != 0) {
8571 send_resp(dut, conn, SIGMA_ERROR,
8572 "ErrorCode,Unsupported method");
8573 return 0;
8574 }
8575
8576 pid = fork();
8577 if (pid < 0) {
8578 perror("fork");
8579 return -1;
8580 }
8581
8582 if (pid == 0) {
8583 char * argv[5] = { "wget", "-O", "/dev/null",
8584 (char *) url, NULL };
8585
8586 execv("/usr/bin/wget", argv);
8587 perror("execv");
8588 exit(0);
8589 return -1;
8590 }
8591
8592 if (waitpid(pid, &status, 0) < 0) {
8593 perror("waitpid");
8594 return -1;
8595 }
8596
8597 if (WIFEXITED(status)) {
8598 const char *errmsg;
8599
8600 if (WEXITSTATUS(status) == 0)
8601 return 1;
8602 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
8603 WEXITSTATUS(status));
8604 switch (WEXITSTATUS(status)) {
8605 case 4:
8606 errmsg = "errmsg,Network failure";
8607 break;
8608 case 8:
8609 errmsg = "errmsg,Server issued an error response";
8610 break;
8611 default:
8612 errmsg = "errmsg,Unknown failure from wget";
8613 break;
8614 }
8615 send_resp(dut, conn, SIGMA_ERROR, errmsg);
8616 return 0;
8617 }
8618
8619 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
8620 return 0;
8621}
8622
8623
Jouni Malinenf7222712019-06-13 01:50:21 +03008624static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
8625 struct sigma_conn *conn,
8626 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008627{
8628 const char *program = get_param(cmd, "Prog");
8629
Jouni Malinen82905202018-04-29 17:20:10 +03008630 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008631 return -1;
8632#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03008633 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008634 return nan_cmd_sta_exec_action(dut, conn, cmd);
8635#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03008636
8637 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07008638 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03008639
8640 if (get_param(cmd, "url"))
8641 return sta_exec_action_url(dut, conn, cmd);
8642
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008643 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8644 return 0;
8645}
8646
8647
Jouni Malinenf7222712019-06-13 01:50:21 +03008648static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
8649 struct sigma_conn *conn,
8650 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008651{
8652 const char *intf = get_param(cmd, "Interface");
8653 const char *val, *mcs32, *rate;
8654
8655 val = get_param(cmd, "GREENFIELD");
8656 if (val) {
8657 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
8658 /* Enable GD */
8659 send_resp(dut, conn, SIGMA_ERROR,
8660 "ErrorCode,GF not supported");
8661 return 0;
8662 }
8663 }
8664
8665 val = get_param(cmd, "SGI20");
8666 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008667 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008668 case DRIVER_ATHEROS:
8669 ath_sta_set_sgi(dut, intf, val);
8670 break;
8671 default:
8672 send_resp(dut, conn, SIGMA_ERROR,
8673 "ErrorCode,SGI20 not supported");
8674 return 0;
8675 }
8676 }
8677
8678 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
8679 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
8680 if (mcs32 && rate) {
8681 /* TODO */
8682 send_resp(dut, conn, SIGMA_ERROR,
8683 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
8684 return 0;
8685 } else if (mcs32 && !rate) {
8686 /* TODO */
8687 send_resp(dut, conn, SIGMA_ERROR,
8688 "ErrorCode,MCS32 not supported");
8689 return 0;
8690 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008691 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008692 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008693 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008694 ath_sta_set_11nrates(dut, intf, rate);
8695 break;
8696 default:
8697 send_resp(dut, conn, SIGMA_ERROR,
8698 "ErrorCode,MCS32_FIXEDRATE not supported");
8699 return 0;
8700 }
8701 }
8702
8703 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8704}
8705
8706
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008707static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8708 int mcs_config)
8709{
8710#ifdef NL80211_SUPPORT
8711 int ret;
8712
8713 switch (mcs_config) {
8714 case HE_80_MCS0_7:
8715 case HE_80_MCS0_9:
8716 case HE_80_MCS0_11:
8717 ret = sta_set_he_mcs(dut, intf, mcs_config);
8718 if (ret) {
8719 sigma_dut_print(dut, DUT_MSG_ERROR,
8720 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8721 mcs_config, ret);
8722 }
8723 break;
8724 default:
8725 sigma_dut_print(dut, DUT_MSG_ERROR,
8726 "cmd_set_max_he_mcs: Invalid mcs %d",
8727 mcs_config);
8728 break;
8729 }
8730#else /* NL80211_SUPPORT */
8731 sigma_dut_print(dut, DUT_MSG_ERROR,
8732 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8733#endif /* NL80211_SUPPORT */
8734}
8735
8736
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008737#define TWT_REQUEST_CMD 0
8738#define TWT_SUGGEST_CMD 1
8739#define TWT_DEMAND_CMD 2
8740
Arif Hussain480d5f42019-03-12 14:40:42 -07008741static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8742 struct sigma_cmd *cmd)
8743{
8744#ifdef NL80211_SUPPORT
8745 struct nlattr *params;
8746 struct nlattr *attr;
8747 struct nlattr *attr1;
8748 struct nl_msg *msg;
8749 int ifindex, ret;
8750 const char *val;
8751 const char *intf = get_param(cmd, "Interface");
8752 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8753 wake_interval_mantissa = 512;
8754 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008755 protection = 0, cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
Arif Hussain480d5f42019-03-12 14:40:42 -07008756
8757 ifindex = if_nametoindex(intf);
8758 if (ifindex == 0) {
8759 sigma_dut_print(dut, DUT_MSG_ERROR,
8760 "%s: Index for interface %s failed",
8761 __func__, intf);
8762 return -1;
8763 }
8764
8765 val = get_param(cmd, "FlowType");
8766 if (val) {
8767 flow_type = atoi(val);
8768 if (flow_type != 0 && flow_type != 1) {
8769 sigma_dut_print(dut, DUT_MSG_ERROR,
8770 "TWT: Invalid FlowType %d", flow_type);
8771 return -1;
8772 }
8773 }
8774
8775 val = get_param(cmd, "TWT_Trigger");
8776 if (val) {
8777 twt_trigger = atoi(val);
8778 if (twt_trigger != 0 && twt_trigger != 1) {
8779 sigma_dut_print(dut, DUT_MSG_ERROR,
8780 "TWT: Invalid TWT_Trigger %d",
8781 twt_trigger);
8782 return -1;
8783 }
8784 }
8785
8786 val = get_param(cmd, "Protection");
8787 if (val) {
8788 protection = atoi(val);
8789 if (protection != 0 && protection != 1) {
8790 sigma_dut_print(dut, DUT_MSG_ERROR,
8791 "TWT: Invalid Protection %d",
8792 protection);
8793 return -1;
8794 }
8795 }
8796
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008797 val = get_param(cmd, "SetupCommand");
8798 if (val) {
8799 cmd_type = atoi(val);
8800 if (cmd_type == TWT_REQUEST_CMD)
8801 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_REQUEST;
8802 else if (cmd_type == TWT_SUGGEST_CMD)
8803 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
8804 else if (cmd_type == TWT_DEMAND_CMD)
8805 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_DEMAND;
8806 else
8807 sigma_dut_print(dut, DUT_MSG_ERROR,
8808 "Default suggest is used for cmd %d",
8809 cmd_type);
8810 }
8811
Arif Hussain480d5f42019-03-12 14:40:42 -07008812 val = get_param(cmd, "TargetWakeTime");
8813 if (val)
8814 target_wake_time = atoi(val);
8815
8816 val = get_param(cmd, "WakeIntervalMantissa");
8817 if (val)
8818 wake_interval_mantissa = atoi(val);
8819
8820 val = get_param(cmd, "WakeIntervalExp");
8821 if (val)
8822 wake_interval_exp = atoi(val);
8823
8824 val = get_param(cmd, "NominalMinWakeDur");
8825 if (val)
8826 nominal_min_wake_dur = atoi(val);
8827
8828 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8829 NL80211_CMD_VENDOR)) ||
8830 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8831 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8832 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8833 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8834 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8835 !(params = nla_nest_start(
8836 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
8837 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8838 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8839 wake_interval_exp) ||
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008840 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, cmd_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008841 (twt_trigger &&
8842 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008843 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8844 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008845 (protection &&
8846 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008847 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8848 target_wake_time) ||
8849 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8850 nominal_min_wake_dur) ||
8851 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8852 wake_interval_mantissa)) {
8853 sigma_dut_print(dut, DUT_MSG_ERROR,
8854 "%s: err in adding vendor_cmd and vendor_data",
8855 __func__);
8856 nlmsg_free(msg);
8857 return -1;
8858 }
8859 nla_nest_end(msg, attr1);
8860 nla_nest_end(msg, params);
8861 nla_nest_end(msg, attr);
8862
8863 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8864 if (ret) {
8865 sigma_dut_print(dut, DUT_MSG_ERROR,
8866 "%s: err in send_and_recv_msgs, ret=%d",
8867 __func__, ret);
8868 }
8869
8870 return ret;
8871#else /* NL80211_SUPPORT */
8872 sigma_dut_print(dut, DUT_MSG_ERROR,
8873 "TWT request cannot be done without NL80211_SUPPORT defined");
8874 return -1;
8875#endif /* NL80211_SUPPORT */
8876}
8877
8878
8879static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8880 struct sigma_cmd *cmd)
8881{
8882 #ifdef NL80211_SUPPORT
8883 struct nlattr *params;
8884 struct nlattr *attr;
8885 struct nlattr *attr1;
8886 int ifindex, ret;
8887 struct nl_msg *msg;
8888 const char *intf = get_param(cmd, "Interface");
8889
8890 ifindex = if_nametoindex(intf);
8891 if (ifindex == 0) {
8892 sigma_dut_print(dut, DUT_MSG_ERROR,
8893 "%s: Index for interface %s failed",
8894 __func__, intf);
8895 return -1;
8896 }
8897
8898 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8899 NL80211_CMD_VENDOR)) ||
8900 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8901 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8902 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8903 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8904 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8905 !(params = nla_nest_start(
8906 msg,
8907 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8908 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8909 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8910 sigma_dut_print(dut, DUT_MSG_ERROR,
8911 "%s: err in adding vendor_cmd and vendor_data",
8912 __func__);
8913 nlmsg_free(msg);
8914 return -1;
8915 }
8916 nla_nest_end(msg, attr1);
8917 nla_nest_end(msg, params);
8918 nla_nest_end(msg, attr);
8919
8920 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8921 if (ret) {
8922 sigma_dut_print(dut, DUT_MSG_ERROR,
8923 "%s: err in send_and_recv_msgs, ret=%d",
8924 __func__, ret);
8925 }
8926
8927 return ret;
8928#else /* NL80211_SUPPORT */
8929 sigma_dut_print(dut, DUT_MSG_ERROR,
8930 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8931 return -1;
8932#endif /* NL80211_SUPPORT */
8933}
8934
8935
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008936static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8937 struct sigma_cmd *cmd)
8938{
8939#ifdef NL80211_SUPPORT
8940 struct nlattr *params;
8941 struct nlattr *attr;
8942 struct nlattr *attr1;
8943 struct nl_msg *msg;
8944 int ifindex, ret;
8945 const char *val;
8946 const char *intf = get_param(cmd, "Interface");
8947 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8948 ulmu_data_dis = 0;
8949
8950 ifindex = if_nametoindex(intf);
8951 if (ifindex == 0) {
8952 sigma_dut_print(dut, DUT_MSG_ERROR,
8953 "%s: Index for interface %s failed",
8954 __func__, intf);
8955 return -1;
8956 }
8957 val = get_param(cmd, "OMCtrl_RxNSS");
8958 if (val)
8959 rx_nss = atoi(val);
8960
8961 val = get_param(cmd, "OMCtrl_ChnlWidth");
8962 if (val)
8963 ch_bw = atoi(val);
8964
8965 val = get_param(cmd, "OMCtrl_ULMUDisable");
8966 if (val)
8967 ulmu_dis = atoi(val);
8968
8969 val = get_param(cmd, "OMCtrl_TxNSTS");
8970 if (val)
8971 tx_nsts = atoi(val);
8972
8973 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8974 if (val)
8975 ulmu_data_dis = atoi(val);
8976
8977 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8978 NL80211_CMD_VENDOR)) ||
8979 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8980 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8981 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8982 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8983 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8984 !(params = nla_nest_start(
8985 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8986 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8987 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8988 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8989 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8990 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8991 ulmu_data_dis) ||
8992 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8993 ulmu_dis)) {
8994 sigma_dut_print(dut, DUT_MSG_ERROR,
8995 "%s: err in adding vendor_cmd and vendor_data",
8996 __func__);
8997 nlmsg_free(msg);
8998 return -1;
8999 }
9000 nla_nest_end(msg, attr1);
9001 nla_nest_end(msg, params);
9002 nla_nest_end(msg, attr);
9003
9004 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9005 if (ret) {
9006 sigma_dut_print(dut, DUT_MSG_ERROR,
9007 "%s: err in send_and_recv_msgs, ret=%d",
9008 __func__, ret);
9009 }
9010
9011 return ret;
9012#else /* NL80211_SUPPORT */
9013 sigma_dut_print(dut, DUT_MSG_ERROR,
9014 "OMI TX cannot be processed without NL80211_SUPPORT defined");
9015 return -1;
9016#endif /* NL80211_SUPPORT */
9017}
9018
9019
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009020static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
9021 struct sigma_conn *conn,
9022 struct sigma_cmd *cmd)
9023{
9024 const char *intf = get_param(cmd, "Interface");
9025 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07009026 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009027 int tkip = -1;
9028 int wep = -1;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309029 int iwpriv_status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009030
Arif Hussaina37e9552018-06-20 17:05:59 -07009031 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009032 val = get_param(cmd, "SGI80");
9033 if (val) {
9034 int sgi80;
9035
9036 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009037 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009038 }
9039
9040 val = get_param(cmd, "TxBF");
9041 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009042 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009043 case DRIVER_WCN:
9044 if (sta_set_tx_beamformee(dut, intf, 1)) {
9045 send_resp(dut, conn, SIGMA_ERROR,
9046 "ErrorCode,Failed to set TX beamformee enable");
9047 return 0;
9048 }
9049 break;
9050 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009051 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009052 send_resp(dut, conn, SIGMA_ERROR,
9053 "ErrorCode,Setting vhtsubfee failed");
9054 return 0;
9055 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009056 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009057 send_resp(dut, conn, SIGMA_ERROR,
9058 "ErrorCode,Setting vhtsubfer failed");
9059 return 0;
9060 }
9061 break;
9062 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009063 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07009064 "Unsupported driver type");
9065 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009066 }
9067 }
9068
9069 val = get_param(cmd, "MU_TxBF");
9070 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009071 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009072 case DRIVER_ATHEROS:
9073 ath_sta_set_txsp_stream(dut, intf, "1SS");
9074 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009075 run_iwpriv(dut, intf, "vhtmubfee 1");
9076 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05309077 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009078 case DRIVER_WCN:
9079 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
9080 send_resp(dut, conn, SIGMA_ERROR,
9081 "ErrorCode,Failed to set RX/TXSP_STREAM");
9082 return 0;
9083 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05309084 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009085 default:
9086 sigma_dut_print(dut, DUT_MSG_ERROR,
9087 "Setting SP_STREAM not supported");
9088 break;
9089 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009090 }
9091
9092 val = get_param(cmd, "LDPC");
9093 if (val) {
9094 int ldpc;
9095
9096 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309097 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", ldpc);
9098 if (iwpriv_status)
9099 sta_config_params(dut, intf, STA_SET_LDPC, ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009100 }
9101
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08009102 val = get_param(cmd, "BCC");
9103 if (val) {
9104 int bcc;
9105
9106 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9107 /* use LDPC iwpriv itself to set bcc coding, bcc coding
9108 * is mutually exclusive to bcc */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05309109 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", !bcc);
9110 if (iwpriv_status)
9111 sta_config_params(dut, intf, STA_SET_LDPC, !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08009112 }
9113
Arif Hussain7b47d2d2018-05-09 10:44:02 -07009114 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
9115 if (val && dut->sta_nss == 1)
9116 cmd_set_max_he_mcs(dut, intf, atoi(val));
9117
9118 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
9119 if (val && dut->sta_nss == 2)
9120 cmd_set_max_he_mcs(dut, intf, atoi(val));
9121
Arif Hussainac6c5112018-05-25 17:34:00 -07009122 val = get_param(cmd, "MCS_FixedRate");
9123 if (val) {
9124#ifdef NL80211_SUPPORT
9125 int mcs, ratecode = 0;
9126 enum he_mcs_config mcs_config;
9127 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03009128 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07009129
9130 ratecode = (0x07 & dut->sta_nss) << 5;
9131 mcs = atoi(val);
9132 /* Add the MCS to the ratecode */
9133 if (mcs >= 0 && mcs <= 11) {
9134 ratecode += mcs;
9135 if (dut->device_type == STA_testbed &&
9136 mcs > 7 && mcs <= 11) {
9137 if (mcs <= 9)
9138 mcs_config = HE_80_MCS0_9;
9139 else
9140 mcs_config = HE_80_MCS0_11;
9141 ret = sta_set_he_mcs(dut, intf, mcs_config);
9142 if (ret) {
9143 sigma_dut_print(dut, DUT_MSG_ERROR,
9144 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
9145 mcs, mcs_config, ret);
9146 }
9147 }
9148 snprintf(buf, sizeof(buf),
9149 "iwpriv %s set_11ax_rate 0x%03x",
9150 intf, ratecode);
9151 if (system(buf) != 0) {
9152 sigma_dut_print(dut, DUT_MSG_ERROR,
9153 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
9154 ratecode);
9155 }
9156 } else {
9157 sigma_dut_print(dut, DUT_MSG_ERROR,
9158 "MCS_FixedRate: HE MCS %d not supported",
9159 mcs);
9160 }
9161#else /* NL80211_SUPPORT */
9162 sigma_dut_print(dut, DUT_MSG_ERROR,
9163 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
9164#endif /* NL80211_SUPPORT */
9165 }
9166
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009167 val = get_param(cmd, "opt_md_notif_ie");
9168 if (val) {
9169 char *result = NULL;
9170 char delim[] = ";";
9171 char token[30];
9172 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309173 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009174
Peng Xub8fc5cc2017-05-10 17:27:28 -07009175 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309176 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009177
9178 /* Extract the NSS information */
9179 if (result) {
9180 value = atoi(result);
9181 switch (value) {
9182 case 1:
9183 config_val = 1;
9184 break;
9185 case 2:
9186 config_val = 3;
9187 break;
9188 case 3:
9189 config_val = 7;
9190 break;
9191 case 4:
9192 config_val = 15;
9193 break;
9194 default:
9195 config_val = 3;
9196 break;
9197 }
9198
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009199 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
9200 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009201
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009202 }
9203
9204 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309205 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009206 if (result) {
9207 value = atoi(result);
9208 switch (value) {
9209 case 20:
9210 config_val = 0;
9211 break;
9212 case 40:
9213 config_val = 1;
9214 break;
9215 case 80:
9216 config_val = 2;
9217 break;
9218 case 160:
9219 config_val = 3;
9220 break;
9221 default:
9222 config_val = 2;
9223 break;
9224 }
9225
9226 dut->chwidth = config_val;
9227
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009228 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009229 }
9230
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009231 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009232 }
9233
9234 val = get_param(cmd, "nss_mcs_cap");
9235 if (val) {
9236 int nss, mcs;
9237 char token[20];
9238 char *result = NULL;
9239 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309240 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009241
Peng Xub8fc5cc2017-05-10 17:27:28 -07009242 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309243 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309244 if (!result) {
9245 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009246 "NSS not specified");
9247 send_resp(dut, conn, SIGMA_ERROR,
9248 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309249 return 0;
9250 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009251 nss = atoi(result);
9252
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009253 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07009254 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009255
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309256 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009257 if (result == NULL) {
9258 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009259 "MCS not specified");
9260 send_resp(dut, conn, SIGMA_ERROR,
9261 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009262 return 0;
9263 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309264 result = strtok_r(result, "-", &saveptr);
9265 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309266 if (!result) {
9267 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009268 "MCS not specified");
9269 send_resp(dut, conn, SIGMA_ERROR,
9270 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309271 return 0;
9272 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009273 mcs = atoi(result);
9274
Arif Hussaina37e9552018-06-20 17:05:59 -07009275 if (program && strcasecmp(program, "HE") == 0) {
9276#ifdef NL80211_SUPPORT
9277 enum he_mcs_config mcs_config;
9278 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009279
Arif Hussaina37e9552018-06-20 17:05:59 -07009280 if (mcs >= 0 && mcs <= 7) {
9281 mcs_config = HE_80_MCS0_7;
9282 } else if (mcs > 7 && mcs <= 9) {
9283 mcs_config = HE_80_MCS0_9;
9284 } else if (mcs > 9 && mcs <= 11) {
9285 mcs_config = HE_80_MCS0_11;
9286 } else {
9287 sigma_dut_print(dut, DUT_MSG_ERROR,
9288 "nss_mcs_cap: HE: Invalid mcs: %d",
9289 mcs);
9290 send_resp(dut, conn, SIGMA_ERROR,
9291 "errorCode,Invalid MCS");
9292 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009293 }
Arif Hussaina37e9552018-06-20 17:05:59 -07009294
9295 ret = sta_set_he_mcs(dut, intf, mcs_config);
9296 if (ret) {
9297 sigma_dut_print(dut, DUT_MSG_ERROR,
9298 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
9299 mcs_config, ret);
9300 send_resp(dut, conn, SIGMA_ERROR,
9301 "errorCode,Failed to set MCS");
9302 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009303 }
Arif Hussaina37e9552018-06-20 17:05:59 -07009304#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009305 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009306 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
9307#endif /* NL80211_SUPPORT */
9308 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009309 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07009310
9311 switch (nss) {
9312 case 1:
9313 switch (mcs) {
9314 case 7:
9315 vht_mcsmap = 0xfffc;
9316 break;
9317 case 8:
9318 vht_mcsmap = 0xfffd;
9319 break;
9320 case 9:
9321 vht_mcsmap = 0xfffe;
9322 break;
9323 default:
9324 vht_mcsmap = 0xfffe;
9325 break;
9326 }
9327 break;
9328 case 2:
9329 switch (mcs) {
9330 case 7:
9331 vht_mcsmap = 0xfff0;
9332 break;
9333 case 8:
9334 vht_mcsmap = 0xfff5;
9335 break;
9336 case 9:
9337 vht_mcsmap = 0xfffa;
9338 break;
9339 default:
9340 vht_mcsmap = 0xfffa;
9341 break;
9342 }
9343 break;
9344 case 3:
9345 switch (mcs) {
9346 case 7:
9347 vht_mcsmap = 0xffc0;
9348 break;
9349 case 8:
9350 vht_mcsmap = 0xffd5;
9351 break;
9352 case 9:
9353 vht_mcsmap = 0xffea;
9354 break;
9355 default:
9356 vht_mcsmap = 0xffea;
9357 break;
9358 }
9359 break;
9360 default:
9361 vht_mcsmap = 0xffea;
9362 break;
9363 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009364 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009365 }
9366 }
9367
9368 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
9369
9370 val = get_param(cmd, "Vht_tkip");
9371 if (val)
9372 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9373
9374 val = get_param(cmd, "Vht_wep");
9375 if (val)
9376 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9377
9378 if (tkip != -1 || wep != -1) {
9379 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009380 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009381 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009382 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009383 } else {
9384 sigma_dut_print(dut, DUT_MSG_ERROR,
9385 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
9386 return 0;
9387 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009388 }
9389
Arif Hussain55f00da2018-07-03 08:28:26 -07009390 val = get_param(cmd, "txBandwidth");
9391 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009392 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07009393 case DRIVER_WCN:
9394 if (wcn_sta_set_width(dut, intf, val) < 0) {
9395 send_resp(dut, conn, SIGMA_ERROR,
9396 "ErrorCode,Failed to set txBandwidth");
9397 return 0;
9398 }
9399 break;
9400 case DRIVER_ATHEROS:
9401 if (ath_set_width(dut, conn, intf, val) < 0) {
9402 send_resp(dut, conn, SIGMA_ERROR,
9403 "ErrorCode,Failed to set txBandwidth");
9404 return 0;
9405 }
9406 break;
9407 default:
9408 sigma_dut_print(dut, DUT_MSG_ERROR,
9409 "Setting txBandwidth not supported");
9410 break;
9411 }
9412 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009413
Arif Hussain9765f7d2018-07-03 08:28:26 -07009414 val = get_param(cmd, "BeamformeeSTS");
9415 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07009416 if (sta_set_tx_beamformee(dut, intf, 1)) {
9417 send_resp(dut, conn, SIGMA_ERROR,
9418 "ErrorCode,Failed to set TX beamformee enable");
9419 return 0;
9420 }
9421
Arif Hussain9765f7d2018-07-03 08:28:26 -07009422 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
9423 send_resp(dut, conn, SIGMA_ERROR,
9424 "ErrorCode,Failed to set BeamformeeSTS");
9425 return 0;
9426 }
9427 }
9428
Arif Hussain68d23f52018-07-11 13:39:08 -07009429 val = get_param(cmd, "Trig_MAC_Padding_Dur");
9430 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07009431#ifdef NL80211_SUPPORT
9432 enum qca_wlan_he_mac_padding_dur set_val;
9433
9434 switch (atoi(val)) {
9435 case 16:
9436 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
9437 break;
9438 case 8:
9439 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
9440 break;
9441 default:
9442 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
9443 break;
9444 }
9445 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07009446 send_resp(dut, conn, SIGMA_ERROR,
9447 "ErrorCode,Failed to set MAC padding duration");
9448 return 0;
9449 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07009450#else /* NL80211_SUPPORT */
9451 sigma_dut_print(dut, DUT_MSG_ERROR,
9452 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
9453#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07009454 }
9455
Arif Hussain480d5f42019-03-12 14:40:42 -07009456 val = get_param(cmd, "TWT_ReqSupport");
9457 if (val) {
9458 int set_val;
9459
9460 if (strcasecmp(val, "Enable") == 0) {
9461 set_val = 1;
9462 } else if (strcasecmp(val, "Disable") == 0) {
9463 set_val = 0;
9464 } else {
9465 send_resp(dut, conn, SIGMA_ERROR,
9466 "ErrorCode,Invalid TWT_ReqSupport");
9467 return STATUS_SENT;
9468 }
9469
9470 if (sta_set_twt_req_support(dut, intf, set_val)) {
9471 sigma_dut_print(dut, DUT_MSG_ERROR,
9472 "Failed to set TWT req support %d",
9473 set_val);
9474 send_resp(dut, conn, SIGMA_ERROR,
9475 "ErrorCode,Failed to set TWT_ReqSupport");
9476 return STATUS_SENT;
9477 }
9478 }
9479
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07009480 val = get_param(cmd, "MU_EDCA");
9481 if (val && (strcasecmp(val, "Override") == 0)) {
9482 if (sta_set_mu_edca_override(dut, intf, 1)) {
9483 send_resp(dut, conn, SIGMA_ERROR,
9484 "ErrorCode,Failed to set MU EDCA override");
9485 return 0;
9486 }
9487 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009488
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07009489 val = get_param(cmd, "OMControl");
9490 if (val) {
9491 int set_val = 1;
9492
9493 if (strcasecmp(val, "Enable") == 0)
9494 set_val = 1;
9495 else if (strcasecmp(val, "Disable") == 0)
9496 set_val = 0;
9497
9498 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
9499 send_resp(dut, conn, SIGMA_ERROR,
9500 "ErrorCode,Failed to set OM ctrl supp");
9501 return 0;
9502 }
9503 }
9504
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009505 val = get_param(cmd, "ADDBAResp_BufSize");
9506 if (val) {
9507 int buf_size;
9508
9509 if (strcasecmp(val, "gt64") == 0)
9510 buf_size = 256;
9511 else
9512 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009513 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009514 sta_set_addba_buf_size(dut, intf, buf_size)) {
9515 send_resp(dut, conn, SIGMA_ERROR,
9516 "ErrorCode,set addbaresp_buff_size failed");
9517 return 0;
9518 }
9519 }
9520
9521 val = get_param(cmd, "ADDBAReq_BufSize");
9522 if (val) {
9523 int buf_size;
9524
9525 if (strcasecmp(val, "gt64") == 0)
9526 buf_size = 256;
9527 else
9528 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009529 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009530 sta_set_addba_buf_size(dut, intf, buf_size)) {
9531 send_resp(dut, conn, SIGMA_ERROR,
9532 "ErrorCode,set addbareq_buff_size failed");
9533 return 0;
9534 }
9535 }
9536
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009537 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9538}
9539
9540
9541static int sta_set_wireless_60g(struct sigma_dut *dut,
9542 struct sigma_conn *conn,
9543 struct sigma_cmd *cmd)
9544{
9545 const char *dev_role = get_param(cmd, "DevRole");
9546
9547 if (!dev_role) {
9548 send_resp(dut, conn, SIGMA_INVALID,
9549 "ErrorCode,DevRole not specified");
9550 return 0;
9551 }
9552
9553 if (strcasecmp(dev_role, "PCP") == 0)
9554 return sta_set_60g_pcp(dut, conn, cmd);
9555 if (strcasecmp(dev_role, "STA") == 0)
9556 return sta_set_60g_sta(dut, conn, cmd);
9557 send_resp(dut, conn, SIGMA_INVALID,
9558 "ErrorCode,DevRole not supported");
9559 return 0;
9560}
9561
9562
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309563static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
9564 struct sigma_cmd *cmd)
9565{
9566 int status;
9567 const char *intf = get_param(cmd, "Interface");
9568 const char *val = get_param(cmd, "DevRole");
9569
9570 if (val && strcasecmp(val, "STA-CFON") == 0) {
9571 status = sta_cfon_set_wireless(dut, conn, cmd);
9572 if (status)
9573 return status;
9574 }
9575 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9576}
9577
9578
Jouni Malinen67433fc2020-06-26 22:50:33 +03009579static enum sigma_cmd_result
9580sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
9581 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309582{
9583 const char *intf = get_param(cmd, "Interface");
9584 const char *val;
9585
9586 val = get_param(cmd, "ocvc");
9587 if (val)
9588 dut->ocvc = atoi(val);
9589
Jouni Malinen67433fc2020-06-26 22:50:33 +03009590 val = get_param(cmd, "ClientPrivacy");
9591 if (val) {
9592 dut->client_privacy = atoi(val);
9593 if (dut->client_privacy &&
9594 (wpa_command(intf, "SET mac_addr 1") < 0 ||
9595 wpa_command(intf, "SET rand_addr_lifetime 1") < 0 ||
9596 wpa_command(intf, "SET preassoc_mac_addr 1") < 0 ||
9597 wpa_command(intf, "SET gas_rand_mac_addr 1") < 0 ||
9598 wpa_command(intf, "SET gas_rand_addr_lifetime 1") < 0)) {
9599 send_resp(dut, conn, SIGMA_ERROR,
9600 "errorCode,Failed to enable random MAC address use");
9601 return STATUS_SENT_ERROR;
9602 }
9603 }
9604
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309605 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9606}
9607
9608
Jouni Malinenf7222712019-06-13 01:50:21 +03009609static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
9610 struct sigma_conn *conn,
9611 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009612{
9613 const char *val;
9614
9615 val = get_param(cmd, "Program");
9616 if (val) {
9617 if (strcasecmp(val, "11n") == 0)
9618 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08009619 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009620 return cmd_sta_set_wireless_vht(dut, conn, cmd);
9621 if (strcasecmp(val, "60ghz") == 0)
9622 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309623 if (strcasecmp(val, "OCE") == 0)
9624 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02009625 /* sta_set_wireless in WPS program is only used for 60G */
9626 if (is_60g_sigma_dut(dut))
9627 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309628 if (strcasecmp(val, "WPA3") == 0)
9629 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009630 send_resp(dut, conn, SIGMA_ERROR,
9631 "ErrorCode,Program value not supported");
9632 } else {
9633 send_resp(dut, conn, SIGMA_ERROR,
9634 "ErrorCode,Program argument not available");
9635 }
9636
9637 return 0;
9638}
9639
9640
9641static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
9642 int tid)
9643{
9644 char buf[100];
9645 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
9646
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05309647 if (tid < 0 ||
9648 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
9649 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
9650 return;
9651 }
9652
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009653 /*
9654 * Two ways to ensure that addba request with a
9655 * non zero TID could be sent out. EV 117296
9656 */
9657 snprintf(buf, sizeof(buf),
9658 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
9659 tid);
9660 if (system(buf) != 0) {
9661 sigma_dut_print(dut, DUT_MSG_ERROR,
9662 "Ping did not send out");
9663 }
9664
9665 snprintf(buf, sizeof(buf),
9666 "iwconfig %s | grep Access | awk '{print $6}' > %s",
9667 intf, VI_QOS_TMP_FILE);
9668 if (system(buf) != 0)
9669 return;
9670
9671 snprintf(buf, sizeof(buf),
9672 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
9673 intf, VI_QOS_TMP_FILE);
9674 if (system(buf) != 0)
9675 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
9676
9677 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
9678 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
9679 if (system(buf) != 0) {
9680 sigma_dut_print(dut, DUT_MSG_ERROR,
9681 "VI_QOS_TEMP_FILE generation error failed");
9682 }
9683 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9684 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9685 if (system(buf) != 0) {
9686 sigma_dut_print(dut, DUT_MSG_ERROR,
9687 "VI_QOS_FILE generation failed");
9688 }
9689
9690 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9691 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9692 if (system(buf) != 0) {
9693 sigma_dut_print(dut, DUT_MSG_ERROR,
9694 "VI_QOS_FILE generation failed");
9695 }
9696
9697 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
9698 if (system(buf) != 0) {
9699 }
9700}
9701
9702
9703static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9704 struct sigma_cmd *cmd)
9705{
9706 const char *intf = get_param(cmd, "Interface");
9707 const char *val;
9708 int tid = 0;
9709 char buf[100];
9710
9711 val = get_param(cmd, "TID");
9712 if (val) {
9713 tid = atoi(val);
9714 if (tid)
9715 ath_sta_inject_frame(dut, intf, tid);
9716 }
9717
9718 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009719 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009720
9721 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
9722 if (system(buf) != 0) {
9723 sigma_dut_print(dut, DUT_MSG_ERROR,
9724 "wifitool senddelba failed");
9725 }
9726
9727 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
9728 if (system(buf) != 0) {
9729 sigma_dut_print(dut, DUT_MSG_ERROR,
9730 "wifitool sendaddba failed");
9731 }
9732
9733 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9734
9735 return 1;
9736}
9737
9738
Lior David9981b512017-01-20 13:16:40 +02009739#ifdef __linux__
9740
9741static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
9742 int agg_size)
9743{
9744 char dir[128], buf[128];
9745 FILE *f;
9746 regex_t re;
9747 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03009748 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02009749
9750 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
9751 sigma_dut_print(dut, DUT_MSG_ERROR,
9752 "failed to get wil6210 debugfs dir");
9753 return -1;
9754 }
9755
Jouni Malinen3aa72862019-05-29 23:14:51 +03009756 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
9757 if (res < 0 || res >= sizeof(buf))
9758 return -1;
Lior David9981b512017-01-20 13:16:40 +02009759 f = fopen(buf, "r");
9760 if (!f) {
9761 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009762 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009763 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9764 if (res < 0 || res >= sizeof(buf))
9765 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009766 f = fopen(buf, "r");
9767 if (!f) {
9768 sigma_dut_print(dut, DUT_MSG_ERROR,
9769 "failed to open: %s", buf);
9770 return -1;
9771 }
Lior David9981b512017-01-20 13:16:40 +02009772 }
9773
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009774 /* can be either VRING tx... or RING... */
9775 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009776 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9777 goto out;
9778 }
9779
9780 /* find TX VRING for the mac address */
9781 found = 0;
9782 while (fgets(buf, sizeof(buf), f)) {
9783 if (strcasestr(buf, dest_mac)) {
9784 found = 1;
9785 break;
9786 }
9787 }
9788
9789 if (!found) {
9790 sigma_dut_print(dut, DUT_MSG_ERROR,
9791 "no TX VRING for %s", dest_mac);
9792 goto out;
9793 }
9794
9795 /* extract VRING ID, "VRING tx_<id> = {" */
9796 if (!fgets(buf, sizeof(buf), f)) {
9797 sigma_dut_print(dut, DUT_MSG_ERROR,
9798 "no VRING start line for %s", dest_mac);
9799 goto out;
9800 }
9801
9802 rc = regexec(&re, buf, 2, m, 0);
9803 regfree(&re);
9804 if (rc || m[1].rm_so < 0) {
9805 sigma_dut_print(dut, DUT_MSG_ERROR,
9806 "no VRING TX ID for %s", dest_mac);
9807 goto out;
9808 }
9809 buf[m[1].rm_eo] = 0;
9810 vring_id = atoi(&buf[m[1].rm_so]);
9811
9812 /* send the addba command */
9813 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009814 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9815 if (res < 0 || res >= sizeof(buf))
9816 return -1;
Lior David9981b512017-01-20 13:16:40 +02009817 f = fopen(buf, "w");
9818 if (!f) {
9819 sigma_dut_print(dut, DUT_MSG_ERROR,
9820 "failed to open: %s", buf);
9821 return -1;
9822 }
9823
9824 fprintf(f, "add %d %d\n", vring_id, agg_size);
9825
9826 ret = 0;
9827
9828out:
9829 fclose(f);
9830
9831 return ret;
9832}
9833
9834
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009835int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9836 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009837{
9838 const char *val;
9839 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009840
9841 val = get_param(cmd, "TID");
9842 if (val) {
9843 tid = atoi(val);
9844 if (tid != 0) {
9845 sigma_dut_print(dut, DUT_MSG_ERROR,
9846 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9847 tid);
9848 }
9849 }
9850
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009851 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009852 if (!val) {
9853 sigma_dut_print(dut, DUT_MSG_ERROR,
9854 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009855 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009856 }
9857
Lior David9981b512017-01-20 13:16:40 +02009858 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009859 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009860
9861 return 1;
9862}
9863
Lior David9981b512017-01-20 13:16:40 +02009864#endif /* __linux__ */
9865
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009866
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009867static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9868 struct sigma_cmd *cmd)
9869{
9870#ifdef NL80211_SUPPORT
9871 const char *intf = get_param(cmd, "Interface");
9872 const char *val;
9873 int tid = -1;
9874 int bufsize = 64;
9875 struct nl_msg *msg;
9876 int ret = 0;
9877 struct nlattr *params;
9878 int ifindex;
9879
9880 val = get_param(cmd, "TID");
9881 if (val)
9882 tid = atoi(val);
9883
9884 if (tid == -1) {
9885 send_resp(dut, conn, SIGMA_ERROR,
9886 "ErrorCode,sta_send_addba tid invalid");
9887 return 0;
9888 }
9889
9890 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9891
9892 ifindex = if_nametoindex(intf);
9893 if (ifindex == 0) {
9894 sigma_dut_print(dut, DUT_MSG_ERROR,
9895 "%s: Index for interface %s failed",
9896 __func__, intf);
9897 send_resp(dut, conn, SIGMA_ERROR,
9898 "ErrorCode,sta_send_addba interface invalid");
9899 return 0;
9900 }
9901
9902 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9903 NL80211_CMD_VENDOR)) ||
9904 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9905 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9906 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9907 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9908 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9909 nla_put_u8(msg,
9910 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9911 QCA_WLAN_ADD_BA) ||
9912 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9913 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009914 nla_put_u16(msg,
9915 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9916 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009917 sigma_dut_print(dut, DUT_MSG_ERROR,
9918 "%s: err in adding vendor_cmd and vendor_data",
9919 __func__);
9920 nlmsg_free(msg);
9921 send_resp(dut, conn, SIGMA_ERROR,
9922 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9923 return 0;
9924 }
9925 nla_nest_end(msg, params);
9926
9927 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9928 if (ret) {
9929 sigma_dut_print(dut, DUT_MSG_ERROR,
9930 "%s: err in send_and_recv_msgs, ret=%d",
9931 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309932 if (ret == -EOPNOTSUPP)
9933 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009934 send_resp(dut, conn, SIGMA_ERROR,
9935 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9936 return 0;
9937 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009938#else /* NL80211_SUPPORT */
9939 sigma_dut_print(dut, DUT_MSG_ERROR,
9940 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009941#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309942
9943 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009944}
9945
9946
Jouni Malinenf7222712019-06-13 01:50:21 +03009947static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9948 struct sigma_conn *conn,
9949 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009950{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009951 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009952 case DRIVER_ATHEROS:
9953 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009954 case DRIVER_WCN:
9955 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009956#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009957 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009958 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009959#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009960 default:
9961 /*
9962 * There is no driver specific implementation for other drivers.
9963 * Ignore the command and report COMPLETE since the following
9964 * throughput test operation will end up sending ADDBA anyway.
9965 */
9966 return 1;
9967 }
9968}
9969
9970
9971int inject_eth_frame(int s, const void *data, size_t len,
9972 unsigned short ethtype, char *dst, char *src)
9973{
9974 struct iovec iov[4] = {
9975 {
9976 .iov_base = dst,
9977 .iov_len = ETH_ALEN,
9978 },
9979 {
9980 .iov_base = src,
9981 .iov_len = ETH_ALEN,
9982 },
9983 {
9984 .iov_base = &ethtype,
9985 .iov_len = sizeof(unsigned short),
9986 },
9987 {
9988 .iov_base = (void *) data,
9989 .iov_len = len,
9990 }
9991 };
9992 struct msghdr msg = {
9993 .msg_name = NULL,
9994 .msg_namelen = 0,
9995 .msg_iov = iov,
9996 .msg_iovlen = 4,
9997 .msg_control = NULL,
9998 .msg_controllen = 0,
9999 .msg_flags = 0,
10000 };
10001
10002 return sendmsg(s, &msg, 0);
10003}
10004
10005#if defined(__linux__) || defined(__QNXNTO__)
10006
10007int inject_frame(int s, const void *data, size_t len, int encrypt)
10008{
10009#define IEEE80211_RADIOTAP_F_WEP 0x04
10010#define IEEE80211_RADIOTAP_F_FRAG 0x08
10011 unsigned char rtap_hdr[] = {
10012 0x00, 0x00, /* radiotap version */
10013 0x0e, 0x00, /* radiotap length */
10014 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
10015 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
10016 0x00, /* padding */
10017 0x00, 0x00, /* RX and TX flags to indicate that */
10018 0x00, 0x00, /* this is the injected frame directly */
10019 };
10020 struct iovec iov[2] = {
10021 {
10022 .iov_base = &rtap_hdr,
10023 .iov_len = sizeof(rtap_hdr),
10024 },
10025 {
10026 .iov_base = (void *) data,
10027 .iov_len = len,
10028 }
10029 };
10030 struct msghdr msg = {
10031 .msg_name = NULL,
10032 .msg_namelen = 0,
10033 .msg_iov = iov,
10034 .msg_iovlen = 2,
10035 .msg_control = NULL,
10036 .msg_controllen = 0,
10037 .msg_flags = 0,
10038 };
10039
10040 if (encrypt)
10041 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
10042
10043 return sendmsg(s, &msg, 0);
10044}
10045
10046
10047int open_monitor(const char *ifname)
10048{
10049#ifdef __QNXNTO__
10050 struct sockaddr_dl ll;
10051 int s;
10052
10053 memset(&ll, 0, sizeof(ll));
10054 ll.sdl_family = AF_LINK;
10055 ll.sdl_index = if_nametoindex(ifname);
10056 if (ll.sdl_index == 0) {
10057 perror("if_nametoindex");
10058 return -1;
10059 }
10060 s = socket(PF_INET, SOCK_RAW, 0);
10061#else /* __QNXNTO__ */
10062 struct sockaddr_ll ll;
10063 int s;
10064
10065 memset(&ll, 0, sizeof(ll));
10066 ll.sll_family = AF_PACKET;
10067 ll.sll_ifindex = if_nametoindex(ifname);
10068 if (ll.sll_ifindex == 0) {
10069 perror("if_nametoindex");
10070 return -1;
10071 }
10072 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
10073#endif /* __QNXNTO__ */
10074 if (s < 0) {
10075 perror("socket[PF_PACKET,SOCK_RAW]");
10076 return -1;
10077 }
10078
10079 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
10080 perror("monitor socket bind");
10081 close(s);
10082 return -1;
10083 }
10084
10085 return s;
10086}
10087
10088
10089static int hex2num(char c)
10090{
10091 if (c >= '0' && c <= '9')
10092 return c - '0';
10093 if (c >= 'a' && c <= 'f')
10094 return c - 'a' + 10;
10095 if (c >= 'A' && c <= 'F')
10096 return c - 'A' + 10;
10097 return -1;
10098}
10099
10100
10101int hwaddr_aton(const char *txt, unsigned char *addr)
10102{
10103 int i;
10104
10105 for (i = 0; i < 6; i++) {
10106 int a, b;
10107
10108 a = hex2num(*txt++);
10109 if (a < 0)
10110 return -1;
10111 b = hex2num(*txt++);
10112 if (b < 0)
10113 return -1;
10114 *addr++ = (a << 4) | b;
10115 if (i < 5 && *txt++ != ':')
10116 return -1;
10117 }
10118
10119 return 0;
10120}
10121
10122#endif /* defined(__linux__) || defined(__QNXNTO__) */
10123
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010124
10125#ifdef NL80211_SUPPORT
10126static int nl80211_send_frame_cmd(struct sigma_dut *dut, const char *intf,
10127 const u8 *data, size_t data_len, int freq)
10128{
10129 struct nl_msg *msg;
10130 int ret = 0;
10131 int ifindex;
10132
10133 ifindex = if_nametoindex(intf);
10134 if (ifindex == 0) {
10135 sigma_dut_print(dut, DUT_MSG_ERROR,
10136 "%s: Index for interface %s failed",
10137 __func__, intf);
10138 return -1;
10139 }
10140
10141 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10142 NL80211_CMD_FRAME)) ||
10143 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10144 nla_put(msg, NL80211_ATTR_FRAME, data_len, data)) {
10145 sigma_dut_print(dut, DUT_MSG_ERROR,
10146 "%s: Error in adding NL80211_CMD_FRAME",
10147 __func__);
10148 nlmsg_free(msg);
10149 return -1;
10150 }
10151
10152 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
10153 if (ret) {
10154 sigma_dut_print(dut, DUT_MSG_ERROR,
10155 "nl80211: Frame command failed: ret=%d (%s) req=%u",
10156 ret, strerror(-ret), freq);
10157 return -1;
10158 }
10159
10160 return 0;
10161}
10162#endif /* NL80211_SUPPORT */
10163
10164
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010165enum send_frame_type {
10166 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
10167};
10168enum send_frame_protection {
10169 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
10170};
10171
10172
10173static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010174 const char *intf, enum send_frame_type frame,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010175 enum send_frame_protection protected,
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010176 const char *dest, int use_monitor)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010177{
10178#ifdef __linux__
10179 unsigned char buf[1000], *pos;
10180 int s, res;
10181 char bssid[20], addr[20];
10182 char result[32], ssid[100];
10183 size_t ssid_len;
10184
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010185 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010186 sizeof(result)) < 0 ||
10187 strncmp(result, "COMPLETED", 9) != 0) {
10188 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
10189 return 0;
10190 }
10191
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010192 if (get_wpa_status(get_station_ifname(dut), "bssid",
10193 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010194 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
10195 "current BSSID");
10196 return 0;
10197 }
10198
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010199 if (get_wpa_status(get_station_ifname(dut), "address",
10200 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010201 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
10202 "own MAC address");
10203 return 0;
10204 }
10205
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010206 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010207 < 0) {
10208 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
10209 "current SSID");
10210 return 0;
10211 }
10212 ssid_len = strlen(ssid);
10213
10214 pos = buf;
10215
10216 /* Frame Control */
10217 switch (frame) {
10218 case DISASSOC:
10219 *pos++ = 0xa0;
10220 break;
10221 case DEAUTH:
10222 *pos++ = 0xc0;
10223 break;
10224 case SAQUERY:
10225 *pos++ = 0xd0;
10226 break;
10227 case AUTH:
10228 *pos++ = 0xb0;
10229 break;
10230 case ASSOCREQ:
10231 *pos++ = 0x00;
10232 break;
10233 case REASSOCREQ:
10234 *pos++ = 0x20;
10235 break;
10236 case DLS_REQ:
10237 *pos++ = 0xd0;
10238 break;
10239 }
10240
10241 if (protected == INCORRECT_KEY)
10242 *pos++ = 0x40; /* Set Protected field to 1 */
10243 else
10244 *pos++ = 0x00;
10245
10246 /* Duration */
10247 *pos++ = 0x00;
10248 *pos++ = 0x00;
10249
10250 /* addr1 = DA (current AP) */
10251 hwaddr_aton(bssid, pos);
10252 pos += 6;
10253 /* addr2 = SA (own address) */
10254 hwaddr_aton(addr, pos);
10255 pos += 6;
10256 /* addr3 = BSSID (current AP) */
10257 hwaddr_aton(bssid, pos);
10258 pos += 6;
10259
10260 /* Seq# (to be filled by driver/mac80211) */
10261 *pos++ = 0x00;
10262 *pos++ = 0x00;
10263
10264 if (protected == INCORRECT_KEY) {
10265 /* CCMP parameters */
10266 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
10267 pos += 8;
10268 }
10269
10270 if (protected == INCORRECT_KEY) {
10271 switch (frame) {
10272 case DEAUTH:
10273 /* Reason code (encrypted) */
10274 memcpy(pos, "\xa7\x39", 2);
10275 pos += 2;
10276 break;
10277 case DISASSOC:
10278 /* Reason code (encrypted) */
10279 memcpy(pos, "\xa7\x39", 2);
10280 pos += 2;
10281 break;
10282 case SAQUERY:
10283 /* Category|Action|TransID (encrypted) */
10284 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
10285 pos += 4;
10286 break;
10287 default:
10288 return -1;
10289 }
10290
10291 /* CCMP MIC */
10292 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
10293 pos += 8;
10294 } else {
10295 switch (frame) {
10296 case DEAUTH:
10297 /* reason code = 8 */
10298 *pos++ = 0x08;
10299 *pos++ = 0x00;
10300 break;
10301 case DISASSOC:
10302 /* reason code = 8 */
10303 *pos++ = 0x08;
10304 *pos++ = 0x00;
10305 break;
10306 case SAQUERY:
10307 /* Category - SA Query */
10308 *pos++ = 0x08;
10309 /* SA query Action - Request */
10310 *pos++ = 0x00;
10311 /* Transaction ID */
10312 *pos++ = 0x12;
10313 *pos++ = 0x34;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053010314 if (dut->saquery_oci_freq) {
10315 /* OCI IE - Extended ID */
10316 *pos++ = 0xFF;
10317 *pos++ = 0x04;
10318 *pos++ = 0x36;
10319 /* Operating Class */
10320 *pos++ = 0x74;
10321 /* Primary Channel */
10322 *pos++ = freq_to_channel(dut->saquery_oci_freq);
10323 /* Frequency Segment 1 Channel Number */
10324 *pos++ = 0x00;
10325 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010326 break;
10327 case AUTH:
10328 /* Auth Alg (Open) */
10329 *pos++ = 0x00;
10330 *pos++ = 0x00;
10331 /* Seq# */
10332 *pos++ = 0x01;
10333 *pos++ = 0x00;
10334 /* Status code */
10335 *pos++ = 0x00;
10336 *pos++ = 0x00;
10337 break;
10338 case ASSOCREQ:
10339 /* Capability Information */
10340 *pos++ = 0x31;
10341 *pos++ = 0x04;
10342 /* Listen Interval */
10343 *pos++ = 0x0a;
10344 *pos++ = 0x00;
10345 /* SSID */
10346 *pos++ = 0x00;
10347 *pos++ = ssid_len;
10348 memcpy(pos, ssid, ssid_len);
10349 pos += ssid_len;
10350 /* Supported Rates */
10351 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
10352 10);
10353 pos += 10;
10354 /* Extended Supported Rates */
10355 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
10356 pos += 6;
10357 /* RSN */
10358 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
10359 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
10360 "\x00\x00\x00\x00\x0f\xac\x06", 28);
10361 pos += 28;
10362 break;
10363 case REASSOCREQ:
10364 /* Capability Information */
10365 *pos++ = 0x31;
10366 *pos++ = 0x04;
10367 /* Listen Interval */
10368 *pos++ = 0x0a;
10369 *pos++ = 0x00;
10370 /* Current AP */
10371 hwaddr_aton(bssid, pos);
10372 pos += 6;
10373 /* SSID */
10374 *pos++ = 0x00;
10375 *pos++ = ssid_len;
10376 memcpy(pos, ssid, ssid_len);
10377 pos += ssid_len;
10378 /* Supported Rates */
10379 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
10380 10);
10381 pos += 10;
10382 /* Extended Supported Rates */
10383 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
10384 pos += 6;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053010385 /* RSNE - Group and Pairwise ciphers */
10386 memcpy(pos,
10387 "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04",
10388 14);
10389 pos += 14;
10390 /* RSNE - AKM Suite count */
10391 *pos++ = 0x01;
10392 *pos++ = 0x00;
10393 /* RSNE - AKM Suites */
10394 if (dut->program == PROGRAM_WPA3)
10395 memcpy(pos, "\x00\x0f\xac\x08", 4);
10396 else
10397 memcpy(pos, "\x00\x0f\xac\x02", 4);
10398 pos += 4;
10399 /* RSNE - Capabilities */
10400 *pos++ = 0xc0;
10401 if (dut->ocvc)
10402 *pos++ = 0x40;
10403 else
10404 *pos++ = 0x00;
10405 /* RSNE - PMKID list and Group Management Ciphers */
10406 memcpy(pos, "\x00\x00\x00\x0f\xac\x06", 6);
10407 pos += 6;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010408 break;
10409 case DLS_REQ:
10410 /* Category - DLS */
10411 *pos++ = 0x02;
10412 /* DLS Action - Request */
10413 *pos++ = 0x00;
10414 /* Destination MACAddress */
10415 if (dest)
10416 hwaddr_aton(dest, pos);
10417 else
10418 memset(pos, 0, 6);
10419 pos += 6;
10420 /* Source MACAddress */
10421 hwaddr_aton(addr, pos);
10422 pos += 6;
10423 /* Capability Information */
10424 *pos++ = 0x10; /* Privacy */
10425 *pos++ = 0x06; /* QoS */
10426 /* DLS Timeout Value */
10427 *pos++ = 0x00;
10428 *pos++ = 0x01;
10429 /* Supported rates */
10430 *pos++ = 0x01;
10431 *pos++ = 0x08;
10432 *pos++ = 0x0c; /* 6 Mbps */
10433 *pos++ = 0x12; /* 9 Mbps */
10434 *pos++ = 0x18; /* 12 Mbps */
10435 *pos++ = 0x24; /* 18 Mbps */
10436 *pos++ = 0x30; /* 24 Mbps */
10437 *pos++ = 0x48; /* 36 Mbps */
10438 *pos++ = 0x60; /* 48 Mbps */
10439 *pos++ = 0x6c; /* 54 Mbps */
10440 /* TODO: Extended Supported Rates */
10441 /* TODO: HT Capabilities */
10442 break;
10443 }
10444 }
10445
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010446 if (use_monitor) {
10447 s = open_monitor("sigmadut");
10448 if (s < 0) {
10449 send_resp(dut, conn, SIGMA_ERROR,
10450 "errorCode,Failed to open monitor socket");
10451 return 0;
10452 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010453
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010454 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
10455 if (res < 0) {
10456 send_resp(dut, conn, SIGMA_ERROR,
10457 "errorCode,Failed to inject frame");
10458 close(s);
10459 return 0;
10460 }
10461 if (res < pos - buf) {
10462 send_resp(dut, conn, SIGMA_ERROR,
10463 "errorCode,Only partial frame sent");
10464 close(s);
10465 return 0;
10466 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010467
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010468 close(s);
10469 } else {
10470#ifdef NL80211_SUPPORT
10471 int freq;
10472 char freq_str[10];
10473
10474 if (get_wpa_status(get_station_ifname(dut), "freq",
10475 freq_str, sizeof(freq_str)) < 0) {
10476 send_resp(dut, conn, SIGMA_ERROR,
10477 "errorCode,Could not get current operating frequency");
10478 return 0;
10479 }
10480 freq = atoi(freq_str);
10481
10482 if (nl80211_send_frame_cmd(dut, intf, buf, pos - buf, freq)) {
10483 send_resp(dut, conn, SIGMA_ERROR,
10484 "errorCode,Failed to inject frame");
10485 return 0;
10486 }
10487#else /* NL80211_SUPPORT */
10488 send_resp(dut, conn, SIGMA_ERROR,
10489 "errorCode,Failed to inject frame (no NL80211_SUPPORT)");
10490 return 0;
10491#endif /* NL80211_SUPPORT */
10492 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010493
10494 return 1;
10495#else /* __linux__ */
10496 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
10497 "yet supported");
10498 return 0;
10499#endif /* __linux__ */
10500}
10501
10502
10503static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
10504 struct sigma_conn *conn,
10505 struct sigma_cmd *cmd)
10506{
10507 const char *intf = get_param(cmd, "Interface");
10508 const char *sta, *val;
10509 unsigned char addr[ETH_ALEN];
10510 char buf[100];
10511
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010512 if (!intf)
10513 return -1;
10514
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010515 sta = get_param(cmd, "peer");
10516 if (sta == NULL)
10517 sta = get_param(cmd, "station");
10518 if (sta == NULL) {
10519 send_resp(dut, conn, SIGMA_ERROR,
10520 "ErrorCode,Missing peer address");
10521 return 0;
10522 }
10523 if (hwaddr_aton(sta, addr) < 0) {
10524 send_resp(dut, conn, SIGMA_ERROR,
10525 "ErrorCode,Invalid peer address");
10526 return 0;
10527 }
10528
10529 val = get_param(cmd, "type");
10530 if (val == NULL)
10531 return -1;
10532
10533 if (strcasecmp(val, "DISCOVERY") == 0) {
10534 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
10535 if (wpa_command(intf, buf) < 0) {
10536 send_resp(dut, conn, SIGMA_ERROR,
10537 "ErrorCode,Failed to send TDLS discovery");
10538 return 0;
10539 }
10540 return 1;
10541 }
10542
10543 if (strcasecmp(val, "SETUP") == 0) {
10544 int status = 0, timeout = 0;
10545
10546 val = get_param(cmd, "Status");
10547 if (val)
10548 status = atoi(val);
10549
10550 val = get_param(cmd, "Timeout");
10551 if (val)
10552 timeout = atoi(val);
10553
10554 if (status != 0 && status != 37) {
10555 send_resp(dut, conn, SIGMA_ERROR,
10556 "ErrorCode,Unsupported status value");
10557 return 0;
10558 }
10559
10560 if (timeout != 0 && timeout != 301) {
10561 send_resp(dut, conn, SIGMA_ERROR,
10562 "ErrorCode,Unsupported timeout value");
10563 return 0;
10564 }
10565
10566 if (status && timeout) {
10567 send_resp(dut, conn, SIGMA_ERROR,
10568 "ErrorCode,Unsupported timeout+status "
10569 "combination");
10570 return 0;
10571 }
10572
10573 if (status == 37 &&
10574 wpa_command(intf, "SET tdls_testing 0x200")) {
10575 send_resp(dut, conn, SIGMA_ERROR,
10576 "ErrorCode,Failed to enable "
10577 "decline setup response test mode");
10578 return 0;
10579 }
10580
10581 if (timeout == 301) {
10582 int res;
10583 if (dut->no_tpk_expiration)
10584 res = wpa_command(intf,
10585 "SET tdls_testing 0x108");
10586 else
10587 res = wpa_command(intf,
10588 "SET tdls_testing 0x8");
10589 if (res) {
10590 send_resp(dut, conn, SIGMA_ERROR,
10591 "ErrorCode,Failed to set short TPK "
10592 "lifetime");
10593 return 0;
10594 }
10595 }
10596
10597 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
10598 if (wpa_command(intf, buf) < 0) {
10599 send_resp(dut, conn, SIGMA_ERROR,
10600 "ErrorCode,Failed to send TDLS setup");
10601 return 0;
10602 }
10603 return 1;
10604 }
10605
10606 if (strcasecmp(val, "TEARDOWN") == 0) {
10607 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
10608 if (wpa_command(intf, buf) < 0) {
10609 send_resp(dut, conn, SIGMA_ERROR,
10610 "ErrorCode,Failed to send TDLS teardown");
10611 return 0;
10612 }
10613 return 1;
10614 }
10615
10616 send_resp(dut, conn, SIGMA_ERROR,
10617 "ErrorCode,Unsupported TDLS frame");
10618 return 0;
10619}
10620
10621
10622static int sta_ap_known(const char *ifname, const char *bssid)
10623{
10624 char buf[4096];
10625
Jouni Malinendd32f192018-09-15 02:55:19 +030010626 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010627 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
10628 return 0;
10629 if (strncmp(buf, "id=", 3) != 0)
10630 return 0;
10631 return 1;
10632}
10633
10634
10635static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
10636 const char *bssid)
10637{
10638 int res;
10639 struct wpa_ctrl *ctrl;
10640 char buf[256];
10641
10642 if (sta_ap_known(ifname, bssid))
10643 return 0;
10644 sigma_dut_print(dut, DUT_MSG_DEBUG,
10645 "AP not in BSS table - start scan");
10646
10647 ctrl = open_wpa_mon(ifname);
10648 if (ctrl == NULL) {
10649 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10650 "wpa_supplicant monitor connection");
10651 return -1;
10652 }
10653
10654 if (wpa_command(ifname, "SCAN") < 0) {
10655 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
10656 wpa_ctrl_detach(ctrl);
10657 wpa_ctrl_close(ctrl);
10658 return -1;
10659 }
10660
10661 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
10662 buf, sizeof(buf));
10663
10664 wpa_ctrl_detach(ctrl);
10665 wpa_ctrl_close(ctrl);
10666
10667 if (res < 0) {
10668 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
10669 return -1;
10670 }
10671
10672 if (sta_ap_known(ifname, bssid))
10673 return 0;
10674 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
10675 return -1;
10676}
10677
10678
10679static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
10680 struct sigma_conn *conn,
10681 struct sigma_cmd *cmd,
10682 const char *intf)
10683{
10684 char buf[200];
10685
10686 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
10687 if (system(buf) != 0) {
10688 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
10689 "ndsend");
10690 return 0;
10691 }
10692
10693 return 1;
10694}
10695
10696
10697static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
10698 struct sigma_conn *conn,
10699 struct sigma_cmd *cmd,
10700 const char *intf)
10701{
10702 char buf[200];
10703 const char *ip = get_param(cmd, "SenderIP");
10704
Peng Xu26b356d2017-10-04 17:58:16 -070010705 if (!ip)
10706 return 0;
10707
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010708 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
10709 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10710 if (system(buf) == 0) {
10711 sigma_dut_print(dut, DUT_MSG_INFO,
10712 "Neighbor Solicitation got a response "
10713 "for %s@%s", ip, intf);
10714 }
10715
10716 return 1;
10717}
10718
10719
10720static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
10721 struct sigma_conn *conn,
10722 struct sigma_cmd *cmd,
10723 const char *ifname)
10724{
10725 char buf[200];
10726 const char *ip = get_param(cmd, "SenderIP");
10727
10728 if (ip == NULL) {
10729 send_resp(dut, conn, SIGMA_ERROR,
10730 "ErrorCode,Missing SenderIP parameter");
10731 return 0;
10732 }
10733 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
10734 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10735 if (system(buf) != 0) {
10736 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
10737 "for %s@%s", ip, ifname);
10738 }
10739
10740 return 1;
10741}
10742
10743
10744static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
10745 struct sigma_conn *conn,
10746 struct sigma_cmd *cmd,
10747 const char *ifname)
10748{
10749 char buf[200];
10750 char ip[16];
10751 int s;
Peng Xub3756882017-10-04 14:39:09 -070010752 struct ifreq ifr;
10753 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010754
10755 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070010756 if (s < 0) {
10757 perror("socket");
10758 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010759 }
10760
Peng Xub3756882017-10-04 14:39:09 -070010761 memset(&ifr, 0, sizeof(ifr));
10762 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
10763 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
10764 sigma_dut_print(dut, DUT_MSG_INFO,
10765 "Failed to get %s IP address: %s",
10766 ifname, strerror(errno));
10767 close(s);
10768 return -1;
10769 }
10770 close(s);
10771
10772 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
10773 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
10774
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010775 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
10776 ip);
10777 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10778 if (system(buf) != 0) {
10779 }
10780
10781 return 1;
10782}
10783
10784
10785static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
10786 struct sigma_conn *conn,
10787 struct sigma_cmd *cmd,
10788 const char *ifname)
10789{
10790 char buf[200], addr[20];
10791 char dst[ETH_ALEN], src[ETH_ALEN];
10792 short ethtype = htons(ETH_P_ARP);
10793 char *pos;
10794 int s, res;
10795 const char *val;
10796 struct sockaddr_in taddr;
10797
10798 val = get_param(cmd, "dest");
10799 if (val)
10800 hwaddr_aton(val, (unsigned char *) dst);
10801
10802 val = get_param(cmd, "DestIP");
10803 if (val)
10804 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070010805 else
10806 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010807
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010808 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010809 sizeof(addr)) < 0)
10810 return -2;
10811 hwaddr_aton(addr, (unsigned char *) src);
10812
10813 pos = buf;
10814 *pos++ = 0x00;
10815 *pos++ = 0x01;
10816 *pos++ = 0x08;
10817 *pos++ = 0x00;
10818 *pos++ = 0x06;
10819 *pos++ = 0x04;
10820 *pos++ = 0x00;
10821 *pos++ = 0x02;
10822 memcpy(pos, src, ETH_ALEN);
10823 pos += ETH_ALEN;
10824 memcpy(pos, &taddr.sin_addr, 4);
10825 pos += 4;
10826 memcpy(pos, dst, ETH_ALEN);
10827 pos += ETH_ALEN;
10828 memcpy(pos, &taddr.sin_addr, 4);
10829 pos += 4;
10830
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010831 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010832 if (s < 0) {
10833 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
10834 "monitor socket");
10835 return 0;
10836 }
10837
10838 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
10839 if (res < 0) {
10840 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
10841 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053010842 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010843 return 0;
10844 }
10845
10846 close(s);
10847
10848 return 1;
10849}
10850
10851
10852static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
10853 struct sigma_conn *conn,
10854 struct sigma_cmd *cmd,
10855 const char *intf, const char *dest)
10856{
10857 char buf[100];
10858
10859 if (if_nametoindex("sigmadut") == 0) {
10860 snprintf(buf, sizeof(buf),
10861 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010862 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010863 if (system(buf) != 0 ||
10864 if_nametoindex("sigmadut") == 0) {
10865 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10866 "monitor interface with '%s'", buf);
10867 return -2;
10868 }
10869 }
10870
10871 if (system("ifconfig sigmadut up") != 0) {
10872 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10873 "monitor interface up");
10874 return -2;
10875 }
10876
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010877 return sta_inject_frame(dut, conn, intf, DLS_REQ, UNPROTECTED, dest, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010878}
10879
10880
10881static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10882 struct sigma_conn *conn,
10883 struct sigma_cmd *cmd)
10884{
10885 const char *intf = get_param(cmd, "Interface");
10886 const char *dest = get_param(cmd, "Dest");
10887 const char *type = get_param(cmd, "FrameName");
10888 const char *val;
10889 char buf[200], *pos, *end;
10890 int count, count2;
10891
10892 if (type == NULL)
10893 type = get_param(cmd, "Type");
10894
10895 if (intf == NULL || dest == NULL || type == NULL)
10896 return -1;
10897
10898 if (strcasecmp(type, "NeighAdv") == 0)
10899 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10900
10901 if (strcasecmp(type, "NeighSolicitReq") == 0)
10902 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10903
10904 if (strcasecmp(type, "ARPProbe") == 0)
10905 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10906
10907 if (strcasecmp(type, "ARPAnnounce") == 0)
10908 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10909
10910 if (strcasecmp(type, "ARPReply") == 0)
10911 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10912
10913 if (strcasecmp(type, "DLS-request") == 0 ||
10914 strcasecmp(type, "DLSrequest") == 0)
10915 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10916 dest);
10917
10918 if (strcasecmp(type, "ANQPQuery") != 0 &&
10919 strcasecmp(type, "Query") != 0) {
10920 send_resp(dut, conn, SIGMA_ERROR,
10921 "ErrorCode,Unsupported HS 2.0 send frame type");
10922 return 0;
10923 }
10924
10925 if (sta_scan_ap(dut, intf, dest) < 0) {
10926 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10927 "the requested AP");
10928 return 0;
10929 }
10930
10931 pos = buf;
10932 end = buf + sizeof(buf);
10933 count = 0;
10934 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10935
10936 val = get_param(cmd, "ANQP_CAP_LIST");
10937 if (val && atoi(val)) {
10938 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10939 count++;
10940 }
10941
10942 val = get_param(cmd, "VENUE_NAME");
10943 if (val && atoi(val)) {
10944 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10945 count++;
10946 }
10947
10948 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10949 if (val && atoi(val)) {
10950 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10951 count++;
10952 }
10953
10954 val = get_param(cmd, "ROAMING_CONS");
10955 if (val && atoi(val)) {
10956 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10957 count++;
10958 }
10959
10960 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10961 if (val && atoi(val)) {
10962 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10963 count++;
10964 }
10965
10966 val = get_param(cmd, "NAI_REALM_LIST");
10967 if (val && atoi(val)) {
10968 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10969 count++;
10970 }
10971
10972 val = get_param(cmd, "3GPP_INFO");
10973 if (val && atoi(val)) {
10974 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10975 count++;
10976 }
10977
10978 val = get_param(cmd, "DOMAIN_LIST");
10979 if (val && atoi(val)) {
10980 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10981 count++;
10982 }
10983
Jouni Malinen34cf9532018-04-29 19:26:33 +030010984 val = get_param(cmd, "Venue_URL");
10985 if (val && atoi(val)) {
10986 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10987 count++;
10988 }
10989
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010990 val = get_param(cmd, "Advice_Of_Charge");
10991 if (val && atoi(val)) {
10992 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10993 count++;
10994 }
10995
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010996 if (count && wpa_command(intf, buf)) {
10997 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10998 return 0;
10999 }
11000
11001 pos = buf;
11002 end = buf + sizeof(buf);
11003 count2 = 0;
11004 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
11005
11006 val = get_param(cmd, "HS_CAP_LIST");
11007 if (val && atoi(val)) {
11008 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
11009 count2++;
11010 }
11011
11012 val = get_param(cmd, "OPER_NAME");
11013 if (val && atoi(val)) {
11014 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
11015 count2++;
11016 }
11017
11018 val = get_param(cmd, "WAN_METRICS");
11019 if (!val)
11020 val = get_param(cmd, "WAN_MAT");
11021 if (!val)
11022 val = get_param(cmd, "WAN_MET");
11023 if (val && atoi(val)) {
11024 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
11025 count2++;
11026 }
11027
11028 val = get_param(cmd, "CONNECTION_CAPABILITY");
11029 if (val && atoi(val)) {
11030 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
11031 count2++;
11032 }
11033
11034 val = get_param(cmd, "OP_CLASS");
11035 if (val && atoi(val)) {
11036 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
11037 count2++;
11038 }
11039
11040 val = get_param(cmd, "OSU_PROVIDER_LIST");
11041 if (val && atoi(val)) {
11042 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
11043 count2++;
11044 }
11045
Jouni Malinenf67afec2018-04-29 19:24:58 +030011046 val = get_param(cmd, "OPER_ICON_METADATA");
11047 if (!val)
11048 val = get_param(cmd, "OPERATOR_ICON_METADATA");
11049 if (val && atoi(val)) {
11050 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
11051 count2++;
11052 }
11053
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011054 if (count && count2) {
11055 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
11056 "second query");
11057 sleep(1);
11058 }
11059
11060 if (count2 && wpa_command(intf, buf)) {
11061 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
11062 "failed");
11063 return 0;
11064 }
11065
11066 val = get_param(cmd, "NAI_HOME_REALM_LIST");
11067 if (val) {
11068 if (count || count2) {
11069 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
11070 "sending out second query");
11071 sleep(1);
11072 }
11073
11074 if (strcmp(val, "1") == 0)
11075 val = "mail.example.com";
11076 snprintf(buf, end - pos,
11077 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
11078 dest, val);
11079 if (wpa_command(intf, buf)) {
11080 send_resp(dut, conn, SIGMA_ERROR,
11081 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
11082 "failed");
11083 return 0;
11084 }
11085 }
11086
11087 val = get_param(cmd, "ICON_REQUEST");
11088 if (val) {
11089 if (count || count2) {
11090 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
11091 "sending out second query");
11092 sleep(1);
11093 }
11094
11095 snprintf(buf, end - pos,
11096 "HS20_ICON_REQUEST %s %s", dest, val);
11097 if (wpa_command(intf, buf)) {
11098 send_resp(dut, conn, SIGMA_ERROR,
11099 "ErrorCode,HS20_ICON_REQUEST failed");
11100 return 0;
11101 }
11102 }
11103
11104 return 1;
11105}
11106
11107
11108static int ath_sta_send_frame_vht(struct sigma_dut *dut,
11109 struct sigma_conn *conn,
11110 struct sigma_cmd *cmd)
11111{
11112 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011113 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011114 int chwidth, nss;
11115
11116 val = get_param(cmd, "framename");
11117 if (!val)
11118 return -1;
11119 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
11120
11121 /* Command sequence to generate Op mode notification */
11122 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011123 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011124
11125 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011126 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011127
11128 /* Extract Channel width */
11129 val = get_param(cmd, "Channel_width");
11130 if (val) {
11131 switch (atoi(val)) {
11132 case 20:
11133 chwidth = 0;
11134 break;
11135 case 40:
11136 chwidth = 1;
11137 break;
11138 case 80:
11139 chwidth = 2;
11140 break;
11141 case 160:
11142 chwidth = 3;
11143 break;
11144 default:
11145 chwidth = 2;
11146 break;
11147 }
11148
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011149 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011150 }
11151
11152 /* Extract NSS */
11153 val = get_param(cmd, "NSS");
11154 if (val) {
11155 switch (atoi(val)) {
11156 case 1:
11157 nss = 1;
11158 break;
11159 case 2:
11160 nss = 3;
11161 break;
11162 case 3:
11163 nss = 7;
11164 break;
11165 default:
11166 /* We do not support NSS > 3 */
11167 nss = 3;
11168 break;
11169 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011170 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011171 }
11172
11173 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011174 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011175 }
11176
11177 return 1;
11178}
11179
11180
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011181static int wcn_sta_set_pmf_config(struct sigma_dut *dut, const char *intf,
11182 enum send_frame_protection protected)
11183{
11184#ifdef NL80211_SUPPORT
11185 struct nl_msg *msg;
11186 int ret = 0;
11187 struct nlattr *params;
11188 int ifindex;
11189
11190 ifindex = if_nametoindex(intf);
11191 if (ifindex == 0) {
11192 sigma_dut_print(dut, DUT_MSG_ERROR,
11193 "%s: Index for interface %s failed",
11194 __func__, intf);
11195 return -1;
11196 }
11197
11198 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
11199 NL80211_CMD_VENDOR)) ||
11200 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
11201 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
11202 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
11203 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
11204 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
11205 nla_put_u8(msg,
11206 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PMF_PROTECTION,
11207 protected)) {
11208 sigma_dut_print(dut, DUT_MSG_ERROR,
11209 "%s: err in adding vendor_cmd and vendor_data",
11210 __func__);
11211 nlmsg_free(msg);
11212 return -1;
11213 }
11214 nla_nest_end(msg, params);
11215
11216 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
11217 if (ret) {
11218 sigma_dut_print(dut, DUT_MSG_ERROR,
11219 "%s: err in send_and_recv_msgs, ret=%d",
11220 __func__, ret);
11221 }
11222 return ret;
11223#else /* NL80211_SUPPORT */
11224 sigma_dut_print(dut, DUT_MSG_ERROR,
11225 "PMF config cannot be set without NL80211_SUPPORT defined");
11226 return -1;
11227#endif /* NL80211_SUPPORT */
11228}
11229
11230
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011231static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
11232 struct sigma_conn *conn,
11233 struct sigma_cmd *cmd)
11234{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011235 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011236 case DRIVER_ATHEROS:
11237 return ath_sta_send_frame_vht(dut, conn, cmd);
11238 default:
11239 send_resp(dut, conn, SIGMA_ERROR,
11240 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
11241 return 0;
11242 }
11243}
11244
11245
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011246static int wcn_sta_send_disassoc(struct sigma_dut *dut, const char *intf)
11247{
11248#ifdef NL80211_SUPPORT
11249 struct nl_msg *msg;
11250 int ret = 0;
11251 struct nlattr *params;
11252 int ifindex;
11253
11254 ifindex = if_nametoindex(intf);
11255 if (ifindex == 0) {
11256 sigma_dut_print(dut, DUT_MSG_ERROR,
11257 "%s: Index for interface %s failed",
11258 __func__, intf);
11259 return -1;
11260 }
11261
11262 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
11263 NL80211_CMD_VENDOR)) ||
11264 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
11265 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
11266 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
11267 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
11268 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
11269 nla_put_flag(msg,
11270 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISASSOC_TX)) {
11271 sigma_dut_print(dut, DUT_MSG_ERROR,
11272 "%s: err in adding vendor_cmd and vendor_data",
11273 __func__);
11274 nlmsg_free(msg);
11275 return -1;
11276 }
11277 nla_nest_end(msg, params);
11278
11279 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
11280 if (ret) {
11281 sigma_dut_print(dut, DUT_MSG_ERROR,
11282 "%s: err in send_and_recv_msgs, ret=%d",
11283 __func__, ret);
11284 }
11285 return ret;
11286#else /* NL80211_SUPPORT */
11287 sigma_dut_print(dut, DUT_MSG_ERROR,
11288 "Disassoc Tx cannot be done without NL80211_SUPPORT defined");
11289 return -1;
11290#endif /* NL80211_SUPPORT */
11291}
11292
11293
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011294static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
11295 struct sigma_cmd *cmd)
11296{
11297 const char *val;
11298 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011299 enum send_frame_protection protected;
11300 const char *pmf;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011301
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011302 if (!intf)
11303 return -1;
11304
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011305 val = get_param(cmd, "framename");
11306 if (!val)
11307 return -1;
11308 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
11309
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011310 pmf = get_param(cmd, "PMFProtected");
11311 if (!pmf)
11312 pmf = get_param(cmd, "Protected");
11313 if (pmf) {
11314 if (strcasecmp(pmf, "Correct-key") == 0 ||
11315 strcasecmp(pmf, "CorrectKey") == 0) {
11316 protected = CORRECT_KEY;
11317 } else if (strcasecmp(pmf, "IncorrectKey") == 0) {
11318 protected = INCORRECT_KEY;
11319 } else if (strcasecmp(pmf, "Unprotected") == 0) {
11320 protected = UNPROTECTED;
11321 } else {
11322 send_resp(dut, conn, SIGMA_ERROR,
11323 "errorCode,Unsupported PMFProtected");
11324 return STATUS_SENT_ERROR;
11325 }
11326 sigma_dut_print(dut, DUT_MSG_DEBUG, "Config PMF protection %d",
11327 protected);
11328 wcn_sta_set_pmf_config(dut, intf, protected);
11329 }
11330
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011331 /* Command sequence to generate Op mode notification */
11332 if (val && strcasecmp(val, "action") == 0) {
11333 val = get_param(cmd, "PPDUTxType");
11334 if (val && strcasecmp(val, "TB") == 0) {
11335 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
11336 sigma_dut_print(dut, DUT_MSG_ERROR,
11337 "failed to send TB PPDU Tx cfg");
11338 send_resp(dut, conn, SIGMA_ERROR,
11339 "ErrorCode,set TB PPDU Tx cfg failed");
11340 return 0;
11341 }
11342 return 1;
11343 }
11344
11345 sigma_dut_print(dut, DUT_MSG_ERROR,
11346 "Action Tx type is not defined");
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011347
11348 return SUCCESS_SEND_STATUS;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011349 }
11350
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011351 if (strcasecmp(val, "disassoc") == 0)
11352 wcn_sta_send_disassoc(dut, intf);
11353
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011354 return 1;
11355}
11356
11357
11358static int cmd_sta_send_frame_he(struct sigma_dut *dut,
11359 struct sigma_conn *conn,
11360 struct sigma_cmd *cmd)
11361{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011362 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011363 case DRIVER_WCN:
11364 return wcn_sta_send_frame_he(dut, conn, cmd);
11365 default:
11366 send_resp(dut, conn, SIGMA_ERROR,
11367 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
11368 return 0;
11369 }
11370}
11371
11372
Lior David0fe101e2017-03-09 16:09:50 +020011373#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011374
11375static int
11376wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
11377 const char *frame_name, const char *dest_mac)
11378{
11379 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
11380 const char *ssid = get_param(cmd, "ssid");
11381 const char *countstr = get_param(cmd, "count");
11382 const char *channelstr = get_param(cmd, "channel");
11383 const char *group_id = get_param(cmd, "groupid");
11384 const char *client_id = get_param(cmd, "clientmac");
11385 int count, channel, freq, i;
11386 const char *fname;
11387 char frame[1024], src_mac[20], group_id_attr[25],
11388 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
11389 const char *group_ssid;
11390 const int group_ssid_prefix_len = 9;
11391 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
11392 size_t framelen = sizeof(frame);
11393 struct template_frame_tag tags[2];
11394 size_t tags_total = ARRAY_SIZE(tags);
11395 int tag_index, len, dst_len;
11396
11397 if (!countstr || !channelstr) {
11398 sigma_dut_print(dut, DUT_MSG_ERROR,
11399 "Missing argument: count, channel");
11400 return -1;
11401 }
11402 if (isprobereq && !ssid) {
11403 sigma_dut_print(dut, DUT_MSG_ERROR,
11404 "Missing argument: ssid");
11405 return -1;
11406 }
11407 if (!isprobereq && (!group_id || !client_id)) {
11408 sigma_dut_print(dut, DUT_MSG_ERROR,
11409 "Missing argument: group_id, client_id");
11410 return -1;
11411 }
11412
11413 count = atoi(countstr);
11414 channel = atoi(channelstr);
11415 freq = channel_to_freq(dut, channel);
11416
11417 if (!freq) {
11418 sigma_dut_print(dut, DUT_MSG_ERROR,
11419 "invalid channel: %s", channelstr);
11420 return -1;
11421 }
11422
11423 if (isprobereq) {
11424 if (strcasecmp(ssid, "wildcard") == 0) {
11425 fname = "probe_req_wildcard.txt";
11426 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
11427 fname = "probe_req_P2P_Wildcard.txt";
11428 } else {
11429 sigma_dut_print(dut, DUT_MSG_ERROR,
11430 "invalid probe request type");
11431 return -1;
11432 }
11433 } else {
11434 fname = "P2P_device_discovery_req.txt";
11435 }
11436
11437 if (parse_template_frame_file(dut, fname, frame, &framelen,
11438 tags, &tags_total)) {
11439 sigma_dut_print(dut, DUT_MSG_ERROR,
11440 "invalid frame template: %s", fname);
11441 return -1;
11442 }
11443
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011444 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011445 src_mac, sizeof(src_mac)) < 0 ||
11446 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
11447 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
11448 return -1;
11449 /* Use wildcard BSSID, since we are in PBSS */
11450 memset(&hdr->addr3, 0xFF, ETH_ALEN);
11451
11452 if (!isprobereq) {
11453 tag_index = find_template_frame_tag(tags, tags_total, 1);
11454 if (tag_index < 0) {
11455 sigma_dut_print(dut, DUT_MSG_ERROR,
11456 "can't find device id attribute");
11457 return -1;
11458 }
11459 if (parse_mac_address(dut, client_id,
11460 (unsigned char *) client_mac)) {
11461 sigma_dut_print(dut, DUT_MSG_ERROR,
11462 "invalid client_id: %s", client_id);
11463 return -1;
11464 }
11465 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11466 framelen - tags[tag_index].offset,
11467 IEEE80211_P2P_ATTR_DEVICE_ID,
11468 client_mac, ETH_ALEN)) {
11469 sigma_dut_print(dut, DUT_MSG_ERROR,
11470 "fail to replace device id attribute");
11471 return -1;
11472 }
11473
11474 /*
11475 * group_id arg contains device MAC address followed by
11476 * space and SSID (DIRECT-somessid).
11477 * group id attribute contains device address (6 bytes)
11478 * followed by SSID prefix DIRECT-XX (9 bytes)
11479 */
11480 if (strlen(group_id) < sizeof(device_macstr)) {
11481 sigma_dut_print(dut, DUT_MSG_ERROR,
11482 "group_id arg too short");
11483 return -1;
11484 }
11485 memcpy(device_macstr, group_id, sizeof(device_macstr));
11486 device_macstr[sizeof(device_macstr) - 1] = '\0';
11487 if (parse_mac_address(dut, device_macstr,
11488 (unsigned char *) group_id_attr)) {
11489 sigma_dut_print(dut, DUT_MSG_ERROR,
11490 "fail to parse device address from group_id");
11491 return -1;
11492 }
11493 group_ssid = strchr(group_id, ' ');
11494 if (!group_ssid) {
11495 sigma_dut_print(dut, DUT_MSG_ERROR,
11496 "invalid group_id arg, no ssid");
11497 return -1;
11498 }
11499 group_ssid++;
11500 len = strlen(group_ssid);
11501 if (len < group_ssid_prefix_len) {
11502 sigma_dut_print(dut, DUT_MSG_ERROR,
11503 "group_id SSID too short");
11504 return -1;
11505 }
11506 dst_len = sizeof(group_id_attr) - ETH_ALEN;
11507 if (len > dst_len) {
11508 sigma_dut_print(dut, DUT_MSG_ERROR,
11509 "group_id SSID (%s) too long",
11510 group_ssid);
11511 return -1;
11512 }
11513
11514 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
11515 tag_index = find_template_frame_tag(tags, tags_total, 2);
11516 if (tag_index < 0) {
11517 sigma_dut_print(dut, DUT_MSG_ERROR,
11518 "can't find group id attribute");
11519 return -1;
11520 }
11521 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11522 framelen - tags[tag_index].offset,
11523 IEEE80211_P2P_ATTR_GROUP_ID,
11524 group_id_attr,
11525 sizeof(group_id_attr))) {
11526 sigma_dut_print(dut, DUT_MSG_ERROR,
11527 "fail to replace group id attribute");
11528 return -1;
11529 }
11530 }
11531
11532 for (i = 0; i < count; i++) {
11533 if (wil6210_transmit_frame(dut, freq,
11534 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
11535 frame, framelen)) {
11536 sigma_dut_print(dut, DUT_MSG_ERROR,
11537 "fail to transmit probe request frame");
11538 return -1;
11539 }
11540 }
11541
11542 return 0;
11543}
11544
11545
Lior David0fe101e2017-03-09 16:09:50 +020011546int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
11547 struct sigma_cmd *cmd)
11548{
11549 const char *frame_name = get_param(cmd, "framename");
11550 const char *mac = get_param(cmd, "dest_mac");
11551
11552 if (!frame_name || !mac) {
11553 sigma_dut_print(dut, DUT_MSG_ERROR,
11554 "framename and dest_mac must be provided");
11555 return -1;
11556 }
11557
11558 if (strcasecmp(frame_name, "brp") == 0) {
11559 const char *l_rx = get_param(cmd, "L-RX");
11560 int l_rx_i;
11561
11562 if (!l_rx) {
11563 sigma_dut_print(dut, DUT_MSG_ERROR,
11564 "L-RX must be provided");
11565 return -1;
11566 }
11567 l_rx_i = atoi(l_rx);
11568
11569 sigma_dut_print(dut, DUT_MSG_INFO,
11570 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
11571 mac, l_rx);
11572 if (l_rx_i != 16) {
11573 sigma_dut_print(dut, DUT_MSG_ERROR,
11574 "unsupported L-RX: %s", l_rx);
11575 return -1;
11576 }
11577
11578 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
11579 return -1;
11580 } else if (strcasecmp(frame_name, "ssw") == 0) {
11581 sigma_dut_print(dut, DUT_MSG_INFO,
11582 "dev_send_frame: SLS, dest_mac %s", mac);
11583 if (wil6210_send_sls(dut, mac))
11584 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011585 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
11586 (strcasecmp(frame_name, "devdiscreq") == 0)) {
11587 sigma_dut_print(dut, DUT_MSG_INFO,
11588 "dev_send_frame: %s, dest_mac %s", frame_name,
11589 mac);
11590 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
11591 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020011592 } else {
11593 sigma_dut_print(dut, DUT_MSG_ERROR,
11594 "unsupported frame type: %s", frame_name);
11595 return -1;
11596 }
11597
11598 return 1;
11599}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011600
Lior David0fe101e2017-03-09 16:09:50 +020011601#endif /* __linux__ */
11602
11603
11604static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
11605 struct sigma_conn *conn,
11606 struct sigma_cmd *cmd)
11607{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011608 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020011609#ifdef __linux__
11610 case DRIVER_WIL6210:
11611 return wil6210_send_frame_60g(dut, conn, cmd);
11612#endif /* __linux__ */
11613 default:
11614 send_resp(dut, conn, SIGMA_ERROR,
11615 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
11616 return 0;
11617 }
11618}
11619
11620
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011621static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
11622 const char *intf, struct sigma_cmd *cmd)
11623{
11624 const char *val, *addr;
11625 char buf[100];
11626
11627 addr = get_param(cmd, "DestMac");
11628 if (!addr) {
11629 send_resp(dut, conn, SIGMA_INVALID,
11630 "ErrorCode,AP MAC address is missing");
11631 return 0;
11632 }
11633
11634 val = get_param(cmd, "ANQPQuery_ID");
11635 if (!val) {
11636 send_resp(dut, conn, SIGMA_INVALID,
11637 "ErrorCode,Missing ANQPQuery_ID");
11638 return 0;
11639 }
11640
11641 if (strcasecmp(val, "NeighborReportReq") == 0) {
11642 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
11643 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
11644 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
11645 } else {
11646 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
11647 val);
11648 send_resp(dut, conn, SIGMA_INVALID,
11649 "ErrorCode,Invalid ANQPQuery_ID");
11650 return 0;
11651 }
11652
Ashwini Patild174f2c2017-04-13 16:49:46 +053011653 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
11654 * (Address3 = Wildcard BSSID when sent to not-associated AP;
11655 * if associated, AP BSSID).
11656 */
11657 if (wpa_command(intf, "SET gas_address3 1") < 0) {
11658 send_resp(dut, conn, SIGMA_ERROR,
11659 "ErrorCode,Failed to set gas_address3");
11660 return 0;
11661 }
11662
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011663 if (wpa_command(intf, buf) < 0) {
11664 send_resp(dut, conn, SIGMA_ERROR,
11665 "ErrorCode,Failed to send ANQP query");
11666 return 0;
11667 }
11668
11669 return 1;
11670}
11671
11672
11673static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
11674 struct sigma_conn *conn,
11675 const char *intf,
11676 struct sigma_cmd *cmd)
11677{
11678 const char *val = get_param(cmd, "FrameName");
11679
11680 if (val && strcasecmp(val, "ANQPQuery") == 0)
11681 return mbo_send_anqp_query(dut, conn, intf, cmd);
11682
11683 return 2;
11684}
11685
11686
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011687static enum sigma_cmd_result cmd_sta_send_frame_wpa3(struct sigma_dut *dut,
11688 struct sigma_conn *conn,
11689 const char *intf,
11690 struct sigma_cmd *cmd)
11691{
11692 const char *val = get_param(cmd, "framename");
11693
11694 if (!val)
11695 return INVALID_SEND_STATUS;
11696
11697 if (strcasecmp(val, "SAQueryReq") == 0) {
11698 val = get_param(cmd, "OCIChannel");
11699
11700 if (!val) {
11701 send_resp(dut, conn, SIGMA_ERROR,
11702 "errorCode,OCIChannel not present");
11703 return STATUS_SENT_ERROR;
11704 }
11705
11706 dut->saquery_oci_freq = channel_to_freq(dut, atoi(val));
11707 if (!dut->saquery_oci_freq) {
11708 send_resp(dut, conn, SIGMA_ERROR,
11709 "errorCode,Invalid OCIChannel number");
11710 return STATUS_SENT_ERROR;
11711 }
11712
11713 return sta_inject_frame(dut, conn, intf, SAQUERY, CORRECT_KEY,
11714 NULL, 0);
11715 }
11716
11717 if (strcasecmp(val, "reassocreq") == 0)
11718 return sta_inject_frame(dut, conn, intf, REASSOCREQ,
11719 CORRECT_KEY, NULL, 0);
11720
Veerendranath9f81dfb2020-08-10 01:21:29 -070011721 if (strcasecmp(val, "ANQPQuery") == 0) {
11722 char buf[50];
11723 const char *dest = get_param(cmd, "DestMac");
11724 const char *chan = get_param(cmd, "channel");
11725 int len, freq;
11726
11727 freq = chan ? channel_to_freq(dut, atoi(chan)) : 0;
11728 if (!dest || !freq)
11729 return INVALID_SEND_STATUS;
11730
11731 len = snprintf(buf, sizeof(buf), "ANQP_GET %s freq=%d 257",
11732 dest, freq);
11733 if (len < 0 || len >= sizeof(buf)) {
11734 sigma_dut_print(dut, DUT_MSG_ERROR,
11735 "Failed to allocate buf");
11736 return ERROR_SEND_STATUS;
11737 }
11738
11739 if (wpa_command(intf, buf) != 0) {
11740 send_resp(dut, conn, SIGMA_ERROR,
11741 "ErrorCode,Failed to send ANQP Query frame");
11742 return STATUS_SENT_ERROR;
11743 }
11744
11745 sigma_dut_print(dut, DUT_MSG_DEBUG,
11746 "ANQP Query sent: %s", buf);
11747
11748 return SUCCESS_SEND_STATUS;
11749 }
11750
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011751 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported framename");
11752 return STATUS_SENT_ERROR;
11753}
11754
11755
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011756static enum sigma_cmd_result
11757cmd_sta_send_frame_mscs(struct sigma_dut *dut, struct sigma_conn *conn,
11758 const char *intf, struct sigma_cmd *cmd)
11759{
11760 char buf[128], *pos;
11761 const char *val, *classifier_type = "04", *type;
11762 int len, rem_len;
11763 u8 up_bitmap;
11764
11765 val = get_param(cmd, "FrameName");
11766 type = get_param(cmd, "Request_Type");
11767 if (!val || !type || strcasecmp(val, "MSCSReq") != 0) {
11768 sigma_dut_print(dut, DUT_MSG_ERROR,
11769 "%s: frame name or type not valid", __func__);
11770 return INVALID_SEND_STATUS;
11771 }
11772
11773 rem_len = sizeof(buf);
11774 pos = buf;
11775 if (strcasecmp(type, "add") == 0) {
11776 len = snprintf(pos, rem_len, "MSCS add");
11777 } else if (strcasecmp(type, "update") == 0) {
11778 len = snprintf(pos, rem_len, "MSCS change");
11779 } else if (strcasecmp(type, "remove") == 0) {
11780 if (wpa_command(intf, "MSCS remove") != 0) {
11781 send_resp(dut, conn, SIGMA_ERROR,
11782 "ErrorCode,Failed to send MSCS frame req");
11783 return STATUS_SENT_ERROR;
11784 }
11785 return SUCCESS_SEND_STATUS;
11786 } else {
11787 sigma_dut_print(dut, DUT_MSG_ERROR,
11788 "%s: request type invalid", __func__);
11789 return INVALID_SEND_STATUS;
11790 }
11791
11792 if (len < 0 || len >= rem_len)
11793 goto fail;
11794
11795 pos += len;
11796 rem_len -= len;
11797
11798 val = get_param(cmd, "User_Priority_Bitmap");
11799 if (!val) {
11800 sigma_dut_print(dut, DUT_MSG_ERROR,
11801 "%s: user priority bitmap empty", __func__);
11802 return INVALID_SEND_STATUS;
11803 }
11804
11805 switch (atoi(val)) {
11806 case 0:
11807 up_bitmap = 0x00;
11808 break;
11809 case 1:
11810 up_bitmap = 0xF0;
11811 break;
11812 case 2:
11813 up_bitmap = 0xF6;
11814 break;
11815 default:
11816 sigma_dut_print(dut, DUT_MSG_ERROR,
11817 "%s: Unknown User_Priority_Bitmap value %d",
11818 __func__, atoi(val));
11819 return INVALID_SEND_STATUS;
11820 }
11821
11822 len = snprintf(pos, rem_len, " up_bitmap=%02x", up_bitmap);
11823 if (len < 0 || len >= rem_len)
11824 goto fail;
11825
11826 pos += len;
11827 rem_len -= len;
11828
11829 val = get_param(cmd, "User_Priority_Limit");
11830 if (!val) {
11831 sigma_dut_print(dut, DUT_MSG_ERROR,
11832 "%s: invalid user priority limit", __func__);
11833 return INVALID_SEND_STATUS;
11834 }
11835
11836 len = snprintf(pos, rem_len, " up_limit=%s", val);
11837 if (len < 0 || len >= rem_len)
11838 goto fail;
11839
11840 pos += len;
11841 rem_len -= len;
11842
11843 val = get_param(cmd, "Stream_Timeout");
11844 if (!val)
11845 val = get_param(cmd, "Stream_Timtout");
11846 if (!val) {
11847 sigma_dut_print(dut, DUT_MSG_ERROR,
11848 "%s: invalid stream timeout", __func__);
11849 return INVALID_SEND_STATUS;
11850 }
11851
11852 len = snprintf(pos, rem_len, " stream_timeout=%s", val);
11853 if (len < 0 || len >= rem_len)
11854 goto fail;
11855
11856 pos += len;
11857 rem_len -= len;
11858
11859 val = get_param(cmd, "TCLAS_Mask");
11860 if (!val) {
11861 sigma_dut_print(dut, DUT_MSG_ERROR,
11862 "%s: invalid tclas mask", __func__);
11863 return INVALID_SEND_STATUS;
11864 }
11865
11866 len = snprintf(pos, rem_len, " frame_classifier=%s%lx%032x",
11867 classifier_type, strtol(val, NULL, 2), 0);
11868 if (len < 0 || len >= rem_len)
11869 goto fail;
11870
11871 if (wpa_command(intf, buf) != 0) {
11872 send_resp(dut, conn, SIGMA_ERROR,
11873 "ErrorCode,Failed to send MSCS frame req");
11874 return STATUS_SENT_ERROR;
11875 }
11876
11877 sigma_dut_print(dut, DUT_MSG_DEBUG,
11878 "MSCS frame request sent: %s", buf);
11879
11880 return SUCCESS_SEND_STATUS;
11881fail:
11882 sigma_dut_print(dut, DUT_MSG_ERROR,
11883 "Failed to create MSCS frame req");
11884 return ERROR_SEND_STATUS;
11885}
11886
11887
Jouni Malinenf7222712019-06-13 01:50:21 +030011888enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
11889 struct sigma_conn *conn,
11890 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011891{
11892 const char *intf = get_param(cmd, "Interface");
11893 const char *val;
11894 enum send_frame_type frame;
11895 enum send_frame_protection protected;
11896 char buf[100];
11897 unsigned char addr[ETH_ALEN];
11898 int res;
11899
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011900 if (!intf)
11901 return -1;
11902
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011903 val = get_param(cmd, "program");
11904 if (val == NULL)
11905 val = get_param(cmd, "frame");
11906 if (val && strcasecmp(val, "TDLS") == 0)
11907 return cmd_sta_send_frame_tdls(dut, conn, cmd);
11908 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011909 strcasecmp(val, "HS2-R2") == 0 ||
11910 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011911 return cmd_sta_send_frame_hs2(dut, conn, cmd);
11912 if (val && strcasecmp(val, "VHT") == 0)
11913 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011914 if (val && strcasecmp(val, "HE") == 0)
11915 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070011916 if (val && strcasecmp(val, "LOC") == 0)
11917 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020011918 if (val && strcasecmp(val, "60GHz") == 0)
11919 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011920 if (val && strcasecmp(val, "MBO") == 0) {
11921 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
11922 if (res != 2)
11923 return res;
11924 }
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011925 if (val && strcasecmp(val, "WPA3") == 0)
11926 return cmd_sta_send_frame_wpa3(dut, conn, intf, cmd);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011927 if (val && strcasecmp(val, "QM") == 0)
11928 return cmd_sta_send_frame_mscs(dut, conn, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011929
11930 val = get_param(cmd, "TD_DISC");
11931 if (val) {
11932 if (hwaddr_aton(val, addr) < 0)
11933 return -1;
11934 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
11935 if (wpa_command(intf, buf) < 0) {
11936 send_resp(dut, conn, SIGMA_ERROR,
11937 "ErrorCode,Failed to send TDLS discovery");
11938 return 0;
11939 }
11940 return 1;
11941 }
11942
11943 val = get_param(cmd, "TD_Setup");
11944 if (val) {
11945 if (hwaddr_aton(val, addr) < 0)
11946 return -1;
11947 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
11948 if (wpa_command(intf, buf) < 0) {
11949 send_resp(dut, conn, SIGMA_ERROR,
11950 "ErrorCode,Failed to start TDLS setup");
11951 return 0;
11952 }
11953 return 1;
11954 }
11955
11956 val = get_param(cmd, "TD_TearDown");
11957 if (val) {
11958 if (hwaddr_aton(val, addr) < 0)
11959 return -1;
11960 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
11961 if (wpa_command(intf, buf) < 0) {
11962 send_resp(dut, conn, SIGMA_ERROR,
11963 "ErrorCode,Failed to tear down TDLS link");
11964 return 0;
11965 }
11966 return 1;
11967 }
11968
11969 val = get_param(cmd, "TD_ChannelSwitch");
11970 if (val) {
11971 /* TODO */
11972 send_resp(dut, conn, SIGMA_ERROR,
11973 "ErrorCode,TD_ChannelSwitch not yet supported");
11974 return 0;
11975 }
11976
11977 val = get_param(cmd, "TD_NF");
11978 if (val) {
11979 /* TODO */
11980 send_resp(dut, conn, SIGMA_ERROR,
11981 "ErrorCode,TD_NF not yet supported");
11982 return 0;
11983 }
11984
11985 val = get_param(cmd, "PMFFrameType");
11986 if (val == NULL)
11987 val = get_param(cmd, "FrameName");
11988 if (val == NULL)
11989 val = get_param(cmd, "Type");
11990 if (val == NULL)
11991 return -1;
11992 if (strcasecmp(val, "disassoc") == 0)
11993 frame = DISASSOC;
11994 else if (strcasecmp(val, "deauth") == 0)
11995 frame = DEAUTH;
11996 else if (strcasecmp(val, "saquery") == 0)
11997 frame = SAQUERY;
11998 else if (strcasecmp(val, "auth") == 0)
11999 frame = AUTH;
12000 else if (strcasecmp(val, "assocreq") == 0)
12001 frame = ASSOCREQ;
12002 else if (strcasecmp(val, "reassocreq") == 0)
12003 frame = REASSOCREQ;
12004 else if (strcasecmp(val, "neigreq") == 0) {
12005 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
12006
12007 val = get_param(cmd, "ssid");
12008 if (val == NULL)
12009 return -1;
12010
12011 res = send_neighbor_request(dut, intf, val);
12012 if (res) {
12013 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
12014 "Failed to send neighbor report request");
12015 return 0;
12016 }
12017
12018 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053012019 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
12020 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012021 sigma_dut_print(dut, DUT_MSG_DEBUG,
12022 "Got Transition Management Query");
12023
Ashwini Patil5acd7382017-04-13 15:55:04 +053012024 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012025 if (res) {
12026 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
12027 "Failed to send Transition Management Query");
12028 return 0;
12029 }
12030
12031 return 1;
12032 } else {
12033 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12034 "PMFFrameType");
12035 return 0;
12036 }
12037
12038 val = get_param(cmd, "PMFProtected");
12039 if (val == NULL)
12040 val = get_param(cmd, "Protected");
12041 if (val == NULL)
12042 return -1;
12043 if (strcasecmp(val, "Correct-key") == 0 ||
12044 strcasecmp(val, "CorrectKey") == 0)
12045 protected = CORRECT_KEY;
12046 else if (strcasecmp(val, "IncorrectKey") == 0)
12047 protected = INCORRECT_KEY;
12048 else if (strcasecmp(val, "Unprotected") == 0)
12049 protected = UNPROTECTED;
12050 else {
12051 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12052 "PMFProtected");
12053 return 0;
12054 }
12055
12056 if (protected != UNPROTECTED &&
12057 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
12058 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
12059 "PMFProtected for auth/assocreq/reassocreq");
12060 return 0;
12061 }
12062
12063 if (if_nametoindex("sigmadut") == 0) {
12064 snprintf(buf, sizeof(buf),
12065 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012066 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012067 if (system(buf) != 0 ||
12068 if_nametoindex("sigmadut") == 0) {
12069 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
12070 "monitor interface with '%s'", buf);
12071 return -2;
12072 }
12073 }
12074
12075 if (system("ifconfig sigmadut up") != 0) {
12076 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
12077 "monitor interface up");
12078 return -2;
12079 }
12080
Veerendranath Jakkam49774122020-07-05 09:52:18 +053012081 return sta_inject_frame(dut, conn, intf, frame, protected, NULL, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012082}
12083
12084
12085static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
12086 struct sigma_conn *conn,
12087 struct sigma_cmd *cmd,
12088 const char *ifname)
12089{
12090 char buf[200];
12091 const char *val;
12092
12093 val = get_param(cmd, "ClearARP");
12094 if (val && atoi(val) == 1) {
12095 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
12096 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12097 if (system(buf) != 0) {
12098 send_resp(dut, conn, SIGMA_ERROR,
12099 "errorCode,Failed to clear ARP cache");
12100 return 0;
12101 }
12102 }
12103
12104 return 1;
12105}
12106
12107
12108int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
12109 struct sigma_cmd *cmd)
12110{
12111 const char *intf = get_param(cmd, "Interface");
12112 const char *val;
12113
12114 if (intf == NULL)
12115 return -1;
12116
12117 val = get_param(cmd, "program");
12118 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030012119 strcasecmp(val, "HS2-R2") == 0 ||
12120 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012121 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
12122
12123 return -1;
12124}
12125
12126
Jouni Malinenf7222712019-06-13 01:50:21 +030012127static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
12128 struct sigma_conn *conn,
12129 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012130{
12131 const char *intf = get_param(cmd, "Interface");
12132 const char *mac = get_param(cmd, "MAC");
12133
12134 if (intf == NULL || mac == NULL)
12135 return -1;
12136
12137 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
12138 "interface %s to %s", intf, mac);
12139
12140 if (dut->set_macaddr) {
12141 char buf[128];
12142 int res;
12143 if (strcasecmp(mac, "default") == 0) {
12144 res = snprintf(buf, sizeof(buf), "%s",
12145 dut->set_macaddr);
12146 dut->tmp_mac_addr = 0;
12147 } else {
12148 res = snprintf(buf, sizeof(buf), "%s %s",
12149 dut->set_macaddr, mac);
12150 dut->tmp_mac_addr = 1;
12151 }
12152 if (res < 0 || res >= (int) sizeof(buf))
12153 return -1;
12154 if (system(buf) != 0) {
12155 send_resp(dut, conn, SIGMA_ERROR,
12156 "errorCode,Failed to set MAC "
12157 "address");
12158 return 0;
12159 }
12160 return 1;
12161 }
12162
12163 if (strcasecmp(mac, "default") == 0)
12164 return 1;
12165
12166 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12167 "command");
12168 return 0;
12169}
12170
12171
12172static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
12173 struct sigma_conn *conn, const char *intf,
12174 int val)
12175{
12176 char buf[200];
12177 int res;
12178
12179 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
12180 intf, val);
12181 if (res < 0 || res >= (int) sizeof(buf))
12182 return -1;
12183 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12184 if (system(buf) != 0) {
12185 send_resp(dut, conn, SIGMA_ERROR,
12186 "errorCode,Failed to configure offchannel mode");
12187 return 0;
12188 }
12189
12190 return 1;
12191}
12192
12193
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012194static int off_chan_val(enum sec_ch_offset off)
12195{
12196 switch (off) {
12197 case SEC_CH_NO:
12198 return 0;
12199 case SEC_CH_40ABOVE:
12200 return 40;
12201 case SEC_CH_40BELOW:
12202 return -40;
12203 }
12204
12205 return 0;
12206}
12207
12208
12209static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
12210 const char *intf, int off_ch_num,
12211 enum sec_ch_offset sec)
12212{
12213 char buf[200];
12214 int res;
12215
12216 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
12217 intf, off_ch_num);
12218 if (res < 0 || res >= (int) sizeof(buf))
12219 return -1;
12220 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12221 if (system(buf) != 0) {
12222 send_resp(dut, conn, SIGMA_ERROR,
12223 "errorCode,Failed to set offchan");
12224 return 0;
12225 }
12226
12227 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
12228 intf, off_chan_val(sec));
12229 if (res < 0 || res >= (int) sizeof(buf))
12230 return -1;
12231 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12232 if (system(buf) != 0) {
12233 send_resp(dut, conn, SIGMA_ERROR,
12234 "errorCode,Failed to set sec chan offset");
12235 return 0;
12236 }
12237
12238 return 1;
12239}
12240
12241
12242static int tdls_set_offchannel_offset(struct sigma_dut *dut,
12243 struct sigma_conn *conn,
12244 const char *intf, int off_ch_num,
12245 enum sec_ch_offset sec)
12246{
12247 char buf[200];
12248 int res;
12249
12250 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
12251 off_ch_num);
12252 if (res < 0 || res >= (int) sizeof(buf))
12253 return -1;
12254 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12255
12256 if (wpa_command(intf, buf) < 0) {
12257 send_resp(dut, conn, SIGMA_ERROR,
12258 "ErrorCode,Failed to set offchan");
12259 return 0;
12260 }
12261 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
12262 off_chan_val(sec));
12263 if (res < 0 || res >= (int) sizeof(buf))
12264 return -1;
12265
12266 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12267
12268 if (wpa_command(intf, buf) < 0) {
12269 send_resp(dut, conn, SIGMA_ERROR,
12270 "ErrorCode,Failed to set sec chan offset");
12271 return 0;
12272 }
12273
12274 return 1;
12275}
12276
12277
12278static int tdls_set_offchannel_mode(struct sigma_dut *dut,
12279 struct sigma_conn *conn,
12280 const char *intf, int val)
12281{
12282 char buf[200];
12283 int res;
12284
12285 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
12286 val);
12287 if (res < 0 || res >= (int) sizeof(buf))
12288 return -1;
12289 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12290
12291 if (wpa_command(intf, buf) < 0) {
12292 send_resp(dut, conn, SIGMA_ERROR,
12293 "ErrorCode,Failed to configure offchannel mode");
12294 return 0;
12295 }
12296
12297 return 1;
12298}
12299
12300
12301static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
12302 struct sigma_conn *conn,
12303 struct sigma_cmd *cmd)
12304{
12305 const char *val;
12306 enum {
12307 CHSM_NOT_SET,
12308 CHSM_ENABLE,
12309 CHSM_DISABLE,
12310 CHSM_REJREQ,
12311 CHSM_UNSOLRESP
12312 } chsm = CHSM_NOT_SET;
12313 int off_ch_num = -1;
12314 enum sec_ch_offset sec_ch = SEC_CH_NO;
12315 int res;
12316
12317 val = get_param(cmd, "Uapsd");
12318 if (val) {
12319 char buf[100];
12320 if (strcasecmp(val, "Enable") == 0)
12321 snprintf(buf, sizeof(buf), "SET ps 99");
12322 else if (strcasecmp(val, "Disable") == 0)
12323 snprintf(buf, sizeof(buf), "SET ps 98");
12324 else {
12325 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
12326 "Unsupported uapsd parameter value");
12327 return 0;
12328 }
12329 if (wpa_command(intf, buf)) {
12330 send_resp(dut, conn, SIGMA_ERROR,
12331 "ErrorCode,Failed to change U-APSD "
12332 "powersave mode");
12333 return 0;
12334 }
12335 }
12336
12337 val = get_param(cmd, "TPKTIMER");
12338 if (val && strcasecmp(val, "DISABLE") == 0) {
12339 if (wpa_command(intf, "SET tdls_testing 0x100")) {
12340 send_resp(dut, conn, SIGMA_ERROR,
12341 "ErrorCode,Failed to enable no TPK "
12342 "expiration test mode");
12343 return 0;
12344 }
12345 dut->no_tpk_expiration = 1;
12346 }
12347
12348 val = get_param(cmd, "ChSwitchMode");
12349 if (val) {
12350 if (strcasecmp(val, "Enable") == 0 ||
12351 strcasecmp(val, "Initiate") == 0)
12352 chsm = CHSM_ENABLE;
12353 else if (strcasecmp(val, "Disable") == 0 ||
12354 strcasecmp(val, "passive") == 0)
12355 chsm = CHSM_DISABLE;
12356 else if (strcasecmp(val, "RejReq") == 0)
12357 chsm = CHSM_REJREQ;
12358 else if (strcasecmp(val, "UnSolResp") == 0)
12359 chsm = CHSM_UNSOLRESP;
12360 else {
12361 send_resp(dut, conn, SIGMA_ERROR,
12362 "ErrorCode,Unknown ChSwitchMode value");
12363 return 0;
12364 }
12365 }
12366
12367 val = get_param(cmd, "OffChNum");
12368 if (val) {
12369 off_ch_num = atoi(val);
12370 if (off_ch_num == 0) {
12371 send_resp(dut, conn, SIGMA_ERROR,
12372 "ErrorCode,Invalid OffChNum");
12373 return 0;
12374 }
12375 }
12376
12377 val = get_param(cmd, "SecChOffset");
12378 if (val) {
12379 if (strcmp(val, "20") == 0)
12380 sec_ch = SEC_CH_NO;
12381 else if (strcasecmp(val, "40above") == 0)
12382 sec_ch = SEC_CH_40ABOVE;
12383 else if (strcasecmp(val, "40below") == 0)
12384 sec_ch = SEC_CH_40BELOW;
12385 else {
12386 send_resp(dut, conn, SIGMA_ERROR,
12387 "ErrorCode,Unknown SecChOffset value");
12388 return 0;
12389 }
12390 }
12391
12392 if (chsm == CHSM_NOT_SET) {
12393 /* no offchannel changes requested */
12394 return 1;
12395 }
12396
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012397 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
12398 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012399 send_resp(dut, conn, SIGMA_ERROR,
12400 "ErrorCode,Unknown interface");
12401 return 0;
12402 }
12403
12404 switch (chsm) {
12405 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030012406 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012407 break;
12408 case CHSM_ENABLE:
12409 if (off_ch_num < 0) {
12410 send_resp(dut, conn, SIGMA_ERROR,
12411 "ErrorCode,Missing OffChNum argument");
12412 return 0;
12413 }
12414 if (wifi_chip_type == DRIVER_WCN) {
12415 res = tdls_set_offchannel_offset(dut, conn, intf,
12416 off_ch_num, sec_ch);
12417 } else {
12418 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
12419 sec_ch);
12420 }
12421 if (res != 1)
12422 return res;
12423 if (wifi_chip_type == DRIVER_WCN)
12424 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
12425 else
12426 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
12427 break;
12428 case CHSM_DISABLE:
12429 if (wifi_chip_type == DRIVER_WCN)
12430 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
12431 else
12432 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
12433 break;
12434 case CHSM_REJREQ:
12435 if (wifi_chip_type == DRIVER_WCN)
12436 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
12437 else
12438 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
12439 break;
12440 case CHSM_UNSOLRESP:
12441 if (off_ch_num < 0) {
12442 send_resp(dut, conn, SIGMA_ERROR,
12443 "ErrorCode,Missing OffChNum argument");
12444 return 0;
12445 }
12446 if (wifi_chip_type == DRIVER_WCN) {
12447 res = tdls_set_offchannel_offset(dut, conn, intf,
12448 off_ch_num, sec_ch);
12449 } else {
12450 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
12451 sec_ch);
12452 }
12453 if (res != 1)
12454 return res;
12455 if (wifi_chip_type == DRIVER_WCN)
12456 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
12457 else
12458 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
12459 break;
12460 }
12461
12462 return res;
12463}
12464
12465
12466static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
12467 struct sigma_conn *conn,
12468 struct sigma_cmd *cmd)
12469{
12470 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053012471 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012472
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070012473 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080012474
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012475 val = get_param(cmd, "nss_mcs_opt");
12476 if (val) {
12477 /* String (nss_operating_mode; mcs_operating_mode) */
12478 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012479 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012480
12481 token = strdup(val);
12482 if (!token)
12483 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012484 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053012485 if (!result) {
12486 sigma_dut_print(dut, DUT_MSG_ERROR,
12487 "VHT NSS not specified");
12488 goto failed;
12489 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012490 if (strcasecmp(result, "def") != 0) {
12491 nss = atoi(result);
12492 if (nss == 4)
12493 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012494 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012495 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012496
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012497 }
12498
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012499 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053012500 if (!result) {
12501 sigma_dut_print(dut, DUT_MSG_ERROR,
12502 "VHT MCS not specified");
12503 goto failed;
12504 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012505 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012506 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012507 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012508 } else {
12509 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012510 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012511 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012512 }
12513 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012514 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012515 }
12516
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053012517 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012518 return 1;
12519failed:
12520 free(token);
12521 return 0;
12522}
12523
12524
12525static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
12526 struct sigma_conn *conn,
12527 struct sigma_cmd *cmd)
12528{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012529 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012530 case DRIVER_ATHEROS:
12531 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
12532 default:
12533 send_resp(dut, conn, SIGMA_ERROR,
12534 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
12535 return 0;
12536 }
12537}
12538
12539
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012540static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12541 struct sigma_conn *conn,
12542 struct sigma_cmd *cmd)
12543{
12544 const char *val;
12545 char *token = NULL, *result;
12546 char buf[60];
12547
12548 val = get_param(cmd, "nss_mcs_opt");
12549 if (val) {
12550 /* String (nss_operating_mode; mcs_operating_mode) */
12551 int nss, mcs, ratecode;
12552 char *saveptr;
12553
12554 token = strdup(val);
12555 if (!token)
12556 return -2;
12557
12558 result = strtok_r(token, ";", &saveptr);
12559 if (!result) {
12560 sigma_dut_print(dut, DUT_MSG_ERROR,
12561 "HE NSS not specified");
12562 goto failed;
12563 }
12564 nss = 1;
12565 if (strcasecmp(result, "def") != 0)
12566 nss = atoi(result);
12567
12568 result = strtok_r(NULL, ";", &saveptr);
12569 if (!result) {
12570 sigma_dut_print(dut, DUT_MSG_ERROR,
12571 "HE MCS not specified");
12572 goto failed;
12573 }
12574 mcs = 7;
12575 if (strcasecmp(result, "def") != 0)
12576 mcs = atoi(result);
12577
Arif Hussain557bf412018-05-25 17:29:36 -070012578 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012579 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070012580 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012581 } else if (nss > 2) {
12582 sigma_dut_print(dut, DUT_MSG_ERROR,
12583 "HE NSS %d not supported", nss);
12584 goto failed;
12585 }
12586
Arif Hussain557bf412018-05-25 17:29:36 -070012587 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
12588 if (system(buf) != 0) {
12589 sigma_dut_print(dut, DUT_MSG_ERROR,
12590 "nss_mcs_opt: iwpriv %s nss %d failed",
12591 intf, nss);
12592 goto failed;
12593 }
Arif Hussainac6c5112018-05-25 17:34:00 -070012594 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070012595
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012596 /* Add the MCS to the ratecode */
12597 if (mcs >= 0 && mcs <= 11) {
12598 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070012599#ifdef NL80211_SUPPORT
12600 if (dut->device_type == STA_testbed) {
12601 enum he_mcs_config mcs_config;
12602 int ret;
12603
12604 if (mcs <= 7)
12605 mcs_config = HE_80_MCS0_7;
12606 else if (mcs <= 9)
12607 mcs_config = HE_80_MCS0_9;
12608 else
12609 mcs_config = HE_80_MCS0_11;
12610 ret = sta_set_he_mcs(dut, intf, mcs_config);
12611 if (ret) {
12612 sigma_dut_print(dut, DUT_MSG_ERROR,
12613 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
12614 mcs, mcs_config, ret);
12615 goto failed;
12616 }
12617 }
12618#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012619 } else {
12620 sigma_dut_print(dut, DUT_MSG_ERROR,
12621 "HE MCS %d not supported", mcs);
12622 goto failed;
12623 }
12624 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
12625 intf, ratecode);
12626 if (system(buf) != 0) {
12627 sigma_dut_print(dut, DUT_MSG_ERROR,
12628 "iwpriv setting of 11ax rates failed");
12629 goto failed;
12630 }
12631 free(token);
12632 }
12633
12634 val = get_param(cmd, "GI");
12635 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012636 int fix_rate_sgi;
12637
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012638 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012639 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012640 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012641 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012642 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
12643 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012644 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012645 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012646 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
12647 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012648 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012649 } else {
12650 send_resp(dut, conn, SIGMA_ERROR,
12651 "errorCode,GI value not supported");
12652 return 0;
12653 }
12654 if (system(buf) != 0) {
12655 send_resp(dut, conn, SIGMA_ERROR,
12656 "errorCode,Failed to set shortgi");
12657 return 0;
12658 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012659 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
12660 intf, fix_rate_sgi);
12661 if (system(buf) != 0) {
12662 send_resp(dut, conn, SIGMA_ERROR,
12663 "errorCode,Failed to set fix rate shortgi");
12664 return STATUS_SENT;
12665 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012666 }
12667
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012668 val = get_param(cmd, "LTF");
12669 if (val) {
12670#ifdef NL80211_SUPPORT
12671 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012672 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012673 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012674 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012675 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012676 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012677 } else {
12678 send_resp(dut, conn, SIGMA_ERROR,
12679 "errorCode, LTF value not supported");
12680 return 0;
12681 }
12682#else /* NL80211_SUPPORT */
12683 sigma_dut_print(dut, DUT_MSG_ERROR,
12684 "LTF cannot be set without NL80211_SUPPORT defined");
12685 return -2;
12686#endif /* NL80211_SUPPORT */
12687 }
12688
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070012689 val = get_param(cmd, "TxSUPPDU");
12690 if (val) {
12691 int set_val = 1;
12692
12693 if (strcasecmp(val, "Enable") == 0)
12694 set_val = 1;
12695 else if (strcasecmp(val, "Disable") == 0)
12696 set_val = 0;
12697
12698 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
12699 send_resp(dut, conn, SIGMA_ERROR,
12700 "ErrorCode,Failed to set Tx SU PPDU config");
12701 return 0;
12702 }
12703 }
12704
Arif Hussain480d5f42019-03-12 14:40:42 -070012705 val = get_param(cmd, "TWT_Setup");
12706 if (val) {
12707 if (strcasecmp(val, "Request") == 0) {
12708 if (sta_twt_request(dut, conn, cmd)) {
12709 send_resp(dut, conn, SIGMA_ERROR,
12710 "ErrorCode,sta_twt_request failed");
12711 return STATUS_SENT;
12712 }
12713 } else if (strcasecmp(val, "Teardown") == 0) {
12714 if (sta_twt_teardown(dut, conn, cmd)) {
12715 send_resp(dut, conn, SIGMA_ERROR,
12716 "ErrorCode,sta_twt_teardown failed");
12717 return STATUS_SENT;
12718 }
12719 }
12720 }
12721
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080012722 val = get_param(cmd, "transmitOMI");
12723 if (val && sta_transmit_omi(dut, conn, cmd)) {
12724 send_resp(dut, conn, SIGMA_ERROR,
12725 "ErrorCode,sta_transmit_omi failed");
12726 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070012727 }
12728
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012729 val = get_param(cmd, "Powersave");
12730 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012731 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012732
12733 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012734 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012735 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012736 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012737 } else {
12738 sigma_dut_print(dut, DUT_MSG_ERROR,
12739 "Unsupported Powersave value '%s'",
12740 val);
12741 return -1;
12742 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012743 if (set_power_save_wcn(dut, intf, ps) < 0)
12744 return 0;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012745 }
12746
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080012747 val = get_param(cmd, "MU_EDCA");
12748 if (val) {
12749 if (strcasecmp(val, "Override") == 0) {
12750 if (sta_set_mu_edca_override(dut, intf, 1)) {
12751 send_resp(dut, conn, SIGMA_ERROR,
12752 "errorCode,MU EDCA override set failed");
12753 return STATUS_SENT;
12754 }
12755 } else if (strcasecmp(val, "Disable") == 0) {
12756 if (sta_set_mu_edca_override(dut, intf, 0)) {
12757 send_resp(dut, conn, SIGMA_ERROR,
12758 "errorCode,MU EDCA override disable failed");
12759 return STATUS_SENT;
12760 }
12761 }
12762 }
12763
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -070012764 val = get_param(cmd, "Ch_Pref");
12765 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12766 return STATUS_SENT;
12767
12768 val = get_param(cmd, "Cellular_Data_Cap");
12769 if (val && mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12770 return STATUS_SENT;
12771
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012772 return 1;
12773
12774failed:
12775 free(token);
12776 return -2;
12777}
12778
12779
12780static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12781 struct sigma_conn *conn,
12782 struct sigma_cmd *cmd)
12783{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012784 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012785 case DRIVER_WCN:
12786 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
12787 default:
12788 send_resp(dut, conn, SIGMA_ERROR,
12789 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
12790 return 0;
12791 }
12792}
12793
12794
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012795static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
12796 struct sigma_conn *conn,
12797 struct sigma_cmd *cmd)
12798{
12799 const char *val;
12800
12801 val = get_param(cmd, "powersave");
12802 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012803 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012804
12805 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012806 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012807 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012808 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012809 } else {
12810 sigma_dut_print(dut, DUT_MSG_ERROR,
12811 "Unsupported power save config");
12812 return -1;
12813 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012814 if (set_power_save_wcn(dut, intf, ps) < 0)
12815 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012816 return 1;
12817 }
12818
12819 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
12820
12821 return 0;
12822}
12823
12824
Ashwini Patil5acd7382017-04-13 15:55:04 +053012825static int btm_query_candidate_list(struct sigma_dut *dut,
12826 struct sigma_conn *conn,
12827 struct sigma_cmd *cmd)
12828{
12829 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
12830 int len, ret;
12831 char buf[10];
12832
12833 /*
12834 * Neighbor Report elements format:
12835 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
12836 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
12837 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
12838 */
12839
12840 bssid = get_param(cmd, "Nebor_BSSID");
12841 if (!bssid) {
12842 send_resp(dut, conn, SIGMA_INVALID,
12843 "errorCode,Nebor_BSSID is missing");
12844 return 0;
12845 }
12846
12847 info = get_param(cmd, "Nebor_Bssid_Info");
12848 if (!info) {
12849 sigma_dut_print(dut, DUT_MSG_INFO,
12850 "Using default value for Nebor_Bssid_Info: %s",
12851 DEFAULT_NEIGHBOR_BSSID_INFO);
12852 info = DEFAULT_NEIGHBOR_BSSID_INFO;
12853 }
12854
12855 op_class = get_param(cmd, "Nebor_Op_Class");
12856 if (!op_class) {
12857 send_resp(dut, conn, SIGMA_INVALID,
12858 "errorCode,Nebor_Op_Class is missing");
12859 return 0;
12860 }
12861
12862 ch = get_param(cmd, "Nebor_Op_Ch");
12863 if (!ch) {
12864 send_resp(dut, conn, SIGMA_INVALID,
12865 "errorCode,Nebor_Op_Ch is missing");
12866 return 0;
12867 }
12868
12869 phy_type = get_param(cmd, "Nebor_Phy_Type");
12870 if (!phy_type) {
12871 sigma_dut_print(dut, DUT_MSG_INFO,
12872 "Using default value for Nebor_Phy_Type: %s",
12873 DEFAULT_NEIGHBOR_PHY_TYPE);
12874 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
12875 }
12876
12877 /* Parse optional subelements */
12878 buf[0] = '\0';
12879 pref = get_param(cmd, "Nebor_Pref");
12880 if (pref) {
12881 /* hexdump for preferrence subelement */
12882 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
12883 if (ret < 0 || ret >= (int) sizeof(buf)) {
12884 sigma_dut_print(dut, DUT_MSG_ERROR,
12885 "snprintf failed for optional subelement ret: %d",
12886 ret);
12887 send_resp(dut, conn, SIGMA_ERROR,
12888 "errorCode,snprintf failed for subelement");
12889 return 0;
12890 }
12891 }
12892
12893 if (!dut->btm_query_cand_list) {
12894 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
12895 if (!dut->btm_query_cand_list) {
12896 send_resp(dut, conn, SIGMA_ERROR,
12897 "errorCode,Failed to allocate memory for btm_query_cand_list");
12898 return 0;
12899 }
12900 }
12901
12902 len = strlen(dut->btm_query_cand_list);
12903 ret = snprintf(dut->btm_query_cand_list + len,
12904 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
12905 bssid, info, op_class, ch, phy_type, buf);
12906 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
12907 sigma_dut_print(dut, DUT_MSG_ERROR,
12908 "snprintf failed for neighbor report list ret: %d",
12909 ret);
12910 send_resp(dut, conn, SIGMA_ERROR,
12911 "errorCode,snprintf failed for neighbor report");
12912 free(dut->btm_query_cand_list);
12913 dut->btm_query_cand_list = NULL;
12914 return 0;
12915 }
12916
12917 return 1;
12918}
12919
12920
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012921int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
12922 struct sigma_ese_alloc *allocs, int *allocs_size)
12923{
12924 int max_count = *allocs_size;
12925 int count = 0, i;
12926 const char *val;
12927
12928 do {
12929 val = get_param_indexed(cmd, "AllocID", count);
12930 if (val)
12931 count++;
12932 } while (val);
12933
12934 if (count == 0 || count > max_count) {
12935 sigma_dut_print(dut, DUT_MSG_ERROR,
12936 "Invalid number of allocations(%d)", count);
12937 return -1;
12938 }
12939
12940 for (i = 0; i < count; i++) {
12941 val = get_param_indexed(cmd, "PercentBI", i);
12942 if (!val) {
12943 sigma_dut_print(dut, DUT_MSG_ERROR,
12944 "Missing PercentBI parameter at index %d",
12945 i);
12946 return -1;
12947 }
12948 allocs[i].percent_bi = atoi(val);
12949
12950 val = get_param_indexed(cmd, "SrcAID", i);
12951 if (val)
12952 allocs[i].src_aid = strtol(val, NULL, 0);
12953 else
12954 allocs[i].src_aid = ESE_BCAST_AID;
12955
12956 val = get_param_indexed(cmd, "DestAID", i);
12957 if (val)
12958 allocs[i].dst_aid = strtol(val, NULL, 0);
12959 else
12960 allocs[i].dst_aid = ESE_BCAST_AID;
12961
12962 allocs[i].type = ESE_CBAP;
12963 sigma_dut_print(dut, DUT_MSG_INFO,
12964 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
12965 i, allocs[i].percent_bi, allocs[i].src_aid,
12966 allocs[i].dst_aid);
12967 }
12968
12969 *allocs_size = count;
12970 return 0;
12971}
12972
12973
12974static int sta_set_60g_ese(struct sigma_dut *dut, int count,
12975 struct sigma_ese_alloc *allocs)
12976{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012977 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012978#ifdef __linux__
12979 case DRIVER_WIL6210:
12980 if (wil6210_set_ese(dut, count, allocs))
12981 return -1;
12982 return 1;
12983#endif /* __linux__ */
12984 default:
12985 sigma_dut_print(dut, DUT_MSG_ERROR,
12986 "Unsupported sta_set_60g_ese with the current driver");
12987 return -1;
12988 }
12989}
12990
12991
12992static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
12993 struct sigma_conn *conn,
12994 struct sigma_cmd *cmd)
12995{
12996 const char *val;
12997
12998 val = get_param(cmd, "ExtSchIE");
12999 if (val && !strcasecmp(val, "Enable")) {
13000 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
13001 int count = MAX_ESE_ALLOCS;
13002
13003 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
13004 return -1;
13005 return sta_set_60g_ese(dut, count, allocs);
13006 }
13007
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020013008 val = get_param(cmd, "MCS_FixedRate");
13009 if (val) {
13010 int sta_mcs = atoi(val);
13011
13012 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
13013 sta_mcs);
13014 wil6210_set_force_mcs(dut, 1, sta_mcs);
13015
Jouni Malinen0e29cf22019-02-19 01:13:21 +020013016 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020013017 }
13018
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020013019 send_resp(dut, conn, SIGMA_ERROR,
13020 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020013021 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020013022}
13023
13024
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053013025static int wcn_sta_override_oci(struct sigma_dut *dut, const char *intf,
13026 const char *oci_frametype, uint32_t oci_freq)
13027{
13028#ifdef NL80211_SUPPORT
13029 struct nl_msg *msg;
13030 int ret = 0;
13031 struct nlattr *params;
13032 struct nlattr *attr;
13033 int ifindex;
13034 u8 frame_type;
13035
13036 ifindex = if_nametoindex(intf);
13037 if (ifindex == 0) {
13038 sigma_dut_print(dut, DUT_MSG_ERROR,
13039 "%s: Index for interface %s failed",
13040 __func__, intf);
13041 return -1;
13042 }
13043
13044 if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
13045 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_REQ;
13046 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
13047 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_RESP;
13048 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
13049 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_FT_REASSOC_REQ;
13050 } else {
13051 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: Unknown frametype %s",
13052 __func__, oci_frametype);
13053 return -1;
13054 }
13055
13056
13057 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
13058 NL80211_CMD_VENDOR)) ||
13059 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
13060 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
13061 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
13062 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
13063 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
13064 !(params = nla_nest_start(
13065 msg,
13066 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OCI_OVERRIDE)) ||
13067 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FRAME_TYPE,
13068 frame_type) ||
13069 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FREQUENCY,
13070 oci_freq)) {
13071 sigma_dut_print(dut, DUT_MSG_ERROR,
13072 "%s: err in adding vendor_cmd and vendor_data",
13073 __func__);
13074 nlmsg_free(msg);
13075 return -1;
13076 }
13077 nla_nest_end(msg, params);
13078 nla_nest_end(msg, attr);
13079
13080 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
13081 if (ret) {
13082 sigma_dut_print(dut, DUT_MSG_ERROR,
13083 "%s: err in send_and_recv_msgs, ret=%d",
13084 __func__, ret);
13085 }
13086 return ret;
13087#else /* NL80211_SUPPORT */
13088 sigma_dut_print(dut, DUT_MSG_ERROR,
13089 "OCI override not possible without NL80211_SUPPORT defined");
13090 return -1;
13091#endif /* NL80211_SUPPORT */
13092}
13093
13094
Jouni Malinen6250cb02020-04-15 13:54:45 +030013095static enum sigma_cmd_result
13096cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
13097 struct sigma_conn *conn,
13098 struct sigma_cmd *cmd)
13099{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053013100 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030013101
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053013102 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030013103 if (val && atoi(val) == 1) {
13104 if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
13105 send_resp(dut, conn, SIGMA_ERROR,
13106 "errorCode,Failed to set ft_rsnxe_used");
13107 return STATUS_SENT_ERROR;
13108 }
13109 return SUCCESS_SEND_STATUS;
13110 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053013111
13112 oci_chan = get_param(cmd, "OCIChannel");
13113 oci_frametype = get_param(cmd, "OCIFrameType");
13114 if (oci_chan && oci_frametype) {
13115 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
13116 char buf[100];
13117
13118 if (!oci_freq) {
13119 send_resp(dut, conn, SIGMA_ERROR,
13120 "errorCode,Invalid OCIChannel number");
13121 return STATUS_SENT_ERROR;
13122 }
13123
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053013124 if (wifi_chip_type == DRIVER_WCN &&
13125 (strcasecmp(oci_frametype, "SAQueryReq") == 0 ||
13126 strcasecmp(oci_frametype, "SAQueryResp") == 0 ||
13127 strcasecmp(oci_frametype, "Reassocreq") == 0)) {
13128 if (wcn_sta_override_oci(dut, intf, oci_frametype,
13129 oci_freq)) {
13130 send_resp(dut, conn, SIGMA_ERROR,
13131 "errorCode,Failed to override OCI");
13132 return STATUS_SENT_ERROR;
13133 }
13134 return SUCCESS_SEND_STATUS;
13135 }
13136
Vamsi Krishnad29bc762020-05-08 23:23:30 +053013137 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
13138 snprintf(buf, sizeof(buf),
13139 "SET oci_freq_override_eapol %d", oci_freq);
13140 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
13141 snprintf(buf, sizeof(buf),
13142 "SET oci_freq_override_saquery_req %d",
13143 oci_freq);
13144 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
13145 snprintf(buf, sizeof(buf),
13146 "SET oci_freq_override_saquery_resp %d",
13147 oci_freq);
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053013148 } else if (strcasecmp(oci_frametype, "GrpKeyM2") == 0) {
13149 snprintf(buf, sizeof(buf),
13150 "SET oci_freq_override_eapol_g2 %d",
13151 oci_freq);
13152 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
13153 snprintf(buf, sizeof(buf),
13154 "SET oci_freq_override_ft_assoc %d",
13155 oci_freq);
Vamsi Krishnad29bc762020-05-08 23:23:30 +053013156 } else {
13157 send_resp(dut, conn, SIGMA_ERROR,
13158 "errorCode,Unsupported OCIFrameType");
13159 return STATUS_SENT_ERROR;
13160 }
13161 if (wpa_command(intf, buf) < 0) {
13162 send_resp(dut, conn, SIGMA_ERROR,
13163 "errorCode,Failed to set oci_freq_override");
13164 return STATUS_SENT_ERROR;
13165 }
13166 return SUCCESS_SEND_STATUS;
13167 }
13168
Jouni Malinen6250cb02020-04-15 13:54:45 +030013169 send_resp(dut, conn, SIGMA_ERROR,
13170 "errorCode,Unsupported WPA3 rfeature");
13171 return STATUS_SENT_ERROR;
13172}
13173
13174
Jouni Malinenf7222712019-06-13 01:50:21 +030013175static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
13176 struct sigma_conn *conn,
13177 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013178{
13179 const char *intf = get_param(cmd, "Interface");
13180 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053013181 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013182
13183 if (intf == NULL || prog == NULL)
13184 return -1;
13185
Ashwini Patil5acd7382017-04-13 15:55:04 +053013186 /* BSS Transition candidate list for BTM query */
13187 val = get_param(cmd, "Nebor_BSSID");
13188 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
13189 return 0;
13190
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013191 if (strcasecmp(prog, "TDLS") == 0)
13192 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
13193
13194 if (strcasecmp(prog, "VHT") == 0)
13195 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
13196
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080013197 if (strcasecmp(prog, "HE") == 0)
13198 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
13199
Ashwini Patil68d02cd2017-01-10 15:39:16 +053013200 if (strcasecmp(prog, "MBO") == 0) {
13201 val = get_param(cmd, "Cellular_Data_Cap");
13202 if (val &&
13203 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
13204 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053013205
13206 val = get_param(cmd, "Ch_Pref");
13207 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
13208 return 0;
13209
Ashwini Patil68d02cd2017-01-10 15:39:16 +053013210 return 1;
13211 }
13212
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020013213 if (strcasecmp(prog, "60GHz") == 0)
13214 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
13215
Jouni Malinen6250cb02020-04-15 13:54:45 +030013216 if (strcasecmp(prog, "WPA3") == 0)
13217 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
13218
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013219 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
13220 return 0;
13221}
13222
13223
Jouni Malinenf7222712019-06-13 01:50:21 +030013224static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
13225 struct sigma_conn *conn,
13226 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013227{
13228 const char *intf = get_param(cmd, "Interface");
13229 const char *mode = get_param(cmd, "Mode");
13230 int res;
13231
13232 if (intf == NULL || mode == NULL)
13233 return -1;
13234
13235 if (strcasecmp(mode, "On") == 0)
13236 res = wpa_command(intf, "SET radio_disabled 0");
13237 else if (strcasecmp(mode, "Off") == 0)
13238 res = wpa_command(intf, "SET radio_disabled 1");
13239 else
13240 return -1;
13241
13242 if (res) {
13243 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
13244 "radio mode");
13245 return 0;
13246 }
13247
13248 return 1;
13249}
13250
13251
Jouni Malinenf7222712019-06-13 01:50:21 +030013252static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
13253 struct sigma_conn *conn,
13254 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013255{
13256 const char *intf = get_param(cmd, "Interface");
13257 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013258 const char *prog = get_param(cmd, "program");
13259 const char *powersave = get_param(cmd, "powersave");
13260 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013261
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013262 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013263 return -1;
13264
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013265 if (prog && strcasecmp(prog, "60GHz") == 0) {
13266 /*
13267 * The CAPI mode parameter does not exist in 60G
13268 * unscheduled PS.
13269 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080013270 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013271 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013272 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020013273 strcasecmp(prog, "HE") == 0) {
13274 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013275 } else {
13276 if (mode == NULL)
13277 return -1;
13278
13279 if (strcasecmp(mode, "On") == 0)
13280 res = set_ps(intf, dut, 1);
13281 else if (strcasecmp(mode, "Off") == 0)
13282 res = set_ps(intf, dut, 0);
13283 else
13284 return -1;
13285 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013286
13287 if (res) {
13288 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
13289 "power save mode");
13290 return 0;
13291 }
13292
13293 return 1;
13294}
13295
13296
Jouni Malinenf7222712019-06-13 01:50:21 +030013297static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
13298 struct sigma_conn *conn,
13299 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013300{
13301 const char *intf = get_param(cmd, "Interface");
13302 const char *val, *bssid;
13303 int res;
13304 char *buf;
13305 size_t buf_len;
13306
13307 val = get_param(cmd, "BSSID_FILTER");
13308 if (val == NULL)
13309 return -1;
13310
13311 bssid = get_param(cmd, "BSSID_List");
13312 if (atoi(val) == 0 || bssid == NULL) {
13313 /* Disable BSSID filter */
13314 if (wpa_command(intf, "SET bssid_filter ")) {
13315 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
13316 "to disable BSSID filter");
13317 return 0;
13318 }
13319
13320 return 1;
13321 }
13322
13323 buf_len = 100 + strlen(bssid);
13324 buf = malloc(buf_len);
13325 if (buf == NULL)
13326 return -1;
13327
13328 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
13329 res = wpa_command(intf, buf);
13330 free(buf);
13331 if (res) {
13332 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
13333 "BSSID filter");
13334 return 0;
13335 }
13336
13337 return 1;
13338}
13339
13340
Jouni Malinenf7222712019-06-13 01:50:21 +030013341static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
13342 struct sigma_conn *conn,
13343 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013344{
13345 const char *intf = get_param(cmd, "Interface");
13346 const char *val;
13347
13348 /* TODO: ARP */
13349
13350 val = get_param(cmd, "HS2_CACHE_PROFILE");
13351 if (val && strcasecmp(val, "All") == 0)
13352 hs2_clear_credentials(intf);
13353
13354 return 1;
13355}
13356
13357
Jouni Malinenf7222712019-06-13 01:50:21 +030013358static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
13359 struct sigma_conn *conn,
13360 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013361{
13362 const char *intf = get_param(cmd, "Interface");
13363 const char *key_type = get_param(cmd, "KeyType");
13364 char buf[100], resp[200];
13365
13366 if (key_type == NULL)
13367 return -1;
13368
13369 if (strcasecmp(key_type, "GTK") == 0) {
13370 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
13371 strncmp(buf, "FAIL", 4) == 0) {
13372 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13373 "not fetch current GTK");
13374 return 0;
13375 }
13376 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
13377 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13378 return 0;
13379 } else {
13380 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13381 "KeyType");
13382 return 0;
13383 }
13384
13385 return 1;
13386}
13387
13388
13389static int hs2_set_policy(struct sigma_dut *dut)
13390{
13391#ifdef ANDROID
13392 system("ip rule del prio 23000");
13393 if (system("ip rule add from all lookup main prio 23000") != 0) {
13394 sigma_dut_print(dut, DUT_MSG_ERROR,
13395 "Failed to run:ip rule add from all lookup main prio");
13396 return -1;
13397 }
13398 if (system("ip route flush cache") != 0) {
13399 sigma_dut_print(dut, DUT_MSG_ERROR,
13400 "Failed to run ip route flush cache");
13401 return -1;
13402 }
13403 return 1;
13404#else /* ANDROID */
13405 return 0;
13406#endif /* ANDROID */
13407}
13408
13409
Jouni Malinenf7222712019-06-13 01:50:21 +030013410static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
13411 struct sigma_conn *conn,
13412 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013413{
13414 const char *intf = get_param(cmd, "Interface");
13415 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030013416 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013417 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030013418 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013419 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
13420 int tries = 0;
13421 int ignore_blacklist = 0;
13422 const char *events[] = {
13423 "CTRL-EVENT-CONNECTED",
13424 "INTERWORKING-BLACKLISTED",
13425 "INTERWORKING-NO-MATCH",
13426 NULL
13427 };
13428
13429 start_sta_mode(dut);
13430
Jouni Malinen439352d2018-09-13 03:42:23 +030013431 if (band) {
13432 if (strcmp(band, "2.4") == 0) {
13433 wpa_command(intf, "SET setband 2G");
13434 } else if (strcmp(band, "5") == 0) {
13435 wpa_command(intf, "SET setband 5G");
13436 } else {
13437 send_resp(dut, conn, SIGMA_ERROR,
13438 "errorCode,Unsupported band");
13439 return 0;
13440 }
13441 }
13442
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013443 blacklisted[0] = '\0';
13444 if (val && atoi(val))
13445 ignore_blacklist = 1;
13446
13447try_again:
13448 ctrl = open_wpa_mon(intf);
13449 if (ctrl == NULL) {
13450 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13451 "wpa_supplicant monitor connection");
13452 return -2;
13453 }
13454
13455 tries++;
13456 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
13457 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
13458 "Interworking connection");
13459 wpa_ctrl_detach(ctrl);
13460 wpa_ctrl_close(ctrl);
13461 return 0;
13462 }
13463
13464 buf[0] = '\0';
13465 while (1) {
13466 char *pos;
13467 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13468 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
13469 if (!pos)
13470 break;
13471 pos += 25;
13472 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
13473 pos);
13474 if (!blacklisted[0])
13475 memcpy(blacklisted, pos, strlen(pos) + 1);
13476 }
13477
13478 if (ignore_blacklist && blacklisted[0]) {
13479 char *end;
13480 end = strchr(blacklisted, ' ');
13481 if (end)
13482 *end = '\0';
13483 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
13484 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030013485 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
13486 blacklisted);
13487 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013488 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
13489 wpa_ctrl_detach(ctrl);
13490 wpa_ctrl_close(ctrl);
13491 return 0;
13492 }
13493 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13494 buf, sizeof(buf));
13495 }
13496
13497 wpa_ctrl_detach(ctrl);
13498 wpa_ctrl_close(ctrl);
13499
13500 if (res < 0) {
13501 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
13502 "connect");
13503 return 0;
13504 }
13505
13506 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
13507 strstr(buf, "INTERWORKING-BLACKLISTED")) {
13508 if (tries < 2) {
13509 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
13510 goto try_again;
13511 }
13512 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
13513 "matching credentials found");
13514 return 0;
13515 }
13516
13517 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13518 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13519 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
13520 "get current BSSID/SSID");
13521 return 0;
13522 }
13523
13524 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
13525 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13526 hs2_set_policy(dut);
13527 return 0;
13528}
13529
13530
Jouni Malinenf7222712019-06-13 01:50:21 +030013531static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
13532 struct sigma_conn *conn,
13533 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013534{
13535 const char *intf = get_param(cmd, "Interface");
13536 const char *display = get_param(cmd, "Display");
13537 struct wpa_ctrl *ctrl;
13538 char buf[300], params[400], *pos;
13539 char bssid[20];
13540 int info_avail = 0;
13541 unsigned int old_timeout;
13542 int res;
13543
13544 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
13545 send_resp(dut, conn, SIGMA_ERROR,
13546 "ErrorCode,Could not get current BSSID");
13547 return 0;
13548 }
13549 ctrl = open_wpa_mon(intf);
13550 if (!ctrl) {
13551 sigma_dut_print(dut, DUT_MSG_ERROR,
13552 "Failed to open wpa_supplicant monitor connection");
13553 return -2;
13554 }
13555
13556 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
13557 wpa_command(intf, buf);
13558
13559 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
13560 if (res < 0) {
13561 send_resp(dut, conn, SIGMA_ERROR,
13562 "ErrorCode,Could not complete GAS query");
13563 goto fail;
13564 }
13565
13566 old_timeout = dut->default_timeout;
13567 dut->default_timeout = 2;
13568 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
13569 dut->default_timeout = old_timeout;
13570 if (res < 0)
13571 goto done;
13572 pos = strchr(buf, ' ');
13573 if (!pos)
13574 goto done;
13575 pos++;
13576 pos = strchr(pos, ' ');
13577 if (!pos)
13578 goto done;
13579 pos++;
13580 info_avail = 1;
13581 snprintf(params, sizeof(params), "browser %s", pos);
13582
13583 if (display && strcasecmp(display, "Yes") == 0) {
13584 pid_t pid;
13585
13586 pid = fork();
13587 if (pid < 0) {
13588 perror("fork");
13589 return -1;
13590 }
13591
13592 if (pid == 0) {
13593 run_hs20_osu(dut, params);
13594 exit(0);
13595 }
13596 }
13597
13598done:
13599 snprintf(buf, sizeof(buf), "Info_available,%s",
13600 info_avail ? "Yes" : "No");
13601 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13602fail:
13603 wpa_ctrl_detach(ctrl);
13604 wpa_ctrl_close(ctrl);
13605 return 0;
13606}
13607
13608
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013609static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
13610 struct sigma_conn *conn,
13611 const char *ifname,
13612 struct sigma_cmd *cmd)
13613{
13614 const char *val;
13615 int id;
13616
13617 id = add_cred(ifname);
13618 if (id < 0)
13619 return -2;
13620 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13621
13622 val = get_param(cmd, "prefer");
13623 if (val && atoi(val) > 0)
13624 set_cred(ifname, id, "priority", "1");
13625
13626 val = get_param(cmd, "REALM");
13627 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13628 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13629 "realm");
13630 return 0;
13631 }
13632
13633 val = get_param(cmd, "HOME_FQDN");
13634 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13635 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13636 "home_fqdn");
13637 return 0;
13638 }
13639
13640 val = get_param(cmd, "Username");
13641 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13642 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13643 "username");
13644 return 0;
13645 }
13646
13647 val = get_param(cmd, "Password");
13648 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
13649 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13650 "password");
13651 return 0;
13652 }
13653
13654 val = get_param(cmd, "ROOT_CA");
13655 if (val) {
13656 char fname[200];
13657 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13658#ifdef __linux__
13659 if (!file_exists(fname)) {
13660 char msg[300];
13661 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13662 "file (%s) not found", fname);
13663 send_resp(dut, conn, SIGMA_ERROR, msg);
13664 return 0;
13665 }
13666#endif /* __linux__ */
13667 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13668 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13669 "not set root CA");
13670 return 0;
13671 }
13672 }
13673
13674 return 1;
13675}
13676
13677
13678static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
13679{
13680 FILE *in, *out;
13681 char buf[500];
13682 int found = 0;
13683
13684 in = fopen("devdetail.xml", "r");
13685 if (in == NULL)
13686 return -1;
13687 out = fopen("devdetail.xml.tmp", "w");
13688 if (out == NULL) {
13689 fclose(in);
13690 return -1;
13691 }
13692
13693 while (fgets(buf, sizeof(buf), in)) {
13694 char *pos = strstr(buf, "<IMSI>");
13695 if (pos) {
13696 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
13697 imsi);
13698 pos += 6;
13699 *pos = '\0';
13700 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
13701 found++;
13702 } else {
13703 fprintf(out, "%s", buf);
13704 }
13705 }
13706
13707 fclose(out);
13708 fclose(in);
13709 if (found)
13710 rename("devdetail.xml.tmp", "devdetail.xml");
13711 else
13712 unlink("devdetail.xml.tmp");
13713
13714 return 0;
13715}
13716
13717
13718static int sta_add_credential_sim(struct sigma_dut *dut,
13719 struct sigma_conn *conn,
13720 const char *ifname, struct sigma_cmd *cmd)
13721{
13722 const char *val, *imsi = NULL;
13723 int id;
13724 char buf[200];
13725 int res;
13726 const char *pos;
13727 size_t mnc_len;
13728 char plmn_mcc[4];
13729 char plmn_mnc[4];
13730
13731 id = add_cred(ifname);
13732 if (id < 0)
13733 return -2;
13734 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13735
13736 val = get_param(cmd, "prefer");
13737 if (val && atoi(val) > 0)
13738 set_cred(ifname, id, "priority", "1");
13739
13740 val = get_param(cmd, "PLMN_MCC");
13741 if (val == NULL) {
13742 send_resp(dut, conn, SIGMA_ERROR,
13743 "errorCode,Missing PLMN_MCC");
13744 return 0;
13745 }
13746 if (strlen(val) != 3) {
13747 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
13748 return 0;
13749 }
13750 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
13751
13752 val = get_param(cmd, "PLMN_MNC");
13753 if (val == NULL) {
13754 send_resp(dut, conn, SIGMA_ERROR,
13755 "errorCode,Missing PLMN_MNC");
13756 return 0;
13757 }
13758 if (strlen(val) != 2 && strlen(val) != 3) {
13759 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
13760 return 0;
13761 }
13762 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
13763
13764 val = get_param(cmd, "IMSI");
13765 if (val == NULL) {
13766 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
13767 "IMSI");
13768 return 0;
13769 }
13770
13771 imsi = pos = val;
13772
13773 if (strncmp(plmn_mcc, pos, 3) != 0) {
13774 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
13775 return 0;
13776 }
13777 pos += 3;
13778
13779 mnc_len = strlen(plmn_mnc);
13780 if (mnc_len < 2) {
13781 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
13782 return 0;
13783 }
13784
13785 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
13786 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
13787 return 0;
13788 }
13789 pos += mnc_len;
13790
13791 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
13792 if (res < 0 || res >= (int) sizeof(buf))
13793 return -1;
13794 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
13795 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13796 "not set IMSI");
13797 return 0;
13798 }
13799
13800 val = get_param(cmd, "Password");
13801 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
13802 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13803 "not set password");
13804 return 0;
13805 }
13806
Jouni Malinenba630452018-06-22 11:49:59 +030013807 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013808 /*
13809 * Set provisioning_sp for the test cases where SIM/USIM
13810 * provisioning is used.
13811 */
13812 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
13813 "wi-fi.org") < 0) {
13814 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13815 "not set provisioning_sp");
13816 return 0;
13817 }
13818
13819 update_devdetail_imsi(dut, imsi);
13820 }
13821
13822 return 1;
13823}
13824
13825
13826static int sta_add_credential_cert(struct sigma_dut *dut,
13827 struct sigma_conn *conn,
13828 const char *ifname,
13829 struct sigma_cmd *cmd)
13830{
13831 const char *val;
13832 int id;
13833
13834 id = add_cred(ifname);
13835 if (id < 0)
13836 return -2;
13837 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13838
13839 val = get_param(cmd, "prefer");
13840 if (val && atoi(val) > 0)
13841 set_cred(ifname, id, "priority", "1");
13842
13843 val = get_param(cmd, "REALM");
13844 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13845 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13846 "realm");
13847 return 0;
13848 }
13849
13850 val = get_param(cmd, "HOME_FQDN");
13851 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13852 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13853 "home_fqdn");
13854 return 0;
13855 }
13856
13857 val = get_param(cmd, "Username");
13858 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13859 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13860 "username");
13861 return 0;
13862 }
13863
13864 val = get_param(cmd, "clientCertificate");
13865 if (val) {
13866 char fname[200];
13867 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13868#ifdef __linux__
13869 if (!file_exists(fname)) {
13870 char msg[300];
13871 snprintf(msg, sizeof(msg),
13872 "ErrorCode,clientCertificate "
13873 "file (%s) not found", fname);
13874 send_resp(dut, conn, SIGMA_ERROR, msg);
13875 return 0;
13876 }
13877#endif /* __linux__ */
13878 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
13879 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13880 "not set client_cert");
13881 return 0;
13882 }
13883 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
13884 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13885 "not set private_key");
13886 return 0;
13887 }
13888 }
13889
13890 val = get_param(cmd, "ROOT_CA");
13891 if (val) {
13892 char fname[200];
13893 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13894#ifdef __linux__
13895 if (!file_exists(fname)) {
13896 char msg[300];
13897 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13898 "file (%s) not found", fname);
13899 send_resp(dut, conn, SIGMA_ERROR, msg);
13900 return 0;
13901 }
13902#endif /* __linux__ */
13903 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13904 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13905 "not set root CA");
13906 return 0;
13907 }
13908 }
13909
13910 return 1;
13911}
13912
13913
Jouni Malinenf7222712019-06-13 01:50:21 +030013914static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
13915 struct sigma_conn *conn,
13916 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013917{
13918 const char *intf = get_param(cmd, "Interface");
13919 const char *type;
13920
13921 start_sta_mode(dut);
13922
13923 type = get_param(cmd, "Type");
13924 if (!type)
13925 return -1;
13926
13927 if (strcasecmp(type, "uname_pwd") == 0)
13928 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
13929
13930 if (strcasecmp(type, "sim") == 0)
13931 return sta_add_credential_sim(dut, conn, intf, cmd);
13932
13933 if (strcasecmp(type, "cert") == 0)
13934 return sta_add_credential_cert(dut, conn, intf, cmd);
13935
13936 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
13937 "type");
13938 return 0;
13939}
13940
13941
Jouni Malinenf7222712019-06-13 01:50:21 +030013942static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
13943 struct sigma_conn *conn,
13944 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013945{
13946 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013947 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Veerendranathdc581b52020-08-10 03:29:08 -070013948 char buf[4096], scan_res[20];
vamsi krishna89ad8c62017-09-19 12:51:18 +053013949 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013950 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013951 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013952 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013953 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013954
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020013955 start_sta_mode(dut);
13956
Arif Hussain66a4af02019-02-07 15:04:51 -080013957 val = get_param(cmd, "GetParameter");
13958 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013959 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080013960 buf, sizeof(buf)) < 0) {
13961 sigma_dut_print(dut, DUT_MSG_ERROR,
13962 "Could not get ssid bssid");
13963 return ERROR_SEND_STATUS;
13964 }
13965
13966 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
13967 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13968 return STATUS_SENT;
13969 }
13970
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013971 val = get_param(cmd, "HESSID");
13972 if (val) {
13973 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
13974 if (res < 0 || res >= (int) sizeof(buf))
13975 return -1;
13976 wpa_command(intf, buf);
13977 }
13978
13979 val = get_param(cmd, "ACCS_NET_TYPE");
13980 if (val) {
13981 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
13982 val);
13983 if (res < 0 || res >= (int) sizeof(buf))
13984 return -1;
13985 wpa_command(intf, buf);
13986 }
13987
vamsi krishna89ad8c62017-09-19 12:51:18 +053013988 bssid = get_param(cmd, "Bssid");
13989 ssid = get_param(cmd, "Ssid");
13990
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013991 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
13992 dut->device_type == STA_testbed) {
13993 ssid = NULL;
13994 wildcard_ssid = 1;
13995 }
13996
vamsi krishna89ad8c62017-09-19 12:51:18 +053013997 if (ssid) {
13998 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
13999 send_resp(dut, conn, SIGMA_ERROR,
14000 "ErrorCode,Too long SSID");
14001 return 0;
14002 }
14003 ascii2hexstr(ssid, ssid_hex);
14004 }
14005
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014006 short_ssid = get_param(cmd, "ShortSSID");
14007 if (short_ssid) {
14008 uint32_t short_ssid_hex;
14009
14010 short_ssid_hex = strtoul(short_ssid, NULL, 16);
14011 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
14012 (((short_ssid_hex >> 8) & 0xFF) << 16) |
14013 (((short_ssid_hex >> 16) & 0xFF) << 8) |
14014 ((short_ssid_hex >> 24) & 0xFF);
14015
14016 res = snprintf(buf, sizeof(buf),
14017 "VENDOR_ELEM_ADD 14 ff053a%08x",
14018 short_ssid_hex);
14019 if (res < 0 || res >= (int) sizeof(buf) ||
14020 wpa_command(intf, buf)) {
14021 send_resp(dut, conn, SIGMA_ERROR,
14022 "errorCode,Failed to add short SSID");
14023 return STATUS_SENT_ERROR;
14024 }
14025 }
14026
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080014027 scan_freq = get_param(cmd, "ChnlFreq");
Veerendranath Jakkam132c4b42020-08-10 00:29:03 +053014028 if (scan_freq) {
14029 if (strcasecmp(scan_freq, "2G") == 0)
14030 scan_freq = "2412-2462";
14031 else if (strcasecmp(scan_freq, "5G") == 0)
14032 scan_freq = "5180-5925";
14033 }
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080014034
Jouni Malinen228a2fc2020-06-22 23:37:45 +030014035 val = get_param(cmd, "WaitCompletion");
14036 if (val && atoi(val) == 1) {
14037 ctrl = open_wpa_mon(intf);
14038 if (!ctrl) {
14039 send_resp(dut, conn, SIGMA_ERROR,
14040 "errorCode,Failed to open monitor socket");
14041 return STATUS_SENT_ERROR;
14042 }
14043 }
14044
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080014045 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053014046 bssid ? " bssid=": "",
14047 bssid ? bssid : "",
14048 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080014049 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080014050 wildcard_ssid ? " wildcard_ssid=1" : "",
14051 scan_freq ? " freq=" : "",
14052 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014053 if (res < 0 || res >= (int) sizeof(buf)) {
14054 send_resp(dut, conn, SIGMA_ERROR,
14055 "errorCode,Could not build scan command");
14056 status = STATUS_SENT_ERROR;
14057 goto remove_s_ssid;
14058 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053014059
Veerendranathdc581b52020-08-10 03:29:08 -070014060 res = wpa_command_resp(intf, buf, scan_res, sizeof(scan_res));
14061 if (strncmp(scan_res, "FAIL-BUSY", 9) == 0) {
14062 sigma_dut_print(dut, DUT_MSG_DEBUG,
14063 "Scan request rejected with busy status, abort ongoing scan and try again");
14064 wpa_command(intf, "ABORT_SCAN");
14065 res = wpa_command(intf, buf);
14066 }
14067
14068 if (res < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014069 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
14070 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014071 status = STATUS_SENT_ERROR;
14072 } else {
14073 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014074 }
14075
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014076remove_s_ssid:
14077 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
14078 sigma_dut_print(dut, DUT_MSG_ERROR,
14079 "Failed to delete vendor element");
14080
Jouni Malinen228a2fc2020-06-22 23:37:45 +030014081 if (ctrl) {
14082 if (status == SUCCESS_SEND_STATUS) {
14083 res = get_wpa_cli_event(dut, ctrl,
14084 "CTRL-EVENT-SCAN-RESULTS",
14085 buf, sizeof(buf));
14086 if (res < 0) {
14087 send_resp(dut, conn, SIGMA_ERROR,
14088 "ErrorCode,scan did not complete");
14089 status = STATUS_SENT_ERROR;
14090 }
14091 }
14092
14093 wpa_ctrl_detach(ctrl);
14094 wpa_ctrl_close(ctrl);
14095 }
14096
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080014097 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014098}
14099
14100
Jouni Malinenf7222712019-06-13 01:50:21 +030014101static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
14102 struct sigma_conn *conn,
14103 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020014104{
14105 const char *intf = get_param(cmd, "Interface");
14106 const char *bssid;
14107 char buf[4096], *pos;
14108 int freq, chan;
14109 char *ssid;
14110 char resp[100];
14111 int res;
14112 struct wpa_ctrl *ctrl;
14113
14114 bssid = get_param(cmd, "BSSID");
14115 if (!bssid) {
14116 send_resp(dut, conn, SIGMA_INVALID,
14117 "errorCode,BSSID argument is missing");
14118 return 0;
14119 }
14120
14121 ctrl = open_wpa_mon(intf);
14122 if (!ctrl) {
14123 sigma_dut_print(dut, DUT_MSG_ERROR,
14124 "Failed to open wpa_supplicant monitor connection");
14125 return -1;
14126 }
14127
14128 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
14129 send_resp(dut, conn, SIGMA_ERROR,
14130 "errorCode,Could not start scan");
14131 wpa_ctrl_detach(ctrl);
14132 wpa_ctrl_close(ctrl);
14133 return 0;
14134 }
14135
14136 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
14137 buf, sizeof(buf));
14138
14139 wpa_ctrl_detach(ctrl);
14140 wpa_ctrl_close(ctrl);
14141
14142 if (res < 0) {
14143 send_resp(dut, conn, SIGMA_ERROR,
14144 "errorCode,Scan did not complete");
14145 return 0;
14146 }
14147
14148 snprintf(buf, sizeof(buf), "BSS %s", bssid);
14149 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
14150 strncmp(buf, "id=", 3) != 0) {
14151 send_resp(dut, conn, SIGMA_ERROR,
14152 "errorCode,Specified BSSID not found");
14153 return 0;
14154 }
14155
14156 pos = strstr(buf, "\nfreq=");
14157 if (!pos) {
14158 send_resp(dut, conn, SIGMA_ERROR,
14159 "errorCode,Channel not found");
14160 return 0;
14161 }
14162 freq = atoi(pos + 6);
14163 chan = freq_to_channel(freq);
14164
14165 pos = strstr(buf, "\nssid=");
14166 if (!pos) {
14167 send_resp(dut, conn, SIGMA_ERROR,
14168 "errorCode,SSID not found");
14169 return 0;
14170 }
14171 ssid = pos + 6;
14172 pos = strchr(ssid, '\n');
14173 if (pos)
14174 *pos = '\0';
14175 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
14176 send_resp(dut, conn, SIGMA_COMPLETE, resp);
14177 return 0;
14178}
14179
14180
Jouni Malinenf7222712019-06-13 01:50:21 +030014181static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
14182 struct sigma_conn *conn,
14183 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014184{
14185#ifdef __linux__
14186 struct timeval tv;
14187 struct tm tm;
14188 time_t t;
14189 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053014190 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014191
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014192 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014193
14194 memset(&tm, 0, sizeof(tm));
14195 val = get_param(cmd, "seconds");
14196 if (val)
14197 tm.tm_sec = atoi(val);
14198 val = get_param(cmd, "minutes");
14199 if (val)
14200 tm.tm_min = atoi(val);
14201 val = get_param(cmd, "hours");
14202 if (val)
14203 tm.tm_hour = atoi(val);
14204 val = get_param(cmd, "date");
14205 if (val)
14206 tm.tm_mday = atoi(val);
14207 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053014208 if (val) {
14209 v = atoi(val);
14210 if (v < 1 || v > 12) {
14211 send_resp(dut, conn, SIGMA_INVALID,
14212 "errorCode,Invalid month");
14213 return 0;
14214 }
14215 tm.tm_mon = v - 1;
14216 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014217 val = get_param(cmd, "year");
14218 if (val) {
14219 int year = atoi(val);
14220#ifdef ANDROID
14221 if (year > 2035)
14222 year = 2035; /* years beyond 2035 not supported */
14223#endif /* ANDROID */
14224 tm.tm_year = year - 1900;
14225 }
14226 t = mktime(&tm);
14227 if (t == (time_t) -1) {
14228 send_resp(dut, conn, SIGMA_ERROR,
14229 "errorCode,Invalid date or time");
14230 return 0;
14231 }
14232
14233 memset(&tv, 0, sizeof(tv));
14234 tv.tv_sec = t;
14235
14236 if (settimeofday(&tv, NULL) < 0) {
14237 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
14238 strerror(errno));
14239 send_resp(dut, conn, SIGMA_ERROR,
14240 "errorCode,Failed to set time");
14241 return 0;
14242 }
14243
14244 return 1;
14245#endif /* __linux__ */
14246
14247 return -1;
14248}
14249
14250
Jouni Malinenf7222712019-06-13 01:50:21 +030014251static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
14252 struct sigma_conn *conn,
14253 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014254{
14255 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014256 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014257 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014258 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014259 int res;
14260 struct wpa_ctrl *ctrl;
14261
14262 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014263 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014264
14265 val = get_param(cmd, "ProdESSAssoc");
14266 if (val)
14267 prod_ess_assoc = atoi(val);
14268
14269 kill_dhcp_client(dut, intf);
14270 if (start_dhcp_client(dut, intf) < 0)
14271 return -2;
14272
14273 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
14274 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
14275 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014276 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014277 prod_ess_assoc ? "" : "-N",
14278 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014279 name ? "'" : "",
14280 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
14281 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014282
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053014283 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014284 if (run_hs20_osu(dut, buf) < 0) {
14285 FILE *f;
14286
14287 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
14288
14289 f = fopen("hs20-osu-client.res", "r");
14290 if (f) {
14291 char resp[400], res[300], *pos;
14292 if (!fgets(res, sizeof(res), f))
14293 res[0] = '\0';
14294 pos = strchr(res, '\n');
14295 if (pos)
14296 *pos = '\0';
14297 fclose(f);
14298 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
14299 res);
14300 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
14301 if (system(resp) != 0) {
14302 }
14303 snprintf(resp, sizeof(resp),
14304 "SSID,,BSSID,,failureReason,%s", res);
14305 send_resp(dut, conn, SIGMA_COMPLETE, resp);
14306 return 0;
14307 }
14308
14309 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
14310 return 0;
14311 }
14312
14313 if (!prod_ess_assoc)
14314 goto report;
14315
14316 ctrl = open_wpa_mon(intf);
14317 if (ctrl == NULL) {
14318 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14319 "wpa_supplicant monitor connection");
14320 return -1;
14321 }
14322
14323 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
14324 buf, sizeof(buf));
14325
14326 wpa_ctrl_detach(ctrl);
14327 wpa_ctrl_close(ctrl);
14328
14329 if (res < 0) {
14330 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
14331 "network after OSU");
14332 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
14333 return 0;
14334 }
14335
14336report:
14337 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
14338 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
14339 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
14340 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
14341 return 0;
14342 }
14343
14344 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
14345 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014346 return 0;
14347}
14348
14349
Jouni Malinenf7222712019-06-13 01:50:21 +030014350static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
14351 struct sigma_conn *conn,
14352 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014353{
14354 const char *val;
14355 int timeout = 120;
14356
14357 val = get_param(cmd, "PolicyUpdate");
14358 if (val == NULL || atoi(val) == 0)
14359 return 1; /* No operation requested */
14360
14361 val = get_param(cmd, "Timeout");
14362 if (val)
14363 timeout = atoi(val);
14364
14365 if (timeout) {
14366 /* TODO: time out the command and return
14367 * PolicyUpdateStatus,TIMEOUT if needed. */
14368 }
14369
14370 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
14371 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
14372 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
14373 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
14374 return 0;
14375 }
14376
14377 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
14378 return 0;
14379}
14380
14381
Jouni Malinenf7222712019-06-13 01:50:21 +030014382static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
14383 struct sigma_conn *conn,
14384 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014385{
14386 struct wpa_ctrl *ctrl;
14387 const char *intf = get_param(cmd, "Interface");
14388 const char *bssid = get_param(cmd, "Bssid");
14389 const char *ssid = get_param(cmd, "SSID");
14390 const char *security = get_param(cmd, "Security");
14391 const char *passphrase = get_param(cmd, "Passphrase");
14392 const char *pin = get_param(cmd, "PIN");
14393 char buf[1000];
14394 char ssid_hex[200], passphrase_hex[200];
14395 const char *keymgmt, *cipher;
14396
14397 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014398 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014399
14400 if (!bssid) {
14401 send_resp(dut, conn, SIGMA_ERROR,
14402 "ErrorCode,Missing Bssid argument");
14403 return 0;
14404 }
14405
14406 if (!ssid) {
14407 send_resp(dut, conn, SIGMA_ERROR,
14408 "ErrorCode,Missing SSID argument");
14409 return 0;
14410 }
14411
14412 if (!security) {
14413 send_resp(dut, conn, SIGMA_ERROR,
14414 "ErrorCode,Missing Security argument");
14415 return 0;
14416 }
14417
14418 if (!passphrase) {
14419 send_resp(dut, conn, SIGMA_ERROR,
14420 "ErrorCode,Missing Passphrase argument");
14421 return 0;
14422 }
14423
14424 if (!pin) {
14425 send_resp(dut, conn, SIGMA_ERROR,
14426 "ErrorCode,Missing PIN argument");
14427 return 0;
14428 }
14429
vamsi krishna8c9c1562017-05-12 15:51:46 +053014430 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
14431 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014432 send_resp(dut, conn, SIGMA_ERROR,
14433 "ErrorCode,Too long SSID/passphrase");
14434 return 0;
14435 }
14436
14437 ctrl = open_wpa_mon(intf);
14438 if (ctrl == NULL) {
14439 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14440 "wpa_supplicant monitor connection");
14441 return -2;
14442 }
14443
14444 if (strcasecmp(security, "wpa2-psk") == 0) {
14445 keymgmt = "WPA2PSK";
14446 cipher = "CCMP";
14447 } else {
14448 wpa_ctrl_detach(ctrl);
14449 wpa_ctrl_close(ctrl);
14450 send_resp(dut, conn, SIGMA_ERROR,
14451 "ErrorCode,Unsupported Security value");
14452 return 0;
14453 }
14454
14455 ascii2hexstr(ssid, ssid_hex);
14456 ascii2hexstr(passphrase, passphrase_hex);
14457 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
14458 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
14459
14460 if (wpa_command(intf, buf) < 0) {
14461 wpa_ctrl_detach(ctrl);
14462 wpa_ctrl_close(ctrl);
14463 send_resp(dut, conn, SIGMA_ERROR,
14464 "ErrorCode,Failed to start registrar");
14465 return 0;
14466 }
14467
14468 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
14469 dut->er_oper_performed = 1;
14470
14471 return wps_connection_event(dut, conn, ctrl, intf, 0);
14472}
14473
14474
Jouni Malinenf7222712019-06-13 01:50:21 +030014475static enum sigma_cmd_result
14476cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
14477 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014478{
14479 struct wpa_ctrl *ctrl;
14480 const char *intf = get_param(cmd, "Interface");
14481 const char *bssid = get_param(cmd, "Bssid");
14482 char buf[100];
14483
14484 if (!bssid) {
14485 send_resp(dut, conn, SIGMA_ERROR,
14486 "ErrorCode,Missing Bssid argument");
14487 return 0;
14488 }
14489
14490 ctrl = open_wpa_mon(intf);
14491 if (ctrl == NULL) {
14492 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14493 "wpa_supplicant monitor connection");
14494 return -2;
14495 }
14496
14497 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
14498
14499 if (wpa_command(intf, buf) < 0) {
14500 wpa_ctrl_detach(ctrl);
14501 wpa_ctrl_close(ctrl);
14502 send_resp(dut, conn, SIGMA_ERROR,
14503 "ErrorCode,Failed to start registrar");
14504 return 0;
14505 }
14506
14507 return wps_connection_event(dut, conn, ctrl, intf, 0);
14508}
14509
14510
Jouni Malinenf7222712019-06-13 01:50:21 +030014511static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
14512 struct sigma_conn *conn,
14513 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053014514{
14515 struct wpa_ctrl *ctrl;
14516 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014517 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014518 const char *config_method = get_param(cmd, "WPSConfigMethod");
14519 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053014520 int res;
14521 char buf[256];
14522 const char *events[] = {
14523 "CTRL-EVENT-CONNECTED",
14524 "WPS-OVERLAP-DETECTED",
14525 "WPS-TIMEOUT",
14526 "WPS-FAIL",
14527 NULL
14528 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014529 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053014530
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014531 /* 60G WPS tests do not pass Interface parameter */
14532 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014533 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014534
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014535 if (dut->mode == SIGMA_MODE_AP)
14536 return ap_wps_registration(dut, conn, cmd);
14537
14538 if (config_method) {
14539 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
14540 * sta_wps_enter_pin before calling start_wps_registration. */
14541 if (strcasecmp(config_method, "PBC") == 0)
14542 dut->wps_method = WFA_CS_WPS_PBC;
14543 }
14544 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
14545 send_resp(dut, conn, SIGMA_ERROR,
14546 "ErrorCode,WPS parameters not yet set");
14547 return STATUS_SENT;
14548 }
14549
14550 /* Make sure WPS is enabled (also for STA mode) */
14551 dut->wps_disable = 0;
14552
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014553 if (dut->band == WPS_BAND_60G && network_mode &&
14554 strcasecmp(network_mode, "PBSS") == 0) {
14555 sigma_dut_print(dut, DUT_MSG_DEBUG,
14556 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014557 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014558 return -2;
14559 }
14560
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020014561 if (dut->force_rsn_ie) {
14562 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
14563 dut->force_rsn_ie);
14564 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
14565 sigma_dut_print(dut, DUT_MSG_INFO,
14566 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014567 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020014568 }
14569 }
14570
vamsi krishna9b144002017-09-20 13:28:13 +053014571 ctrl = open_wpa_mon(intf);
14572 if (!ctrl) {
14573 sigma_dut_print(dut, DUT_MSG_ERROR,
14574 "Failed to open wpa_supplicant monitor connection");
14575 return -2;
14576 }
14577
14578 role = get_param(cmd, "WpsRole");
14579 if (!role) {
14580 send_resp(dut, conn, SIGMA_INVALID,
14581 "ErrorCode,WpsRole not provided");
14582 goto fail;
14583 }
14584
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014585 if (strcasecmp(role, "Enrollee") != 0) {
14586 /* Registrar role for STA not supported */
14587 send_resp(dut, conn, SIGMA_ERROR,
14588 "ErrorCode,Unsupported WpsRole value");
14589 goto fail;
14590 }
14591
14592 if (is_60g_sigma_dut(dut)) {
14593 if (dut->wps_method == WFA_CS_WPS_PBC)
14594 snprintf(buf, sizeof(buf), "WPS_PBC");
14595 else /* WFA_CS_WPS_PIN_KEYPAD */
14596 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
14597 dut->wps_pin);
14598 if (wpa_command(intf, buf) < 0) {
14599 send_resp(dut, conn, SIGMA_ERROR,
14600 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053014601 goto fail;
14602 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014603 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
14604 if (res < 0) {
14605 send_resp(dut, conn, SIGMA_ERROR,
14606 "ErrorCode,WPS connection did not complete");
14607 goto fail;
14608 }
14609 if (strstr(buf, "WPS-TIMEOUT")) {
14610 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
14611 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
14612 send_resp(dut, conn, SIGMA_COMPLETE,
14613 "WpsState,OverlapSession");
14614 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
14615 send_resp(dut, conn, SIGMA_COMPLETE,
14616 "WpsState,Successful");
14617 } else {
14618 send_resp(dut, conn, SIGMA_COMPLETE,
14619 "WpsState,Failure");
14620 }
14621 } else {
14622 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053014623 if (wpa_command(intf, "WPS_PBC") < 0) {
14624 send_resp(dut, conn, SIGMA_ERROR,
14625 "ErrorCode,Failed to enable PBC");
14626 goto fail;
14627 }
14628 } else {
14629 /* TODO: PIN method */
14630 send_resp(dut, conn, SIGMA_ERROR,
14631 "ErrorCode,Unsupported WpsConfigMethod value");
14632 goto fail;
14633 }
14634 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
14635 if (res < 0) {
14636 send_resp(dut, conn, SIGMA_ERROR,
14637 "ErrorCode,WPS connection did not complete");
14638 goto fail;
14639 }
14640 if (strstr(buf, "WPS-TIMEOUT")) {
14641 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
14642 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
14643 send_resp(dut, conn, SIGMA_ERROR,
14644 "ErrorCode,OverlapSession");
14645 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
14646 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
14647 } else {
14648 send_resp(dut, conn, SIGMA_ERROR,
14649 "ErrorCode,WPS operation failed");
14650 }
vamsi krishna9b144002017-09-20 13:28:13 +053014651 }
14652
14653fail:
14654 wpa_ctrl_detach(ctrl);
14655 wpa_ctrl_close(ctrl);
14656 return 0;
14657}
14658
14659
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014660static int req_intf(struct sigma_cmd *cmd)
14661{
14662 return get_param(cmd, "interface") == NULL ? -1 : 0;
14663}
14664
14665
14666void sta_register_cmds(void)
14667{
14668 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
14669 cmd_sta_get_ip_config);
14670 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
14671 cmd_sta_set_ip_config);
14672 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
14673 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
14674 cmd_sta_get_mac_address);
14675 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
14676 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
14677 cmd_sta_verify_ip_connection);
14678 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
14679 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
14680 cmd_sta_set_encryption);
14681 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
14682 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
14683 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
14684 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
14685 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
14686 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
14687 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
14688 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
14689 cmd_sta_set_eapakaprime);
14690 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
14691 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
14692 /* TODO: sta_set_ibss */
14693 /* TODO: sta_set_mode */
14694 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
14695 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
14696 /* TODO: sta_up_load */
14697 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
14698 cmd_sta_preset_testparameters);
14699 /* TODO: sta_set_system */
14700 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
14701 /* TODO: sta_set_rifs_test */
14702 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
14703 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
14704 /* TODO: sta_send_coexist_mgmt */
14705 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
14706 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
14707 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
14708 sigma_dut_reg_cmd("sta_reset_default", req_intf,
14709 cmd_sta_reset_default);
14710 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
14711 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
14712 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
14713 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
14714 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014715 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014716 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
14717 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
14718 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
14719 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
14720 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030014721 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
14722 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014723 sigma_dut_reg_cmd("sta_add_credential", req_intf,
14724 cmd_sta_add_credential);
14725 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020014726 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014727 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
14728 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
14729 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
14730 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
14731 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
14732 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030014733 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014734 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
14735 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014736 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053014737 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014738}