blob: f1eb3ad6ea1f50cbfa7b0c059544387bfc1d6d13 [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
Veerendranath Jakkam54fd51c2020-12-21 01:36:04 +05302103 if (dut->ocvc && set_network(ifname, id, "ocv", "1") < 0)
2104 return ERROR_SEND_STATUS;
2105
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002106 return id;
2107}
2108
2109
Jouni Malinenf7222712019-06-13 01:50:21 +03002110static enum sigma_cmd_result cmd_sta_set_psk(struct sigma_dut *dut,
2111 struct sigma_conn *conn,
2112 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002113{
2114 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002115 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002116 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002117 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002118 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002119 const char *ifname, *val, *alg;
2120 int id;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002121 char buf[50];
Jouni Malinen11e55212019-11-22 21:46:59 +02002122 int sae_pwe = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002123
2124 if (intf == NULL)
2125 return -1;
2126
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002127 if (strcmp(intf, get_main_ifname(dut)) == 0)
2128 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002129 else
2130 ifname = intf;
2131
2132 id = set_wpa_common(dut, conn, ifname, cmd);
2133 if (id < 0)
2134 return id;
2135
2136 val = get_param(cmd, "keyMgmtType");
2137 alg = get_param(cmd, "micAlg");
2138
Jouni Malinen992a81e2017-08-22 13:57:47 +03002139 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002140 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002141 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2142 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002143 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002144 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2145 return -2;
2146 }
2147 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2148 sigma_dut_print(dut, DUT_MSG_ERROR,
2149 "Failed to clear sae_groups to default");
2150 return -2;
2151 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002152 if (!pmf) {
2153 dut->sta_pmf = STA_PMF_REQUIRED;
2154 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2155 return -2;
2156 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002157 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2158 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2159 if (set_network(ifname, id, "key_mgmt",
2160 "FT-SAE FT-PSK") < 0)
2161 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002162 } else if (!akm) {
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002163 if (set_network(ifname, id, "key_mgmt",
2164 "SAE WPA-PSK") < 0)
2165 return -2;
2166 }
2167 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2168 sigma_dut_print(dut, DUT_MSG_ERROR,
2169 "Failed to clear sae_groups to default");
2170 return -2;
2171 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002172 if (!pmf) {
2173 dut->sta_pmf = STA_PMF_OPTIONAL;
2174 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2175 return -2;
2176 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002177 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002178 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2179 return -2;
2180 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2181 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2182 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302183 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2184 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2185 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002186 } else if (!akm &&
2187 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2188 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002189 if (set_network(ifname, id, "key_mgmt",
2190 "WPA-PSK WPA-PSK-SHA256") < 0)
2191 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002192 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002193 if (set_network(ifname, id, "key_mgmt",
2194 "WPA-PSK WPA-PSK-SHA256") < 0)
2195 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002196 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002197 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2198 return -2;
2199 }
2200
2201 val = get_param(cmd, "passPhrase");
2202 if (val == NULL)
2203 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002204 if (type && strcasecmp(type, "SAE") == 0) {
2205 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2206 return -2;
2207 } else {
2208 if (set_network_quoted(ifname, id, "psk", val) < 0)
2209 return -2;
2210 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002211
Jouni Malinen78d10c42019-03-25 22:34:32 +02002212 val = get_param(cmd, "PasswordId");
2213 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2214 return ERROR_SEND_STATUS;
2215
Jouni Malinen992a81e2017-08-22 13:57:47 +03002216 val = get_param(cmd, "ECGroupID");
2217 if (val) {
Jouni Malinenb54f0df2019-12-12 01:57:29 +02002218 snprintf(buf, sizeof(buf), "SET sae_groups %s", val);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002219 if (wpa_command(ifname, buf) != 0) {
2220 sigma_dut_print(dut, DUT_MSG_ERROR,
2221 "Failed to clear sae_groups");
2222 return -2;
2223 }
2224 }
2225
Jouni Malinen68143132017-09-02 02:34:08 +03002226 val = get_param(cmd, "InvalidSAEElement");
2227 if (val) {
2228 free(dut->sae_commit_override);
2229 dut->sae_commit_override = strdup(val);
2230 }
2231
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002232 val = get_param(cmd, "PMKID_Include");
2233 if (val) {
2234 snprintf(buf, sizeof(buf), "SET sae_pmkid_in_assoc %d",
2235 get_enable_disable(val));
2236 wpa_command(intf, buf);
2237 }
2238
Jouni Malineneeb43d32019-12-06 17:40:07 +02002239 val = get_param(cmd, "IgnoreH2E_RSNXE_BSSMemSel");
2240 if (val) {
2241 snprintf(buf, sizeof(buf), "SET ignore_sae_h2e_only %d",
2242 get_enable_disable(val));
2243 wpa_command(intf, buf);
2244 }
2245
Jouni Malinenf2348d22019-12-07 11:52:55 +02002246 val = get_param(cmd, "ECGroupID_RGE");
2247 if (val) {
2248 snprintf(buf, sizeof(buf), "SET extra_sae_rejected_groups %s",
2249 val);
2250 wpa_command(intf, buf);
2251 }
2252
Jouni Malinen99e55022019-12-07 13:59:41 +02002253 val = get_param(cmd, "RSNXE_Content");
2254 if (val) {
2255 const char *param;
2256
2257 if (strncasecmp(val, "AssocReq:", 9) == 0) {
2258 val += 9;
2259 param = "rsnxe_override_assoc";
2260 } else if (strncasecmp(val, "EapolM2:", 8) == 0) {
2261 val += 8;
2262 param = "rsnxe_override_eapol";
2263 } else {
2264 send_resp(dut, conn, SIGMA_ERROR,
2265 "errorCode,Unsupported RSNXE_Content value");
2266 return STATUS_SENT_ERROR;
2267 }
2268 snprintf(buf, sizeof(buf), "SET %s %s", param, val);
2269 wpa_command(intf, buf);
2270 }
2271
Jouni Malinen11e55212019-11-22 21:46:59 +02002272 val = get_param(cmd, "sae_pwe");
2273 if (val) {
2274 if (strcasecmp(val, "h2e") == 0) {
2275 dut->sae_pwe = SAE_PWE_H2E;
Jouni Malinen7244a412019-12-07 11:54:10 +02002276 } else if (strcasecmp(val, "loop") == 0 ||
2277 strcasecmp(val, "looping") == 0) {
Jouni Malinen11e55212019-11-22 21:46:59 +02002278 dut->sae_pwe = SAE_PWE_LOOP;
2279 } else {
2280 send_resp(dut, conn, SIGMA_ERROR,
2281 "errorCode,Unsupported sae_pwe value");
2282 return STATUS_SENT_ERROR;
2283 }
2284 }
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302285
2286 val = get_param(cmd, "Clear_RSNXE");
2287 if (val && strcmp(val, "1") == 0 &&
2288 (wpa_command(intf, "SET rsnxe_override_assoc ") ||
2289 wpa_command(intf, "SET rsnxe_override_eapol "))) {
2290 send_resp(dut, conn, SIGMA_ERROR,
2291 "errorCode,Failed to clear RSNXE");
Jouni Malinenb11498c2020-08-03 11:05:53 +03002292 return STATUS_SENT_ERROR;
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302293 }
2294
Jouni Malinenc0078772020-03-04 21:23:16 +02002295 if (dut->sae_pwe == SAE_PWE_LOOP && get_param(cmd, "PasswordId"))
2296 sae_pwe = 3;
2297 else if (dut->sae_pwe == SAE_PWE_LOOP)
Jouni Malinen11e55212019-11-22 21:46:59 +02002298 sae_pwe = 0;
2299 else if (dut->sae_pwe == SAE_PWE_H2E)
2300 sae_pwe = 1;
2301 else if (dut->sae_h2e_default)
2302 sae_pwe = 2;
2303 snprintf(buf, sizeof(buf), "SET sae_pwe %d", sae_pwe);
2304 if (sae_pwe >= 0 && wpa_command(ifname, buf) != 0)
2305 return ERROR_SEND_STATUS;
2306
Veerendranath Jakkam0316be12020-06-23 20:11:41 +05302307 val = get_param(cmd, "sae_pk");
2308 if (val && strcmp(val, "0") == 0 &&
2309 set_network(ifname, id, "sae_pk", "2") < 0)
2310 return ERROR_SEND_STATUS;
2311
Veerendranath Jakkama9177042020-08-10 00:14:03 +05302312 val = get_param(cmd, "sae_pk_only");
2313 if (val && strcmp(val, "1") == 0 &&
2314 set_network(ifname, id, "sae_pk", "1") < 0)
2315 return ERROR_SEND_STATUS;
2316
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002317 if (dut->program == PROGRAM_60GHZ && network_mode &&
2318 strcasecmp(network_mode, "PBSS") == 0 &&
2319 set_network(ifname, id, "pbss", "1") < 0)
2320 return -2;
2321
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002322 return 1;
2323}
2324
2325
Jouni Malinen8ac93452019-08-14 15:19:13 +03002326static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2327 struct sigma_conn *conn,
2328 const char *ifname, int id)
2329{
2330 char buf[200];
2331
2332 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2333 if (!file_exists(buf))
2334 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2335 if (!file_exists(buf))
2336 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2337 if (!file_exists(buf)) {
2338 char msg[300];
2339
2340 snprintf(msg, sizeof(msg),
2341 "ErrorCode,trustedRootCA system store (%s) not found",
2342 buf);
2343 send_resp(dut, conn, SIGMA_ERROR, msg);
2344 return STATUS_SENT_ERROR;
2345 }
2346
2347 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2348 return ERROR_SEND_STATUS;
2349
2350 return SUCCESS_SEND_STATUS;
2351}
2352
2353
2354static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2355 struct sigma_conn *conn,
2356 const char *ifname, int id,
2357 const char *val)
2358{
2359 char buf[200];
2360#ifdef ANDROID
2361 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2362 int length;
2363#endif /* ANDROID */
2364
2365 if (strcmp(val, "DEFAULT") == 0)
2366 return set_trust_root_system(dut, conn, ifname, id);
2367
2368#ifdef ANDROID
2369 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2370 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2371 if (length > 0) {
2372 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2373 buf);
2374 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2375 goto ca_cert_selected;
2376 }
2377#endif /* ANDROID */
2378
2379 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2380#ifdef __linux__
2381 if (!file_exists(buf)) {
2382 char msg[300];
2383
2384 snprintf(msg, sizeof(msg),
2385 "ErrorCode,trustedRootCA file (%s) not found", buf);
2386 send_resp(dut, conn, SIGMA_ERROR, msg);
2387 return STATUS_SENT_ERROR;
2388 }
2389#endif /* __linux__ */
2390#ifdef ANDROID
2391ca_cert_selected:
2392#endif /* ANDROID */
2393 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2394 return ERROR_SEND_STATUS;
2395
2396 return SUCCESS_SEND_STATUS;
2397}
2398
2399
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002400static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302401 const char *ifname, int username_identity,
2402 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002403{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002404 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002405 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002406 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002407 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002408 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002409
2410 id = set_wpa_common(dut, conn, ifname, cmd);
2411 if (id < 0)
2412 return id;
2413
2414 val = get_param(cmd, "keyMgmtType");
2415 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302416 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002417 trust_root = get_param(cmd, "trustedRootCA");
2418 domain = get_param(cmd, "Domain");
2419 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002420
Jouni Malinenad395a22017-09-01 21:13:46 +03002421 if (val && strcasecmp(val, "SuiteB") == 0) {
2422 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2423 0)
2424 return -2;
2425 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002426 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2427 return -2;
2428 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2429 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2430 return -2;
2431 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2432 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2433 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002434 } else if (!akm &&
2435 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2436 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002437 if (set_network(ifname, id, "key_mgmt",
2438 "WPA-EAP WPA-EAP-SHA256") < 0)
2439 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302440 } else if (akm && atoi(akm) == 14) {
2441 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2442 dut->sta_pmf == STA_PMF_REQUIRED) {
2443 if (set_network(ifname, id, "key_mgmt",
2444 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2445 return -2;
2446 } else {
2447 if (set_network(ifname, id, "key_mgmt",
2448 "WPA-EAP FILS-SHA256") < 0)
2449 return -2;
2450 }
2451
Jouni Malinen8179fee2019-03-28 03:19:47 +02002452 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302453 } else if (akm && atoi(akm) == 15) {
2454 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2455 dut->sta_pmf == STA_PMF_REQUIRED) {
2456 if (set_network(ifname, id, "key_mgmt",
2457 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2458 return -2;
2459 } else {
2460 if (set_network(ifname, id, "key_mgmt",
2461 "WPA-EAP FILS-SHA384") < 0)
2462 return -2;
2463 }
2464
Jouni Malinen8179fee2019-03-28 03:19:47 +02002465 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002466 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002467 if (set_network(ifname, id, "key_mgmt",
2468 "WPA-EAP WPA-EAP-SHA256") < 0)
2469 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002470 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002471 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2472 return -2;
2473 }
2474
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002475 if (trust_root) {
2476 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2477 !domain_suffix) {
2478 send_resp(dut, conn, SIGMA_ERROR,
2479 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2480 return STATUS_SENT_ERROR;
2481 }
2482 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002483 if (res != SUCCESS_SEND_STATUS)
2484 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002485 }
2486
Jouni Malinen53264f62019-05-03 13:04:40 +03002487 val = get_param(cmd, "ServerCert");
2488 if (val) {
2489 FILE *f;
2490 char *result = NULL, *pos;
2491
2492 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2493 val);
2494 f = fopen(buf, "r");
2495 if (f) {
2496 result = fgets(buf, sizeof(buf), f);
2497 fclose(f);
2498 }
2499 if (!result) {
2500 snprintf(buf2, sizeof(buf2),
2501 "ErrorCode,ServerCert hash could not be read from %s",
2502 buf);
2503 send_resp(dut, conn, SIGMA_ERROR, buf2);
2504 return STATUS_SENT_ERROR;
2505 }
2506 pos = strchr(buf, '\n');
2507 if (pos)
2508 *pos = '\0';
Jouni Malinen0572a742020-10-08 13:53:25 +03002509 pos = strchr(buf, '\r');
2510 if (pos)
2511 *pos = '\0';
Jouni Malinen53264f62019-05-03 13:04:40 +03002512 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2513 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2514 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002515
2516 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2517 if (file_exists(buf)) {
2518 sigma_dut_print(dut, DUT_MSG_DEBUG,
2519 "TOD policy enabled for the configured ServerCert hash");
2520 dut->sta_tod_policy = 1;
2521 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002522 }
2523
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002524 if (domain &&
2525 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002526 return ERROR_SEND_STATUS;
2527
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002528 if (domain_suffix &&
2529 set_network_quoted(ifname, id, "domain_suffix_match",
2530 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002531 return ERROR_SEND_STATUS;
2532
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302533 if (username_identity) {
2534 val = get_param(cmd, "username");
2535 if (val) {
2536 if (set_network_quoted(ifname, id, "identity", val) < 0)
2537 return -2;
2538 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002539
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302540 val = get_param(cmd, "password");
2541 if (val) {
2542 if (set_network_quoted(ifname, id, "password", val) < 0)
2543 return -2;
2544 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002545 }
2546
Jouni Malinen8179fee2019-03-28 03:19:47 +02002547 if (dut->akm_values &
2548 ((1 << AKM_FILS_SHA256) |
2549 (1 << AKM_FILS_SHA384) |
2550 (1 << AKM_FT_FILS_SHA256) |
2551 (1 << AKM_FT_FILS_SHA384)))
2552 erp = 1;
2553 if (erp && set_network(ifname, id, "erp", "1") < 0)
2554 return ERROR_SEND_STATUS;
2555
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002556 dut->sta_associate_wait_connect = 1;
2557
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002558 return id;
2559}
2560
2561
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002562static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2563{
2564 const char *val;
2565
2566 if (!cipher)
2567 return 0;
2568
2569 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2570 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2571 else if (strcasecmp(cipher,
2572 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2573 val = "ECDHE-RSA-AES256-GCM-SHA384";
2574 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2575 val = "DHE-RSA-AES256-GCM-SHA384";
2576 else if (strcasecmp(cipher,
2577 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2578 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2579 else
2580 return -1;
2581
2582 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2583 set_network_quoted(ifname, id, "phase1", "");
2584
2585 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2586}
2587
2588
Jouni Malinenf7222712019-06-13 01:50:21 +03002589static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2590 struct sigma_conn *conn,
2591 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002592{
2593 const char *intf = get_param(cmd, "Interface");
2594 const char *ifname, *val;
2595 int id;
2596 char buf[200];
2597#ifdef ANDROID
2598 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2599 int length;
2600 int jb_or_newer = 0;
2601 char prop[PROPERTY_VALUE_MAX];
2602#endif /* ANDROID */
2603
2604 if (intf == NULL)
2605 return -1;
2606
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002607 if (strcmp(intf, get_main_ifname(dut)) == 0)
2608 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002609 else
2610 ifname = intf;
2611
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302612 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002613 if (id < 0)
2614 return id;
2615
2616 if (set_network(ifname, id, "eap", "TLS") < 0)
2617 return -2;
2618
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302619 if (!get_param(cmd, "username") &&
2620 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002621 "wifi-user@wifilabs.local") < 0)
2622 return -2;
2623
2624 val = get_param(cmd, "clientCertificate");
2625 if (val == NULL)
2626 return -1;
2627#ifdef ANDROID
2628 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2629 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2630 if (length < 0) {
2631 /*
2632 * JB started reporting keystore type mismatches, so retry with
2633 * the GET_PUBKEY command if the generic GET fails.
2634 */
2635 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2636 buf, kvalue);
2637 }
2638
2639 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2640 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2641 if (strncmp(prop, "4.0", 3) != 0)
2642 jb_or_newer = 1;
2643 } else
2644 jb_or_newer = 1; /* assume newer */
2645
2646 if (jb_or_newer && length > 0) {
2647 sigma_dut_print(dut, DUT_MSG_INFO,
2648 "Use Android keystore [%s]", buf);
2649 if (set_network(ifname, id, "engine", "1") < 0)
2650 return -2;
2651 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2652 return -2;
2653 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2654 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2655 return -2;
2656 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2657 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2658 return -2;
2659 return 1;
2660 } else if (length > 0) {
2661 sigma_dut_print(dut, DUT_MSG_INFO,
2662 "Use Android keystore [%s]", buf);
2663 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2664 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2665 return -2;
2666 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2667 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2668 return -2;
2669 return 1;
2670 }
2671#endif /* ANDROID */
2672
2673 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2674#ifdef __linux__
2675 if (!file_exists(buf)) {
2676 char msg[300];
2677 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2678 "(%s) not found", buf);
2679 send_resp(dut, conn, SIGMA_ERROR, msg);
2680 return -3;
2681 }
2682#endif /* __linux__ */
2683 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2684 return -2;
2685 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2686 return -2;
2687
2688 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2689 return -2;
2690
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002691 val = get_param(cmd, "keyMgmtType");
2692 if (val && strcasecmp(val, "SuiteB") == 0) {
2693 val = get_param(cmd, "CertType");
2694 if (val && strcasecmp(val, "RSA") == 0) {
2695 if (set_network_quoted(ifname, id, "phase1",
2696 "tls_suiteb=1") < 0)
2697 return -2;
2698 } else {
2699 if (set_network_quoted(ifname, id, "openssl_ciphers",
2700 "SUITEB192") < 0)
2701 return -2;
2702 }
2703
2704 val = get_param(cmd, "TLSCipher");
2705 if (set_tls_cipher(ifname, id, val) < 0) {
2706 send_resp(dut, conn, SIGMA_ERROR,
2707 "ErrorCode,Unsupported TLSCipher value");
2708 return -3;
2709 }
2710 }
2711
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002712 return 1;
2713}
2714
2715
Jouni Malinenf7222712019-06-13 01:50:21 +03002716static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2717 struct sigma_conn *conn,
2718 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002719{
2720 const char *intf = get_param(cmd, "Interface");
2721 const char *ifname;
2722 int id;
2723
2724 if (intf == NULL)
2725 return -1;
2726
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002727 if (strcmp(intf, get_main_ifname(dut)) == 0)
2728 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002729 else
2730 ifname = intf;
2731
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302732 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002733 if (id < 0)
2734 return id;
2735
2736 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2737 send_resp(dut, conn, SIGMA_ERROR,
2738 "errorCode,Failed to set TTLS method");
2739 return 0;
2740 }
2741
2742 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2743 send_resp(dut, conn, SIGMA_ERROR,
2744 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2745 return 0;
2746 }
2747
2748 return 1;
2749}
2750
2751
Jouni Malinenf7222712019-06-13 01:50:21 +03002752static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2753 struct sigma_conn *conn,
2754 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002755{
2756 const char *intf = get_param(cmd, "Interface");
2757 const char *ifname;
2758 int id;
2759
2760 if (intf == NULL)
2761 return -1;
2762
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002763 if (strcmp(intf, get_main_ifname(dut)) == 0)
2764 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002765 else
2766 ifname = intf;
2767
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302768 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002769 if (id < 0)
2770 return id;
2771
2772 if (set_network(ifname, id, "eap", "SIM") < 0)
2773 return -2;
2774
2775 return 1;
2776}
2777
2778
Jouni Malinenf7222712019-06-13 01:50:21 +03002779static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2780 struct sigma_conn *conn,
2781 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002782{
2783 const char *intf = get_param(cmd, "Interface");
2784 const char *ifname, *val;
2785 int id;
2786 char buf[100];
2787
2788 if (intf == NULL)
2789 return -1;
2790
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002791 if (strcmp(intf, get_main_ifname(dut)) == 0)
2792 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002793 else
2794 ifname = intf;
2795
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302796 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002797 if (id < 0)
2798 return id;
2799
2800 if (set_network(ifname, id, "eap", "PEAP") < 0)
2801 return -2;
2802
2803 val = get_param(cmd, "innerEAP");
2804 if (val) {
2805 if (strcasecmp(val, "MSCHAPv2") == 0) {
2806 if (set_network_quoted(ifname, id, "phase2",
2807 "auth=MSCHAPV2") < 0)
2808 return -2;
2809 } else if (strcasecmp(val, "GTC") == 0) {
2810 if (set_network_quoted(ifname, id, "phase2",
2811 "auth=GTC") < 0)
2812 return -2;
2813 } else
2814 return -1;
2815 }
2816
2817 val = get_param(cmd, "peapVersion");
2818 if (val) {
2819 int ver = atoi(val);
2820 if (ver < 0 || ver > 1)
2821 return -1;
2822 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2823 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2824 return -2;
2825 }
2826
2827 return 1;
2828}
2829
2830
Jouni Malinenf7222712019-06-13 01:50:21 +03002831static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2832 struct sigma_conn *conn,
2833 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002834{
2835 const char *intf = get_param(cmd, "Interface");
2836 const char *ifname, *val;
2837 int id;
2838 char buf[100];
2839
2840 if (intf == NULL)
2841 return -1;
2842
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002843 if (strcmp(intf, get_main_ifname(dut)) == 0)
2844 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002845 else
2846 ifname = intf;
2847
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302848 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002849 if (id < 0)
2850 return id;
2851
2852 if (set_network(ifname, id, "eap", "FAST") < 0)
2853 return -2;
2854
2855 val = get_param(cmd, "innerEAP");
2856 if (val) {
2857 if (strcasecmp(val, "MSCHAPV2") == 0) {
2858 if (set_network_quoted(ifname, id, "phase2",
2859 "auth=MSCHAPV2") < 0)
2860 return -2;
2861 } else if (strcasecmp(val, "GTC") == 0) {
2862 if (set_network_quoted(ifname, id, "phase2",
2863 "auth=GTC") < 0)
2864 return -2;
2865 } else
2866 return -1;
2867 }
2868
2869 val = get_param(cmd, "validateServer");
2870 if (val) {
2871 /* TODO */
2872 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2873 "validateServer=%s", val);
2874 }
2875
2876 val = get_param(cmd, "pacFile");
2877 if (val) {
2878 snprintf(buf, sizeof(buf), "blob://%s", val);
2879 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2880 return -2;
2881 }
2882
2883 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2884 0)
2885 return -2;
2886
2887 return 1;
2888}
2889
2890
Jouni Malinenf7222712019-06-13 01:50:21 +03002891static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2892 struct sigma_conn *conn,
2893 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002894{
2895 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302896 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002897 const char *ifname;
2898 int id;
2899
2900 if (intf == NULL)
2901 return -1;
2902
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002903 if (strcmp(intf, get_main_ifname(dut)) == 0)
2904 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002905 else
2906 ifname = intf;
2907
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302908 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002909 if (id < 0)
2910 return id;
2911
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302912 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2913 * hexadecimal).
2914 */
2915 if (username && username[0] == '6') {
2916 if (set_network(ifname, id, "eap", "AKA'") < 0)
2917 return -2;
2918 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002919 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302920 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002921
2922 return 1;
2923}
2924
2925
Jouni Malinenf7222712019-06-13 01:50:21 +03002926static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2927 struct sigma_conn *conn,
2928 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002929{
2930 const char *intf = get_param(cmd, "Interface");
2931 const char *ifname;
2932 int id;
2933
2934 if (intf == NULL)
2935 return -1;
2936
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002937 if (strcmp(intf, get_main_ifname(dut)) == 0)
2938 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002939 else
2940 ifname = intf;
2941
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302942 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002943 if (id < 0)
2944 return id;
2945
2946 if (set_network(ifname, id, "eap", "AKA'") < 0)
2947 return -2;
2948
2949 return 1;
2950}
2951
2952
2953static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2954 struct sigma_cmd *cmd)
2955{
2956 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002957 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002958 const char *ifname;
2959 int id;
2960
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002961 if (strcmp(intf, get_main_ifname(dut)) == 0)
2962 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002963 else
2964 ifname = intf;
2965
2966 id = add_network_common(dut, conn, ifname, cmd);
2967 if (id < 0)
2968 return id;
2969
2970 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2971 return -2;
2972
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002973 if (dut->program == PROGRAM_60GHZ && network_mode &&
2974 strcasecmp(network_mode, "PBSS") == 0 &&
2975 set_network(ifname, id, "pbss", "1") < 0)
2976 return -2;
2977
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002978 return 1;
2979}
2980
2981
Jouni Malinen8e3f8812020-10-05 10:02:03 +03002982static enum sigma_cmd_result sta_set_owe(struct sigma_dut *dut,
2983 struct sigma_conn *conn,
2984 struct sigma_cmd *cmd)
Jouni Malinen47dcc952017-10-09 16:43:24 +03002985{
2986 const char *intf = get_param(cmd, "Interface");
2987 const char *ifname, *val;
2988 int id;
2989
2990 if (intf == NULL)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03002991 return INVALID_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03002992
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002993 if (strcmp(intf, get_main_ifname(dut)) == 0)
2994 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002995 else
2996 ifname = intf;
2997
2998 id = set_wpa_common(dut, conn, ifname, cmd);
2999 if (id < 0)
3000 return id;
3001
3002 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003003 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003004
Hu Wangdd5eed22020-07-16 12:18:03 +08003005 if (dut->owe_ptk_workaround &&
3006 set_network(ifname, id, "owe_ptk_workaround", "1") < 0) {
3007 sigma_dut_print(dut, DUT_MSG_ERROR,
3008 "Failed to set owe_ptk_workaround to 1");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003009 return ERROR_SEND_STATUS;
Hu Wangdd5eed22020-07-16 12:18:03 +08003010 }
3011
Jouni Malinen47dcc952017-10-09 16:43:24 +03003012 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003013 if (val && strcmp(val, "0") == 0) {
3014 if (wpa_command(ifname,
3015 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
3016 sigma_dut_print(dut, DUT_MSG_ERROR,
3017 "Failed to set OWE DH Param element override");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003018 return ERROR_SEND_STATUS;
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003019 }
Hu Wangdd5eed22020-07-16 12:18:03 +08003020 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003021 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003022 "Failed to set owe_group");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003023 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003024 }
3025
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003026 return SUCCESS_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003027}
3028
3029
Jouni Malinenf7222712019-06-13 01:50:21 +03003030static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3031 struct sigma_conn *conn,
3032 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003033{
3034 const char *type = get_param(cmd, "Type");
3035
3036 if (type == NULL) {
3037 send_resp(dut, conn, SIGMA_ERROR,
3038 "ErrorCode,Missing Type argument");
3039 return 0;
3040 }
3041
3042 if (strcasecmp(type, "OPEN") == 0)
3043 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003044 if (strcasecmp(type, "OWE") == 0)
3045 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003046 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003047 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003048 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003049 return cmd_sta_set_psk(dut, conn, cmd);
3050 if (strcasecmp(type, "EAPTLS") == 0)
3051 return cmd_sta_set_eaptls(dut, conn, cmd);
3052 if (strcasecmp(type, "EAPTTLS") == 0)
3053 return cmd_sta_set_eapttls(dut, conn, cmd);
3054 if (strcasecmp(type, "EAPPEAP") == 0)
3055 return cmd_sta_set_peap(dut, conn, cmd);
3056 if (strcasecmp(type, "EAPSIM") == 0)
3057 return cmd_sta_set_eapsim(dut, conn, cmd);
3058 if (strcasecmp(type, "EAPFAST") == 0)
3059 return cmd_sta_set_eapfast(dut, conn, cmd);
3060 if (strcasecmp(type, "EAPAKA") == 0)
3061 return cmd_sta_set_eapaka(dut, conn, cmd);
3062 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3063 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003064 if (strcasecmp(type, "wep") == 0)
3065 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003066
3067 send_resp(dut, conn, SIGMA_ERROR,
3068 "ErrorCode,Unsupported Type value");
3069 return 0;
3070}
3071
3072
3073int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3074{
3075#ifdef __linux__
3076 /* special handling for ath6kl */
3077 char path[128], fname[128], *pos;
3078 ssize_t res;
3079 FILE *f;
3080
Jouni Malinene39cd562019-05-29 23:39:56 +03003081 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3082 intf);
3083 if (res < 0 || res >= sizeof(fname))
3084 return 0;
3085 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003086 if (res < 0)
3087 return 0; /* not ath6kl */
3088
3089 if (res >= (int) sizeof(path))
3090 res = sizeof(path) - 1;
3091 path[res] = '\0';
3092 pos = strrchr(path, '/');
3093 if (pos == NULL)
3094 pos = path;
3095 else
3096 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003097 res = snprintf(fname, sizeof(fname),
3098 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3099 "create_qos", pos);
3100 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003101 return 0; /* not ath6kl */
3102
3103 if (uapsd) {
3104 f = fopen(fname, "w");
3105 if (f == NULL)
3106 return -1;
3107
3108 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3109 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3110 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3111 "20000 0\n");
3112 fclose(f);
3113 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003114 res = snprintf(fname, sizeof(fname),
3115 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3116 "delete_qos", pos);
3117 if (res < 0 || res >= sizeof(fname))
3118 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003119
3120 f = fopen(fname, "w");
3121 if (f == NULL)
3122 return -1;
3123
3124 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3125 fprintf(f, "2 4\n");
3126 fclose(f);
3127 }
3128#endif /* __linux__ */
3129
3130 return 0;
3131}
3132
3133
Jouni Malinenf7222712019-06-13 01:50:21 +03003134static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3135 struct sigma_conn *conn,
3136 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003137{
3138 const char *intf = get_param(cmd, "Interface");
3139 /* const char *ssid = get_param(cmd, "ssid"); */
3140 const char *val;
3141 int max_sp_len = 4;
3142 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3143 char buf[100];
3144 int ret1, ret2;
3145
3146 val = get_param(cmd, "maxSPLength");
3147 if (val) {
3148 max_sp_len = atoi(val);
3149 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3150 max_sp_len != 4)
3151 return -1;
3152 }
3153
3154 val = get_param(cmd, "acBE");
3155 if (val)
3156 ac_be = atoi(val);
3157
3158 val = get_param(cmd, "acBK");
3159 if (val)
3160 ac_bk = atoi(val);
3161
3162 val = get_param(cmd, "acVI");
3163 if (val)
3164 ac_vi = atoi(val);
3165
3166 val = get_param(cmd, "acVO");
3167 if (val)
3168 ac_vo = atoi(val);
3169
3170 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3171
3172 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3173 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3174 ret1 = wpa_command(intf, buf);
3175
3176 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3177 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3178 ret2 = wpa_command(intf, buf);
3179
3180 if (ret1 && ret2) {
3181 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3182 "UAPSD parameters.");
3183 return -2;
3184 }
3185
3186 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3187 send_resp(dut, conn, SIGMA_ERROR,
3188 "ErrorCode,Failed to set ath6kl QoS parameters");
3189 return 0;
3190 }
3191
3192 return 1;
3193}
3194
3195
Jouni Malinenf7222712019-06-13 01:50:21 +03003196static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3197 struct sigma_conn *conn,
3198 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003199{
3200 char buf[1000];
3201 const char *intf = get_param(cmd, "Interface");
3202 const char *grp = get_param(cmd, "Group");
3203 const char *act = get_param(cmd, "Action");
3204 const char *tid = get_param(cmd, "Tid");
3205 const char *dir = get_param(cmd, "Direction");
3206 const char *psb = get_param(cmd, "Psb");
3207 const char *up = get_param(cmd, "Up");
3208 const char *fixed = get_param(cmd, "Fixed");
3209 const char *size = get_param(cmd, "Size");
3210 const char *msize = get_param(cmd, "Maxsize");
3211 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3212 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3213 const char *inact = get_param(cmd, "Inactivity");
3214 const char *sus = get_param(cmd, "Suspension");
3215 const char *mindr = get_param(cmd, "Mindatarate");
3216 const char *meandr = get_param(cmd, "Meandatarate");
3217 const char *peakdr = get_param(cmd, "Peakdatarate");
3218 const char *phyrate = get_param(cmd, "Phyrate");
3219 const char *burstsize = get_param(cmd, "Burstsize");
3220 const char *sba = get_param(cmd, "Sba");
3221 int direction;
3222 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003223 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003224 int fixed_int;
3225 int psb_ts;
3226
3227 if (intf == NULL || grp == NULL || act == NULL )
3228 return -1;
3229
3230 if (strcasecmp(act, "addts") == 0) {
3231 if (tid == NULL || dir == NULL || psb == NULL ||
3232 up == NULL || fixed == NULL || size == NULL)
3233 return -1;
3234
3235 /*
3236 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3237 * possible values, but WMM-AC and V-E test scripts use "UP,
3238 * "DOWN", and "BIDI".
3239 */
3240 if (strcasecmp(dir, "uplink") == 0 ||
3241 strcasecmp(dir, "up") == 0) {
3242 direction = 0;
3243 } else if (strcasecmp(dir, "downlink") == 0 ||
3244 strcasecmp(dir, "down") == 0) {
3245 direction = 1;
3246 } else if (strcasecmp(dir, "bidi") == 0) {
3247 direction = 2;
3248 } else {
3249 sigma_dut_print(dut, DUT_MSG_ERROR,
3250 "Direction %s not supported", dir);
3251 return -1;
3252 }
3253
3254 if (strcasecmp(psb, "legacy") == 0) {
3255 psb_ts = 0;
3256 } else if (strcasecmp(psb, "uapsd") == 0) {
3257 psb_ts = 1;
3258 } else {
3259 sigma_dut_print(dut, DUT_MSG_ERROR,
3260 "PSB %s not supported", psb);
3261 return -1;
3262 }
3263
3264 if (atoi(tid) < 0 || atoi(tid) > 7) {
3265 sigma_dut_print(dut, DUT_MSG_ERROR,
3266 "TID %s not supported", tid);
3267 return -1;
3268 }
3269
3270 if (strcasecmp(fixed, "true") == 0) {
3271 fixed_int = 1;
3272 } else {
3273 fixed_int = 0;
3274 }
3275
Peng Xu93319622017-10-04 17:58:16 -07003276 if (sba)
3277 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003278
3279 dut->dialog_token++;
3280 handle = 7000 + dut->dialog_token;
3281
3282 /*
3283 * size: convert to hex
3284 * maxsi: convert to hex
3285 * mindr: convert to hex
3286 * meandr: convert to hex
3287 * peakdr: convert to hex
3288 * burstsize: convert to hex
3289 * phyrate: convert to hex
3290 * sba: convert to hex with modification
3291 * minsi: convert to integer
3292 * sus: convert to integer
3293 * inact: convert to integer
3294 * maxsi: convert to integer
3295 */
3296
3297 /*
3298 * The Nominal MSDU Size field is 2 octets long and contains an
3299 * unsigned integer that specifies the nominal size, in octets,
3300 * of MSDUs belonging to the traffic under this traffic
3301 * specification and is defined in Figure 16. If the Fixed
3302 * subfield is set to 1, then the size of the MSDU is fixed and
3303 * is indicated by the Size Subfield. If the Fixed subfield is
3304 * set to 0, then the size of the MSDU might not be fixed and
3305 * the Size indicates the nominal MSDU size.
3306 *
3307 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3308 * and specifies the excess allocation of time (and bandwidth)
3309 * over and above the stated rates required to transport an MSDU
3310 * belonging to the traffic in this TSPEC. This field is
3311 * represented as an unsigned binary number with an implicit
3312 * binary point after the leftmost 3 bits. For example, an SBA
3313 * of 1.75 is represented as 0x3800. This field is included to
3314 * account for retransmissions. As such, the value of this field
3315 * must be greater than unity.
3316 */
3317
3318 snprintf(buf, sizeof(buf),
3319 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3320 " 0x%X 0x%X 0x%X"
3321 " 0x%X 0x%X 0x%X"
3322 " 0x%X %d %d %d %d"
3323 " %d %d",
3324 intf, handle, tid, direction, psb_ts, up,
3325 (unsigned int) ((fixed_int << 15) | atoi(size)),
3326 msize ? atoi(msize) : 0,
3327 mindr ? atoi(mindr) : 0,
3328 meandr ? atoi(meandr) : 0,
3329 peakdr ? atoi(peakdr) : 0,
3330 burstsize ? atoi(burstsize) : 0,
3331 phyrate ? atoi(phyrate) : 0,
3332 sba ? ((unsigned int) (((int) sba_fv << 13) |
3333 (int)((sba_fv - (int) sba_fv) *
3334 8192))) : 0,
3335 minsi ? atoi(minsi) : 0,
3336 sus ? atoi(sus) : 0,
3337 0, 0,
3338 inact ? atoi(inact) : 0,
3339 maxsi ? atoi(maxsi) : 0);
3340
3341 if (system(buf) != 0) {
3342 sigma_dut_print(dut, DUT_MSG_ERROR,
3343 "iwpriv addtspec request failed");
3344 send_resp(dut, conn, SIGMA_ERROR,
3345 "errorCode,Failed to execute addTspec command");
3346 return 0;
3347 }
3348
3349 sigma_dut_print(dut, DUT_MSG_INFO,
3350 "iwpriv addtspec request send");
3351
3352 /* Mapping handle to a TID */
3353 dut->tid_to_handle[atoi(tid)] = handle;
3354 } else if (strcasecmp(act, "delts") == 0) {
3355 if (tid == NULL)
3356 return -1;
3357
3358 if (atoi(tid) < 0 || atoi(tid) > 7) {
3359 sigma_dut_print(dut, DUT_MSG_ERROR,
3360 "TID %s not supported", tid);
3361 send_resp(dut, conn, SIGMA_ERROR,
3362 "errorCode,Unsupported TID");
3363 return 0;
3364 }
3365
3366 handle = dut->tid_to_handle[atoi(tid)];
3367
3368 if (handle < 7000 || handle > 7255) {
3369 /* Invalid handle ie no mapping for that TID */
3370 sigma_dut_print(dut, DUT_MSG_ERROR,
3371 "handle-> %d not found", handle);
3372 }
3373
3374 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3375 intf, handle);
3376
3377 if (system(buf) != 0) {
3378 sigma_dut_print(dut, DUT_MSG_ERROR,
3379 "iwpriv deltspec request failed");
3380 send_resp(dut, conn, SIGMA_ERROR,
3381 "errorCode,Failed to execute delTspec command");
3382 return 0;
3383 }
3384
3385 sigma_dut_print(dut, DUT_MSG_INFO,
3386 "iwpriv deltspec request send");
3387
3388 dut->tid_to_handle[atoi(tid)] = 0;
3389 } else {
3390 sigma_dut_print(dut, DUT_MSG_ERROR,
3391 "Action type %s not supported", act);
3392 send_resp(dut, conn, SIGMA_ERROR,
3393 "errorCode,Unsupported Action");
3394 return 0;
3395 }
3396
3397 return 1;
3398}
3399
3400
vamsi krishna52e16f92017-08-29 12:37:34 +05303401static int find_network(struct sigma_dut *dut, const char *ssid)
3402{
3403 char list[4096];
3404 char *pos;
3405
3406 sigma_dut_print(dut, DUT_MSG_DEBUG,
3407 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003408 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303409 list, sizeof(list)) < 0)
3410 return -1;
3411 pos = strstr(list, ssid);
3412 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3413 return -1;
3414
3415 while (pos > list && pos[-1] != '\n')
3416 pos--;
3417 dut->infra_network_id = atoi(pos);
3418 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3419 return 0;
3420}
3421
3422
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303423/**
3424 * enum qca_sta_helper_config_params - This helper enum defines the config
3425 * parameters which can be delivered to sta.
3426 */
3427enum qca_sta_helper_config_params {
3428 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE */
3429 STA_SET_RSNIE,
3430
3431 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC */
3432 STA_SET_LDPC,
3433
3434 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC */
3435 STA_SET_TX_STBC,
3436
3437 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC */
3438 STA_SET_RX_STBC,
3439
3440 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION */
3441 STA_SET_TX_MSDU,
3442
3443 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION */
3444 STA_SET_RX_MSDU,
3445};
3446
3447
3448static int sta_config_params(struct sigma_dut *dut, const char *intf,
3449 enum qca_sta_helper_config_params config_cmd,
3450 int value)
Sunil Dutt44595082018-02-12 19:41:45 +05303451{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303452#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05303453 struct nl_msg *msg;
3454 int ret;
3455 struct nlattr *params;
3456 int ifindex;
3457
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303458 ifindex = if_nametoindex(intf);
3459 if (ifindex == 0) {
3460 sigma_dut_print(dut, DUT_MSG_ERROR,
3461 "%s: Interface %s does not exist",
3462 __func__, intf);
3463 return -1;
3464 }
3465
Sunil Dutt44595082018-02-12 19:41:45 +05303466 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3467 NL80211_CMD_VENDOR)) ||
3468 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3469 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3470 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3471 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303472 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)))
3473 goto fail;
3474
3475 switch (config_cmd) {
3476 case STA_SET_RSNIE:
3477 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, value))
3478 goto fail;
3479 break;
3480 case STA_SET_LDPC:
3481 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC, value))
3482 goto fail;
3483 break;
3484 case STA_SET_TX_STBC:
3485 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC, value))
3486 goto fail;
3487 break;
3488 case STA_SET_RX_STBC:
3489 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC, value))
3490 goto fail;
3491 break;
3492 case STA_SET_TX_MSDU:
3493 if (nla_put_u8(msg,
3494 QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION,
3495 value))
3496 goto fail;
3497 break;
3498 case STA_SET_RX_MSDU:
3499 if (nla_put_u8(msg,
3500 QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION,
3501 value))
3502 goto fail;
3503 break;
Sunil Dutt44595082018-02-12 19:41:45 +05303504 }
3505 nla_nest_end(msg, params);
3506
3507 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3508 if (ret) {
3509 sigma_dut_print(dut, DUT_MSG_ERROR,
3510 "%s: err in send_and_recv_msgs, ret=%d",
3511 __func__, ret);
3512 return ret;
3513 }
3514
3515 return 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303516
3517fail:
3518 sigma_dut_print(dut, DUT_MSG_ERROR,
3519 "%s: err in adding vendor_cmd and vendor_data",
3520 __func__);
3521 nlmsg_free(msg);
Sunil Dutt44595082018-02-12 19:41:45 +05303522#endif /* NL80211_SUPPORT */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303523 return -1;
3524}
Sunil Dutt44595082018-02-12 19:41:45 +05303525
3526
Jouni Malinenf7222712019-06-13 01:50:21 +03003527static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3528 struct sigma_conn *conn,
3529 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003530{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303531#ifdef NL80211_SUPPORT
3532 const char *intf = get_param(cmd, "Interface");
3533#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003534 const char *ssid = get_param(cmd, "ssid");
3535 const char *wps_param = get_param(cmd, "WPS");
3536 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003537 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003538 const char *network_mode = get_param(cmd, "network_mode");
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303539 const char *ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003540 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003541 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003542 int e;
3543 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3544 struct wpa_ctrl *ctrl = NULL;
3545 int num_network_not_found = 0;
3546 int num_disconnected = 0;
3547 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003548
3549 if (ssid == NULL)
3550 return -1;
3551
Jouni Malinen37d5c692019-08-19 16:56:55 +03003552 dut->server_cert_tod = 0;
3553
Jouni Malinen3c367e82017-06-23 17:01:47 +03003554 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303555#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003556 if (get_driver_type(dut) == DRIVER_WCN) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303557 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Sunil Dutt44595082018-02-12 19:41:45 +05303558 dut->config_rsnie = 1;
3559 }
3560#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003561 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3562 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003563 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03003564 send_resp(dut, conn, SIGMA_ERROR,
3565 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3566 return 0;
3567 }
3568 }
3569
Jouni Malinen68143132017-09-02 02:34:08 +03003570 if (dut->sae_commit_override) {
3571 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3572 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003573 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03003574 send_resp(dut, conn, SIGMA_ERROR,
3575 "ErrorCode,Failed to set SAE commit override");
3576 return 0;
3577 }
3578 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303579#ifdef ANDROID
3580 if (dut->fils_hlp)
3581 process_fils_hlp(dut);
3582#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003583
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003584 if (wps_param &&
3585 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3586 wps = 1;
3587
3588 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003589 if (dut->program == PROGRAM_60GHZ && network_mode &&
3590 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003591 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003592 "pbss", "1") < 0)
3593 return -2;
3594
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003595 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3596 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3597 "parameters not yet set");
3598 return 0;
3599 }
3600 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003601 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003602 return -2;
3603 } else {
3604 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3605 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003606 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003607 return -2;
3608 }
3609 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303610 if (strcmp(ssid, dut->infra_ssid) == 0) {
3611 sigma_dut_print(dut, DUT_MSG_DEBUG,
3612 "sta_associate for the most recently added network");
3613 } else if (find_network(dut, ssid) < 0) {
3614 sigma_dut_print(dut, DUT_MSG_DEBUG,
3615 "sta_associate for a previously stored network profile");
3616 send_resp(dut, conn, SIGMA_ERROR,
3617 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003618 return 0;
3619 }
3620
3621 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003622 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003623 "bssid", bssid) < 0) {
3624 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3625 "Invalid bssid argument");
3626 return 0;
3627 }
3628
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303629 if ((dut->program == PROGRAM_WPA3 &&
3630 dut->sta_associate_wait_connect) ||
3631 dut->program == PROGRAM_QM) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003632 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003633 if (!ctrl)
3634 return ERROR_SEND_STATUS;
3635 }
3636
Jouni Malinen46a19b62017-06-23 14:31:27 +03003637 extra[0] = '\0';
3638 if (chan)
3639 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003640 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003641 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3642 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003643 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003644 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3645 "network id %d on %s",
3646 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003647 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003648 ret = ERROR_SEND_STATUS;
3649 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003650 }
3651 }
3652
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003653 if (!ctrl)
3654 return SUCCESS_SEND_STATUS;
3655
3656 /* Wait for connection result to be able to store server certificate
3657 * hash for trust root override testing
3658 * (dev_exec_action,ServerCertTrust). */
3659
3660 for (e = 0; e < 20; e++) {
3661 const char *events[] = {
3662 "CTRL-EVENT-EAP-PEER-CERT",
3663 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3664 "CTRL-EVENT-DISCONNECTED",
3665 "CTRL-EVENT-CONNECTED",
3666 "CTRL-EVENT-NETWORK-NOT-FOUND",
3667 NULL
3668 };
3669 char buf[1024];
3670 int res;
3671
3672 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3673 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02003674 send_resp(dut, conn, SIGMA_COMPLETE,
3675 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003676 ret = STATUS_SENT_ERROR;
3677 break;
3678 }
3679 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3680 buf);
3681
3682 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3683 strstr(buf, " depth=0")) {
3684 char *pos = strstr(buf, " hash=");
3685
3686 if (pos) {
3687 char *end;
3688
Jouni Malinen34b19cb2019-08-16 16:37:17 +03003689 if (strstr(buf, " tod=1"))
3690 tod = 1;
3691 else if (strstr(buf, " tod=2"))
3692 tod = 2;
3693 else
3694 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003695 sigma_dut_print(dut, DUT_MSG_DEBUG,
3696 "Server certificate TOD policy: %d",
3697 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03003698 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003699
3700 pos += 6;
3701 end = strchr(pos, ' ');
3702 if (end)
3703 *end = '\0';
3704 strlcpy(dut->server_cert_hash, pos,
3705 sizeof(dut->server_cert_hash));
3706 sigma_dut_print(dut, DUT_MSG_DEBUG,
3707 "Server certificate hash: %s",
3708 dut->server_cert_hash);
3709 }
3710 }
3711
3712 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3713 send_resp(dut, conn, SIGMA_COMPLETE,
3714 "Result,TLS server certificate validation failed");
3715 ret = STATUS_SENT_ERROR;
3716 break;
3717 }
3718
3719 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3720 num_network_not_found++;
3721
3722 if (num_network_not_found > 2) {
3723 send_resp(dut, conn, SIGMA_COMPLETE,
3724 "Result,Network not found");
3725 ret = STATUS_SENT_ERROR;
3726 break;
3727 }
3728 }
3729
3730 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3731 num_disconnected++;
3732
3733 if (num_disconnected > 2) {
3734 send_resp(dut, conn, SIGMA_COMPLETE,
3735 "Result,Connection failed");
3736 ret = STATUS_SENT_ERROR;
3737 break;
3738 }
3739 }
3740
3741 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3742 if (tod >= 0) {
3743 sigma_dut_print(dut, DUT_MSG_DEBUG,
3744 "Network profile TOD policy update: %d -> %d",
3745 dut->sta_tod_policy, tod);
3746 dut->sta_tod_policy = tod;
3747 }
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303748 if (dut->program == PROGRAM_QM) {
3749 unsigned char iface_mac_addr[ETH_ALEN];
3750 char ipv6[100];
3751
3752 if (get_hwaddr(ifname, iface_mac_addr) < 0) {
3753 sigma_dut_print(dut, DUT_MSG_ERROR,
3754 "%s: get_hwaddr %s failed",
3755 __func__, ifname);
3756 ret = ERROR_SEND_STATUS;
3757 break;
3758 }
3759
3760 convert_mac_addr_to_ipv6_lladdr(iface_mac_addr,
3761 ipv6,
3762 sizeof(ipv6));
3763
3764 if (set_ipv6_addr(dut, ipv6, "64", ifname) !=
3765 0) {
3766 ret = ERROR_SEND_STATUS;
3767 break;
3768 }
3769 }
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003770 break;
3771 }
3772 }
3773done:
3774 if (ctrl) {
3775 wpa_ctrl_detach(ctrl);
3776 wpa_ctrl_close(ctrl);
3777 }
3778 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003779}
3780
3781
3782static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3783{
3784 char buf[500], cmd[200];
3785 int res;
3786
3787 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3788 * default path */
3789 res = snprintf(cmd, sizeof(cmd),
3790 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3791 file_exists("./hs20-osu-client") ?
3792 "./hs20-osu-client" : "hs20-osu-client",
3793 sigma_wpas_ctrl,
3794 dut->summary_log ? "-s " : "",
3795 dut->summary_log ? dut->summary_log : "");
3796 if (res < 0 || res >= (int) sizeof(cmd))
3797 return -1;
3798
3799 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3800 if (res < 0 || res >= (int) sizeof(buf))
3801 return -1;
3802 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3803
3804 if (system(buf) != 0) {
3805 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3806 return -1;
3807 }
3808 sigma_dut_print(dut, DUT_MSG_DEBUG,
3809 "Completed hs20-osu-client operation");
3810
3811 return 0;
3812}
3813
3814
3815static int download_ppsmo(struct sigma_dut *dut,
3816 struct sigma_conn *conn,
3817 const char *intf,
3818 struct sigma_cmd *cmd)
3819{
3820 const char *name, *path, *val;
3821 char url[500], buf[600], fbuf[100];
3822 char *fqdn = NULL;
3823
3824 name = get_param(cmd, "FileName");
3825 path = get_param(cmd, "FilePath");
3826 if (name == NULL || path == NULL)
3827 return -1;
3828
3829 if (strcasecmp(path, "VendorSpecific") == 0) {
3830 snprintf(url, sizeof(url), "PPS/%s", name);
3831 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3832 "from the device (%s)", url);
3833 if (!file_exists(url)) {
3834 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3835 "PPS MO file does not exist");
3836 return 0;
3837 }
3838 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3839 if (system(buf) != 0) {
3840 send_resp(dut, conn, SIGMA_ERROR,
3841 "errorCode,Failed to copy PPS MO");
3842 return 0;
3843 }
3844 } else if (strncasecmp(path, "http:", 5) != 0 &&
3845 strncasecmp(path, "https:", 6) != 0) {
3846 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3847 "Unsupported FilePath value");
3848 return 0;
3849 } else {
3850 snprintf(url, sizeof(url), "%s/%s", path, name);
3851 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3852 url);
3853 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3854 remove("pps-tnds.xml");
3855 if (system(buf) != 0) {
3856 send_resp(dut, conn, SIGMA_ERROR,
3857 "errorCode,Failed to download PPS MO");
3858 return 0;
3859 }
3860 }
3861
3862 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3863 send_resp(dut, conn, SIGMA_ERROR,
3864 "errorCode,Failed to parse downloaded PPSMO");
3865 return 0;
3866 }
3867 unlink("pps-tnds.xml");
3868
3869 val = get_param(cmd, "managementTreeURI");
3870 if (val) {
3871 const char *pos, *end;
3872 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3873 val);
3874 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3875 send_resp(dut, conn, SIGMA_ERROR,
3876 "errorCode,Invalid managementTreeURI prefix");
3877 return 0;
3878 }
3879 pos = val + 8;
3880 end = strchr(pos, '/');
3881 if (end == NULL ||
3882 strcmp(end, "/PerProviderSubscription") != 0) {
3883 send_resp(dut, conn, SIGMA_ERROR,
3884 "errorCode,Invalid managementTreeURI postfix");
3885 return 0;
3886 }
3887 if (end - pos >= (int) sizeof(fbuf)) {
3888 send_resp(dut, conn, SIGMA_ERROR,
3889 "errorCode,Too long FQDN in managementTreeURI");
3890 return 0;
3891 }
3892 memcpy(fbuf, pos, end - pos);
3893 fbuf[end - pos] = '\0';
3894 fqdn = fbuf;
3895 sigma_dut_print(dut, DUT_MSG_INFO,
3896 "FQDN from managementTreeURI: %s", fqdn);
3897 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3898 FILE *f = fopen("pps-fqdn", "r");
3899 if (f) {
3900 if (fgets(fbuf, sizeof(fbuf), f)) {
3901 fbuf[sizeof(fbuf) - 1] = '\0';
3902 fqdn = fbuf;
3903 sigma_dut_print(dut, DUT_MSG_DEBUG,
3904 "Use FQDN %s", fqdn);
3905 }
3906 fclose(f);
3907 }
3908 }
3909
3910 if (fqdn == NULL) {
3911 send_resp(dut, conn, SIGMA_ERROR,
3912 "errorCode,No FQDN specified");
3913 return 0;
3914 }
3915
3916 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3917 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3918 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3919
3920 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3921 if (rename("pps.xml", buf) < 0) {
3922 send_resp(dut, conn, SIGMA_ERROR,
3923 "errorCode,Could not move PPS MO");
3924 return 0;
3925 }
3926
3927 if (strcasecmp(path, "VendorSpecific") == 0) {
3928 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3929 fqdn);
3930 if (system(buf)) {
3931 send_resp(dut, conn, SIGMA_ERROR,
3932 "errorCode,Failed to copy OSU CA cert");
3933 return 0;
3934 }
3935
3936 snprintf(buf, sizeof(buf),
3937 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3938 fqdn);
3939 if (system(buf)) {
3940 send_resp(dut, conn, SIGMA_ERROR,
3941 "errorCode,Failed to copy AAA CA cert");
3942 return 0;
3943 }
3944 } else {
3945 snprintf(buf, sizeof(buf),
3946 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3947 fqdn, fqdn);
3948 if (run_hs20_osu(dut, buf) < 0) {
3949 send_resp(dut, conn, SIGMA_ERROR,
3950 "errorCode,Failed to download OSU CA cert");
3951 return 0;
3952 }
3953
3954 snprintf(buf, sizeof(buf),
3955 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3956 fqdn, fqdn);
3957 if (run_hs20_osu(dut, buf) < 0) {
3958 sigma_dut_print(dut, DUT_MSG_INFO,
3959 "Failed to download AAA CA cert");
3960 }
3961 }
3962
3963 if (file_exists("next-client-cert.pem")) {
3964 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3965 if (rename("next-client-cert.pem", buf) < 0) {
3966 send_resp(dut, conn, SIGMA_ERROR,
3967 "errorCode,Could not move client certificate");
3968 return 0;
3969 }
3970 }
3971
3972 if (file_exists("next-client-key.pem")) {
3973 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3974 if (rename("next-client-key.pem", buf) < 0) {
3975 send_resp(dut, conn, SIGMA_ERROR,
3976 "errorCode,Could not move client key");
3977 return 0;
3978 }
3979 }
3980
3981 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3982 if (run_hs20_osu(dut, buf) < 0) {
3983 send_resp(dut, conn, SIGMA_ERROR,
3984 "errorCode,Failed to configure credential from "
3985 "PPSMO");
3986 return 0;
3987 }
3988
3989 return 1;
3990}
3991
3992
3993static int download_cert(struct sigma_dut *dut,
3994 struct sigma_conn *conn,
3995 const char *intf,
3996 struct sigma_cmd *cmd)
3997{
3998 const char *name, *path;
3999 char url[500], buf[600];
4000
4001 name = get_param(cmd, "FileName");
4002 path = get_param(cmd, "FilePath");
4003 if (name == NULL || path == NULL)
4004 return -1;
4005
4006 if (strcasecmp(path, "VendorSpecific") == 0) {
4007 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
4008 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4009 "certificate from the device (%s)", url);
4010 if (!file_exists(url)) {
4011 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4012 "certificate file does not exist");
4013 return 0;
4014 }
4015 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
4016 if (system(buf) != 0) {
4017 send_resp(dut, conn, SIGMA_ERROR,
4018 "errorCode,Failed to copy client "
4019 "certificate");
4020 return 0;
4021 }
4022
4023 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
4024 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4025 "private key from the device (%s)", url);
4026 if (!file_exists(url)) {
4027 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4028 "private key file does not exist");
4029 return 0;
4030 }
4031 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
4032 if (system(buf) != 0) {
4033 send_resp(dut, conn, SIGMA_ERROR,
4034 "errorCode,Failed to copy client key");
4035 return 0;
4036 }
4037 } else if (strncasecmp(path, "http:", 5) != 0 &&
4038 strncasecmp(path, "https:", 6) != 0) {
4039 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4040 "Unsupported FilePath value");
4041 return 0;
4042 } else {
4043 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
4044 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
4045 "certificate/key from %s", url);
4046 snprintf(buf, sizeof(buf),
4047 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
4048 if (system(buf) != 0) {
4049 send_resp(dut, conn, SIGMA_ERROR,
4050 "errorCode,Failed to download client "
4051 "certificate");
4052 return 0;
4053 }
4054
4055 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
4056 {
4057 send_resp(dut, conn, SIGMA_ERROR,
4058 "errorCode,Failed to copy client key");
4059 return 0;
4060 }
4061 }
4062
4063 return 1;
4064}
4065
4066
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004067static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
4068 struct sigma_conn *conn,
4069 struct sigma_cmd *cmd)
4070{
4071 const char *val;
4072 const char *intf = get_param(cmd, "interface");
4073
4074 if (!intf)
4075 return -1;
4076
4077 val = get_param(cmd, "WscIEFragment");
4078 if (val && strcasecmp(val, "enable") == 0) {
4079 sigma_dut_print(dut, DUT_MSG_DEBUG,
4080 "Enable WSC IE fragmentation");
4081
4082 dut->wsc_fragment = 1;
4083 /* set long attributes to force fragmentation */
4084 if (wpa_command(intf, "SET device_name "
4085 WPS_LONG_DEVICE_NAME) < 0)
4086 return -2;
4087 if (wpa_command(intf, "SET manufacturer "
4088 WPS_LONG_MANUFACTURER) < 0)
4089 return -2;
4090 if (wpa_command(intf, "SET model_name "
4091 WPS_LONG_MODEL_NAME) < 0)
4092 return -2;
4093 if (wpa_command(intf, "SET model_number "
4094 WPS_LONG_MODEL_NUMBER) < 0)
4095 return -2;
4096 if (wpa_command(intf, "SET serial_number "
4097 WPS_LONG_SERIAL_NUMBER) < 0)
4098 return -2;
4099 }
4100
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02004101 val = get_param(cmd, "RSN_IE");
4102 if (val) {
4103 if (strcasecmp(val, "disable") == 0)
4104 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
4105 else if (strcasecmp(val, "enable") == 0)
4106 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
4107 }
4108
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004109 val = get_param(cmd, "WpsVersion");
4110 if (val)
4111 dut->wps_forced_version = get_wps_forced_version(dut, val);
4112
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004113 val = get_param(cmd, "WscEAPFragment");
4114 if (val && strcasecmp(val, "enable") == 0)
4115 dut->eap_fragment = 1;
4116
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004117 return 1;
4118}
4119
4120
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004121static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4122 struct sigma_conn *conn,
4123 const char *intf,
4124 struct sigma_cmd *cmd)
4125{
4126 const char *val;
4127
4128 val = get_param(cmd, "FileType");
4129 if (val && strcasecmp(val, "PPSMO") == 0)
4130 return download_ppsmo(dut, conn, intf, cmd);
4131 if (val && strcasecmp(val, "CERT") == 0)
4132 return download_cert(dut, conn, intf, cmd);
4133 if (val) {
4134 send_resp(dut, conn, SIGMA_ERROR,
4135 "ErrorCode,Unsupported FileType");
4136 return 0;
4137 }
4138
4139 return 1;
4140}
4141
4142
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304143static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4144 struct sigma_conn *conn,
4145 const char *intf,
4146 struct sigma_cmd *cmd)
4147{
4148 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304149 char buf[1000];
4150 char text[20];
4151 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304152
4153 val = get_param(cmd, "OCESupport");
4154 if (val && strcasecmp(val, "Disable") == 0) {
4155 if (wpa_command(intf, "SET oce 0") < 0) {
4156 send_resp(dut, conn, SIGMA_ERROR,
4157 "ErrorCode,Failed to disable OCE");
4158 return 0;
4159 }
4160 } else if (val && strcasecmp(val, "Enable") == 0) {
4161 if (wpa_command(intf, "SET oce 1") < 0) {
4162 send_resp(dut, conn, SIGMA_ERROR,
4163 "ErrorCode,Failed to enable OCE");
4164 return 0;
4165 }
4166 }
4167
vamsi krishnaa2799492017-12-05 14:28:01 +05304168 val = get_param(cmd, "FILScap");
4169 if (val && (atoi(val) == 1)) {
4170 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4171 send_resp(dut, conn, SIGMA_ERROR,
4172 "ErrorCode,Failed to enable FILS");
4173 return 0;
4174 }
4175 } else if (val && (atoi(val) == 0)) {
4176 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4177 send_resp(dut, conn, SIGMA_ERROR,
4178 "ErrorCode,Failed to disable FILS");
4179 return 0;
4180 }
4181 }
4182
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304183 val = get_param(cmd, "FILSHLP");
4184 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004185 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304186 sizeof(text)) < 0)
4187 return -2;
4188 hwaddr_aton(text, addr);
4189 snprintf(buf, sizeof(buf),
4190 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4191 "080045100140000040004011399e00000000ffffffff00440043"
4192 "012cb30001010600fd4f46410000000000000000000000000000"
4193 "000000000000"
4194 "%02x%02x%02x%02x%02x%02x"
4195 "0000000000000000000000000000000000000000000000000000"
4196 "0000000000000000000000000000000000000000000000000000"
4197 "0000000000000000000000000000000000000000000000000000"
4198 "0000000000000000000000000000000000000000000000000000"
4199 "0000000000000000000000000000000000000000000000000000"
4200 "0000000000000000000000000000000000000000000000000000"
4201 "0000000000000000000000000000000000000000000000000000"
4202 "0000000000000000000000000000000000000000638253633501"
4203 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4204 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4205 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4206 if (wpa_command(intf, buf)) {
4207 send_resp(dut, conn, SIGMA_ERROR,
4208 "ErrorCode,Failed to add HLP");
4209 return 0;
4210 }
4211 dut->fils_hlp = 1;
4212 }
4213
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304214 return 1;
4215}
4216
4217
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004218static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4219 const char *val)
4220{
4221 int counter = 0;
4222 char token[50];
4223 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304224 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004225
Peng Xub8fc5cc2017-05-10 17:27:28 -07004226 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004227 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304228 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004229 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004230 if (strcmp(result, "disable") == 0)
4231 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4232 else
4233 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304234 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004235 counter++;
4236 }
4237}
4238
4239
4240static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4241 const char *val)
4242{
4243 char buf[100];
4244
4245 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4246 if (system(buf) != 0) {
4247 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4248 }
4249}
4250
4251
4252static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4253 const char *val)
4254{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004255 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004256 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004257 }
4258}
4259
4260
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004261static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4262 const char *val)
4263{
4264#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004265 int wmmenable = 1;
4266
4267 if (val &&
4268 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4269 wmmenable = 0;
4270
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304271 return wcn_wifi_test_config_set_u8(
4272 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4273 wmmenable);
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004274#else /* NL80211_SUPPORT */
4275 sigma_dut_print(dut, DUT_MSG_ERROR,
4276 "WMM cannot be changed without NL80211_SUPPORT defined");
4277 return -1;
4278#endif /* NL80211_SUPPORT */
4279}
4280
4281
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004282static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4283 const char *val)
4284{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004285 int sgi20;
4286
4287 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4288
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004289 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004290}
4291
4292
4293static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4294 const char *val)
4295{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304296 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004297
4298 /* Disable Tx Beam forming when using a fixed rate */
4299 ath_disable_txbf(dut, intf);
4300
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304301 v = atoi(val);
4302 if (v < 0 || v > 32) {
4303 sigma_dut_print(dut, DUT_MSG_ERROR,
4304 "Invalid Fixed MCS rate: %d", v);
4305 return;
4306 }
4307 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004308
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004309 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004310
4311 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004312 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004313}
4314
4315
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004316static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4317 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004318{
4319 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304320 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004321
4322 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4323 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4324 else
4325 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4326
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304327 ret = system(buf);
4328#ifdef NL80211_SUPPORT
4329 if (ret) {
4330 int value = (strcasecmp(val, "Enable") == 0) ? 2 : 1;
4331
4332 ret = sta_config_params(dut, intf, STA_SET_TX_MSDU, value);
4333 ret |= sta_config_params(dut, intf, STA_SET_RX_MSDU, value);
4334 }
4335#endif /* NL80211_SUPPORT */
4336 if (ret)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004337 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4338}
4339
4340
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004341static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4342 int ampdu)
4343{
4344 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004345 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004346
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004347 if (ampdu)
4348 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004349 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4350 if (system(buf) != 0) {
4351 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4352 return -1;
4353 }
4354
4355 return 0;
4356}
4357
4358
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004359static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4360 const char *val)
4361{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004362 run_iwpriv(dut, intf, "tx_stbc %s", val);
4363 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004364}
4365
4366
4367static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4368 const char *val)
4369{
4370 char buf[60];
4371
Peng Xucc317ed2017-05-18 16:44:37 -07004372 if (strcmp(val, "160") == 0) {
4373 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4374 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004375 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4376 } else if (strcmp(val, "40") == 0) {
4377 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4378 } else if (strcmp(val, "20") == 0) {
4379 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4380 } else if (strcasecmp(val, "Auto") == 0) {
4381 buf[0] = '\0';
4382 } else {
4383 sigma_dut_print(dut, DUT_MSG_ERROR,
4384 "WIDTH/CTS_WIDTH value not supported");
4385 return -1;
4386 }
4387
4388 if (buf[0] != '\0' && system(buf) != 0) {
4389 sigma_dut_print(dut, DUT_MSG_ERROR,
4390 "Failed to set WIDTH/CTS_WIDTH");
4391 return -1;
4392 }
4393
4394 return 0;
4395}
4396
4397
4398int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4399 const char *intf, const char *val)
4400{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004401 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004402 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004403 dut->chwidth = 0;
4404 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004405 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004406 dut->chwidth = 0;
4407 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004408 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004409 dut->chwidth = 1;
4410 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004411 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004412 dut->chwidth = 2;
4413 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004414 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004415 dut->chwidth = 3;
4416 } else {
4417 send_resp(dut, conn, SIGMA_ERROR,
4418 "ErrorCode,WIDTH not supported");
4419 return -1;
4420 }
4421
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004422 return 0;
4423}
4424
4425
4426static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4427 const char *val)
4428{
4429 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004430 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004431
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004432 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004433 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004434 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004435 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004436 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004437 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004438 } else {
4439 sigma_dut_print(dut, DUT_MSG_ERROR,
4440 "SP_STREAM value not supported");
4441 return -1;
4442 }
4443
4444 if (system(buf) != 0) {
4445 sigma_dut_print(dut, DUT_MSG_ERROR,
4446 "Failed to set SP_STREAM");
4447 return -1;
4448 }
4449
Arif Hussainac6c5112018-05-25 17:34:00 -07004450 dut->sta_nss = sta_nss;
4451
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004452 return 0;
4453}
4454
4455
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304456static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4457 const char *val)
4458{
4459 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304460 int ret;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304461
4462 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304463 ret = system(buf);
4464#ifdef NL80211_SUPPORT
4465 if (ret)
4466 ret = sta_config_params(dut, intf, STA_SET_TX_STBC,
4467 strcmp(val, "0") == 0 ? 0 : 1);
4468#endif /* NL80211_SUPPORT */
4469 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304470 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4471
4472 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304473 ret = system(buf);
4474#ifdef NL80211_SUPPORT
4475 if (ret)
4476 ret = sta_config_params(dut, intf, STA_SET_RX_STBC,
4477 strcmp(val, "0") == 0 ? 0 : 1);
4478#endif /* NL80211_SUPPORT */
4479 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304480 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4481}
4482
4483
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304484static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4485 struct sigma_conn *conn,
4486 const char *intf, int capa)
4487{
4488 char buf[32];
4489
4490 if (capa > 0 && capa < 4) {
4491 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4492 if (wpa_command(intf, buf) < 0) {
4493 send_resp(dut, conn, SIGMA_ERROR,
4494 "ErrorCode, Failed to set cellular data capability");
4495 return 0;
4496 }
4497 return 1;
4498 }
4499
4500 sigma_dut_print(dut, DUT_MSG_ERROR,
4501 "Invalid Cellular data capability: %d", capa);
4502 send_resp(dut, conn, SIGMA_INVALID,
4503 "ErrorCode,Invalid cellular data capability");
4504 return 0;
4505}
4506
4507
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304508static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4509 const char *intf, const char *val)
4510{
4511 if (strcasecmp(val, "Disable") == 0) {
4512 if (wpa_command(intf, "SET roaming 0") < 0) {
4513 send_resp(dut, conn, SIGMA_ERROR,
4514 "ErrorCode,Failed to disable roaming");
4515 return 0;
4516 }
4517 return 1;
4518 }
4519
4520 if (strcasecmp(val, "Enable") == 0) {
4521 if (wpa_command(intf, "SET roaming 1") < 0) {
4522 send_resp(dut, conn, SIGMA_ERROR,
4523 "ErrorCode,Failed to enable roaming");
4524 return 0;
4525 }
4526 return 1;
4527 }
4528
4529 sigma_dut_print(dut, DUT_MSG_ERROR,
4530 "Invalid value provided for roaming: %s", val);
4531 send_resp(dut, conn, SIGMA_INVALID,
4532 "ErrorCode,Unknown value provided for Roaming");
4533 return 0;
4534}
4535
4536
Ashwini Patila75de5a2017-04-13 16:35:05 +05304537static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4538 struct sigma_conn *conn,
4539 const char *intf, const char *val)
4540{
4541 if (strcasecmp(val, "Disable") == 0) {
4542 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4543 send_resp(dut, conn, SIGMA_ERROR,
4544 "ErrorCode,Failed to disable Assoc_disallow");
4545 return 0;
4546 }
4547 return 1;
4548 }
4549
4550 if (strcasecmp(val, "Enable") == 0) {
4551 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4552 send_resp(dut, conn, SIGMA_ERROR,
4553 "ErrorCode,Failed to enable Assoc_disallow");
4554 return 0;
4555 }
4556 return 1;
4557 }
4558
4559 sigma_dut_print(dut, DUT_MSG_ERROR,
4560 "Invalid value provided for Assoc_disallow: %s", val);
4561 send_resp(dut, conn, SIGMA_INVALID,
4562 "ErrorCode,Unknown value provided for Assoc_disallow");
4563 return 0;
4564}
4565
4566
Ashwini Patilc63161e2017-04-13 16:30:23 +05304567static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4568 const char *intf, const char *val)
4569{
4570 if (strcasecmp(val, "Reject") == 0) {
4571 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4572 send_resp(dut, conn, SIGMA_ERROR,
4573 "ErrorCode,Failed to Reject BTM Request");
4574 return 0;
4575 }
4576 return 1;
4577 }
4578
4579 if (strcasecmp(val, "Accept") == 0) {
4580 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4581 send_resp(dut, conn, SIGMA_ERROR,
4582 "ErrorCode,Failed to Accept BTM Request");
4583 return 0;
4584 }
4585 return 1;
4586 }
4587
4588 sigma_dut_print(dut, DUT_MSG_ERROR,
4589 "Invalid value provided for BSS_Transition: %s", val);
4590 send_resp(dut, conn, SIGMA_INVALID,
4591 "ErrorCode,Unknown value provided for BSS_Transition");
4592 return 0;
4593}
4594
4595
Ashwini Patil00402582017-04-13 12:29:39 +05304596static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4597 struct sigma_conn *conn,
4598 const char *intf,
4599 struct sigma_cmd *cmd)
4600{
4601 const char *ch, *pref, *op_class, *reason;
4602 char buf[120];
4603 int len, ret;
4604
4605 pref = get_param(cmd, "Ch_Pref");
4606 if (!pref)
4607 return 1;
4608
4609 if (strcasecmp(pref, "clear") == 0) {
4610 free(dut->non_pref_ch_list);
4611 dut->non_pref_ch_list = NULL;
4612 } else {
4613 op_class = get_param(cmd, "Ch_Op_Class");
4614 if (!op_class) {
4615 send_resp(dut, conn, SIGMA_INVALID,
4616 "ErrorCode,Ch_Op_Class not provided");
4617 return 0;
4618 }
4619
4620 ch = get_param(cmd, "Ch_Pref_Num");
4621 if (!ch) {
4622 send_resp(dut, conn, SIGMA_INVALID,
4623 "ErrorCode,Ch_Pref_Num not provided");
4624 return 0;
4625 }
4626
4627 reason = get_param(cmd, "Ch_Reason_Code");
4628 if (!reason) {
4629 send_resp(dut, conn, SIGMA_INVALID,
4630 "ErrorCode,Ch_Reason_Code not provided");
4631 return 0;
4632 }
4633
4634 if (!dut->non_pref_ch_list) {
4635 dut->non_pref_ch_list =
4636 calloc(1, NON_PREF_CH_LIST_SIZE);
4637 if (!dut->non_pref_ch_list) {
4638 send_resp(dut, conn, SIGMA_ERROR,
4639 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4640 return 0;
4641 }
4642 }
4643 len = strlen(dut->non_pref_ch_list);
4644 ret = snprintf(dut->non_pref_ch_list + len,
4645 NON_PREF_CH_LIST_SIZE - len,
4646 " %s:%s:%s:%s", op_class, ch, pref, reason);
4647 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4648 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4649 dut->non_pref_ch_list);
4650 } else {
4651 sigma_dut_print(dut, DUT_MSG_ERROR,
4652 "snprintf failed for non_pref_list, ret = %d",
4653 ret);
4654 send_resp(dut, conn, SIGMA_ERROR,
4655 "ErrorCode,snprintf failed");
4656 free(dut->non_pref_ch_list);
4657 dut->non_pref_ch_list = NULL;
4658 return 0;
4659 }
4660 }
4661
4662 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4663 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4664 if (ret < 0 || ret >= (int) sizeof(buf)) {
4665 sigma_dut_print(dut, DUT_MSG_DEBUG,
4666 "snprintf failed for set non_pref_chan, ret: %d",
4667 ret);
4668 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4669 return 0;
4670 }
4671
4672 if (wpa_command(intf, buf) < 0) {
4673 send_resp(dut, conn, SIGMA_ERROR,
4674 "ErrorCode,Failed to set non-preferred channel list");
4675 return 0;
4676 }
4677
4678 return 1;
4679}
4680
4681
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004682#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004683
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004684static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4685 uint8_t cfg)
4686{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304687 return wcn_wifi_test_config_set_u8(
4688 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4689 cfg);
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004690}
4691
4692
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004693static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4694 enum he_fragmentation_val frag)
4695{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304696 return wcn_wifi_test_config_set_u8(
4697 dut, intf,
4698 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION, frag);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004699}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004700
4701
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08004702int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
4703 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004704{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304705 return wcn_wifi_test_config_set_u8(
4706 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF, ltf);
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004707}
4708
4709
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004710static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4711 int noack, enum qca_wlan_ac_type ac)
4712{
4713 struct nl_msg *msg;
4714 int ret = 0;
4715 struct nlattr *params;
4716 int ifindex;
4717
4718 ifindex = if_nametoindex(intf);
4719 if (ifindex == 0) {
4720 sigma_dut_print(dut, DUT_MSG_ERROR,
4721 "%s: Index for interface %s failed",
4722 __func__, intf);
4723 return -1;
4724 }
4725
4726 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4727 NL80211_CMD_VENDOR)) ||
4728 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4729 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4730 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4731 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4732 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4733 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4734 noack) ||
4735 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4736 ac)) {
4737 sigma_dut_print(dut, DUT_MSG_ERROR,
4738 "%s: err in adding vendor_cmd and vendor_data",
4739 __func__);
4740 nlmsg_free(msg);
4741 return -1;
4742 }
4743 nla_nest_end(msg, params);
4744
4745 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4746 if (ret) {
4747 sigma_dut_print(dut, DUT_MSG_ERROR,
4748 "%s: err in send_and_recv_msgs, ret=%d",
4749 __func__, ret);
4750 }
4751 return ret;
4752}
4753
4754
4755static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4756 const char *val)
4757{
4758 int noack, ret;
4759 char token[100];
4760 char *result;
4761 char *saveptr;
4762 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4763
4764 strlcpy(token, val, sizeof(token));
4765 token[sizeof(token) - 1] = '\0';
4766 result = strtok_r(token, ":", &saveptr);
4767 while (result) {
4768 noack = strcasecmp(result, "Disable") != 0;
4769 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4770 if (ret) {
4771 sigma_dut_print(dut, DUT_MSG_ERROR,
4772 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4773 ac, ret);
4774 }
4775 result = strtok_r(NULL, ":", &saveptr);
4776 ac++;
4777 }
4778}
4779
Vinita S. Maloo7462e812020-05-22 15:16:04 +05304780
4781static int nlvendor_sta_set_phymode(struct sigma_dut *dut, const char *intf,
4782 enum qca_wlan_vendor_phy_mode val)
4783{
4784 struct nl_msg *msg;
4785 struct nlattr *params;
4786 int ifindex, ret;
4787
4788 ifindex = if_nametoindex(intf);
4789 if (ifindex == 0) {
4790 sigma_dut_print(dut, DUT_MSG_ERROR,
4791 "%s: Index for interface %s not found",
4792 __func__, intf);
4793 return -1;
4794 }
4795
4796 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4797 NL80211_CMD_VENDOR);
4798 if (!msg) {
4799 sigma_dut_print(dut, DUT_MSG_ERROR,
4800 "%s: err in adding vendor_cmd", __func__);
4801 return -1;
4802 }
4803
4804 if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4805 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4806 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) {
4807 sigma_dut_print(dut, DUT_MSG_ERROR,
4808 "%s: err in adding vendor_attr", __func__);
4809 nlmsg_free(msg);
4810 return -1;
4811 }
4812
4813 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
4814 if (!params || nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_PHY_MODE,
4815 val)) {
4816 sigma_dut_print(dut, DUT_MSG_ERROR,
4817 "%s: err in adding vendor_data", __func__);
4818 nlmsg_free(msg);
4819 return -1;
4820 }
4821
4822 nla_nest_end(msg, params);
4823 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4824 if (ret) {
4825 sigma_dut_print(dut, DUT_MSG_ERROR,
4826 "%s: err in send_and_recv_msgs, ret=%d (%s)",
4827 __func__, ret, strerror(-ret));
4828 return ret;
4829 }
4830
4831 return 0;
4832}
4833
4834
4835static enum qca_wlan_vendor_phy_mode get_qca_vendor_phymode(const char *val)
4836{
4837 if (strcmp(val, "11a") == 0) {
4838 /* IEEE80211_MODE_11A */
4839 return QCA_WLAN_VENDOR_PHY_MODE_11A;
4840 }
4841
4842 if (strcmp(val, "11g") == 0) {
4843 /* IEEE80211_MODE_11G */
4844 return QCA_WLAN_VENDOR_PHY_MODE_11G;
4845 }
4846
4847 if (strcmp(val, "11b") == 0) {
4848 /* IEEE80211_MODE_11B */
4849 return QCA_WLAN_VENDOR_PHY_MODE_11B;
4850 }
4851
4852 if (strcmp(val, "11n") == 0 ||
4853 strcmp(val, "11nl") == 0 ||
4854 strcmp(val, "11nl(nabg)") == 0) {
4855 /* IEEE80211_MODE_11AGN */
4856 return QCA_WLAN_VENDOR_PHY_MODE_11AGN;
4857 }
4858
4859 if (strcmp(val, "11ng") == 0) {
4860 /* IEEE80211_MODE_11NG_HT40 */
4861 return QCA_WLAN_VENDOR_PHY_MODE_11NG_HT40;
4862 }
4863
4864 if (strcmp(val, "AC") == 0 ||
4865 strcasecmp(val, "11AC") == 0) {
4866 /* IEEE80211_MODE_11AC_VHT80 */
4867 return QCA_WLAN_VENDOR_PHY_MODE_11AC_VHT80;
4868 }
4869
4870 if (strcmp(val, "11na") == 0 ||
4871 strcasecmp(val, "11an") == 0) {
4872 /* IEEE80211_MODE_11NA_HT40 */
4873 return QCA_WLAN_VENDOR_PHY_MODE_11NA_HT40;
4874 }
4875
4876 if (strcmp(val, "11ax") == 0 ||
4877 strcmp(val, "auto") == 0) {
4878 /* IEEE80211_MODE_AUTO */
4879 return QCA_WLAN_VENDOR_PHY_MODE_AUTO;
4880 }
4881
4882 return -1;
4883}
4884
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004885#endif /* NL80211_SUPPORT */
4886
4887
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05304888static int get_phymode(const char *val)
4889{
4890 if (strcmp(val, "11a") == 0)
4891 return 1; /* IEEE80211_MODE_11A */
4892 if (strcmp(val, "11g") == 0)
4893 return 3; /* IEEE80211_MODE_11G */
4894 if (strcmp(val, "11b") == 0)
4895 return 2; /* IEEE80211_MODE_11B */
4896 if (strcmp(val, "11n") == 0 ||
4897 strcmp(val, "11nl") == 0 ||
4898 strcmp(val, "11nl(nabg)") == 0)
4899 return 22; /* IEEE80211_MODE_11AGN */
4900 if (strcmp(val, "11ng") == 0)
4901 return 13; /* IEEE80211_MODE_11NG_HT40 */
4902 if (strcmp(val, "AC") == 0 ||
4903 strcasecmp(val, "11AC") == 0)
4904 return 19; /* IEEE80211_MODE_11AC_VHT80 */
4905 if (strcmp(val, "11na") == 0 ||
4906 strcasecmp(val, "11an") == 0)
4907 return 14; /* IEEE80211_MODE_11NA_HT40 */
4908 if (strcmp(val, "11ax") == 0 ||
4909 strcmp(val, "auto") == 0)
4910 return 0; /* IEEE80211_MODE_AUTO */
4911 return -1;
4912}
4913
4914
4915static void sta_set_phymode(struct sigma_dut *dut, const char *intf,
4916 const char *val)
4917{
4918 char buf[100];
4919 int len, phymode;
Vinita S. Maloo7462e812020-05-22 15:16:04 +05304920#ifdef NL80211_SUPPORT
4921 enum qca_wlan_vendor_phy_mode qca_phymode;
4922
4923 qca_phymode = get_qca_vendor_phymode(val);
4924 if (qca_phymode == -1) {
4925 sigma_dut_print(dut, DUT_MSG_DEBUG,
4926 "Ignoring mode change for mode: %s",
4927 val);
4928 return;
4929 }
4930
4931 if (nlvendor_sta_set_phymode(dut, intf, qca_phymode) == 0)
4932 return;
4933#endif /* NL80211_SUPPORT */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05304934
4935 phymode = get_phymode(val);
4936 if (phymode == -1) {
4937 sigma_dut_print(dut, DUT_MSG_DEBUG,
4938 "Ignoring mode change for mode: %s",
4939 val);
4940 return;
4941 }
4942
4943 len = snprintf(buf, sizeof(buf), "iwpriv %s setphymode %d", intf,
4944 phymode);
4945 if (len < 0 || len >= sizeof(buf)) {
4946 sigma_dut_print(dut, DUT_MSG_ERROR,
4947 "Failed to set phymode");
4948 return;
4949 }
4950
4951 if (system(buf) != 0)
4952 sigma_dut_print(dut, DUT_MSG_ERROR,
4953 "iwpriv setting of phymode failed");
4954}
4955
4956
Jouni Malinenf7222712019-06-13 01:50:21 +03004957static enum sigma_cmd_result
4958cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
4959 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004960{
4961 const char *intf = get_param(cmd, "Interface");
4962 const char *val;
4963
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03004964 val = get_param(cmd, "FT_DS");
4965 if (val) {
4966 if (strcasecmp(val, "Enable") == 0) {
4967 dut->sta_ft_ds = 1;
4968 } else if (strcasecmp(val, "Disable") == 0) {
4969 dut->sta_ft_ds = 0;
4970 } else {
4971 send_resp(dut, conn, SIGMA_ERROR,
4972 "errorCode,Unsupported value for FT_DS");
4973 return STATUS_SENT_ERROR;
4974 }
4975 }
4976
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004977 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03004978 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
4979 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004980 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
4981 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004982
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004983 if (val && strcasecmp(val, "LOC") == 0)
4984 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02004985 if (val && strcasecmp(val, "60GHZ") == 0) {
4986 val = get_param(cmd, "WPS");
4987 if (val && strcasecmp(val, "disable") == 0) {
4988 dut->wps_disable = 1;
4989 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
4990 } else {
4991 /* wps_disable can have other value from the previous
4992 * test, so make sure it has the correct value.
4993 */
4994 dut->wps_disable = 0;
4995 }
4996
4997 val = get_param(cmd, "P2P");
4998 if (val && strcasecmp(val, "disable") == 0)
4999 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
5000 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005001
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02005002 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
5003 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
5004
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005005#ifdef ANDROID_NAN
5006 if (val && strcasecmp(val, "NAN") == 0)
5007 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
5008#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005009#ifdef MIRACAST
5010 if (val && (strcasecmp(val, "WFD") == 0 ||
5011 strcasecmp(val, "DisplayR2") == 0))
5012 return miracast_preset_testparameters(dut, conn, cmd);
5013#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005014
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07005015 if (val &&
5016 (strcasecmp(val, "MBO") == 0 || strcasecmp(val, "HE") == 0)) {
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305017 val = get_param(cmd, "Cellular_Data_Cap");
5018 if (val &&
5019 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
5020 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05305021
5022 val = get_param(cmd, "Ch_Pref");
5023 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
5024 return 0;
5025
Ashwini Patilc63161e2017-04-13 16:30:23 +05305026 val = get_param(cmd, "BSS_Transition");
5027 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
5028 return 0;
5029
Ashwini Patila75de5a2017-04-13 16:35:05 +05305030 val = get_param(cmd, "Assoc_Disallow");
5031 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
5032 return 0;
5033
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305034 val = get_param(cmd, "Roaming");
5035 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
5036 return 0;
5037
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305038 return 1;
5039 }
5040
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305041 if (val && strcasecmp(val, "OCE") == 0)
5042 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
5043
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005044#if 0
5045 val = get_param(cmd, "Supplicant");
5046 if (val && strcasecmp(val, "Default") != 0) {
5047 send_resp(dut, conn, SIGMA_ERROR,
5048 "ErrorCode,Only default(Vendor) supplicant "
5049 "supported");
5050 return 0;
5051 }
5052#endif
5053
5054 val = get_param(cmd, "RTS");
5055 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005056 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005057 case DRIVER_ATHEROS:
5058 ath_sta_set_rts(dut, intf, val);
5059 break;
5060 default:
5061#if 0
5062 send_resp(dut, conn, SIGMA_ERROR,
5063 "ErrorCode,Setting RTS not supported");
5064 return 0;
5065#else
5066 sigma_dut_print(dut, DUT_MSG_DEBUG,
5067 "Setting RTS not supported");
5068 break;
5069#endif
5070 }
5071 }
5072
5073#if 0
5074 val = get_param(cmd, "FRGMNT");
5075 if (val) {
5076 /* TODO */
5077 send_resp(dut, conn, SIGMA_ERROR,
5078 "ErrorCode,Setting FRGMNT not supported");
5079 return 0;
5080 }
5081#endif
5082
5083#if 0
5084 val = get_param(cmd, "Preamble");
5085 if (val) {
5086 /* TODO: Long/Short */
5087 send_resp(dut, conn, SIGMA_ERROR,
5088 "ErrorCode,Setting Preamble not supported");
5089 return 0;
5090 }
5091#endif
5092
5093 val = get_param(cmd, "Mode");
5094 if (val) {
5095 if (strcmp(val, "11b") == 0 ||
5096 strcmp(val, "11g") == 0 ||
5097 strcmp(val, "11a") == 0 ||
5098 strcmp(val, "11n") == 0 ||
5099 strcmp(val, "11ng") == 0 ||
5100 strcmp(val, "11nl") == 0 ||
5101 strcmp(val, "11nl(nabg)") == 0 ||
5102 strcmp(val, "AC") == 0 ||
5103 strcmp(val, "11AC") == 0 ||
5104 strcmp(val, "11ac") == 0 ||
5105 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08005106 strcmp(val, "11an") == 0 ||
5107 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005108 /* STA supports all modes by default */
5109 } else {
5110 send_resp(dut, conn, SIGMA_ERROR,
5111 "ErrorCode,Setting Mode not supported");
5112 return 0;
5113 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005114
5115 /* Change the mode only in case of testbed for HE program
5116 * and for 11a and 11g modes only. */
5117 if (dut->program == PROGRAM_HE &&
5118 dut->device_type == STA_testbed) {
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305119 sta_set_phymode(dut, intf, val);
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005120 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005121 }
5122
5123 val = get_param(cmd, "wmm");
5124 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005125 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005126 case DRIVER_ATHEROS:
5127 ath_sta_set_wmm(dut, intf, val);
5128 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005129 case DRIVER_WCN:
5130 wcn_sta_set_wmm(dut, intf, val);
5131 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005132 default:
5133 sigma_dut_print(dut, DUT_MSG_DEBUG,
5134 "Setting wmm not supported");
5135 break;
5136 }
5137 }
5138
5139 val = get_param(cmd, "Powersave");
5140 if (val) {
5141 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005142 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305143 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005144 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005145 }
5146
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005147 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005148 "P2P_SET ps 0") < 0)
5149 return -2;
5150 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005151 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5152 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005153 } else if (strcmp(val, "1") == 0 ||
5154 strcasecmp(val, "PSPoll") == 0 ||
5155 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005156 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305157 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005158 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005159 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005160 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005161 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005162 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005163 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005164 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005165 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005166 "P2P_SET ps 99") < 0)
5167 return -2;
5168 } else if (strcmp(val, "2") == 0 ||
5169 strcasecmp(val, "Fast") == 0) {
5170 /* TODO */
5171 send_resp(dut, conn, SIGMA_ERROR,
5172 "ErrorCode,Powersave=Fast not supported");
5173 return 0;
5174 } else if (strcmp(val, "3") == 0 ||
5175 strcasecmp(val, "PSNonPoll") == 0) {
5176 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005177 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5178 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005179
5180 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005181 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005182 "P2P_SET ps 1") < 0)
5183 return -2;
5184 } else
5185 return -1;
5186 }
5187
5188 val = get_param(cmd, "NoAck");
5189 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005190 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005191 case DRIVER_ATHEROS:
5192 ath_sta_set_noack(dut, intf, val);
5193 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005194#ifdef NL80211_SUPPORT
5195 case DRIVER_WCN:
5196 wcn_sta_set_noack(dut, intf, val);
5197 break;
5198#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005199 default:
5200 send_resp(dut, conn, SIGMA_ERROR,
5201 "ErrorCode,Setting NoAck not supported");
5202 return 0;
5203 }
5204 }
5205
5206 val = get_param(cmd, "IgnoreChswitchProhibit");
5207 if (val) {
5208 /* TODO: Enabled/disabled */
5209 if (strcasecmp(val, "Enabled") == 0) {
5210 send_resp(dut, conn, SIGMA_ERROR,
5211 "ErrorCode,Enabling IgnoreChswitchProhibit "
5212 "not supported");
5213 return 0;
5214 }
5215 }
5216
5217 val = get_param(cmd, "TDLS");
5218 if (val) {
5219 if (strcasecmp(val, "Disabled") == 0) {
5220 if (wpa_command(intf, "SET tdls_disabled 1")) {
5221 send_resp(dut, conn, SIGMA_ERROR,
5222 "ErrorCode,Failed to disable TDLS");
5223 return 0;
5224 }
5225 } else if (strcasecmp(val, "Enabled") == 0) {
5226 if (wpa_command(intf, "SET tdls_disabled 0")) {
5227 send_resp(dut, conn, SIGMA_ERROR,
5228 "ErrorCode,Failed to enable TDLS");
5229 return 0;
5230 }
5231 } else {
5232 send_resp(dut, conn, SIGMA_ERROR,
5233 "ErrorCode,Unsupported TDLS value");
5234 return 0;
5235 }
5236 }
5237
5238 val = get_param(cmd, "TDLSmode");
5239 if (val) {
5240 if (strcasecmp(val, "Default") == 0) {
5241 wpa_command(intf, "SET tdls_testing 0");
5242 } else if (strcasecmp(val, "APProhibit") == 0) {
5243 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5244 send_resp(dut, conn, SIGMA_ERROR,
5245 "ErrorCode,Failed to enable ignore "
5246 "APProhibit TDLS mode");
5247 return 0;
5248 }
5249 } else if (strcasecmp(val, "HiLoMac") == 0) {
5250 /* STA should respond with TDLS setup req for a TDLS
5251 * setup req */
5252 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5253 send_resp(dut, conn, SIGMA_ERROR,
5254 "ErrorCode,Failed to enable HiLoMac "
5255 "TDLS mode");
5256 return 0;
5257 }
5258 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5259 /*
5260 * Since all security modes are enabled by default when
5261 * Sigma control is used, there is no need to do
5262 * anything here.
5263 */
5264 } else if (strcasecmp(val, "ExistLink") == 0) {
5265 /*
5266 * Since we allow new TDLS Setup Request even if there
5267 * is an existing link, nothing needs to be done for
5268 * this.
5269 */
5270 } else {
5271 /* TODO:
5272 * ExistLink: STA should send TDLS setup req even if
5273 * direct link already exists
5274 */
5275 send_resp(dut, conn, SIGMA_ERROR,
5276 "ErrorCode,Unsupported TDLSmode value");
5277 return 0;
5278 }
5279 }
5280
5281 val = get_param(cmd, "FakePubKey");
5282 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5283 send_resp(dut, conn, SIGMA_ERROR,
5284 "ErrorCode,Failed to enable FakePubKey");
5285 return 0;
5286 }
5287
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005288#ifdef NL80211_SUPPORT
5289 val = get_param(cmd, "FrgmntSupport");
5290 if (val) {
5291 if (strcasecmp(val, "Enable") == 0) {
5292 if (sta_set_he_fragmentation(dut, intf,
5293 HE_FRAG_LEVEL1)) {
5294 send_resp(dut, conn, SIGMA_ERROR,
5295 "ErrorCode,Failed to enable HE Fragmentation");
5296 return 0;
5297 }
5298 } else if (strcasecmp(val, "Disable") == 0) {
5299 if (sta_set_he_fragmentation(dut, intf,
5300 HE_FRAG_DISABLE)) {
5301 send_resp(dut, conn, SIGMA_ERROR,
5302 "ErrorCode,Failed to disable HE Fragmentation");
5303 return 0;
5304 }
5305 }
5306 }
5307#endif /* NL80211_SUPPORT */
5308
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305309 val = get_param(cmd, "IncludeMSCSDescriptor");
5310 if (val && strcasecmp(val, "1") == 0) {
5311 char buf[128];
5312 int len;
5313
5314 len = snprintf(buf, sizeof(buf),
Veerendranath Jakkam62cde372020-08-19 18:03:06 +05305315 "MSCS add up_bitmap=F0 up_limit=7 stream_timeout=60000 frame_classifier=045F%032x",
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305316 0);
5317
5318 if (len < 0 || len >= sizeof(buf)) {
5319 sigma_dut_print(dut, DUT_MSG_ERROR,
5320 "Failed to build MSCS Descriptor IE");
5321 return ERROR_SEND_STATUS;
5322 }
5323
5324 if (wpa_command(intf, buf) != 0) {
5325 send_resp(dut, conn, SIGMA_ERROR,
5326 "ErrorCode,Failed to include MSCS descriptor");
5327 return STATUS_SENT_ERROR;
5328 }
5329 }
5330
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005331 return 1;
5332}
5333
5334
5335static const char * ath_get_radio_name(const char *radio_name)
5336{
5337 if (radio_name == NULL)
5338 return "wifi0";
5339 if (strcmp(radio_name, "wifi1") == 0)
5340 return "wifi1";
5341 if (strcmp(radio_name, "wifi2") == 0)
5342 return "wifi2";
5343 return "wifi0";
5344}
5345
5346
5347static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5348 const char *val)
5349{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005350 unsigned int vht_mcsmap = 0;
5351 int txchainmask = 0;
5352 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5353
5354 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5355 if (dut->testbed_flag_txsp == 1) {
5356 vht_mcsmap = 0xfffc;
5357 dut->testbed_flag_txsp = 0;
5358 } else {
5359 vht_mcsmap = 0xfffe;
5360 }
5361 txchainmask = 1;
5362 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5363 if (dut->testbed_flag_txsp == 1) {
5364 vht_mcsmap = 0xfff0;
5365 dut->testbed_flag_txsp = 0;
5366 } else {
5367 vht_mcsmap = 0xfffa;
5368 }
5369 txchainmask = 3;
5370 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5371 if (dut->testbed_flag_txsp == 1) {
5372 vht_mcsmap = 0xffc0;
5373 dut->testbed_flag_txsp = 0;
5374 } else {
5375 vht_mcsmap = 0xffea;
5376 }
5377 txchainmask = 7;
5378 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5379 if (dut->testbed_flag_txsp == 1) {
5380 vht_mcsmap = 0xff00;
5381 dut->testbed_flag_txsp = 0;
5382 } else {
5383 vht_mcsmap = 0xffaa;
5384 }
5385 txchainmask = 15;
5386 } else {
5387 if (dut->testbed_flag_txsp == 1) {
5388 vht_mcsmap = 0xffc0;
5389 dut->testbed_flag_txsp = 0;
5390 } else {
5391 vht_mcsmap = 0xffea;
5392 }
5393 }
5394
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005395 if (txchainmask)
5396 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005397
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005398 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005399}
5400
5401
5402static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5403 const char *val)
5404{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005405 unsigned int vht_mcsmap = 0;
5406 int rxchainmask = 0;
5407 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5408
5409 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5410 if (dut->testbed_flag_rxsp == 1) {
5411 vht_mcsmap = 0xfffc;
5412 dut->testbed_flag_rxsp = 0;
5413 } else {
5414 vht_mcsmap = 0xfffe;
5415 }
5416 rxchainmask = 1;
5417 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5418 if (dut->testbed_flag_rxsp == 1) {
5419 vht_mcsmap = 0xfff0;
5420 dut->testbed_flag_rxsp = 0;
5421 } else {
5422 vht_mcsmap = 0xfffa;
5423 }
5424 rxchainmask = 3;
5425 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5426 if (dut->testbed_flag_rxsp == 1) {
5427 vht_mcsmap = 0xffc0;
5428 dut->testbed_flag_rxsp = 0;
5429 } else {
5430 vht_mcsmap = 0xffea;
5431 }
5432 rxchainmask = 7;
5433 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5434 if (dut->testbed_flag_rxsp == 1) {
5435 vht_mcsmap = 0xff00;
5436 dut->testbed_flag_rxsp = 0;
5437 } else {
5438 vht_mcsmap = 0xffaa;
5439 }
5440 rxchainmask = 15;
5441 } else {
5442 if (dut->testbed_flag_rxsp == 1) {
5443 vht_mcsmap = 0xffc0;
5444 dut->testbed_flag_rxsp = 0;
5445 } else {
5446 vht_mcsmap = 0xffea;
5447 }
5448 }
5449
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005450 if (rxchainmask)
5451 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005452
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005453 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005454}
5455
5456
5457void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5458{
5459 if (strcasecmp(val, "enable") == 0) {
5460 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5461 != 0) {
5462 sigma_dut_print(dut, DUT_MSG_ERROR,
5463 "Disable BB_VHTSIGB_CRC_CALC failed");
5464 }
5465
5466 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5467 != 0) {
5468 sigma_dut_print(dut, DUT_MSG_ERROR,
5469 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5470 }
5471 } else {
5472 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5473 != 0) {
5474 sigma_dut_print(dut, DUT_MSG_ERROR,
5475 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5476 }
5477
5478 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5479 != 0) {
5480 sigma_dut_print(dut, DUT_MSG_ERROR,
5481 "Enable BB_VHTSIGB_CRC_CALC failed");
5482 }
5483 }
5484}
5485
5486
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005487static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5488 const char *val)
5489{
5490 char buf[60];
5491
5492 if (strcmp(val, "20") == 0) {
5493 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5494 dut->chwidth = 0;
5495 } else if (strcmp(val, "40") == 0) {
5496 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5497 dut->chwidth = 1;
5498 } else if (strcmp(val, "80") == 0) {
5499 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5500 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305501 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005502 buf[0] = '\0';
5503 } else {
5504 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5505 val);
5506 return -1;
5507 }
5508
5509 if (buf[0] != '\0' && system(buf) != 0) {
5510 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5511 return -1;
5512 }
5513
5514 return 0;
5515}
5516
5517
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005518static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5519 const char *intf, int addbareject)
5520{
5521#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305522 return wcn_wifi_test_config_set_u8(
5523 dut, intf,
5524 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5525 !addbareject);
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005526#else /* NL80211_SUPPORT */
5527 sigma_dut_print(dut, DUT_MSG_ERROR,
5528 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5529 return -1;
5530#endif /* NL80211_SUPPORT */
5531}
5532
5533
5534static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5535 int addbareject)
5536{
5537 int ret;
5538
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005539 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005540 case DRIVER_WCN:
5541 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5542 if (ret) {
5543 sigma_dut_print(dut, DUT_MSG_ERROR,
5544 "nlvendor_sta_set_addba_reject failed, ret:%d",
5545 ret);
5546 return ret;
5547 }
5548 break;
5549 default:
5550 sigma_dut_print(dut, DUT_MSG_ERROR,
5551 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5552 ret = -1;
5553 break;
5554 }
5555
5556 return ret;
5557}
5558
5559
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005560static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5561 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005562{
5563#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305564 return wcn_wifi_test_config_set_u8(
5565 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
5566 enable);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005567#else /* NL80211_SUPPORT */
5568 sigma_dut_print(dut, DUT_MSG_ERROR,
5569 "Disable addba not possible without NL80211_SUPPORT defined");
5570 return -1;
5571#endif /* NL80211_SUPPORT */
5572}
5573
5574
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305575#ifdef NL80211_SUPPORT
5576static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5577{
5578 struct nl_msg *msg;
5579 int ret = 0;
5580 int ifindex;
5581
5582 ifindex = if_nametoindex(intf);
5583 if (ifindex == 0) {
5584 sigma_dut_print(dut, DUT_MSG_ERROR,
5585 "%s: Index for interface %s failed",
5586 __func__, intf);
5587 return -1;
5588 }
5589
5590 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5591 NL80211_CMD_SET_WIPHY)) ||
5592 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5593 sigma_dut_print(dut, DUT_MSG_ERROR,
5594 "%s: err in adding RTS threshold",
5595 __func__);
5596 nlmsg_free(msg);
5597 return -1;
5598 }
5599
5600 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5601 if (ret) {
5602 sigma_dut_print(dut, DUT_MSG_ERROR,
5603 "%s: err in send_and_recv_msgs, ret=%d",
5604 __func__, ret);
5605 }
5606 return ret;
5607}
5608#endif /* NL80211_SUPPORT */
5609
5610
5611static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5612{
5613 char buf[100];
5614
5615#ifdef NL80211_SUPPORT
5616 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5617 return 0;
5618 sigma_dut_print(dut, DUT_MSG_DEBUG,
5619 "Fall back to using iwconfig for setting RTS threshold");
5620#endif /* NL80211_SUPPORT */
5621
5622 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5623 if (system(buf) != 0) {
5624 sigma_dut_print(dut, DUT_MSG_ERROR,
5625 "Failed to set RTS threshold %d", val);
5626 return -1;
5627 }
5628 return 0;
5629}
5630
5631
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005632static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5633 struct sigma_conn *conn,
5634 struct sigma_cmd *cmd)
5635{
5636 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005637 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005638 char buf[128];
5639 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005640
5641 val = get_param(cmd, "40_INTOLERANT");
5642 if (val) {
5643 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5644 /* TODO: iwpriv ht40intol through wpa_supplicant */
5645 send_resp(dut, conn, SIGMA_ERROR,
5646 "ErrorCode,40_INTOLERANT not supported");
5647 return 0;
5648 }
5649 }
5650
5651 val = get_param(cmd, "ADDBA_REJECT");
5652 if (val) {
5653 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5654 /* reject any ADDBA with status "decline" */
5655 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005656 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005657 } else {
5658 /* accept ADDBA */
5659 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005660 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005661 }
5662 }
5663
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005664 if (addbareject >= 0 &&
5665 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5666 send_resp(dut, conn, SIGMA_ERROR,
5667 "ErrorCode,set addba_reject failed");
5668 return 0;
5669 }
5670
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005671 val = get_param(cmd, "AMPDU");
5672 if (val) {
5673 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5674 /* enable AMPDU Aggregation */
5675 if (ampdu == 0) {
5676 send_resp(dut, conn, SIGMA_ERROR,
5677 "ErrorCode,Mismatch in "
5678 "addba_reject/ampdu - "
5679 "not supported");
5680 return 0;
5681 }
5682 ampdu = 1;
5683 } else {
5684 /* disable AMPDU Aggregation */
5685 if (ampdu == 1) {
5686 send_resp(dut, conn, SIGMA_ERROR,
5687 "ErrorCode,Mismatch in "
5688 "addba_reject/ampdu - "
5689 "not supported");
5690 return 0;
5691 }
5692 ampdu = 0;
5693 }
5694 }
5695
5696 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005697 int ret;
5698
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005699 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5700 ampdu ? "Enabling" : "Disabling");
5701 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005702 if (wpa_command(intf, buf) < 0 &&
5703 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005704 send_resp(dut, conn, SIGMA_ERROR,
5705 "ErrorCode,set aggr failed");
5706 return 0;
5707 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005708
5709 if (ampdu == 0) {
5710 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005711 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005712 if (ret) {
5713 sigma_dut_print(dut, DUT_MSG_ERROR,
5714 "Failed to disable addba, ret:%d",
5715 ret);
5716 }
5717 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005718 }
5719
5720 val = get_param(cmd, "AMSDU");
5721 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005722 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005723 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005724 case DRIVER_WCN:
5725 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005726 break;
5727 default:
5728 if (strcmp(val, "1") == 0 ||
5729 strcasecmp(val, "Enable") == 0) {
5730 /* Enable AMSDU Aggregation */
5731 send_resp(dut, conn, SIGMA_ERROR,
5732 "ErrorCode,AMSDU aggregation not supported");
5733 return 0;
5734 }
5735 break;
5736 }
5737 }
5738
5739 val = get_param(cmd, "STBC_RX");
5740 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005741 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005742 case DRIVER_ATHEROS:
5743 ath_sta_set_stbc(dut, intf, val);
5744 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305745 case DRIVER_WCN:
5746 wcn_sta_set_stbc(dut, intf, val);
5747 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005748 default:
5749 send_resp(dut, conn, SIGMA_ERROR,
5750 "ErrorCode,STBC_RX not supported");
5751 return 0;
5752 }
5753 }
5754
5755 val = get_param(cmd, "WIDTH");
5756 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005757 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005758 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005759 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005760 send_resp(dut, conn, SIGMA_ERROR,
5761 "ErrorCode,Failed to set WIDTH");
5762 return 0;
5763 }
5764 break;
5765 case DRIVER_ATHEROS:
5766 if (ath_set_width(dut, conn, intf, val) < 0)
5767 return 0;
5768 break;
5769 default:
5770 sigma_dut_print(dut, DUT_MSG_ERROR,
5771 "Setting WIDTH not supported");
5772 break;
5773 }
5774 }
5775
5776 val = get_param(cmd, "SMPS");
5777 if (val) {
5778 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5779 send_resp(dut, conn, SIGMA_ERROR,
5780 "ErrorCode,SMPS not supported");
5781 return 0;
5782 }
5783
5784 val = get_param(cmd, "TXSP_STREAM");
5785 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005786 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005787 case DRIVER_WCN:
5788 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5789 send_resp(dut, conn, SIGMA_ERROR,
5790 "ErrorCode,Failed to set TXSP_STREAM");
5791 return 0;
5792 }
5793 break;
5794 case DRIVER_ATHEROS:
5795 ath_sta_set_txsp_stream(dut, intf, val);
5796 break;
5797 default:
5798 sigma_dut_print(dut, DUT_MSG_ERROR,
5799 "Setting TXSP_STREAM not supported");
5800 break;
5801 }
5802 }
5803
5804 val = get_param(cmd, "RXSP_STREAM");
5805 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005806 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005807 case DRIVER_WCN:
5808 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5809 send_resp(dut, conn, SIGMA_ERROR,
5810 "ErrorCode,Failed to set RXSP_STREAM");
5811 return 0;
5812 }
5813 break;
5814 case DRIVER_ATHEROS:
5815 ath_sta_set_rxsp_stream(dut, intf, val);
5816 break;
5817 default:
5818 sigma_dut_print(dut, DUT_MSG_ERROR,
5819 "Setting RXSP_STREAM not supported");
5820 break;
5821 }
5822 }
5823
5824 val = get_param(cmd, "DYN_BW_SGNL");
5825 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005826 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005827 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08005828 if (strcasecmp(val, "enable") == 0) {
5829 snprintf(buf, sizeof(buf),
5830 "iwpriv %s cwmenable 1", intf);
5831 if (system(buf) != 0) {
5832 sigma_dut_print(dut, DUT_MSG_ERROR,
5833 "iwpriv cwmenable 1 failed");
5834 return 0;
5835 }
5836 } else if (strcasecmp(val, "disable") == 0) {
5837 snprintf(buf, sizeof(buf),
5838 "iwpriv %s cwmenable 0", intf);
5839 if (system(buf) != 0) {
5840 sigma_dut_print(dut, DUT_MSG_ERROR,
5841 "iwpriv cwmenable 0 failed");
5842 return 0;
5843 }
5844 } else {
5845 sigma_dut_print(dut, DUT_MSG_ERROR,
5846 "Unsupported DYN_BW_SGL");
5847 }
5848
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005849 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5850 if (system(buf) != 0) {
5851 sigma_dut_print(dut, DUT_MSG_ERROR,
5852 "Failed to set cts_cbw in DYN_BW_SGNL");
5853 return 0;
5854 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005855 break;
5856 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005857 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005858 ath_config_dyn_bw_sig(dut, intf, val);
5859 break;
5860 default:
5861 sigma_dut_print(dut, DUT_MSG_ERROR,
5862 "Failed to set DYN_BW_SGNL");
5863 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005864 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005865 }
5866
5867 val = get_param(cmd, "RTS_FORCE");
5868 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005869 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005870 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305871 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005872 sigma_dut_print(dut, DUT_MSG_ERROR,
5873 "Failed to set RTS_FORCE 64");
5874 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03005875 res = snprintf(buf, sizeof(buf),
5876 "wifitool %s beeliner_fw_test 100 1",
5877 intf);
5878 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08005879 sigma_dut_print(dut, DUT_MSG_ERROR,
5880 "wifitool beeliner_fw_test 100 1 failed");
5881 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005882 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305883 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005884 sigma_dut_print(dut, DUT_MSG_ERROR,
5885 "Failed to set RTS_FORCE 2347");
5886 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005887 } else {
5888 send_resp(dut, conn, SIGMA_ERROR,
5889 "ErrorCode,RTS_FORCE value not supported");
5890 return 0;
5891 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005892 }
5893
5894 val = get_param(cmd, "CTS_WIDTH");
5895 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005896 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005897 case DRIVER_WCN:
5898 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
5899 send_resp(dut, conn, SIGMA_ERROR,
5900 "ErrorCode,Failed to set CTS_WIDTH");
5901 return 0;
5902 }
5903 break;
5904 case DRIVER_ATHEROS:
5905 ath_set_cts_width(dut, intf, val);
5906 break;
5907 default:
5908 sigma_dut_print(dut, DUT_MSG_ERROR,
5909 "Setting CTS_WIDTH not supported");
5910 break;
5911 }
5912 }
5913
5914 val = get_param(cmd, "BW_SGNL");
5915 if (val) {
5916 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005917 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005918 } else if (strcasecmp(val, "Disable") == 0) {
5919 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005920 } else {
5921 send_resp(dut, conn, SIGMA_ERROR,
5922 "ErrorCode,BW_SGNL value not supported");
5923 return 0;
5924 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005925 }
5926
5927 val = get_param(cmd, "Band");
5928 if (val) {
5929 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
5930 /* STA supports all bands by default */
5931 } else {
5932 send_resp(dut, conn, SIGMA_ERROR,
5933 "ErrorCode,Unsupported Band");
5934 return 0;
5935 }
5936 }
5937
5938 val = get_param(cmd, "zero_crc");
5939 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005940 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005941 case DRIVER_ATHEROS:
5942 ath_set_zero_crc(dut, val);
5943 break;
5944 default:
5945 break;
5946 }
5947 }
5948
5949 return 1;
5950}
5951
5952
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005953static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
5954{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005955 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005956#ifdef __linux__
5957 case DRIVER_WIL6210:
5958 return wil6210_set_force_mcs(dut, force, mcs);
5959#endif /* __linux__ */
5960 default:
5961 sigma_dut_print(dut, DUT_MSG_ERROR,
5962 "Unsupported sta_set_force_mcs with the current driver");
5963 return -1;
5964 }
5965}
5966
5967
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005968static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
5969{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005970 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005971#ifdef __linux__
5972 case DRIVER_WIL6210:
5973 return wil6210_force_rsn_ie(dut, state);
5974#endif /* __linux__ */
5975 default:
5976 sigma_dut_print(dut, DUT_MSG_ERROR,
5977 "Unsupported sta_60g_force_rsn_ie with the current driver");
5978 return -1;
5979 }
5980}
5981
5982
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005983static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
5984 struct sigma_cmd *cmd)
5985{
5986 const char *val;
5987 char buf[100];
5988
5989 val = get_param(cmd, "MSDUSize");
5990 if (val) {
5991 int mtu;
5992
5993 dut->amsdu_size = atoi(val);
5994 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
5995 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
5996 sigma_dut_print(dut, DUT_MSG_ERROR,
5997 "MSDUSize %d is above max %d or below min %d",
5998 dut->amsdu_size,
5999 IEEE80211_MAX_DATA_LEN_DMG,
6000 IEEE80211_SNAP_LEN_DMG);
6001 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006002 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006003 }
6004
6005 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
6006 sigma_dut_print(dut, DUT_MSG_DEBUG,
6007 "Setting amsdu_size to %d", mtu);
6008 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006009 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006010
6011 if (system(buf) != 0) {
6012 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
6013 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006014 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006015 }
6016 }
6017
6018 val = get_param(cmd, "BAckRcvBuf");
6019 if (val) {
6020 dut->back_rcv_buf = atoi(val);
6021 if (dut->back_rcv_buf == 0) {
6022 sigma_dut_print(dut, DUT_MSG_ERROR,
6023 "Failed to convert %s or value is 0",
6024 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006025 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006026 }
6027
6028 sigma_dut_print(dut, DUT_MSG_DEBUG,
6029 "Setting BAckRcvBuf to %s", val);
6030 }
6031
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006032 val = get_param(cmd, "MCS_FixedRate");
6033 if (val) {
6034 if (sta_set_force_mcs(dut, 1, atoi(val))) {
6035 sigma_dut_print(dut, DUT_MSG_ERROR,
6036 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006037 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006038 }
6039 }
6040
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006041 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006042}
6043
6044
6045static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
6046 struct sigma_cmd *cmd)
6047{
6048 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006049 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006050 const char *val;
6051 char buf[100];
6052
6053 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006054 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006055 if (wpa_command(ifname, "PING") != 0) {
6056 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006057 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006058 }
6059
6060 wpa_command(ifname, "FLUSH");
6061 net_id = add_network_common(dut, conn, ifname, cmd);
6062 if (net_id < 0) {
6063 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
6064 return net_id;
6065 }
6066
6067 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
6068 if (set_network(ifname, net_id, "mode", "2") < 0) {
6069 sigma_dut_print(dut, DUT_MSG_ERROR,
6070 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006071 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006072 }
6073
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006074 if (set_network(ifname, net_id, "pbss", "1") < 0)
6075 return -2;
6076
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006077 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006078 "Supplicant set network with mode 2. network_id %d",
6079 net_id);
6080
6081 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6082 sigma_dut_print(dut, DUT_MSG_INFO,
6083 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006084 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006085 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006086
6087 val = get_param(cmd, "Security");
6088 if (val && strcasecmp(val, "OPEN") == 0) {
6089 dut->ap_key_mgmt = AP_OPEN;
6090 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6091 sigma_dut_print(dut, DUT_MSG_ERROR,
6092 "Failed to set supplicant to %s security",
6093 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006094 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006095 }
6096 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6097 dut->ap_key_mgmt = AP_WPA2_PSK;
6098 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6099 sigma_dut_print(dut, DUT_MSG_ERROR,
6100 "Failed to set supplicant to %s security",
6101 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006102 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006103 }
6104
6105 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6106 sigma_dut_print(dut, DUT_MSG_ERROR,
6107 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006108 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006109 }
6110 } else if (val) {
6111 sigma_dut_print(dut, DUT_MSG_ERROR,
6112 "Requested Security %s is not supported on 60GHz",
6113 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006114 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006115 }
6116
6117 val = get_param(cmd, "Encrypt");
6118 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6119 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6120 sigma_dut_print(dut, DUT_MSG_ERROR,
6121 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006122 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006123 }
6124 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6125 sigma_dut_print(dut, DUT_MSG_ERROR,
6126 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006127 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006128 }
6129 } else if (val) {
6130 sigma_dut_print(dut, DUT_MSG_ERROR,
6131 "Requested Encrypt %s is not supported on 60 GHz",
6132 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006133 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006134 }
6135
6136 val = get_param(cmd, "PSK");
6137 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6138 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6139 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006140 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006141 }
6142
6143 /* Convert 60G channel to freq */
6144 switch (dut->ap_channel) {
6145 case 1:
6146 val = "58320";
6147 break;
6148 case 2:
6149 val = "60480";
6150 break;
6151 case 3:
6152 val = "62640";
6153 break;
6154 default:
6155 sigma_dut_print(dut, DUT_MSG_ERROR,
6156 "Failed to configure channel %d. Not supported",
6157 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006158 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006159 }
6160
6161 if (set_network(ifname, net_id, "frequency", val) < 0) {
6162 sigma_dut_print(dut, DUT_MSG_ERROR,
6163 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006164 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006165 }
6166
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006167 if (dut->eap_fragment) {
6168 sigma_dut_print(dut, DUT_MSG_DEBUG,
6169 "Set EAP fragment size to 128 bytes.");
6170 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6171 return ERROR_SEND_STATUS;
6172 }
6173
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006174 sigma_dut_print(dut, DUT_MSG_DEBUG,
6175 "Supplicant set network with frequency");
6176
6177 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6178 if (wpa_command(ifname, buf) < 0) {
6179 sigma_dut_print(dut, DUT_MSG_INFO,
6180 "Failed to select network id %d on %s",
6181 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006182 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006183 }
6184
6185 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6186
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006187 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006188}
6189
6190
Lior David67543f52017-01-03 19:04:22 +02006191static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6192{
6193 char buf[128], fname[128];
6194 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006195 int res;
Lior David67543f52017-01-03 19:04:22 +02006196
6197 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6198 sigma_dut_print(dut, DUT_MSG_ERROR,
6199 "failed to get wil6210 debugfs dir");
6200 return -1;
6201 }
6202
Jouni Malinen3aa72862019-05-29 23:14:51 +03006203 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6204 if (res < 0 || res >= sizeof(fname))
6205 return -1;
Lior David67543f52017-01-03 19:04:22 +02006206 f = fopen(fname, "w");
6207 if (!f) {
6208 sigma_dut_print(dut, DUT_MSG_ERROR,
6209 "failed to open: %s", fname);
6210 return -1;
6211 }
6212
6213 fprintf(f, "%d\n", abft_len);
6214 fclose(f);
6215
6216 return 0;
6217}
6218
6219
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006220int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6221 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006222{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006223 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006224 case DRIVER_WIL6210:
6225 return wil6210_set_abft_len(dut, abft_len);
6226 default:
6227 sigma_dut_print(dut, DUT_MSG_ERROR,
6228 "set abft_len not supported");
6229 return -1;
6230 }
6231}
6232
6233
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006234static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6235 struct sigma_cmd *cmd)
6236{
6237 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006238 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006239
6240 if (dut->dev_role != DEVROLE_PCP) {
6241 send_resp(dut, conn, SIGMA_INVALID,
6242 "ErrorCode,Invalid DevRole");
6243 return 0;
6244 }
6245
6246 val = get_param(cmd, "SSID");
6247 if (val) {
6248 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6249 send_resp(dut, conn, SIGMA_INVALID,
6250 "ErrorCode,Invalid SSID");
6251 return -1;
6252 }
6253
Peng Xub8fc5cc2017-05-10 17:27:28 -07006254 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006255 }
6256
6257 val = get_param(cmd, "CHANNEL");
6258 if (val) {
6259 const char *pos;
6260
6261 dut->ap_channel = atoi(val);
6262 pos = strchr(val, ';');
6263 if (pos) {
6264 pos++;
6265 dut->ap_channel_1 = atoi(pos);
6266 }
6267 }
6268
6269 switch (dut->ap_channel) {
6270 case 1:
6271 case 2:
6272 case 3:
6273 break;
6274 default:
6275 sigma_dut_print(dut, DUT_MSG_ERROR,
6276 "Channel %d is not supported", dut->ap_channel);
6277 send_resp(dut, conn, SIGMA_ERROR,
6278 "Requested channel is not supported");
6279 return -1;
6280 }
6281
6282 val = get_param(cmd, "BCNINT");
6283 if (val)
6284 dut->ap_bcnint = atoi(val);
6285
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006286 val = get_param(cmd, "AllocType");
6287 if (val) {
6288 send_resp(dut, conn, SIGMA_ERROR,
6289 "ErrorCode,AllocType is not supported yet");
6290 return -1;
6291 }
6292
6293 val = get_param(cmd, "PercentBI");
6294 if (val) {
6295 send_resp(dut, conn, SIGMA_ERROR,
6296 "ErrorCode,PercentBI is not supported yet");
6297 return -1;
6298 }
6299
6300 val = get_param(cmd, "CBAPOnly");
6301 if (val) {
6302 send_resp(dut, conn, SIGMA_ERROR,
6303 "ErrorCode,CBAPOnly is not supported yet");
6304 return -1;
6305 }
6306
6307 val = get_param(cmd, "AMPDU");
6308 if (val) {
6309 if (strcasecmp(val, "Enable") == 0)
6310 dut->ap_ampdu = 1;
6311 else if (strcasecmp(val, "Disable") == 0)
6312 dut->ap_ampdu = 2;
6313 else {
6314 send_resp(dut, conn, SIGMA_ERROR,
6315 "ErrorCode,AMPDU value is not Enable nor Disabled");
6316 return -1;
6317 }
6318 }
6319
6320 val = get_param(cmd, "AMSDU");
6321 if (val) {
6322 if (strcasecmp(val, "Enable") == 0)
6323 dut->ap_amsdu = 1;
6324 else if (strcasecmp(val, "Disable") == 0)
6325 dut->ap_amsdu = 2;
6326 }
6327
6328 val = get_param(cmd, "NumMSDU");
6329 if (val) {
6330 send_resp(dut, conn, SIGMA_ERROR,
6331 "ErrorCode, NumMSDU is not supported yet");
6332 return -1;
6333 }
6334
6335 val = get_param(cmd, "ABFTLRang");
6336 if (val) {
6337 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006338 "ABFTLRang parameter %s", val);
6339 if (strcmp(val, "Gt1") == 0)
6340 abft_len = 2; /* 2 slots in this case */
6341 }
6342
6343 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6344 send_resp(dut, conn, SIGMA_ERROR,
6345 "ErrorCode, Can't set ABFT length");
6346 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006347 }
6348
6349 if (sta_pcp_start(dut, conn, cmd) < 0) {
6350 send_resp(dut, conn, SIGMA_ERROR,
6351 "ErrorCode, Can't start PCP role");
6352 return -1;
6353 }
6354
6355 return sta_set_60g_common(dut, conn, cmd);
6356}
6357
6358
6359static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6360 struct sigma_cmd *cmd)
6361{
6362 const char *val = get_param(cmd, "DiscoveryMode");
6363
6364 if (dut->dev_role != DEVROLE_STA) {
6365 send_resp(dut, conn, SIGMA_INVALID,
6366 "ErrorCode,Invalid DevRole");
6367 return 0;
6368 }
6369
6370 if (val) {
6371 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6372 /* Ignore Discovery mode till Driver expose API. */
6373#if 0
6374 if (strcasecmp(val, "1") == 0) {
6375 send_resp(dut, conn, SIGMA_INVALID,
6376 "ErrorCode,DiscoveryMode 1 not supported");
6377 return 0;
6378 }
6379
6380 if (strcasecmp(val, "0") == 0) {
6381 /* OK */
6382 } else {
6383 send_resp(dut, conn, SIGMA_INVALID,
6384 "ErrorCode,DiscoveryMode not supported");
6385 return 0;
6386 }
6387#endif
6388 }
6389
6390 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006391 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006392 return sta_set_60g_common(dut, conn, cmd);
6393}
6394
6395
Jouni Malinenf7222712019-06-13 01:50:21 +03006396static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6397 struct sigma_conn *conn,
6398 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006399{
6400 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006401 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306402
Jouni Malinened77e672018-01-10 16:45:13 +02006403 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006404 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006405 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306406 wpa_command(intf, "DISCONNECT");
6407 return 1;
6408 }
6409
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006410 disconnect_station(dut);
6411 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6412 * due to cached results. */
6413 wpa_command(intf, "SET ignore_old_scan_res 1");
6414 wpa_command(intf, "BSS_FLUSH");
6415 return 1;
6416}
6417
6418
Jouni Malinenf7222712019-06-13 01:50:21 +03006419static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6420 struct sigma_conn *conn,
6421 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006422{
6423 const char *intf = get_param(cmd, "Interface");
6424 const char *bssid = get_param(cmd, "bssid");
6425 const char *val = get_param(cmd, "CHANNEL");
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006426 const char *freq_val = get_param(cmd, "ChnlFreq");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006427 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306428 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306429 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006430 int res;
6431 int chan = 0;
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006432 int freq = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006433 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306434 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006435 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006436
6437 if (bssid == NULL) {
6438 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6439 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006440 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006441 }
6442
6443 if (val)
6444 chan = atoi(val);
6445
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006446 if (freq_val)
6447 freq = atoi(freq_val);
6448
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006449 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6450 /* The current network may be from sta_associate or
6451 * sta_hs2_associate
6452 */
6453 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6454 0 ||
6455 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006456 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006457 }
6458
6459 ctrl = open_wpa_mon(intf);
6460 if (ctrl == NULL) {
6461 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6462 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006463 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006464 }
6465
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006466 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05306467 sizeof(result)) < 0 ||
6468 strncmp(result, "COMPLETED", 9) != 0) {
6469 sigma_dut_print(dut, DUT_MSG_DEBUG,
6470 "sta_reassoc: Not connected");
6471 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006472 } else if (dut->sta_ft_ds) {
6473 sigma_dut_print(dut, DUT_MSG_DEBUG,
6474 "sta_reassoc: Use FT-over-DS");
6475 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306476 }
6477
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306478 if (dut->rsne_override) {
6479#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006480 if (get_driver_type(dut) == DRIVER_WCN &&
6481 dut->config_rsnie == 0) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05306482 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306483 dut->config_rsnie = 1;
6484 }
6485#endif /* NL80211_SUPPORT */
6486 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6487 dut->rsne_override);
6488 if (wpa_command(intf, buf) < 0) {
6489 send_resp(dut, conn, SIGMA_ERROR,
6490 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6491 return 0;
6492 }
6493 }
6494
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006495 if (ft_ds) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006496 if (chan || freq) {
6497 if (!freq)
6498 freq = channel_to_freq(dut, chan);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006499 if (!freq) {
6500 sigma_dut_print(dut, DUT_MSG_ERROR,
6501 "Invalid channel number provided: %d",
6502 chan);
6503 send_resp(dut, conn, SIGMA_INVALID,
6504 "ErrorCode,Invalid channel number");
6505 goto close_mon_conn;
6506 }
6507 res = snprintf(buf, sizeof(buf),
6508 "SCAN TYPE=ONLY freq=%d", freq);
6509 } else {
6510 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6511 }
6512 if (res < 0 || res >= (int) sizeof(buf)) {
6513 send_resp(dut, conn, SIGMA_ERROR,
6514 "ErrorCode,snprintf failed");
6515 goto close_mon_conn;
6516 }
6517 if (wpa_command(intf, buf) < 0) {
6518 sigma_dut_print(dut, DUT_MSG_INFO,
6519 "Failed to start scan");
6520 send_resp(dut, conn, SIGMA_ERROR,
6521 "ErrorCode,scan failed");
6522 goto close_mon_conn;
6523 }
6524
6525 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6526 buf, sizeof(buf));
6527 if (res < 0) {
6528 sigma_dut_print(dut, DUT_MSG_INFO,
6529 "Scan did not complete");
6530 send_resp(dut, conn, SIGMA_ERROR,
6531 "ErrorCode,scan did not complete");
6532 goto close_mon_conn;
6533 }
6534
6535 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6536 if (res > 0 && res < (int) sizeof(buf))
6537 res = wpa_command(intf, buf);
6538
6539 if (res < 0 || res >= (int) sizeof(buf)) {
6540 send_resp(dut, conn, SIGMA_ERROR,
6541 "errorCode,FT_DS command failed");
6542 status = STATUS_SENT_ERROR;
6543 goto close_mon_conn;
6544 }
6545 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006546 if (chan || freq) {
6547 if (!freq)
6548 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306549 if (!freq) {
6550 sigma_dut_print(dut, DUT_MSG_ERROR,
6551 "Invalid channel number provided: %d",
6552 chan);
6553 send_resp(dut, conn, SIGMA_INVALID,
6554 "ErrorCode,Invalid channel number");
6555 goto close_mon_conn;
6556 }
6557 res = snprintf(buf, sizeof(buf),
6558 "SCAN TYPE=ONLY freq=%d", freq);
6559 } else {
6560 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6561 }
6562 if (res < 0 || res >= (int) sizeof(buf)) {
6563 send_resp(dut, conn, SIGMA_ERROR,
6564 "ErrorCode,snprintf failed");
6565 goto close_mon_conn;
6566 }
6567 if (wpa_command(intf, buf) < 0) {
6568 sigma_dut_print(dut, DUT_MSG_INFO,
6569 "Failed to start scan");
6570 send_resp(dut, conn, SIGMA_ERROR,
6571 "ErrorCode,scan failed");
6572 goto close_mon_conn;
6573 }
6574
6575 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6576 buf, sizeof(buf));
6577 if (res < 0) {
6578 sigma_dut_print(dut, DUT_MSG_INFO,
6579 "Scan did not complete");
6580 send_resp(dut, conn, SIGMA_ERROR,
6581 "ErrorCode,scan did not complete");
6582 goto close_mon_conn;
6583 }
6584
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006585 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6586 < 0) {
6587 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6588 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006589 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306590 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006591 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306592 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006593 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306594 if (res < 0 || res >= (int) sizeof(buf) ||
6595 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006596 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306597 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306598 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006599 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006600 sigma_dut_print(dut, DUT_MSG_INFO,
6601 "sta_reassoc: Run %s successful", buf);
6602 } else if (wpa_command(intf, "REASSOCIATE")) {
6603 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6604 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306605 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006606 }
6607
6608 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6609 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306610 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006611 send_resp(dut, conn, SIGMA_ERROR,
6612 "errorCode,Connection did not complete");
6613 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306614 goto close_mon_conn;
6615 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006616 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006617
Ashwini Patil467efef2017-05-25 12:18:27 +05306618close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006619 wpa_ctrl_detach(ctrl);
6620 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306621 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006622}
6623
6624
6625static void hs2_clear_credentials(const char *intf)
6626{
6627 wpa_command(intf, "REMOVE_CRED all");
6628}
6629
6630
Lior Davidcc88b562017-01-03 18:52:09 +02006631#ifdef __linux__
6632static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6633 unsigned int *aid)
6634{
Lior David0fe101e2017-03-09 16:09:50 +02006635 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006636
Lior David0fe101e2017-03-09 16:09:50 +02006637 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006638}
6639#endif /* __linux__ */
6640
6641
6642static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6643 unsigned int *aid)
6644{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006645 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02006646#ifdef __linux__
6647 case DRIVER_WIL6210:
6648 return wil6210_get_aid(dut, bssid, aid);
6649#endif /* __linux__ */
6650 default:
6651 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6652 return -1;
6653 }
6654}
6655
6656
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006657static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6658 struct sigma_cmd *cmd)
6659{
6660 char buf[MAX_CMD_LEN];
6661 char bss_list[MAX_CMD_LEN];
6662 const char *parameter = get_param(cmd, "Parameter");
6663
6664 if (parameter == NULL)
6665 return -1;
6666
Lior Davidcc88b562017-01-03 18:52:09 +02006667 if (strcasecmp(parameter, "AID") == 0) {
6668 unsigned int aid = 0;
6669 char bssid[20];
6670
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006671 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02006672 bssid, sizeof(bssid)) < 0) {
6673 sigma_dut_print(dut, DUT_MSG_ERROR,
6674 "could not get bssid");
6675 return -2;
6676 }
6677
6678 if (sta_get_aid_60g(dut, bssid, &aid))
6679 return -2;
6680
6681 snprintf(buf, sizeof(buf), "aid,%d", aid);
6682 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6683 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6684 return 0;
6685 }
6686
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006687 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6688 char *bss_line;
6689 char *bss_id = NULL;
6690 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306691 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006692
6693 if (ifname == NULL) {
6694 sigma_dut_print(dut, DUT_MSG_INFO,
6695 "For get DiscoveredDevList need Interface name.");
6696 return -1;
6697 }
6698
6699 /*
6700 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6701 * of BSSIDs in "bssid=<BSSID>\n"
6702 */
6703 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6704 bss_list,
6705 sizeof(bss_list)) < 0) {
6706 sigma_dut_print(dut, DUT_MSG_ERROR,
6707 "Failed to get bss list");
6708 return -1;
6709 }
6710
6711 sigma_dut_print(dut, DUT_MSG_DEBUG,
6712 "bss list for ifname:%s is:%s",
6713 ifname, bss_list);
6714
6715 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306716 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006717 while (bss_line) {
6718 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6719 bss_id) {
6720 int len;
6721
6722 len = snprintf(buf + strlen(buf),
6723 sizeof(buf) - strlen(buf),
6724 ",%s", bss_id);
6725 free(bss_id);
6726 bss_id = NULL;
6727 if (len < 0) {
6728 sigma_dut_print(dut,
6729 DUT_MSG_ERROR,
6730 "Failed to read BSSID");
6731 send_resp(dut, conn, SIGMA_ERROR,
6732 "ErrorCode,Failed to read BSS ID");
6733 return 0;
6734 }
6735
6736 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6737 sigma_dut_print(dut,
6738 DUT_MSG_ERROR,
6739 "Response buf too small for list");
6740 send_resp(dut, conn,
6741 SIGMA_ERROR,
6742 "ErrorCode,Response buf too small for list");
6743 return 0;
6744 }
6745 }
6746
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306747 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006748 }
6749
6750 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6751 buf);
6752 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6753 return 0;
6754 }
6755
6756 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6757 return 0;
6758}
6759
6760
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006761static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6762 struct sigma_cmd *cmd)
6763{
6764 char buf[MAX_CMD_LEN];
6765 const char *parameter = get_param(cmd, "Parameter");
6766
6767 if (!parameter)
6768 return -1;
6769
6770 if (strcasecmp(parameter, "RSSI") == 0) {
6771 char rssi[10];
6772
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006773 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006774 rssi, sizeof(rssi)) < 0) {
6775 sigma_dut_print(dut, DUT_MSG_ERROR,
6776 "Could not get RSSI");
6777 return -2;
6778 }
6779
6780 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6781 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6782 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6783 return 0;
6784 }
6785
6786 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6787 return 0;
6788}
6789
6790
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05306791#ifdef NL80211_SUPPORT
6792
6793struct station_info {
6794 uint64_t filled;
6795 uint32_t beacon_mic_error_count;
6796 uint32_t beacon_replay_count;
6797};
6798
6799
6800static int qca_get_sta_info_handler(struct nl_msg *msg, void *arg)
6801{
6802 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6803 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6804 struct station_info *data = arg;
6805 struct nlattr *info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1];
6806 static struct nla_policy info_policy[
6807 QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1] = {
6808 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT] = {
6809 .type = NLA_U32
6810 },
6811 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT] = {
6812 .type = NLA_U32
6813 },
6814 };
6815
6816 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6817 genlmsg_attrlen(gnlh, 0), NULL);
6818
6819 if (!tb[NL80211_ATTR_VENDOR_DATA])
6820 return NL_SKIP;
6821
6822 if (nla_parse_nested(info, QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX,
6823 tb[NL80211_ATTR_VENDOR_DATA], info_policy)) {
6824 return NL_SKIP;
6825 }
6826
6827 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]) {
6828 data->filled |=
6829 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT);
6830 data->beacon_mic_error_count =
6831 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]);
6832 }
6833
6834 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]) {
6835 data->filled |=
6836 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT);
6837 data->beacon_replay_count =
6838 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]);
6839 }
6840
6841 return NL_SKIP;
6842}
6843
6844
6845static int qca_nl80211_get_sta_info(struct sigma_dut *dut, const char *intf,
6846 struct station_info *sta_data)
6847{
6848 struct nl_msg *msg;
6849 int ifindex, ret;
6850
6851 ifindex = if_nametoindex(intf);
6852 if (ifindex == 0) {
6853 sigma_dut_print(dut, DUT_MSG_ERROR,
6854 "%s: Index for interface %s not found",
6855 __func__, intf);
6856 return -1;
6857 }
6858
6859 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6860 NL80211_CMD_VENDOR)) ||
6861 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6862 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6863 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6864 QCA_NL80211_VENDOR_SUBCMD_GET_STA_INFO)) {
6865 sigma_dut_print(dut, DUT_MSG_ERROR,
6866 "%s: err in adding vendor_cmd", __func__);
6867 nlmsg_free(msg);
6868 return -1;
6869 }
6870
6871 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg,
6872 qca_get_sta_info_handler, sta_data);
6873 if (ret) {
6874 sigma_dut_print(dut, DUT_MSG_ERROR,
6875 "%s: err in send_and_recv_msgs, ret=%d",
6876 __func__, ret);
6877 }
6878 return ret;
6879}
6880#endif /* NL80211_SUPPORT */
6881
6882
6883static int get_bip_mic_error_count(struct sigma_dut *dut,
6884 const char *ifname,
6885 unsigned int *count)
6886{
6887#ifdef NL80211_SUPPORT
6888 struct station_info sta_data;
6889#endif /* NL80211_SUPPORT */
6890
6891 if (get_driver_type(dut) != DRIVER_WCN) {
6892 sigma_dut_print(dut, DUT_MSG_ERROR,
6893 "BIP MIC error count not supported");
6894 return -1;
6895 }
6896
6897#ifdef NL80211_SUPPORT
6898 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
6899 !(sta_data.filled &
6900 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT))) {
6901 sigma_dut_print(dut, DUT_MSG_ERROR,
6902 "BIP MIC error count fetching failed");
6903 return -1;
6904 }
6905
6906 *count = sta_data.beacon_mic_error_count;
6907 return 0;
6908#else /* NL80211_SUPPORT */
6909 sigma_dut_print(dut, DUT_MSG_ERROR,
6910 "BIP MIC error count cannot be fetched without NL80211_SUPPORT defined");
6911 return -1;
6912#endif /* NL80211_SUPPORT */
6913}
6914
6915
6916static int get_cmac_replay_count(struct sigma_dut *dut, const char *ifname,
6917 unsigned int *count)
6918{
6919#ifdef NL80211_SUPPORT
6920 struct station_info sta_data;
6921#endif /* NL80211_SUPPORT */
6922
6923 if (get_driver_type(dut) != DRIVER_WCN) {
6924 sigma_dut_print(dut, DUT_MSG_ERROR,
6925 "CMAC reply count not supported");
6926 return -1;
6927 }
6928
6929#ifdef NL80211_SUPPORT
6930 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
6931 !(sta_data.filled &
6932 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT))) {
6933 sigma_dut_print(dut, DUT_MSG_ERROR,
6934 "CMAC replay count fetching failed");
6935 return -1;
6936 }
6937
6938 *count = sta_data.beacon_replay_count;
6939 return 0;
6940#else /* NL80211_SUPPORT */
6941 sigma_dut_print(dut, DUT_MSG_ERROR,
6942 "CMAC replay count cannot be fetched without NL80211_SUPPORT defined");
6943 return -1;
6944#endif /* NL80211_SUPPORT */
6945}
6946
6947
6948static enum sigma_cmd_result sta_get_parameter_wpa3(struct sigma_dut *dut,
6949 struct sigma_conn *conn,
6950 struct sigma_cmd *cmd)
6951{
6952 char buf[MAX_CMD_LEN];
6953 const char *ifname = get_param(cmd, "interface");
6954 const char *parameter = get_param(cmd, "Parameter");
6955 unsigned int val;
6956
6957 if (!ifname || !parameter)
6958 return INVALID_SEND_STATUS;
6959
6960 if (strcasecmp(parameter, "BIPMICErrors") == 0) {
6961 if (get_bip_mic_error_count(dut, ifname, &val)) {
6962 send_resp(dut, conn, SIGMA_ERROR,
6963 "ErrorCode,Failed to get BIPMICErrors");
6964 return STATUS_SENT_ERROR;
6965 }
6966 snprintf(buf, sizeof(buf), "BIPMICErrors,%d", val);
6967 sigma_dut_print(dut, DUT_MSG_INFO, "BIPMICErrors %s", buf);
6968 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6969 return STATUS_SENT;
6970 }
6971
6972 if (strcasecmp(parameter, "CMACReplays") == 0) {
6973 if (get_cmac_replay_count(dut, ifname, &val)) {
6974 send_resp(dut, conn, SIGMA_ERROR,
6975 "ErrorCode,Failed to get CMACReplays");
6976 return STATUS_SENT_ERROR;
6977 }
6978 snprintf(buf, sizeof(buf), "CMACReplays,%d", val);
6979 sigma_dut_print(dut, DUT_MSG_INFO, "CMACReplays %s", buf);
6980 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6981 return STATUS_SENT;
6982 }
6983
6984 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6985 return STATUS_SENT_ERROR;
6986}
6987
6988
Jouni Malinenca0abd32020-02-09 20:18:10 +02006989static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
6990 struct sigma_conn *conn,
6991 struct sigma_cmd *cmd)
6992{
6993 const char *intf = get_param(cmd, "Interface");
6994 char buf[4096], bssid[20], resp[200], *pos, *tmp;
6995
6996 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
6997 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
6998 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
6999 send_resp(dut, conn, SIGMA_ERROR,
7000 "ErrorCode,PMKSA_GET not supported");
7001 return STATUS_SENT_ERROR;
7002 }
7003
7004 if (strncmp(buf, "FAIL", 4) == 0 ||
7005 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
7006 send_resp(dut, conn, SIGMA_ERROR,
7007 "ErrorCode,Could not find current network");
7008 return STATUS_SENT_ERROR;
7009 }
7010
7011 pos = buf;
7012 while (pos) {
7013 if (strncmp(pos, bssid, 17) == 0) {
7014 pos = strchr(pos, ' ');
7015 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307016 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007017 pos++;
7018 pos = strchr(pos, ' ');
7019 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307020 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007021 pos++;
7022 tmp = strchr(pos, ' ');
7023 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307024 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007025 *tmp = '\0';
7026 break;
7027 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02007028 pos = strchr(pos, '\n');
7029 if (pos)
7030 pos++;
7031 }
7032
7033 if (!pos) {
7034 send_resp(dut, conn, SIGMA_ERROR,
7035 "ErrorCode,PMK not available");
7036 return STATUS_SENT_ERROR;
7037 }
7038
7039 snprintf(resp, sizeof(resp), "PMK,%s", pos);
7040 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7041 return STATUS_SENT;
7042}
7043
7044
Jouni Malinenf7222712019-06-13 01:50:21 +03007045static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
7046 struct sigma_conn *conn,
7047 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007048{
7049 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02007050 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007051
Jouni Malinenca0abd32020-02-09 20:18:10 +02007052 if (!parameter)
7053 return INVALID_SEND_STATUS;
7054
7055 if (strcasecmp(parameter, "PMK") == 0)
7056 return sta_get_pmk(dut, conn, cmd);
7057
7058 if (!program)
7059 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007060
7061 if (strcasecmp(program, "P2PNFC") == 0)
7062 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
7063
7064 if (strcasecmp(program, "60ghz") == 0)
7065 return sta_get_parameter_60g(dut, conn, cmd);
7066
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007067 if (strcasecmp(program, "he") == 0)
7068 return sta_get_parameter_he(dut, conn, cmd);
7069
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007070#ifdef ANDROID_NAN
7071 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07007072 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007073#endif /* ANDROID_NAN */
7074
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007075#ifdef MIRACAST
7076 if (strcasecmp(program, "WFD") == 0 ||
7077 strcasecmp(program, "DisplayR2") == 0)
7078 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
7079#endif /* MIRACAST */
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05307080 if (strcasecmp(program, "WPA3") == 0)
7081 return sta_get_parameter_wpa3(dut, conn, cmd);
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007082
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007083 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7084 return 0;
7085}
7086
7087
7088static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
7089 const char *type)
7090{
7091 char buf[100];
7092
7093 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007094 run_iwpriv(dut, intf, "chwidth 2");
7095 run_iwpriv(dut, intf, "mode 11ACVHT80");
7096 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007097 }
7098
7099 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007100 run_iwpriv(dut, intf, "chwidth 0");
7101 run_iwpriv(dut, intf, "mode 11naht40");
7102 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007103 }
7104
7105 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007106 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007107
7108 /* Reset CTS width */
7109 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
7110 intf);
7111 if (system(buf) != 0) {
7112 sigma_dut_print(dut, DUT_MSG_ERROR,
7113 "wifitool %s beeliner_fw_test 54 0 failed",
7114 intf);
7115 }
7116
7117 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007118 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007119
7120 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
7121 if (system(buf) != 0) {
7122 sigma_dut_print(dut, DUT_MSG_ERROR,
7123 "iwpriv rts failed");
7124 }
7125 }
7126
7127 if (type && strcasecmp(type, "Testbed") == 0) {
7128 dut->testbed_flag_txsp = 1;
7129 dut->testbed_flag_rxsp = 1;
7130 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007131 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007132
7133 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007134 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007135
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007136 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007137
7138 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007139 run_iwpriv(dut, intf, "tx_stbc 0");
7140 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007141
7142 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007143 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007144 }
7145
7146 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007147 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07007148 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007149
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007150 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007151 }
7152}
7153
7154
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007155#ifdef NL80211_SUPPORT
7156static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
7157 enum he_mcs_config mcs)
7158{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307159 return wcn_wifi_test_config_set_u8(
7160 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS, mcs);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007161}
7162#endif /* NL80211_SUPPORT */
7163
7164
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007165static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
7166 const char *intf, int enable)
7167{
7168#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307169 return wcn_wifi_test_config_set_u8(
7170 dut, intf,
7171 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
7172 enable);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007173#else /* NL80211_SUPPORT */
7174 sigma_dut_print(dut, DUT_MSG_ERROR,
7175 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
7176 return -1;
7177#endif /* NL80211_SUPPORT */
7178}
7179
7180
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007181static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
7182 const char *intf, int enable)
7183{
7184#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307185 return wcn_wifi_test_config_set_u8(
7186 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7187 enable);
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007188#else /* NL80211_SUPPORT */
7189 sigma_dut_print(dut, DUT_MSG_ERROR,
7190 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7191 return -1;
7192#endif /* NL80211_SUPPORT */
7193}
7194
7195
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007196#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007197
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007198static int sta_set_he_testbed_def(struct sigma_dut *dut,
7199 const char *intf, int cfg)
7200{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307201 return wcn_wifi_test_config_set_u8(
7202 dut, intf,
7203 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7204 cfg);
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007205}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007206
7207
7208static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7209{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307210 return wcn_wifi_test_config_set_u8(
7211 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7212 cfg);
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007213}
7214
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007215#endif /* NL80211_SUPPORT */
7216
7217
Qiwei Caib6806972020-01-15 13:52:11 +08007218int sta_set_addba_buf_size(struct sigma_dut *dut,
7219 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007220{
7221#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307222 return wcn_wifi_test_config_set_u16(
7223 dut, intf,
7224 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE, bufsize);
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007225#else /* NL80211_SUPPORT */
7226 sigma_dut_print(dut, DUT_MSG_ERROR,
7227 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7228 return -1;
7229#endif /* NL80211_SUPPORT */
7230}
7231
7232
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007233static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
7234 int enable)
7235{
7236#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307237 return wcn_wifi_test_config_set_u8(
7238 dut, intf,
7239 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7240 enable);
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007241#else /* NL80211_SUPPORT */
7242 sigma_dut_print(dut, DUT_MSG_ERROR,
7243 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7244 return -1;
7245#endif /* NL80211_SUPPORT */
7246}
7247
7248
Arif Hussain9765f7d2018-07-03 08:28:26 -07007249static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7250 int val)
7251{
7252#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307253 return wcn_wifi_test_config_set_u8(
7254 dut, intf,
7255 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7256 val);
Arif Hussain9765f7d2018-07-03 08:28:26 -07007257#else /* NL80211_SUPPORT */
7258 sigma_dut_print(dut, DUT_MSG_ERROR,
7259 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7260 return -1;
7261#endif /* NL80211_SUPPORT */
7262}
7263
7264
Arif Hussain68d23f52018-07-11 13:39:08 -07007265#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007266static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7267 enum qca_wlan_he_mac_padding_dur val)
7268{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307269 return wcn_wifi_test_config_set_u8(
7270 dut, intf,
7271 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR, val);
Arif Hussain68d23f52018-07-11 13:39:08 -07007272}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007273#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007274
7275
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007276static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7277 int val)
7278{
7279#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307280 return wcn_wifi_test_config_set_u8(
7281 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7282 val);
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007283#else /* NL80211_SUPPORT */
7284 sigma_dut_print(dut, DUT_MSG_ERROR,
7285 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7286 return -1;
7287#endif /* NL80211_SUPPORT */
7288}
7289
7290
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007291#ifdef NL80211_SUPPORT
7292static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7293{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307294 return wcn_wifi_test_config_set_flag(
7295 dut, intf,
7296 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG);
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007297}
7298#endif /* NL80211_SUPPORT */
7299
7300
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007301static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7302 int val)
7303{
7304#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307305 return wcn_wifi_test_config_set_u8(
7306 dut, intf,
7307 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA, val);
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007308#else /* NL80211_SUPPORT */
7309 sigma_dut_print(dut, DUT_MSG_ERROR,
7310 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7311 return -1;
7312#endif /* NL80211_SUPPORT */
7313}
7314
7315
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007316static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7317 int val)
7318{
7319#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307320 return wcn_wifi_test_config_set_u8(
7321 dut, intf,
7322 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP, val);
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007323#else /* NL80211_SUPPORT */
7324 sigma_dut_print(dut, DUT_MSG_ERROR,
7325 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7326 return -1;
7327#endif /* NL80211_SUPPORT */
7328}
7329
7330
Arif Hussain480d5f42019-03-12 14:40:42 -07007331static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7332 int val)
7333{
7334#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307335 return wcn_wifi_test_config_set_u8(
7336 dut, intf,
7337 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT, val);
Arif Hussain480d5f42019-03-12 14:40:42 -07007338#else /* NL80211_SUPPORT */
7339 sigma_dut_print(dut, DUT_MSG_ERROR,
7340 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7341 return -1;
7342#endif /* NL80211_SUPPORT */
7343}
7344
7345
Srinivas Girigowda0525e292020-11-12 13:28:21 -08007346static int sta_set_fullbw_ulmumimo(struct sigma_dut *dut, const char *intf,
7347 int val)
7348{
7349#ifdef NL80211_SUPPORT
7350 return wcn_wifi_test_config_set_u8(
7351 dut, intf,
7352 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FULL_BW_UL_MU_MIMO, val);
7353#else /* NL80211_SUPPORT */
7354 sigma_dut_print(dut, DUT_MSG_ERROR,
7355 "Full BW UL MU MIMO cannot be changed without NL80211_SUPPORT defined");
7356 return -1;
7357#endif /* NL80211_SUPPORT */
7358}
7359
7360
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007361static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7362 const char *type)
7363{
7364 char buf[60];
7365
7366 if (dut->program == PROGRAM_HE) {
7367 /* resetting phymode to auto in case of HE program */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05307368 sta_set_phymode(dut, intf, "auto");
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007369
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007370 /* reset the rate to Auto rate */
7371 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7372 intf);
7373 if (system(buf) != 0) {
7374 sigma_dut_print(dut, DUT_MSG_ERROR,
7375 "iwpriv %s set_11ax_rate 0xff failed",
7376 intf);
7377 }
7378
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007379 /* reset the LDPC setting */
7380 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7381 if (system(buf) != 0) {
7382 sigma_dut_print(dut, DUT_MSG_ERROR,
7383 "iwpriv %s ldpc 1 failed", intf);
7384 }
7385
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007386 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05307387 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007388
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007389 /* remove all network profiles */
7390 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007391
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007392 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7393 sta_set_addba_buf_size(dut, intf, 64);
7394
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007395#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007396 /* Reset the device HE capabilities to its default supported
7397 * configuration. */
7398 sta_set_he_testbed_def(dut, intf, 0);
7399
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007400 /* Disable noackpolicy for all AC */
7401 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7402 sigma_dut_print(dut, DUT_MSG_ERROR,
7403 "Disable of noackpolicy for all AC failed");
7404 }
7405#endif /* NL80211_SUPPORT */
7406
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007407 /* Enable WMM by default */
7408 if (wcn_sta_set_wmm(dut, intf, "on")) {
7409 sigma_dut_print(dut, DUT_MSG_ERROR,
7410 "Enable of WMM in sta_reset_default_wcn failed");
7411 }
7412
7413 /* Disable ADDBA_REJECT by default */
7414 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7415 sigma_dut_print(dut, DUT_MSG_ERROR,
7416 "Disable of addba_reject in sta_reset_default_wcn failed");
7417 }
7418
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007419 /* Enable sending of ADDBA by default */
7420 if (nlvendor_config_send_addba(dut, intf, 1)) {
7421 sigma_dut_print(dut, DUT_MSG_ERROR,
7422 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7423 }
7424
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007425 /* Enable AMPDU by default */
7426 iwpriv_sta_set_ampdu(dut, intf, 1);
7427
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007428#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08007429 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007430 sigma_dut_print(dut, DUT_MSG_ERROR,
7431 "Set LTF config to default in sta_reset_default_wcn failed");
7432 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007433
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007434 /* set the beamformee NSTS(maximum number of
7435 * space-time streams) to default DUT config
7436 */
7437 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007438 sigma_dut_print(dut, DUT_MSG_ERROR,
7439 "Failed to set BeamformeeSTS");
7440 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007441
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007442 if (sta_set_mac_padding_duration(
7443 dut, intf,
7444 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007445 sigma_dut_print(dut, DUT_MSG_ERROR,
7446 "Failed to set MAC padding duration");
7447 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007448
7449 if (sta_set_mu_edca_override(dut, intf, 0)) {
7450 sigma_dut_print(dut, DUT_MSG_ERROR,
7451 "ErrorCode,Failed to set MU EDCA override disable");
7452 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007453
7454 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7455 sigma_dut_print(dut, DUT_MSG_ERROR,
7456 "Failed to set OM ctrl supp");
7457 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007458
7459 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7460 sigma_dut_print(dut, DUT_MSG_ERROR,
7461 "Failed to set Tx SU PPDU enable");
7462 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007463
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007464 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7465 sigma_dut_print(dut, DUT_MSG_ERROR,
7466 "failed to send TB PPDU Tx cfg");
7467 }
7468
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007469 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7470 sigma_dut_print(dut, DUT_MSG_ERROR,
7471 "Failed to set OM ctrl reset");
7472 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007473
7474 /* +HTC-HE support default on */
7475 if (sta_set_he_htc_supp(dut, intf, 1)) {
7476 sigma_dut_print(dut, DUT_MSG_ERROR,
7477 "Setting of +HTC-HE support failed");
7478 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007479#endif /* NL80211_SUPPORT */
7480
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007481 if (sta_set_tx_beamformee(dut, intf, 1)) {
7482 sigma_dut_print(dut, DUT_MSG_ERROR,
7483 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7484 }
7485
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007486 wpa_command(intf, "SET oce 1");
7487
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007488 /* Set nss to 1 and MCS 0-7 in case of testbed */
7489 if (type && strcasecmp(type, "Testbed") == 0) {
7490#ifdef NL80211_SUPPORT
7491 int ret;
7492#endif /* NL80211_SUPPORT */
7493
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007494 wpa_command(intf, "SET oce 0");
7495
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007496 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7497 if (system(buf) != 0) {
7498 sigma_dut_print(dut, DUT_MSG_ERROR,
7499 "iwpriv %s nss failed", intf);
7500 }
7501
7502#ifdef NL80211_SUPPORT
7503 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7504 if (ret) {
7505 sigma_dut_print(dut, DUT_MSG_ERROR,
7506 "Setting of MCS failed, ret:%d",
7507 ret);
7508 }
7509#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007510
7511 /* Disable STBC as default */
7512 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007513
7514 /* Disable AMSDU as default */
7515 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007516
7517#ifdef NL80211_SUPPORT
7518 /* HE fragmentation default off */
7519 if (sta_set_he_fragmentation(dut, intf,
7520 HE_FRAG_DISABLE)) {
7521 sigma_dut_print(dut, DUT_MSG_ERROR,
7522 "Setting of HE fragmentation failed");
7523 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007524
7525 /* set the beamformee NSTS(maximum number of
7526 * space-time streams) to default testbed config
7527 */
7528 if (sta_set_beamformee_sts(dut, intf, 3)) {
7529 sigma_dut_print(dut, DUT_MSG_ERROR,
7530 "Failed to set BeamformeeSTS");
7531 }
7532
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007533 /* +HTC-HE support default off */
7534 if (sta_set_he_htc_supp(dut, intf, 0)) {
7535 sigma_dut_print(dut, DUT_MSG_ERROR,
7536 "Setting of +HTC-HE support failed");
7537 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007538
7539 /* Set device HE capabilities to testbed default
7540 * configuration. */
7541 if (sta_set_he_testbed_def(dut, intf, 1)) {
7542 sigma_dut_print(dut, DUT_MSG_DEBUG,
7543 "Failed to set HE defaults");
7544 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007545
7546 /* Disable VHT support in 2.4 GHz for testbed */
7547 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007548#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007549
7550 /* Enable WEP/TKIP with HE capability in testbed */
7551 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
7552 sigma_dut_print(dut, DUT_MSG_ERROR,
7553 "Enabling HE config with WEP/TKIP failed");
7554 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007555 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007556
7557 /* Defaults in case of DUT */
7558 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07007559 /* Enable STBC by default */
7560 wcn_sta_set_stbc(dut, intf, "1");
7561
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007562 /* set nss to 2 */
7563 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
7564 if (system(buf) != 0) {
7565 sigma_dut_print(dut, DUT_MSG_ERROR,
7566 "iwpriv %s nss 2 failed", intf);
7567 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007568 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007569
7570#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07007571 /* Set HE_MCS to 0-11 */
7572 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007573 sigma_dut_print(dut, DUT_MSG_ERROR,
7574 "Setting of MCS failed");
7575 }
7576#endif /* NL80211_SUPPORT */
7577
7578 /* Disable WEP/TKIP with HE capability in DUT */
7579 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
7580 sigma_dut_print(dut, DUT_MSG_ERROR,
7581 "Enabling HE config with WEP/TKIP failed");
7582 }
7583 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007584 }
7585}
7586
7587
Jouni Malinenf7222712019-06-13 01:50:21 +03007588static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
7589 struct sigma_conn *conn,
7590 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007591{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007592 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007593 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007594 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007595 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307596 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007597
Jouni Malinenb21f0542019-11-04 17:53:38 +02007598 if (dut->station_ifname_2g &&
7599 strcmp(dut->station_ifname_2g, intf) == 0)
7600 dut->use_5g = 0;
7601 else if (dut->station_ifname_5g &&
7602 strcmp(dut->station_ifname_5g, intf) == 0)
7603 dut->use_5g = 1;
7604
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007605 if (!program)
7606 program = get_param(cmd, "prog");
7607 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007608 dut->device_type = STA_unknown;
7609 type = get_param(cmd, "type");
7610 if (type && strcasecmp(type, "Testbed") == 0)
7611 dut->device_type = STA_testbed;
7612 if (type && strcasecmp(type, "DUT") == 0)
7613 dut->device_type = STA_dut;
7614
7615 if (dut->program == PROGRAM_TDLS) {
7616 /* Clear TDLS testing mode */
7617 wpa_command(intf, "SET tdls_disabled 0");
7618 wpa_command(intf, "SET tdls_testing 0");
7619 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007620 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05307621 /* Enable the WCN driver in TDLS Explicit trigger mode
7622 */
7623 wpa_command(intf, "SET tdls_external_control 0");
7624 wpa_command(intf, "SET tdls_trigger_control 0");
7625 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007626 }
7627
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007628#ifdef MIRACAST
7629 if (dut->program == PROGRAM_WFD ||
7630 dut->program == PROGRAM_DISPLAYR2)
7631 miracast_sta_reset_default(dut, conn, cmd);
7632#endif /* MIRACAST */
7633
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007634 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007635 case DRIVER_ATHEROS:
7636 sta_reset_default_ath(dut, intf, type);
7637 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007638 case DRIVER_WCN:
7639 sta_reset_default_wcn(dut, intf, type);
7640 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007641 default:
7642 break;
7643 }
7644
7645#ifdef ANDROID_NAN
7646 if (dut->program == PROGRAM_NAN)
7647 nan_cmd_sta_reset_default(dut, conn, cmd);
7648#endif /* ANDROID_NAN */
7649
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05307650 if (dut->program == PROGRAM_LOC &&
7651 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
7652 return ERROR_SEND_STATUS;
7653
Jouni Malinenba630452018-06-22 11:49:59 +03007654 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007655 unlink("SP/wi-fi.org/pps.xml");
7656 if (system("rm -r SP/*") != 0) {
7657 }
7658 unlink("next-client-cert.pem");
7659 unlink("next-client-key.pem");
7660 }
7661
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007662 /* For WPS program of the 60 GHz band the band type needs to be saved */
7663 if (dut->program == PROGRAM_WPS) {
7664 if (band && strcasecmp(band, "60GHz") == 0) {
7665 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007666 /* For 60 GHz enable WPS for WPS TCs */
7667 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007668 } else {
7669 dut->band = WPS_BAND_NON_60G;
7670 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007671 } else if (dut->program == PROGRAM_60GHZ) {
7672 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
7673 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007674 }
7675
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02007676 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007677 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007678 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007679
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007680 sigma_dut_print(dut, DUT_MSG_INFO,
7681 "WPS 60 GHz program, wps_disable = %d",
7682 dut->wps_disable);
7683
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007684 if (!dev_role) {
7685 send_resp(dut, conn, SIGMA_ERROR,
7686 "errorCode,Missing DevRole argument");
7687 return 0;
7688 }
7689
7690 if (strcasecmp(dev_role, "STA") == 0)
7691 dut->dev_role = DEVROLE_STA;
7692 else if (strcasecmp(dev_role, "PCP") == 0)
7693 dut->dev_role = DEVROLE_PCP;
7694 else {
7695 send_resp(dut, conn, SIGMA_ERROR,
7696 "errorCode,Unknown DevRole");
7697 return 0;
7698 }
7699
7700 if (dut->device_type == STA_unknown) {
7701 sigma_dut_print(dut, DUT_MSG_ERROR,
7702 "Device type is not STA testbed or DUT");
7703 send_resp(dut, conn, SIGMA_ERROR,
7704 "errorCode,Unknown device type");
7705 return 0;
7706 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007707
7708 sigma_dut_print(dut, DUT_MSG_DEBUG,
7709 "Setting msdu_size to MAX: 7912");
7710 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007711 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007712
7713 if (system(buf) != 0) {
7714 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
7715 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007716 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007717 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007718
7719 if (sta_set_force_mcs(dut, 0, 1)) {
7720 sigma_dut_print(dut, DUT_MSG_ERROR,
7721 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007722 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007723 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007724 }
7725
7726 wpa_command(intf, "WPS_ER_STOP");
7727 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05307728 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007729 wpa_command(intf, "SET radio_disabled 0");
7730
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007731 dut->wps_forced_version = 0;
7732
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007733 if (dut->wsc_fragment) {
7734 dut->wsc_fragment = 0;
7735 wpa_command(intf, "SET device_name Test client");
7736 wpa_command(intf, "SET manufacturer ");
7737 wpa_command(intf, "SET model_name ");
7738 wpa_command(intf, "SET model_number ");
7739 wpa_command(intf, "SET serial_number ");
7740 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02007741 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
7742 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
7743 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
7744 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007745
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007746 if (dut->tmp_mac_addr && dut->set_macaddr) {
7747 dut->tmp_mac_addr = 0;
7748 if (system(dut->set_macaddr) != 0) {
7749 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
7750 "temporary MAC address");
7751 }
7752 }
7753
7754 set_ps(intf, dut, 0);
7755
Jouni Malinenba630452018-06-22 11:49:59 +03007756 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
7757 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007758 wpa_command(intf, "SET interworking 1");
7759 wpa_command(intf, "SET hs20 1");
7760 }
7761
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007762 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007763 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007764 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007765 wpa_command(intf, "SET pmf 1");
7766 } else {
7767 wpa_command(intf, "SET pmf 0");
7768 }
7769
7770 hs2_clear_credentials(intf);
7771 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
7772 wpa_command(intf, "SET access_network_type 15");
7773
7774 static_ip_file(0, NULL, NULL, NULL);
7775 kill_dhcp_client(dut, intf);
7776 clear_ip_addr(dut, intf);
7777
7778 dut->er_oper_performed = 0;
7779 dut->er_oper_bssid[0] = '\0';
7780
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007781 if (dut->program == PROGRAM_LOC) {
7782 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007783 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007784 }
7785
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07007786 if (dut->program == PROGRAM_MBO || dut->program == PROGRAM_HE) {
Ashwini Patil00402582017-04-13 12:29:39 +05307787 free(dut->non_pref_ch_list);
7788 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05307789 free(dut->btm_query_cand_list);
7790 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05307791 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05307792 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05307793 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05307794 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05307795 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05307796 }
7797
Jouni Malinen3c367e82017-06-23 17:01:47 +03007798 free(dut->rsne_override);
7799 dut->rsne_override = NULL;
7800
Jouni Malinen68143132017-09-02 02:34:08 +03007801 free(dut->sae_commit_override);
7802 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03007803 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02007804 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03007805
Jouni Malinen134fe3c2019-06-12 04:16:49 +03007806 dut->sta_associate_wait_connect = 0;
7807 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03007808 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03007809 dut->sta_tod_policy = 0;
7810
Jouni Malinend86e5822017-08-29 03:55:32 +03007811 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02007812 free(dut->dpp_peer_uri);
7813 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02007814 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02007815 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03007816 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03007817
Jouni Malinenfac9cad2017-10-10 18:35:55 +03007818 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
7819
vamsi krishnaa2799492017-12-05 14:28:01 +05307820 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307821 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05307822 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05307823 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
7824 dut->fils_hlp = 0;
7825#ifdef ANDROID
7826 hlp_thread_cleanup(dut);
7827#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05307828 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307829
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05307830 if (dut->program == PROGRAM_QM)
7831 wpa_command(intf, "SET interworking 1");
7832
Jouni Malinen8179fee2019-03-28 03:19:47 +02007833 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007834 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02007835
Sunil Dutt076081f2018-02-05 19:45:50 +05307836#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007837 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05307838 dut->config_rsnie == 1) {
7839 dut->config_rsnie = 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05307840 sta_config_params(dut, intf, STA_SET_RSNIE, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05307841 }
7842#endif /* NL80211_SUPPORT */
7843
Sunil Duttfebf8a82018-02-09 18:50:13 +05307844 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
7845 dut->dev_role = DEVROLE_STA_CFON;
7846 return sta_cfon_reset_default(dut, conn, cmd);
7847 }
7848
Jouni Malinen439352d2018-09-13 03:42:23 +03007849 wpa_command(intf, "SET setband AUTO");
7850
Vamsi Krishnac1633d22020-05-06 18:31:21 +05307851 dut->ocvc = 0;
Jouni Malinen67433fc2020-06-26 22:50:33 +03007852 dut->client_privacy = 0;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05307853 dut->saquery_oci_freq = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05307854
Sunil Duttfebf8a82018-02-09 18:50:13 +05307855 if (dut->program != PROGRAM_VHT)
7856 return cmd_sta_p2p_reset(dut, conn, cmd);
7857
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08007858 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007859}
7860
7861
Jouni Malinenf7222712019-06-13 01:50:21 +03007862static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
7863 struct sigma_conn *conn,
7864 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007865{
7866 const char *program = get_param(cmd, "Program");
7867
7868 if (program == NULL)
7869 return -1;
7870#ifdef ANDROID_NAN
7871 if (strcasecmp(program, "NAN") == 0)
7872 return nan_cmd_sta_get_events(dut, conn, cmd);
7873#endif /* ANDROID_NAN */
7874 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7875 return 0;
7876}
7877
7878
Jouni Malinen82905202018-04-29 17:20:10 +03007879static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
7880 struct sigma_cmd *cmd)
7881{
7882 const char *url = get_param(cmd, "url");
7883 const char *method = get_param(cmd, "method");
7884 pid_t pid;
7885 int status;
7886
7887 if (!url || !method)
7888 return -1;
7889
7890 /* TODO: Add support for method,post */
7891 if (strcasecmp(method, "get") != 0) {
7892 send_resp(dut, conn, SIGMA_ERROR,
7893 "ErrorCode,Unsupported method");
7894 return 0;
7895 }
7896
7897 pid = fork();
7898 if (pid < 0) {
7899 perror("fork");
7900 return -1;
7901 }
7902
7903 if (pid == 0) {
7904 char * argv[5] = { "wget", "-O", "/dev/null",
7905 (char *) url, NULL };
7906
7907 execv("/usr/bin/wget", argv);
7908 perror("execv");
7909 exit(0);
7910 return -1;
7911 }
7912
7913 if (waitpid(pid, &status, 0) < 0) {
7914 perror("waitpid");
7915 return -1;
7916 }
7917
7918 if (WIFEXITED(status)) {
7919 const char *errmsg;
7920
7921 if (WEXITSTATUS(status) == 0)
7922 return 1;
7923 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
7924 WEXITSTATUS(status));
7925 switch (WEXITSTATUS(status)) {
7926 case 4:
7927 errmsg = "errmsg,Network failure";
7928 break;
7929 case 8:
7930 errmsg = "errmsg,Server issued an error response";
7931 break;
7932 default:
7933 errmsg = "errmsg,Unknown failure from wget";
7934 break;
7935 }
7936 send_resp(dut, conn, SIGMA_ERROR, errmsg);
7937 return 0;
7938 }
7939
7940 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
7941 return 0;
7942}
7943
7944
Jouni Malinenf7222712019-06-13 01:50:21 +03007945static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
7946 struct sigma_conn *conn,
7947 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007948{
7949 const char *program = get_param(cmd, "Prog");
7950
Jouni Malinen82905202018-04-29 17:20:10 +03007951 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007952 return -1;
7953#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03007954 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007955 return nan_cmd_sta_exec_action(dut, conn, cmd);
7956#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03007957
7958 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07007959 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03007960
7961 if (get_param(cmd, "url"))
7962 return sta_exec_action_url(dut, conn, cmd);
7963
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007964 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7965 return 0;
7966}
7967
7968
Jouni Malinenf7222712019-06-13 01:50:21 +03007969static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
7970 struct sigma_conn *conn,
7971 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007972{
7973 const char *intf = get_param(cmd, "Interface");
7974 const char *val, *mcs32, *rate;
7975
7976 val = get_param(cmd, "GREENFIELD");
7977 if (val) {
7978 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
7979 /* Enable GD */
7980 send_resp(dut, conn, SIGMA_ERROR,
7981 "ErrorCode,GF not supported");
7982 return 0;
7983 }
7984 }
7985
7986 val = get_param(cmd, "SGI20");
7987 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007988 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007989 case DRIVER_ATHEROS:
7990 ath_sta_set_sgi(dut, intf, val);
7991 break;
7992 default:
7993 send_resp(dut, conn, SIGMA_ERROR,
7994 "ErrorCode,SGI20 not supported");
7995 return 0;
7996 }
7997 }
7998
7999 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
8000 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
8001 if (mcs32 && rate) {
8002 /* TODO */
8003 send_resp(dut, conn, SIGMA_ERROR,
8004 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
8005 return 0;
8006 } else if (mcs32 && !rate) {
8007 /* TODO */
8008 send_resp(dut, conn, SIGMA_ERROR,
8009 "ErrorCode,MCS32 not supported");
8010 return 0;
8011 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008012 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008013 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008014 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008015 ath_sta_set_11nrates(dut, intf, rate);
8016 break;
8017 default:
8018 send_resp(dut, conn, SIGMA_ERROR,
8019 "ErrorCode,MCS32_FIXEDRATE not supported");
8020 return 0;
8021 }
8022 }
8023
8024 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8025}
8026
8027
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008028static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8029 int mcs_config)
8030{
8031#ifdef NL80211_SUPPORT
8032 int ret;
8033
8034 switch (mcs_config) {
8035 case HE_80_MCS0_7:
8036 case HE_80_MCS0_9:
8037 case HE_80_MCS0_11:
8038 ret = sta_set_he_mcs(dut, intf, mcs_config);
8039 if (ret) {
8040 sigma_dut_print(dut, DUT_MSG_ERROR,
8041 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8042 mcs_config, ret);
8043 }
8044 break;
8045 default:
8046 sigma_dut_print(dut, DUT_MSG_ERROR,
8047 "cmd_set_max_he_mcs: Invalid mcs %d",
8048 mcs_config);
8049 break;
8050 }
8051#else /* NL80211_SUPPORT */
8052 sigma_dut_print(dut, DUT_MSG_ERROR,
8053 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8054#endif /* NL80211_SUPPORT */
8055}
8056
8057
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008058static int sta_twt_send_suspend(struct sigma_dut *dut, struct sigma_conn *conn,
8059 struct sigma_cmd *cmd)
8060{
8061#ifdef NL80211_SUPPORT
8062 struct nlattr *attr, *attr1;
8063 struct nl_msg *msg;
8064 int ifindex, ret;
8065 const char *intf = get_param(cmd, "Interface");
8066
8067 ifindex = if_nametoindex(intf);
8068 if (ifindex == 0) {
8069 sigma_dut_print(dut, DUT_MSG_ERROR,
8070 "%s: Index for interface %s failed",
8071 __func__, intf);
8072 return ERROR_SEND_STATUS;
8073 }
8074
8075 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8076 NL80211_CMD_VENDOR)) ||
8077 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8078 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8079 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8080 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
8081 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8082 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
8083 QCA_WLAN_TWT_SUSPEND) ||
8084 !(attr1 = nla_nest_start(msg,
8085 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
8086 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_FLOW_ID, 0)) {
8087 sigma_dut_print(dut, DUT_MSG_ERROR,
8088 "%s: err in adding vendor_cmd and vendor_data",
8089 __func__);
8090 nlmsg_free(msg);
8091 return ERROR_SEND_STATUS;
8092 }
8093 nla_nest_end(msg, attr1);
8094 nla_nest_end(msg, attr);
8095
8096 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8097 if (ret) {
8098 sigma_dut_print(dut, DUT_MSG_ERROR,
8099 "%s: err in send_and_recv_msgs, ret=%d",
8100 __func__, ret);
8101 }
8102
8103 return ret;
8104#else /* NL80211_SUPPORT */
8105 sigma_dut_print(dut, DUT_MSG_ERROR,
8106 "TWT suspend cannot be done without NL80211_SUPPORT defined");
8107 return ERROR_SEND_STATUS;
8108#endif /* NL80211_SUPPORT */
8109}
8110
8111
8112static int sta_twt_send_nudge(struct sigma_dut *dut, struct sigma_conn *conn,
8113 struct sigma_cmd *cmd,
8114 unsigned int suspend_duration)
8115{
8116#ifdef NL80211_SUPPORT
8117 struct nlattr *attr, *attr1;
8118 struct nl_msg *msg;
8119 int ifindex, ret;
8120 const char *intf = get_param(cmd, "Interface");
8121 int next_twt_size = 1;
8122
8123 ifindex = if_nametoindex(intf);
8124 if (ifindex == 0) {
8125 sigma_dut_print(dut, DUT_MSG_ERROR,
8126 "%s: Index for interface %s failed",
8127 __func__, intf);
8128 return ERROR_SEND_STATUS;
8129 }
8130
8131 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8132 NL80211_CMD_VENDOR)) ||
8133 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8134 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8135 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8136 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
8137 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8138 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
8139 QCA_WLAN_TWT_NUDGE) ||
8140 !(attr1 = nla_nest_start(msg,
8141 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
8142 (suspend_duration &&
8143 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_WAKE_TIME,
8144 suspend_duration)) ||
8145 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_NEXT_TWT_SIZE,
8146 next_twt_size)) {
8147 sigma_dut_print(dut, DUT_MSG_ERROR,
8148 "%s: err in adding vendor_cmd and vendor_data",
8149 __func__);
8150 nlmsg_free(msg);
8151 return ERROR_SEND_STATUS;
8152 }
8153 nla_nest_end(msg, attr1);
8154 nla_nest_end(msg, attr);
8155
8156 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8157 if (ret) {
8158 sigma_dut_print(dut, DUT_MSG_ERROR,
8159 "%s: err in send_and_recv_msgs, ret=%d",
8160 __func__, ret);
8161 }
8162
8163 return ret;
8164#else /* NL80211_SUPPORT */
8165 sigma_dut_print(dut, DUT_MSG_ERROR,
8166 "TWT suspend cannot be done without NL80211_SUPPORT defined");
8167 return ERROR_SEND_STATUS;
8168#endif /* NL80211_SUPPORT */
8169}
8170
8171
8172static int sta_twt_suspend_or_nudge(struct sigma_dut *dut,
8173 struct sigma_conn *conn,
8174 struct sigma_cmd *cmd)
8175{
8176 const char *val;
8177
8178 val = get_param(cmd, "TWT_SuspendDuration");
8179 if (val) {
8180 unsigned int suspend_duration;
8181
8182 suspend_duration = atoi(val);
8183 suspend_duration = suspend_duration * 1000 * 1000;
8184 return sta_twt_send_nudge(dut, conn, cmd, suspend_duration);
8185 }
8186
8187 return sta_twt_send_suspend(dut, conn, cmd);
8188}
8189
8190
8191static int sta_twt_resume(struct sigma_dut *dut, struct sigma_conn *conn,
8192 struct sigma_cmd *cmd)
8193{
8194#ifdef NL80211_SUPPORT
8195 struct nlattr *attr, *attr1;
8196 struct nl_msg *msg;
8197 int ifindex, ret;
8198 const char *intf = get_param(cmd, "Interface");
8199 int next2_twt_size = 1;
8200 unsigned int resume_duration = 0;
8201 const char *val;
8202
8203 ifindex = if_nametoindex(intf);
8204 if (ifindex == 0) {
8205 sigma_dut_print(dut, DUT_MSG_ERROR,
8206 "%s: Index for interface %s failed",
8207 __func__, intf);
8208 return ERROR_SEND_STATUS;
8209 }
8210
8211 val = get_param(cmd, "TWT_ResumeDuration");
8212 if (val) {
8213 resume_duration = atoi(val);
8214 resume_duration = resume_duration * 1000 * 1000;
8215 }
8216
8217 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8218 NL80211_CMD_VENDOR)) ||
8219 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8220 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8221 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8222 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
8223 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8224 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
8225 QCA_WLAN_TWT_RESUME) ||
8226 !(attr1 = nla_nest_start(msg,
8227 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
8228 (resume_duration &&
8229 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_RESUME_NEXT2_TWT,
8230 resume_duration)) ||
8231 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_RESUME_NEXT_TWT_SIZE,
8232 next2_twt_size)) {
8233 sigma_dut_print(dut, DUT_MSG_ERROR,
8234 "%s: err in adding vendor_cmd and vendor_data",
8235 __func__);
8236 nlmsg_free(msg);
8237 return ERROR_SEND_STATUS;
8238 }
8239 nla_nest_end(msg, attr1);
8240 nla_nest_end(msg, attr);
8241
8242 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8243 if (ret) {
8244 sigma_dut_print(dut, DUT_MSG_ERROR,
8245 "%s: err in send_and_recv_msgs, ret=%d",
8246 __func__, ret);
8247 }
8248
8249 return ret;
8250#else /* NL80211_SUPPORT */
8251 sigma_dut_print(dut, DUT_MSG_ERROR,
8252 "TWT resume cannot be done without NL80211_SUPPORT defined");
8253 return ERROR_SEND_STATUS;
8254#endif /* NL80211_SUPPORT */
8255}
8256
8257
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008258#define TWT_REQUEST_CMD 0
8259#define TWT_SUGGEST_CMD 1
8260#define TWT_DEMAND_CMD 2
8261
Arif Hussain480d5f42019-03-12 14:40:42 -07008262static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8263 struct sigma_cmd *cmd)
8264{
8265#ifdef NL80211_SUPPORT
8266 struct nlattr *params;
8267 struct nlattr *attr;
Arif Hussain480d5f42019-03-12 14:40:42 -07008268 struct nl_msg *msg;
8269 int ifindex, ret;
8270 const char *val;
8271 const char *intf = get_param(cmd, "Interface");
8272 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8273 wake_interval_mantissa = 512;
8274 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008275 protection = 0, cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
Arif Hussain480d5f42019-03-12 14:40:42 -07008276
8277 ifindex = if_nametoindex(intf);
8278 if (ifindex == 0) {
8279 sigma_dut_print(dut, DUT_MSG_ERROR,
8280 "%s: Index for interface %s failed",
8281 __func__, intf);
8282 return -1;
8283 }
8284
8285 val = get_param(cmd, "FlowType");
8286 if (val) {
8287 flow_type = atoi(val);
8288 if (flow_type != 0 && flow_type != 1) {
8289 sigma_dut_print(dut, DUT_MSG_ERROR,
8290 "TWT: Invalid FlowType %d", flow_type);
8291 return -1;
8292 }
8293 }
8294
8295 val = get_param(cmd, "TWT_Trigger");
8296 if (val) {
8297 twt_trigger = atoi(val);
8298 if (twt_trigger != 0 && twt_trigger != 1) {
8299 sigma_dut_print(dut, DUT_MSG_ERROR,
8300 "TWT: Invalid TWT_Trigger %d",
8301 twt_trigger);
8302 return -1;
8303 }
8304 }
8305
8306 val = get_param(cmd, "Protection");
8307 if (val) {
8308 protection = atoi(val);
8309 if (protection != 0 && protection != 1) {
8310 sigma_dut_print(dut, DUT_MSG_ERROR,
8311 "TWT: Invalid Protection %d",
8312 protection);
8313 return -1;
8314 }
8315 }
8316
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008317 val = get_param(cmd, "SetupCommand");
8318 if (val) {
8319 cmd_type = atoi(val);
8320 if (cmd_type == TWT_REQUEST_CMD)
8321 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_REQUEST;
8322 else if (cmd_type == TWT_SUGGEST_CMD)
8323 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
8324 else if (cmd_type == TWT_DEMAND_CMD)
8325 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_DEMAND;
8326 else
8327 sigma_dut_print(dut, DUT_MSG_ERROR,
8328 "Default suggest is used for cmd %d",
8329 cmd_type);
8330 }
8331
Arif Hussain480d5f42019-03-12 14:40:42 -07008332 val = get_param(cmd, "TargetWakeTime");
8333 if (val)
8334 target_wake_time = atoi(val);
8335
8336 val = get_param(cmd, "WakeIntervalMantissa");
8337 if (val)
8338 wake_interval_mantissa = atoi(val);
8339
8340 val = get_param(cmd, "WakeIntervalExp");
8341 if (val)
8342 wake_interval_exp = atoi(val);
8343
8344 val = get_param(cmd, "NominalMinWakeDur");
8345 if (val)
8346 nominal_min_wake_dur = atoi(val);
8347
8348 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8349 NL80211_CMD_VENDOR)) ||
8350 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8351 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8352 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008353 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008354 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008355 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
8356 QCA_WLAN_TWT_SET) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008357 !(params = nla_nest_start(
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008358 msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008359 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8360 wake_interval_exp) ||
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008361 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, cmd_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008362 (twt_trigger &&
8363 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008364 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8365 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008366 (protection &&
8367 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008368 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8369 target_wake_time) ||
8370 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8371 nominal_min_wake_dur) ||
8372 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8373 wake_interval_mantissa)) {
8374 sigma_dut_print(dut, DUT_MSG_ERROR,
8375 "%s: err in adding vendor_cmd and vendor_data",
8376 __func__);
8377 nlmsg_free(msg);
8378 return -1;
8379 }
Arif Hussain480d5f42019-03-12 14:40:42 -07008380 nla_nest_end(msg, params);
8381 nla_nest_end(msg, attr);
8382
8383 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8384 if (ret) {
8385 sigma_dut_print(dut, DUT_MSG_ERROR,
8386 "%s: err in send_and_recv_msgs, ret=%d",
8387 __func__, ret);
8388 }
8389
8390 return ret;
8391#else /* NL80211_SUPPORT */
8392 sigma_dut_print(dut, DUT_MSG_ERROR,
8393 "TWT request cannot be done without NL80211_SUPPORT defined");
8394 return -1;
8395#endif /* NL80211_SUPPORT */
8396}
8397
8398
8399static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8400 struct sigma_cmd *cmd)
8401{
8402 #ifdef NL80211_SUPPORT
8403 struct nlattr *params;
8404 struct nlattr *attr;
Arif Hussain480d5f42019-03-12 14:40:42 -07008405 int ifindex, ret;
8406 struct nl_msg *msg;
8407 const char *intf = get_param(cmd, "Interface");
8408
8409 ifindex = if_nametoindex(intf);
8410 if (ifindex == 0) {
8411 sigma_dut_print(dut, DUT_MSG_ERROR,
8412 "%s: Index for interface %s failed",
8413 __func__, intf);
8414 return -1;
8415 }
8416
8417 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8418 NL80211_CMD_VENDOR)) ||
8419 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8420 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8421 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008422 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008423 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008424 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
8425 QCA_WLAN_TWT_TERMINATE) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008426 !(params = nla_nest_start(
8427 msg,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008428 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008429 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8430 sigma_dut_print(dut, DUT_MSG_ERROR,
8431 "%s: err in adding vendor_cmd and vendor_data",
8432 __func__);
8433 nlmsg_free(msg);
8434 return -1;
8435 }
Arif Hussain480d5f42019-03-12 14:40:42 -07008436 nla_nest_end(msg, params);
8437 nla_nest_end(msg, attr);
8438
8439 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8440 if (ret) {
8441 sigma_dut_print(dut, DUT_MSG_ERROR,
8442 "%s: err in send_and_recv_msgs, ret=%d",
8443 __func__, ret);
8444 }
8445
8446 return ret;
8447#else /* NL80211_SUPPORT */
8448 sigma_dut_print(dut, DUT_MSG_ERROR,
8449 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8450 return -1;
8451#endif /* NL80211_SUPPORT */
8452}
8453
8454
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008455static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8456 struct sigma_cmd *cmd)
8457{
8458#ifdef NL80211_SUPPORT
8459 struct nlattr *params;
8460 struct nlattr *attr;
8461 struct nlattr *attr1;
8462 struct nl_msg *msg;
8463 int ifindex, ret;
8464 const char *val;
8465 const char *intf = get_param(cmd, "Interface");
8466 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8467 ulmu_data_dis = 0;
8468
8469 ifindex = if_nametoindex(intf);
8470 if (ifindex == 0) {
8471 sigma_dut_print(dut, DUT_MSG_ERROR,
8472 "%s: Index for interface %s failed",
8473 __func__, intf);
8474 return -1;
8475 }
8476 val = get_param(cmd, "OMCtrl_RxNSS");
8477 if (val)
8478 rx_nss = atoi(val);
8479
8480 val = get_param(cmd, "OMCtrl_ChnlWidth");
8481 if (val)
8482 ch_bw = atoi(val);
8483
8484 val = get_param(cmd, "OMCtrl_ULMUDisable");
8485 if (val)
8486 ulmu_dis = atoi(val);
8487
8488 val = get_param(cmd, "OMCtrl_TxNSTS");
8489 if (val)
8490 tx_nsts = atoi(val);
8491
8492 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8493 if (val)
8494 ulmu_data_dis = atoi(val);
8495
8496 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8497 NL80211_CMD_VENDOR)) ||
8498 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8499 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8500 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8501 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8502 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8503 !(params = nla_nest_start(
8504 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8505 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8506 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8507 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8508 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8509 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8510 ulmu_data_dis) ||
8511 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8512 ulmu_dis)) {
8513 sigma_dut_print(dut, DUT_MSG_ERROR,
8514 "%s: err in adding vendor_cmd and vendor_data",
8515 __func__);
8516 nlmsg_free(msg);
8517 return -1;
8518 }
8519 nla_nest_end(msg, attr1);
8520 nla_nest_end(msg, params);
8521 nla_nest_end(msg, attr);
8522
8523 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8524 if (ret) {
8525 sigma_dut_print(dut, DUT_MSG_ERROR,
8526 "%s: err in send_and_recv_msgs, ret=%d",
8527 __func__, ret);
8528 }
8529
8530 return ret;
8531#else /* NL80211_SUPPORT */
8532 sigma_dut_print(dut, DUT_MSG_ERROR,
8533 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8534 return -1;
8535#endif /* NL80211_SUPPORT */
8536}
8537
8538
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008539static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8540 struct sigma_conn *conn,
8541 struct sigma_cmd *cmd)
8542{
8543 const char *intf = get_param(cmd, "Interface");
8544 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008545 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008546 int tkip = -1;
8547 int wep = -1;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308548 int iwpriv_status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008549
Arif Hussaina37e9552018-06-20 17:05:59 -07008550 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008551 val = get_param(cmd, "SGI80");
8552 if (val) {
8553 int sgi80;
8554
8555 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008556 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008557 }
8558
8559 val = get_param(cmd, "TxBF");
8560 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008561 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008562 case DRIVER_WCN:
8563 if (sta_set_tx_beamformee(dut, intf, 1)) {
8564 send_resp(dut, conn, SIGMA_ERROR,
8565 "ErrorCode,Failed to set TX beamformee enable");
8566 return 0;
8567 }
8568 break;
8569 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008570 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008571 send_resp(dut, conn, SIGMA_ERROR,
8572 "ErrorCode,Setting vhtsubfee failed");
8573 return 0;
8574 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008575 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008576 send_resp(dut, conn, SIGMA_ERROR,
8577 "ErrorCode,Setting vhtsubfer failed");
8578 return 0;
8579 }
8580 break;
8581 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008582 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008583 "Unsupported driver type");
8584 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008585 }
8586 }
8587
8588 val = get_param(cmd, "MU_TxBF");
8589 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008590 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008591 case DRIVER_ATHEROS:
8592 ath_sta_set_txsp_stream(dut, intf, "1SS");
8593 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008594 run_iwpriv(dut, intf, "vhtmubfee 1");
8595 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308596 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008597 case DRIVER_WCN:
8598 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8599 send_resp(dut, conn, SIGMA_ERROR,
8600 "ErrorCode,Failed to set RX/TXSP_STREAM");
8601 return 0;
8602 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308603 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008604 default:
8605 sigma_dut_print(dut, DUT_MSG_ERROR,
8606 "Setting SP_STREAM not supported");
8607 break;
8608 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008609 }
8610
8611 val = get_param(cmd, "LDPC");
8612 if (val) {
8613 int ldpc;
8614
8615 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308616 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", ldpc);
8617 if (iwpriv_status)
8618 sta_config_params(dut, intf, STA_SET_LDPC, ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008619 }
8620
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008621 val = get_param(cmd, "BCC");
8622 if (val) {
8623 int bcc;
8624
8625 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8626 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8627 * is mutually exclusive to bcc */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308628 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", !bcc);
8629 if (iwpriv_status)
8630 sta_config_params(dut, intf, STA_SET_LDPC, !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008631 }
8632
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008633 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8634 if (val && dut->sta_nss == 1)
8635 cmd_set_max_he_mcs(dut, intf, atoi(val));
8636
8637 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8638 if (val && dut->sta_nss == 2)
8639 cmd_set_max_he_mcs(dut, intf, atoi(val));
8640
Arif Hussainac6c5112018-05-25 17:34:00 -07008641 val = get_param(cmd, "MCS_FixedRate");
8642 if (val) {
8643#ifdef NL80211_SUPPORT
8644 int mcs, ratecode = 0;
8645 enum he_mcs_config mcs_config;
8646 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008647 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008648
8649 ratecode = (0x07 & dut->sta_nss) << 5;
8650 mcs = atoi(val);
8651 /* Add the MCS to the ratecode */
8652 if (mcs >= 0 && mcs <= 11) {
8653 ratecode += mcs;
8654 if (dut->device_type == STA_testbed &&
8655 mcs > 7 && mcs <= 11) {
8656 if (mcs <= 9)
8657 mcs_config = HE_80_MCS0_9;
8658 else
8659 mcs_config = HE_80_MCS0_11;
8660 ret = sta_set_he_mcs(dut, intf, mcs_config);
8661 if (ret) {
8662 sigma_dut_print(dut, DUT_MSG_ERROR,
8663 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8664 mcs, mcs_config, ret);
8665 }
8666 }
8667 snprintf(buf, sizeof(buf),
8668 "iwpriv %s set_11ax_rate 0x%03x",
8669 intf, ratecode);
8670 if (system(buf) != 0) {
8671 sigma_dut_print(dut, DUT_MSG_ERROR,
8672 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8673 ratecode);
8674 }
8675 } else {
8676 sigma_dut_print(dut, DUT_MSG_ERROR,
8677 "MCS_FixedRate: HE MCS %d not supported",
8678 mcs);
8679 }
8680#else /* NL80211_SUPPORT */
8681 sigma_dut_print(dut, DUT_MSG_ERROR,
8682 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8683#endif /* NL80211_SUPPORT */
8684 }
8685
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008686 val = get_param(cmd, "opt_md_notif_ie");
8687 if (val) {
8688 char *result = NULL;
8689 char delim[] = ";";
8690 char token[30];
8691 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308692 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008693
Peng Xub8fc5cc2017-05-10 17:27:28 -07008694 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308695 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008696
8697 /* Extract the NSS information */
8698 if (result) {
8699 value = atoi(result);
8700 switch (value) {
8701 case 1:
8702 config_val = 1;
8703 break;
8704 case 2:
8705 config_val = 3;
8706 break;
8707 case 3:
8708 config_val = 7;
8709 break;
8710 case 4:
8711 config_val = 15;
8712 break;
8713 default:
8714 config_val = 3;
8715 break;
8716 }
8717
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008718 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8719 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008720
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008721 }
8722
8723 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308724 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008725 if (result) {
8726 value = atoi(result);
8727 switch (value) {
8728 case 20:
8729 config_val = 0;
8730 break;
8731 case 40:
8732 config_val = 1;
8733 break;
8734 case 80:
8735 config_val = 2;
8736 break;
8737 case 160:
8738 config_val = 3;
8739 break;
8740 default:
8741 config_val = 2;
8742 break;
8743 }
8744
8745 dut->chwidth = config_val;
8746
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008747 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008748 }
8749
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008750 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008751 }
8752
8753 val = get_param(cmd, "nss_mcs_cap");
8754 if (val) {
8755 int nss, mcs;
8756 char token[20];
8757 char *result = NULL;
8758 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308759 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008760
Peng Xub8fc5cc2017-05-10 17:27:28 -07008761 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308762 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308763 if (!result) {
8764 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008765 "NSS not specified");
8766 send_resp(dut, conn, SIGMA_ERROR,
8767 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308768 return 0;
8769 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008770 nss = atoi(result);
8771
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008772 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07008773 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008774
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308775 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008776 if (result == NULL) {
8777 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008778 "MCS not specified");
8779 send_resp(dut, conn, SIGMA_ERROR,
8780 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008781 return 0;
8782 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308783 result = strtok_r(result, "-", &saveptr);
8784 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308785 if (!result) {
8786 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008787 "MCS not specified");
8788 send_resp(dut, conn, SIGMA_ERROR,
8789 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308790 return 0;
8791 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008792 mcs = atoi(result);
8793
Arif Hussaina37e9552018-06-20 17:05:59 -07008794 if (program && strcasecmp(program, "HE") == 0) {
8795#ifdef NL80211_SUPPORT
8796 enum he_mcs_config mcs_config;
8797 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008798
Arif Hussaina37e9552018-06-20 17:05:59 -07008799 if (mcs >= 0 && mcs <= 7) {
8800 mcs_config = HE_80_MCS0_7;
8801 } else if (mcs > 7 && mcs <= 9) {
8802 mcs_config = HE_80_MCS0_9;
8803 } else if (mcs > 9 && mcs <= 11) {
8804 mcs_config = HE_80_MCS0_11;
8805 } else {
8806 sigma_dut_print(dut, DUT_MSG_ERROR,
8807 "nss_mcs_cap: HE: Invalid mcs: %d",
8808 mcs);
8809 send_resp(dut, conn, SIGMA_ERROR,
8810 "errorCode,Invalid MCS");
8811 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008812 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008813
8814 ret = sta_set_he_mcs(dut, intf, mcs_config);
8815 if (ret) {
8816 sigma_dut_print(dut, DUT_MSG_ERROR,
8817 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
8818 mcs_config, ret);
8819 send_resp(dut, conn, SIGMA_ERROR,
8820 "errorCode,Failed to set MCS");
8821 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008822 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008823#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008824 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008825 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
8826#endif /* NL80211_SUPPORT */
8827 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008828 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07008829
8830 switch (nss) {
8831 case 1:
8832 switch (mcs) {
8833 case 7:
8834 vht_mcsmap = 0xfffc;
8835 break;
8836 case 8:
8837 vht_mcsmap = 0xfffd;
8838 break;
8839 case 9:
8840 vht_mcsmap = 0xfffe;
8841 break;
8842 default:
8843 vht_mcsmap = 0xfffe;
8844 break;
8845 }
8846 break;
8847 case 2:
8848 switch (mcs) {
8849 case 7:
8850 vht_mcsmap = 0xfff0;
8851 break;
8852 case 8:
8853 vht_mcsmap = 0xfff5;
8854 break;
8855 case 9:
8856 vht_mcsmap = 0xfffa;
8857 break;
8858 default:
8859 vht_mcsmap = 0xfffa;
8860 break;
8861 }
8862 break;
8863 case 3:
8864 switch (mcs) {
8865 case 7:
8866 vht_mcsmap = 0xffc0;
8867 break;
8868 case 8:
8869 vht_mcsmap = 0xffd5;
8870 break;
8871 case 9:
8872 vht_mcsmap = 0xffea;
8873 break;
8874 default:
8875 vht_mcsmap = 0xffea;
8876 break;
8877 }
8878 break;
8879 default:
8880 vht_mcsmap = 0xffea;
8881 break;
8882 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008883 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008884 }
8885 }
8886
8887 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
8888
8889 val = get_param(cmd, "Vht_tkip");
8890 if (val)
8891 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8892
8893 val = get_param(cmd, "Vht_wep");
8894 if (val)
8895 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8896
8897 if (tkip != -1 || wep != -1) {
8898 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008899 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008900 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008901 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008902 } else {
8903 sigma_dut_print(dut, DUT_MSG_ERROR,
8904 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
8905 return 0;
8906 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008907 }
8908
Arif Hussain55f00da2018-07-03 08:28:26 -07008909 val = get_param(cmd, "txBandwidth");
8910 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008911 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07008912 case DRIVER_WCN:
8913 if (wcn_sta_set_width(dut, intf, val) < 0) {
8914 send_resp(dut, conn, SIGMA_ERROR,
8915 "ErrorCode,Failed to set txBandwidth");
8916 return 0;
8917 }
8918 break;
8919 case DRIVER_ATHEROS:
8920 if (ath_set_width(dut, conn, intf, val) < 0) {
8921 send_resp(dut, conn, SIGMA_ERROR,
8922 "ErrorCode,Failed to set txBandwidth");
8923 return 0;
8924 }
8925 break;
8926 default:
8927 sigma_dut_print(dut, DUT_MSG_ERROR,
8928 "Setting txBandwidth not supported");
8929 break;
8930 }
8931 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008932
Arif Hussain9765f7d2018-07-03 08:28:26 -07008933 val = get_param(cmd, "BeamformeeSTS");
8934 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07008935 if (sta_set_tx_beamformee(dut, intf, 1)) {
8936 send_resp(dut, conn, SIGMA_ERROR,
8937 "ErrorCode,Failed to set TX beamformee enable");
8938 return 0;
8939 }
8940
Arif Hussain9765f7d2018-07-03 08:28:26 -07008941 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
8942 send_resp(dut, conn, SIGMA_ERROR,
8943 "ErrorCode,Failed to set BeamformeeSTS");
8944 return 0;
8945 }
8946 }
8947
Arif Hussain68d23f52018-07-11 13:39:08 -07008948 val = get_param(cmd, "Trig_MAC_Padding_Dur");
8949 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008950#ifdef NL80211_SUPPORT
8951 enum qca_wlan_he_mac_padding_dur set_val;
8952
8953 switch (atoi(val)) {
8954 case 16:
8955 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
8956 break;
8957 case 8:
8958 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
8959 break;
8960 default:
8961 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
8962 break;
8963 }
8964 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008965 send_resp(dut, conn, SIGMA_ERROR,
8966 "ErrorCode,Failed to set MAC padding duration");
8967 return 0;
8968 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008969#else /* NL80211_SUPPORT */
8970 sigma_dut_print(dut, DUT_MSG_ERROR,
8971 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
8972#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008973 }
8974
Arif Hussain480d5f42019-03-12 14:40:42 -07008975 val = get_param(cmd, "TWT_ReqSupport");
8976 if (val) {
8977 int set_val;
8978
8979 if (strcasecmp(val, "Enable") == 0) {
8980 set_val = 1;
8981 } else if (strcasecmp(val, "Disable") == 0) {
8982 set_val = 0;
8983 } else {
8984 send_resp(dut, conn, SIGMA_ERROR,
8985 "ErrorCode,Invalid TWT_ReqSupport");
8986 return STATUS_SENT;
8987 }
8988
8989 if (sta_set_twt_req_support(dut, intf, set_val)) {
8990 sigma_dut_print(dut, DUT_MSG_ERROR,
8991 "Failed to set TWT req support %d",
8992 set_val);
8993 send_resp(dut, conn, SIGMA_ERROR,
8994 "ErrorCode,Failed to set TWT_ReqSupport");
8995 return STATUS_SENT;
8996 }
8997 }
8998
Srinivas Girigowda0525e292020-11-12 13:28:21 -08008999 val = get_param(cmd, "FullBW_ULMUMIMO");
9000 if (val) {
9001 int set_val;
9002
9003 if (strcasecmp(val, "Enable") == 0) {
9004 set_val = 1;
9005 } else if (strcasecmp(val, "Disable") == 0) {
9006 set_val = 0;
9007 } else {
9008 send_resp(dut, conn, SIGMA_ERROR,
9009 "ErrorCode,Invalid FullBW_ULMUMIMO");
9010 return STATUS_SENT_ERROR;
9011 }
9012
9013 if (sta_set_fullbw_ulmumimo(dut, intf, set_val)) {
9014 sigma_dut_print(dut, DUT_MSG_ERROR,
9015 "Failed to set FullBW_ULMUMIMO %d",
9016 set_val);
9017 send_resp(dut, conn, SIGMA_ERROR,
9018 "ErrorCode,Failed to set FullBW_ULMUMIMO");
9019 return STATUS_SENT_ERROR;
9020 }
9021 }
9022
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009023 val = get_param(cmd, "TWTInfoFrameTx");
9024 if (val) {
9025 if (strcasecmp(val, "Enable") == 0) {
9026 /* No-op */
9027 } else if (strcasecmp(val, "Disable") == 0) {
9028 /* No-op */
9029 } else {
9030 send_resp(dut, conn, SIGMA_ERROR,
9031 "ErrorCode,Invalid TWTInfoFrameTx");
9032 return STATUS_SENT_ERROR;
9033 }
9034 }
9035
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07009036 val = get_param(cmd, "MU_EDCA");
9037 if (val && (strcasecmp(val, "Override") == 0)) {
9038 if (sta_set_mu_edca_override(dut, intf, 1)) {
9039 send_resp(dut, conn, SIGMA_ERROR,
9040 "ErrorCode,Failed to set MU EDCA override");
9041 return 0;
9042 }
9043 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009044
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07009045 val = get_param(cmd, "OMControl");
9046 if (val) {
9047 int set_val = 1;
9048
9049 if (strcasecmp(val, "Enable") == 0)
9050 set_val = 1;
9051 else if (strcasecmp(val, "Disable") == 0)
9052 set_val = 0;
9053
9054 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
9055 send_resp(dut, conn, SIGMA_ERROR,
9056 "ErrorCode,Failed to set OM ctrl supp");
9057 return 0;
9058 }
9059 }
9060
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009061 val = get_param(cmd, "ADDBAResp_BufSize");
9062 if (val) {
9063 int buf_size;
9064
9065 if (strcasecmp(val, "gt64") == 0)
9066 buf_size = 256;
9067 else
9068 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009069 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009070 sta_set_addba_buf_size(dut, intf, buf_size)) {
9071 send_resp(dut, conn, SIGMA_ERROR,
9072 "ErrorCode,set addbaresp_buff_size failed");
9073 return 0;
9074 }
9075 }
9076
9077 val = get_param(cmd, "ADDBAReq_BufSize");
9078 if (val) {
9079 int buf_size;
9080
9081 if (strcasecmp(val, "gt64") == 0)
9082 buf_size = 256;
9083 else
9084 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009085 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009086 sta_set_addba_buf_size(dut, intf, buf_size)) {
9087 send_resp(dut, conn, SIGMA_ERROR,
9088 "ErrorCode,set addbareq_buff_size failed");
9089 return 0;
9090 }
9091 }
9092
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009093 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9094}
9095
9096
9097static int sta_set_wireless_60g(struct sigma_dut *dut,
9098 struct sigma_conn *conn,
9099 struct sigma_cmd *cmd)
9100{
9101 const char *dev_role = get_param(cmd, "DevRole");
9102
9103 if (!dev_role) {
9104 send_resp(dut, conn, SIGMA_INVALID,
9105 "ErrorCode,DevRole not specified");
9106 return 0;
9107 }
9108
9109 if (strcasecmp(dev_role, "PCP") == 0)
9110 return sta_set_60g_pcp(dut, conn, cmd);
9111 if (strcasecmp(dev_role, "STA") == 0)
9112 return sta_set_60g_sta(dut, conn, cmd);
9113 send_resp(dut, conn, SIGMA_INVALID,
9114 "ErrorCode,DevRole not supported");
9115 return 0;
9116}
9117
9118
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309119static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
9120 struct sigma_cmd *cmd)
9121{
9122 int status;
9123 const char *intf = get_param(cmd, "Interface");
9124 const char *val = get_param(cmd, "DevRole");
9125
9126 if (val && strcasecmp(val, "STA-CFON") == 0) {
9127 status = sta_cfon_set_wireless(dut, conn, cmd);
9128 if (status)
9129 return status;
9130 }
9131 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9132}
9133
9134
Jouni Malinen67433fc2020-06-26 22:50:33 +03009135static enum sigma_cmd_result
9136sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
9137 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309138{
9139 const char *intf = get_param(cmd, "Interface");
9140 const char *val;
9141
9142 val = get_param(cmd, "ocvc");
9143 if (val)
9144 dut->ocvc = atoi(val);
9145
Jouni Malinen67433fc2020-06-26 22:50:33 +03009146 val = get_param(cmd, "ClientPrivacy");
9147 if (val) {
9148 dut->client_privacy = atoi(val);
9149 if (dut->client_privacy &&
9150 (wpa_command(intf, "SET mac_addr 1") < 0 ||
9151 wpa_command(intf, "SET rand_addr_lifetime 1") < 0 ||
9152 wpa_command(intf, "SET preassoc_mac_addr 1") < 0 ||
9153 wpa_command(intf, "SET gas_rand_mac_addr 1") < 0 ||
9154 wpa_command(intf, "SET gas_rand_addr_lifetime 1") < 0)) {
9155 send_resp(dut, conn, SIGMA_ERROR,
9156 "errorCode,Failed to enable random MAC address use");
9157 return STATUS_SENT_ERROR;
9158 }
9159 }
9160
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309161 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9162}
9163
9164
Jouni Malinenf7222712019-06-13 01:50:21 +03009165static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
9166 struct sigma_conn *conn,
9167 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009168{
9169 const char *val;
9170
9171 val = get_param(cmd, "Program");
9172 if (val) {
9173 if (strcasecmp(val, "11n") == 0)
9174 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08009175 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009176 return cmd_sta_set_wireless_vht(dut, conn, cmd);
9177 if (strcasecmp(val, "60ghz") == 0)
9178 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309179 if (strcasecmp(val, "OCE") == 0)
9180 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02009181 /* sta_set_wireless in WPS program is only used for 60G */
9182 if (is_60g_sigma_dut(dut))
9183 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309184 if (strcasecmp(val, "WPA3") == 0)
9185 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009186 send_resp(dut, conn, SIGMA_ERROR,
9187 "ErrorCode,Program value not supported");
9188 } else {
9189 send_resp(dut, conn, SIGMA_ERROR,
9190 "ErrorCode,Program argument not available");
9191 }
9192
9193 return 0;
9194}
9195
9196
9197static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
9198 int tid)
9199{
9200 char buf[100];
9201 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
9202
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05309203 if (tid < 0 ||
9204 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
9205 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
9206 return;
9207 }
9208
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009209 /*
9210 * Two ways to ensure that addba request with a
9211 * non zero TID could be sent out. EV 117296
9212 */
9213 snprintf(buf, sizeof(buf),
9214 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
9215 tid);
9216 if (system(buf) != 0) {
9217 sigma_dut_print(dut, DUT_MSG_ERROR,
9218 "Ping did not send out");
9219 }
9220
9221 snprintf(buf, sizeof(buf),
9222 "iwconfig %s | grep Access | awk '{print $6}' > %s",
9223 intf, VI_QOS_TMP_FILE);
9224 if (system(buf) != 0)
9225 return;
9226
9227 snprintf(buf, sizeof(buf),
9228 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
9229 intf, VI_QOS_TMP_FILE);
9230 if (system(buf) != 0)
9231 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
9232
9233 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
9234 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
9235 if (system(buf) != 0) {
9236 sigma_dut_print(dut, DUT_MSG_ERROR,
9237 "VI_QOS_TEMP_FILE generation error failed");
9238 }
9239 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9240 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9241 if (system(buf) != 0) {
9242 sigma_dut_print(dut, DUT_MSG_ERROR,
9243 "VI_QOS_FILE generation failed");
9244 }
9245
9246 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9247 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9248 if (system(buf) != 0) {
9249 sigma_dut_print(dut, DUT_MSG_ERROR,
9250 "VI_QOS_FILE generation failed");
9251 }
9252
9253 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
9254 if (system(buf) != 0) {
9255 }
9256}
9257
9258
9259static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9260 struct sigma_cmd *cmd)
9261{
9262 const char *intf = get_param(cmd, "Interface");
9263 const char *val;
9264 int tid = 0;
9265 char buf[100];
9266
9267 val = get_param(cmd, "TID");
9268 if (val) {
9269 tid = atoi(val);
9270 if (tid)
9271 ath_sta_inject_frame(dut, intf, tid);
9272 }
9273
9274 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009275 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009276
9277 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
9278 if (system(buf) != 0) {
9279 sigma_dut_print(dut, DUT_MSG_ERROR,
9280 "wifitool senddelba failed");
9281 }
9282
9283 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
9284 if (system(buf) != 0) {
9285 sigma_dut_print(dut, DUT_MSG_ERROR,
9286 "wifitool sendaddba failed");
9287 }
9288
9289 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9290
9291 return 1;
9292}
9293
9294
Lior David9981b512017-01-20 13:16:40 +02009295#ifdef __linux__
9296
9297static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
9298 int agg_size)
9299{
9300 char dir[128], buf[128];
9301 FILE *f;
9302 regex_t re;
9303 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03009304 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02009305
9306 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
9307 sigma_dut_print(dut, DUT_MSG_ERROR,
9308 "failed to get wil6210 debugfs dir");
9309 return -1;
9310 }
9311
Jouni Malinen3aa72862019-05-29 23:14:51 +03009312 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
9313 if (res < 0 || res >= sizeof(buf))
9314 return -1;
Lior David9981b512017-01-20 13:16:40 +02009315 f = fopen(buf, "r");
9316 if (!f) {
9317 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009318 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009319 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9320 if (res < 0 || res >= sizeof(buf))
9321 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009322 f = fopen(buf, "r");
9323 if (!f) {
9324 sigma_dut_print(dut, DUT_MSG_ERROR,
9325 "failed to open: %s", buf);
9326 return -1;
9327 }
Lior David9981b512017-01-20 13:16:40 +02009328 }
9329
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009330 /* can be either VRING tx... or RING... */
9331 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009332 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9333 goto out;
9334 }
9335
9336 /* find TX VRING for the mac address */
9337 found = 0;
9338 while (fgets(buf, sizeof(buf), f)) {
9339 if (strcasestr(buf, dest_mac)) {
9340 found = 1;
9341 break;
9342 }
9343 }
9344
9345 if (!found) {
9346 sigma_dut_print(dut, DUT_MSG_ERROR,
9347 "no TX VRING for %s", dest_mac);
9348 goto out;
9349 }
9350
9351 /* extract VRING ID, "VRING tx_<id> = {" */
9352 if (!fgets(buf, sizeof(buf), f)) {
9353 sigma_dut_print(dut, DUT_MSG_ERROR,
9354 "no VRING start line for %s", dest_mac);
9355 goto out;
9356 }
9357
9358 rc = regexec(&re, buf, 2, m, 0);
9359 regfree(&re);
9360 if (rc || m[1].rm_so < 0) {
9361 sigma_dut_print(dut, DUT_MSG_ERROR,
9362 "no VRING TX ID for %s", dest_mac);
9363 goto out;
9364 }
9365 buf[m[1].rm_eo] = 0;
9366 vring_id = atoi(&buf[m[1].rm_so]);
9367
9368 /* send the addba command */
9369 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009370 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9371 if (res < 0 || res >= sizeof(buf))
9372 return -1;
Lior David9981b512017-01-20 13:16:40 +02009373 f = fopen(buf, "w");
9374 if (!f) {
9375 sigma_dut_print(dut, DUT_MSG_ERROR,
9376 "failed to open: %s", buf);
9377 return -1;
9378 }
9379
9380 fprintf(f, "add %d %d\n", vring_id, agg_size);
9381
9382 ret = 0;
9383
9384out:
9385 fclose(f);
9386
9387 return ret;
9388}
9389
9390
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009391int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9392 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009393{
9394 const char *val;
9395 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009396
9397 val = get_param(cmd, "TID");
9398 if (val) {
9399 tid = atoi(val);
9400 if (tid != 0) {
9401 sigma_dut_print(dut, DUT_MSG_ERROR,
9402 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9403 tid);
9404 }
9405 }
9406
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009407 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009408 if (!val) {
9409 sigma_dut_print(dut, DUT_MSG_ERROR,
9410 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009411 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009412 }
9413
Lior David9981b512017-01-20 13:16:40 +02009414 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009415 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009416
9417 return 1;
9418}
9419
Lior David9981b512017-01-20 13:16:40 +02009420#endif /* __linux__ */
9421
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009422
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009423static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9424 struct sigma_cmd *cmd)
9425{
9426#ifdef NL80211_SUPPORT
9427 const char *intf = get_param(cmd, "Interface");
9428 const char *val;
9429 int tid = -1;
9430 int bufsize = 64;
9431 struct nl_msg *msg;
9432 int ret = 0;
9433 struct nlattr *params;
9434 int ifindex;
9435
9436 val = get_param(cmd, "TID");
9437 if (val)
9438 tid = atoi(val);
9439
9440 if (tid == -1) {
9441 send_resp(dut, conn, SIGMA_ERROR,
9442 "ErrorCode,sta_send_addba tid invalid");
9443 return 0;
9444 }
9445
9446 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9447
9448 ifindex = if_nametoindex(intf);
9449 if (ifindex == 0) {
9450 sigma_dut_print(dut, DUT_MSG_ERROR,
9451 "%s: Index for interface %s failed",
9452 __func__, intf);
9453 send_resp(dut, conn, SIGMA_ERROR,
9454 "ErrorCode,sta_send_addba interface invalid");
9455 return 0;
9456 }
9457
9458 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9459 NL80211_CMD_VENDOR)) ||
9460 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9461 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9462 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9463 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9464 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9465 nla_put_u8(msg,
9466 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9467 QCA_WLAN_ADD_BA) ||
9468 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9469 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009470 nla_put_u16(msg,
9471 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9472 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009473 sigma_dut_print(dut, DUT_MSG_ERROR,
9474 "%s: err in adding vendor_cmd and vendor_data",
9475 __func__);
9476 nlmsg_free(msg);
9477 send_resp(dut, conn, SIGMA_ERROR,
9478 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9479 return 0;
9480 }
9481 nla_nest_end(msg, params);
9482
9483 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9484 if (ret) {
9485 sigma_dut_print(dut, DUT_MSG_ERROR,
9486 "%s: err in send_and_recv_msgs, ret=%d",
9487 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309488 if (ret == -EOPNOTSUPP)
9489 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009490 send_resp(dut, conn, SIGMA_ERROR,
9491 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9492 return 0;
9493 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009494#else /* NL80211_SUPPORT */
9495 sigma_dut_print(dut, DUT_MSG_ERROR,
9496 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009497#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309498
9499 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009500}
9501
9502
Jouni Malinenf7222712019-06-13 01:50:21 +03009503static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9504 struct sigma_conn *conn,
9505 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009506{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009507 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009508 case DRIVER_ATHEROS:
9509 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009510 case DRIVER_WCN:
9511 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009512#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009513 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009514 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009515#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009516 default:
9517 /*
9518 * There is no driver specific implementation for other drivers.
9519 * Ignore the command and report COMPLETE since the following
9520 * throughput test operation will end up sending ADDBA anyway.
9521 */
9522 return 1;
9523 }
9524}
9525
9526
9527int inject_eth_frame(int s, const void *data, size_t len,
9528 unsigned short ethtype, char *dst, char *src)
9529{
9530 struct iovec iov[4] = {
9531 {
9532 .iov_base = dst,
9533 .iov_len = ETH_ALEN,
9534 },
9535 {
9536 .iov_base = src,
9537 .iov_len = ETH_ALEN,
9538 },
9539 {
9540 .iov_base = &ethtype,
9541 .iov_len = sizeof(unsigned short),
9542 },
9543 {
9544 .iov_base = (void *) data,
9545 .iov_len = len,
9546 }
9547 };
9548 struct msghdr msg = {
9549 .msg_name = NULL,
9550 .msg_namelen = 0,
9551 .msg_iov = iov,
9552 .msg_iovlen = 4,
9553 .msg_control = NULL,
9554 .msg_controllen = 0,
9555 .msg_flags = 0,
9556 };
9557
9558 return sendmsg(s, &msg, 0);
9559}
9560
9561#if defined(__linux__) || defined(__QNXNTO__)
9562
9563int inject_frame(int s, const void *data, size_t len, int encrypt)
9564{
9565#define IEEE80211_RADIOTAP_F_WEP 0x04
9566#define IEEE80211_RADIOTAP_F_FRAG 0x08
9567 unsigned char rtap_hdr[] = {
9568 0x00, 0x00, /* radiotap version */
9569 0x0e, 0x00, /* radiotap length */
9570 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9571 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9572 0x00, /* padding */
9573 0x00, 0x00, /* RX and TX flags to indicate that */
9574 0x00, 0x00, /* this is the injected frame directly */
9575 };
9576 struct iovec iov[2] = {
9577 {
9578 .iov_base = &rtap_hdr,
9579 .iov_len = sizeof(rtap_hdr),
9580 },
9581 {
9582 .iov_base = (void *) data,
9583 .iov_len = len,
9584 }
9585 };
9586 struct msghdr msg = {
9587 .msg_name = NULL,
9588 .msg_namelen = 0,
9589 .msg_iov = iov,
9590 .msg_iovlen = 2,
9591 .msg_control = NULL,
9592 .msg_controllen = 0,
9593 .msg_flags = 0,
9594 };
9595
9596 if (encrypt)
9597 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9598
9599 return sendmsg(s, &msg, 0);
9600}
9601
9602
9603int open_monitor(const char *ifname)
9604{
9605#ifdef __QNXNTO__
9606 struct sockaddr_dl ll;
9607 int s;
9608
9609 memset(&ll, 0, sizeof(ll));
9610 ll.sdl_family = AF_LINK;
9611 ll.sdl_index = if_nametoindex(ifname);
9612 if (ll.sdl_index == 0) {
9613 perror("if_nametoindex");
9614 return -1;
9615 }
9616 s = socket(PF_INET, SOCK_RAW, 0);
9617#else /* __QNXNTO__ */
9618 struct sockaddr_ll ll;
9619 int s;
9620
9621 memset(&ll, 0, sizeof(ll));
9622 ll.sll_family = AF_PACKET;
9623 ll.sll_ifindex = if_nametoindex(ifname);
9624 if (ll.sll_ifindex == 0) {
9625 perror("if_nametoindex");
9626 return -1;
9627 }
9628 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9629#endif /* __QNXNTO__ */
9630 if (s < 0) {
9631 perror("socket[PF_PACKET,SOCK_RAW]");
9632 return -1;
9633 }
9634
9635 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9636 perror("monitor socket bind");
9637 close(s);
9638 return -1;
9639 }
9640
9641 return s;
9642}
9643
9644
9645static int hex2num(char c)
9646{
9647 if (c >= '0' && c <= '9')
9648 return c - '0';
9649 if (c >= 'a' && c <= 'f')
9650 return c - 'a' + 10;
9651 if (c >= 'A' && c <= 'F')
9652 return c - 'A' + 10;
9653 return -1;
9654}
9655
9656
9657int hwaddr_aton(const char *txt, unsigned char *addr)
9658{
9659 int i;
9660
9661 for (i = 0; i < 6; i++) {
9662 int a, b;
9663
9664 a = hex2num(*txt++);
9665 if (a < 0)
9666 return -1;
9667 b = hex2num(*txt++);
9668 if (b < 0)
9669 return -1;
9670 *addr++ = (a << 4) | b;
9671 if (i < 5 && *txt++ != ':')
9672 return -1;
9673 }
9674
9675 return 0;
9676}
9677
9678#endif /* defined(__linux__) || defined(__QNXNTO__) */
9679
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309680
9681#ifdef NL80211_SUPPORT
9682static int nl80211_send_frame_cmd(struct sigma_dut *dut, const char *intf,
9683 const u8 *data, size_t data_len, int freq)
9684{
9685 struct nl_msg *msg;
9686 int ret = 0;
9687 int ifindex;
9688
9689 ifindex = if_nametoindex(intf);
9690 if (ifindex == 0) {
9691 sigma_dut_print(dut, DUT_MSG_ERROR,
9692 "%s: Index for interface %s failed",
9693 __func__, intf);
9694 return -1;
9695 }
9696
9697 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9698 NL80211_CMD_FRAME)) ||
9699 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
9700 nla_put(msg, NL80211_ATTR_FRAME, data_len, data)) {
9701 sigma_dut_print(dut, DUT_MSG_ERROR,
9702 "%s: Error in adding NL80211_CMD_FRAME",
9703 __func__);
9704 nlmsg_free(msg);
9705 return -1;
9706 }
9707
9708 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9709 if (ret) {
9710 sigma_dut_print(dut, DUT_MSG_ERROR,
9711 "nl80211: Frame command failed: ret=%d (%s) req=%u",
9712 ret, strerror(-ret), freq);
9713 return -1;
9714 }
9715
9716 return 0;
9717}
9718#endif /* NL80211_SUPPORT */
9719
9720
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009721enum send_frame_type {
9722 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9723};
9724enum send_frame_protection {
9725 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9726};
9727
9728
9729static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309730 const char *intf, enum send_frame_type frame,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009731 enum send_frame_protection protected,
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309732 const char *dest, int use_monitor)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009733{
9734#ifdef __linux__
9735 unsigned char buf[1000], *pos;
9736 int s, res;
9737 char bssid[20], addr[20];
9738 char result[32], ssid[100];
9739 size_t ssid_len;
9740
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009741 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009742 sizeof(result)) < 0 ||
9743 strncmp(result, "COMPLETED", 9) != 0) {
9744 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9745 return 0;
9746 }
9747
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009748 if (get_wpa_status(get_station_ifname(dut), "bssid",
9749 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009750 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9751 "current BSSID");
9752 return 0;
9753 }
9754
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009755 if (get_wpa_status(get_station_ifname(dut), "address",
9756 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009757 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9758 "own MAC address");
9759 return 0;
9760 }
9761
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009762 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009763 < 0) {
9764 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9765 "current SSID");
9766 return 0;
9767 }
9768 ssid_len = strlen(ssid);
9769
9770 pos = buf;
9771
9772 /* Frame Control */
9773 switch (frame) {
9774 case DISASSOC:
9775 *pos++ = 0xa0;
9776 break;
9777 case DEAUTH:
9778 *pos++ = 0xc0;
9779 break;
9780 case SAQUERY:
9781 *pos++ = 0xd0;
9782 break;
9783 case AUTH:
9784 *pos++ = 0xb0;
9785 break;
9786 case ASSOCREQ:
9787 *pos++ = 0x00;
9788 break;
9789 case REASSOCREQ:
9790 *pos++ = 0x20;
9791 break;
9792 case DLS_REQ:
9793 *pos++ = 0xd0;
9794 break;
9795 }
9796
9797 if (protected == INCORRECT_KEY)
9798 *pos++ = 0x40; /* Set Protected field to 1 */
9799 else
9800 *pos++ = 0x00;
9801
9802 /* Duration */
9803 *pos++ = 0x00;
9804 *pos++ = 0x00;
9805
9806 /* addr1 = DA (current AP) */
9807 hwaddr_aton(bssid, pos);
9808 pos += 6;
9809 /* addr2 = SA (own address) */
9810 hwaddr_aton(addr, pos);
9811 pos += 6;
9812 /* addr3 = BSSID (current AP) */
9813 hwaddr_aton(bssid, pos);
9814 pos += 6;
9815
9816 /* Seq# (to be filled by driver/mac80211) */
9817 *pos++ = 0x00;
9818 *pos++ = 0x00;
9819
9820 if (protected == INCORRECT_KEY) {
9821 /* CCMP parameters */
9822 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9823 pos += 8;
9824 }
9825
9826 if (protected == INCORRECT_KEY) {
9827 switch (frame) {
9828 case DEAUTH:
9829 /* Reason code (encrypted) */
9830 memcpy(pos, "\xa7\x39", 2);
9831 pos += 2;
9832 break;
9833 case DISASSOC:
9834 /* Reason code (encrypted) */
9835 memcpy(pos, "\xa7\x39", 2);
9836 pos += 2;
9837 break;
9838 case SAQUERY:
9839 /* Category|Action|TransID (encrypted) */
9840 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9841 pos += 4;
9842 break;
9843 default:
9844 return -1;
9845 }
9846
9847 /* CCMP MIC */
9848 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9849 pos += 8;
9850 } else {
9851 switch (frame) {
9852 case DEAUTH:
9853 /* reason code = 8 */
9854 *pos++ = 0x08;
9855 *pos++ = 0x00;
9856 break;
9857 case DISASSOC:
9858 /* reason code = 8 */
9859 *pos++ = 0x08;
9860 *pos++ = 0x00;
9861 break;
9862 case SAQUERY:
9863 /* Category - SA Query */
9864 *pos++ = 0x08;
9865 /* SA query Action - Request */
9866 *pos++ = 0x00;
9867 /* Transaction ID */
9868 *pos++ = 0x12;
9869 *pos++ = 0x34;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05309870 if (dut->saquery_oci_freq) {
9871 /* OCI IE - Extended ID */
9872 *pos++ = 0xFF;
9873 *pos++ = 0x04;
9874 *pos++ = 0x36;
9875 /* Operating Class */
9876 *pos++ = 0x74;
9877 /* Primary Channel */
9878 *pos++ = freq_to_channel(dut->saquery_oci_freq);
9879 /* Frequency Segment 1 Channel Number */
9880 *pos++ = 0x00;
9881 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009882 break;
9883 case AUTH:
9884 /* Auth Alg (Open) */
9885 *pos++ = 0x00;
9886 *pos++ = 0x00;
9887 /* Seq# */
9888 *pos++ = 0x01;
9889 *pos++ = 0x00;
9890 /* Status code */
9891 *pos++ = 0x00;
9892 *pos++ = 0x00;
9893 break;
9894 case ASSOCREQ:
9895 /* Capability Information */
9896 *pos++ = 0x31;
9897 *pos++ = 0x04;
9898 /* Listen Interval */
9899 *pos++ = 0x0a;
9900 *pos++ = 0x00;
9901 /* SSID */
9902 *pos++ = 0x00;
9903 *pos++ = ssid_len;
9904 memcpy(pos, ssid, ssid_len);
9905 pos += ssid_len;
9906 /* Supported Rates */
9907 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9908 10);
9909 pos += 10;
9910 /* Extended Supported Rates */
9911 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9912 pos += 6;
9913 /* RSN */
9914 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9915 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9916 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9917 pos += 28;
9918 break;
9919 case REASSOCREQ:
9920 /* Capability Information */
9921 *pos++ = 0x31;
9922 *pos++ = 0x04;
9923 /* Listen Interval */
9924 *pos++ = 0x0a;
9925 *pos++ = 0x00;
9926 /* Current AP */
9927 hwaddr_aton(bssid, pos);
9928 pos += 6;
9929 /* SSID */
9930 *pos++ = 0x00;
9931 *pos++ = ssid_len;
9932 memcpy(pos, ssid, ssid_len);
9933 pos += ssid_len;
9934 /* Supported Rates */
9935 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9936 10);
9937 pos += 10;
9938 /* Extended Supported Rates */
9939 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9940 pos += 6;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05309941 /* RSNE - Group and Pairwise ciphers */
9942 memcpy(pos,
9943 "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04",
9944 14);
9945 pos += 14;
9946 /* RSNE - AKM Suite count */
9947 *pos++ = 0x01;
9948 *pos++ = 0x00;
9949 /* RSNE - AKM Suites */
9950 if (dut->program == PROGRAM_WPA3)
9951 memcpy(pos, "\x00\x0f\xac\x08", 4);
9952 else
9953 memcpy(pos, "\x00\x0f\xac\x02", 4);
9954 pos += 4;
9955 /* RSNE - Capabilities */
9956 *pos++ = 0xc0;
9957 if (dut->ocvc)
9958 *pos++ = 0x40;
9959 else
9960 *pos++ = 0x00;
9961 /* RSNE - PMKID list and Group Management Ciphers */
9962 memcpy(pos, "\x00\x00\x00\x0f\xac\x06", 6);
9963 pos += 6;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009964 break;
9965 case DLS_REQ:
9966 /* Category - DLS */
9967 *pos++ = 0x02;
9968 /* DLS Action - Request */
9969 *pos++ = 0x00;
9970 /* Destination MACAddress */
9971 if (dest)
9972 hwaddr_aton(dest, pos);
9973 else
9974 memset(pos, 0, 6);
9975 pos += 6;
9976 /* Source MACAddress */
9977 hwaddr_aton(addr, pos);
9978 pos += 6;
9979 /* Capability Information */
9980 *pos++ = 0x10; /* Privacy */
9981 *pos++ = 0x06; /* QoS */
9982 /* DLS Timeout Value */
9983 *pos++ = 0x00;
9984 *pos++ = 0x01;
9985 /* Supported rates */
9986 *pos++ = 0x01;
9987 *pos++ = 0x08;
9988 *pos++ = 0x0c; /* 6 Mbps */
9989 *pos++ = 0x12; /* 9 Mbps */
9990 *pos++ = 0x18; /* 12 Mbps */
9991 *pos++ = 0x24; /* 18 Mbps */
9992 *pos++ = 0x30; /* 24 Mbps */
9993 *pos++ = 0x48; /* 36 Mbps */
9994 *pos++ = 0x60; /* 48 Mbps */
9995 *pos++ = 0x6c; /* 54 Mbps */
9996 /* TODO: Extended Supported Rates */
9997 /* TODO: HT Capabilities */
9998 break;
9999 }
10000 }
10001
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010002 if (use_monitor) {
10003 s = open_monitor("sigmadut");
10004 if (s < 0) {
10005 send_resp(dut, conn, SIGMA_ERROR,
10006 "errorCode,Failed to open monitor socket");
10007 return 0;
10008 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010009
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010010 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
10011 if (res < 0) {
10012 send_resp(dut, conn, SIGMA_ERROR,
10013 "errorCode,Failed to inject frame");
10014 close(s);
10015 return 0;
10016 }
10017 if (res < pos - buf) {
10018 send_resp(dut, conn, SIGMA_ERROR,
10019 "errorCode,Only partial frame sent");
10020 close(s);
10021 return 0;
10022 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010023
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010024 close(s);
10025 } else {
10026#ifdef NL80211_SUPPORT
10027 int freq;
10028 char freq_str[10];
10029
10030 if (get_wpa_status(get_station_ifname(dut), "freq",
10031 freq_str, sizeof(freq_str)) < 0) {
10032 send_resp(dut, conn, SIGMA_ERROR,
10033 "errorCode,Could not get current operating frequency");
10034 return 0;
10035 }
10036 freq = atoi(freq_str);
10037
10038 if (nl80211_send_frame_cmd(dut, intf, buf, pos - buf, freq)) {
10039 send_resp(dut, conn, SIGMA_ERROR,
10040 "errorCode,Failed to inject frame");
10041 return 0;
10042 }
10043#else /* NL80211_SUPPORT */
10044 send_resp(dut, conn, SIGMA_ERROR,
10045 "errorCode,Failed to inject frame (no NL80211_SUPPORT)");
10046 return 0;
10047#endif /* NL80211_SUPPORT */
10048 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010049
10050 return 1;
10051#else /* __linux__ */
10052 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
10053 "yet supported");
10054 return 0;
10055#endif /* __linux__ */
10056}
10057
10058
10059static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
10060 struct sigma_conn *conn,
10061 struct sigma_cmd *cmd)
10062{
10063 const char *intf = get_param(cmd, "Interface");
10064 const char *sta, *val;
10065 unsigned char addr[ETH_ALEN];
10066 char buf[100];
10067
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010068 if (!intf)
10069 return -1;
10070
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010071 sta = get_param(cmd, "peer");
10072 if (sta == NULL)
10073 sta = get_param(cmd, "station");
10074 if (sta == NULL) {
10075 send_resp(dut, conn, SIGMA_ERROR,
10076 "ErrorCode,Missing peer address");
10077 return 0;
10078 }
10079 if (hwaddr_aton(sta, addr) < 0) {
10080 send_resp(dut, conn, SIGMA_ERROR,
10081 "ErrorCode,Invalid peer address");
10082 return 0;
10083 }
10084
10085 val = get_param(cmd, "type");
10086 if (val == NULL)
10087 return -1;
10088
10089 if (strcasecmp(val, "DISCOVERY") == 0) {
10090 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
10091 if (wpa_command(intf, buf) < 0) {
10092 send_resp(dut, conn, SIGMA_ERROR,
10093 "ErrorCode,Failed to send TDLS discovery");
10094 return 0;
10095 }
10096 return 1;
10097 }
10098
10099 if (strcasecmp(val, "SETUP") == 0) {
10100 int status = 0, timeout = 0;
10101
10102 val = get_param(cmd, "Status");
10103 if (val)
10104 status = atoi(val);
10105
10106 val = get_param(cmd, "Timeout");
10107 if (val)
10108 timeout = atoi(val);
10109
10110 if (status != 0 && status != 37) {
10111 send_resp(dut, conn, SIGMA_ERROR,
10112 "ErrorCode,Unsupported status value");
10113 return 0;
10114 }
10115
10116 if (timeout != 0 && timeout != 301) {
10117 send_resp(dut, conn, SIGMA_ERROR,
10118 "ErrorCode,Unsupported timeout value");
10119 return 0;
10120 }
10121
10122 if (status && timeout) {
10123 send_resp(dut, conn, SIGMA_ERROR,
10124 "ErrorCode,Unsupported timeout+status "
10125 "combination");
10126 return 0;
10127 }
10128
10129 if (status == 37 &&
10130 wpa_command(intf, "SET tdls_testing 0x200")) {
10131 send_resp(dut, conn, SIGMA_ERROR,
10132 "ErrorCode,Failed to enable "
10133 "decline setup response test mode");
10134 return 0;
10135 }
10136
10137 if (timeout == 301) {
10138 int res;
10139 if (dut->no_tpk_expiration)
10140 res = wpa_command(intf,
10141 "SET tdls_testing 0x108");
10142 else
10143 res = wpa_command(intf,
10144 "SET tdls_testing 0x8");
10145 if (res) {
10146 send_resp(dut, conn, SIGMA_ERROR,
10147 "ErrorCode,Failed to set short TPK "
10148 "lifetime");
10149 return 0;
10150 }
10151 }
10152
10153 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
10154 if (wpa_command(intf, buf) < 0) {
10155 send_resp(dut, conn, SIGMA_ERROR,
10156 "ErrorCode,Failed to send TDLS setup");
10157 return 0;
10158 }
10159 return 1;
10160 }
10161
10162 if (strcasecmp(val, "TEARDOWN") == 0) {
10163 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
10164 if (wpa_command(intf, buf) < 0) {
10165 send_resp(dut, conn, SIGMA_ERROR,
10166 "ErrorCode,Failed to send TDLS teardown");
10167 return 0;
10168 }
10169 return 1;
10170 }
10171
10172 send_resp(dut, conn, SIGMA_ERROR,
10173 "ErrorCode,Unsupported TDLS frame");
10174 return 0;
10175}
10176
10177
10178static int sta_ap_known(const char *ifname, const char *bssid)
10179{
10180 char buf[4096];
10181
Jouni Malinendd32f192018-09-15 02:55:19 +030010182 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010183 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
10184 return 0;
10185 if (strncmp(buf, "id=", 3) != 0)
10186 return 0;
10187 return 1;
10188}
10189
10190
10191static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
10192 const char *bssid)
10193{
10194 int res;
10195 struct wpa_ctrl *ctrl;
10196 char buf[256];
10197
10198 if (sta_ap_known(ifname, bssid))
10199 return 0;
10200 sigma_dut_print(dut, DUT_MSG_DEBUG,
10201 "AP not in BSS table - start scan");
10202
10203 ctrl = open_wpa_mon(ifname);
10204 if (ctrl == NULL) {
10205 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10206 "wpa_supplicant monitor connection");
10207 return -1;
10208 }
10209
10210 if (wpa_command(ifname, "SCAN") < 0) {
10211 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
10212 wpa_ctrl_detach(ctrl);
10213 wpa_ctrl_close(ctrl);
10214 return -1;
10215 }
10216
10217 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
10218 buf, sizeof(buf));
10219
10220 wpa_ctrl_detach(ctrl);
10221 wpa_ctrl_close(ctrl);
10222
10223 if (res < 0) {
10224 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
10225 return -1;
10226 }
10227
10228 if (sta_ap_known(ifname, bssid))
10229 return 0;
10230 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
10231 return -1;
10232}
10233
10234
10235static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
10236 struct sigma_conn *conn,
10237 struct sigma_cmd *cmd,
10238 const char *intf)
10239{
10240 char buf[200];
10241
10242 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
10243 if (system(buf) != 0) {
10244 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
10245 "ndsend");
10246 return 0;
10247 }
10248
10249 return 1;
10250}
10251
10252
10253static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
10254 struct sigma_conn *conn,
10255 struct sigma_cmd *cmd,
10256 const char *intf)
10257{
10258 char buf[200];
10259 const char *ip = get_param(cmd, "SenderIP");
10260
Peng Xu26b356d2017-10-04 17:58:16 -070010261 if (!ip)
10262 return 0;
10263
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010264 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
10265 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10266 if (system(buf) == 0) {
10267 sigma_dut_print(dut, DUT_MSG_INFO,
10268 "Neighbor Solicitation got a response "
10269 "for %s@%s", ip, intf);
10270 }
10271
10272 return 1;
10273}
10274
10275
10276static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
10277 struct sigma_conn *conn,
10278 struct sigma_cmd *cmd,
10279 const char *ifname)
10280{
10281 char buf[200];
10282 const char *ip = get_param(cmd, "SenderIP");
10283
10284 if (ip == NULL) {
10285 send_resp(dut, conn, SIGMA_ERROR,
10286 "ErrorCode,Missing SenderIP parameter");
10287 return 0;
10288 }
10289 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
10290 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10291 if (system(buf) != 0) {
10292 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
10293 "for %s@%s", ip, ifname);
10294 }
10295
10296 return 1;
10297}
10298
10299
10300static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
10301 struct sigma_conn *conn,
10302 struct sigma_cmd *cmd,
10303 const char *ifname)
10304{
10305 char buf[200];
10306 char ip[16];
10307 int s;
Peng Xub3756882017-10-04 14:39:09 -070010308 struct ifreq ifr;
10309 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010310
10311 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070010312 if (s < 0) {
10313 perror("socket");
10314 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010315 }
10316
Peng Xub3756882017-10-04 14:39:09 -070010317 memset(&ifr, 0, sizeof(ifr));
10318 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
10319 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
10320 sigma_dut_print(dut, DUT_MSG_INFO,
10321 "Failed to get %s IP address: %s",
10322 ifname, strerror(errno));
10323 close(s);
10324 return -1;
10325 }
10326 close(s);
10327
10328 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
10329 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
10330
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010331 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
10332 ip);
10333 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10334 if (system(buf) != 0) {
10335 }
10336
10337 return 1;
10338}
10339
10340
10341static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
10342 struct sigma_conn *conn,
10343 struct sigma_cmd *cmd,
10344 const char *ifname)
10345{
10346 char buf[200], addr[20];
10347 char dst[ETH_ALEN], src[ETH_ALEN];
10348 short ethtype = htons(ETH_P_ARP);
10349 char *pos;
10350 int s, res;
10351 const char *val;
10352 struct sockaddr_in taddr;
10353
10354 val = get_param(cmd, "dest");
10355 if (val)
10356 hwaddr_aton(val, (unsigned char *) dst);
10357
10358 val = get_param(cmd, "DestIP");
10359 if (val)
10360 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070010361 else
10362 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010363
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010364 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010365 sizeof(addr)) < 0)
10366 return -2;
10367 hwaddr_aton(addr, (unsigned char *) src);
10368
10369 pos = buf;
10370 *pos++ = 0x00;
10371 *pos++ = 0x01;
10372 *pos++ = 0x08;
10373 *pos++ = 0x00;
10374 *pos++ = 0x06;
10375 *pos++ = 0x04;
10376 *pos++ = 0x00;
10377 *pos++ = 0x02;
10378 memcpy(pos, src, ETH_ALEN);
10379 pos += ETH_ALEN;
10380 memcpy(pos, &taddr.sin_addr, 4);
10381 pos += 4;
10382 memcpy(pos, dst, ETH_ALEN);
10383 pos += ETH_ALEN;
10384 memcpy(pos, &taddr.sin_addr, 4);
10385 pos += 4;
10386
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010387 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010388 if (s < 0) {
10389 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
10390 "monitor socket");
10391 return 0;
10392 }
10393
10394 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
10395 if (res < 0) {
10396 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
10397 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053010398 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010399 return 0;
10400 }
10401
10402 close(s);
10403
10404 return 1;
10405}
10406
10407
10408static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
10409 struct sigma_conn *conn,
10410 struct sigma_cmd *cmd,
10411 const char *intf, const char *dest)
10412{
10413 char buf[100];
10414
10415 if (if_nametoindex("sigmadut") == 0) {
10416 snprintf(buf, sizeof(buf),
10417 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010418 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010419 if (system(buf) != 0 ||
10420 if_nametoindex("sigmadut") == 0) {
10421 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10422 "monitor interface with '%s'", buf);
10423 return -2;
10424 }
10425 }
10426
10427 if (system("ifconfig sigmadut up") != 0) {
10428 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10429 "monitor interface up");
10430 return -2;
10431 }
10432
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010433 return sta_inject_frame(dut, conn, intf, DLS_REQ, UNPROTECTED, dest, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010434}
10435
10436
10437static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10438 struct sigma_conn *conn,
10439 struct sigma_cmd *cmd)
10440{
10441 const char *intf = get_param(cmd, "Interface");
10442 const char *dest = get_param(cmd, "Dest");
10443 const char *type = get_param(cmd, "FrameName");
10444 const char *val;
10445 char buf[200], *pos, *end;
10446 int count, count2;
10447
10448 if (type == NULL)
10449 type = get_param(cmd, "Type");
10450
10451 if (intf == NULL || dest == NULL || type == NULL)
10452 return -1;
10453
10454 if (strcasecmp(type, "NeighAdv") == 0)
10455 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10456
10457 if (strcasecmp(type, "NeighSolicitReq") == 0)
10458 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10459
10460 if (strcasecmp(type, "ARPProbe") == 0)
10461 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10462
10463 if (strcasecmp(type, "ARPAnnounce") == 0)
10464 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10465
10466 if (strcasecmp(type, "ARPReply") == 0)
10467 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10468
10469 if (strcasecmp(type, "DLS-request") == 0 ||
10470 strcasecmp(type, "DLSrequest") == 0)
10471 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10472 dest);
10473
10474 if (strcasecmp(type, "ANQPQuery") != 0 &&
10475 strcasecmp(type, "Query") != 0) {
10476 send_resp(dut, conn, SIGMA_ERROR,
10477 "ErrorCode,Unsupported HS 2.0 send frame type");
10478 return 0;
10479 }
10480
10481 if (sta_scan_ap(dut, intf, dest) < 0) {
10482 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10483 "the requested AP");
10484 return 0;
10485 }
10486
10487 pos = buf;
10488 end = buf + sizeof(buf);
10489 count = 0;
10490 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10491
10492 val = get_param(cmd, "ANQP_CAP_LIST");
10493 if (val && atoi(val)) {
10494 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10495 count++;
10496 }
10497
10498 val = get_param(cmd, "VENUE_NAME");
10499 if (val && atoi(val)) {
10500 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10501 count++;
10502 }
10503
10504 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10505 if (val && atoi(val)) {
10506 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10507 count++;
10508 }
10509
10510 val = get_param(cmd, "ROAMING_CONS");
10511 if (val && atoi(val)) {
10512 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10513 count++;
10514 }
10515
10516 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10517 if (val && atoi(val)) {
10518 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10519 count++;
10520 }
10521
10522 val = get_param(cmd, "NAI_REALM_LIST");
10523 if (val && atoi(val)) {
10524 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10525 count++;
10526 }
10527
10528 val = get_param(cmd, "3GPP_INFO");
10529 if (val && atoi(val)) {
10530 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10531 count++;
10532 }
10533
10534 val = get_param(cmd, "DOMAIN_LIST");
10535 if (val && atoi(val)) {
10536 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10537 count++;
10538 }
10539
Jouni Malinen34cf9532018-04-29 19:26:33 +030010540 val = get_param(cmd, "Venue_URL");
10541 if (val && atoi(val)) {
10542 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10543 count++;
10544 }
10545
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010546 val = get_param(cmd, "Advice_Of_Charge");
10547 if (val && atoi(val)) {
10548 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10549 count++;
10550 }
10551
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010552 if (count && wpa_command(intf, buf)) {
10553 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10554 return 0;
10555 }
10556
10557 pos = buf;
10558 end = buf + sizeof(buf);
10559 count2 = 0;
10560 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
10561
10562 val = get_param(cmd, "HS_CAP_LIST");
10563 if (val && atoi(val)) {
10564 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
10565 count2++;
10566 }
10567
10568 val = get_param(cmd, "OPER_NAME");
10569 if (val && atoi(val)) {
10570 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
10571 count2++;
10572 }
10573
10574 val = get_param(cmd, "WAN_METRICS");
10575 if (!val)
10576 val = get_param(cmd, "WAN_MAT");
10577 if (!val)
10578 val = get_param(cmd, "WAN_MET");
10579 if (val && atoi(val)) {
10580 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10581 count2++;
10582 }
10583
10584 val = get_param(cmd, "CONNECTION_CAPABILITY");
10585 if (val && atoi(val)) {
10586 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10587 count2++;
10588 }
10589
10590 val = get_param(cmd, "OP_CLASS");
10591 if (val && atoi(val)) {
10592 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10593 count2++;
10594 }
10595
10596 val = get_param(cmd, "OSU_PROVIDER_LIST");
10597 if (val && atoi(val)) {
10598 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10599 count2++;
10600 }
10601
Jouni Malinenf67afec2018-04-29 19:24:58 +030010602 val = get_param(cmd, "OPER_ICON_METADATA");
10603 if (!val)
10604 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10605 if (val && atoi(val)) {
10606 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10607 count2++;
10608 }
10609
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010610 if (count && count2) {
10611 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10612 "second query");
10613 sleep(1);
10614 }
10615
10616 if (count2 && wpa_command(intf, buf)) {
10617 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10618 "failed");
10619 return 0;
10620 }
10621
10622 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10623 if (val) {
10624 if (count || count2) {
10625 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10626 "sending out second query");
10627 sleep(1);
10628 }
10629
10630 if (strcmp(val, "1") == 0)
10631 val = "mail.example.com";
10632 snprintf(buf, end - pos,
10633 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10634 dest, val);
10635 if (wpa_command(intf, buf)) {
10636 send_resp(dut, conn, SIGMA_ERROR,
10637 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10638 "failed");
10639 return 0;
10640 }
10641 }
10642
10643 val = get_param(cmd, "ICON_REQUEST");
10644 if (val) {
10645 if (count || count2) {
10646 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10647 "sending out second query");
10648 sleep(1);
10649 }
10650
10651 snprintf(buf, end - pos,
10652 "HS20_ICON_REQUEST %s %s", dest, val);
10653 if (wpa_command(intf, buf)) {
10654 send_resp(dut, conn, SIGMA_ERROR,
10655 "ErrorCode,HS20_ICON_REQUEST failed");
10656 return 0;
10657 }
10658 }
10659
10660 return 1;
10661}
10662
10663
10664static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10665 struct sigma_conn *conn,
10666 struct sigma_cmd *cmd)
10667{
10668 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010669 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010670 int chwidth, nss;
10671
10672 val = get_param(cmd, "framename");
10673 if (!val)
10674 return -1;
10675 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10676
10677 /* Command sequence to generate Op mode notification */
10678 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010679 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010680
10681 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010682 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010683
10684 /* Extract Channel width */
10685 val = get_param(cmd, "Channel_width");
10686 if (val) {
10687 switch (atoi(val)) {
10688 case 20:
10689 chwidth = 0;
10690 break;
10691 case 40:
10692 chwidth = 1;
10693 break;
10694 case 80:
10695 chwidth = 2;
10696 break;
10697 case 160:
10698 chwidth = 3;
10699 break;
10700 default:
10701 chwidth = 2;
10702 break;
10703 }
10704
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010705 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010706 }
10707
10708 /* Extract NSS */
10709 val = get_param(cmd, "NSS");
10710 if (val) {
10711 switch (atoi(val)) {
10712 case 1:
10713 nss = 1;
10714 break;
10715 case 2:
10716 nss = 3;
10717 break;
10718 case 3:
10719 nss = 7;
10720 break;
10721 default:
10722 /* We do not support NSS > 3 */
10723 nss = 3;
10724 break;
10725 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010726 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010727 }
10728
10729 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010730 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010731 }
10732
10733 return 1;
10734}
10735
10736
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010737static int wcn_sta_set_pmf_config(struct sigma_dut *dut, const char *intf,
10738 enum send_frame_protection protected)
10739{
10740#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053010741 return wcn_wifi_test_config_set_u8(
10742 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PMF_PROTECTION,
10743 protected);
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010744#else /* NL80211_SUPPORT */
10745 sigma_dut_print(dut, DUT_MSG_ERROR,
10746 "PMF config cannot be set without NL80211_SUPPORT defined");
10747 return -1;
10748#endif /* NL80211_SUPPORT */
10749}
10750
10751
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010752static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
10753 struct sigma_conn *conn,
10754 struct sigma_cmd *cmd)
10755{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010756 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010757 case DRIVER_ATHEROS:
10758 return ath_sta_send_frame_vht(dut, conn, cmd);
10759 default:
10760 send_resp(dut, conn, SIGMA_ERROR,
10761 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
10762 return 0;
10763 }
10764}
10765
10766
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010767static int wcn_sta_send_disassoc(struct sigma_dut *dut, const char *intf)
10768{
10769#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053010770 return wcn_wifi_test_config_set_flag(
10771 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISASSOC_TX);
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010772#else /* NL80211_SUPPORT */
10773 sigma_dut_print(dut, DUT_MSG_ERROR,
10774 "Disassoc Tx cannot be done without NL80211_SUPPORT defined");
10775 return -1;
10776#endif /* NL80211_SUPPORT */
10777}
10778
10779
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010780static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
10781 struct sigma_cmd *cmd)
10782{
10783 const char *val;
10784 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010785 enum send_frame_protection protected;
10786 const char *pmf;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010787
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010788 if (!intf)
10789 return -1;
10790
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010791 val = get_param(cmd, "framename");
10792 if (!val)
10793 return -1;
10794 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10795
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010796 pmf = get_param(cmd, "PMFProtected");
10797 if (!pmf)
10798 pmf = get_param(cmd, "Protected");
10799 if (pmf) {
10800 if (strcasecmp(pmf, "Correct-key") == 0 ||
10801 strcasecmp(pmf, "CorrectKey") == 0) {
10802 protected = CORRECT_KEY;
10803 } else if (strcasecmp(pmf, "IncorrectKey") == 0) {
10804 protected = INCORRECT_KEY;
10805 } else if (strcasecmp(pmf, "Unprotected") == 0) {
10806 protected = UNPROTECTED;
10807 } else {
10808 send_resp(dut, conn, SIGMA_ERROR,
10809 "errorCode,Unsupported PMFProtected");
10810 return STATUS_SENT_ERROR;
10811 }
10812 sigma_dut_print(dut, DUT_MSG_DEBUG, "Config PMF protection %d",
10813 protected);
10814 wcn_sta_set_pmf_config(dut, intf, protected);
10815 }
10816
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010817 /* Command sequence to generate Op mode notification */
10818 if (val && strcasecmp(val, "action") == 0) {
10819 val = get_param(cmd, "PPDUTxType");
10820 if (val && strcasecmp(val, "TB") == 0) {
10821 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
10822 sigma_dut_print(dut, DUT_MSG_ERROR,
10823 "failed to send TB PPDU Tx cfg");
10824 send_resp(dut, conn, SIGMA_ERROR,
10825 "ErrorCode,set TB PPDU Tx cfg failed");
10826 return 0;
10827 }
10828 return 1;
10829 }
10830
10831 sigma_dut_print(dut, DUT_MSG_ERROR,
10832 "Action Tx type is not defined");
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010833
10834 return SUCCESS_SEND_STATUS;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010835 }
10836
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010837 if (strcasecmp(val, "disassoc") == 0)
10838 wcn_sta_send_disassoc(dut, intf);
10839
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010840 return 1;
10841}
10842
10843
10844static int cmd_sta_send_frame_he(struct sigma_dut *dut,
10845 struct sigma_conn *conn,
10846 struct sigma_cmd *cmd)
10847{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010848 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010849 case DRIVER_WCN:
10850 return wcn_sta_send_frame_he(dut, conn, cmd);
10851 default:
10852 send_resp(dut, conn, SIGMA_ERROR,
10853 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
10854 return 0;
10855 }
10856}
10857
10858
Lior David0fe101e2017-03-09 16:09:50 +020010859#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010860
10861static int
10862wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
10863 const char *frame_name, const char *dest_mac)
10864{
10865 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
10866 const char *ssid = get_param(cmd, "ssid");
10867 const char *countstr = get_param(cmd, "count");
10868 const char *channelstr = get_param(cmd, "channel");
10869 const char *group_id = get_param(cmd, "groupid");
10870 const char *client_id = get_param(cmd, "clientmac");
10871 int count, channel, freq, i;
10872 const char *fname;
10873 char frame[1024], src_mac[20], group_id_attr[25],
10874 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
10875 const char *group_ssid;
10876 const int group_ssid_prefix_len = 9;
10877 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
10878 size_t framelen = sizeof(frame);
10879 struct template_frame_tag tags[2];
10880 size_t tags_total = ARRAY_SIZE(tags);
10881 int tag_index, len, dst_len;
10882
10883 if (!countstr || !channelstr) {
10884 sigma_dut_print(dut, DUT_MSG_ERROR,
10885 "Missing argument: count, channel");
10886 return -1;
10887 }
10888 if (isprobereq && !ssid) {
10889 sigma_dut_print(dut, DUT_MSG_ERROR,
10890 "Missing argument: ssid");
10891 return -1;
10892 }
10893 if (!isprobereq && (!group_id || !client_id)) {
10894 sigma_dut_print(dut, DUT_MSG_ERROR,
10895 "Missing argument: group_id, client_id");
10896 return -1;
10897 }
10898
10899 count = atoi(countstr);
10900 channel = atoi(channelstr);
10901 freq = channel_to_freq(dut, channel);
10902
10903 if (!freq) {
10904 sigma_dut_print(dut, DUT_MSG_ERROR,
10905 "invalid channel: %s", channelstr);
10906 return -1;
10907 }
10908
10909 if (isprobereq) {
10910 if (strcasecmp(ssid, "wildcard") == 0) {
10911 fname = "probe_req_wildcard.txt";
10912 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
10913 fname = "probe_req_P2P_Wildcard.txt";
10914 } else {
10915 sigma_dut_print(dut, DUT_MSG_ERROR,
10916 "invalid probe request type");
10917 return -1;
10918 }
10919 } else {
10920 fname = "P2P_device_discovery_req.txt";
10921 }
10922
10923 if (parse_template_frame_file(dut, fname, frame, &framelen,
10924 tags, &tags_total)) {
10925 sigma_dut_print(dut, DUT_MSG_ERROR,
10926 "invalid frame template: %s", fname);
10927 return -1;
10928 }
10929
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010930 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010931 src_mac, sizeof(src_mac)) < 0 ||
10932 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
10933 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
10934 return -1;
10935 /* Use wildcard BSSID, since we are in PBSS */
10936 memset(&hdr->addr3, 0xFF, ETH_ALEN);
10937
10938 if (!isprobereq) {
10939 tag_index = find_template_frame_tag(tags, tags_total, 1);
10940 if (tag_index < 0) {
10941 sigma_dut_print(dut, DUT_MSG_ERROR,
10942 "can't find device id attribute");
10943 return -1;
10944 }
10945 if (parse_mac_address(dut, client_id,
10946 (unsigned char *) client_mac)) {
10947 sigma_dut_print(dut, DUT_MSG_ERROR,
10948 "invalid client_id: %s", client_id);
10949 return -1;
10950 }
10951 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10952 framelen - tags[tag_index].offset,
10953 IEEE80211_P2P_ATTR_DEVICE_ID,
10954 client_mac, ETH_ALEN)) {
10955 sigma_dut_print(dut, DUT_MSG_ERROR,
10956 "fail to replace device id attribute");
10957 return -1;
10958 }
10959
10960 /*
10961 * group_id arg contains device MAC address followed by
10962 * space and SSID (DIRECT-somessid).
10963 * group id attribute contains device address (6 bytes)
10964 * followed by SSID prefix DIRECT-XX (9 bytes)
10965 */
10966 if (strlen(group_id) < sizeof(device_macstr)) {
10967 sigma_dut_print(dut, DUT_MSG_ERROR,
10968 "group_id arg too short");
10969 return -1;
10970 }
10971 memcpy(device_macstr, group_id, sizeof(device_macstr));
10972 device_macstr[sizeof(device_macstr) - 1] = '\0';
10973 if (parse_mac_address(dut, device_macstr,
10974 (unsigned char *) group_id_attr)) {
10975 sigma_dut_print(dut, DUT_MSG_ERROR,
10976 "fail to parse device address from group_id");
10977 return -1;
10978 }
10979 group_ssid = strchr(group_id, ' ');
10980 if (!group_ssid) {
10981 sigma_dut_print(dut, DUT_MSG_ERROR,
10982 "invalid group_id arg, no ssid");
10983 return -1;
10984 }
10985 group_ssid++;
10986 len = strlen(group_ssid);
10987 if (len < group_ssid_prefix_len) {
10988 sigma_dut_print(dut, DUT_MSG_ERROR,
10989 "group_id SSID too short");
10990 return -1;
10991 }
10992 dst_len = sizeof(group_id_attr) - ETH_ALEN;
10993 if (len > dst_len) {
10994 sigma_dut_print(dut, DUT_MSG_ERROR,
10995 "group_id SSID (%s) too long",
10996 group_ssid);
10997 return -1;
10998 }
10999
11000 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
11001 tag_index = find_template_frame_tag(tags, tags_total, 2);
11002 if (tag_index < 0) {
11003 sigma_dut_print(dut, DUT_MSG_ERROR,
11004 "can't find group id attribute");
11005 return -1;
11006 }
11007 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11008 framelen - tags[tag_index].offset,
11009 IEEE80211_P2P_ATTR_GROUP_ID,
11010 group_id_attr,
11011 sizeof(group_id_attr))) {
11012 sigma_dut_print(dut, DUT_MSG_ERROR,
11013 "fail to replace group id attribute");
11014 return -1;
11015 }
11016 }
11017
11018 for (i = 0; i < count; i++) {
11019 if (wil6210_transmit_frame(dut, freq,
11020 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
11021 frame, framelen)) {
11022 sigma_dut_print(dut, DUT_MSG_ERROR,
11023 "fail to transmit probe request frame");
11024 return -1;
11025 }
11026 }
11027
11028 return 0;
11029}
11030
11031
Lior David0fe101e2017-03-09 16:09:50 +020011032int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
11033 struct sigma_cmd *cmd)
11034{
11035 const char *frame_name = get_param(cmd, "framename");
11036 const char *mac = get_param(cmd, "dest_mac");
11037
11038 if (!frame_name || !mac) {
11039 sigma_dut_print(dut, DUT_MSG_ERROR,
11040 "framename and dest_mac must be provided");
11041 return -1;
11042 }
11043
11044 if (strcasecmp(frame_name, "brp") == 0) {
11045 const char *l_rx = get_param(cmd, "L-RX");
11046 int l_rx_i;
11047
11048 if (!l_rx) {
11049 sigma_dut_print(dut, DUT_MSG_ERROR,
11050 "L-RX must be provided");
11051 return -1;
11052 }
11053 l_rx_i = atoi(l_rx);
11054
11055 sigma_dut_print(dut, DUT_MSG_INFO,
11056 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
11057 mac, l_rx);
11058 if (l_rx_i != 16) {
11059 sigma_dut_print(dut, DUT_MSG_ERROR,
11060 "unsupported L-RX: %s", l_rx);
11061 return -1;
11062 }
11063
11064 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
11065 return -1;
11066 } else if (strcasecmp(frame_name, "ssw") == 0) {
11067 sigma_dut_print(dut, DUT_MSG_INFO,
11068 "dev_send_frame: SLS, dest_mac %s", mac);
11069 if (wil6210_send_sls(dut, mac))
11070 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011071 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
11072 (strcasecmp(frame_name, "devdiscreq") == 0)) {
11073 sigma_dut_print(dut, DUT_MSG_INFO,
11074 "dev_send_frame: %s, dest_mac %s", frame_name,
11075 mac);
11076 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
11077 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020011078 } else {
11079 sigma_dut_print(dut, DUT_MSG_ERROR,
11080 "unsupported frame type: %s", frame_name);
11081 return -1;
11082 }
11083
11084 return 1;
11085}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011086
Lior David0fe101e2017-03-09 16:09:50 +020011087#endif /* __linux__ */
11088
11089
11090static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
11091 struct sigma_conn *conn,
11092 struct sigma_cmd *cmd)
11093{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011094 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020011095#ifdef __linux__
11096 case DRIVER_WIL6210:
11097 return wil6210_send_frame_60g(dut, conn, cmd);
11098#endif /* __linux__ */
11099 default:
11100 send_resp(dut, conn, SIGMA_ERROR,
11101 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
11102 return 0;
11103 }
11104}
11105
11106
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011107static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
11108 const char *intf, struct sigma_cmd *cmd)
11109{
11110 const char *val, *addr;
11111 char buf[100];
11112
11113 addr = get_param(cmd, "DestMac");
11114 if (!addr) {
11115 send_resp(dut, conn, SIGMA_INVALID,
11116 "ErrorCode,AP MAC address is missing");
11117 return 0;
11118 }
11119
11120 val = get_param(cmd, "ANQPQuery_ID");
11121 if (!val) {
11122 send_resp(dut, conn, SIGMA_INVALID,
11123 "ErrorCode,Missing ANQPQuery_ID");
11124 return 0;
11125 }
11126
11127 if (strcasecmp(val, "NeighborReportReq") == 0) {
11128 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
11129 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
11130 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
11131 } else {
11132 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
11133 val);
11134 send_resp(dut, conn, SIGMA_INVALID,
11135 "ErrorCode,Invalid ANQPQuery_ID");
11136 return 0;
11137 }
11138
Ashwini Patild174f2c2017-04-13 16:49:46 +053011139 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
11140 * (Address3 = Wildcard BSSID when sent to not-associated AP;
11141 * if associated, AP BSSID).
11142 */
11143 if (wpa_command(intf, "SET gas_address3 1") < 0) {
11144 send_resp(dut, conn, SIGMA_ERROR,
11145 "ErrorCode,Failed to set gas_address3");
11146 return 0;
11147 }
11148
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011149 if (wpa_command(intf, buf) < 0) {
11150 send_resp(dut, conn, SIGMA_ERROR,
11151 "ErrorCode,Failed to send ANQP query");
11152 return 0;
11153 }
11154
11155 return 1;
11156}
11157
11158
11159static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
11160 struct sigma_conn *conn,
11161 const char *intf,
11162 struct sigma_cmd *cmd)
11163{
11164 const char *val = get_param(cmd, "FrameName");
11165
11166 if (val && strcasecmp(val, "ANQPQuery") == 0)
11167 return mbo_send_anqp_query(dut, conn, intf, cmd);
11168
11169 return 2;
11170}
11171
11172
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011173static enum sigma_cmd_result cmd_sta_send_frame_wpa3(struct sigma_dut *dut,
11174 struct sigma_conn *conn,
11175 const char *intf,
11176 struct sigma_cmd *cmd)
11177{
11178 const char *val = get_param(cmd, "framename");
11179
11180 if (!val)
11181 return INVALID_SEND_STATUS;
11182
11183 if (strcasecmp(val, "SAQueryReq") == 0) {
11184 val = get_param(cmd, "OCIChannel");
11185
11186 if (!val) {
11187 send_resp(dut, conn, SIGMA_ERROR,
11188 "errorCode,OCIChannel not present");
11189 return STATUS_SENT_ERROR;
11190 }
11191
11192 dut->saquery_oci_freq = channel_to_freq(dut, atoi(val));
11193 if (!dut->saquery_oci_freq) {
11194 send_resp(dut, conn, SIGMA_ERROR,
11195 "errorCode,Invalid OCIChannel number");
11196 return STATUS_SENT_ERROR;
11197 }
11198
11199 return sta_inject_frame(dut, conn, intf, SAQUERY, CORRECT_KEY,
11200 NULL, 0);
11201 }
11202
11203 if (strcasecmp(val, "reassocreq") == 0)
11204 return sta_inject_frame(dut, conn, intf, REASSOCREQ,
11205 CORRECT_KEY, NULL, 0);
11206
Veerendranath9f81dfb2020-08-10 01:21:29 -070011207 if (strcasecmp(val, "ANQPQuery") == 0) {
11208 char buf[50];
11209 const char *dest = get_param(cmd, "DestMac");
11210 const char *chan = get_param(cmd, "channel");
Veerendranath Jakkam78862fc2020-11-19 21:23:27 +053011211 const char *freq_str = get_param(cmd, "ChnlFreq");
Veerendranath9f81dfb2020-08-10 01:21:29 -070011212 int len, freq;
11213
Veerendranath Jakkam78862fc2020-11-19 21:23:27 +053011214 if (freq_str)
11215 freq = atoi(freq_str);
11216 else
11217 freq = chan ? channel_to_freq(dut, atoi(chan)) : 0;
11218
Veerendranath9f81dfb2020-08-10 01:21:29 -070011219 if (!dest || !freq)
11220 return INVALID_SEND_STATUS;
11221
11222 len = snprintf(buf, sizeof(buf), "ANQP_GET %s freq=%d 257",
11223 dest, freq);
11224 if (len < 0 || len >= sizeof(buf)) {
11225 sigma_dut_print(dut, DUT_MSG_ERROR,
11226 "Failed to allocate buf");
11227 return ERROR_SEND_STATUS;
11228 }
11229
11230 if (wpa_command(intf, buf) != 0) {
11231 send_resp(dut, conn, SIGMA_ERROR,
11232 "ErrorCode,Failed to send ANQP Query frame");
11233 return STATUS_SENT_ERROR;
11234 }
11235
11236 sigma_dut_print(dut, DUT_MSG_DEBUG,
11237 "ANQP Query sent: %s", buf);
11238
11239 return SUCCESS_SEND_STATUS;
11240 }
11241
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011242 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported framename");
11243 return STATUS_SENT_ERROR;
11244}
11245
11246
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011247static enum sigma_cmd_result
11248cmd_sta_send_frame_mscs(struct sigma_dut *dut, struct sigma_conn *conn,
11249 const char *intf, struct sigma_cmd *cmd)
11250{
11251 char buf[128], *pos;
11252 const char *val, *classifier_type = "04", *type;
11253 int len, rem_len;
11254 u8 up_bitmap;
11255
11256 val = get_param(cmd, "FrameName");
11257 type = get_param(cmd, "Request_Type");
11258 if (!val || !type || strcasecmp(val, "MSCSReq") != 0) {
11259 sigma_dut_print(dut, DUT_MSG_ERROR,
11260 "%s: frame name or type not valid", __func__);
11261 return INVALID_SEND_STATUS;
11262 }
11263
11264 rem_len = sizeof(buf);
11265 pos = buf;
11266 if (strcasecmp(type, "add") == 0) {
11267 len = snprintf(pos, rem_len, "MSCS add");
11268 } else if (strcasecmp(type, "update") == 0) {
11269 len = snprintf(pos, rem_len, "MSCS change");
11270 } else if (strcasecmp(type, "remove") == 0) {
11271 if (wpa_command(intf, "MSCS remove") != 0) {
11272 send_resp(dut, conn, SIGMA_ERROR,
11273 "ErrorCode,Failed to send MSCS frame req");
11274 return STATUS_SENT_ERROR;
11275 }
11276 return SUCCESS_SEND_STATUS;
11277 } else {
11278 sigma_dut_print(dut, DUT_MSG_ERROR,
11279 "%s: request type invalid", __func__);
11280 return INVALID_SEND_STATUS;
11281 }
11282
11283 if (len < 0 || len >= rem_len)
11284 goto fail;
11285
11286 pos += len;
11287 rem_len -= len;
11288
11289 val = get_param(cmd, "User_Priority_Bitmap");
11290 if (!val) {
11291 sigma_dut_print(dut, DUT_MSG_ERROR,
11292 "%s: user priority bitmap empty", __func__);
11293 return INVALID_SEND_STATUS;
11294 }
11295
11296 switch (atoi(val)) {
11297 case 0:
11298 up_bitmap = 0x00;
11299 break;
11300 case 1:
11301 up_bitmap = 0xF0;
11302 break;
11303 case 2:
11304 up_bitmap = 0xF6;
11305 break;
11306 default:
11307 sigma_dut_print(dut, DUT_MSG_ERROR,
11308 "%s: Unknown User_Priority_Bitmap value %d",
11309 __func__, atoi(val));
11310 return INVALID_SEND_STATUS;
11311 }
11312
11313 len = snprintf(pos, rem_len, " up_bitmap=%02x", up_bitmap);
11314 if (len < 0 || len >= rem_len)
11315 goto fail;
11316
11317 pos += len;
11318 rem_len -= len;
11319
11320 val = get_param(cmd, "User_Priority_Limit");
11321 if (!val) {
11322 sigma_dut_print(dut, DUT_MSG_ERROR,
11323 "%s: invalid user priority limit", __func__);
11324 return INVALID_SEND_STATUS;
11325 }
11326
11327 len = snprintf(pos, rem_len, " up_limit=%s", val);
11328 if (len < 0 || len >= rem_len)
11329 goto fail;
11330
11331 pos += len;
11332 rem_len -= len;
11333
11334 val = get_param(cmd, "Stream_Timeout");
11335 if (!val)
11336 val = get_param(cmd, "Stream_Timtout");
11337 if (!val) {
11338 sigma_dut_print(dut, DUT_MSG_ERROR,
11339 "%s: invalid stream timeout", __func__);
11340 return INVALID_SEND_STATUS;
11341 }
11342
11343 len = snprintf(pos, rem_len, " stream_timeout=%s", val);
11344 if (len < 0 || len >= rem_len)
11345 goto fail;
11346
11347 pos += len;
11348 rem_len -= len;
11349
11350 val = get_param(cmd, "TCLAS_Mask");
11351 if (!val) {
11352 sigma_dut_print(dut, DUT_MSG_ERROR,
11353 "%s: invalid tclas mask", __func__);
11354 return INVALID_SEND_STATUS;
11355 }
11356
11357 len = snprintf(pos, rem_len, " frame_classifier=%s%lx%032x",
11358 classifier_type, strtol(val, NULL, 2), 0);
11359 if (len < 0 || len >= rem_len)
11360 goto fail;
11361
11362 if (wpa_command(intf, buf) != 0) {
11363 send_resp(dut, conn, SIGMA_ERROR,
11364 "ErrorCode,Failed to send MSCS frame req");
11365 return STATUS_SENT_ERROR;
11366 }
11367
11368 sigma_dut_print(dut, DUT_MSG_DEBUG,
11369 "MSCS frame request sent: %s", buf);
11370
11371 return SUCCESS_SEND_STATUS;
11372fail:
11373 sigma_dut_print(dut, DUT_MSG_ERROR,
11374 "Failed to create MSCS frame req");
11375 return ERROR_SEND_STATUS;
11376}
11377
11378
Jouni Malinenf7222712019-06-13 01:50:21 +030011379enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
11380 struct sigma_conn *conn,
11381 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011382{
11383 const char *intf = get_param(cmd, "Interface");
11384 const char *val;
11385 enum send_frame_type frame;
11386 enum send_frame_protection protected;
11387 char buf[100];
11388 unsigned char addr[ETH_ALEN];
11389 int res;
11390
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011391 if (!intf)
11392 return -1;
11393
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011394 val = get_param(cmd, "program");
11395 if (val == NULL)
11396 val = get_param(cmd, "frame");
11397 if (val && strcasecmp(val, "TDLS") == 0)
11398 return cmd_sta_send_frame_tdls(dut, conn, cmd);
11399 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011400 strcasecmp(val, "HS2-R2") == 0 ||
11401 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011402 return cmd_sta_send_frame_hs2(dut, conn, cmd);
11403 if (val && strcasecmp(val, "VHT") == 0)
11404 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011405 if (val && strcasecmp(val, "HE") == 0)
11406 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070011407 if (val && strcasecmp(val, "LOC") == 0)
11408 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020011409 if (val && strcasecmp(val, "60GHz") == 0)
11410 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011411 if (val && strcasecmp(val, "MBO") == 0) {
11412 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
11413 if (res != 2)
11414 return res;
11415 }
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011416 if (val && strcasecmp(val, "WPA3") == 0)
11417 return cmd_sta_send_frame_wpa3(dut, conn, intf, cmd);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011418 if (val && strcasecmp(val, "QM") == 0)
11419 return cmd_sta_send_frame_mscs(dut, conn, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011420
11421 val = get_param(cmd, "TD_DISC");
11422 if (val) {
11423 if (hwaddr_aton(val, addr) < 0)
11424 return -1;
11425 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
11426 if (wpa_command(intf, buf) < 0) {
11427 send_resp(dut, conn, SIGMA_ERROR,
11428 "ErrorCode,Failed to send TDLS discovery");
11429 return 0;
11430 }
11431 return 1;
11432 }
11433
11434 val = get_param(cmd, "TD_Setup");
11435 if (val) {
11436 if (hwaddr_aton(val, addr) < 0)
11437 return -1;
11438 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
11439 if (wpa_command(intf, buf) < 0) {
11440 send_resp(dut, conn, SIGMA_ERROR,
11441 "ErrorCode,Failed to start TDLS setup");
11442 return 0;
11443 }
11444 return 1;
11445 }
11446
11447 val = get_param(cmd, "TD_TearDown");
11448 if (val) {
11449 if (hwaddr_aton(val, addr) < 0)
11450 return -1;
11451 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
11452 if (wpa_command(intf, buf) < 0) {
11453 send_resp(dut, conn, SIGMA_ERROR,
11454 "ErrorCode,Failed to tear down TDLS link");
11455 return 0;
11456 }
11457 return 1;
11458 }
11459
11460 val = get_param(cmd, "TD_ChannelSwitch");
11461 if (val) {
11462 /* TODO */
11463 send_resp(dut, conn, SIGMA_ERROR,
11464 "ErrorCode,TD_ChannelSwitch not yet supported");
11465 return 0;
11466 }
11467
11468 val = get_param(cmd, "TD_NF");
11469 if (val) {
11470 /* TODO */
11471 send_resp(dut, conn, SIGMA_ERROR,
11472 "ErrorCode,TD_NF not yet supported");
11473 return 0;
11474 }
11475
11476 val = get_param(cmd, "PMFFrameType");
11477 if (val == NULL)
11478 val = get_param(cmd, "FrameName");
11479 if (val == NULL)
11480 val = get_param(cmd, "Type");
11481 if (val == NULL)
11482 return -1;
11483 if (strcasecmp(val, "disassoc") == 0)
11484 frame = DISASSOC;
11485 else if (strcasecmp(val, "deauth") == 0)
11486 frame = DEAUTH;
11487 else if (strcasecmp(val, "saquery") == 0)
11488 frame = SAQUERY;
11489 else if (strcasecmp(val, "auth") == 0)
11490 frame = AUTH;
11491 else if (strcasecmp(val, "assocreq") == 0)
11492 frame = ASSOCREQ;
11493 else if (strcasecmp(val, "reassocreq") == 0)
11494 frame = REASSOCREQ;
11495 else if (strcasecmp(val, "neigreq") == 0) {
11496 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
11497
11498 val = get_param(cmd, "ssid");
11499 if (val == NULL)
11500 return -1;
11501
11502 res = send_neighbor_request(dut, intf, val);
11503 if (res) {
11504 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11505 "Failed to send neighbor report request");
11506 return 0;
11507 }
11508
11509 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053011510 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
11511 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011512 sigma_dut_print(dut, DUT_MSG_DEBUG,
11513 "Got Transition Management Query");
11514
Ashwini Patil5acd7382017-04-13 15:55:04 +053011515 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011516 if (res) {
11517 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11518 "Failed to send Transition Management Query");
11519 return 0;
11520 }
11521
11522 return 1;
11523 } else {
11524 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11525 "PMFFrameType");
11526 return 0;
11527 }
11528
11529 val = get_param(cmd, "PMFProtected");
11530 if (val == NULL)
11531 val = get_param(cmd, "Protected");
11532 if (val == NULL)
11533 return -1;
11534 if (strcasecmp(val, "Correct-key") == 0 ||
11535 strcasecmp(val, "CorrectKey") == 0)
11536 protected = CORRECT_KEY;
11537 else if (strcasecmp(val, "IncorrectKey") == 0)
11538 protected = INCORRECT_KEY;
11539 else if (strcasecmp(val, "Unprotected") == 0)
11540 protected = UNPROTECTED;
11541 else {
11542 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11543 "PMFProtected");
11544 return 0;
11545 }
11546
11547 if (protected != UNPROTECTED &&
11548 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
11549 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
11550 "PMFProtected for auth/assocreq/reassocreq");
11551 return 0;
11552 }
11553
11554 if (if_nametoindex("sigmadut") == 0) {
11555 snprintf(buf, sizeof(buf),
11556 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011557 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011558 if (system(buf) != 0 ||
11559 if_nametoindex("sigmadut") == 0) {
11560 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11561 "monitor interface with '%s'", buf);
11562 return -2;
11563 }
11564 }
11565
11566 if (system("ifconfig sigmadut up") != 0) {
11567 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11568 "monitor interface up");
11569 return -2;
11570 }
11571
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011572 return sta_inject_frame(dut, conn, intf, frame, protected, NULL, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011573}
11574
11575
11576static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
11577 struct sigma_conn *conn,
11578 struct sigma_cmd *cmd,
11579 const char *ifname)
11580{
11581 char buf[200];
11582 const char *val;
11583
11584 val = get_param(cmd, "ClearARP");
11585 if (val && atoi(val) == 1) {
11586 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
11587 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11588 if (system(buf) != 0) {
11589 send_resp(dut, conn, SIGMA_ERROR,
11590 "errorCode,Failed to clear ARP cache");
11591 return 0;
11592 }
11593 }
11594
11595 return 1;
11596}
11597
11598
11599int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
11600 struct sigma_cmd *cmd)
11601{
11602 const char *intf = get_param(cmd, "Interface");
11603 const char *val;
11604
11605 if (intf == NULL)
11606 return -1;
11607
11608 val = get_param(cmd, "program");
11609 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011610 strcasecmp(val, "HS2-R2") == 0 ||
11611 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011612 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
11613
11614 return -1;
11615}
11616
11617
Jouni Malinenf7222712019-06-13 01:50:21 +030011618static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
11619 struct sigma_conn *conn,
11620 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011621{
11622 const char *intf = get_param(cmd, "Interface");
11623 const char *mac = get_param(cmd, "MAC");
11624
11625 if (intf == NULL || mac == NULL)
11626 return -1;
11627
11628 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
11629 "interface %s to %s", intf, mac);
11630
11631 if (dut->set_macaddr) {
11632 char buf[128];
11633 int res;
11634 if (strcasecmp(mac, "default") == 0) {
11635 res = snprintf(buf, sizeof(buf), "%s",
11636 dut->set_macaddr);
11637 dut->tmp_mac_addr = 0;
11638 } else {
11639 res = snprintf(buf, sizeof(buf), "%s %s",
11640 dut->set_macaddr, mac);
11641 dut->tmp_mac_addr = 1;
11642 }
11643 if (res < 0 || res >= (int) sizeof(buf))
11644 return -1;
11645 if (system(buf) != 0) {
11646 send_resp(dut, conn, SIGMA_ERROR,
11647 "errorCode,Failed to set MAC "
11648 "address");
11649 return 0;
11650 }
11651 return 1;
11652 }
11653
11654 if (strcasecmp(mac, "default") == 0)
11655 return 1;
11656
11657 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11658 "command");
11659 return 0;
11660}
11661
11662
11663static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
11664 struct sigma_conn *conn, const char *intf,
11665 int val)
11666{
11667 char buf[200];
11668 int res;
11669
11670 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
11671 intf, val);
11672 if (res < 0 || res >= (int) sizeof(buf))
11673 return -1;
11674 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11675 if (system(buf) != 0) {
11676 send_resp(dut, conn, SIGMA_ERROR,
11677 "errorCode,Failed to configure offchannel mode");
11678 return 0;
11679 }
11680
11681 return 1;
11682}
11683
11684
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011685static int off_chan_val(enum sec_ch_offset off)
11686{
11687 switch (off) {
11688 case SEC_CH_NO:
11689 return 0;
11690 case SEC_CH_40ABOVE:
11691 return 40;
11692 case SEC_CH_40BELOW:
11693 return -40;
11694 }
11695
11696 return 0;
11697}
11698
11699
11700static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
11701 const char *intf, int off_ch_num,
11702 enum sec_ch_offset sec)
11703{
11704 char buf[200];
11705 int res;
11706
11707 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
11708 intf, off_ch_num);
11709 if (res < 0 || res >= (int) sizeof(buf))
11710 return -1;
11711 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11712 if (system(buf) != 0) {
11713 send_resp(dut, conn, SIGMA_ERROR,
11714 "errorCode,Failed to set offchan");
11715 return 0;
11716 }
11717
11718 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
11719 intf, off_chan_val(sec));
11720 if (res < 0 || res >= (int) sizeof(buf))
11721 return -1;
11722 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11723 if (system(buf) != 0) {
11724 send_resp(dut, conn, SIGMA_ERROR,
11725 "errorCode,Failed to set sec chan offset");
11726 return 0;
11727 }
11728
11729 return 1;
11730}
11731
11732
11733static int tdls_set_offchannel_offset(struct sigma_dut *dut,
11734 struct sigma_conn *conn,
11735 const char *intf, int off_ch_num,
11736 enum sec_ch_offset sec)
11737{
11738 char buf[200];
11739 int res;
11740
11741 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
11742 off_ch_num);
11743 if (res < 0 || res >= (int) sizeof(buf))
11744 return -1;
11745 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11746
11747 if (wpa_command(intf, buf) < 0) {
11748 send_resp(dut, conn, SIGMA_ERROR,
11749 "ErrorCode,Failed to set offchan");
11750 return 0;
11751 }
11752 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
11753 off_chan_val(sec));
11754 if (res < 0 || res >= (int) sizeof(buf))
11755 return -1;
11756
11757 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11758
11759 if (wpa_command(intf, buf) < 0) {
11760 send_resp(dut, conn, SIGMA_ERROR,
11761 "ErrorCode,Failed to set sec chan offset");
11762 return 0;
11763 }
11764
11765 return 1;
11766}
11767
11768
11769static int tdls_set_offchannel_mode(struct sigma_dut *dut,
11770 struct sigma_conn *conn,
11771 const char *intf, int val)
11772{
11773 char buf[200];
11774 int res;
11775
11776 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
11777 val);
11778 if (res < 0 || res >= (int) sizeof(buf))
11779 return -1;
11780 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11781
11782 if (wpa_command(intf, buf) < 0) {
11783 send_resp(dut, conn, SIGMA_ERROR,
11784 "ErrorCode,Failed to configure offchannel mode");
11785 return 0;
11786 }
11787
11788 return 1;
11789}
11790
11791
11792static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
11793 struct sigma_conn *conn,
11794 struct sigma_cmd *cmd)
11795{
11796 const char *val;
11797 enum {
11798 CHSM_NOT_SET,
11799 CHSM_ENABLE,
11800 CHSM_DISABLE,
11801 CHSM_REJREQ,
11802 CHSM_UNSOLRESP
11803 } chsm = CHSM_NOT_SET;
11804 int off_ch_num = -1;
11805 enum sec_ch_offset sec_ch = SEC_CH_NO;
11806 int res;
11807
11808 val = get_param(cmd, "Uapsd");
11809 if (val) {
11810 char buf[100];
11811 if (strcasecmp(val, "Enable") == 0)
11812 snprintf(buf, sizeof(buf), "SET ps 99");
11813 else if (strcasecmp(val, "Disable") == 0)
11814 snprintf(buf, sizeof(buf), "SET ps 98");
11815 else {
11816 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11817 "Unsupported uapsd parameter value");
11818 return 0;
11819 }
11820 if (wpa_command(intf, buf)) {
11821 send_resp(dut, conn, SIGMA_ERROR,
11822 "ErrorCode,Failed to change U-APSD "
11823 "powersave mode");
11824 return 0;
11825 }
11826 }
11827
11828 val = get_param(cmd, "TPKTIMER");
11829 if (val && strcasecmp(val, "DISABLE") == 0) {
11830 if (wpa_command(intf, "SET tdls_testing 0x100")) {
11831 send_resp(dut, conn, SIGMA_ERROR,
11832 "ErrorCode,Failed to enable no TPK "
11833 "expiration test mode");
11834 return 0;
11835 }
11836 dut->no_tpk_expiration = 1;
11837 }
11838
11839 val = get_param(cmd, "ChSwitchMode");
11840 if (val) {
11841 if (strcasecmp(val, "Enable") == 0 ||
11842 strcasecmp(val, "Initiate") == 0)
11843 chsm = CHSM_ENABLE;
11844 else if (strcasecmp(val, "Disable") == 0 ||
11845 strcasecmp(val, "passive") == 0)
11846 chsm = CHSM_DISABLE;
11847 else if (strcasecmp(val, "RejReq") == 0)
11848 chsm = CHSM_REJREQ;
11849 else if (strcasecmp(val, "UnSolResp") == 0)
11850 chsm = CHSM_UNSOLRESP;
11851 else {
11852 send_resp(dut, conn, SIGMA_ERROR,
11853 "ErrorCode,Unknown ChSwitchMode value");
11854 return 0;
11855 }
11856 }
11857
11858 val = get_param(cmd, "OffChNum");
11859 if (val) {
11860 off_ch_num = atoi(val);
11861 if (off_ch_num == 0) {
11862 send_resp(dut, conn, SIGMA_ERROR,
11863 "ErrorCode,Invalid OffChNum");
11864 return 0;
11865 }
11866 }
11867
11868 val = get_param(cmd, "SecChOffset");
11869 if (val) {
11870 if (strcmp(val, "20") == 0)
11871 sec_ch = SEC_CH_NO;
11872 else if (strcasecmp(val, "40above") == 0)
11873 sec_ch = SEC_CH_40ABOVE;
11874 else if (strcasecmp(val, "40below") == 0)
11875 sec_ch = SEC_CH_40BELOW;
11876 else {
11877 send_resp(dut, conn, SIGMA_ERROR,
11878 "ErrorCode,Unknown SecChOffset value");
11879 return 0;
11880 }
11881 }
11882
11883 if (chsm == CHSM_NOT_SET) {
11884 /* no offchannel changes requested */
11885 return 1;
11886 }
11887
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011888 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
11889 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011890 send_resp(dut, conn, SIGMA_ERROR,
11891 "ErrorCode,Unknown interface");
11892 return 0;
11893 }
11894
11895 switch (chsm) {
11896 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030011897 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011898 break;
11899 case CHSM_ENABLE:
11900 if (off_ch_num < 0) {
11901 send_resp(dut, conn, SIGMA_ERROR,
11902 "ErrorCode,Missing OffChNum argument");
11903 return 0;
11904 }
11905 if (wifi_chip_type == DRIVER_WCN) {
11906 res = tdls_set_offchannel_offset(dut, conn, intf,
11907 off_ch_num, sec_ch);
11908 } else {
11909 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11910 sec_ch);
11911 }
11912 if (res != 1)
11913 return res;
11914 if (wifi_chip_type == DRIVER_WCN)
11915 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
11916 else
11917 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
11918 break;
11919 case CHSM_DISABLE:
11920 if (wifi_chip_type == DRIVER_WCN)
11921 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
11922 else
11923 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
11924 break;
11925 case CHSM_REJREQ:
11926 if (wifi_chip_type == DRIVER_WCN)
11927 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
11928 else
11929 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
11930 break;
11931 case CHSM_UNSOLRESP:
11932 if (off_ch_num < 0) {
11933 send_resp(dut, conn, SIGMA_ERROR,
11934 "ErrorCode,Missing OffChNum argument");
11935 return 0;
11936 }
11937 if (wifi_chip_type == DRIVER_WCN) {
11938 res = tdls_set_offchannel_offset(dut, conn, intf,
11939 off_ch_num, sec_ch);
11940 } else {
11941 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11942 sec_ch);
11943 }
11944 if (res != 1)
11945 return res;
11946 if (wifi_chip_type == DRIVER_WCN)
11947 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
11948 else
11949 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
11950 break;
11951 }
11952
11953 return res;
11954}
11955
11956
11957static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11958 struct sigma_conn *conn,
11959 struct sigma_cmd *cmd)
11960{
11961 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011962 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011963
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011964 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080011965
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011966 val = get_param(cmd, "nss_mcs_opt");
11967 if (val) {
11968 /* String (nss_operating_mode; mcs_operating_mode) */
11969 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011970 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011971
11972 token = strdup(val);
11973 if (!token)
11974 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011975 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011976 if (!result) {
11977 sigma_dut_print(dut, DUT_MSG_ERROR,
11978 "VHT NSS not specified");
11979 goto failed;
11980 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011981 if (strcasecmp(result, "def") != 0) {
11982 nss = atoi(result);
11983 if (nss == 4)
11984 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011985 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011986 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011987
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011988 }
11989
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011990 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011991 if (!result) {
11992 sigma_dut_print(dut, DUT_MSG_ERROR,
11993 "VHT MCS not specified");
11994 goto failed;
11995 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011996 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011997 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011998 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011999 } else {
12000 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012001 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012002 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012003 }
12004 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012005 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012006 }
12007
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053012008 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012009 return 1;
12010failed:
12011 free(token);
12012 return 0;
12013}
12014
12015
12016static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
12017 struct sigma_conn *conn,
12018 struct sigma_cmd *cmd)
12019{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012020 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012021 case DRIVER_ATHEROS:
12022 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
12023 default:
12024 send_resp(dut, conn, SIGMA_ERROR,
12025 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
12026 return 0;
12027 }
12028}
12029
12030
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012031static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12032 struct sigma_conn *conn,
12033 struct sigma_cmd *cmd)
12034{
12035 const char *val;
12036 char *token = NULL, *result;
12037 char buf[60];
12038
12039 val = get_param(cmd, "nss_mcs_opt");
12040 if (val) {
12041 /* String (nss_operating_mode; mcs_operating_mode) */
12042 int nss, mcs, ratecode;
12043 char *saveptr;
12044
12045 token = strdup(val);
12046 if (!token)
12047 return -2;
12048
12049 result = strtok_r(token, ";", &saveptr);
12050 if (!result) {
12051 sigma_dut_print(dut, DUT_MSG_ERROR,
12052 "HE NSS not specified");
12053 goto failed;
12054 }
12055 nss = 1;
12056 if (strcasecmp(result, "def") != 0)
12057 nss = atoi(result);
12058
12059 result = strtok_r(NULL, ";", &saveptr);
12060 if (!result) {
12061 sigma_dut_print(dut, DUT_MSG_ERROR,
12062 "HE MCS not specified");
12063 goto failed;
12064 }
12065 mcs = 7;
12066 if (strcasecmp(result, "def") != 0)
12067 mcs = atoi(result);
12068
Arif Hussain557bf412018-05-25 17:29:36 -070012069 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012070 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070012071 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012072 } else if (nss > 2) {
12073 sigma_dut_print(dut, DUT_MSG_ERROR,
12074 "HE NSS %d not supported", nss);
12075 goto failed;
12076 }
12077
Arif Hussain557bf412018-05-25 17:29:36 -070012078 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
12079 if (system(buf) != 0) {
12080 sigma_dut_print(dut, DUT_MSG_ERROR,
12081 "nss_mcs_opt: iwpriv %s nss %d failed",
12082 intf, nss);
12083 goto failed;
12084 }
Arif Hussainac6c5112018-05-25 17:34:00 -070012085 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070012086
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012087 /* Add the MCS to the ratecode */
12088 if (mcs >= 0 && mcs <= 11) {
12089 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070012090#ifdef NL80211_SUPPORT
12091 if (dut->device_type == STA_testbed) {
12092 enum he_mcs_config mcs_config;
12093 int ret;
12094
12095 if (mcs <= 7)
12096 mcs_config = HE_80_MCS0_7;
12097 else if (mcs <= 9)
12098 mcs_config = HE_80_MCS0_9;
12099 else
12100 mcs_config = HE_80_MCS0_11;
12101 ret = sta_set_he_mcs(dut, intf, mcs_config);
12102 if (ret) {
12103 sigma_dut_print(dut, DUT_MSG_ERROR,
12104 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
12105 mcs, mcs_config, ret);
12106 goto failed;
12107 }
12108 }
12109#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012110 } else {
12111 sigma_dut_print(dut, DUT_MSG_ERROR,
12112 "HE MCS %d not supported", mcs);
12113 goto failed;
12114 }
12115 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
12116 intf, ratecode);
12117 if (system(buf) != 0) {
12118 sigma_dut_print(dut, DUT_MSG_ERROR,
12119 "iwpriv setting of 11ax rates failed");
12120 goto failed;
12121 }
12122 free(token);
12123 }
12124
12125 val = get_param(cmd, "GI");
12126 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012127 int fix_rate_sgi;
12128
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012129 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012130 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012131 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012132 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012133 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
12134 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012135 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012136 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012137 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
12138 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012139 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012140 } else {
12141 send_resp(dut, conn, SIGMA_ERROR,
12142 "errorCode,GI value not supported");
12143 return 0;
12144 }
12145 if (system(buf) != 0) {
12146 send_resp(dut, conn, SIGMA_ERROR,
12147 "errorCode,Failed to set shortgi");
12148 return 0;
12149 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012150 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
12151 intf, fix_rate_sgi);
12152 if (system(buf) != 0) {
12153 send_resp(dut, conn, SIGMA_ERROR,
12154 "errorCode,Failed to set fix rate shortgi");
12155 return STATUS_SENT;
12156 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012157 }
12158
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012159 val = get_param(cmd, "LTF");
12160 if (val) {
12161#ifdef NL80211_SUPPORT
12162 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012163 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012164 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012165 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012166 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012167 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012168 } else {
12169 send_resp(dut, conn, SIGMA_ERROR,
12170 "errorCode, LTF value not supported");
12171 return 0;
12172 }
12173#else /* NL80211_SUPPORT */
12174 sigma_dut_print(dut, DUT_MSG_ERROR,
12175 "LTF cannot be set without NL80211_SUPPORT defined");
12176 return -2;
12177#endif /* NL80211_SUPPORT */
12178 }
12179
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070012180 val = get_param(cmd, "TxSUPPDU");
12181 if (val) {
12182 int set_val = 1;
12183
12184 if (strcasecmp(val, "Enable") == 0)
12185 set_val = 1;
12186 else if (strcasecmp(val, "Disable") == 0)
12187 set_val = 0;
12188
12189 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
12190 send_resp(dut, conn, SIGMA_ERROR,
12191 "ErrorCode,Failed to set Tx SU PPDU config");
12192 return 0;
12193 }
12194 }
12195
Arif Hussain480d5f42019-03-12 14:40:42 -070012196 val = get_param(cmd, "TWT_Setup");
12197 if (val) {
12198 if (strcasecmp(val, "Request") == 0) {
12199 if (sta_twt_request(dut, conn, cmd)) {
12200 send_resp(dut, conn, SIGMA_ERROR,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070012201 "ErrorCode,TWT setup failed");
Arif Hussain480d5f42019-03-12 14:40:42 -070012202 return STATUS_SENT;
12203 }
12204 } else if (strcasecmp(val, "Teardown") == 0) {
12205 if (sta_twt_teardown(dut, conn, cmd)) {
12206 send_resp(dut, conn, SIGMA_ERROR,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070012207 "ErrorCode,TWT teardown failed");
Arif Hussain480d5f42019-03-12 14:40:42 -070012208 return STATUS_SENT;
12209 }
12210 }
12211 }
12212
Srinivas Girigowda6707f032020-10-26 15:24:46 -070012213 val = get_param(cmd, "TWT_Operation");
12214 if (val) {
12215 if (strcasecmp(val, "Suspend") == 0) {
12216 if (sta_twt_suspend_or_nudge(dut, conn, cmd)) {
12217 send_resp(dut, conn, SIGMA_ERROR,
12218 "ErrorCode,TWT suspend failed");
12219 return STATUS_SENT_ERROR;
12220 }
12221 } else if (strcasecmp(val, "Resume") == 0) {
12222 if (sta_twt_resume(dut, conn, cmd)) {
12223 send_resp(dut, conn, SIGMA_ERROR,
12224 "ErrorCode,TWT resume failed");
12225 return STATUS_SENT_ERROR;
12226 }
12227 }
12228 }
12229
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080012230 val = get_param(cmd, "transmitOMI");
12231 if (val && sta_transmit_omi(dut, conn, cmd)) {
12232 send_resp(dut, conn, SIGMA_ERROR,
12233 "ErrorCode,sta_transmit_omi failed");
12234 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070012235 }
12236
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012237 val = get_param(cmd, "Powersave");
12238 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012239 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012240
12241 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012242 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012243 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012244 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012245 } else {
12246 sigma_dut_print(dut, DUT_MSG_ERROR,
12247 "Unsupported Powersave value '%s'",
12248 val);
12249 return -1;
12250 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012251 if (set_power_save_wcn(dut, intf, ps) < 0)
12252 return 0;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012253 }
12254
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080012255 val = get_param(cmd, "MU_EDCA");
12256 if (val) {
12257 if (strcasecmp(val, "Override") == 0) {
12258 if (sta_set_mu_edca_override(dut, intf, 1)) {
12259 send_resp(dut, conn, SIGMA_ERROR,
12260 "errorCode,MU EDCA override set failed");
12261 return STATUS_SENT;
12262 }
12263 } else if (strcasecmp(val, "Disable") == 0) {
12264 if (sta_set_mu_edca_override(dut, intf, 0)) {
12265 send_resp(dut, conn, SIGMA_ERROR,
12266 "errorCode,MU EDCA override disable failed");
12267 return STATUS_SENT;
12268 }
12269 }
12270 }
12271
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -070012272 val = get_param(cmd, "Ch_Pref");
12273 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12274 return STATUS_SENT;
12275
12276 val = get_param(cmd, "Cellular_Data_Cap");
12277 if (val && mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12278 return STATUS_SENT;
12279
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012280 return 1;
12281
12282failed:
12283 free(token);
12284 return -2;
12285}
12286
12287
12288static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12289 struct sigma_conn *conn,
12290 struct sigma_cmd *cmd)
12291{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012292 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012293 case DRIVER_WCN:
12294 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
12295 default:
12296 send_resp(dut, conn, SIGMA_ERROR,
12297 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
12298 return 0;
12299 }
12300}
12301
12302
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012303static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
12304 struct sigma_conn *conn,
12305 struct sigma_cmd *cmd)
12306{
12307 const char *val;
12308
12309 val = get_param(cmd, "powersave");
12310 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012311 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012312
12313 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012314 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012315 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012316 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012317 } else {
12318 sigma_dut_print(dut, DUT_MSG_ERROR,
12319 "Unsupported power save config");
12320 return -1;
12321 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012322 if (set_power_save_wcn(dut, intf, ps) < 0)
12323 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012324 return 1;
12325 }
12326
12327 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
12328
12329 return 0;
12330}
12331
12332
Ashwini Patil5acd7382017-04-13 15:55:04 +053012333static int btm_query_candidate_list(struct sigma_dut *dut,
12334 struct sigma_conn *conn,
12335 struct sigma_cmd *cmd)
12336{
12337 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
12338 int len, ret;
12339 char buf[10];
12340
12341 /*
12342 * Neighbor Report elements format:
12343 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
12344 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
12345 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
12346 */
12347
12348 bssid = get_param(cmd, "Nebor_BSSID");
12349 if (!bssid) {
12350 send_resp(dut, conn, SIGMA_INVALID,
12351 "errorCode,Nebor_BSSID is missing");
12352 return 0;
12353 }
12354
12355 info = get_param(cmd, "Nebor_Bssid_Info");
12356 if (!info) {
12357 sigma_dut_print(dut, DUT_MSG_INFO,
12358 "Using default value for Nebor_Bssid_Info: %s",
12359 DEFAULT_NEIGHBOR_BSSID_INFO);
12360 info = DEFAULT_NEIGHBOR_BSSID_INFO;
12361 }
12362
12363 op_class = get_param(cmd, "Nebor_Op_Class");
12364 if (!op_class) {
12365 send_resp(dut, conn, SIGMA_INVALID,
12366 "errorCode,Nebor_Op_Class is missing");
12367 return 0;
12368 }
12369
12370 ch = get_param(cmd, "Nebor_Op_Ch");
12371 if (!ch) {
12372 send_resp(dut, conn, SIGMA_INVALID,
12373 "errorCode,Nebor_Op_Ch is missing");
12374 return 0;
12375 }
12376
12377 phy_type = get_param(cmd, "Nebor_Phy_Type");
12378 if (!phy_type) {
12379 sigma_dut_print(dut, DUT_MSG_INFO,
12380 "Using default value for Nebor_Phy_Type: %s",
12381 DEFAULT_NEIGHBOR_PHY_TYPE);
12382 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
12383 }
12384
12385 /* Parse optional subelements */
12386 buf[0] = '\0';
12387 pref = get_param(cmd, "Nebor_Pref");
12388 if (pref) {
12389 /* hexdump for preferrence subelement */
12390 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
12391 if (ret < 0 || ret >= (int) sizeof(buf)) {
12392 sigma_dut_print(dut, DUT_MSG_ERROR,
12393 "snprintf failed for optional subelement ret: %d",
12394 ret);
12395 send_resp(dut, conn, SIGMA_ERROR,
12396 "errorCode,snprintf failed for subelement");
12397 return 0;
12398 }
12399 }
12400
12401 if (!dut->btm_query_cand_list) {
12402 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
12403 if (!dut->btm_query_cand_list) {
12404 send_resp(dut, conn, SIGMA_ERROR,
12405 "errorCode,Failed to allocate memory for btm_query_cand_list");
12406 return 0;
12407 }
12408 }
12409
12410 len = strlen(dut->btm_query_cand_list);
12411 ret = snprintf(dut->btm_query_cand_list + len,
12412 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
12413 bssid, info, op_class, ch, phy_type, buf);
12414 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
12415 sigma_dut_print(dut, DUT_MSG_ERROR,
12416 "snprintf failed for neighbor report list ret: %d",
12417 ret);
12418 send_resp(dut, conn, SIGMA_ERROR,
12419 "errorCode,snprintf failed for neighbor report");
12420 free(dut->btm_query_cand_list);
12421 dut->btm_query_cand_list = NULL;
12422 return 0;
12423 }
12424
12425 return 1;
12426}
12427
12428
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012429int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
12430 struct sigma_ese_alloc *allocs, int *allocs_size)
12431{
12432 int max_count = *allocs_size;
12433 int count = 0, i;
12434 const char *val;
12435
12436 do {
12437 val = get_param_indexed(cmd, "AllocID", count);
12438 if (val)
12439 count++;
12440 } while (val);
12441
12442 if (count == 0 || count > max_count) {
12443 sigma_dut_print(dut, DUT_MSG_ERROR,
12444 "Invalid number of allocations(%d)", count);
12445 return -1;
12446 }
12447
12448 for (i = 0; i < count; i++) {
12449 val = get_param_indexed(cmd, "PercentBI", i);
12450 if (!val) {
12451 sigma_dut_print(dut, DUT_MSG_ERROR,
12452 "Missing PercentBI parameter at index %d",
12453 i);
12454 return -1;
12455 }
12456 allocs[i].percent_bi = atoi(val);
12457
12458 val = get_param_indexed(cmd, "SrcAID", i);
12459 if (val)
12460 allocs[i].src_aid = strtol(val, NULL, 0);
12461 else
12462 allocs[i].src_aid = ESE_BCAST_AID;
12463
12464 val = get_param_indexed(cmd, "DestAID", i);
12465 if (val)
12466 allocs[i].dst_aid = strtol(val, NULL, 0);
12467 else
12468 allocs[i].dst_aid = ESE_BCAST_AID;
12469
12470 allocs[i].type = ESE_CBAP;
12471 sigma_dut_print(dut, DUT_MSG_INFO,
12472 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
12473 i, allocs[i].percent_bi, allocs[i].src_aid,
12474 allocs[i].dst_aid);
12475 }
12476
12477 *allocs_size = count;
12478 return 0;
12479}
12480
12481
12482static int sta_set_60g_ese(struct sigma_dut *dut, int count,
12483 struct sigma_ese_alloc *allocs)
12484{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012485 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012486#ifdef __linux__
12487 case DRIVER_WIL6210:
12488 if (wil6210_set_ese(dut, count, allocs))
12489 return -1;
12490 return 1;
12491#endif /* __linux__ */
12492 default:
12493 sigma_dut_print(dut, DUT_MSG_ERROR,
12494 "Unsupported sta_set_60g_ese with the current driver");
12495 return -1;
12496 }
12497}
12498
12499
12500static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
12501 struct sigma_conn *conn,
12502 struct sigma_cmd *cmd)
12503{
12504 const char *val;
12505
12506 val = get_param(cmd, "ExtSchIE");
12507 if (val && !strcasecmp(val, "Enable")) {
12508 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
12509 int count = MAX_ESE_ALLOCS;
12510
12511 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
12512 return -1;
12513 return sta_set_60g_ese(dut, count, allocs);
12514 }
12515
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012516 val = get_param(cmd, "MCS_FixedRate");
12517 if (val) {
12518 int sta_mcs = atoi(val);
12519
12520 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
12521 sta_mcs);
12522 wil6210_set_force_mcs(dut, 1, sta_mcs);
12523
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012524 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012525 }
12526
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012527 send_resp(dut, conn, SIGMA_ERROR,
12528 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012529 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012530}
12531
12532
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012533static int wcn_sta_override_oci(struct sigma_dut *dut, const char *intf,
12534 const char *oci_frametype, uint32_t oci_freq)
12535{
12536#ifdef NL80211_SUPPORT
12537 struct nl_msg *msg;
12538 int ret = 0;
12539 struct nlattr *params;
12540 struct nlattr *attr;
12541 int ifindex;
12542 u8 frame_type;
12543
12544 ifindex = if_nametoindex(intf);
12545 if (ifindex == 0) {
12546 sigma_dut_print(dut, DUT_MSG_ERROR,
12547 "%s: Index for interface %s failed",
12548 __func__, intf);
12549 return -1;
12550 }
12551
12552 if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12553 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_REQ;
12554 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12555 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_RESP;
12556 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
12557 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_FT_REASSOC_REQ;
12558 } else {
12559 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: Unknown frametype %s",
12560 __func__, oci_frametype);
12561 return -1;
12562 }
12563
12564
12565 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
12566 NL80211_CMD_VENDOR)) ||
12567 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
12568 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
12569 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
12570 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
12571 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
12572 !(params = nla_nest_start(
12573 msg,
12574 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OCI_OVERRIDE)) ||
12575 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FRAME_TYPE,
12576 frame_type) ||
12577 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FREQUENCY,
12578 oci_freq)) {
12579 sigma_dut_print(dut, DUT_MSG_ERROR,
12580 "%s: err in adding vendor_cmd and vendor_data",
12581 __func__);
12582 nlmsg_free(msg);
12583 return -1;
12584 }
12585 nla_nest_end(msg, params);
12586 nla_nest_end(msg, attr);
12587
12588 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
12589 if (ret) {
12590 sigma_dut_print(dut, DUT_MSG_ERROR,
12591 "%s: err in send_and_recv_msgs, ret=%d",
12592 __func__, ret);
12593 }
12594 return ret;
12595#else /* NL80211_SUPPORT */
12596 sigma_dut_print(dut, DUT_MSG_ERROR,
12597 "OCI override not possible without NL80211_SUPPORT defined");
12598 return -1;
12599#endif /* NL80211_SUPPORT */
12600}
12601
12602
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053012603static int wcn_sta_ignore_csa(struct sigma_dut *dut, const char *intf,
12604 uint8_t ignore_csa)
12605{
12606#ifdef NL80211_SUPPORT
12607 return wcn_wifi_test_config_set_u8(
12608 dut, intf,
12609 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_CSA, ignore_csa);
12610#else /* NL80211_SUPPORT */
12611 sigma_dut_print(dut, DUT_MSG_ERROR,
12612 "IgnoreCSA can't be set without NL80211_SUPPORT defined");
12613 return -1;
12614#endif /* NL80211_SUPPORT */
12615}
12616
12617
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053012618static int wcn_sta_set_rsnxe_used(struct sigma_dut *dut, const char *intf,
12619 uint8_t rsnxe_used)
12620{
12621#ifdef NL80211_SUPPORT
12622 return wcn_wifi_test_config_set_u8(
12623 dut, intf,
12624 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FT_REASSOCREQ_RSNXE_USED,
12625 rsnxe_used);
12626#else /* NL80211_SUPPORT */
12627 sigma_dut_print(dut, DUT_MSG_ERROR,
12628 "RSNXE_Used can't be set without NL80211_SUPPORT defined");
12629 return -1;
12630#endif /* NL80211_SUPPORT */
12631}
12632
12633
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053012634static int wcn_sta_ignore_sa_query_timeout(struct sigma_dut *dut,
12635 const char *intf,
12636 uint8_t ignore_sa_query_timeout)
12637{
12638#ifdef NL80211_SUPPORT
12639 return wcn_wifi_test_config_set_u8(
12640 dut, intf,
12641 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_SA_QUERY_TIMEOUT,
12642 ignore_sa_query_timeout);
12643#else /* NL80211_SUPPORT */
12644 sigma_dut_print(dut, DUT_MSG_ERROR,
12645 "Ignore SA Query timeout can't be set without NL80211_SUPPORT defined");
12646 return -1;
12647#endif /* NL80211_SUPPORT */
12648}
12649
12650
Jouni Malinen6250cb02020-04-15 13:54:45 +030012651static enum sigma_cmd_result
12652cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
12653 struct sigma_conn *conn,
12654 struct sigma_cmd *cmd)
12655{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012656 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030012657
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053012658 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030012659 if (val && atoi(val) == 1) {
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053012660 if (wifi_chip_type == DRIVER_WCN) {
12661 if (wcn_sta_set_rsnxe_used(dut, intf, 1)) {
12662 send_resp(dut, conn, SIGMA_ERROR,
12663 "errorCode,Failed to set ft_rsnxe_used");
12664 return STATUS_SENT_ERROR;
12665 }
12666 return SUCCESS_SEND_STATUS;
12667 } else if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
Jouni Malinen6250cb02020-04-15 13:54:45 +030012668 send_resp(dut, conn, SIGMA_ERROR,
12669 "errorCode,Failed to set ft_rsnxe_used");
12670 return STATUS_SENT_ERROR;
12671 }
12672 return SUCCESS_SEND_STATUS;
12673 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012674
12675 oci_chan = get_param(cmd, "OCIChannel");
12676 oci_frametype = get_param(cmd, "OCIFrameType");
12677 if (oci_chan && oci_frametype) {
12678 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
12679 char buf[100];
12680
12681 if (!oci_freq) {
12682 send_resp(dut, conn, SIGMA_ERROR,
12683 "errorCode,Invalid OCIChannel number");
12684 return STATUS_SENT_ERROR;
12685 }
12686
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012687 if (wifi_chip_type == DRIVER_WCN &&
12688 (strcasecmp(oci_frametype, "SAQueryReq") == 0 ||
12689 strcasecmp(oci_frametype, "SAQueryResp") == 0 ||
12690 strcasecmp(oci_frametype, "Reassocreq") == 0)) {
12691 if (wcn_sta_override_oci(dut, intf, oci_frametype,
12692 oci_freq)) {
12693 send_resp(dut, conn, SIGMA_ERROR,
12694 "errorCode,Failed to override OCI");
12695 return STATUS_SENT_ERROR;
12696 }
12697 return SUCCESS_SEND_STATUS;
12698 }
12699
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012700 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
12701 snprintf(buf, sizeof(buf),
12702 "SET oci_freq_override_eapol %d", oci_freq);
12703 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12704 snprintf(buf, sizeof(buf),
12705 "SET oci_freq_override_saquery_req %d",
12706 oci_freq);
12707 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12708 snprintf(buf, sizeof(buf),
12709 "SET oci_freq_override_saquery_resp %d",
12710 oci_freq);
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012711 } else if (strcasecmp(oci_frametype, "GrpKeyM2") == 0) {
12712 snprintf(buf, sizeof(buf),
12713 "SET oci_freq_override_eapol_g2 %d",
12714 oci_freq);
12715 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
12716 snprintf(buf, sizeof(buf),
12717 "SET oci_freq_override_ft_assoc %d",
12718 oci_freq);
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012719 } else {
12720 send_resp(dut, conn, SIGMA_ERROR,
12721 "errorCode,Unsupported OCIFrameType");
12722 return STATUS_SENT_ERROR;
12723 }
12724 if (wpa_command(intf, buf) < 0) {
12725 send_resp(dut, conn, SIGMA_ERROR,
12726 "errorCode,Failed to set oci_freq_override");
12727 return STATUS_SENT_ERROR;
12728 }
12729 return SUCCESS_SEND_STATUS;
12730 }
12731
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053012732 val = get_param(cmd, "IgnoreCSA");
12733 if (val && atoi(val) == 1) {
12734 if (wifi_chip_type == DRIVER_WCN) {
12735 if (wcn_sta_ignore_csa(dut, intf, 1)) {
12736 send_resp(dut, conn, SIGMA_ERROR,
12737 "errorCode,Failed to set ignore CSA");
12738 return STATUS_SENT_ERROR;
12739 }
12740 return SUCCESS_SEND_STATUS;
12741 }
12742 }
12743
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053012744 val = get_param(cmd, "Deauth_Per_SAQueryResp");
12745 if (val && atoi(val) == 0) {
12746 if (wifi_chip_type == DRIVER_WCN) {
12747 if (wcn_sta_ignore_sa_query_timeout(dut, intf, 1)) {
12748 send_resp(dut, conn, SIGMA_ERROR,
12749 "errorCode,Failed to set ignore SA Query timeout");
12750 return STATUS_SENT_ERROR;
12751 }
12752 return SUCCESS_SEND_STATUS;
12753 }
12754 }
12755
Jouni Malinen6250cb02020-04-15 13:54:45 +030012756 send_resp(dut, conn, SIGMA_ERROR,
12757 "errorCode,Unsupported WPA3 rfeature");
12758 return STATUS_SENT_ERROR;
12759}
12760
12761
Jouni Malinenf7222712019-06-13 01:50:21 +030012762static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
12763 struct sigma_conn *conn,
12764 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012765{
12766 const char *intf = get_param(cmd, "Interface");
12767 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012768 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012769
12770 if (intf == NULL || prog == NULL)
12771 return -1;
12772
Ashwini Patil5acd7382017-04-13 15:55:04 +053012773 /* BSS Transition candidate list for BTM query */
12774 val = get_param(cmd, "Nebor_BSSID");
12775 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
12776 return 0;
12777
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012778 if (strcasecmp(prog, "TDLS") == 0)
12779 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
12780
12781 if (strcasecmp(prog, "VHT") == 0)
12782 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
12783
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012784 if (strcasecmp(prog, "HE") == 0)
12785 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
12786
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012787 if (strcasecmp(prog, "MBO") == 0) {
12788 val = get_param(cmd, "Cellular_Data_Cap");
12789 if (val &&
12790 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12791 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053012792
12793 val = get_param(cmd, "Ch_Pref");
12794 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12795 return 0;
12796
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012797 return 1;
12798 }
12799
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012800 if (strcasecmp(prog, "60GHz") == 0)
12801 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
12802
Jouni Malinen6250cb02020-04-15 13:54:45 +030012803 if (strcasecmp(prog, "WPA3") == 0)
12804 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
12805
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012806 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
12807 return 0;
12808}
12809
12810
Jouni Malinenf7222712019-06-13 01:50:21 +030012811static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
12812 struct sigma_conn *conn,
12813 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012814{
12815 const char *intf = get_param(cmd, "Interface");
12816 const char *mode = get_param(cmd, "Mode");
12817 int res;
12818
12819 if (intf == NULL || mode == NULL)
12820 return -1;
12821
12822 if (strcasecmp(mode, "On") == 0)
12823 res = wpa_command(intf, "SET radio_disabled 0");
12824 else if (strcasecmp(mode, "Off") == 0)
12825 res = wpa_command(intf, "SET radio_disabled 1");
12826 else
12827 return -1;
12828
12829 if (res) {
12830 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12831 "radio mode");
12832 return 0;
12833 }
12834
12835 return 1;
12836}
12837
12838
Jouni Malinenf7222712019-06-13 01:50:21 +030012839static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
12840 struct sigma_conn *conn,
12841 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012842{
12843 const char *intf = get_param(cmd, "Interface");
12844 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012845 const char *prog = get_param(cmd, "program");
12846 const char *powersave = get_param(cmd, "powersave");
12847 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012848
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012849 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012850 return -1;
12851
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012852 if (prog && strcasecmp(prog, "60GHz") == 0) {
12853 /*
12854 * The CAPI mode parameter does not exist in 60G
12855 * unscheduled PS.
12856 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080012857 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012858 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012859 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020012860 strcasecmp(prog, "HE") == 0) {
12861 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012862 } else {
12863 if (mode == NULL)
12864 return -1;
12865
12866 if (strcasecmp(mode, "On") == 0)
12867 res = set_ps(intf, dut, 1);
12868 else if (strcasecmp(mode, "Off") == 0)
12869 res = set_ps(intf, dut, 0);
12870 else
12871 return -1;
12872 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012873
12874 if (res) {
12875 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12876 "power save mode");
12877 return 0;
12878 }
12879
12880 return 1;
12881}
12882
12883
Jouni Malinenf7222712019-06-13 01:50:21 +030012884static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
12885 struct sigma_conn *conn,
12886 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012887{
12888 const char *intf = get_param(cmd, "Interface");
12889 const char *val, *bssid;
12890 int res;
12891 char *buf;
12892 size_t buf_len;
12893
12894 val = get_param(cmd, "BSSID_FILTER");
12895 if (val == NULL)
12896 return -1;
12897
12898 bssid = get_param(cmd, "BSSID_List");
12899 if (atoi(val) == 0 || bssid == NULL) {
12900 /* Disable BSSID filter */
12901 if (wpa_command(intf, "SET bssid_filter ")) {
12902 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
12903 "to disable BSSID filter");
12904 return 0;
12905 }
12906
12907 return 1;
12908 }
12909
12910 buf_len = 100 + strlen(bssid);
12911 buf = malloc(buf_len);
12912 if (buf == NULL)
12913 return -1;
12914
12915 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
12916 res = wpa_command(intf, buf);
12917 free(buf);
12918 if (res) {
12919 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
12920 "BSSID filter");
12921 return 0;
12922 }
12923
12924 return 1;
12925}
12926
12927
Jouni Malinenf7222712019-06-13 01:50:21 +030012928static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
12929 struct sigma_conn *conn,
12930 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012931{
12932 const char *intf = get_param(cmd, "Interface");
12933 const char *val;
12934
12935 /* TODO: ARP */
12936
12937 val = get_param(cmd, "HS2_CACHE_PROFILE");
12938 if (val && strcasecmp(val, "All") == 0)
12939 hs2_clear_credentials(intf);
12940
12941 return 1;
12942}
12943
12944
Jouni Malinenf7222712019-06-13 01:50:21 +030012945static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
12946 struct sigma_conn *conn,
12947 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012948{
12949 const char *intf = get_param(cmd, "Interface");
12950 const char *key_type = get_param(cmd, "KeyType");
12951 char buf[100], resp[200];
12952
12953 if (key_type == NULL)
12954 return -1;
12955
12956 if (strcasecmp(key_type, "GTK") == 0) {
12957 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
12958 strncmp(buf, "FAIL", 4) == 0) {
12959 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12960 "not fetch current GTK");
12961 return 0;
12962 }
12963 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
12964 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12965 return 0;
12966 } else {
12967 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12968 "KeyType");
12969 return 0;
12970 }
12971
12972 return 1;
12973}
12974
12975
12976static int hs2_set_policy(struct sigma_dut *dut)
12977{
12978#ifdef ANDROID
12979 system("ip rule del prio 23000");
12980 if (system("ip rule add from all lookup main prio 23000") != 0) {
12981 sigma_dut_print(dut, DUT_MSG_ERROR,
12982 "Failed to run:ip rule add from all lookup main prio");
12983 return -1;
12984 }
12985 if (system("ip route flush cache") != 0) {
12986 sigma_dut_print(dut, DUT_MSG_ERROR,
12987 "Failed to run ip route flush cache");
12988 return -1;
12989 }
12990 return 1;
12991#else /* ANDROID */
12992 return 0;
12993#endif /* ANDROID */
12994}
12995
12996
Jouni Malinenf7222712019-06-13 01:50:21 +030012997static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
12998 struct sigma_conn *conn,
12999 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013000{
13001 const char *intf = get_param(cmd, "Interface");
13002 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030013003 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013004 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030013005 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013006 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
13007 int tries = 0;
13008 int ignore_blacklist = 0;
13009 const char *events[] = {
13010 "CTRL-EVENT-CONNECTED",
13011 "INTERWORKING-BLACKLISTED",
13012 "INTERWORKING-NO-MATCH",
13013 NULL
13014 };
13015
13016 start_sta_mode(dut);
13017
Jouni Malinen439352d2018-09-13 03:42:23 +030013018 if (band) {
13019 if (strcmp(band, "2.4") == 0) {
13020 wpa_command(intf, "SET setband 2G");
13021 } else if (strcmp(band, "5") == 0) {
13022 wpa_command(intf, "SET setband 5G");
13023 } else {
13024 send_resp(dut, conn, SIGMA_ERROR,
13025 "errorCode,Unsupported band");
13026 return 0;
13027 }
13028 }
13029
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013030 blacklisted[0] = '\0';
13031 if (val && atoi(val))
13032 ignore_blacklist = 1;
13033
13034try_again:
13035 ctrl = open_wpa_mon(intf);
13036 if (ctrl == NULL) {
13037 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13038 "wpa_supplicant monitor connection");
13039 return -2;
13040 }
13041
13042 tries++;
13043 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
13044 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
13045 "Interworking connection");
13046 wpa_ctrl_detach(ctrl);
13047 wpa_ctrl_close(ctrl);
13048 return 0;
13049 }
13050
13051 buf[0] = '\0';
13052 while (1) {
13053 char *pos;
13054 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13055 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
13056 if (!pos)
13057 break;
13058 pos += 25;
13059 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
13060 pos);
13061 if (!blacklisted[0])
13062 memcpy(blacklisted, pos, strlen(pos) + 1);
13063 }
13064
13065 if (ignore_blacklist && blacklisted[0]) {
13066 char *end;
13067 end = strchr(blacklisted, ' ');
13068 if (end)
13069 *end = '\0';
13070 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
13071 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030013072 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
13073 blacklisted);
13074 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013075 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
13076 wpa_ctrl_detach(ctrl);
13077 wpa_ctrl_close(ctrl);
13078 return 0;
13079 }
13080 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13081 buf, sizeof(buf));
13082 }
13083
13084 wpa_ctrl_detach(ctrl);
13085 wpa_ctrl_close(ctrl);
13086
13087 if (res < 0) {
13088 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
13089 "connect");
13090 return 0;
13091 }
13092
13093 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
13094 strstr(buf, "INTERWORKING-BLACKLISTED")) {
13095 if (tries < 2) {
13096 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
13097 goto try_again;
13098 }
13099 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
13100 "matching credentials found");
13101 return 0;
13102 }
13103
13104 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13105 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13106 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
13107 "get current BSSID/SSID");
13108 return 0;
13109 }
13110
13111 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
13112 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13113 hs2_set_policy(dut);
13114 return 0;
13115}
13116
13117
Jouni Malinenf7222712019-06-13 01:50:21 +030013118static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
13119 struct sigma_conn *conn,
13120 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013121{
13122 const char *intf = get_param(cmd, "Interface");
13123 const char *display = get_param(cmd, "Display");
13124 struct wpa_ctrl *ctrl;
13125 char buf[300], params[400], *pos;
13126 char bssid[20];
13127 int info_avail = 0;
13128 unsigned int old_timeout;
13129 int res;
13130
13131 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
13132 send_resp(dut, conn, SIGMA_ERROR,
13133 "ErrorCode,Could not get current BSSID");
13134 return 0;
13135 }
13136 ctrl = open_wpa_mon(intf);
13137 if (!ctrl) {
13138 sigma_dut_print(dut, DUT_MSG_ERROR,
13139 "Failed to open wpa_supplicant monitor connection");
13140 return -2;
13141 }
13142
13143 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
13144 wpa_command(intf, buf);
13145
13146 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
13147 if (res < 0) {
13148 send_resp(dut, conn, SIGMA_ERROR,
13149 "ErrorCode,Could not complete GAS query");
13150 goto fail;
13151 }
13152
13153 old_timeout = dut->default_timeout;
13154 dut->default_timeout = 2;
13155 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
13156 dut->default_timeout = old_timeout;
13157 if (res < 0)
13158 goto done;
13159 pos = strchr(buf, ' ');
13160 if (!pos)
13161 goto done;
13162 pos++;
13163 pos = strchr(pos, ' ');
13164 if (!pos)
13165 goto done;
13166 pos++;
13167 info_avail = 1;
13168 snprintf(params, sizeof(params), "browser %s", pos);
13169
13170 if (display && strcasecmp(display, "Yes") == 0) {
13171 pid_t pid;
13172
13173 pid = fork();
13174 if (pid < 0) {
13175 perror("fork");
13176 return -1;
13177 }
13178
13179 if (pid == 0) {
13180 run_hs20_osu(dut, params);
13181 exit(0);
13182 }
13183 }
13184
13185done:
13186 snprintf(buf, sizeof(buf), "Info_available,%s",
13187 info_avail ? "Yes" : "No");
13188 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13189fail:
13190 wpa_ctrl_detach(ctrl);
13191 wpa_ctrl_close(ctrl);
13192 return 0;
13193}
13194
13195
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013196static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
13197 struct sigma_conn *conn,
13198 const char *ifname,
13199 struct sigma_cmd *cmd)
13200{
13201 const char *val;
13202 int id;
13203
13204 id = add_cred(ifname);
13205 if (id < 0)
13206 return -2;
13207 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13208
13209 val = get_param(cmd, "prefer");
13210 if (val && atoi(val) > 0)
13211 set_cred(ifname, id, "priority", "1");
13212
13213 val = get_param(cmd, "REALM");
13214 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13215 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13216 "realm");
13217 return 0;
13218 }
13219
13220 val = get_param(cmd, "HOME_FQDN");
13221 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13222 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13223 "home_fqdn");
13224 return 0;
13225 }
13226
13227 val = get_param(cmd, "Username");
13228 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13229 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13230 "username");
13231 return 0;
13232 }
13233
13234 val = get_param(cmd, "Password");
13235 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
13236 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13237 "password");
13238 return 0;
13239 }
13240
13241 val = get_param(cmd, "ROOT_CA");
13242 if (val) {
13243 char fname[200];
13244 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13245#ifdef __linux__
13246 if (!file_exists(fname)) {
13247 char msg[300];
13248 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13249 "file (%s) not found", fname);
13250 send_resp(dut, conn, SIGMA_ERROR, msg);
13251 return 0;
13252 }
13253#endif /* __linux__ */
13254 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13255 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13256 "not set root CA");
13257 return 0;
13258 }
13259 }
13260
13261 return 1;
13262}
13263
13264
13265static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
13266{
13267 FILE *in, *out;
13268 char buf[500];
13269 int found = 0;
13270
13271 in = fopen("devdetail.xml", "r");
13272 if (in == NULL)
13273 return -1;
13274 out = fopen("devdetail.xml.tmp", "w");
13275 if (out == NULL) {
13276 fclose(in);
13277 return -1;
13278 }
13279
13280 while (fgets(buf, sizeof(buf), in)) {
13281 char *pos = strstr(buf, "<IMSI>");
13282 if (pos) {
13283 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
13284 imsi);
13285 pos += 6;
13286 *pos = '\0';
13287 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
13288 found++;
13289 } else {
13290 fprintf(out, "%s", buf);
13291 }
13292 }
13293
13294 fclose(out);
13295 fclose(in);
13296 if (found)
13297 rename("devdetail.xml.tmp", "devdetail.xml");
13298 else
13299 unlink("devdetail.xml.tmp");
13300
13301 return 0;
13302}
13303
13304
13305static int sta_add_credential_sim(struct sigma_dut *dut,
13306 struct sigma_conn *conn,
13307 const char *ifname, struct sigma_cmd *cmd)
13308{
13309 const char *val, *imsi = NULL;
13310 int id;
13311 char buf[200];
13312 int res;
13313 const char *pos;
13314 size_t mnc_len;
13315 char plmn_mcc[4];
13316 char plmn_mnc[4];
13317
13318 id = add_cred(ifname);
13319 if (id < 0)
13320 return -2;
13321 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13322
13323 val = get_param(cmd, "prefer");
13324 if (val && atoi(val) > 0)
13325 set_cred(ifname, id, "priority", "1");
13326
13327 val = get_param(cmd, "PLMN_MCC");
13328 if (val == NULL) {
13329 send_resp(dut, conn, SIGMA_ERROR,
13330 "errorCode,Missing PLMN_MCC");
13331 return 0;
13332 }
13333 if (strlen(val) != 3) {
13334 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
13335 return 0;
13336 }
13337 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
13338
13339 val = get_param(cmd, "PLMN_MNC");
13340 if (val == NULL) {
13341 send_resp(dut, conn, SIGMA_ERROR,
13342 "errorCode,Missing PLMN_MNC");
13343 return 0;
13344 }
13345 if (strlen(val) != 2 && strlen(val) != 3) {
13346 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
13347 return 0;
13348 }
13349 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
13350
13351 val = get_param(cmd, "IMSI");
13352 if (val == NULL) {
13353 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
13354 "IMSI");
13355 return 0;
13356 }
13357
13358 imsi = pos = val;
13359
13360 if (strncmp(plmn_mcc, pos, 3) != 0) {
13361 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
13362 return 0;
13363 }
13364 pos += 3;
13365
13366 mnc_len = strlen(plmn_mnc);
13367 if (mnc_len < 2) {
13368 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
13369 return 0;
13370 }
13371
13372 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
13373 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
13374 return 0;
13375 }
13376 pos += mnc_len;
13377
13378 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
13379 if (res < 0 || res >= (int) sizeof(buf))
13380 return -1;
13381 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
13382 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13383 "not set IMSI");
13384 return 0;
13385 }
13386
13387 val = get_param(cmd, "Password");
13388 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
13389 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13390 "not set password");
13391 return 0;
13392 }
13393
Jouni Malinenba630452018-06-22 11:49:59 +030013394 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013395 /*
13396 * Set provisioning_sp for the test cases where SIM/USIM
13397 * provisioning is used.
13398 */
13399 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
13400 "wi-fi.org") < 0) {
13401 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13402 "not set provisioning_sp");
13403 return 0;
13404 }
13405
13406 update_devdetail_imsi(dut, imsi);
13407 }
13408
13409 return 1;
13410}
13411
13412
13413static int sta_add_credential_cert(struct sigma_dut *dut,
13414 struct sigma_conn *conn,
13415 const char *ifname,
13416 struct sigma_cmd *cmd)
13417{
13418 const char *val;
13419 int id;
13420
13421 id = add_cred(ifname);
13422 if (id < 0)
13423 return -2;
13424 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13425
13426 val = get_param(cmd, "prefer");
13427 if (val && atoi(val) > 0)
13428 set_cred(ifname, id, "priority", "1");
13429
13430 val = get_param(cmd, "REALM");
13431 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13432 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13433 "realm");
13434 return 0;
13435 }
13436
13437 val = get_param(cmd, "HOME_FQDN");
13438 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13439 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13440 "home_fqdn");
13441 return 0;
13442 }
13443
13444 val = get_param(cmd, "Username");
13445 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13446 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13447 "username");
13448 return 0;
13449 }
13450
13451 val = get_param(cmd, "clientCertificate");
13452 if (val) {
13453 char fname[200];
13454 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13455#ifdef __linux__
13456 if (!file_exists(fname)) {
13457 char msg[300];
13458 snprintf(msg, sizeof(msg),
13459 "ErrorCode,clientCertificate "
13460 "file (%s) not found", fname);
13461 send_resp(dut, conn, SIGMA_ERROR, msg);
13462 return 0;
13463 }
13464#endif /* __linux__ */
13465 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
13466 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13467 "not set client_cert");
13468 return 0;
13469 }
13470 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
13471 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13472 "not set private_key");
13473 return 0;
13474 }
13475 }
13476
13477 val = get_param(cmd, "ROOT_CA");
13478 if (val) {
13479 char fname[200];
13480 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13481#ifdef __linux__
13482 if (!file_exists(fname)) {
13483 char msg[300];
13484 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13485 "file (%s) not found", fname);
13486 send_resp(dut, conn, SIGMA_ERROR, msg);
13487 return 0;
13488 }
13489#endif /* __linux__ */
13490 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13491 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13492 "not set root CA");
13493 return 0;
13494 }
13495 }
13496
13497 return 1;
13498}
13499
13500
Jouni Malinenf7222712019-06-13 01:50:21 +030013501static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
13502 struct sigma_conn *conn,
13503 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013504{
13505 const char *intf = get_param(cmd, "Interface");
13506 const char *type;
13507
13508 start_sta_mode(dut);
13509
13510 type = get_param(cmd, "Type");
13511 if (!type)
13512 return -1;
13513
13514 if (strcasecmp(type, "uname_pwd") == 0)
13515 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
13516
13517 if (strcasecmp(type, "sim") == 0)
13518 return sta_add_credential_sim(dut, conn, intf, cmd);
13519
13520 if (strcasecmp(type, "cert") == 0)
13521 return sta_add_credential_cert(dut, conn, intf, cmd);
13522
13523 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
13524 "type");
13525 return 0;
13526}
13527
13528
Jouni Malinenf7222712019-06-13 01:50:21 +030013529static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
13530 struct sigma_conn *conn,
13531 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013532{
13533 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013534 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Veerendranathdc581b52020-08-10 03:29:08 -070013535 char buf[4096], scan_res[20];
vamsi krishna89ad8c62017-09-19 12:51:18 +053013536 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013537 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013538 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013539 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013540 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013541
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020013542 start_sta_mode(dut);
13543
Arif Hussain66a4af02019-02-07 15:04:51 -080013544 val = get_param(cmd, "GetParameter");
13545 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013546 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080013547 buf, sizeof(buf)) < 0) {
13548 sigma_dut_print(dut, DUT_MSG_ERROR,
13549 "Could not get ssid bssid");
13550 return ERROR_SEND_STATUS;
13551 }
13552
13553 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
13554 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13555 return STATUS_SENT;
13556 }
13557
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013558 val = get_param(cmd, "HESSID");
13559 if (val) {
13560 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
13561 if (res < 0 || res >= (int) sizeof(buf))
13562 return -1;
13563 wpa_command(intf, buf);
13564 }
13565
13566 val = get_param(cmd, "ACCS_NET_TYPE");
13567 if (val) {
13568 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
13569 val);
13570 if (res < 0 || res >= (int) sizeof(buf))
13571 return -1;
13572 wpa_command(intf, buf);
13573 }
13574
vamsi krishna89ad8c62017-09-19 12:51:18 +053013575 bssid = get_param(cmd, "Bssid");
13576 ssid = get_param(cmd, "Ssid");
13577
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013578 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
13579 dut->device_type == STA_testbed) {
13580 ssid = NULL;
13581 wildcard_ssid = 1;
13582 }
13583
vamsi krishna89ad8c62017-09-19 12:51:18 +053013584 if (ssid) {
13585 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
13586 send_resp(dut, conn, SIGMA_ERROR,
13587 "ErrorCode,Too long SSID");
13588 return 0;
13589 }
13590 ascii2hexstr(ssid, ssid_hex);
13591 }
13592
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013593 short_ssid = get_param(cmd, "ShortSSID");
13594 if (short_ssid) {
13595 uint32_t short_ssid_hex;
13596
13597 short_ssid_hex = strtoul(short_ssid, NULL, 16);
13598 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
13599 (((short_ssid_hex >> 8) & 0xFF) << 16) |
13600 (((short_ssid_hex >> 16) & 0xFF) << 8) |
13601 ((short_ssid_hex >> 24) & 0xFF);
13602
13603 res = snprintf(buf, sizeof(buf),
13604 "VENDOR_ELEM_ADD 14 ff053a%08x",
13605 short_ssid_hex);
13606 if (res < 0 || res >= (int) sizeof(buf) ||
13607 wpa_command(intf, buf)) {
13608 send_resp(dut, conn, SIGMA_ERROR,
13609 "errorCode,Failed to add short SSID");
13610 return STATUS_SENT_ERROR;
13611 }
13612 }
13613
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013614 scan_freq = get_param(cmd, "ChnlFreq");
Veerendranath Jakkam132c4b42020-08-10 00:29:03 +053013615 if (scan_freq) {
13616 if (strcasecmp(scan_freq, "2G") == 0)
13617 scan_freq = "2412-2462";
13618 else if (strcasecmp(scan_freq, "5G") == 0)
13619 scan_freq = "5180-5925";
13620 }
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013621
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013622 val = get_param(cmd, "WaitCompletion");
13623 if (val && atoi(val) == 1) {
13624 ctrl = open_wpa_mon(intf);
13625 if (!ctrl) {
13626 send_resp(dut, conn, SIGMA_ERROR,
13627 "errorCode,Failed to open monitor socket");
13628 return STATUS_SENT_ERROR;
13629 }
13630 }
13631
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013632 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053013633 bssid ? " bssid=": "",
13634 bssid ? bssid : "",
13635 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013636 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013637 wildcard_ssid ? " wildcard_ssid=1" : "",
13638 scan_freq ? " freq=" : "",
13639 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013640 if (res < 0 || res >= (int) sizeof(buf)) {
13641 send_resp(dut, conn, SIGMA_ERROR,
13642 "errorCode,Could not build scan command");
13643 status = STATUS_SENT_ERROR;
13644 goto remove_s_ssid;
13645 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053013646
Veerendranathdc581b52020-08-10 03:29:08 -070013647 res = wpa_command_resp(intf, buf, scan_res, sizeof(scan_res));
13648 if (strncmp(scan_res, "FAIL-BUSY", 9) == 0) {
13649 sigma_dut_print(dut, DUT_MSG_DEBUG,
13650 "Scan request rejected with busy status, abort ongoing scan and try again");
13651 wpa_command(intf, "ABORT_SCAN");
13652 res = wpa_command(intf, buf);
13653 }
13654
13655 if (res < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013656 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
13657 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013658 status = STATUS_SENT_ERROR;
13659 } else {
13660 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013661 }
13662
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013663remove_s_ssid:
13664 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
13665 sigma_dut_print(dut, DUT_MSG_ERROR,
13666 "Failed to delete vendor element");
13667
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013668 if (ctrl) {
13669 if (status == SUCCESS_SEND_STATUS) {
13670 res = get_wpa_cli_event(dut, ctrl,
13671 "CTRL-EVENT-SCAN-RESULTS",
13672 buf, sizeof(buf));
13673 if (res < 0) {
13674 send_resp(dut, conn, SIGMA_ERROR,
13675 "ErrorCode,scan did not complete");
13676 status = STATUS_SENT_ERROR;
13677 }
13678 }
13679
13680 wpa_ctrl_detach(ctrl);
13681 wpa_ctrl_close(ctrl);
13682 }
13683
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013684 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013685}
13686
13687
Jouni Malinenf7222712019-06-13 01:50:21 +030013688static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
13689 struct sigma_conn *conn,
13690 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013691{
13692 const char *intf = get_param(cmd, "Interface");
13693 const char *bssid;
13694 char buf[4096], *pos;
13695 int freq, chan;
13696 char *ssid;
13697 char resp[100];
13698 int res;
13699 struct wpa_ctrl *ctrl;
13700
13701 bssid = get_param(cmd, "BSSID");
13702 if (!bssid) {
13703 send_resp(dut, conn, SIGMA_INVALID,
13704 "errorCode,BSSID argument is missing");
13705 return 0;
13706 }
13707
13708 ctrl = open_wpa_mon(intf);
13709 if (!ctrl) {
13710 sigma_dut_print(dut, DUT_MSG_ERROR,
13711 "Failed to open wpa_supplicant monitor connection");
13712 return -1;
13713 }
13714
13715 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
13716 send_resp(dut, conn, SIGMA_ERROR,
13717 "errorCode,Could not start scan");
13718 wpa_ctrl_detach(ctrl);
13719 wpa_ctrl_close(ctrl);
13720 return 0;
13721 }
13722
13723 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
13724 buf, sizeof(buf));
13725
13726 wpa_ctrl_detach(ctrl);
13727 wpa_ctrl_close(ctrl);
13728
13729 if (res < 0) {
13730 send_resp(dut, conn, SIGMA_ERROR,
13731 "errorCode,Scan did not complete");
13732 return 0;
13733 }
13734
13735 snprintf(buf, sizeof(buf), "BSS %s", bssid);
13736 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
13737 strncmp(buf, "id=", 3) != 0) {
13738 send_resp(dut, conn, SIGMA_ERROR,
13739 "errorCode,Specified BSSID not found");
13740 return 0;
13741 }
13742
13743 pos = strstr(buf, "\nfreq=");
13744 if (!pos) {
13745 send_resp(dut, conn, SIGMA_ERROR,
13746 "errorCode,Channel not found");
13747 return 0;
13748 }
13749 freq = atoi(pos + 6);
13750 chan = freq_to_channel(freq);
13751
13752 pos = strstr(buf, "\nssid=");
13753 if (!pos) {
13754 send_resp(dut, conn, SIGMA_ERROR,
13755 "errorCode,SSID not found");
13756 return 0;
13757 }
13758 ssid = pos + 6;
13759 pos = strchr(ssid, '\n');
13760 if (pos)
13761 *pos = '\0';
13762 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
13763 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13764 return 0;
13765}
13766
13767
Jouni Malinenf7222712019-06-13 01:50:21 +030013768static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
13769 struct sigma_conn *conn,
13770 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013771{
13772#ifdef __linux__
13773 struct timeval tv;
13774 struct tm tm;
13775 time_t t;
13776 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013777 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013778
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013779 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013780
13781 memset(&tm, 0, sizeof(tm));
13782 val = get_param(cmd, "seconds");
13783 if (val)
13784 tm.tm_sec = atoi(val);
13785 val = get_param(cmd, "minutes");
13786 if (val)
13787 tm.tm_min = atoi(val);
13788 val = get_param(cmd, "hours");
13789 if (val)
13790 tm.tm_hour = atoi(val);
13791 val = get_param(cmd, "date");
13792 if (val)
13793 tm.tm_mday = atoi(val);
13794 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013795 if (val) {
13796 v = atoi(val);
13797 if (v < 1 || v > 12) {
13798 send_resp(dut, conn, SIGMA_INVALID,
13799 "errorCode,Invalid month");
13800 return 0;
13801 }
13802 tm.tm_mon = v - 1;
13803 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013804 val = get_param(cmd, "year");
13805 if (val) {
13806 int year = atoi(val);
13807#ifdef ANDROID
13808 if (year > 2035)
13809 year = 2035; /* years beyond 2035 not supported */
13810#endif /* ANDROID */
13811 tm.tm_year = year - 1900;
13812 }
13813 t = mktime(&tm);
13814 if (t == (time_t) -1) {
13815 send_resp(dut, conn, SIGMA_ERROR,
13816 "errorCode,Invalid date or time");
13817 return 0;
13818 }
13819
13820 memset(&tv, 0, sizeof(tv));
13821 tv.tv_sec = t;
13822
13823 if (settimeofday(&tv, NULL) < 0) {
13824 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
13825 strerror(errno));
13826 send_resp(dut, conn, SIGMA_ERROR,
13827 "errorCode,Failed to set time");
13828 return 0;
13829 }
13830
13831 return 1;
13832#endif /* __linux__ */
13833
13834 return -1;
13835}
13836
13837
Jouni Malinenf7222712019-06-13 01:50:21 +030013838static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
13839 struct sigma_conn *conn,
13840 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013841{
13842 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013843 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013844 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013845 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013846 int res;
13847 struct wpa_ctrl *ctrl;
13848
13849 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013850 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013851
13852 val = get_param(cmd, "ProdESSAssoc");
13853 if (val)
13854 prod_ess_assoc = atoi(val);
13855
13856 kill_dhcp_client(dut, intf);
13857 if (start_dhcp_client(dut, intf) < 0)
13858 return -2;
13859
13860 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
13861 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13862 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013863 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013864 prod_ess_assoc ? "" : "-N",
13865 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013866 name ? "'" : "",
13867 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
13868 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013869
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053013870 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013871 if (run_hs20_osu(dut, buf) < 0) {
13872 FILE *f;
13873
13874 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
13875
13876 f = fopen("hs20-osu-client.res", "r");
13877 if (f) {
13878 char resp[400], res[300], *pos;
13879 if (!fgets(res, sizeof(res), f))
13880 res[0] = '\0';
13881 pos = strchr(res, '\n');
13882 if (pos)
13883 *pos = '\0';
13884 fclose(f);
13885 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
13886 res);
13887 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
13888 if (system(resp) != 0) {
13889 }
13890 snprintf(resp, sizeof(resp),
13891 "SSID,,BSSID,,failureReason,%s", res);
13892 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13893 return 0;
13894 }
13895
13896 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13897 return 0;
13898 }
13899
13900 if (!prod_ess_assoc)
13901 goto report;
13902
13903 ctrl = open_wpa_mon(intf);
13904 if (ctrl == NULL) {
13905 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13906 "wpa_supplicant monitor connection");
13907 return -1;
13908 }
13909
13910 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13911 buf, sizeof(buf));
13912
13913 wpa_ctrl_detach(ctrl);
13914 wpa_ctrl_close(ctrl);
13915
13916 if (res < 0) {
13917 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
13918 "network after OSU");
13919 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13920 return 0;
13921 }
13922
13923report:
13924 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13925 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13926 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
13927 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13928 return 0;
13929 }
13930
13931 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
13932 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013933 return 0;
13934}
13935
13936
Jouni Malinenf7222712019-06-13 01:50:21 +030013937static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
13938 struct sigma_conn *conn,
13939 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013940{
13941 const char *val;
13942 int timeout = 120;
13943
13944 val = get_param(cmd, "PolicyUpdate");
13945 if (val == NULL || atoi(val) == 0)
13946 return 1; /* No operation requested */
13947
13948 val = get_param(cmd, "Timeout");
13949 if (val)
13950 timeout = atoi(val);
13951
13952 if (timeout) {
13953 /* TODO: time out the command and return
13954 * PolicyUpdateStatus,TIMEOUT if needed. */
13955 }
13956
13957 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
13958 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13959 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
13960 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
13961 return 0;
13962 }
13963
13964 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
13965 return 0;
13966}
13967
13968
Jouni Malinenf7222712019-06-13 01:50:21 +030013969static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
13970 struct sigma_conn *conn,
13971 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013972{
13973 struct wpa_ctrl *ctrl;
13974 const char *intf = get_param(cmd, "Interface");
13975 const char *bssid = get_param(cmd, "Bssid");
13976 const char *ssid = get_param(cmd, "SSID");
13977 const char *security = get_param(cmd, "Security");
13978 const char *passphrase = get_param(cmd, "Passphrase");
13979 const char *pin = get_param(cmd, "PIN");
13980 char buf[1000];
13981 char ssid_hex[200], passphrase_hex[200];
13982 const char *keymgmt, *cipher;
13983
13984 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013985 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013986
13987 if (!bssid) {
13988 send_resp(dut, conn, SIGMA_ERROR,
13989 "ErrorCode,Missing Bssid argument");
13990 return 0;
13991 }
13992
13993 if (!ssid) {
13994 send_resp(dut, conn, SIGMA_ERROR,
13995 "ErrorCode,Missing SSID argument");
13996 return 0;
13997 }
13998
13999 if (!security) {
14000 send_resp(dut, conn, SIGMA_ERROR,
14001 "ErrorCode,Missing Security argument");
14002 return 0;
14003 }
14004
14005 if (!passphrase) {
14006 send_resp(dut, conn, SIGMA_ERROR,
14007 "ErrorCode,Missing Passphrase argument");
14008 return 0;
14009 }
14010
14011 if (!pin) {
14012 send_resp(dut, conn, SIGMA_ERROR,
14013 "ErrorCode,Missing PIN argument");
14014 return 0;
14015 }
14016
vamsi krishna8c9c1562017-05-12 15:51:46 +053014017 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
14018 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014019 send_resp(dut, conn, SIGMA_ERROR,
14020 "ErrorCode,Too long SSID/passphrase");
14021 return 0;
14022 }
14023
14024 ctrl = open_wpa_mon(intf);
14025 if (ctrl == NULL) {
14026 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14027 "wpa_supplicant monitor connection");
14028 return -2;
14029 }
14030
14031 if (strcasecmp(security, "wpa2-psk") == 0) {
14032 keymgmt = "WPA2PSK";
14033 cipher = "CCMP";
14034 } else {
14035 wpa_ctrl_detach(ctrl);
14036 wpa_ctrl_close(ctrl);
14037 send_resp(dut, conn, SIGMA_ERROR,
14038 "ErrorCode,Unsupported Security value");
14039 return 0;
14040 }
14041
14042 ascii2hexstr(ssid, ssid_hex);
14043 ascii2hexstr(passphrase, passphrase_hex);
14044 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
14045 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
14046
14047 if (wpa_command(intf, buf) < 0) {
14048 wpa_ctrl_detach(ctrl);
14049 wpa_ctrl_close(ctrl);
14050 send_resp(dut, conn, SIGMA_ERROR,
14051 "ErrorCode,Failed to start registrar");
14052 return 0;
14053 }
14054
14055 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
14056 dut->er_oper_performed = 1;
14057
14058 return wps_connection_event(dut, conn, ctrl, intf, 0);
14059}
14060
14061
Jouni Malinenf7222712019-06-13 01:50:21 +030014062static enum sigma_cmd_result
14063cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
14064 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014065{
14066 struct wpa_ctrl *ctrl;
14067 const char *intf = get_param(cmd, "Interface");
14068 const char *bssid = get_param(cmd, "Bssid");
14069 char buf[100];
14070
14071 if (!bssid) {
14072 send_resp(dut, conn, SIGMA_ERROR,
14073 "ErrorCode,Missing Bssid argument");
14074 return 0;
14075 }
14076
14077 ctrl = open_wpa_mon(intf);
14078 if (ctrl == NULL) {
14079 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14080 "wpa_supplicant monitor connection");
14081 return -2;
14082 }
14083
14084 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
14085
14086 if (wpa_command(intf, buf) < 0) {
14087 wpa_ctrl_detach(ctrl);
14088 wpa_ctrl_close(ctrl);
14089 send_resp(dut, conn, SIGMA_ERROR,
14090 "ErrorCode,Failed to start registrar");
14091 return 0;
14092 }
14093
14094 return wps_connection_event(dut, conn, ctrl, intf, 0);
14095}
14096
14097
Jouni Malinenf7222712019-06-13 01:50:21 +030014098static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
14099 struct sigma_conn *conn,
14100 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053014101{
14102 struct wpa_ctrl *ctrl;
14103 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014104 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014105 const char *config_method = get_param(cmd, "WPSConfigMethod");
14106 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053014107 int res;
14108 char buf[256];
14109 const char *events[] = {
14110 "CTRL-EVENT-CONNECTED",
14111 "WPS-OVERLAP-DETECTED",
14112 "WPS-TIMEOUT",
14113 "WPS-FAIL",
14114 NULL
14115 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014116 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053014117
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014118 /* 60G WPS tests do not pass Interface parameter */
14119 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014120 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014121
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014122 if (dut->mode == SIGMA_MODE_AP)
14123 return ap_wps_registration(dut, conn, cmd);
14124
14125 if (config_method) {
14126 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
14127 * sta_wps_enter_pin before calling start_wps_registration. */
14128 if (strcasecmp(config_method, "PBC") == 0)
14129 dut->wps_method = WFA_CS_WPS_PBC;
14130 }
14131 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
14132 send_resp(dut, conn, SIGMA_ERROR,
14133 "ErrorCode,WPS parameters not yet set");
14134 return STATUS_SENT;
14135 }
14136
14137 /* Make sure WPS is enabled (also for STA mode) */
14138 dut->wps_disable = 0;
14139
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014140 if (dut->band == WPS_BAND_60G && network_mode &&
14141 strcasecmp(network_mode, "PBSS") == 0) {
14142 sigma_dut_print(dut, DUT_MSG_DEBUG,
14143 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014144 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014145 return -2;
14146 }
14147
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020014148 if (dut->force_rsn_ie) {
14149 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
14150 dut->force_rsn_ie);
14151 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
14152 sigma_dut_print(dut, DUT_MSG_INFO,
14153 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014154 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020014155 }
14156 }
14157
vamsi krishna9b144002017-09-20 13:28:13 +053014158 ctrl = open_wpa_mon(intf);
14159 if (!ctrl) {
14160 sigma_dut_print(dut, DUT_MSG_ERROR,
14161 "Failed to open wpa_supplicant monitor connection");
14162 return -2;
14163 }
14164
14165 role = get_param(cmd, "WpsRole");
14166 if (!role) {
14167 send_resp(dut, conn, SIGMA_INVALID,
14168 "ErrorCode,WpsRole not provided");
14169 goto fail;
14170 }
14171
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014172 if (strcasecmp(role, "Enrollee") != 0) {
14173 /* Registrar role for STA not supported */
14174 send_resp(dut, conn, SIGMA_ERROR,
14175 "ErrorCode,Unsupported WpsRole value");
14176 goto fail;
14177 }
14178
14179 if (is_60g_sigma_dut(dut)) {
14180 if (dut->wps_method == WFA_CS_WPS_PBC)
14181 snprintf(buf, sizeof(buf), "WPS_PBC");
14182 else /* WFA_CS_WPS_PIN_KEYPAD */
14183 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
14184 dut->wps_pin);
14185 if (wpa_command(intf, buf) < 0) {
14186 send_resp(dut, conn, SIGMA_ERROR,
14187 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053014188 goto fail;
14189 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014190 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
14191 if (res < 0) {
14192 send_resp(dut, conn, SIGMA_ERROR,
14193 "ErrorCode,WPS connection did not complete");
14194 goto fail;
14195 }
14196 if (strstr(buf, "WPS-TIMEOUT")) {
14197 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
14198 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
14199 send_resp(dut, conn, SIGMA_COMPLETE,
14200 "WpsState,OverlapSession");
14201 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
14202 send_resp(dut, conn, SIGMA_COMPLETE,
14203 "WpsState,Successful");
14204 } else {
14205 send_resp(dut, conn, SIGMA_COMPLETE,
14206 "WpsState,Failure");
14207 }
14208 } else {
14209 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053014210 if (wpa_command(intf, "WPS_PBC") < 0) {
14211 send_resp(dut, conn, SIGMA_ERROR,
14212 "ErrorCode,Failed to enable PBC");
14213 goto fail;
14214 }
14215 } else {
14216 /* TODO: PIN method */
14217 send_resp(dut, conn, SIGMA_ERROR,
14218 "ErrorCode,Unsupported WpsConfigMethod value");
14219 goto fail;
14220 }
14221 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
14222 if (res < 0) {
14223 send_resp(dut, conn, SIGMA_ERROR,
14224 "ErrorCode,WPS connection did not complete");
14225 goto fail;
14226 }
14227 if (strstr(buf, "WPS-TIMEOUT")) {
14228 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
14229 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
14230 send_resp(dut, conn, SIGMA_ERROR,
14231 "ErrorCode,OverlapSession");
14232 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
14233 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
14234 } else {
14235 send_resp(dut, conn, SIGMA_ERROR,
14236 "ErrorCode,WPS operation failed");
14237 }
vamsi krishna9b144002017-09-20 13:28:13 +053014238 }
14239
14240fail:
14241 wpa_ctrl_detach(ctrl);
14242 wpa_ctrl_close(ctrl);
14243 return 0;
14244}
14245
14246
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014247static int req_intf(struct sigma_cmd *cmd)
14248{
14249 return get_param(cmd, "interface") == NULL ? -1 : 0;
14250}
14251
14252
14253void sta_register_cmds(void)
14254{
14255 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
14256 cmd_sta_get_ip_config);
14257 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
14258 cmd_sta_set_ip_config);
14259 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
14260 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
14261 cmd_sta_get_mac_address);
14262 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
14263 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
14264 cmd_sta_verify_ip_connection);
14265 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
14266 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
14267 cmd_sta_set_encryption);
14268 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
14269 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
14270 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
14271 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
14272 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
14273 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
14274 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
14275 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
14276 cmd_sta_set_eapakaprime);
14277 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
14278 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
14279 /* TODO: sta_set_ibss */
14280 /* TODO: sta_set_mode */
14281 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
14282 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
14283 /* TODO: sta_up_load */
14284 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
14285 cmd_sta_preset_testparameters);
14286 /* TODO: sta_set_system */
14287 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
14288 /* TODO: sta_set_rifs_test */
14289 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
14290 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
14291 /* TODO: sta_send_coexist_mgmt */
14292 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
14293 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
14294 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
14295 sigma_dut_reg_cmd("sta_reset_default", req_intf,
14296 cmd_sta_reset_default);
14297 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
14298 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
14299 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
14300 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
14301 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014302 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014303 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
14304 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
14305 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
14306 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
14307 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030014308 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
14309 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014310 sigma_dut_reg_cmd("sta_add_credential", req_intf,
14311 cmd_sta_add_credential);
14312 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020014313 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014314 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
14315 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
14316 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
14317 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
14318 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
14319 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030014320 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014321 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
14322 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014323 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053014324 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014325}