blob: 983adb4822633dee17868f37bd082259889523cd [file] [log] [blame]
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001/*
2 * Sigma Control API DUT (station/AP)
3 * Copyright (c) 2010-2011, Atheros Communications, Inc.
Jouni Malinen9d7e31d2017-12-22 18:55:04 +02004 * Copyright (c) 2011-2017, Qualcomm Atheros, Inc.
Jouni Malinenc12ea4a2018-01-05 21:07:10 +02005 * Copyright (c) 2018, The Linux Foundation
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006 * All Rights Reserved.
7 * Licensed under the Clear BSD license. See README for more details.
8 */
9
10#include "sigma_dut.h"
11#include <sys/ioctl.h>
12#include <sys/stat.h>
Jouni Malinen82905202018-04-29 17:20:10 +030013#include <sys/wait.h>
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030014#include <ctype.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015#ifdef __linux__
Lior Davidcc88b562017-01-03 18:52:09 +020016#include <regex.h>
17#include <dirent.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020018#include <sys/time.h>
19#include <netpacket/packet.h>
20#include <linux/if_ether.h>
21#ifdef ANDROID
22#include <cutils/properties.h>
23#include <android/log.h>
24#include "keystore_get.h"
25#else /* ANDROID */
26#include <ifaddrs.h>
27#endif /* ANDROID */
28#include <netdb.h>
29#endif /* __linux__ */
30#ifdef __QNXNTO__
31#include <net/if_dl.h>
32#endif /* __QNXNTO__ */
33#include "wpa_ctrl.h"
34#include "wpa_helpers.h"
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070035#include "miracast.h"
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070036#include "qca-vendor_copy.h"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020037
38/* Temporary files for sta_send_addba */
39#define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp"
40#define VI_QOS_FILE "/tmp/vi-qos.txt"
41#define VI_QOS_REFFILE "/etc/vi-qos.txt"
42
43/*
44 * MTU for Ethernet need to take into account 8-byte SNAP header
45 * to be added when encapsulating Ethernet frame into 802.11
46 */
47#ifndef IEEE80211_MAX_DATA_LEN_DMG
48#define IEEE80211_MAX_DATA_LEN_DMG 7920
49#endif
50#ifndef IEEE80211_SNAP_LEN_DMG
51#define IEEE80211_SNAP_LEN_DMG 8
52#endif
53
Ashwini Patil00402582017-04-13 12:29:39 +053054#define NON_PREF_CH_LIST_SIZE 100
Ashwini Patil5acd7382017-04-13 15:55:04 +053055#define NEIGHBOR_REPORT_SIZE 1000
56#define DEFAULT_NEIGHBOR_BSSID_INFO "17"
57#define DEFAULT_NEIGHBOR_PHY_TYPE "1"
Ashwini Patil00402582017-04-13 12:29:39 +053058
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030059#define WIL_DEFAULT_BI 100
60
61/* default remain on channel time for transmitting frames (milliseconds) */
62#define WIL_TRANSMIT_FRAME_DEFAULT_ROC 500
63#define IEEE80211_P2P_ATTR_DEVICE_ID 3
64#define IEEE80211_P2P_ATTR_GROUP_ID 15
65
66/* describes tagged bytes in template frame file */
67struct template_frame_tag {
68 int num;
69 int offset;
70 size_t len;
71};
72
Jouni Malinencd4e3c32015-10-29 12:39:56 +020073extern char *sigma_wpas_ctrl;
74extern char *sigma_cert_path;
75extern enum driver_type wifi_chip_type;
76extern char *sigma_radio_ifname[];
77
Lior David0fe101e2017-03-09 16:09:50 +020078#ifdef __linux__
79#define WIL_WMI_MAX_PAYLOAD 248
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020080#define WIL_WMI_ESE_CFG_CMDID 0xa01
Lior David0fe101e2017-03-09 16:09:50 +020081#define WIL_WMI_BF_TRIG_CMDID 0x83a
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020082#define WIL_WMI_UNIT_TEST_CMDID 0x900
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030083#define WIL_WMI_P2P_CFG_CMDID 0x910
84#define WIL_WMI_START_LISTEN_CMDID 0x914
85#define WIL_WMI_DISCOVERY_STOP_CMDID 0x917
Lior David0fe101e2017-03-09 16:09:50 +020086
87struct wil_wmi_header {
88 uint8_t mid;
89 uint8_t reserved;
90 uint16_t cmd;
91 uint32_t ts;
92} __attribute__((packed));
93
94enum wil_wmi_bf_trig_type {
95 WIL_WMI_SLS,
96 WIL_WMI_BRP_RX,
97 WIL_WMI_BRP_TX,
98};
99
100struct wil_wmi_bf_trig_cmd {
101 /* enum wil_wmi_bf_trig_type */
102 uint32_t bf_type;
103 /* cid when type == WMI_BRP_RX */
104 uint32_t sta_id;
105 uint32_t reserved;
106 /* mac address when type = WIL_WMI_SLS */
107 uint8_t dest_mac[6];
108} __attribute__((packed));
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200109
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200110enum wil_wmi_sched_scheme_advertisment {
111 WIL_WMI_ADVERTISE_ESE_DISABLED,
112 WIL_WMI_ADVERTISE_ESE_IN_BEACON,
113 WIL_WMI_ADVERTISE_ESE_IN_ANNOUNCE_FRAME,
114};
115
116enum wil_wmi_ese_slot_type {
117 WIL_WMI_ESE_SP,
118 WIL_WMI_ESE_CBAP,
119 WIL_WMI_ESE_ANNOUNCE_NO_ACK,
120};
121
122struct wil_wmi_ese_slot {
123 /* offset from start of BI in microseconds */
124 uint32_t tbtt_offset;
125 uint8_t flags;
126 /* enum wil_wmi_ese_slot_type */
127 uint8_t slot_type;
128 /* duration in microseconds */
129 uint16_t duration;
130 /* frame exchange sequence duration, microseconds */
131 uint16_t tx_op;
132 /* time between 2 blocks for periodic allocation(microseconds) */
133 uint16_t period;
134 /* number of blocks in periodic allocation */
135 uint8_t num_blocks;
136 /* for semi-active allocations */
137 uint8_t idle_period;
138 uint8_t src_aid;
139 uint8_t dst_aid;
140 uint32_t reserved;
141} __attribute__((packed));
142
143#define WIL_WMI_MAX_ESE_SLOTS 4
144struct wil_wmi_ese_cfg {
145 uint8_t serial_num;
146 /* wil_wmi_sched_scheme_advertisment */
147 uint8_t ese_advertisment;
148 uint16_t flags;
149 uint8_t num_allocs;
150 uint8_t reserved[3];
151 uint64_t start_tbtt;
152 /* allocations list */
153 struct wil_wmi_ese_slot slots[WIL_WMI_MAX_ESE_SLOTS];
154} __attribute__((packed));
155
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200156#define WIL_WMI_UT_FORCE_MCS 6
157struct wil_wmi_force_mcs {
158 /* WIL_WMI_UT_HW_SYSAPI */
159 uint16_t module_id;
160 /* WIL_WMI_UT_FORCE_MCS */
161 uint16_t subtype_id;
162 /* cid (ignored in oob_mode, affects all stations) */
163 uint32_t cid;
164 /* 1 to force MCS, 0 to restore default behavior */
165 uint32_t force_enable;
166 /* MCS index, 0-12 */
167 uint32_t mcs;
168} __attribute__((packed));
169
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200170#define WIL_WMI_UT_HW_SYSAPI 10
171#define WIL_WMI_UT_FORCE_RSN_IE 0x29
172struct wil_wmi_force_rsn_ie {
173 /* WIL_WMI_UT_HW_SYSAPI */
174 uint16_t module_id;
175 /* WIL_WMI_UT_FORCE_RSN_IE */
176 uint16_t subtype_id;
177 /* 0 = no change, 1 = remove if exists, 2 = add if does not exist */
178 uint32_t state;
179} __attribute__((packed));
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300180
181enum wil_wmi_discovery_mode {
182 WMI_DISCOVERY_MODE_NON_OFFLOAD,
183 WMI_DISCOVERY_MODE_OFFLOAD,
184 WMI_DISCOVERY_MODE_PEER2PEER,
185};
186
187struct wil_wmi_p2p_cfg_cmd {
188 /* enum wil_wmi_discovery_mode */
189 uint8_t discovery_mode;
190 /* 0-based (wireless channel - 1) */
191 uint8_t channel;
192 /* set to WIL_DEFAULT_BI */
193 uint16_t bcon_interval;
194} __attribute__((packed));
Lior David0fe101e2017-03-09 16:09:50 +0200195#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200196
197#ifdef ANDROID
198
199static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname);
200
201#define ANDROID_KEYSTORE_GET 'g'
202#define ANDROID_KEYSTORE_GET_PUBKEY 'b'
203
204static int android_keystore_get(char cmd, const char *key, unsigned char *val)
205{
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200206 /* Android 4.3 changed keystore design, so need to use keystore_get() */
207#ifndef KEYSTORE_MESSAGE_SIZE
208#define KEYSTORE_MESSAGE_SIZE 65535
209#endif /* KEYSTORE_MESSAGE_SIZE */
210
211 ssize_t len;
212 uint8_t *value = NULL;
213
214 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
215 "keystore command '%c' key '%s' --> keystore_get",
216 cmd, key);
217
218 len = keystore_get(key, strlen(key), &value);
219 if (len < 0) {
220 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
221 "keystore_get() failed");
222 return -1;
223 }
224
225 if (len > KEYSTORE_MESSAGE_SIZE)
226 len = KEYSTORE_MESSAGE_SIZE;
227 memcpy(val, value, len);
228 free(value);
229 return len;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200230}
231#endif /* ANDROID */
232
233
Vinita S. Maloo0fcb57d2020-04-24 14:03:56 +0530234#ifdef NL80211_SUPPORT
235static int nl80211_sta_set_power_save(struct sigma_dut *dut,
236 const char *intf,
237 enum nl80211_ps_state ps_state)
238{
239 struct nl_msg *msg;
240 int ifindex, ret;
241
242 ifindex = if_nametoindex(intf);
243 if (ifindex == 0) {
244 sigma_dut_print(dut, DUT_MSG_ERROR,
245 "%s: Index for interface %s not found",
246 __func__, intf);
247 return -1;
248 }
249
250 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
251 NL80211_CMD_SET_POWER_SAVE);
252 if (!msg) {
253 sigma_dut_print(dut, DUT_MSG_ERROR,
254 "%s: err in creating nl80211 msg", __func__);
255 return -1;
256 }
257
258 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) {
259 sigma_dut_print(dut, DUT_MSG_ERROR,
260 "%s: err in populating nl80211 msg", __func__);
261 nlmsg_free(msg);
262 return -1;
263 }
264
265 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
266 if (ret) {
267 sigma_dut_print(dut, DUT_MSG_ERROR,
268 "%s: err in send_and_recv_msgs, ret=%d (%s)",
269 __func__, ret, strerror(-ret));
270 return -1;
271 }
272
273 return 0;
274}
275#endif /* NL80211_SUPPORT */
276
277
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530278static int set_power_save_wcn(struct sigma_dut *dut, const char *intf, int ps)
279{
280 char buf[100];
Vinita S. Maloo0fcb57d2020-04-24 14:03:56 +0530281#ifdef NL80211_SUPPORT
282 enum nl80211_ps_state ps_state;
283
284 ps_state = ps == 1 ? NL80211_PS_ENABLED : NL80211_PS_DISABLED;
285 if (nl80211_sta_set_power_save(dut, intf, ps_state) == 0)
286 return 0;
287#endif /* NL80211_SUPPORT */
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530288
289 snprintf(buf, sizeof(buf), "iwpriv %s setPower %d", intf, ps);
290 if (system(buf) != 0) {
291 sigma_dut_print(dut, DUT_MSG_ERROR,
292 "iwpriv setPower %d failed", ps);
293 return -1;
294 }
295 return 0;
296}
297
298
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200299int set_ps(const char *intf, struct sigma_dut *dut, int enabled)
300{
301#ifdef __linux__
302 char buf[100];
303
304 if (wifi_chip_type == DRIVER_WCN) {
305 if (enabled) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530306 if (set_power_save_wcn(dut, intf, 1) < 0) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530307 snprintf(buf, sizeof(buf),
308 "iwpriv wlan0 dump 906");
309 if (system(buf) != 0)
310 goto set_power_save;
311 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200312 } else {
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530313 if (set_power_save_wcn(dut, intf, 2) < 0) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530314 snprintf(buf, sizeof(buf),
315 "iwpriv wlan0 dump 905");
316 if (system(buf) != 0)
317 goto set_power_save;
318 snprintf(buf, sizeof(buf),
319 "iwpriv wlan0 dump 912");
320 if (system(buf) != 0)
321 goto set_power_save;
322 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200323 }
324
325 return 0;
326 }
327
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530328set_power_save:
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200329 snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s",
330 intf, enabled ? "on" : "off");
331 if (system(buf) != 0) {
332 snprintf(buf, sizeof(buf), "iw dev %s set power_save %s",
333 intf, enabled ? "on" : "off");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530334 if (system(buf) != 0) {
335 sigma_dut_print(dut, DUT_MSG_ERROR,
336 "Failed to set power save %s",
337 enabled ? "on" : "off");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200338 return -1;
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530339 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200340 }
341
342 return 0;
343#else /* __linux__ */
344 return -1;
345#endif /* __linux__ */
346}
347
348
Lior Davidcc88b562017-01-03 18:52:09 +0200349#ifdef __linux__
Lior David0fe101e2017-03-09 16:09:50 +0200350
Lior Davidcc88b562017-01-03 18:52:09 +0200351static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path,
352 size_t len)
353{
354 DIR *dir, *wil_dir;
355 struct dirent *entry;
356 int ret = -1;
357 const char *root_path = "/sys/kernel/debug/ieee80211";
358
359 dir = opendir(root_path);
360 if (!dir)
361 return -2;
362
363 while ((entry = readdir(dir))) {
364 if (strcmp(entry->d_name, ".") == 0 ||
365 strcmp(entry->d_name, "..") == 0)
366 continue;
367
368 if (snprintf(path, len, "%s/%s/wil6210",
369 root_path, entry->d_name) >= (int) len) {
370 ret = -3;
371 break;
372 }
373
374 wil_dir = opendir(path);
375 if (wil_dir) {
376 closedir(wil_dir);
377 ret = 0;
378 break;
379 }
380 }
381
382 closedir(dir);
383 return ret;
384}
Lior David0fe101e2017-03-09 16:09:50 +0200385
386
387static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command,
388 void *payload, uint16_t length)
389{
390 struct {
391 struct wil_wmi_header hdr;
392 char payload[WIL_WMI_MAX_PAYLOAD];
393 } __attribute__((packed)) cmd;
394 char buf[128], fname[128];
395 size_t towrite, written;
396 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300397 int res;
Lior David0fe101e2017-03-09 16:09:50 +0200398
399 if (length > WIL_WMI_MAX_PAYLOAD) {
400 sigma_dut_print(dut, DUT_MSG_ERROR,
401 "payload too large(%u, max %u)",
402 length, WIL_WMI_MAX_PAYLOAD);
403 return -1;
404 }
405
406 memset(&cmd.hdr, 0, sizeof(cmd.hdr));
407 cmd.hdr.cmd = command;
408 memcpy(cmd.payload, payload, length);
409
410 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
411 sigma_dut_print(dut, DUT_MSG_ERROR,
412 "failed to get wil6210 debugfs dir");
413 return -1;
414 }
415
Jouni Malinen3aa72862019-05-29 23:14:51 +0300416 res = snprintf(fname, sizeof(fname), "%s/wmi_send", buf);
417 if (res < 0 || res >= sizeof(fname))
418 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200419 f = fopen(fname, "wb");
420 if (!f) {
421 sigma_dut_print(dut, DUT_MSG_ERROR,
422 "failed to open: %s", fname);
423 return -1;
424 }
425
426 towrite = sizeof(cmd.hdr) + length;
427 written = fwrite(&cmd, 1, towrite, f);
428 fclose(f);
429 if (written != towrite) {
430 sigma_dut_print(dut, DUT_MSG_ERROR,
431 "failed to send wmi %u", command);
432 return -1;
433 }
434
435 return 0;
436}
437
438
439static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid,
440 const char *pattern, unsigned int *field)
441{
442 char buf[128], fname[128];
443 FILE *f;
444 regex_t re;
445 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +0300446 int rc, ret = -1, res;
Lior David0fe101e2017-03-09 16:09:50 +0200447
448 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
449 sigma_dut_print(dut, DUT_MSG_ERROR,
450 "failed to get wil6210 debugfs dir");
451 return -1;
452 }
453
Jouni Malinen3aa72862019-05-29 23:14:51 +0300454 res = snprintf(fname, sizeof(fname), "%s/stations", buf);
455 if (res < 0 || res >= sizeof(fname))
456 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200457 f = fopen(fname, "r");
458 if (!f) {
459 sigma_dut_print(dut, DUT_MSG_ERROR,
460 "failed to open: %s", fname);
461 return -1;
462 }
463
464 if (regcomp(&re, pattern, REG_EXTENDED)) {
465 sigma_dut_print(dut, DUT_MSG_ERROR,
466 "regcomp failed: %s", pattern);
467 goto out;
468 }
469
470 /*
471 * find the entry for the mac address
472 * line is of the form: [n] 11:22:33:44:55:66 state AID aid
473 */
474 while (fgets(buf, sizeof(buf), f)) {
475 if (strcasestr(buf, bssid)) {
476 /* extract the field (CID/AID/state) */
477 rc = regexec(&re, buf, 2, m, 0);
478 if (!rc && (m[1].rm_so >= 0)) {
479 buf[m[1].rm_eo] = 0;
480 *field = atoi(&buf[m[1].rm_so]);
481 ret = 0;
482 break;
483 }
484 }
485 }
486
487 regfree(&re);
488 if (ret)
489 sigma_dut_print(dut, DUT_MSG_ERROR,
490 "could not extract field");
491
492out:
493 fclose(f);
494
495 return ret;
496}
497
498
499static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid,
500 unsigned int *cid)
501{
502 const char *pattern = "\\[([0-9]+)\\]";
503
504 return wil6210_get_sta_info_field(dut, bssid, pattern, cid);
505}
506
507
508static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac,
509 int l_rx)
510{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700511 struct wil_wmi_bf_trig_cmd cmd;
Lior David0fe101e2017-03-09 16:09:50 +0200512 unsigned int cid;
513
Rakesh Sunki556237d2017-03-30 14:49:31 -0700514 memset(&cmd, 0, sizeof(cmd));
515
Lior David0fe101e2017-03-09 16:09:50 +0200516 if (wil6210_get_cid(dut, mac, &cid))
517 return -1;
518
519 cmd.bf_type = WIL_WMI_BRP_RX;
520 cmd.sta_id = cid;
521 /* training length (l_rx) is ignored, FW always uses length 16 */
522 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
523 &cmd, sizeof(cmd));
524}
525
526
527static int wil6210_send_sls(struct sigma_dut *dut, const char *mac)
528{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700529 struct wil_wmi_bf_trig_cmd cmd;
530
531 memset(&cmd, 0, sizeof(cmd));
Lior David0fe101e2017-03-09 16:09:50 +0200532
533 if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac))
534 return -1;
535
536 cmd.bf_type = WIL_WMI_SLS;
537 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
538 &cmd, sizeof(cmd));
539}
540
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200541
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200542int wil6210_set_ese(struct sigma_dut *dut, int count,
543 struct sigma_ese_alloc *allocs)
544{
545 struct wil_wmi_ese_cfg cmd = { };
546 int i;
547
548 if (count == 0 || count > WIL_WMI_MAX_ESE_SLOTS)
549 return -1;
550
551 if (dut->ap_bcnint <= 0) {
552 sigma_dut_print(dut, DUT_MSG_ERROR,
553 "invalid beacon interval(%d), check test",
554 dut->ap_bcnint);
555 return -1;
556 }
557
558 cmd.ese_advertisment = WIL_WMI_ADVERTISE_ESE_IN_BEACON;
559 cmd.flags = 0x1d;
560 cmd.num_allocs = count;
561 for (i = 0; i < count; i++) {
562 /*
563 * Convert percent from BI (BI specified in milliseconds)
564 * to absolute duration in microseconds.
565 */
566 cmd.slots[i].duration =
567 (allocs[i].percent_bi * dut->ap_bcnint * 1000) / 100;
568 switch (allocs[i].type) {
569 case ESE_CBAP:
570 cmd.slots[i].slot_type = WIL_WMI_ESE_CBAP;
571 break;
572 case ESE_SP:
573 cmd.slots[i].slot_type = WIL_WMI_ESE_SP;
574 break;
575 default:
576 sigma_dut_print(dut, DUT_MSG_ERROR,
577 "invalid slot type(%d) at index %d",
578 allocs[i].type, i);
579 return -1;
580 }
581 cmd.slots[i].src_aid = allocs[i].src_aid;
582 cmd.slots[i].dst_aid = allocs[i].dst_aid;
583 sigma_dut_print(dut, DUT_MSG_INFO,
584 "slot %d, duration %u, type %d, srcAID %u dstAID %u",
585 i, cmd.slots[i].duration,
586 cmd.slots[i].slot_type, cmd.slots[i].src_aid,
587 cmd.slots[i].dst_aid);
588 }
589
590 return wil6210_wmi_send(dut, WIL_WMI_ESE_CFG_CMDID, &cmd, sizeof(cmd));
591}
592
593
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200594int wil6210_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
595{
596 struct wil_wmi_force_mcs cmd = { };
597
598 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
599 cmd.subtype_id = WIL_WMI_UT_FORCE_MCS;
600 cmd.force_enable = (uint32_t) force;
601 cmd.mcs = (uint32_t) mcs;
602
603 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
604 &cmd, sizeof(cmd));
605}
606
607
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200608static int wil6210_force_rsn_ie(struct sigma_dut *dut, int state)
609{
610 struct wil_wmi_force_rsn_ie cmd = { };
611
612 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
613 cmd.subtype_id = WIL_WMI_UT_FORCE_RSN_IE;
614 cmd.state = (uint32_t) state;
615
616 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
617 &cmd, sizeof(cmd));
618}
619
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300620
621/*
622 * this function is also used to configure generic remain-on-channel
623 */
624static int wil6210_p2p_cfg(struct sigma_dut *dut, int freq)
625{
626 struct wil_wmi_p2p_cfg_cmd cmd = { };
627 int channel = freq_to_channel(freq);
628
629 if (channel < 0)
630 return -1;
631 cmd.discovery_mode = WMI_DISCOVERY_MODE_NON_OFFLOAD;
632 cmd.channel = channel - 1;
633 cmd.bcon_interval = WIL_DEFAULT_BI;
634 cmd.discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER;
635
636 return wil6210_wmi_send(dut, WIL_WMI_P2P_CFG_CMDID,
637 &cmd, sizeof(cmd));
638}
639
640
641static int wil6210_remain_on_channel(struct sigma_dut *dut, int freq)
642{
643 int ret = wil6210_p2p_cfg(dut, freq);
644
645 if (ret)
646 return ret;
647
648 ret = wil6210_wmi_send(dut, WIL_WMI_START_LISTEN_CMDID, NULL, 0);
649 if (!ret) {
650 /*
651 * wait a bit to allow FW to setup the radio
652 * especially important if we switch channels
653 */
654 usleep(500000);
655 }
656
657 return ret;
658}
659
660
661static int wil6210_stop_discovery(struct sigma_dut *dut)
662{
663 return wil6210_wmi_send(dut, WIL_WMI_DISCOVERY_STOP_CMDID, NULL, 0);
664}
665
666
667static int wil6210_transmit_frame(struct sigma_dut *dut, int freq,
668 int wait_duration,
669 const char *frame, size_t frame_len)
670{
671 char buf[128], fname[128];
672 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300673 int res = 0, r;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300674 size_t written;
675
676 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
677 sigma_dut_print(dut, DUT_MSG_ERROR,
678 "failed to get wil6210 debugfs dir");
679 return -1;
680 }
Jouni Malinen3aa72862019-05-29 23:14:51 +0300681 r = snprintf(fname, sizeof(fname), "%s/tx_mgmt", buf);
682 if (r < 0 || r >= sizeof(fname))
683 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300684
685 if (wil6210_remain_on_channel(dut, freq)) {
686 sigma_dut_print(dut, DUT_MSG_ERROR,
687 "failed to listen on channel");
688 return -1;
689 }
690
691 f = fopen(fname, "wb");
692 if (!f) {
693 sigma_dut_print(dut, DUT_MSG_ERROR,
694 "failed to open: %s", fname);
695 res = -1;
696 goto out_stop;
697 }
698 written = fwrite(frame, 1, frame_len, f);
699 fclose(f);
700
701 if (written != frame_len) {
702 sigma_dut_print(dut, DUT_MSG_ERROR,
703 "failed to transmit frame (got %zd, expected %zd)",
704 written, frame_len);
705 res = -1;
706 goto out_stop;
707 }
708
709 usleep(wait_duration * 1000);
710
711out_stop:
712 wil6210_stop_discovery(dut);
713 return res;
714}
715
716
717static int find_template_frame_tag(struct template_frame_tag *tags,
718 int total_tags, int tag_num)
719{
720 int i;
721
722 for (i = 0; i < total_tags; i++) {
723 if (tag_num == tags[i].num)
724 return i;
725 }
726
727 return -1;
728}
729
730
731static int replace_p2p_attribute(struct sigma_dut *dut, char *buf, size_t len,
732 int id, const char *value, size_t val_len)
733{
734 struct wfa_p2p_attribute *attr = (struct wfa_p2p_attribute *) buf;
735
736 if (len < 3 + val_len) {
737 sigma_dut_print(dut, DUT_MSG_ERROR,
738 "not enough space to replace P2P attribute");
739 return -1;
740 }
741
742 if (attr->len != val_len) {
743 sigma_dut_print(dut, DUT_MSG_ERROR,
744 "attribute length mismatch (need %zu have %hu)",
745 val_len, attr->len);
746 return -1;
747 }
748
749 if (attr->id != id) {
750 sigma_dut_print(dut, DUT_MSG_ERROR,
751 "incorrect attribute id (expected %d actual %d)",
752 id, attr->id);
753 return -1;
754 }
755
756 memcpy(attr->variable, value, val_len);
757
758 return 0;
759}
760
761
762static int parse_template_frame_file(struct sigma_dut *dut, const char *fname,
763 char *buf, size_t *length,
764 struct template_frame_tag *tags,
765 size_t *num_tags)
766{
767 char line[512];
768 FILE *f;
769 size_t offset = 0, tag_index = 0;
770 int num, index;
771 int in_tag = 0, tag_num = 0, tag_offset = 0;
772
773 if (*length < sizeof(struct ieee80211_hdr_3addr)) {
774 sigma_dut_print(dut, DUT_MSG_ERROR,
775 "supplied buffer is too small");
776 return -1;
777 }
778
779 f = fopen(fname, "r");
780 if (!f) {
781 sigma_dut_print(dut, DUT_MSG_ERROR,
782 "failed to open template file %s", fname);
783 return -1;
784 }
785
786 /*
787 * template file format: lines beginning with # are comments and
788 * ignored.
789 * It is possible to tag bytes in the frame to make it easy
790 * to replace fields in the template, espcially if they appear
791 * in variable-sized sections (such as IEs)
792 * This is done by a line beginning with $NUM where NUM is an integer
793 * tag number. It can be followed by space(s) and comment.
794 * The next line is considered the tagged bytes. The parser will fill
795 * the tag number, offset and length of the tagged bytes.
796 * rest of the lines contain frame bytes as sequence of hex digits,
797 * 2 digits for each byte. Spaces are allowed between bytes.
798 * On bytes lines only hex digits and spaces are allowed
799 */
800 while (!feof(f)) {
801 if (!fgets(line, sizeof(line), f))
802 break;
803 index = 0;
804 while (isspace((unsigned char) line[index]))
805 index++;
806 if (!line[index] || line[index] == '#')
807 continue;
808 if (line[index] == '$') {
809 if (tags) {
810 index++;
811 tag_num = strtol(&line[index], NULL, 0);
812 tag_offset = offset;
813 in_tag = 1;
814 }
815 continue;
816 }
817 while (line[index]) {
818 if (isspace((unsigned char) line[index])) {
819 index++;
820 continue;
821 }
822 num = hex_byte(&line[index]);
823 if (num < 0)
824 break;
825 buf[offset++] = num;
826 if (offset == *length)
827 goto out;
828 index += 2;
829 }
830
831 if (in_tag) {
832 if (tag_index < *num_tags) {
833 tags[tag_index].num = tag_num;
834 tags[tag_index].offset = tag_offset;
835 tags[tag_index].len = offset - tag_offset;
836 tag_index++;
837 } else {
838 sigma_dut_print(dut, DUT_MSG_INFO,
839 "too many tags, tag ignored");
840 }
841 in_tag = 0;
842 }
843 }
844
845 if (num_tags)
846 *num_tags = tag_index;
847out:
848 fclose(f);
849 if (offset < sizeof(struct ieee80211_hdr_3addr)) {
850 sigma_dut_print(dut, DUT_MSG_ERROR,
851 "template frame is too small");
852 return -1;
853 }
854
855 *length = offset;
856 return 0;
857}
858
Lior Davidcc88b562017-01-03 18:52:09 +0200859#endif /* __linux__ */
860
861
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200862static void static_ip_file(int proto, const char *addr, const char *mask,
863 const char *gw)
864{
865 if (proto) {
866 FILE *f = fopen("static-ip", "w");
867 if (f) {
868 fprintf(f, "%d %s %s %s\n", proto, addr,
869 mask ? mask : "N/A",
870 gw ? gw : "N/A");
871 fclose(f);
872 }
873 } else {
874 unlink("static-ip");
875 }
876}
877
878
879static int send_neighbor_request(struct sigma_dut *dut, const char *intf,
880 const char *ssid)
881{
882#ifdef __linux__
883 char buf[100];
884
885 snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s",
886 intf, ssid);
887 sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf);
888
889 if (system(buf) != 0) {
890 sigma_dut_print(dut, DUT_MSG_ERROR,
891 "iwpriv neighbor request failed");
892 return -1;
893 }
894
895 sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send");
896
897 return 0;
898#else /* __linux__ */
899 return -1;
900#endif /* __linux__ */
901}
902
903
904static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf,
Ashwini Patil5acd7382017-04-13 15:55:04 +0530905 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200906{
Ashwini Patil5acd7382017-04-13 15:55:04 +0530907 const char *val;
908 int reason_code = 0;
909 char buf[1024];
910
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200911 /*
912 * In the earlier builds we used WNM_QUERY and in later
913 * builds used WNM_BSS_QUERY.
914 */
915
Ashwini Patil5acd7382017-04-13 15:55:04 +0530916 val = get_param(cmd, "BTMQuery_Reason_Code");
917 if (val)
918 reason_code = atoi(val);
919
920 val = get_param(cmd, "Cand_List");
921 if (val && atoi(val) == 1 && dut->btm_query_cand_list) {
922 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code,
923 dut->btm_query_cand_list);
924 free(dut->btm_query_cand_list);
925 dut->btm_query_cand_list = NULL;
926 } else {
927 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code);
928 }
929
930 if (wpa_command(intf, buf) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200931 sigma_dut_print(dut, DUT_MSG_ERROR,
932 "transition management query failed");
933 return -1;
934 }
935
936 sigma_dut_print(dut, DUT_MSG_DEBUG,
937 "transition management query sent");
938
939 return 0;
940}
941
942
943int is_ip_addr(const char *str)
944{
945 const char *pos = str;
946 struct in_addr addr;
947
948 while (*pos) {
949 if (*pos != '.' && (*pos < '0' || *pos > '9'))
950 return 0;
951 pos++;
952 }
953
954 return inet_aton(str, &addr);
955}
956
957
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200958int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
959 size_t buf_len)
960{
vamsi krishnaa11d0732018-05-16 12:19:48 +0530961 char tmp[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200962 char ip[16], mask[15], dns[16], sec_dns[16];
963 int is_dhcp = 0;
964 int s;
965#ifdef ANDROID
966 char prop[PROPERTY_VALUE_MAX];
vamsi krishnaa11d0732018-05-16 12:19:48 +0530967#else /* ANDROID */
968 FILE *f;
969#ifdef __linux__
970 const char *str_ps;
971#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200972#endif /* ANDROID */
973
974 ip[0] = '\0';
975 mask[0] = '\0';
976 dns[0] = '\0';
977 sec_dns[0] = '\0';
978
979 s = socket(PF_INET, SOCK_DGRAM, 0);
980 if (s >= 0) {
981 struct ifreq ifr;
982 struct sockaddr_in saddr;
983
984 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700985 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200986 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
987 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
988 "%s IP address: %s",
989 ifname, strerror(errno));
990 } else {
991 memcpy(&saddr, &ifr.ifr_addr,
992 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700993 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200994 }
995
996 if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) {
997 memcpy(&saddr, &ifr.ifr_addr,
998 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700999 strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001000 }
1001 close(s);
1002 }
1003
1004#ifdef ANDROID
1005 snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname);
1006 if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) {
1007 snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname);
1008 if (property_get(tmp, prop, NULL) != 0 &&
1009 strcmp(prop, "ok") == 0) {
1010 snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress",
1011 ifname);
1012 if (property_get(tmp, prop, NULL) != 0 &&
1013 strcmp(ip, prop) == 0)
1014 is_dhcp = 1;
1015 }
1016 }
1017
1018 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -07001019 if (property_get(tmp, prop, NULL) != 0)
1020 strlcpy(dns, prop, sizeof(dns));
1021 else if (property_get("net.dns1", prop, NULL) != 0)
1022 strlcpy(dns, prop, sizeof(dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001023
1024 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -07001025 if (property_get(tmp, prop, NULL) != 0)
1026 strlcpy(sec_dns, prop, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001027#else /* ANDROID */
1028#ifdef __linux__
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001029 if (get_driver_type(dut) == DRIVER_OPENWRT)
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301030 str_ps = "ps -w";
1031 else
1032 str_ps = "ps ax";
1033 snprintf(tmp, sizeof(tmp),
1034 "%s | grep dhclient | grep -v grep | grep -q %s",
1035 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001036 if (system(tmp) == 0)
1037 is_dhcp = 1;
1038 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301039 snprintf(tmp, sizeof(tmp),
1040 "%s | grep udhcpc | grep -v grep | grep -q %s",
1041 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001042 if (system(tmp) == 0)
1043 is_dhcp = 1;
1044 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301045 snprintf(tmp, sizeof(tmp),
1046 "%s | grep dhcpcd | grep -v grep | grep -q %s",
1047 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001048 if (system(tmp) == 0)
1049 is_dhcp = 1;
1050 }
1051 }
1052#endif /* __linux__ */
1053
1054 f = fopen("/etc/resolv.conf", "r");
1055 if (f) {
vamsi krishnaa11d0732018-05-16 12:19:48 +05301056 char *pos, *pos2;
1057
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001058 while (fgets(tmp, sizeof(tmp), f)) {
1059 if (strncmp(tmp, "nameserver", 10) != 0)
1060 continue;
1061 pos = tmp + 10;
1062 while (*pos == ' ' || *pos == '\t')
1063 pos++;
1064 pos2 = pos;
1065 while (*pos2) {
1066 if (*pos2 == '\n' || *pos2 == '\r') {
1067 *pos2 = '\0';
1068 break;
1069 }
1070 pos2++;
1071 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07001072 if (!dns[0])
1073 strlcpy(dns, pos, sizeof(dns));
1074 else if (!sec_dns[0])
1075 strlcpy(sec_dns, pos, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001076 }
1077 fclose(f);
1078 }
1079#endif /* ANDROID */
1080
1081 snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s",
1082 is_dhcp, ip, mask, dns);
1083 buf[buf_len - 1] = '\0';
1084
1085 return 0;
1086}
1087
1088
1089
1090
1091int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf,
1092 size_t buf_len)
1093{
1094#ifdef __linux__
1095#ifdef ANDROID
1096 char cmd[200], result[1000], *pos, *end;
1097 FILE *f;
1098 size_t len;
1099
1100 snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname);
1101 f = popen(cmd, "r");
1102 if (f == NULL)
1103 return -1;
1104 len = fread(result, 1, sizeof(result) - 1, f);
1105 pclose(f);
1106 if (len == 0)
1107 return -1;
1108 result[len] = '\0';
1109 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result);
1110
1111 pos = strstr(result, "inet6 ");
1112 if (pos == NULL)
1113 return -1;
1114 pos += 6;
1115 end = strchr(pos, ' ');
1116 if (end)
1117 *end = '\0';
1118 end = strchr(pos, '/');
1119 if (end)
1120 *end = '\0';
1121 snprintf(buf, buf_len, "ip,%s", pos);
1122 buf[buf_len - 1] = '\0';
1123 return 0;
1124#else /* ANDROID */
1125 struct ifaddrs *ifaddr, *ifa;
1126 int res, found = 0;
1127 char host[NI_MAXHOST];
1128
1129 if (getifaddrs(&ifaddr) < 0) {
1130 perror("getifaddrs");
1131 return -1;
1132 }
1133
1134 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
1135 if (strcasecmp(ifname, ifa->ifa_name) != 0)
1136 continue;
1137 if (ifa->ifa_addr == NULL ||
1138 ifa->ifa_addr->sa_family != AF_INET6)
1139 continue;
1140
1141 res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
1142 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
1143 if (res != 0) {
1144 sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s",
1145 gai_strerror(res));
1146 continue;
1147 }
1148 if (strncmp(host, "fe80::", 6) == 0)
1149 continue; /* skip link-local */
1150
1151 sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host);
1152 found = 1;
1153 break;
1154 }
1155
1156 freeifaddrs(ifaddr);
1157
1158 if (found) {
1159 char *pos;
1160 pos = strchr(host, '%');
1161 if (pos)
1162 *pos = '\0';
1163 snprintf(buf, buf_len, "ip,%s", host);
1164 buf[buf_len - 1] = '\0';
1165 return 0;
1166 }
1167
1168#endif /* ANDROID */
1169#endif /* __linux__ */
1170 return -1;
1171}
1172
1173
Jouni Malinenf7222712019-06-13 01:50:21 +03001174static enum sigma_cmd_result cmd_sta_get_ip_config(struct sigma_dut *dut,
1175 struct sigma_conn *conn,
1176 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001177{
1178 const char *intf = get_param(cmd, "Interface");
1179 const char *ifname;
1180 char buf[200];
1181 const char *val;
1182 int type = 1;
1183
1184 if (intf == NULL)
1185 return -1;
1186
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001187 if (strcmp(intf, get_main_ifname(dut)) == 0)
1188 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001189 else
1190 ifname = intf;
1191
1192 /*
1193 * UCC may assume the IP address to be available immediately after
1194 * association without trying to run sta_get_ip_config multiple times.
1195 * Sigma CAPI does not specify this command as a block command that
1196 * would wait for the address to become available, but to pass tests
1197 * more reliably, it looks like such a wait may be needed here.
1198 */
1199 if (wait_ip_addr(dut, ifname, 15) < 0) {
1200 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address "
1201 "for sta_get_ip_config");
1202 /*
1203 * Try to continue anyway since many UCC tests do not really
1204 * care about the return value from here..
1205 */
1206 }
1207
1208 val = get_param(cmd, "Type");
1209 if (val)
1210 type = atoi(val);
1211 if (type == 2 || dut->last_set_ip_config_ipv6) {
1212 int i;
1213
1214 /*
1215 * Since we do not have proper wait for IPv6 addresses, use a
1216 * fixed two second delay here as a workaround for UCC script
1217 * assuming IPv6 address is available when this command returns.
1218 * Some scripts did not use Type,2 properly for IPv6, so include
1219 * also the cases where the previous sta_set_ip_config indicated
1220 * use of IPv6.
1221 */
1222 sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address");
1223 for (i = 0; i < 10; i++) {
1224 sleep(1);
1225 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0)
1226 {
1227 sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address");
1228 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1229#ifdef ANDROID
1230 sigma_dut_print(dut, DUT_MSG_INFO,
1231 "Adding IPv6 rule on Android");
1232 add_ipv6_rule(dut, intf);
1233#endif /* ANDROID */
1234
1235 return 0;
1236 }
1237 }
1238 }
1239 if (type == 1) {
1240 if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0)
1241 return -2;
1242 } else if (type == 2) {
1243 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0)
1244 return -2;
1245 } else {
1246 send_resp(dut, conn, SIGMA_ERROR,
1247 "errorCode,Unsupported address type");
1248 return 0;
1249 }
1250
1251 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1252 return 0;
1253}
1254
1255
1256static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname)
1257{
1258#ifdef __linux__
1259 char buf[200];
1260 char path[128];
1261 struct stat s;
1262
1263#ifdef ANDROID
1264 snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname);
1265#else /* ANDROID */
1266 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname);
1267#endif /* ANDROID */
1268 if (stat(path, &s) == 0) {
1269 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1270 sigma_dut_print(dut, DUT_MSG_INFO,
1271 "Kill previous DHCP client: %s", buf);
1272 if (system(buf) != 0)
1273 sigma_dut_print(dut, DUT_MSG_INFO,
1274 "Failed to kill DHCP client");
1275 unlink(path);
1276 sleep(1);
1277 } else {
1278 snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname);
1279
1280 if (stat(path, &s) == 0) {
1281 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1282 sigma_dut_print(dut, DUT_MSG_INFO,
1283 "Kill previous DHCP client: %s", buf);
1284 if (system(buf) != 0)
1285 sigma_dut_print(dut, DUT_MSG_INFO,
1286 "Failed to kill DHCP client");
1287 unlink(path);
1288 sleep(1);
1289 }
1290 }
1291#endif /* __linux__ */
1292}
1293
1294
1295static int start_dhcp_client(struct sigma_dut *dut, const char *ifname)
1296{
1297#ifdef __linux__
1298 char buf[200];
1299
1300#ifdef ANDROID
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301301 if (access("/system/bin/dhcpcd", F_OK) != -1) {
1302 snprintf(buf, sizeof(buf),
1303 "/system/bin/dhcpcd -b %s", ifname);
1304 } else if (access("/system/bin/dhcptool", F_OK) != -1) {
1305 snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname);
Ankita Bajaj8454e5d2019-04-05 16:04:55 +05301306 } else if (access("/vendor/bin/dhcpcd", F_OK) != -1) {
1307 snprintf(buf, sizeof(buf), "/vendor/bin/dhcpcd -b %s", ifname);
1308 } else if (access("/vendor/bin/dhcptool", F_OK) != -1) {
1309 snprintf(buf, sizeof(buf), "/vendor/bin/dhcptool %s", ifname);
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301310 } else {
1311 sigma_dut_print(dut, DUT_MSG_ERROR,
1312 "DHCP client program missing");
1313 return 0;
1314 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001315#else /* ANDROID */
1316 snprintf(buf, sizeof(buf),
1317 "dhclient -nw -pf /var/run/dhclient-%s.pid %s",
1318 ifname, ifname);
1319#endif /* ANDROID */
1320 sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf);
1321 if (system(buf) != 0) {
1322 snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname);
1323 if (system(buf) != 0) {
1324 sigma_dut_print(dut, DUT_MSG_INFO,
1325 "Failed to start DHCP client");
1326#ifndef ANDROID
1327 return -1;
1328#endif /* ANDROID */
1329 }
1330 }
1331#endif /* __linux__ */
1332
1333 return 0;
1334}
1335
1336
1337static int clear_ip_addr(struct sigma_dut *dut, const char *ifname)
1338{
1339#ifdef __linux__
1340 char buf[200];
1341
1342 snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname);
1343 if (system(buf) != 0) {
1344 sigma_dut_print(dut, DUT_MSG_INFO,
1345 "Failed to clear IP addresses");
1346 return -1;
1347 }
1348#endif /* __linux__ */
1349
1350 return 0;
1351}
1352
1353
1354#ifdef ANDROID
1355static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname)
1356{
1357 char cmd[200], *result, *pos;
1358 FILE *fp;
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301359 int tableid;
1360 size_t len, result_len = 1000;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001361
1362 snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s",
1363 ifname);
1364 fp = popen(cmd, "r");
1365 if (fp == NULL)
1366 return -1;
1367
1368 result = malloc(result_len);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301369 if (result == NULL) {
1370 fclose(fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001371 return -1;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301372 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001373
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301374 len = fread(result, 1, result_len - 1, fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001375 fclose(fp);
1376
1377 if (len == 0) {
1378 free(result);
1379 return -1;
1380 }
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301381 result[len] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001382
1383 pos = strstr(result, "table ");
1384 if (pos == NULL) {
1385 free(result);
1386 return -1;
1387 }
1388
1389 pos += strlen("table ");
1390 tableid = atoi(pos);
1391 if (tableid != 0) {
1392 if (system("ip -6 rule del prio 22000") != 0) {
1393 /* ignore any error */
1394 }
1395 snprintf(cmd, sizeof(cmd),
1396 "ip -6 rule add from all lookup %d prio 22000",
1397 tableid);
1398 if (system(cmd) != 0) {
1399 sigma_dut_print(dut, DUT_MSG_INFO,
1400 "Failed to run %s", cmd);
1401 free(result);
1402 return -1;
1403 }
1404 } else {
1405 sigma_dut_print(dut, DUT_MSG_INFO,
1406 "No Valid Table Id found %s", pos);
1407 free(result);
1408 return -1;
1409 }
1410 free(result);
1411
1412 return 0;
1413}
1414#endif /* ANDROID */
1415
1416
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301417int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
1418 const char *ip, const char *mask)
1419{
1420 char buf[200];
1421
1422 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
1423 ifname, ip, mask);
1424 return system(buf) == 0;
1425}
1426
1427
1428int set_ipv4_gw(struct sigma_dut *dut, const char *gw)
1429{
1430 char buf[200];
1431
1432 if (!is_ip_addr(gw)) {
1433 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw);
1434 return -1;
1435 }
1436
1437 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
1438 if (!dut->no_ip_addr_set && system(buf) != 0) {
1439 snprintf(buf, sizeof(buf), "ip ro re default via %s",
1440 gw);
1441 if (system(buf) != 0)
1442 return 0;
1443 }
1444
1445 return 1;
1446}
1447
1448
Jouni Malinenf7222712019-06-13 01:50:21 +03001449static enum sigma_cmd_result cmd_sta_set_ip_config(struct sigma_dut *dut,
1450 struct sigma_conn *conn,
1451 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001452{
1453 const char *intf = get_param(cmd, "Interface");
1454 const char *ifname;
1455 char buf[200];
1456 const char *val, *ip, *mask, *gw;
1457 int type = 1;
1458
1459 if (intf == NULL)
1460 return -1;
1461
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001462 if (strcmp(intf, get_main_ifname(dut)) == 0)
1463 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001464 else
1465 ifname = intf;
1466
1467 if (if_nametoindex(ifname) == 0) {
1468 send_resp(dut, conn, SIGMA_ERROR,
1469 "ErrorCode,Unknown interface");
1470 return 0;
1471 }
1472
1473 val = get_param(cmd, "Type");
1474 if (val) {
1475 type = atoi(val);
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301476 if (type < 1 || type > 3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001477 send_resp(dut, conn, SIGMA_ERROR,
1478 "ErrorCode,Unsupported address type");
1479 return 0;
1480 }
1481 }
1482
1483 dut->last_set_ip_config_ipv6 = 0;
1484
1485 val = get_param(cmd, "dhcp");
1486 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
1487 static_ip_file(0, NULL, NULL, NULL);
1488#ifdef __linux__
1489 if (type == 2) {
1490 dut->last_set_ip_config_ipv6 = 1;
1491 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
1492 "stateless address autoconfiguration");
1493#ifdef ANDROID
1494 /*
1495 * This sleep is required as the assignment in case of
1496 * Android is taking time and is done by the kernel.
1497 * The subsequent ping for IPv6 is impacting HS20 test
1498 * case.
1499 */
1500 sleep(2);
1501 add_ipv6_rule(dut, intf);
1502#endif /* ANDROID */
1503 /* Assume this happens by default */
1504 return 1;
1505 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301506 if (type != 3) {
1507 kill_dhcp_client(dut, ifname);
1508 if (start_dhcp_client(dut, ifname) < 0)
1509 return -2;
1510 } else {
1511 sigma_dut_print(dut, DUT_MSG_DEBUG,
1512 "Using FILS HLP DHCPv4 Rapid Commit");
1513 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001514
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001515 return 1;
1516#endif /* __linux__ */
1517 return -2;
1518 }
1519
1520 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301521 if (!ip) {
1522 send_resp(dut, conn, SIGMA_INVALID,
1523 "ErrorCode,Missing IP address");
1524 return 0;
1525 }
1526
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001527 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301528 if (!mask) {
1529 send_resp(dut, conn, SIGMA_INVALID,
1530 "ErrorCode,Missing subnet mask");
1531 return 0;
1532 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001533
1534 if (type == 2) {
1535 int net = atoi(mask);
1536
1537 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
1538 return -1;
1539
1540 if (dut->no_ip_addr_set) {
1541 snprintf(buf, sizeof(buf),
1542 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
1543 ifname);
1544 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1545 if (system(buf) != 0) {
1546 sigma_dut_print(dut, DUT_MSG_DEBUG,
1547 "Failed to disable IPv6 address before association");
1548 }
1549 } else {
Veerendranath Jakkam176181c2020-05-16 00:19:21 +05301550 if (set_ipv6_addr(dut, ip, mask, ifname) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001551 send_resp(dut, conn, SIGMA_ERROR,
1552 "ErrorCode,Failed to set IPv6 address");
1553 return 0;
1554 }
1555 }
1556
1557 dut->last_set_ip_config_ipv6 = 1;
1558 static_ip_file(6, ip, mask, NULL);
1559 return 1;
1560 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301561 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001562 return -1;
1563 }
1564
1565 kill_dhcp_client(dut, ifname);
1566
1567 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301568 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001569 send_resp(dut, conn, SIGMA_ERROR,
1570 "ErrorCode,Failed to set IP address");
1571 return 0;
1572 }
1573 }
1574
1575 gw = get_param(cmd, "defaultGateway");
1576 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301577 if (set_ipv4_gw(dut, gw) < 1) {
1578 send_resp(dut, conn, SIGMA_ERROR,
1579 "ErrorCode,Failed to set default gateway");
1580 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001581 }
1582 }
1583
1584 val = get_param(cmd, "primary-dns");
1585 if (val) {
1586 /* TODO */
1587 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1588 "setting", val);
1589 }
1590
1591 val = get_param(cmd, "secondary-dns");
1592 if (val) {
1593 /* TODO */
1594 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1595 "setting", val);
1596 }
1597
1598 static_ip_file(4, ip, mask, gw);
1599
1600 return 1;
1601}
1602
1603
Jouni Malinenf7222712019-06-13 01:50:21 +03001604static enum sigma_cmd_result cmd_sta_get_info(struct sigma_dut *dut,
1605 struct sigma_conn *conn,
1606 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001607{
1608 /* const char *intf = get_param(cmd, "Interface"); */
1609 /* TODO: could report more details here */
1610 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1611 return 0;
1612}
1613
1614
Jouni Malinenf7222712019-06-13 01:50:21 +03001615static enum sigma_cmd_result cmd_sta_get_mac_address(struct sigma_dut *dut,
1616 struct sigma_conn *conn,
1617 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001618{
1619 /* const char *intf = get_param(cmd, "Interface"); */
1620 char addr[20], resp[50];
1621
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301622 if (dut->dev_role == DEVROLE_STA_CFON)
1623 return sta_cfon_get_mac_address(dut, conn, cmd);
1624
Jouni Malinen9540e012019-11-05 17:08:42 +02001625 start_sta_mode(dut);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001626 if (get_wpa_status(get_station_ifname(dut), "address",
1627 addr, sizeof(addr)) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001628 return -2;
1629
1630 snprintf(resp, sizeof(resp), "mac,%s", addr);
1631 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1632 return 0;
1633}
1634
1635
Jouni Malinenf7222712019-06-13 01:50:21 +03001636static enum sigma_cmd_result cmd_sta_is_connected(struct sigma_dut *dut,
1637 struct sigma_conn *conn,
1638 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001639{
1640 /* const char *intf = get_param(cmd, "Interface"); */
1641 int connected = 0;
1642 char result[32];
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001643 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001644 sizeof(result)) < 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001645 sigma_dut_print(dut, DUT_MSG_INFO,
1646 "Could not get interface %s status",
1647 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001648 return -2;
1649 }
1650
1651 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1652 if (strncmp(result, "COMPLETED", 9) == 0)
1653 connected = 1;
1654
1655 if (connected)
1656 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1657 else
1658 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1659
1660 return 0;
1661}
1662
1663
Jouni Malinenf7222712019-06-13 01:50:21 +03001664static enum sigma_cmd_result
1665cmd_sta_verify_ip_connection(struct sigma_dut *dut, struct sigma_conn *conn,
1666 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001667{
1668 /* const char *intf = get_param(cmd, "Interface"); */
1669 const char *dst, *timeout;
1670 int wait_time = 90;
1671 char buf[100];
1672 int res;
1673
1674 dst = get_param(cmd, "destination");
1675 if (dst == NULL || !is_ip_addr(dst))
1676 return -1;
1677
1678 timeout = get_param(cmd, "timeout");
1679 if (timeout) {
1680 wait_time = atoi(timeout);
1681 if (wait_time < 1)
1682 wait_time = 1;
1683 }
1684
1685 /* TODO: force renewal of IP lease if DHCP is enabled */
1686
1687 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1688 res = system(buf);
1689 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1690 if (res == 0)
1691 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1692 else if (res == 256)
1693 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1694 else
1695 return -2;
1696
1697 return 0;
1698}
1699
1700
Jouni Malinenf7222712019-06-13 01:50:21 +03001701static enum sigma_cmd_result cmd_sta_get_bssid(struct sigma_dut *dut,
1702 struct sigma_conn *conn,
1703 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001704{
1705 /* const char *intf = get_param(cmd, "Interface"); */
1706 char bssid[20], resp[50];
1707
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001708 if (get_wpa_status(get_station_ifname(dut), "bssid",
1709 bssid, sizeof(bssid)) < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001710 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001711
1712 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1713 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1714 return 0;
1715}
1716
1717
1718#ifdef __SAMSUNG__
1719static int add_use_network(const char *ifname)
1720{
1721 char buf[100];
1722
1723 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1724 wpa_command(ifname, buf);
1725 return 0;
1726}
1727#endif /* __SAMSUNG__ */
1728
1729
1730static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1731 const char *ifname, struct sigma_cmd *cmd)
1732{
1733 const char *ssid = get_param(cmd, "ssid");
1734 int id;
1735 const char *val;
1736
1737 if (ssid == NULL)
1738 return -1;
1739
1740 start_sta_mode(dut);
1741
1742#ifdef __SAMSUNG__
1743 add_use_network(ifname);
1744#endif /* __SAMSUNG__ */
1745
1746 id = add_network(ifname);
1747 if (id < 0)
1748 return -2;
1749 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1750
1751 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1752 return -2;
1753
1754 dut->infra_network_id = id;
1755 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1756
1757 val = get_param(cmd, "program");
1758 if (!val)
1759 val = get_param(cmd, "prog");
1760 if (val && strcasecmp(val, "hs2") == 0) {
1761 char buf[100];
1762 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1763 wpa_command(ifname, buf);
1764
1765 val = get_param(cmd, "prefer");
1766 if (val && atoi(val) > 0)
1767 set_network(ifname, id, "priority", "1");
1768 }
1769
1770 return id;
1771}
1772
1773
Jouni Malinenf7222712019-06-13 01:50:21 +03001774static enum sigma_cmd_result cmd_sta_set_encryption(struct sigma_dut *dut,
1775 struct sigma_conn *conn,
1776 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001777{
1778 const char *intf = get_param(cmd, "Interface");
1779 const char *ssid = get_param(cmd, "ssid");
1780 const char *type = get_param(cmd, "encpType");
1781 const char *ifname;
1782 char buf[200];
1783 int id;
1784
1785 if (intf == NULL || ssid == NULL)
1786 return -1;
1787
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001788 if (strcmp(intf, get_main_ifname(dut)) == 0)
1789 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001790 else
1791 ifname = intf;
1792
1793 id = add_network_common(dut, conn, ifname, cmd);
1794 if (id < 0)
1795 return id;
1796
1797 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1798 return -2;
1799
1800 if (type && strcasecmp(type, "wep") == 0) {
1801 const char *val;
1802 int i;
1803
1804 val = get_param(cmd, "activeKey");
1805 if (val) {
1806 int keyid;
1807 keyid = atoi(val);
1808 if (keyid < 1 || keyid > 4)
1809 return -1;
1810 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1811 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1812 return -2;
1813 }
1814
1815 for (i = 0; i < 4; i++) {
1816 snprintf(buf, sizeof(buf), "key%d", i + 1);
1817 val = get_param(cmd, buf);
1818 if (val == NULL)
1819 continue;
1820 snprintf(buf, sizeof(buf), "wep_key%d", i);
1821 if (set_network(ifname, id, buf, val) < 0)
1822 return -2;
1823 }
1824 }
1825
1826 return 1;
1827}
1828
1829
Jouni Malinene4fde732019-03-25 22:29:37 +02001830static int set_akm_suites(struct sigma_dut *dut, const char *ifname,
1831 int id, const char *val)
1832{
1833 char key_mgmt[200], *end, *pos;
1834 const char *in_pos = val;
1835
Jouni Malinen8179fee2019-03-28 03:19:47 +02001836 dut->akm_values = 0;
Jouni Malinene4fde732019-03-25 22:29:37 +02001837 pos = key_mgmt;
1838 end = pos + sizeof(key_mgmt);
1839 while (*in_pos) {
1840 int res, akm = atoi(in_pos);
1841 const char *str;
1842
Jouni Malinen8179fee2019-03-28 03:19:47 +02001843 if (akm >= 0 && akm < 32)
1844 dut->akm_values |= 1 << akm;
1845
Jouni Malinene4fde732019-03-25 22:29:37 +02001846 switch (akm) {
1847 case AKM_WPA_EAP:
1848 str = "WPA-EAP";
1849 break;
1850 case AKM_WPA_PSK:
1851 str = "WPA-PSK";
1852 break;
1853 case AKM_FT_EAP:
1854 str = "FT-EAP";
1855 break;
1856 case AKM_FT_PSK:
1857 str = "FT-PSK";
1858 break;
1859 case AKM_EAP_SHA256:
1860 str = "WPA-EAP-SHA256";
1861 break;
1862 case AKM_PSK_SHA256:
1863 str = "WPA-PSK-SHA256";
1864 break;
1865 case AKM_SAE:
1866 str = "SAE";
1867 break;
1868 case AKM_FT_SAE:
1869 str = "FT-SAE";
1870 break;
1871 case AKM_SUITE_B:
1872 str = "WPA-EAP-SUITE-B-192";
1873 break;
1874 case AKM_FT_SUITE_B:
1875 str = "FT-EAP-SHA384";
1876 break;
1877 case AKM_FILS_SHA256:
1878 str = "FILS-SHA256";
1879 break;
1880 case AKM_FILS_SHA384:
1881 str = "FILS-SHA384";
1882 break;
1883 case AKM_FT_FILS_SHA256:
1884 str = "FT-FILS-SHA256";
1885 break;
1886 case AKM_FT_FILS_SHA384:
1887 str = "FT-FILS-SHA384";
1888 break;
1889 default:
1890 sigma_dut_print(dut, DUT_MSG_ERROR,
1891 "Unsupported AKMSuitetype %d", akm);
1892 return -1;
1893 }
1894
1895 res = snprintf(pos, end - pos, "%s%s",
1896 pos == key_mgmt ? "" : " ", str);
1897 if (res < 0 || res >= end - pos)
1898 return -1;
1899 pos += res;
1900
1901 in_pos = strchr(in_pos, ';');
1902 if (!in_pos)
1903 break;
1904 while (*in_pos == ';')
1905 in_pos++;
1906 }
1907 sigma_dut_print(dut, DUT_MSG_DEBUG, "AKMSuiteType %s --> %s",
1908 val, key_mgmt);
1909 return set_network(ifname, id, "key_mgmt", key_mgmt);
1910}
1911
1912
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001913static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1914 const char *ifname, struct sigma_cmd *cmd)
1915{
1916 const char *val;
1917 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001918 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001919 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301920 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001921
1922 id = add_network_common(dut, conn, ifname, cmd);
1923 if (id < 0)
1924 return id;
1925
Jouni Malinen47dcc952017-10-09 16:43:24 +03001926 val = get_param(cmd, "Type");
1927 owe = val && strcasecmp(val, "OWE") == 0;
1928
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001929 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001930 if (!val && owe)
1931 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001932 if (val == NULL) {
Jouni Malinene4fde732019-03-25 22:29:37 +02001933 /* keyMgmtType is being replaced with AKMSuiteType, so ignore
1934 * this missing parameter and assume proto=WPA2. */
1935 if (set_network(ifname, id, "proto", "WPA2") < 0)
1936 return ERROR_SEND_STATUS;
1937 } else if (strcasecmp(val, "wpa") == 0 ||
1938 strcasecmp(val, "wpa-psk") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001939 if (set_network(ifname, id, "proto", "WPA") < 0)
1940 return -2;
1941 } else if (strcasecmp(val, "wpa2") == 0 ||
1942 strcasecmp(val, "wpa2-psk") == 0 ||
1943 strcasecmp(val, "wpa2-ft") == 0 ||
1944 strcasecmp(val, "wpa2-sha256") == 0) {
1945 if (set_network(ifname, id, "proto", "WPA2") < 0)
1946 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301947 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1948 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001949 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1950 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001951 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301952 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001953 if (set_network(ifname, id, "proto", "WPA2") < 0)
1954 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001955 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001956 } else {
1957 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1958 return 0;
1959 }
1960
1961 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001962 if (val) {
1963 cipher_set = 1;
1964 if (strcasecmp(val, "tkip") == 0) {
1965 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1966 return -2;
1967 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1968 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1969 return -2;
1970 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1971 if (set_network(ifname, id, "pairwise",
1972 "CCMP TKIP") < 0)
1973 return -2;
1974 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1975 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1976 return -2;
1977 if (set_network(ifname, id, "group", "GCMP") < 0)
1978 return -2;
1979 } else {
1980 send_resp(dut, conn, SIGMA_ERROR,
1981 "errorCode,Unrecognized encpType value");
1982 return 0;
1983 }
1984 }
1985
1986 val = get_param(cmd, "PairwiseCipher");
1987 if (val) {
1988 cipher_set = 1;
1989 /* TODO: Support space separated list */
1990 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1991 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
1992 return -2;
1993 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1994 if (set_network(ifname, id, "pairwise",
1995 "CCMP-256") < 0)
1996 return -2;
1997 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1998 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1999 return -2;
2000 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2001 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
2002 return -2;
2003 } else {
2004 send_resp(dut, conn, SIGMA_ERROR,
2005 "errorCode,Unrecognized PairwiseCipher value");
2006 return 0;
2007 }
2008 }
2009
Jouni Malinen47dcc952017-10-09 16:43:24 +03002010 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03002011 send_resp(dut, conn, SIGMA_ERROR,
2012 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002013 return 0;
2014 }
Jouni Malinenad395a22017-09-01 21:13:46 +03002015
2016 val = get_param(cmd, "GroupCipher");
2017 if (val) {
2018 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2019 if (set_network(ifname, id, "group", "GCMP-256") < 0)
2020 return -2;
2021 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2022 if (set_network(ifname, id, "group", "CCMP-256") < 0)
2023 return -2;
2024 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2025 if (set_network(ifname, id, "group", "GCMP") < 0)
2026 return -2;
2027 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2028 if (set_network(ifname, id, "group", "CCMP") < 0)
2029 return -2;
2030 } else {
2031 send_resp(dut, conn, SIGMA_ERROR,
2032 "errorCode,Unrecognized GroupCipher value");
2033 return 0;
2034 }
2035 }
2036
Jouni Malinen7b239522017-09-14 21:37:18 +03002037 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03002038 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03002039 const char *cipher;
2040
2041 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
2042 cipher = "BIP-GMAC-256";
2043 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
2044 cipher = "BIP-CMAC-256";
2045 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
2046 cipher = "BIP-GMAC-128";
2047 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
2048 cipher = "AES-128-CMAC";
2049 } else {
2050 send_resp(dut, conn, SIGMA_INVALID,
2051 "errorCode,Unsupported GroupMgntCipher");
2052 return 0;
2053 }
2054 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
2055 send_resp(dut, conn, SIGMA_INVALID,
2056 "errorCode,Failed to set GroupMgntCipher");
2057 return 0;
2058 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002059 }
2060
Jouni Malinene4fde732019-03-25 22:29:37 +02002061 val = get_param(cmd, "AKMSuiteType");
2062 if (val && set_akm_suites(dut, ifname, id, val) < 0)
2063 return ERROR_SEND_STATUS;
2064
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002065 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302066
2067 if (dut->program == PROGRAM_OCE) {
2068 dut->sta_pmf = STA_PMF_OPTIONAL;
2069 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2070 return -2;
2071 }
2072
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002073 val = get_param(cmd, "PMF");
2074 if (val) {
2075 if (strcasecmp(val, "Required") == 0 ||
2076 strcasecmp(val, "Forced_Required") == 0) {
2077 dut->sta_pmf = STA_PMF_REQUIRED;
2078 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2079 return -2;
2080 } else if (strcasecmp(val, "Optional") == 0) {
2081 dut->sta_pmf = STA_PMF_OPTIONAL;
2082 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2083 return -2;
2084 } else if (strcasecmp(val, "Disabled") == 0 ||
Kiran Kumar Lokere07da3b22018-12-16 22:42:49 -08002085 strcasecmp(val, "Disable") == 0 ||
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002086 strcasecmp(val, "Forced_Disabled") == 0) {
2087 dut->sta_pmf = STA_PMF_DISABLED;
2088 } else {
2089 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
2090 return 0;
2091 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05302092 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02002093 dut->sta_pmf = STA_PMF_REQUIRED;
2094 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2095 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002096 }
2097
Jouni Malinen0165c7f2020-03-26 11:51:58 +02002098 val = get_param(cmd, "BeaconProtection");
2099 if (val && atoi(val) == 1 &&
2100 set_network(ifname, id, "beacon_prot", "1") < 0)
2101 return ERROR_SEND_STATUS;
2102
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002103 return id;
2104}
2105
2106
Jouni Malinenf7222712019-06-13 01:50:21 +03002107static enum sigma_cmd_result cmd_sta_set_psk(struct sigma_dut *dut,
2108 struct sigma_conn *conn,
2109 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002110{
2111 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002112 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002113 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002114 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002115 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002116 const char *ifname, *val, *alg;
2117 int id;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002118 char buf[50];
Jouni Malinen11e55212019-11-22 21:46:59 +02002119 int sae_pwe = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002120
2121 if (intf == NULL)
2122 return -1;
2123
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002124 if (strcmp(intf, get_main_ifname(dut)) == 0)
2125 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002126 else
2127 ifname = intf;
2128
2129 id = set_wpa_common(dut, conn, ifname, cmd);
2130 if (id < 0)
2131 return id;
2132
2133 val = get_param(cmd, "keyMgmtType");
2134 alg = get_param(cmd, "micAlg");
2135
Jouni Malinen992a81e2017-08-22 13:57:47 +03002136 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002137 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002138 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2139 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002140 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002141 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2142 return -2;
2143 }
2144 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2145 sigma_dut_print(dut, DUT_MSG_ERROR,
2146 "Failed to clear sae_groups to default");
2147 return -2;
2148 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002149 if (!pmf) {
2150 dut->sta_pmf = STA_PMF_REQUIRED;
2151 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2152 return -2;
2153 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002154 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2155 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2156 if (set_network(ifname, id, "key_mgmt",
2157 "FT-SAE FT-PSK") < 0)
2158 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002159 } else if (!akm) {
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002160 if (set_network(ifname, id, "key_mgmt",
2161 "SAE WPA-PSK") < 0)
2162 return -2;
2163 }
2164 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2165 sigma_dut_print(dut, DUT_MSG_ERROR,
2166 "Failed to clear sae_groups to default");
2167 return -2;
2168 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002169 if (!pmf) {
2170 dut->sta_pmf = STA_PMF_OPTIONAL;
2171 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2172 return -2;
2173 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002174 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002175 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2176 return -2;
2177 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2178 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2179 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302180 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2181 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2182 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002183 } else if (!akm &&
2184 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2185 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002186 if (set_network(ifname, id, "key_mgmt",
2187 "WPA-PSK WPA-PSK-SHA256") < 0)
2188 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002189 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002190 if (set_network(ifname, id, "key_mgmt",
2191 "WPA-PSK WPA-PSK-SHA256") < 0)
2192 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002193 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002194 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2195 return -2;
2196 }
2197
2198 val = get_param(cmd, "passPhrase");
2199 if (val == NULL)
2200 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002201 if (type && strcasecmp(type, "SAE") == 0) {
2202 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2203 return -2;
2204 } else {
2205 if (set_network_quoted(ifname, id, "psk", val) < 0)
2206 return -2;
2207 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002208
Jouni Malinen78d10c42019-03-25 22:34:32 +02002209 val = get_param(cmd, "PasswordId");
2210 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2211 return ERROR_SEND_STATUS;
2212
Jouni Malinen992a81e2017-08-22 13:57:47 +03002213 val = get_param(cmd, "ECGroupID");
2214 if (val) {
Jouni Malinenb54f0df2019-12-12 01:57:29 +02002215 snprintf(buf, sizeof(buf), "SET sae_groups %s", val);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002216 if (wpa_command(ifname, buf) != 0) {
2217 sigma_dut_print(dut, DUT_MSG_ERROR,
2218 "Failed to clear sae_groups");
2219 return -2;
2220 }
2221 }
2222
Jouni Malinen68143132017-09-02 02:34:08 +03002223 val = get_param(cmd, "InvalidSAEElement");
2224 if (val) {
2225 free(dut->sae_commit_override);
2226 dut->sae_commit_override = strdup(val);
2227 }
2228
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002229 val = get_param(cmd, "PMKID_Include");
2230 if (val) {
2231 snprintf(buf, sizeof(buf), "SET sae_pmkid_in_assoc %d",
2232 get_enable_disable(val));
2233 wpa_command(intf, buf);
2234 }
2235
Jouni Malineneeb43d32019-12-06 17:40:07 +02002236 val = get_param(cmd, "IgnoreH2E_RSNXE_BSSMemSel");
2237 if (val) {
2238 snprintf(buf, sizeof(buf), "SET ignore_sae_h2e_only %d",
2239 get_enable_disable(val));
2240 wpa_command(intf, buf);
2241 }
2242
Jouni Malinenf2348d22019-12-07 11:52:55 +02002243 val = get_param(cmd, "ECGroupID_RGE");
2244 if (val) {
2245 snprintf(buf, sizeof(buf), "SET extra_sae_rejected_groups %s",
2246 val);
2247 wpa_command(intf, buf);
2248 }
2249
Jouni Malinen99e55022019-12-07 13:59:41 +02002250 val = get_param(cmd, "RSNXE_Content");
2251 if (val) {
2252 const char *param;
2253
2254 if (strncasecmp(val, "AssocReq:", 9) == 0) {
2255 val += 9;
2256 param = "rsnxe_override_assoc";
2257 } else if (strncasecmp(val, "EapolM2:", 8) == 0) {
2258 val += 8;
2259 param = "rsnxe_override_eapol";
2260 } else {
2261 send_resp(dut, conn, SIGMA_ERROR,
2262 "errorCode,Unsupported RSNXE_Content value");
2263 return STATUS_SENT_ERROR;
2264 }
2265 snprintf(buf, sizeof(buf), "SET %s %s", param, val);
2266 wpa_command(intf, buf);
2267 }
2268
Jouni Malinen11e55212019-11-22 21:46:59 +02002269 val = get_param(cmd, "sae_pwe");
2270 if (val) {
2271 if (strcasecmp(val, "h2e") == 0) {
2272 dut->sae_pwe = SAE_PWE_H2E;
Jouni Malinen7244a412019-12-07 11:54:10 +02002273 } else if (strcasecmp(val, "loop") == 0 ||
2274 strcasecmp(val, "looping") == 0) {
Jouni Malinen11e55212019-11-22 21:46:59 +02002275 dut->sae_pwe = SAE_PWE_LOOP;
2276 } else {
2277 send_resp(dut, conn, SIGMA_ERROR,
2278 "errorCode,Unsupported sae_pwe value");
2279 return STATUS_SENT_ERROR;
2280 }
2281 }
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302282
2283 val = get_param(cmd, "Clear_RSNXE");
2284 if (val && strcmp(val, "1") == 0 &&
2285 (wpa_command(intf, "SET rsnxe_override_assoc ") ||
2286 wpa_command(intf, "SET rsnxe_override_eapol "))) {
2287 send_resp(dut, conn, SIGMA_ERROR,
2288 "errorCode,Failed to clear RSNXE");
Jouni Malinenb11498c2020-08-03 11:05:53 +03002289 return STATUS_SENT_ERROR;
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302290 }
2291
Jouni Malinenc0078772020-03-04 21:23:16 +02002292 if (dut->sae_pwe == SAE_PWE_LOOP && get_param(cmd, "PasswordId"))
2293 sae_pwe = 3;
2294 else if (dut->sae_pwe == SAE_PWE_LOOP)
Jouni Malinen11e55212019-11-22 21:46:59 +02002295 sae_pwe = 0;
2296 else if (dut->sae_pwe == SAE_PWE_H2E)
2297 sae_pwe = 1;
2298 else if (dut->sae_h2e_default)
2299 sae_pwe = 2;
2300 snprintf(buf, sizeof(buf), "SET sae_pwe %d", sae_pwe);
2301 if (sae_pwe >= 0 && wpa_command(ifname, buf) != 0)
2302 return ERROR_SEND_STATUS;
2303
Veerendranath Jakkam0316be12020-06-23 20:11:41 +05302304 val = get_param(cmd, "sae_pk");
2305 if (val && strcmp(val, "0") == 0 &&
2306 set_network(ifname, id, "sae_pk", "2") < 0)
2307 return ERROR_SEND_STATUS;
2308
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002309 if (dut->program == PROGRAM_60GHZ && network_mode &&
2310 strcasecmp(network_mode, "PBSS") == 0 &&
2311 set_network(ifname, id, "pbss", "1") < 0)
2312 return -2;
2313
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002314 return 1;
2315}
2316
2317
Jouni Malinen8ac93452019-08-14 15:19:13 +03002318static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2319 struct sigma_conn *conn,
2320 const char *ifname, int id)
2321{
2322 char buf[200];
2323
2324 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2325 if (!file_exists(buf))
2326 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2327 if (!file_exists(buf))
2328 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2329 if (!file_exists(buf)) {
2330 char msg[300];
2331
2332 snprintf(msg, sizeof(msg),
2333 "ErrorCode,trustedRootCA system store (%s) not found",
2334 buf);
2335 send_resp(dut, conn, SIGMA_ERROR, msg);
2336 return STATUS_SENT_ERROR;
2337 }
2338
2339 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2340 return ERROR_SEND_STATUS;
2341
2342 return SUCCESS_SEND_STATUS;
2343}
2344
2345
2346static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2347 struct sigma_conn *conn,
2348 const char *ifname, int id,
2349 const char *val)
2350{
2351 char buf[200];
2352#ifdef ANDROID
2353 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2354 int length;
2355#endif /* ANDROID */
2356
2357 if (strcmp(val, "DEFAULT") == 0)
2358 return set_trust_root_system(dut, conn, ifname, id);
2359
2360#ifdef ANDROID
2361 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2362 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2363 if (length > 0) {
2364 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2365 buf);
2366 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2367 goto ca_cert_selected;
2368 }
2369#endif /* ANDROID */
2370
2371 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2372#ifdef __linux__
2373 if (!file_exists(buf)) {
2374 char msg[300];
2375
2376 snprintf(msg, sizeof(msg),
2377 "ErrorCode,trustedRootCA file (%s) not found", buf);
2378 send_resp(dut, conn, SIGMA_ERROR, msg);
2379 return STATUS_SENT_ERROR;
2380 }
2381#endif /* __linux__ */
2382#ifdef ANDROID
2383ca_cert_selected:
2384#endif /* ANDROID */
2385 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2386 return ERROR_SEND_STATUS;
2387
2388 return SUCCESS_SEND_STATUS;
2389}
2390
2391
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002392static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302393 const char *ifname, int username_identity,
2394 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002395{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002396 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002397 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002398 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002399 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002400 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002401
2402 id = set_wpa_common(dut, conn, ifname, cmd);
2403 if (id < 0)
2404 return id;
2405
2406 val = get_param(cmd, "keyMgmtType");
2407 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302408 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002409 trust_root = get_param(cmd, "trustedRootCA");
2410 domain = get_param(cmd, "Domain");
2411 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002412
Jouni Malinenad395a22017-09-01 21:13:46 +03002413 if (val && strcasecmp(val, "SuiteB") == 0) {
2414 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2415 0)
2416 return -2;
2417 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002418 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2419 return -2;
2420 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2421 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2422 return -2;
2423 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2424 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2425 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002426 } else if (!akm &&
2427 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2428 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002429 if (set_network(ifname, id, "key_mgmt",
2430 "WPA-EAP WPA-EAP-SHA256") < 0)
2431 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302432 } else if (akm && atoi(akm) == 14) {
2433 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2434 dut->sta_pmf == STA_PMF_REQUIRED) {
2435 if (set_network(ifname, id, "key_mgmt",
2436 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2437 return -2;
2438 } else {
2439 if (set_network(ifname, id, "key_mgmt",
2440 "WPA-EAP FILS-SHA256") < 0)
2441 return -2;
2442 }
2443
Jouni Malinen8179fee2019-03-28 03:19:47 +02002444 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302445 } else if (akm && atoi(akm) == 15) {
2446 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2447 dut->sta_pmf == STA_PMF_REQUIRED) {
2448 if (set_network(ifname, id, "key_mgmt",
2449 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2450 return -2;
2451 } else {
2452 if (set_network(ifname, id, "key_mgmt",
2453 "WPA-EAP FILS-SHA384") < 0)
2454 return -2;
2455 }
2456
Jouni Malinen8179fee2019-03-28 03:19:47 +02002457 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002458 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002459 if (set_network(ifname, id, "key_mgmt",
2460 "WPA-EAP WPA-EAP-SHA256") < 0)
2461 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002462 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002463 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2464 return -2;
2465 }
2466
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002467 if (trust_root) {
2468 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2469 !domain_suffix) {
2470 send_resp(dut, conn, SIGMA_ERROR,
2471 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2472 return STATUS_SENT_ERROR;
2473 }
2474 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002475 if (res != SUCCESS_SEND_STATUS)
2476 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002477 }
2478
Jouni Malinen53264f62019-05-03 13:04:40 +03002479 val = get_param(cmd, "ServerCert");
2480 if (val) {
2481 FILE *f;
2482 char *result = NULL, *pos;
2483
2484 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2485 val);
2486 f = fopen(buf, "r");
2487 if (f) {
2488 result = fgets(buf, sizeof(buf), f);
2489 fclose(f);
2490 }
2491 if (!result) {
2492 snprintf(buf2, sizeof(buf2),
2493 "ErrorCode,ServerCert hash could not be read from %s",
2494 buf);
2495 send_resp(dut, conn, SIGMA_ERROR, buf2);
2496 return STATUS_SENT_ERROR;
2497 }
2498 pos = strchr(buf, '\n');
2499 if (pos)
2500 *pos = '\0';
2501 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2502 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2503 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002504
2505 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2506 if (file_exists(buf)) {
2507 sigma_dut_print(dut, DUT_MSG_DEBUG,
2508 "TOD policy enabled for the configured ServerCert hash");
2509 dut->sta_tod_policy = 1;
2510 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002511 }
2512
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002513 if (domain &&
2514 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002515 return ERROR_SEND_STATUS;
2516
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002517 if (domain_suffix &&
2518 set_network_quoted(ifname, id, "domain_suffix_match",
2519 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002520 return ERROR_SEND_STATUS;
2521
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302522 if (username_identity) {
2523 val = get_param(cmd, "username");
2524 if (val) {
2525 if (set_network_quoted(ifname, id, "identity", val) < 0)
2526 return -2;
2527 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002528
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302529 val = get_param(cmd, "password");
2530 if (val) {
2531 if (set_network_quoted(ifname, id, "password", val) < 0)
2532 return -2;
2533 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002534 }
2535
Jouni Malinen8179fee2019-03-28 03:19:47 +02002536 if (dut->akm_values &
2537 ((1 << AKM_FILS_SHA256) |
2538 (1 << AKM_FILS_SHA384) |
2539 (1 << AKM_FT_FILS_SHA256) |
2540 (1 << AKM_FT_FILS_SHA384)))
2541 erp = 1;
2542 if (erp && set_network(ifname, id, "erp", "1") < 0)
2543 return ERROR_SEND_STATUS;
2544
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002545 dut->sta_associate_wait_connect = 1;
2546
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002547 return id;
2548}
2549
2550
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002551static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2552{
2553 const char *val;
2554
2555 if (!cipher)
2556 return 0;
2557
2558 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2559 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2560 else if (strcasecmp(cipher,
2561 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2562 val = "ECDHE-RSA-AES256-GCM-SHA384";
2563 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2564 val = "DHE-RSA-AES256-GCM-SHA384";
2565 else if (strcasecmp(cipher,
2566 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2567 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2568 else
2569 return -1;
2570
2571 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2572 set_network_quoted(ifname, id, "phase1", "");
2573
2574 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2575}
2576
2577
Jouni Malinenf7222712019-06-13 01:50:21 +03002578static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2579 struct sigma_conn *conn,
2580 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002581{
2582 const char *intf = get_param(cmd, "Interface");
2583 const char *ifname, *val;
2584 int id;
2585 char buf[200];
2586#ifdef ANDROID
2587 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2588 int length;
2589 int jb_or_newer = 0;
2590 char prop[PROPERTY_VALUE_MAX];
2591#endif /* ANDROID */
2592
2593 if (intf == NULL)
2594 return -1;
2595
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002596 if (strcmp(intf, get_main_ifname(dut)) == 0)
2597 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002598 else
2599 ifname = intf;
2600
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302601 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002602 if (id < 0)
2603 return id;
2604
2605 if (set_network(ifname, id, "eap", "TLS") < 0)
2606 return -2;
2607
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302608 if (!get_param(cmd, "username") &&
2609 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002610 "wifi-user@wifilabs.local") < 0)
2611 return -2;
2612
2613 val = get_param(cmd, "clientCertificate");
2614 if (val == NULL)
2615 return -1;
2616#ifdef ANDROID
2617 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2618 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2619 if (length < 0) {
2620 /*
2621 * JB started reporting keystore type mismatches, so retry with
2622 * the GET_PUBKEY command if the generic GET fails.
2623 */
2624 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2625 buf, kvalue);
2626 }
2627
2628 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2629 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2630 if (strncmp(prop, "4.0", 3) != 0)
2631 jb_or_newer = 1;
2632 } else
2633 jb_or_newer = 1; /* assume newer */
2634
2635 if (jb_or_newer && length > 0) {
2636 sigma_dut_print(dut, DUT_MSG_INFO,
2637 "Use Android keystore [%s]", buf);
2638 if (set_network(ifname, id, "engine", "1") < 0)
2639 return -2;
2640 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2641 return -2;
2642 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2643 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2644 return -2;
2645 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2646 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2647 return -2;
2648 return 1;
2649 } else if (length > 0) {
2650 sigma_dut_print(dut, DUT_MSG_INFO,
2651 "Use Android keystore [%s]", buf);
2652 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2653 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2654 return -2;
2655 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2656 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2657 return -2;
2658 return 1;
2659 }
2660#endif /* ANDROID */
2661
2662 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2663#ifdef __linux__
2664 if (!file_exists(buf)) {
2665 char msg[300];
2666 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2667 "(%s) not found", buf);
2668 send_resp(dut, conn, SIGMA_ERROR, msg);
2669 return -3;
2670 }
2671#endif /* __linux__ */
2672 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2673 return -2;
2674 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2675 return -2;
2676
2677 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2678 return -2;
2679
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002680 val = get_param(cmd, "keyMgmtType");
2681 if (val && strcasecmp(val, "SuiteB") == 0) {
2682 val = get_param(cmd, "CertType");
2683 if (val && strcasecmp(val, "RSA") == 0) {
2684 if (set_network_quoted(ifname, id, "phase1",
2685 "tls_suiteb=1") < 0)
2686 return -2;
2687 } else {
2688 if (set_network_quoted(ifname, id, "openssl_ciphers",
2689 "SUITEB192") < 0)
2690 return -2;
2691 }
2692
2693 val = get_param(cmd, "TLSCipher");
2694 if (set_tls_cipher(ifname, id, val) < 0) {
2695 send_resp(dut, conn, SIGMA_ERROR,
2696 "ErrorCode,Unsupported TLSCipher value");
2697 return -3;
2698 }
2699 }
2700
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002701 return 1;
2702}
2703
2704
Jouni Malinenf7222712019-06-13 01:50:21 +03002705static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2706 struct sigma_conn *conn,
2707 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002708{
2709 const char *intf = get_param(cmd, "Interface");
2710 const char *ifname;
2711 int id;
2712
2713 if (intf == NULL)
2714 return -1;
2715
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002716 if (strcmp(intf, get_main_ifname(dut)) == 0)
2717 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002718 else
2719 ifname = intf;
2720
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302721 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002722 if (id < 0)
2723 return id;
2724
2725 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2726 send_resp(dut, conn, SIGMA_ERROR,
2727 "errorCode,Failed to set TTLS method");
2728 return 0;
2729 }
2730
2731 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2732 send_resp(dut, conn, SIGMA_ERROR,
2733 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2734 return 0;
2735 }
2736
2737 return 1;
2738}
2739
2740
Jouni Malinenf7222712019-06-13 01:50:21 +03002741static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2742 struct sigma_conn *conn,
2743 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002744{
2745 const char *intf = get_param(cmd, "Interface");
2746 const char *ifname;
2747 int id;
2748
2749 if (intf == NULL)
2750 return -1;
2751
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002752 if (strcmp(intf, get_main_ifname(dut)) == 0)
2753 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002754 else
2755 ifname = intf;
2756
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302757 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002758 if (id < 0)
2759 return id;
2760
2761 if (set_network(ifname, id, "eap", "SIM") < 0)
2762 return -2;
2763
2764 return 1;
2765}
2766
2767
Jouni Malinenf7222712019-06-13 01:50:21 +03002768static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2769 struct sigma_conn *conn,
2770 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002771{
2772 const char *intf = get_param(cmd, "Interface");
2773 const char *ifname, *val;
2774 int id;
2775 char buf[100];
2776
2777 if (intf == NULL)
2778 return -1;
2779
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002780 if (strcmp(intf, get_main_ifname(dut)) == 0)
2781 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002782 else
2783 ifname = intf;
2784
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302785 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002786 if (id < 0)
2787 return id;
2788
2789 if (set_network(ifname, id, "eap", "PEAP") < 0)
2790 return -2;
2791
2792 val = get_param(cmd, "innerEAP");
2793 if (val) {
2794 if (strcasecmp(val, "MSCHAPv2") == 0) {
2795 if (set_network_quoted(ifname, id, "phase2",
2796 "auth=MSCHAPV2") < 0)
2797 return -2;
2798 } else if (strcasecmp(val, "GTC") == 0) {
2799 if (set_network_quoted(ifname, id, "phase2",
2800 "auth=GTC") < 0)
2801 return -2;
2802 } else
2803 return -1;
2804 }
2805
2806 val = get_param(cmd, "peapVersion");
2807 if (val) {
2808 int ver = atoi(val);
2809 if (ver < 0 || ver > 1)
2810 return -1;
2811 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2812 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2813 return -2;
2814 }
2815
2816 return 1;
2817}
2818
2819
Jouni Malinenf7222712019-06-13 01:50:21 +03002820static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2821 struct sigma_conn *conn,
2822 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002823{
2824 const char *intf = get_param(cmd, "Interface");
2825 const char *ifname, *val;
2826 int id;
2827 char buf[100];
2828
2829 if (intf == NULL)
2830 return -1;
2831
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002832 if (strcmp(intf, get_main_ifname(dut)) == 0)
2833 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002834 else
2835 ifname = intf;
2836
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302837 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002838 if (id < 0)
2839 return id;
2840
2841 if (set_network(ifname, id, "eap", "FAST") < 0)
2842 return -2;
2843
2844 val = get_param(cmd, "innerEAP");
2845 if (val) {
2846 if (strcasecmp(val, "MSCHAPV2") == 0) {
2847 if (set_network_quoted(ifname, id, "phase2",
2848 "auth=MSCHAPV2") < 0)
2849 return -2;
2850 } else if (strcasecmp(val, "GTC") == 0) {
2851 if (set_network_quoted(ifname, id, "phase2",
2852 "auth=GTC") < 0)
2853 return -2;
2854 } else
2855 return -1;
2856 }
2857
2858 val = get_param(cmd, "validateServer");
2859 if (val) {
2860 /* TODO */
2861 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2862 "validateServer=%s", val);
2863 }
2864
2865 val = get_param(cmd, "pacFile");
2866 if (val) {
2867 snprintf(buf, sizeof(buf), "blob://%s", val);
2868 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2869 return -2;
2870 }
2871
2872 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2873 0)
2874 return -2;
2875
2876 return 1;
2877}
2878
2879
Jouni Malinenf7222712019-06-13 01:50:21 +03002880static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2881 struct sigma_conn *conn,
2882 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002883{
2884 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302885 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002886 const char *ifname;
2887 int id;
2888
2889 if (intf == NULL)
2890 return -1;
2891
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002892 if (strcmp(intf, get_main_ifname(dut)) == 0)
2893 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002894 else
2895 ifname = intf;
2896
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302897 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002898 if (id < 0)
2899 return id;
2900
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302901 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2902 * hexadecimal).
2903 */
2904 if (username && username[0] == '6') {
2905 if (set_network(ifname, id, "eap", "AKA'") < 0)
2906 return -2;
2907 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002908 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302909 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002910
2911 return 1;
2912}
2913
2914
Jouni Malinenf7222712019-06-13 01:50:21 +03002915static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2916 struct sigma_conn *conn,
2917 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002918{
2919 const char *intf = get_param(cmd, "Interface");
2920 const char *ifname;
2921 int id;
2922
2923 if (intf == NULL)
2924 return -1;
2925
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002926 if (strcmp(intf, get_main_ifname(dut)) == 0)
2927 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002928 else
2929 ifname = intf;
2930
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302931 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002932 if (id < 0)
2933 return id;
2934
2935 if (set_network(ifname, id, "eap", "AKA'") < 0)
2936 return -2;
2937
2938 return 1;
2939}
2940
2941
2942static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2943 struct sigma_cmd *cmd)
2944{
2945 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002946 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002947 const char *ifname;
2948 int id;
2949
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002950 if (strcmp(intf, get_main_ifname(dut)) == 0)
2951 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002952 else
2953 ifname = intf;
2954
2955 id = add_network_common(dut, conn, ifname, cmd);
2956 if (id < 0)
2957 return id;
2958
2959 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2960 return -2;
2961
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002962 if (dut->program == PROGRAM_60GHZ && network_mode &&
2963 strcasecmp(network_mode, "PBSS") == 0 &&
2964 set_network(ifname, id, "pbss", "1") < 0)
2965 return -2;
2966
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002967 return 1;
2968}
2969
2970
Jouni Malinen47dcc952017-10-09 16:43:24 +03002971static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2972 struct sigma_cmd *cmd)
2973{
2974 const char *intf = get_param(cmd, "Interface");
2975 const char *ifname, *val;
2976 int id;
2977
2978 if (intf == NULL)
2979 return -1;
2980
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002981 if (strcmp(intf, get_main_ifname(dut)) == 0)
2982 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002983 else
2984 ifname = intf;
2985
2986 id = set_wpa_common(dut, conn, ifname, cmd);
2987 if (id < 0)
2988 return id;
2989
2990 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
2991 return -2;
2992
2993 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03002994 if (val && strcmp(val, "0") == 0) {
2995 if (wpa_command(ifname,
2996 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
2997 sigma_dut_print(dut, DUT_MSG_ERROR,
2998 "Failed to set OWE DH Param element override");
2999 return -2;
3000 }
Hu Wang6010ce72020-03-05 19:33:53 +08003001 } else if (val &&
3002 (set_network(ifname, id, "owe_group", val) < 0 ||
3003 (dut->owe_ptk_workaround &&
3004 set_network(ifname, id, "owe_ptk_workaround", "1") < 0))) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003005 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003006 "Failed to set owe_group");
Jouni Malinen47dcc952017-10-09 16:43:24 +03003007 return -2;
3008 }
3009
3010 return 1;
3011}
3012
3013
Jouni Malinenf7222712019-06-13 01:50:21 +03003014static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3015 struct sigma_conn *conn,
3016 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003017{
3018 const char *type = get_param(cmd, "Type");
3019
3020 if (type == NULL) {
3021 send_resp(dut, conn, SIGMA_ERROR,
3022 "ErrorCode,Missing Type argument");
3023 return 0;
3024 }
3025
3026 if (strcasecmp(type, "OPEN") == 0)
3027 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003028 if (strcasecmp(type, "OWE") == 0)
3029 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003030 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003031 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003032 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003033 return cmd_sta_set_psk(dut, conn, cmd);
3034 if (strcasecmp(type, "EAPTLS") == 0)
3035 return cmd_sta_set_eaptls(dut, conn, cmd);
3036 if (strcasecmp(type, "EAPTTLS") == 0)
3037 return cmd_sta_set_eapttls(dut, conn, cmd);
3038 if (strcasecmp(type, "EAPPEAP") == 0)
3039 return cmd_sta_set_peap(dut, conn, cmd);
3040 if (strcasecmp(type, "EAPSIM") == 0)
3041 return cmd_sta_set_eapsim(dut, conn, cmd);
3042 if (strcasecmp(type, "EAPFAST") == 0)
3043 return cmd_sta_set_eapfast(dut, conn, cmd);
3044 if (strcasecmp(type, "EAPAKA") == 0)
3045 return cmd_sta_set_eapaka(dut, conn, cmd);
3046 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3047 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003048 if (strcasecmp(type, "wep") == 0)
3049 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003050
3051 send_resp(dut, conn, SIGMA_ERROR,
3052 "ErrorCode,Unsupported Type value");
3053 return 0;
3054}
3055
3056
3057int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3058{
3059#ifdef __linux__
3060 /* special handling for ath6kl */
3061 char path[128], fname[128], *pos;
3062 ssize_t res;
3063 FILE *f;
3064
Jouni Malinene39cd562019-05-29 23:39:56 +03003065 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3066 intf);
3067 if (res < 0 || res >= sizeof(fname))
3068 return 0;
3069 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003070 if (res < 0)
3071 return 0; /* not ath6kl */
3072
3073 if (res >= (int) sizeof(path))
3074 res = sizeof(path) - 1;
3075 path[res] = '\0';
3076 pos = strrchr(path, '/');
3077 if (pos == NULL)
3078 pos = path;
3079 else
3080 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003081 res = snprintf(fname, sizeof(fname),
3082 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3083 "create_qos", pos);
3084 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003085 return 0; /* not ath6kl */
3086
3087 if (uapsd) {
3088 f = fopen(fname, "w");
3089 if (f == NULL)
3090 return -1;
3091
3092 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3093 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3094 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3095 "20000 0\n");
3096 fclose(f);
3097 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003098 res = snprintf(fname, sizeof(fname),
3099 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3100 "delete_qos", pos);
3101 if (res < 0 || res >= sizeof(fname))
3102 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003103
3104 f = fopen(fname, "w");
3105 if (f == NULL)
3106 return -1;
3107
3108 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3109 fprintf(f, "2 4\n");
3110 fclose(f);
3111 }
3112#endif /* __linux__ */
3113
3114 return 0;
3115}
3116
3117
Jouni Malinenf7222712019-06-13 01:50:21 +03003118static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3119 struct sigma_conn *conn,
3120 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003121{
3122 const char *intf = get_param(cmd, "Interface");
3123 /* const char *ssid = get_param(cmd, "ssid"); */
3124 const char *val;
3125 int max_sp_len = 4;
3126 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3127 char buf[100];
3128 int ret1, ret2;
3129
3130 val = get_param(cmd, "maxSPLength");
3131 if (val) {
3132 max_sp_len = atoi(val);
3133 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3134 max_sp_len != 4)
3135 return -1;
3136 }
3137
3138 val = get_param(cmd, "acBE");
3139 if (val)
3140 ac_be = atoi(val);
3141
3142 val = get_param(cmd, "acBK");
3143 if (val)
3144 ac_bk = atoi(val);
3145
3146 val = get_param(cmd, "acVI");
3147 if (val)
3148 ac_vi = atoi(val);
3149
3150 val = get_param(cmd, "acVO");
3151 if (val)
3152 ac_vo = atoi(val);
3153
3154 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3155
3156 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3157 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3158 ret1 = wpa_command(intf, buf);
3159
3160 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3161 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3162 ret2 = wpa_command(intf, buf);
3163
3164 if (ret1 && ret2) {
3165 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3166 "UAPSD parameters.");
3167 return -2;
3168 }
3169
3170 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3171 send_resp(dut, conn, SIGMA_ERROR,
3172 "ErrorCode,Failed to set ath6kl QoS parameters");
3173 return 0;
3174 }
3175
3176 return 1;
3177}
3178
3179
Jouni Malinenf7222712019-06-13 01:50:21 +03003180static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3181 struct sigma_conn *conn,
3182 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003183{
3184 char buf[1000];
3185 const char *intf = get_param(cmd, "Interface");
3186 const char *grp = get_param(cmd, "Group");
3187 const char *act = get_param(cmd, "Action");
3188 const char *tid = get_param(cmd, "Tid");
3189 const char *dir = get_param(cmd, "Direction");
3190 const char *psb = get_param(cmd, "Psb");
3191 const char *up = get_param(cmd, "Up");
3192 const char *fixed = get_param(cmd, "Fixed");
3193 const char *size = get_param(cmd, "Size");
3194 const char *msize = get_param(cmd, "Maxsize");
3195 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3196 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3197 const char *inact = get_param(cmd, "Inactivity");
3198 const char *sus = get_param(cmd, "Suspension");
3199 const char *mindr = get_param(cmd, "Mindatarate");
3200 const char *meandr = get_param(cmd, "Meandatarate");
3201 const char *peakdr = get_param(cmd, "Peakdatarate");
3202 const char *phyrate = get_param(cmd, "Phyrate");
3203 const char *burstsize = get_param(cmd, "Burstsize");
3204 const char *sba = get_param(cmd, "Sba");
3205 int direction;
3206 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003207 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003208 int fixed_int;
3209 int psb_ts;
3210
3211 if (intf == NULL || grp == NULL || act == NULL )
3212 return -1;
3213
3214 if (strcasecmp(act, "addts") == 0) {
3215 if (tid == NULL || dir == NULL || psb == NULL ||
3216 up == NULL || fixed == NULL || size == NULL)
3217 return -1;
3218
3219 /*
3220 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3221 * possible values, but WMM-AC and V-E test scripts use "UP,
3222 * "DOWN", and "BIDI".
3223 */
3224 if (strcasecmp(dir, "uplink") == 0 ||
3225 strcasecmp(dir, "up") == 0) {
3226 direction = 0;
3227 } else if (strcasecmp(dir, "downlink") == 0 ||
3228 strcasecmp(dir, "down") == 0) {
3229 direction = 1;
3230 } else if (strcasecmp(dir, "bidi") == 0) {
3231 direction = 2;
3232 } else {
3233 sigma_dut_print(dut, DUT_MSG_ERROR,
3234 "Direction %s not supported", dir);
3235 return -1;
3236 }
3237
3238 if (strcasecmp(psb, "legacy") == 0) {
3239 psb_ts = 0;
3240 } else if (strcasecmp(psb, "uapsd") == 0) {
3241 psb_ts = 1;
3242 } else {
3243 sigma_dut_print(dut, DUT_MSG_ERROR,
3244 "PSB %s not supported", psb);
3245 return -1;
3246 }
3247
3248 if (atoi(tid) < 0 || atoi(tid) > 7) {
3249 sigma_dut_print(dut, DUT_MSG_ERROR,
3250 "TID %s not supported", tid);
3251 return -1;
3252 }
3253
3254 if (strcasecmp(fixed, "true") == 0) {
3255 fixed_int = 1;
3256 } else {
3257 fixed_int = 0;
3258 }
3259
Peng Xu93319622017-10-04 17:58:16 -07003260 if (sba)
3261 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003262
3263 dut->dialog_token++;
3264 handle = 7000 + dut->dialog_token;
3265
3266 /*
3267 * size: convert to hex
3268 * maxsi: convert to hex
3269 * mindr: convert to hex
3270 * meandr: convert to hex
3271 * peakdr: convert to hex
3272 * burstsize: convert to hex
3273 * phyrate: convert to hex
3274 * sba: convert to hex with modification
3275 * minsi: convert to integer
3276 * sus: convert to integer
3277 * inact: convert to integer
3278 * maxsi: convert to integer
3279 */
3280
3281 /*
3282 * The Nominal MSDU Size field is 2 octets long and contains an
3283 * unsigned integer that specifies the nominal size, in octets,
3284 * of MSDUs belonging to the traffic under this traffic
3285 * specification and is defined in Figure 16. If the Fixed
3286 * subfield is set to 1, then the size of the MSDU is fixed and
3287 * is indicated by the Size Subfield. If the Fixed subfield is
3288 * set to 0, then the size of the MSDU might not be fixed and
3289 * the Size indicates the nominal MSDU size.
3290 *
3291 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3292 * and specifies the excess allocation of time (and bandwidth)
3293 * over and above the stated rates required to transport an MSDU
3294 * belonging to the traffic in this TSPEC. This field is
3295 * represented as an unsigned binary number with an implicit
3296 * binary point after the leftmost 3 bits. For example, an SBA
3297 * of 1.75 is represented as 0x3800. This field is included to
3298 * account for retransmissions. As such, the value of this field
3299 * must be greater than unity.
3300 */
3301
3302 snprintf(buf, sizeof(buf),
3303 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3304 " 0x%X 0x%X 0x%X"
3305 " 0x%X 0x%X 0x%X"
3306 " 0x%X %d %d %d %d"
3307 " %d %d",
3308 intf, handle, tid, direction, psb_ts, up,
3309 (unsigned int) ((fixed_int << 15) | atoi(size)),
3310 msize ? atoi(msize) : 0,
3311 mindr ? atoi(mindr) : 0,
3312 meandr ? atoi(meandr) : 0,
3313 peakdr ? atoi(peakdr) : 0,
3314 burstsize ? atoi(burstsize) : 0,
3315 phyrate ? atoi(phyrate) : 0,
3316 sba ? ((unsigned int) (((int) sba_fv << 13) |
3317 (int)((sba_fv - (int) sba_fv) *
3318 8192))) : 0,
3319 minsi ? atoi(minsi) : 0,
3320 sus ? atoi(sus) : 0,
3321 0, 0,
3322 inact ? atoi(inact) : 0,
3323 maxsi ? atoi(maxsi) : 0);
3324
3325 if (system(buf) != 0) {
3326 sigma_dut_print(dut, DUT_MSG_ERROR,
3327 "iwpriv addtspec request failed");
3328 send_resp(dut, conn, SIGMA_ERROR,
3329 "errorCode,Failed to execute addTspec command");
3330 return 0;
3331 }
3332
3333 sigma_dut_print(dut, DUT_MSG_INFO,
3334 "iwpriv addtspec request send");
3335
3336 /* Mapping handle to a TID */
3337 dut->tid_to_handle[atoi(tid)] = handle;
3338 } else if (strcasecmp(act, "delts") == 0) {
3339 if (tid == NULL)
3340 return -1;
3341
3342 if (atoi(tid) < 0 || atoi(tid) > 7) {
3343 sigma_dut_print(dut, DUT_MSG_ERROR,
3344 "TID %s not supported", tid);
3345 send_resp(dut, conn, SIGMA_ERROR,
3346 "errorCode,Unsupported TID");
3347 return 0;
3348 }
3349
3350 handle = dut->tid_to_handle[atoi(tid)];
3351
3352 if (handle < 7000 || handle > 7255) {
3353 /* Invalid handle ie no mapping for that TID */
3354 sigma_dut_print(dut, DUT_MSG_ERROR,
3355 "handle-> %d not found", handle);
3356 }
3357
3358 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3359 intf, handle);
3360
3361 if (system(buf) != 0) {
3362 sigma_dut_print(dut, DUT_MSG_ERROR,
3363 "iwpriv deltspec request failed");
3364 send_resp(dut, conn, SIGMA_ERROR,
3365 "errorCode,Failed to execute delTspec command");
3366 return 0;
3367 }
3368
3369 sigma_dut_print(dut, DUT_MSG_INFO,
3370 "iwpriv deltspec request send");
3371
3372 dut->tid_to_handle[atoi(tid)] = 0;
3373 } else {
3374 sigma_dut_print(dut, DUT_MSG_ERROR,
3375 "Action type %s not supported", act);
3376 send_resp(dut, conn, SIGMA_ERROR,
3377 "errorCode,Unsupported Action");
3378 return 0;
3379 }
3380
3381 return 1;
3382}
3383
3384
vamsi krishna52e16f92017-08-29 12:37:34 +05303385static int find_network(struct sigma_dut *dut, const char *ssid)
3386{
3387 char list[4096];
3388 char *pos;
3389
3390 sigma_dut_print(dut, DUT_MSG_DEBUG,
3391 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003392 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303393 list, sizeof(list)) < 0)
3394 return -1;
3395 pos = strstr(list, ssid);
3396 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3397 return -1;
3398
3399 while (pos > list && pos[-1] != '\n')
3400 pos--;
3401 dut->infra_network_id = atoi(pos);
3402 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3403 return 0;
3404}
3405
3406
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303407/**
3408 * enum qca_sta_helper_config_params - This helper enum defines the config
3409 * parameters which can be delivered to sta.
3410 */
3411enum qca_sta_helper_config_params {
3412 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE */
3413 STA_SET_RSNIE,
3414
3415 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC */
3416 STA_SET_LDPC,
3417
3418 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC */
3419 STA_SET_TX_STBC,
3420
3421 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC */
3422 STA_SET_RX_STBC,
3423
3424 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION */
3425 STA_SET_TX_MSDU,
3426
3427 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION */
3428 STA_SET_RX_MSDU,
3429};
3430
3431
3432static int sta_config_params(struct sigma_dut *dut, const char *intf,
3433 enum qca_sta_helper_config_params config_cmd,
3434 int value)
Sunil Dutt44595082018-02-12 19:41:45 +05303435{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303436#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05303437 struct nl_msg *msg;
3438 int ret;
3439 struct nlattr *params;
3440 int ifindex;
3441
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303442 ifindex = if_nametoindex(intf);
3443 if (ifindex == 0) {
3444 sigma_dut_print(dut, DUT_MSG_ERROR,
3445 "%s: Interface %s does not exist",
3446 __func__, intf);
3447 return -1;
3448 }
3449
Sunil Dutt44595082018-02-12 19:41:45 +05303450 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3451 NL80211_CMD_VENDOR)) ||
3452 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3453 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3454 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3455 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303456 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)))
3457 goto fail;
3458
3459 switch (config_cmd) {
3460 case STA_SET_RSNIE:
3461 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, value))
3462 goto fail;
3463 break;
3464 case STA_SET_LDPC:
3465 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC, value))
3466 goto fail;
3467 break;
3468 case STA_SET_TX_STBC:
3469 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC, value))
3470 goto fail;
3471 break;
3472 case STA_SET_RX_STBC:
3473 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC, value))
3474 goto fail;
3475 break;
3476 case STA_SET_TX_MSDU:
3477 if (nla_put_u8(msg,
3478 QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION,
3479 value))
3480 goto fail;
3481 break;
3482 case STA_SET_RX_MSDU:
3483 if (nla_put_u8(msg,
3484 QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION,
3485 value))
3486 goto fail;
3487 break;
Sunil Dutt44595082018-02-12 19:41:45 +05303488 }
3489 nla_nest_end(msg, params);
3490
3491 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3492 if (ret) {
3493 sigma_dut_print(dut, DUT_MSG_ERROR,
3494 "%s: err in send_and_recv_msgs, ret=%d",
3495 __func__, ret);
3496 return ret;
3497 }
3498
3499 return 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303500
3501fail:
3502 sigma_dut_print(dut, DUT_MSG_ERROR,
3503 "%s: err in adding vendor_cmd and vendor_data",
3504 __func__);
3505 nlmsg_free(msg);
Sunil Dutt44595082018-02-12 19:41:45 +05303506#endif /* NL80211_SUPPORT */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303507 return -1;
3508}
Sunil Dutt44595082018-02-12 19:41:45 +05303509
3510
Jouni Malinenf7222712019-06-13 01:50:21 +03003511static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3512 struct sigma_conn *conn,
3513 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003514{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303515#ifdef NL80211_SUPPORT
3516 const char *intf = get_param(cmd, "Interface");
3517#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003518 const char *ssid = get_param(cmd, "ssid");
3519 const char *wps_param = get_param(cmd, "WPS");
3520 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003521 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003522 const char *network_mode = get_param(cmd, "network_mode");
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303523 const char *ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003524 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003525 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003526 int e;
3527 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3528 struct wpa_ctrl *ctrl = NULL;
3529 int num_network_not_found = 0;
3530 int num_disconnected = 0;
3531 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003532
3533 if (ssid == NULL)
3534 return -1;
3535
Jouni Malinen37d5c692019-08-19 16:56:55 +03003536 dut->server_cert_tod = 0;
3537
Jouni Malinen3c367e82017-06-23 17:01:47 +03003538 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303539#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003540 if (get_driver_type(dut) == DRIVER_WCN) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303541 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Sunil Dutt44595082018-02-12 19:41:45 +05303542 dut->config_rsnie = 1;
3543 }
3544#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003545 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3546 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003547 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03003548 send_resp(dut, conn, SIGMA_ERROR,
3549 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3550 return 0;
3551 }
3552 }
3553
Jouni Malinen68143132017-09-02 02:34:08 +03003554 if (dut->sae_commit_override) {
3555 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3556 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003557 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03003558 send_resp(dut, conn, SIGMA_ERROR,
3559 "ErrorCode,Failed to set SAE commit override");
3560 return 0;
3561 }
3562 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303563#ifdef ANDROID
3564 if (dut->fils_hlp)
3565 process_fils_hlp(dut);
3566#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003567
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003568 if (wps_param &&
3569 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3570 wps = 1;
3571
Vamsi Krishnac1633d22020-05-06 18:31:21 +05303572 if (dut->ocvc &&
3573 set_network(get_station_ifname(dut), dut->infra_network_id,
3574 "ocv", "1") < 0)
3575 return ERROR_SEND_STATUS;
3576
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003577 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003578 if (dut->program == PROGRAM_60GHZ && network_mode &&
3579 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003580 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003581 "pbss", "1") < 0)
3582 return -2;
3583
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003584 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3585 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3586 "parameters not yet set");
3587 return 0;
3588 }
3589 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003590 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003591 return -2;
3592 } else {
3593 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3594 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003595 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003596 return -2;
3597 }
3598 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303599 if (strcmp(ssid, dut->infra_ssid) == 0) {
3600 sigma_dut_print(dut, DUT_MSG_DEBUG,
3601 "sta_associate for the most recently added network");
3602 } else if (find_network(dut, ssid) < 0) {
3603 sigma_dut_print(dut, DUT_MSG_DEBUG,
3604 "sta_associate for a previously stored network profile");
3605 send_resp(dut, conn, SIGMA_ERROR,
3606 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003607 return 0;
3608 }
3609
3610 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003611 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003612 "bssid", bssid) < 0) {
3613 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3614 "Invalid bssid argument");
3615 return 0;
3616 }
3617
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303618 if ((dut->program == PROGRAM_WPA3 &&
3619 dut->sta_associate_wait_connect) ||
3620 dut->program == PROGRAM_QM) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003621 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003622 if (!ctrl)
3623 return ERROR_SEND_STATUS;
3624 }
3625
Jouni Malinen46a19b62017-06-23 14:31:27 +03003626 extra[0] = '\0';
3627 if (chan)
3628 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003629 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003630 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3631 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003632 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003633 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3634 "network id %d on %s",
3635 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003636 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003637 ret = ERROR_SEND_STATUS;
3638 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003639 }
3640 }
3641
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003642 if (!ctrl)
3643 return SUCCESS_SEND_STATUS;
3644
3645 /* Wait for connection result to be able to store server certificate
3646 * hash for trust root override testing
3647 * (dev_exec_action,ServerCertTrust). */
3648
3649 for (e = 0; e < 20; e++) {
3650 const char *events[] = {
3651 "CTRL-EVENT-EAP-PEER-CERT",
3652 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3653 "CTRL-EVENT-DISCONNECTED",
3654 "CTRL-EVENT-CONNECTED",
3655 "CTRL-EVENT-NETWORK-NOT-FOUND",
3656 NULL
3657 };
3658 char buf[1024];
3659 int res;
3660
3661 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3662 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02003663 send_resp(dut, conn, SIGMA_COMPLETE,
3664 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003665 ret = STATUS_SENT_ERROR;
3666 break;
3667 }
3668 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3669 buf);
3670
3671 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3672 strstr(buf, " depth=0")) {
3673 char *pos = strstr(buf, " hash=");
3674
3675 if (pos) {
3676 char *end;
3677
Jouni Malinen34b19cb2019-08-16 16:37:17 +03003678 if (strstr(buf, " tod=1"))
3679 tod = 1;
3680 else if (strstr(buf, " tod=2"))
3681 tod = 2;
3682 else
3683 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003684 sigma_dut_print(dut, DUT_MSG_DEBUG,
3685 "Server certificate TOD policy: %d",
3686 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03003687 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003688
3689 pos += 6;
3690 end = strchr(pos, ' ');
3691 if (end)
3692 *end = '\0';
3693 strlcpy(dut->server_cert_hash, pos,
3694 sizeof(dut->server_cert_hash));
3695 sigma_dut_print(dut, DUT_MSG_DEBUG,
3696 "Server certificate hash: %s",
3697 dut->server_cert_hash);
3698 }
3699 }
3700
3701 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3702 send_resp(dut, conn, SIGMA_COMPLETE,
3703 "Result,TLS server certificate validation failed");
3704 ret = STATUS_SENT_ERROR;
3705 break;
3706 }
3707
3708 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3709 num_network_not_found++;
3710
3711 if (num_network_not_found > 2) {
3712 send_resp(dut, conn, SIGMA_COMPLETE,
3713 "Result,Network not found");
3714 ret = STATUS_SENT_ERROR;
3715 break;
3716 }
3717 }
3718
3719 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3720 num_disconnected++;
3721
3722 if (num_disconnected > 2) {
3723 send_resp(dut, conn, SIGMA_COMPLETE,
3724 "Result,Connection failed");
3725 ret = STATUS_SENT_ERROR;
3726 break;
3727 }
3728 }
3729
3730 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3731 if (tod >= 0) {
3732 sigma_dut_print(dut, DUT_MSG_DEBUG,
3733 "Network profile TOD policy update: %d -> %d",
3734 dut->sta_tod_policy, tod);
3735 dut->sta_tod_policy = tod;
3736 }
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303737 if (dut->program == PROGRAM_QM) {
3738 unsigned char iface_mac_addr[ETH_ALEN];
3739 char ipv6[100];
3740
3741 if (get_hwaddr(ifname, iface_mac_addr) < 0) {
3742 sigma_dut_print(dut, DUT_MSG_ERROR,
3743 "%s: get_hwaddr %s failed",
3744 __func__, ifname);
3745 ret = ERROR_SEND_STATUS;
3746 break;
3747 }
3748
3749 convert_mac_addr_to_ipv6_lladdr(iface_mac_addr,
3750 ipv6,
3751 sizeof(ipv6));
3752
3753 if (set_ipv6_addr(dut, ipv6, "64", ifname) !=
3754 0) {
3755 ret = ERROR_SEND_STATUS;
3756 break;
3757 }
3758 }
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003759 break;
3760 }
3761 }
3762done:
3763 if (ctrl) {
3764 wpa_ctrl_detach(ctrl);
3765 wpa_ctrl_close(ctrl);
3766 }
3767 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003768}
3769
3770
3771static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3772{
3773 char buf[500], cmd[200];
3774 int res;
3775
3776 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3777 * default path */
3778 res = snprintf(cmd, sizeof(cmd),
3779 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3780 file_exists("./hs20-osu-client") ?
3781 "./hs20-osu-client" : "hs20-osu-client",
3782 sigma_wpas_ctrl,
3783 dut->summary_log ? "-s " : "",
3784 dut->summary_log ? dut->summary_log : "");
3785 if (res < 0 || res >= (int) sizeof(cmd))
3786 return -1;
3787
3788 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3789 if (res < 0 || res >= (int) sizeof(buf))
3790 return -1;
3791 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3792
3793 if (system(buf) != 0) {
3794 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3795 return -1;
3796 }
3797 sigma_dut_print(dut, DUT_MSG_DEBUG,
3798 "Completed hs20-osu-client operation");
3799
3800 return 0;
3801}
3802
3803
3804static int download_ppsmo(struct sigma_dut *dut,
3805 struct sigma_conn *conn,
3806 const char *intf,
3807 struct sigma_cmd *cmd)
3808{
3809 const char *name, *path, *val;
3810 char url[500], buf[600], fbuf[100];
3811 char *fqdn = NULL;
3812
3813 name = get_param(cmd, "FileName");
3814 path = get_param(cmd, "FilePath");
3815 if (name == NULL || path == NULL)
3816 return -1;
3817
3818 if (strcasecmp(path, "VendorSpecific") == 0) {
3819 snprintf(url, sizeof(url), "PPS/%s", name);
3820 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3821 "from the device (%s)", url);
3822 if (!file_exists(url)) {
3823 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3824 "PPS MO file does not exist");
3825 return 0;
3826 }
3827 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3828 if (system(buf) != 0) {
3829 send_resp(dut, conn, SIGMA_ERROR,
3830 "errorCode,Failed to copy PPS MO");
3831 return 0;
3832 }
3833 } else if (strncasecmp(path, "http:", 5) != 0 &&
3834 strncasecmp(path, "https:", 6) != 0) {
3835 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3836 "Unsupported FilePath value");
3837 return 0;
3838 } else {
3839 snprintf(url, sizeof(url), "%s/%s", path, name);
3840 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3841 url);
3842 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3843 remove("pps-tnds.xml");
3844 if (system(buf) != 0) {
3845 send_resp(dut, conn, SIGMA_ERROR,
3846 "errorCode,Failed to download PPS MO");
3847 return 0;
3848 }
3849 }
3850
3851 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3852 send_resp(dut, conn, SIGMA_ERROR,
3853 "errorCode,Failed to parse downloaded PPSMO");
3854 return 0;
3855 }
3856 unlink("pps-tnds.xml");
3857
3858 val = get_param(cmd, "managementTreeURI");
3859 if (val) {
3860 const char *pos, *end;
3861 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3862 val);
3863 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3864 send_resp(dut, conn, SIGMA_ERROR,
3865 "errorCode,Invalid managementTreeURI prefix");
3866 return 0;
3867 }
3868 pos = val + 8;
3869 end = strchr(pos, '/');
3870 if (end == NULL ||
3871 strcmp(end, "/PerProviderSubscription") != 0) {
3872 send_resp(dut, conn, SIGMA_ERROR,
3873 "errorCode,Invalid managementTreeURI postfix");
3874 return 0;
3875 }
3876 if (end - pos >= (int) sizeof(fbuf)) {
3877 send_resp(dut, conn, SIGMA_ERROR,
3878 "errorCode,Too long FQDN in managementTreeURI");
3879 return 0;
3880 }
3881 memcpy(fbuf, pos, end - pos);
3882 fbuf[end - pos] = '\0';
3883 fqdn = fbuf;
3884 sigma_dut_print(dut, DUT_MSG_INFO,
3885 "FQDN from managementTreeURI: %s", fqdn);
3886 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3887 FILE *f = fopen("pps-fqdn", "r");
3888 if (f) {
3889 if (fgets(fbuf, sizeof(fbuf), f)) {
3890 fbuf[sizeof(fbuf) - 1] = '\0';
3891 fqdn = fbuf;
3892 sigma_dut_print(dut, DUT_MSG_DEBUG,
3893 "Use FQDN %s", fqdn);
3894 }
3895 fclose(f);
3896 }
3897 }
3898
3899 if (fqdn == NULL) {
3900 send_resp(dut, conn, SIGMA_ERROR,
3901 "errorCode,No FQDN specified");
3902 return 0;
3903 }
3904
3905 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3906 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3907 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3908
3909 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3910 if (rename("pps.xml", buf) < 0) {
3911 send_resp(dut, conn, SIGMA_ERROR,
3912 "errorCode,Could not move PPS MO");
3913 return 0;
3914 }
3915
3916 if (strcasecmp(path, "VendorSpecific") == 0) {
3917 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3918 fqdn);
3919 if (system(buf)) {
3920 send_resp(dut, conn, SIGMA_ERROR,
3921 "errorCode,Failed to copy OSU CA cert");
3922 return 0;
3923 }
3924
3925 snprintf(buf, sizeof(buf),
3926 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3927 fqdn);
3928 if (system(buf)) {
3929 send_resp(dut, conn, SIGMA_ERROR,
3930 "errorCode,Failed to copy AAA CA cert");
3931 return 0;
3932 }
3933 } else {
3934 snprintf(buf, sizeof(buf),
3935 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3936 fqdn, fqdn);
3937 if (run_hs20_osu(dut, buf) < 0) {
3938 send_resp(dut, conn, SIGMA_ERROR,
3939 "errorCode,Failed to download OSU CA cert");
3940 return 0;
3941 }
3942
3943 snprintf(buf, sizeof(buf),
3944 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3945 fqdn, fqdn);
3946 if (run_hs20_osu(dut, buf) < 0) {
3947 sigma_dut_print(dut, DUT_MSG_INFO,
3948 "Failed to download AAA CA cert");
3949 }
3950 }
3951
3952 if (file_exists("next-client-cert.pem")) {
3953 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3954 if (rename("next-client-cert.pem", buf) < 0) {
3955 send_resp(dut, conn, SIGMA_ERROR,
3956 "errorCode,Could not move client certificate");
3957 return 0;
3958 }
3959 }
3960
3961 if (file_exists("next-client-key.pem")) {
3962 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3963 if (rename("next-client-key.pem", buf) < 0) {
3964 send_resp(dut, conn, SIGMA_ERROR,
3965 "errorCode,Could not move client key");
3966 return 0;
3967 }
3968 }
3969
3970 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3971 if (run_hs20_osu(dut, buf) < 0) {
3972 send_resp(dut, conn, SIGMA_ERROR,
3973 "errorCode,Failed to configure credential from "
3974 "PPSMO");
3975 return 0;
3976 }
3977
3978 return 1;
3979}
3980
3981
3982static int download_cert(struct sigma_dut *dut,
3983 struct sigma_conn *conn,
3984 const char *intf,
3985 struct sigma_cmd *cmd)
3986{
3987 const char *name, *path;
3988 char url[500], buf[600];
3989
3990 name = get_param(cmd, "FileName");
3991 path = get_param(cmd, "FilePath");
3992 if (name == NULL || path == NULL)
3993 return -1;
3994
3995 if (strcasecmp(path, "VendorSpecific") == 0) {
3996 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
3997 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3998 "certificate from the device (%s)", url);
3999 if (!file_exists(url)) {
4000 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4001 "certificate file does not exist");
4002 return 0;
4003 }
4004 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
4005 if (system(buf) != 0) {
4006 send_resp(dut, conn, SIGMA_ERROR,
4007 "errorCode,Failed to copy client "
4008 "certificate");
4009 return 0;
4010 }
4011
4012 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
4013 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4014 "private key from the device (%s)", url);
4015 if (!file_exists(url)) {
4016 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4017 "private key file does not exist");
4018 return 0;
4019 }
4020 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
4021 if (system(buf) != 0) {
4022 send_resp(dut, conn, SIGMA_ERROR,
4023 "errorCode,Failed to copy client key");
4024 return 0;
4025 }
4026 } else if (strncasecmp(path, "http:", 5) != 0 &&
4027 strncasecmp(path, "https:", 6) != 0) {
4028 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4029 "Unsupported FilePath value");
4030 return 0;
4031 } else {
4032 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
4033 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
4034 "certificate/key from %s", url);
4035 snprintf(buf, sizeof(buf),
4036 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
4037 if (system(buf) != 0) {
4038 send_resp(dut, conn, SIGMA_ERROR,
4039 "errorCode,Failed to download client "
4040 "certificate");
4041 return 0;
4042 }
4043
4044 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
4045 {
4046 send_resp(dut, conn, SIGMA_ERROR,
4047 "errorCode,Failed to copy client key");
4048 return 0;
4049 }
4050 }
4051
4052 return 1;
4053}
4054
4055
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004056static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
4057 struct sigma_conn *conn,
4058 struct sigma_cmd *cmd)
4059{
4060 const char *val;
4061 const char *intf = get_param(cmd, "interface");
4062
4063 if (!intf)
4064 return -1;
4065
4066 val = get_param(cmd, "WscIEFragment");
4067 if (val && strcasecmp(val, "enable") == 0) {
4068 sigma_dut_print(dut, DUT_MSG_DEBUG,
4069 "Enable WSC IE fragmentation");
4070
4071 dut->wsc_fragment = 1;
4072 /* set long attributes to force fragmentation */
4073 if (wpa_command(intf, "SET device_name "
4074 WPS_LONG_DEVICE_NAME) < 0)
4075 return -2;
4076 if (wpa_command(intf, "SET manufacturer "
4077 WPS_LONG_MANUFACTURER) < 0)
4078 return -2;
4079 if (wpa_command(intf, "SET model_name "
4080 WPS_LONG_MODEL_NAME) < 0)
4081 return -2;
4082 if (wpa_command(intf, "SET model_number "
4083 WPS_LONG_MODEL_NUMBER) < 0)
4084 return -2;
4085 if (wpa_command(intf, "SET serial_number "
4086 WPS_LONG_SERIAL_NUMBER) < 0)
4087 return -2;
4088 }
4089
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02004090 val = get_param(cmd, "RSN_IE");
4091 if (val) {
4092 if (strcasecmp(val, "disable") == 0)
4093 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
4094 else if (strcasecmp(val, "enable") == 0)
4095 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
4096 }
4097
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004098 val = get_param(cmd, "WpsVersion");
4099 if (val)
4100 dut->wps_forced_version = get_wps_forced_version(dut, val);
4101
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004102 val = get_param(cmd, "WscEAPFragment");
4103 if (val && strcasecmp(val, "enable") == 0)
4104 dut->eap_fragment = 1;
4105
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004106 return 1;
4107}
4108
4109
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004110static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4111 struct sigma_conn *conn,
4112 const char *intf,
4113 struct sigma_cmd *cmd)
4114{
4115 const char *val;
4116
4117 val = get_param(cmd, "FileType");
4118 if (val && strcasecmp(val, "PPSMO") == 0)
4119 return download_ppsmo(dut, conn, intf, cmd);
4120 if (val && strcasecmp(val, "CERT") == 0)
4121 return download_cert(dut, conn, intf, cmd);
4122 if (val) {
4123 send_resp(dut, conn, SIGMA_ERROR,
4124 "ErrorCode,Unsupported FileType");
4125 return 0;
4126 }
4127
4128 return 1;
4129}
4130
4131
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304132static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4133 struct sigma_conn *conn,
4134 const char *intf,
4135 struct sigma_cmd *cmd)
4136{
4137 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304138 char buf[1000];
4139 char text[20];
4140 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304141
4142 val = get_param(cmd, "OCESupport");
4143 if (val && strcasecmp(val, "Disable") == 0) {
4144 if (wpa_command(intf, "SET oce 0") < 0) {
4145 send_resp(dut, conn, SIGMA_ERROR,
4146 "ErrorCode,Failed to disable OCE");
4147 return 0;
4148 }
4149 } else if (val && strcasecmp(val, "Enable") == 0) {
4150 if (wpa_command(intf, "SET oce 1") < 0) {
4151 send_resp(dut, conn, SIGMA_ERROR,
4152 "ErrorCode,Failed to enable OCE");
4153 return 0;
4154 }
4155 }
4156
vamsi krishnaa2799492017-12-05 14:28:01 +05304157 val = get_param(cmd, "FILScap");
4158 if (val && (atoi(val) == 1)) {
4159 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4160 send_resp(dut, conn, SIGMA_ERROR,
4161 "ErrorCode,Failed to enable FILS");
4162 return 0;
4163 }
4164 } else if (val && (atoi(val) == 0)) {
4165 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4166 send_resp(dut, conn, SIGMA_ERROR,
4167 "ErrorCode,Failed to disable FILS");
4168 return 0;
4169 }
4170 }
4171
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304172 val = get_param(cmd, "FILSHLP");
4173 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004174 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304175 sizeof(text)) < 0)
4176 return -2;
4177 hwaddr_aton(text, addr);
4178 snprintf(buf, sizeof(buf),
4179 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4180 "080045100140000040004011399e00000000ffffffff00440043"
4181 "012cb30001010600fd4f46410000000000000000000000000000"
4182 "000000000000"
4183 "%02x%02x%02x%02x%02x%02x"
4184 "0000000000000000000000000000000000000000000000000000"
4185 "0000000000000000000000000000000000000000000000000000"
4186 "0000000000000000000000000000000000000000000000000000"
4187 "0000000000000000000000000000000000000000000000000000"
4188 "0000000000000000000000000000000000000000000000000000"
4189 "0000000000000000000000000000000000000000000000000000"
4190 "0000000000000000000000000000000000000000000000000000"
4191 "0000000000000000000000000000000000000000638253633501"
4192 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4193 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4194 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4195 if (wpa_command(intf, buf)) {
4196 send_resp(dut, conn, SIGMA_ERROR,
4197 "ErrorCode,Failed to add HLP");
4198 return 0;
4199 }
4200 dut->fils_hlp = 1;
4201 }
4202
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304203 return 1;
4204}
4205
4206
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004207static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4208 const char *val)
4209{
4210 int counter = 0;
4211 char token[50];
4212 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304213 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004214
Peng Xub8fc5cc2017-05-10 17:27:28 -07004215 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004216 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304217 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004218 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004219 if (strcmp(result, "disable") == 0)
4220 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4221 else
4222 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304223 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004224 counter++;
4225 }
4226}
4227
4228
4229static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4230 const char *val)
4231{
4232 char buf[100];
4233
4234 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4235 if (system(buf) != 0) {
4236 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4237 }
4238}
4239
4240
4241static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4242 const char *val)
4243{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004244 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004245 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004246 }
4247}
4248
4249
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004250static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4251 const char *val)
4252{
4253#ifdef NL80211_SUPPORT
4254 struct nl_msg *msg;
4255 int ret = 0;
4256 struct nlattr *params;
4257 int ifindex;
4258 int wmmenable = 1;
4259
4260 if (val &&
4261 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4262 wmmenable = 0;
4263
4264 ifindex = if_nametoindex(intf);
4265 if (ifindex == 0) {
4266 sigma_dut_print(dut, DUT_MSG_ERROR,
4267 "%s: Index for interface %s failed",
4268 __func__, intf);
4269 return -1;
4270 }
4271
4272 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4273 NL80211_CMD_VENDOR)) ||
4274 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4275 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4276 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4277 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4278 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4279 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4280 wmmenable)) {
4281 sigma_dut_print(dut, DUT_MSG_ERROR,
4282 "%s: err in adding vendor_cmd and vendor_data",
4283 __func__);
4284 nlmsg_free(msg);
4285 return -1;
4286 }
4287 nla_nest_end(msg, params);
4288
4289 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4290 if (ret) {
4291 sigma_dut_print(dut, DUT_MSG_ERROR,
4292 "%s: err in send_and_recv_msgs, ret=%d",
4293 __func__, ret);
4294 }
4295 return ret;
4296#else /* NL80211_SUPPORT */
4297 sigma_dut_print(dut, DUT_MSG_ERROR,
4298 "WMM cannot be changed without NL80211_SUPPORT defined");
4299 return -1;
4300#endif /* NL80211_SUPPORT */
4301}
4302
4303
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004304static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4305 const char *val)
4306{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004307 int sgi20;
4308
4309 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4310
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004311 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004312}
4313
4314
4315static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4316 const char *val)
4317{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304318 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004319
4320 /* Disable Tx Beam forming when using a fixed rate */
4321 ath_disable_txbf(dut, intf);
4322
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304323 v = atoi(val);
4324 if (v < 0 || v > 32) {
4325 sigma_dut_print(dut, DUT_MSG_ERROR,
4326 "Invalid Fixed MCS rate: %d", v);
4327 return;
4328 }
4329 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004330
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004331 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004332
4333 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004334 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004335}
4336
4337
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004338static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4339 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004340{
4341 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304342 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004343
4344 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4345 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4346 else
4347 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4348
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304349 ret = system(buf);
4350#ifdef NL80211_SUPPORT
4351 if (ret) {
4352 int value = (strcasecmp(val, "Enable") == 0) ? 2 : 1;
4353
4354 ret = sta_config_params(dut, intf, STA_SET_TX_MSDU, value);
4355 ret |= sta_config_params(dut, intf, STA_SET_RX_MSDU, value);
4356 }
4357#endif /* NL80211_SUPPORT */
4358 if (ret)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004359 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4360}
4361
4362
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004363static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4364 int ampdu)
4365{
4366 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004367 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004368
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004369 if (ampdu)
4370 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004371 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4372 if (system(buf) != 0) {
4373 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4374 return -1;
4375 }
4376
4377 return 0;
4378}
4379
4380
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004381static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4382 const char *val)
4383{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004384 run_iwpriv(dut, intf, "tx_stbc %s", val);
4385 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004386}
4387
4388
4389static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4390 const char *val)
4391{
4392 char buf[60];
4393
Peng Xucc317ed2017-05-18 16:44:37 -07004394 if (strcmp(val, "160") == 0) {
4395 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4396 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004397 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4398 } else if (strcmp(val, "40") == 0) {
4399 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4400 } else if (strcmp(val, "20") == 0) {
4401 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4402 } else if (strcasecmp(val, "Auto") == 0) {
4403 buf[0] = '\0';
4404 } else {
4405 sigma_dut_print(dut, DUT_MSG_ERROR,
4406 "WIDTH/CTS_WIDTH value not supported");
4407 return -1;
4408 }
4409
4410 if (buf[0] != '\0' && system(buf) != 0) {
4411 sigma_dut_print(dut, DUT_MSG_ERROR,
4412 "Failed to set WIDTH/CTS_WIDTH");
4413 return -1;
4414 }
4415
4416 return 0;
4417}
4418
4419
4420int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4421 const char *intf, const char *val)
4422{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004423 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004424 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004425 dut->chwidth = 0;
4426 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004427 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004428 dut->chwidth = 0;
4429 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004430 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004431 dut->chwidth = 1;
4432 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004433 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004434 dut->chwidth = 2;
4435 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004436 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004437 dut->chwidth = 3;
4438 } else {
4439 send_resp(dut, conn, SIGMA_ERROR,
4440 "ErrorCode,WIDTH not supported");
4441 return -1;
4442 }
4443
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004444 return 0;
4445}
4446
4447
4448static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4449 const char *val)
4450{
4451 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004452 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004453
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004454 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004455 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004456 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004457 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004458 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004459 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004460 } else {
4461 sigma_dut_print(dut, DUT_MSG_ERROR,
4462 "SP_STREAM value not supported");
4463 return -1;
4464 }
4465
4466 if (system(buf) != 0) {
4467 sigma_dut_print(dut, DUT_MSG_ERROR,
4468 "Failed to set SP_STREAM");
4469 return -1;
4470 }
4471
Arif Hussainac6c5112018-05-25 17:34:00 -07004472 dut->sta_nss = sta_nss;
4473
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004474 return 0;
4475}
4476
4477
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304478static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4479 const char *val)
4480{
4481 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304482 int ret;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304483
4484 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304485 ret = system(buf);
4486#ifdef NL80211_SUPPORT
4487 if (ret)
4488 ret = sta_config_params(dut, intf, STA_SET_TX_STBC,
4489 strcmp(val, "0") == 0 ? 0 : 1);
4490#endif /* NL80211_SUPPORT */
4491 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304492 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4493
4494 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304495 ret = system(buf);
4496#ifdef NL80211_SUPPORT
4497 if (ret)
4498 ret = sta_config_params(dut, intf, STA_SET_RX_STBC,
4499 strcmp(val, "0") == 0 ? 0 : 1);
4500#endif /* NL80211_SUPPORT */
4501 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304502 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4503}
4504
4505
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304506static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4507 struct sigma_conn *conn,
4508 const char *intf, int capa)
4509{
4510 char buf[32];
4511
4512 if (capa > 0 && capa < 4) {
4513 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4514 if (wpa_command(intf, buf) < 0) {
4515 send_resp(dut, conn, SIGMA_ERROR,
4516 "ErrorCode, Failed to set cellular data capability");
4517 return 0;
4518 }
4519 return 1;
4520 }
4521
4522 sigma_dut_print(dut, DUT_MSG_ERROR,
4523 "Invalid Cellular data capability: %d", capa);
4524 send_resp(dut, conn, SIGMA_INVALID,
4525 "ErrorCode,Invalid cellular data capability");
4526 return 0;
4527}
4528
4529
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304530static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4531 const char *intf, const char *val)
4532{
4533 if (strcasecmp(val, "Disable") == 0) {
4534 if (wpa_command(intf, "SET roaming 0") < 0) {
4535 send_resp(dut, conn, SIGMA_ERROR,
4536 "ErrorCode,Failed to disable roaming");
4537 return 0;
4538 }
4539 return 1;
4540 }
4541
4542 if (strcasecmp(val, "Enable") == 0) {
4543 if (wpa_command(intf, "SET roaming 1") < 0) {
4544 send_resp(dut, conn, SIGMA_ERROR,
4545 "ErrorCode,Failed to enable roaming");
4546 return 0;
4547 }
4548 return 1;
4549 }
4550
4551 sigma_dut_print(dut, DUT_MSG_ERROR,
4552 "Invalid value provided for roaming: %s", val);
4553 send_resp(dut, conn, SIGMA_INVALID,
4554 "ErrorCode,Unknown value provided for Roaming");
4555 return 0;
4556}
4557
4558
Ashwini Patila75de5a2017-04-13 16:35:05 +05304559static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4560 struct sigma_conn *conn,
4561 const char *intf, const char *val)
4562{
4563 if (strcasecmp(val, "Disable") == 0) {
4564 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4565 send_resp(dut, conn, SIGMA_ERROR,
4566 "ErrorCode,Failed to disable Assoc_disallow");
4567 return 0;
4568 }
4569 return 1;
4570 }
4571
4572 if (strcasecmp(val, "Enable") == 0) {
4573 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4574 send_resp(dut, conn, SIGMA_ERROR,
4575 "ErrorCode,Failed to enable Assoc_disallow");
4576 return 0;
4577 }
4578 return 1;
4579 }
4580
4581 sigma_dut_print(dut, DUT_MSG_ERROR,
4582 "Invalid value provided for Assoc_disallow: %s", val);
4583 send_resp(dut, conn, SIGMA_INVALID,
4584 "ErrorCode,Unknown value provided for Assoc_disallow");
4585 return 0;
4586}
4587
4588
Ashwini Patilc63161e2017-04-13 16:30:23 +05304589static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4590 const char *intf, const char *val)
4591{
4592 if (strcasecmp(val, "Reject") == 0) {
4593 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4594 send_resp(dut, conn, SIGMA_ERROR,
4595 "ErrorCode,Failed to Reject BTM Request");
4596 return 0;
4597 }
4598 return 1;
4599 }
4600
4601 if (strcasecmp(val, "Accept") == 0) {
4602 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4603 send_resp(dut, conn, SIGMA_ERROR,
4604 "ErrorCode,Failed to Accept BTM Request");
4605 return 0;
4606 }
4607 return 1;
4608 }
4609
4610 sigma_dut_print(dut, DUT_MSG_ERROR,
4611 "Invalid value provided for BSS_Transition: %s", val);
4612 send_resp(dut, conn, SIGMA_INVALID,
4613 "ErrorCode,Unknown value provided for BSS_Transition");
4614 return 0;
4615}
4616
4617
Ashwini Patil00402582017-04-13 12:29:39 +05304618static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4619 struct sigma_conn *conn,
4620 const char *intf,
4621 struct sigma_cmd *cmd)
4622{
4623 const char *ch, *pref, *op_class, *reason;
4624 char buf[120];
4625 int len, ret;
4626
4627 pref = get_param(cmd, "Ch_Pref");
4628 if (!pref)
4629 return 1;
4630
4631 if (strcasecmp(pref, "clear") == 0) {
4632 free(dut->non_pref_ch_list);
4633 dut->non_pref_ch_list = NULL;
4634 } else {
4635 op_class = get_param(cmd, "Ch_Op_Class");
4636 if (!op_class) {
4637 send_resp(dut, conn, SIGMA_INVALID,
4638 "ErrorCode,Ch_Op_Class not provided");
4639 return 0;
4640 }
4641
4642 ch = get_param(cmd, "Ch_Pref_Num");
4643 if (!ch) {
4644 send_resp(dut, conn, SIGMA_INVALID,
4645 "ErrorCode,Ch_Pref_Num not provided");
4646 return 0;
4647 }
4648
4649 reason = get_param(cmd, "Ch_Reason_Code");
4650 if (!reason) {
4651 send_resp(dut, conn, SIGMA_INVALID,
4652 "ErrorCode,Ch_Reason_Code not provided");
4653 return 0;
4654 }
4655
4656 if (!dut->non_pref_ch_list) {
4657 dut->non_pref_ch_list =
4658 calloc(1, NON_PREF_CH_LIST_SIZE);
4659 if (!dut->non_pref_ch_list) {
4660 send_resp(dut, conn, SIGMA_ERROR,
4661 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4662 return 0;
4663 }
4664 }
4665 len = strlen(dut->non_pref_ch_list);
4666 ret = snprintf(dut->non_pref_ch_list + len,
4667 NON_PREF_CH_LIST_SIZE - len,
4668 " %s:%s:%s:%s", op_class, ch, pref, reason);
4669 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4670 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4671 dut->non_pref_ch_list);
4672 } else {
4673 sigma_dut_print(dut, DUT_MSG_ERROR,
4674 "snprintf failed for non_pref_list, ret = %d",
4675 ret);
4676 send_resp(dut, conn, SIGMA_ERROR,
4677 "ErrorCode,snprintf failed");
4678 free(dut->non_pref_ch_list);
4679 dut->non_pref_ch_list = NULL;
4680 return 0;
4681 }
4682 }
4683
4684 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4685 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4686 if (ret < 0 || ret >= (int) sizeof(buf)) {
4687 sigma_dut_print(dut, DUT_MSG_DEBUG,
4688 "snprintf failed for set non_pref_chan, ret: %d",
4689 ret);
4690 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4691 return 0;
4692 }
4693
4694 if (wpa_command(intf, buf) < 0) {
4695 send_resp(dut, conn, SIGMA_ERROR,
4696 "ErrorCode,Failed to set non-preferred channel list");
4697 return 0;
4698 }
4699
4700 return 1;
4701}
4702
4703
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004704#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004705
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004706static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4707 uint8_t cfg)
4708{
4709 struct nl_msg *msg;
4710 int ret = 0;
4711 struct nlattr *params;
4712 int ifindex;
4713
4714 ifindex = if_nametoindex(intf);
4715 if (ifindex == 0) {
4716 sigma_dut_print(dut, DUT_MSG_ERROR,
4717 "%s: Index for interface %s failed",
4718 __func__, intf);
4719 return -1;
4720 }
4721
4722 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4723 NL80211_CMD_VENDOR)) ||
4724 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4725 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4726 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4727 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4728 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4729 nla_put_u8(msg,
4730 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4731 cfg)) {
4732 sigma_dut_print(dut, DUT_MSG_ERROR,
4733 "%s: err in adding vendor_cmd and vendor_data",
4734 __func__);
4735 nlmsg_free(msg);
4736 return -1;
4737 }
4738 nla_nest_end(msg, params);
4739
4740 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4741 if (ret) {
4742 sigma_dut_print(dut, DUT_MSG_ERROR,
4743 "%s: err in send_and_recv_msgs, ret=%d",
4744 __func__, ret);
4745 }
4746 return ret;
4747}
4748
4749
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004750static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4751 enum he_fragmentation_val frag)
4752{
4753 struct nl_msg *msg;
4754 int ret = 0;
4755 struct nlattr *params;
4756 int ifindex;
4757
4758 ifindex = if_nametoindex(intf);
4759 if (ifindex == 0) {
4760 sigma_dut_print(dut, DUT_MSG_ERROR,
4761 "%s: Index for interface %s failed",
4762 __func__, intf);
4763 return -1;
4764 }
4765
4766 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4767 NL80211_CMD_VENDOR)) ||
4768 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4769 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4770 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4771 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4772 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4773 nla_put_u8(msg,
4774 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
4775 frag)) {
4776 sigma_dut_print(dut, DUT_MSG_ERROR,
4777 "%s: err in adding vendor_cmd and vendor_data",
4778 __func__);
4779 nlmsg_free(msg);
4780 return -1;
4781 }
4782 nla_nest_end(msg, params);
4783
4784 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4785 if (ret) {
4786 sigma_dut_print(dut, DUT_MSG_ERROR,
4787 "%s: err in send_and_recv_msgs, ret=%d",
4788 __func__, ret);
4789 }
4790 return ret;
4791}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004792
4793
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08004794int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
4795 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004796{
4797 struct nl_msg *msg;
4798 int ret = 0;
4799 struct nlattr *params;
4800 int ifindex;
4801
4802 ifindex = if_nametoindex(intf);
4803 if (ifindex == 0) {
4804 sigma_dut_print(dut, DUT_MSG_ERROR,
4805 "%s: Index for interface %s failed",
4806 __func__, intf);
4807 return -1;
4808 }
4809
4810 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4811 NL80211_CMD_VENDOR)) ||
4812 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4813 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4814 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4815 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4816 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4817 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
4818 ltf)) {
4819 sigma_dut_print(dut, DUT_MSG_ERROR,
4820 "%s: err in adding vendor_cmd and vendor_data",
4821 __func__);
4822 nlmsg_free(msg);
4823 return -1;
4824 }
4825 nla_nest_end(msg, params);
4826
4827 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4828 if (ret) {
4829 sigma_dut_print(dut, DUT_MSG_ERROR,
4830 "%s: err in send_and_recv_msgs, ret=%d",
4831 __func__, ret);
4832 }
4833 return ret;
4834}
4835
4836
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004837static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4838 int noack, enum qca_wlan_ac_type ac)
4839{
4840 struct nl_msg *msg;
4841 int ret = 0;
4842 struct nlattr *params;
4843 int ifindex;
4844
4845 ifindex = if_nametoindex(intf);
4846 if (ifindex == 0) {
4847 sigma_dut_print(dut, DUT_MSG_ERROR,
4848 "%s: Index for interface %s failed",
4849 __func__, intf);
4850 return -1;
4851 }
4852
4853 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4854 NL80211_CMD_VENDOR)) ||
4855 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4856 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4857 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4858 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4859 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4860 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4861 noack) ||
4862 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4863 ac)) {
4864 sigma_dut_print(dut, DUT_MSG_ERROR,
4865 "%s: err in adding vendor_cmd and vendor_data",
4866 __func__);
4867 nlmsg_free(msg);
4868 return -1;
4869 }
4870 nla_nest_end(msg, params);
4871
4872 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4873 if (ret) {
4874 sigma_dut_print(dut, DUT_MSG_ERROR,
4875 "%s: err in send_and_recv_msgs, ret=%d",
4876 __func__, ret);
4877 }
4878 return ret;
4879}
4880
4881
4882static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4883 const char *val)
4884{
4885 int noack, ret;
4886 char token[100];
4887 char *result;
4888 char *saveptr;
4889 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4890
4891 strlcpy(token, val, sizeof(token));
4892 token[sizeof(token) - 1] = '\0';
4893 result = strtok_r(token, ":", &saveptr);
4894 while (result) {
4895 noack = strcasecmp(result, "Disable") != 0;
4896 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4897 if (ret) {
4898 sigma_dut_print(dut, DUT_MSG_ERROR,
4899 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4900 ac, ret);
4901 }
4902 result = strtok_r(NULL, ":", &saveptr);
4903 ac++;
4904 }
4905}
4906
Vinita S. Maloo7462e812020-05-22 15:16:04 +05304907
4908static int nlvendor_sta_set_phymode(struct sigma_dut *dut, const char *intf,
4909 enum qca_wlan_vendor_phy_mode val)
4910{
4911 struct nl_msg *msg;
4912 struct nlattr *params;
4913 int ifindex, ret;
4914
4915 ifindex = if_nametoindex(intf);
4916 if (ifindex == 0) {
4917 sigma_dut_print(dut, DUT_MSG_ERROR,
4918 "%s: Index for interface %s not found",
4919 __func__, intf);
4920 return -1;
4921 }
4922
4923 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4924 NL80211_CMD_VENDOR);
4925 if (!msg) {
4926 sigma_dut_print(dut, DUT_MSG_ERROR,
4927 "%s: err in adding vendor_cmd", __func__);
4928 return -1;
4929 }
4930
4931 if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4932 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4933 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) {
4934 sigma_dut_print(dut, DUT_MSG_ERROR,
4935 "%s: err in adding vendor_attr", __func__);
4936 nlmsg_free(msg);
4937 return -1;
4938 }
4939
4940 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
4941 if (!params || nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_PHY_MODE,
4942 val)) {
4943 sigma_dut_print(dut, DUT_MSG_ERROR,
4944 "%s: err in adding vendor_data", __func__);
4945 nlmsg_free(msg);
4946 return -1;
4947 }
4948
4949 nla_nest_end(msg, params);
4950 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4951 if (ret) {
4952 sigma_dut_print(dut, DUT_MSG_ERROR,
4953 "%s: err in send_and_recv_msgs, ret=%d (%s)",
4954 __func__, ret, strerror(-ret));
4955 return ret;
4956 }
4957
4958 return 0;
4959}
4960
4961
4962static enum qca_wlan_vendor_phy_mode get_qca_vendor_phymode(const char *val)
4963{
4964 if (strcmp(val, "11a") == 0) {
4965 /* IEEE80211_MODE_11A */
4966 return QCA_WLAN_VENDOR_PHY_MODE_11A;
4967 }
4968
4969 if (strcmp(val, "11g") == 0) {
4970 /* IEEE80211_MODE_11G */
4971 return QCA_WLAN_VENDOR_PHY_MODE_11G;
4972 }
4973
4974 if (strcmp(val, "11b") == 0) {
4975 /* IEEE80211_MODE_11B */
4976 return QCA_WLAN_VENDOR_PHY_MODE_11B;
4977 }
4978
4979 if (strcmp(val, "11n") == 0 ||
4980 strcmp(val, "11nl") == 0 ||
4981 strcmp(val, "11nl(nabg)") == 0) {
4982 /* IEEE80211_MODE_11AGN */
4983 return QCA_WLAN_VENDOR_PHY_MODE_11AGN;
4984 }
4985
4986 if (strcmp(val, "11ng") == 0) {
4987 /* IEEE80211_MODE_11NG_HT40 */
4988 return QCA_WLAN_VENDOR_PHY_MODE_11NG_HT40;
4989 }
4990
4991 if (strcmp(val, "AC") == 0 ||
4992 strcasecmp(val, "11AC") == 0) {
4993 /* IEEE80211_MODE_11AC_VHT80 */
4994 return QCA_WLAN_VENDOR_PHY_MODE_11AC_VHT80;
4995 }
4996
4997 if (strcmp(val, "11na") == 0 ||
4998 strcasecmp(val, "11an") == 0) {
4999 /* IEEE80211_MODE_11NA_HT40 */
5000 return QCA_WLAN_VENDOR_PHY_MODE_11NA_HT40;
5001 }
5002
5003 if (strcmp(val, "11ax") == 0 ||
5004 strcmp(val, "auto") == 0) {
5005 /* IEEE80211_MODE_AUTO */
5006 return QCA_WLAN_VENDOR_PHY_MODE_AUTO;
5007 }
5008
5009 return -1;
5010}
5011
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005012#endif /* NL80211_SUPPORT */
5013
5014
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305015static int get_phymode(const char *val)
5016{
5017 if (strcmp(val, "11a") == 0)
5018 return 1; /* IEEE80211_MODE_11A */
5019 if (strcmp(val, "11g") == 0)
5020 return 3; /* IEEE80211_MODE_11G */
5021 if (strcmp(val, "11b") == 0)
5022 return 2; /* IEEE80211_MODE_11B */
5023 if (strcmp(val, "11n") == 0 ||
5024 strcmp(val, "11nl") == 0 ||
5025 strcmp(val, "11nl(nabg)") == 0)
5026 return 22; /* IEEE80211_MODE_11AGN */
5027 if (strcmp(val, "11ng") == 0)
5028 return 13; /* IEEE80211_MODE_11NG_HT40 */
5029 if (strcmp(val, "AC") == 0 ||
5030 strcasecmp(val, "11AC") == 0)
5031 return 19; /* IEEE80211_MODE_11AC_VHT80 */
5032 if (strcmp(val, "11na") == 0 ||
5033 strcasecmp(val, "11an") == 0)
5034 return 14; /* IEEE80211_MODE_11NA_HT40 */
5035 if (strcmp(val, "11ax") == 0 ||
5036 strcmp(val, "auto") == 0)
5037 return 0; /* IEEE80211_MODE_AUTO */
5038 return -1;
5039}
5040
5041
5042static void sta_set_phymode(struct sigma_dut *dut, const char *intf,
5043 const char *val)
5044{
5045 char buf[100];
5046 int len, phymode;
Vinita S. Maloo7462e812020-05-22 15:16:04 +05305047#ifdef NL80211_SUPPORT
5048 enum qca_wlan_vendor_phy_mode qca_phymode;
5049
5050 qca_phymode = get_qca_vendor_phymode(val);
5051 if (qca_phymode == -1) {
5052 sigma_dut_print(dut, DUT_MSG_DEBUG,
5053 "Ignoring mode change for mode: %s",
5054 val);
5055 return;
5056 }
5057
5058 if (nlvendor_sta_set_phymode(dut, intf, qca_phymode) == 0)
5059 return;
5060#endif /* NL80211_SUPPORT */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305061
5062 phymode = get_phymode(val);
5063 if (phymode == -1) {
5064 sigma_dut_print(dut, DUT_MSG_DEBUG,
5065 "Ignoring mode change for mode: %s",
5066 val);
5067 return;
5068 }
5069
5070 len = snprintf(buf, sizeof(buf), "iwpriv %s setphymode %d", intf,
5071 phymode);
5072 if (len < 0 || len >= sizeof(buf)) {
5073 sigma_dut_print(dut, DUT_MSG_ERROR,
5074 "Failed to set phymode");
5075 return;
5076 }
5077
5078 if (system(buf) != 0)
5079 sigma_dut_print(dut, DUT_MSG_ERROR,
5080 "iwpriv setting of phymode failed");
5081}
5082
5083
Jouni Malinenf7222712019-06-13 01:50:21 +03005084static enum sigma_cmd_result
5085cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
5086 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005087{
5088 const char *intf = get_param(cmd, "Interface");
5089 const char *val;
5090
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03005091 val = get_param(cmd, "FT_DS");
5092 if (val) {
5093 if (strcasecmp(val, "Enable") == 0) {
5094 dut->sta_ft_ds = 1;
5095 } else if (strcasecmp(val, "Disable") == 0) {
5096 dut->sta_ft_ds = 0;
5097 } else {
5098 send_resp(dut, conn, SIGMA_ERROR,
5099 "errorCode,Unsupported value for FT_DS");
5100 return STATUS_SENT_ERROR;
5101 }
5102 }
5103
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005104 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03005105 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
5106 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005107 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
5108 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005109
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005110 if (val && strcasecmp(val, "LOC") == 0)
5111 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02005112 if (val && strcasecmp(val, "60GHZ") == 0) {
5113 val = get_param(cmd, "WPS");
5114 if (val && strcasecmp(val, "disable") == 0) {
5115 dut->wps_disable = 1;
5116 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
5117 } else {
5118 /* wps_disable can have other value from the previous
5119 * test, so make sure it has the correct value.
5120 */
5121 dut->wps_disable = 0;
5122 }
5123
5124 val = get_param(cmd, "P2P");
5125 if (val && strcasecmp(val, "disable") == 0)
5126 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
5127 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005128
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02005129 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
5130 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
5131
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005132#ifdef ANDROID_NAN
5133 if (val && strcasecmp(val, "NAN") == 0)
5134 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
5135#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005136#ifdef MIRACAST
5137 if (val && (strcasecmp(val, "WFD") == 0 ||
5138 strcasecmp(val, "DisplayR2") == 0))
5139 return miracast_preset_testparameters(dut, conn, cmd);
5140#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005141
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07005142 if (val &&
5143 (strcasecmp(val, "MBO") == 0 || strcasecmp(val, "HE") == 0)) {
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305144 val = get_param(cmd, "Cellular_Data_Cap");
5145 if (val &&
5146 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
5147 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05305148
5149 val = get_param(cmd, "Ch_Pref");
5150 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
5151 return 0;
5152
Ashwini Patilc63161e2017-04-13 16:30:23 +05305153 val = get_param(cmd, "BSS_Transition");
5154 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
5155 return 0;
5156
Ashwini Patila75de5a2017-04-13 16:35:05 +05305157 val = get_param(cmd, "Assoc_Disallow");
5158 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
5159 return 0;
5160
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305161 val = get_param(cmd, "Roaming");
5162 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
5163 return 0;
5164
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305165 return 1;
5166 }
5167
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305168 if (val && strcasecmp(val, "OCE") == 0)
5169 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
5170
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005171#if 0
5172 val = get_param(cmd, "Supplicant");
5173 if (val && strcasecmp(val, "Default") != 0) {
5174 send_resp(dut, conn, SIGMA_ERROR,
5175 "ErrorCode,Only default(Vendor) supplicant "
5176 "supported");
5177 return 0;
5178 }
5179#endif
5180
5181 val = get_param(cmd, "RTS");
5182 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005183 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005184 case DRIVER_ATHEROS:
5185 ath_sta_set_rts(dut, intf, val);
5186 break;
5187 default:
5188#if 0
5189 send_resp(dut, conn, SIGMA_ERROR,
5190 "ErrorCode,Setting RTS not supported");
5191 return 0;
5192#else
5193 sigma_dut_print(dut, DUT_MSG_DEBUG,
5194 "Setting RTS not supported");
5195 break;
5196#endif
5197 }
5198 }
5199
5200#if 0
5201 val = get_param(cmd, "FRGMNT");
5202 if (val) {
5203 /* TODO */
5204 send_resp(dut, conn, SIGMA_ERROR,
5205 "ErrorCode,Setting FRGMNT not supported");
5206 return 0;
5207 }
5208#endif
5209
5210#if 0
5211 val = get_param(cmd, "Preamble");
5212 if (val) {
5213 /* TODO: Long/Short */
5214 send_resp(dut, conn, SIGMA_ERROR,
5215 "ErrorCode,Setting Preamble not supported");
5216 return 0;
5217 }
5218#endif
5219
5220 val = get_param(cmd, "Mode");
5221 if (val) {
5222 if (strcmp(val, "11b") == 0 ||
5223 strcmp(val, "11g") == 0 ||
5224 strcmp(val, "11a") == 0 ||
5225 strcmp(val, "11n") == 0 ||
5226 strcmp(val, "11ng") == 0 ||
5227 strcmp(val, "11nl") == 0 ||
5228 strcmp(val, "11nl(nabg)") == 0 ||
5229 strcmp(val, "AC") == 0 ||
5230 strcmp(val, "11AC") == 0 ||
5231 strcmp(val, "11ac") == 0 ||
5232 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08005233 strcmp(val, "11an") == 0 ||
5234 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005235 /* STA supports all modes by default */
5236 } else {
5237 send_resp(dut, conn, SIGMA_ERROR,
5238 "ErrorCode,Setting Mode not supported");
5239 return 0;
5240 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005241
5242 /* Change the mode only in case of testbed for HE program
5243 * and for 11a and 11g modes only. */
5244 if (dut->program == PROGRAM_HE &&
5245 dut->device_type == STA_testbed) {
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305246 sta_set_phymode(dut, intf, val);
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005247 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005248 }
5249
5250 val = get_param(cmd, "wmm");
5251 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005252 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005253 case DRIVER_ATHEROS:
5254 ath_sta_set_wmm(dut, intf, val);
5255 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005256 case DRIVER_WCN:
5257 wcn_sta_set_wmm(dut, intf, val);
5258 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005259 default:
5260 sigma_dut_print(dut, DUT_MSG_DEBUG,
5261 "Setting wmm not supported");
5262 break;
5263 }
5264 }
5265
5266 val = get_param(cmd, "Powersave");
5267 if (val) {
5268 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005269 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305270 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005271 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005272 }
5273
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005274 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005275 "P2P_SET ps 0") < 0)
5276 return -2;
5277 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005278 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5279 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005280 } else if (strcmp(val, "1") == 0 ||
5281 strcasecmp(val, "PSPoll") == 0 ||
5282 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005283 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305284 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005285 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005286 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005287 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005288 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005289 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005290 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005291 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005292 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005293 "P2P_SET ps 99") < 0)
5294 return -2;
5295 } else if (strcmp(val, "2") == 0 ||
5296 strcasecmp(val, "Fast") == 0) {
5297 /* TODO */
5298 send_resp(dut, conn, SIGMA_ERROR,
5299 "ErrorCode,Powersave=Fast not supported");
5300 return 0;
5301 } else if (strcmp(val, "3") == 0 ||
5302 strcasecmp(val, "PSNonPoll") == 0) {
5303 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005304 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5305 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005306
5307 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005308 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005309 "P2P_SET ps 1") < 0)
5310 return -2;
5311 } else
5312 return -1;
5313 }
5314
5315 val = get_param(cmd, "NoAck");
5316 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005317 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005318 case DRIVER_ATHEROS:
5319 ath_sta_set_noack(dut, intf, val);
5320 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005321#ifdef NL80211_SUPPORT
5322 case DRIVER_WCN:
5323 wcn_sta_set_noack(dut, intf, val);
5324 break;
5325#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005326 default:
5327 send_resp(dut, conn, SIGMA_ERROR,
5328 "ErrorCode,Setting NoAck not supported");
5329 return 0;
5330 }
5331 }
5332
5333 val = get_param(cmd, "IgnoreChswitchProhibit");
5334 if (val) {
5335 /* TODO: Enabled/disabled */
5336 if (strcasecmp(val, "Enabled") == 0) {
5337 send_resp(dut, conn, SIGMA_ERROR,
5338 "ErrorCode,Enabling IgnoreChswitchProhibit "
5339 "not supported");
5340 return 0;
5341 }
5342 }
5343
5344 val = get_param(cmd, "TDLS");
5345 if (val) {
5346 if (strcasecmp(val, "Disabled") == 0) {
5347 if (wpa_command(intf, "SET tdls_disabled 1")) {
5348 send_resp(dut, conn, SIGMA_ERROR,
5349 "ErrorCode,Failed to disable TDLS");
5350 return 0;
5351 }
5352 } else if (strcasecmp(val, "Enabled") == 0) {
5353 if (wpa_command(intf, "SET tdls_disabled 0")) {
5354 send_resp(dut, conn, SIGMA_ERROR,
5355 "ErrorCode,Failed to enable TDLS");
5356 return 0;
5357 }
5358 } else {
5359 send_resp(dut, conn, SIGMA_ERROR,
5360 "ErrorCode,Unsupported TDLS value");
5361 return 0;
5362 }
5363 }
5364
5365 val = get_param(cmd, "TDLSmode");
5366 if (val) {
5367 if (strcasecmp(val, "Default") == 0) {
5368 wpa_command(intf, "SET tdls_testing 0");
5369 } else if (strcasecmp(val, "APProhibit") == 0) {
5370 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5371 send_resp(dut, conn, SIGMA_ERROR,
5372 "ErrorCode,Failed to enable ignore "
5373 "APProhibit TDLS mode");
5374 return 0;
5375 }
5376 } else if (strcasecmp(val, "HiLoMac") == 0) {
5377 /* STA should respond with TDLS setup req for a TDLS
5378 * setup req */
5379 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5380 send_resp(dut, conn, SIGMA_ERROR,
5381 "ErrorCode,Failed to enable HiLoMac "
5382 "TDLS mode");
5383 return 0;
5384 }
5385 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5386 /*
5387 * Since all security modes are enabled by default when
5388 * Sigma control is used, there is no need to do
5389 * anything here.
5390 */
5391 } else if (strcasecmp(val, "ExistLink") == 0) {
5392 /*
5393 * Since we allow new TDLS Setup Request even if there
5394 * is an existing link, nothing needs to be done for
5395 * this.
5396 */
5397 } else {
5398 /* TODO:
5399 * ExistLink: STA should send TDLS setup req even if
5400 * direct link already exists
5401 */
5402 send_resp(dut, conn, SIGMA_ERROR,
5403 "ErrorCode,Unsupported TDLSmode value");
5404 return 0;
5405 }
5406 }
5407
5408 val = get_param(cmd, "FakePubKey");
5409 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5410 send_resp(dut, conn, SIGMA_ERROR,
5411 "ErrorCode,Failed to enable FakePubKey");
5412 return 0;
5413 }
5414
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005415#ifdef NL80211_SUPPORT
5416 val = get_param(cmd, "FrgmntSupport");
5417 if (val) {
5418 if (strcasecmp(val, "Enable") == 0) {
5419 if (sta_set_he_fragmentation(dut, intf,
5420 HE_FRAG_LEVEL1)) {
5421 send_resp(dut, conn, SIGMA_ERROR,
5422 "ErrorCode,Failed to enable HE Fragmentation");
5423 return 0;
5424 }
5425 } else if (strcasecmp(val, "Disable") == 0) {
5426 if (sta_set_he_fragmentation(dut, intf,
5427 HE_FRAG_DISABLE)) {
5428 send_resp(dut, conn, SIGMA_ERROR,
5429 "ErrorCode,Failed to disable HE Fragmentation");
5430 return 0;
5431 }
5432 }
5433 }
5434#endif /* NL80211_SUPPORT */
5435
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305436 val = get_param(cmd, "IncludeMSCSDescriptor");
5437 if (val && strcasecmp(val, "1") == 0) {
5438 char buf[128];
5439 int len;
5440
5441 len = snprintf(buf, sizeof(buf),
5442 "MSCS add up_bitmap=0xF0 up_limit=7 stream_timeout=60000 frame_classifier=045F%032x",
5443 0);
5444
5445 if (len < 0 || len >= sizeof(buf)) {
5446 sigma_dut_print(dut, DUT_MSG_ERROR,
5447 "Failed to build MSCS Descriptor IE");
5448 return ERROR_SEND_STATUS;
5449 }
5450
5451 if (wpa_command(intf, buf) != 0) {
5452 send_resp(dut, conn, SIGMA_ERROR,
5453 "ErrorCode,Failed to include MSCS descriptor");
5454 return STATUS_SENT_ERROR;
5455 }
5456 }
5457
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005458 return 1;
5459}
5460
5461
5462static const char * ath_get_radio_name(const char *radio_name)
5463{
5464 if (radio_name == NULL)
5465 return "wifi0";
5466 if (strcmp(radio_name, "wifi1") == 0)
5467 return "wifi1";
5468 if (strcmp(radio_name, "wifi2") == 0)
5469 return "wifi2";
5470 return "wifi0";
5471}
5472
5473
5474static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5475 const char *val)
5476{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005477 unsigned int vht_mcsmap = 0;
5478 int txchainmask = 0;
5479 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5480
5481 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5482 if (dut->testbed_flag_txsp == 1) {
5483 vht_mcsmap = 0xfffc;
5484 dut->testbed_flag_txsp = 0;
5485 } else {
5486 vht_mcsmap = 0xfffe;
5487 }
5488 txchainmask = 1;
5489 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5490 if (dut->testbed_flag_txsp == 1) {
5491 vht_mcsmap = 0xfff0;
5492 dut->testbed_flag_txsp = 0;
5493 } else {
5494 vht_mcsmap = 0xfffa;
5495 }
5496 txchainmask = 3;
5497 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5498 if (dut->testbed_flag_txsp == 1) {
5499 vht_mcsmap = 0xffc0;
5500 dut->testbed_flag_txsp = 0;
5501 } else {
5502 vht_mcsmap = 0xffea;
5503 }
5504 txchainmask = 7;
5505 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5506 if (dut->testbed_flag_txsp == 1) {
5507 vht_mcsmap = 0xff00;
5508 dut->testbed_flag_txsp = 0;
5509 } else {
5510 vht_mcsmap = 0xffaa;
5511 }
5512 txchainmask = 15;
5513 } else {
5514 if (dut->testbed_flag_txsp == 1) {
5515 vht_mcsmap = 0xffc0;
5516 dut->testbed_flag_txsp = 0;
5517 } else {
5518 vht_mcsmap = 0xffea;
5519 }
5520 }
5521
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005522 if (txchainmask)
5523 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005524
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005525 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005526}
5527
5528
5529static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5530 const char *val)
5531{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005532 unsigned int vht_mcsmap = 0;
5533 int rxchainmask = 0;
5534 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5535
5536 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5537 if (dut->testbed_flag_rxsp == 1) {
5538 vht_mcsmap = 0xfffc;
5539 dut->testbed_flag_rxsp = 0;
5540 } else {
5541 vht_mcsmap = 0xfffe;
5542 }
5543 rxchainmask = 1;
5544 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5545 if (dut->testbed_flag_rxsp == 1) {
5546 vht_mcsmap = 0xfff0;
5547 dut->testbed_flag_rxsp = 0;
5548 } else {
5549 vht_mcsmap = 0xfffa;
5550 }
5551 rxchainmask = 3;
5552 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5553 if (dut->testbed_flag_rxsp == 1) {
5554 vht_mcsmap = 0xffc0;
5555 dut->testbed_flag_rxsp = 0;
5556 } else {
5557 vht_mcsmap = 0xffea;
5558 }
5559 rxchainmask = 7;
5560 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5561 if (dut->testbed_flag_rxsp == 1) {
5562 vht_mcsmap = 0xff00;
5563 dut->testbed_flag_rxsp = 0;
5564 } else {
5565 vht_mcsmap = 0xffaa;
5566 }
5567 rxchainmask = 15;
5568 } else {
5569 if (dut->testbed_flag_rxsp == 1) {
5570 vht_mcsmap = 0xffc0;
5571 dut->testbed_flag_rxsp = 0;
5572 } else {
5573 vht_mcsmap = 0xffea;
5574 }
5575 }
5576
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005577 if (rxchainmask)
5578 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005579
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005580 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005581}
5582
5583
5584void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5585{
5586 if (strcasecmp(val, "enable") == 0) {
5587 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5588 != 0) {
5589 sigma_dut_print(dut, DUT_MSG_ERROR,
5590 "Disable BB_VHTSIGB_CRC_CALC failed");
5591 }
5592
5593 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5594 != 0) {
5595 sigma_dut_print(dut, DUT_MSG_ERROR,
5596 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5597 }
5598 } else {
5599 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5600 != 0) {
5601 sigma_dut_print(dut, DUT_MSG_ERROR,
5602 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5603 }
5604
5605 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5606 != 0) {
5607 sigma_dut_print(dut, DUT_MSG_ERROR,
5608 "Enable BB_VHTSIGB_CRC_CALC failed");
5609 }
5610 }
5611}
5612
5613
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005614static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5615 const char *val)
5616{
5617 char buf[60];
5618
5619 if (strcmp(val, "20") == 0) {
5620 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5621 dut->chwidth = 0;
5622 } else if (strcmp(val, "40") == 0) {
5623 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5624 dut->chwidth = 1;
5625 } else if (strcmp(val, "80") == 0) {
5626 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5627 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305628 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005629 buf[0] = '\0';
5630 } else {
5631 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5632 val);
5633 return -1;
5634 }
5635
5636 if (buf[0] != '\0' && system(buf) != 0) {
5637 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5638 return -1;
5639 }
5640
5641 return 0;
5642}
5643
5644
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005645static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5646 const char *intf, int addbareject)
5647{
5648#ifdef NL80211_SUPPORT
5649 struct nl_msg *msg;
5650 int ret = 0;
5651 struct nlattr *params;
5652 int ifindex;
5653
5654 ifindex = if_nametoindex(intf);
5655 if (ifindex == 0) {
5656 sigma_dut_print(dut, DUT_MSG_ERROR,
5657 "%s: Index for interface %s failed",
5658 __func__, intf);
5659 return -1;
5660 }
5661
5662 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5663 NL80211_CMD_VENDOR)) ||
5664 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5665 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5666 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5667 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5668 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5669 nla_put_u8(msg,
5670 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5671 !addbareject)) {
5672 sigma_dut_print(dut, DUT_MSG_ERROR,
5673 "%s: err in adding vendor_cmd and vendor_data",
5674 __func__);
5675 nlmsg_free(msg);
5676 return -1;
5677 }
5678 nla_nest_end(msg, params);
5679
5680 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5681 if (ret) {
5682 sigma_dut_print(dut, DUT_MSG_ERROR,
5683 "%s: err in send_and_recv_msgs, ret=%d",
5684 __func__, ret);
5685 }
5686 return ret;
5687#else /* NL80211_SUPPORT */
5688 sigma_dut_print(dut, DUT_MSG_ERROR,
5689 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5690 return -1;
5691#endif /* NL80211_SUPPORT */
5692}
5693
5694
5695static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5696 int addbareject)
5697{
5698 int ret;
5699
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005700 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005701 case DRIVER_WCN:
5702 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5703 if (ret) {
5704 sigma_dut_print(dut, DUT_MSG_ERROR,
5705 "nlvendor_sta_set_addba_reject failed, ret:%d",
5706 ret);
5707 return ret;
5708 }
5709 break;
5710 default:
5711 sigma_dut_print(dut, DUT_MSG_ERROR,
5712 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5713 ret = -1;
5714 break;
5715 }
5716
5717 return ret;
5718}
5719
5720
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005721static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5722 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005723{
5724#ifdef NL80211_SUPPORT
5725 struct nl_msg *msg;
5726 int ret = 0;
5727 struct nlattr *params;
5728 int ifindex;
5729
5730 ifindex = if_nametoindex(intf);
5731 if (ifindex == 0) {
5732 sigma_dut_print(dut, DUT_MSG_ERROR,
5733 "%s: Index for interface %s failed",
5734 __func__, intf);
5735 return -1;
5736 }
5737
5738 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5739 NL80211_CMD_VENDOR)) ||
5740 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5741 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5742 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5743 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5744 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5745 nla_put_u8(msg,
5746 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005747 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005748 sigma_dut_print(dut, DUT_MSG_ERROR,
5749 "%s: err in adding vendor_cmd and vendor_data",
5750 __func__);
5751 nlmsg_free(msg);
5752 return -1;
5753 }
5754 nla_nest_end(msg, params);
5755
5756 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5757 if (ret) {
5758 sigma_dut_print(dut, DUT_MSG_ERROR,
5759 "%s: err in send_and_recv_msgs, ret=%d",
5760 __func__, ret);
5761 }
5762 return ret;
5763#else /* NL80211_SUPPORT */
5764 sigma_dut_print(dut, DUT_MSG_ERROR,
5765 "Disable addba not possible without NL80211_SUPPORT defined");
5766 return -1;
5767#endif /* NL80211_SUPPORT */
5768}
5769
5770
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305771#ifdef NL80211_SUPPORT
5772static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5773{
5774 struct nl_msg *msg;
5775 int ret = 0;
5776 int ifindex;
5777
5778 ifindex = if_nametoindex(intf);
5779 if (ifindex == 0) {
5780 sigma_dut_print(dut, DUT_MSG_ERROR,
5781 "%s: Index for interface %s failed",
5782 __func__, intf);
5783 return -1;
5784 }
5785
5786 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5787 NL80211_CMD_SET_WIPHY)) ||
5788 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5789 sigma_dut_print(dut, DUT_MSG_ERROR,
5790 "%s: err in adding RTS threshold",
5791 __func__);
5792 nlmsg_free(msg);
5793 return -1;
5794 }
5795
5796 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5797 if (ret) {
5798 sigma_dut_print(dut, DUT_MSG_ERROR,
5799 "%s: err in send_and_recv_msgs, ret=%d",
5800 __func__, ret);
5801 }
5802 return ret;
5803}
5804#endif /* NL80211_SUPPORT */
5805
5806
5807static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5808{
5809 char buf[100];
5810
5811#ifdef NL80211_SUPPORT
5812 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5813 return 0;
5814 sigma_dut_print(dut, DUT_MSG_DEBUG,
5815 "Fall back to using iwconfig for setting RTS threshold");
5816#endif /* NL80211_SUPPORT */
5817
5818 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5819 if (system(buf) != 0) {
5820 sigma_dut_print(dut, DUT_MSG_ERROR,
5821 "Failed to set RTS threshold %d", val);
5822 return -1;
5823 }
5824 return 0;
5825}
5826
5827
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005828static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5829 struct sigma_conn *conn,
5830 struct sigma_cmd *cmd)
5831{
5832 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005833 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005834 char buf[128];
5835 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005836
5837 val = get_param(cmd, "40_INTOLERANT");
5838 if (val) {
5839 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5840 /* TODO: iwpriv ht40intol through wpa_supplicant */
5841 send_resp(dut, conn, SIGMA_ERROR,
5842 "ErrorCode,40_INTOLERANT not supported");
5843 return 0;
5844 }
5845 }
5846
5847 val = get_param(cmd, "ADDBA_REJECT");
5848 if (val) {
5849 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5850 /* reject any ADDBA with status "decline" */
5851 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005852 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005853 } else {
5854 /* accept ADDBA */
5855 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005856 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005857 }
5858 }
5859
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005860 if (addbareject >= 0 &&
5861 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5862 send_resp(dut, conn, SIGMA_ERROR,
5863 "ErrorCode,set addba_reject failed");
5864 return 0;
5865 }
5866
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005867 val = get_param(cmd, "AMPDU");
5868 if (val) {
5869 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5870 /* enable AMPDU Aggregation */
5871 if (ampdu == 0) {
5872 send_resp(dut, conn, SIGMA_ERROR,
5873 "ErrorCode,Mismatch in "
5874 "addba_reject/ampdu - "
5875 "not supported");
5876 return 0;
5877 }
5878 ampdu = 1;
5879 } else {
5880 /* disable AMPDU Aggregation */
5881 if (ampdu == 1) {
5882 send_resp(dut, conn, SIGMA_ERROR,
5883 "ErrorCode,Mismatch in "
5884 "addba_reject/ampdu - "
5885 "not supported");
5886 return 0;
5887 }
5888 ampdu = 0;
5889 }
5890 }
5891
5892 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005893 int ret;
5894
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005895 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5896 ampdu ? "Enabling" : "Disabling");
5897 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005898 if (wpa_command(intf, buf) < 0 &&
5899 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005900 send_resp(dut, conn, SIGMA_ERROR,
5901 "ErrorCode,set aggr failed");
5902 return 0;
5903 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005904
5905 if (ampdu == 0) {
5906 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005907 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005908 if (ret) {
5909 sigma_dut_print(dut, DUT_MSG_ERROR,
5910 "Failed to disable addba, ret:%d",
5911 ret);
5912 }
5913 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005914 }
5915
5916 val = get_param(cmd, "AMSDU");
5917 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005918 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005919 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005920 case DRIVER_WCN:
5921 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005922 break;
5923 default:
5924 if (strcmp(val, "1") == 0 ||
5925 strcasecmp(val, "Enable") == 0) {
5926 /* Enable AMSDU Aggregation */
5927 send_resp(dut, conn, SIGMA_ERROR,
5928 "ErrorCode,AMSDU aggregation not supported");
5929 return 0;
5930 }
5931 break;
5932 }
5933 }
5934
5935 val = get_param(cmd, "STBC_RX");
5936 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005937 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005938 case DRIVER_ATHEROS:
5939 ath_sta_set_stbc(dut, intf, val);
5940 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305941 case DRIVER_WCN:
5942 wcn_sta_set_stbc(dut, intf, val);
5943 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005944 default:
5945 send_resp(dut, conn, SIGMA_ERROR,
5946 "ErrorCode,STBC_RX not supported");
5947 return 0;
5948 }
5949 }
5950
5951 val = get_param(cmd, "WIDTH");
5952 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005953 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005954 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005955 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005956 send_resp(dut, conn, SIGMA_ERROR,
5957 "ErrorCode,Failed to set WIDTH");
5958 return 0;
5959 }
5960 break;
5961 case DRIVER_ATHEROS:
5962 if (ath_set_width(dut, conn, intf, val) < 0)
5963 return 0;
5964 break;
5965 default:
5966 sigma_dut_print(dut, DUT_MSG_ERROR,
5967 "Setting WIDTH not supported");
5968 break;
5969 }
5970 }
5971
5972 val = get_param(cmd, "SMPS");
5973 if (val) {
5974 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5975 send_resp(dut, conn, SIGMA_ERROR,
5976 "ErrorCode,SMPS not supported");
5977 return 0;
5978 }
5979
5980 val = get_param(cmd, "TXSP_STREAM");
5981 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005982 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005983 case DRIVER_WCN:
5984 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5985 send_resp(dut, conn, SIGMA_ERROR,
5986 "ErrorCode,Failed to set TXSP_STREAM");
5987 return 0;
5988 }
5989 break;
5990 case DRIVER_ATHEROS:
5991 ath_sta_set_txsp_stream(dut, intf, val);
5992 break;
5993 default:
5994 sigma_dut_print(dut, DUT_MSG_ERROR,
5995 "Setting TXSP_STREAM not supported");
5996 break;
5997 }
5998 }
5999
6000 val = get_param(cmd, "RXSP_STREAM");
6001 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006002 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006003 case DRIVER_WCN:
6004 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
6005 send_resp(dut, conn, SIGMA_ERROR,
6006 "ErrorCode,Failed to set RXSP_STREAM");
6007 return 0;
6008 }
6009 break;
6010 case DRIVER_ATHEROS:
6011 ath_sta_set_rxsp_stream(dut, intf, val);
6012 break;
6013 default:
6014 sigma_dut_print(dut, DUT_MSG_ERROR,
6015 "Setting RXSP_STREAM not supported");
6016 break;
6017 }
6018 }
6019
6020 val = get_param(cmd, "DYN_BW_SGNL");
6021 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006022 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006023 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08006024 if (strcasecmp(val, "enable") == 0) {
6025 snprintf(buf, sizeof(buf),
6026 "iwpriv %s cwmenable 1", intf);
6027 if (system(buf) != 0) {
6028 sigma_dut_print(dut, DUT_MSG_ERROR,
6029 "iwpriv cwmenable 1 failed");
6030 return 0;
6031 }
6032 } else if (strcasecmp(val, "disable") == 0) {
6033 snprintf(buf, sizeof(buf),
6034 "iwpriv %s cwmenable 0", intf);
6035 if (system(buf) != 0) {
6036 sigma_dut_print(dut, DUT_MSG_ERROR,
6037 "iwpriv cwmenable 0 failed");
6038 return 0;
6039 }
6040 } else {
6041 sigma_dut_print(dut, DUT_MSG_ERROR,
6042 "Unsupported DYN_BW_SGL");
6043 }
6044
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006045 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
6046 if (system(buf) != 0) {
6047 sigma_dut_print(dut, DUT_MSG_ERROR,
6048 "Failed to set cts_cbw in DYN_BW_SGNL");
6049 return 0;
6050 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006051 break;
6052 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006053 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006054 ath_config_dyn_bw_sig(dut, intf, val);
6055 break;
6056 default:
6057 sigma_dut_print(dut, DUT_MSG_ERROR,
6058 "Failed to set DYN_BW_SGNL");
6059 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006060 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006061 }
6062
6063 val = get_param(cmd, "RTS_FORCE");
6064 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006065 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006066 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306067 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006068 sigma_dut_print(dut, DUT_MSG_ERROR,
6069 "Failed to set RTS_FORCE 64");
6070 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03006071 res = snprintf(buf, sizeof(buf),
6072 "wifitool %s beeliner_fw_test 100 1",
6073 intf);
6074 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08006075 sigma_dut_print(dut, DUT_MSG_ERROR,
6076 "wifitool beeliner_fw_test 100 1 failed");
6077 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006078 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306079 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006080 sigma_dut_print(dut, DUT_MSG_ERROR,
6081 "Failed to set RTS_FORCE 2347");
6082 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006083 } else {
6084 send_resp(dut, conn, SIGMA_ERROR,
6085 "ErrorCode,RTS_FORCE value not supported");
6086 return 0;
6087 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006088 }
6089
6090 val = get_param(cmd, "CTS_WIDTH");
6091 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006092 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006093 case DRIVER_WCN:
6094 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
6095 send_resp(dut, conn, SIGMA_ERROR,
6096 "ErrorCode,Failed to set CTS_WIDTH");
6097 return 0;
6098 }
6099 break;
6100 case DRIVER_ATHEROS:
6101 ath_set_cts_width(dut, intf, val);
6102 break;
6103 default:
6104 sigma_dut_print(dut, DUT_MSG_ERROR,
6105 "Setting CTS_WIDTH not supported");
6106 break;
6107 }
6108 }
6109
6110 val = get_param(cmd, "BW_SGNL");
6111 if (val) {
6112 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006113 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006114 } else if (strcasecmp(val, "Disable") == 0) {
6115 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006116 } else {
6117 send_resp(dut, conn, SIGMA_ERROR,
6118 "ErrorCode,BW_SGNL value not supported");
6119 return 0;
6120 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006121 }
6122
6123 val = get_param(cmd, "Band");
6124 if (val) {
6125 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
6126 /* STA supports all bands by default */
6127 } else {
6128 send_resp(dut, conn, SIGMA_ERROR,
6129 "ErrorCode,Unsupported Band");
6130 return 0;
6131 }
6132 }
6133
6134 val = get_param(cmd, "zero_crc");
6135 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006136 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006137 case DRIVER_ATHEROS:
6138 ath_set_zero_crc(dut, val);
6139 break;
6140 default:
6141 break;
6142 }
6143 }
6144
6145 return 1;
6146}
6147
6148
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006149static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
6150{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006151 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006152#ifdef __linux__
6153 case DRIVER_WIL6210:
6154 return wil6210_set_force_mcs(dut, force, mcs);
6155#endif /* __linux__ */
6156 default:
6157 sigma_dut_print(dut, DUT_MSG_ERROR,
6158 "Unsupported sta_set_force_mcs with the current driver");
6159 return -1;
6160 }
6161}
6162
6163
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006164static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
6165{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006166 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006167#ifdef __linux__
6168 case DRIVER_WIL6210:
6169 return wil6210_force_rsn_ie(dut, state);
6170#endif /* __linux__ */
6171 default:
6172 sigma_dut_print(dut, DUT_MSG_ERROR,
6173 "Unsupported sta_60g_force_rsn_ie with the current driver");
6174 return -1;
6175 }
6176}
6177
6178
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006179static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
6180 struct sigma_cmd *cmd)
6181{
6182 const char *val;
6183 char buf[100];
6184
6185 val = get_param(cmd, "MSDUSize");
6186 if (val) {
6187 int mtu;
6188
6189 dut->amsdu_size = atoi(val);
6190 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
6191 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
6192 sigma_dut_print(dut, DUT_MSG_ERROR,
6193 "MSDUSize %d is above max %d or below min %d",
6194 dut->amsdu_size,
6195 IEEE80211_MAX_DATA_LEN_DMG,
6196 IEEE80211_SNAP_LEN_DMG);
6197 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006198 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006199 }
6200
6201 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
6202 sigma_dut_print(dut, DUT_MSG_DEBUG,
6203 "Setting amsdu_size to %d", mtu);
6204 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006205 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006206
6207 if (system(buf) != 0) {
6208 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
6209 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006210 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006211 }
6212 }
6213
6214 val = get_param(cmd, "BAckRcvBuf");
6215 if (val) {
6216 dut->back_rcv_buf = atoi(val);
6217 if (dut->back_rcv_buf == 0) {
6218 sigma_dut_print(dut, DUT_MSG_ERROR,
6219 "Failed to convert %s or value is 0",
6220 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006221 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006222 }
6223
6224 sigma_dut_print(dut, DUT_MSG_DEBUG,
6225 "Setting BAckRcvBuf to %s", val);
6226 }
6227
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006228 val = get_param(cmd, "MCS_FixedRate");
6229 if (val) {
6230 if (sta_set_force_mcs(dut, 1, atoi(val))) {
6231 sigma_dut_print(dut, DUT_MSG_ERROR,
6232 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006233 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006234 }
6235 }
6236
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006237 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006238}
6239
6240
6241static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
6242 struct sigma_cmd *cmd)
6243{
6244 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006245 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006246 const char *val;
6247 char buf[100];
6248
6249 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006250 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006251 if (wpa_command(ifname, "PING") != 0) {
6252 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006253 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006254 }
6255
6256 wpa_command(ifname, "FLUSH");
6257 net_id = add_network_common(dut, conn, ifname, cmd);
6258 if (net_id < 0) {
6259 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
6260 return net_id;
6261 }
6262
6263 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
6264 if (set_network(ifname, net_id, "mode", "2") < 0) {
6265 sigma_dut_print(dut, DUT_MSG_ERROR,
6266 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006267 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006268 }
6269
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006270 if (set_network(ifname, net_id, "pbss", "1") < 0)
6271 return -2;
6272
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006273 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006274 "Supplicant set network with mode 2. network_id %d",
6275 net_id);
6276
6277 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6278 sigma_dut_print(dut, DUT_MSG_INFO,
6279 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006280 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006281 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006282
6283 val = get_param(cmd, "Security");
6284 if (val && strcasecmp(val, "OPEN") == 0) {
6285 dut->ap_key_mgmt = AP_OPEN;
6286 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6287 sigma_dut_print(dut, DUT_MSG_ERROR,
6288 "Failed to set supplicant to %s security",
6289 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006290 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006291 }
6292 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6293 dut->ap_key_mgmt = AP_WPA2_PSK;
6294 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6295 sigma_dut_print(dut, DUT_MSG_ERROR,
6296 "Failed to set supplicant to %s security",
6297 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006298 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006299 }
6300
6301 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6302 sigma_dut_print(dut, DUT_MSG_ERROR,
6303 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006304 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006305 }
6306 } else if (val) {
6307 sigma_dut_print(dut, DUT_MSG_ERROR,
6308 "Requested Security %s is not supported on 60GHz",
6309 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006310 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006311 }
6312
6313 val = get_param(cmd, "Encrypt");
6314 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6315 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6316 sigma_dut_print(dut, DUT_MSG_ERROR,
6317 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006318 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006319 }
6320 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6321 sigma_dut_print(dut, DUT_MSG_ERROR,
6322 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006323 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006324 }
6325 } else if (val) {
6326 sigma_dut_print(dut, DUT_MSG_ERROR,
6327 "Requested Encrypt %s is not supported on 60 GHz",
6328 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006329 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006330 }
6331
6332 val = get_param(cmd, "PSK");
6333 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6334 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6335 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006336 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006337 }
6338
6339 /* Convert 60G channel to freq */
6340 switch (dut->ap_channel) {
6341 case 1:
6342 val = "58320";
6343 break;
6344 case 2:
6345 val = "60480";
6346 break;
6347 case 3:
6348 val = "62640";
6349 break;
6350 default:
6351 sigma_dut_print(dut, DUT_MSG_ERROR,
6352 "Failed to configure channel %d. Not supported",
6353 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006354 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006355 }
6356
6357 if (set_network(ifname, net_id, "frequency", val) < 0) {
6358 sigma_dut_print(dut, DUT_MSG_ERROR,
6359 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006360 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006361 }
6362
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006363 if (dut->eap_fragment) {
6364 sigma_dut_print(dut, DUT_MSG_DEBUG,
6365 "Set EAP fragment size to 128 bytes.");
6366 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6367 return ERROR_SEND_STATUS;
6368 }
6369
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006370 sigma_dut_print(dut, DUT_MSG_DEBUG,
6371 "Supplicant set network with frequency");
6372
6373 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6374 if (wpa_command(ifname, buf) < 0) {
6375 sigma_dut_print(dut, DUT_MSG_INFO,
6376 "Failed to select network id %d on %s",
6377 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006378 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006379 }
6380
6381 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6382
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006383 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006384}
6385
6386
Lior David67543f52017-01-03 19:04:22 +02006387static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6388{
6389 char buf[128], fname[128];
6390 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006391 int res;
Lior David67543f52017-01-03 19:04:22 +02006392
6393 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6394 sigma_dut_print(dut, DUT_MSG_ERROR,
6395 "failed to get wil6210 debugfs dir");
6396 return -1;
6397 }
6398
Jouni Malinen3aa72862019-05-29 23:14:51 +03006399 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6400 if (res < 0 || res >= sizeof(fname))
6401 return -1;
Lior David67543f52017-01-03 19:04:22 +02006402 f = fopen(fname, "w");
6403 if (!f) {
6404 sigma_dut_print(dut, DUT_MSG_ERROR,
6405 "failed to open: %s", fname);
6406 return -1;
6407 }
6408
6409 fprintf(f, "%d\n", abft_len);
6410 fclose(f);
6411
6412 return 0;
6413}
6414
6415
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006416int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6417 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006418{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006419 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006420 case DRIVER_WIL6210:
6421 return wil6210_set_abft_len(dut, abft_len);
6422 default:
6423 sigma_dut_print(dut, DUT_MSG_ERROR,
6424 "set abft_len not supported");
6425 return -1;
6426 }
6427}
6428
6429
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006430static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6431 struct sigma_cmd *cmd)
6432{
6433 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006434 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006435
6436 if (dut->dev_role != DEVROLE_PCP) {
6437 send_resp(dut, conn, SIGMA_INVALID,
6438 "ErrorCode,Invalid DevRole");
6439 return 0;
6440 }
6441
6442 val = get_param(cmd, "SSID");
6443 if (val) {
6444 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6445 send_resp(dut, conn, SIGMA_INVALID,
6446 "ErrorCode,Invalid SSID");
6447 return -1;
6448 }
6449
Peng Xub8fc5cc2017-05-10 17:27:28 -07006450 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006451 }
6452
6453 val = get_param(cmd, "CHANNEL");
6454 if (val) {
6455 const char *pos;
6456
6457 dut->ap_channel = atoi(val);
6458 pos = strchr(val, ';');
6459 if (pos) {
6460 pos++;
6461 dut->ap_channel_1 = atoi(pos);
6462 }
6463 }
6464
6465 switch (dut->ap_channel) {
6466 case 1:
6467 case 2:
6468 case 3:
6469 break;
6470 default:
6471 sigma_dut_print(dut, DUT_MSG_ERROR,
6472 "Channel %d is not supported", dut->ap_channel);
6473 send_resp(dut, conn, SIGMA_ERROR,
6474 "Requested channel is not supported");
6475 return -1;
6476 }
6477
6478 val = get_param(cmd, "BCNINT");
6479 if (val)
6480 dut->ap_bcnint = atoi(val);
6481
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006482 val = get_param(cmd, "AllocType");
6483 if (val) {
6484 send_resp(dut, conn, SIGMA_ERROR,
6485 "ErrorCode,AllocType is not supported yet");
6486 return -1;
6487 }
6488
6489 val = get_param(cmd, "PercentBI");
6490 if (val) {
6491 send_resp(dut, conn, SIGMA_ERROR,
6492 "ErrorCode,PercentBI is not supported yet");
6493 return -1;
6494 }
6495
6496 val = get_param(cmd, "CBAPOnly");
6497 if (val) {
6498 send_resp(dut, conn, SIGMA_ERROR,
6499 "ErrorCode,CBAPOnly is not supported yet");
6500 return -1;
6501 }
6502
6503 val = get_param(cmd, "AMPDU");
6504 if (val) {
6505 if (strcasecmp(val, "Enable") == 0)
6506 dut->ap_ampdu = 1;
6507 else if (strcasecmp(val, "Disable") == 0)
6508 dut->ap_ampdu = 2;
6509 else {
6510 send_resp(dut, conn, SIGMA_ERROR,
6511 "ErrorCode,AMPDU value is not Enable nor Disabled");
6512 return -1;
6513 }
6514 }
6515
6516 val = get_param(cmd, "AMSDU");
6517 if (val) {
6518 if (strcasecmp(val, "Enable") == 0)
6519 dut->ap_amsdu = 1;
6520 else if (strcasecmp(val, "Disable") == 0)
6521 dut->ap_amsdu = 2;
6522 }
6523
6524 val = get_param(cmd, "NumMSDU");
6525 if (val) {
6526 send_resp(dut, conn, SIGMA_ERROR,
6527 "ErrorCode, NumMSDU is not supported yet");
6528 return -1;
6529 }
6530
6531 val = get_param(cmd, "ABFTLRang");
6532 if (val) {
6533 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006534 "ABFTLRang parameter %s", val);
6535 if (strcmp(val, "Gt1") == 0)
6536 abft_len = 2; /* 2 slots in this case */
6537 }
6538
6539 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6540 send_resp(dut, conn, SIGMA_ERROR,
6541 "ErrorCode, Can't set ABFT length");
6542 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006543 }
6544
6545 if (sta_pcp_start(dut, conn, cmd) < 0) {
6546 send_resp(dut, conn, SIGMA_ERROR,
6547 "ErrorCode, Can't start PCP role");
6548 return -1;
6549 }
6550
6551 return sta_set_60g_common(dut, conn, cmd);
6552}
6553
6554
6555static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6556 struct sigma_cmd *cmd)
6557{
6558 const char *val = get_param(cmd, "DiscoveryMode");
6559
6560 if (dut->dev_role != DEVROLE_STA) {
6561 send_resp(dut, conn, SIGMA_INVALID,
6562 "ErrorCode,Invalid DevRole");
6563 return 0;
6564 }
6565
6566 if (val) {
6567 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6568 /* Ignore Discovery mode till Driver expose API. */
6569#if 0
6570 if (strcasecmp(val, "1") == 0) {
6571 send_resp(dut, conn, SIGMA_INVALID,
6572 "ErrorCode,DiscoveryMode 1 not supported");
6573 return 0;
6574 }
6575
6576 if (strcasecmp(val, "0") == 0) {
6577 /* OK */
6578 } else {
6579 send_resp(dut, conn, SIGMA_INVALID,
6580 "ErrorCode,DiscoveryMode not supported");
6581 return 0;
6582 }
6583#endif
6584 }
6585
6586 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006587 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006588 return sta_set_60g_common(dut, conn, cmd);
6589}
6590
6591
Jouni Malinenf7222712019-06-13 01:50:21 +03006592static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6593 struct sigma_conn *conn,
6594 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006595{
6596 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006597 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306598
Jouni Malinened77e672018-01-10 16:45:13 +02006599 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006600 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006601 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306602 wpa_command(intf, "DISCONNECT");
6603 return 1;
6604 }
6605
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006606 disconnect_station(dut);
6607 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6608 * due to cached results. */
6609 wpa_command(intf, "SET ignore_old_scan_res 1");
6610 wpa_command(intf, "BSS_FLUSH");
6611 return 1;
6612}
6613
6614
Jouni Malinenf7222712019-06-13 01:50:21 +03006615static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6616 struct sigma_conn *conn,
6617 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006618{
6619 const char *intf = get_param(cmd, "Interface");
6620 const char *bssid = get_param(cmd, "bssid");
6621 const char *val = get_param(cmd, "CHANNEL");
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006622 const char *freq_val = get_param(cmd, "ChnlFreq");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006623 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306624 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306625 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006626 int res;
6627 int chan = 0;
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006628 int freq = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006629 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306630 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006631 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006632
6633 if (bssid == NULL) {
6634 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6635 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006636 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006637 }
6638
6639 if (val)
6640 chan = atoi(val);
6641
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006642 if (freq_val)
6643 freq = atoi(freq_val);
6644
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006645 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6646 /* The current network may be from sta_associate or
6647 * sta_hs2_associate
6648 */
6649 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6650 0 ||
6651 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006652 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006653 }
6654
6655 ctrl = open_wpa_mon(intf);
6656 if (ctrl == NULL) {
6657 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6658 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006659 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006660 }
6661
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006662 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05306663 sizeof(result)) < 0 ||
6664 strncmp(result, "COMPLETED", 9) != 0) {
6665 sigma_dut_print(dut, DUT_MSG_DEBUG,
6666 "sta_reassoc: Not connected");
6667 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006668 } else if (dut->sta_ft_ds) {
6669 sigma_dut_print(dut, DUT_MSG_DEBUG,
6670 "sta_reassoc: Use FT-over-DS");
6671 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306672 }
6673
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306674 if (dut->rsne_override) {
6675#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006676 if (get_driver_type(dut) == DRIVER_WCN &&
6677 dut->config_rsnie == 0) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05306678 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306679 dut->config_rsnie = 1;
6680 }
6681#endif /* NL80211_SUPPORT */
6682 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6683 dut->rsne_override);
6684 if (wpa_command(intf, buf) < 0) {
6685 send_resp(dut, conn, SIGMA_ERROR,
6686 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6687 return 0;
6688 }
6689 }
6690
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006691 if (ft_ds) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006692 if (chan || freq) {
6693 if (!freq)
6694 freq = channel_to_freq(dut, chan);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006695 if (!freq) {
6696 sigma_dut_print(dut, DUT_MSG_ERROR,
6697 "Invalid channel number provided: %d",
6698 chan);
6699 send_resp(dut, conn, SIGMA_INVALID,
6700 "ErrorCode,Invalid channel number");
6701 goto close_mon_conn;
6702 }
6703 res = snprintf(buf, sizeof(buf),
6704 "SCAN TYPE=ONLY freq=%d", freq);
6705 } else {
6706 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6707 }
6708 if (res < 0 || res >= (int) sizeof(buf)) {
6709 send_resp(dut, conn, SIGMA_ERROR,
6710 "ErrorCode,snprintf failed");
6711 goto close_mon_conn;
6712 }
6713 if (wpa_command(intf, buf) < 0) {
6714 sigma_dut_print(dut, DUT_MSG_INFO,
6715 "Failed to start scan");
6716 send_resp(dut, conn, SIGMA_ERROR,
6717 "ErrorCode,scan failed");
6718 goto close_mon_conn;
6719 }
6720
6721 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6722 buf, sizeof(buf));
6723 if (res < 0) {
6724 sigma_dut_print(dut, DUT_MSG_INFO,
6725 "Scan did not complete");
6726 send_resp(dut, conn, SIGMA_ERROR,
6727 "ErrorCode,scan did not complete");
6728 goto close_mon_conn;
6729 }
6730
6731 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6732 if (res > 0 && res < (int) sizeof(buf))
6733 res = wpa_command(intf, buf);
6734
6735 if (res < 0 || res >= (int) sizeof(buf)) {
6736 send_resp(dut, conn, SIGMA_ERROR,
6737 "errorCode,FT_DS command failed");
6738 status = STATUS_SENT_ERROR;
6739 goto close_mon_conn;
6740 }
6741 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006742 if (chan || freq) {
6743 if (!freq)
6744 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306745 if (!freq) {
6746 sigma_dut_print(dut, DUT_MSG_ERROR,
6747 "Invalid channel number provided: %d",
6748 chan);
6749 send_resp(dut, conn, SIGMA_INVALID,
6750 "ErrorCode,Invalid channel number");
6751 goto close_mon_conn;
6752 }
6753 res = snprintf(buf, sizeof(buf),
6754 "SCAN TYPE=ONLY freq=%d", freq);
6755 } else {
6756 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6757 }
6758 if (res < 0 || res >= (int) sizeof(buf)) {
6759 send_resp(dut, conn, SIGMA_ERROR,
6760 "ErrorCode,snprintf failed");
6761 goto close_mon_conn;
6762 }
6763 if (wpa_command(intf, buf) < 0) {
6764 sigma_dut_print(dut, DUT_MSG_INFO,
6765 "Failed to start scan");
6766 send_resp(dut, conn, SIGMA_ERROR,
6767 "ErrorCode,scan failed");
6768 goto close_mon_conn;
6769 }
6770
6771 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6772 buf, sizeof(buf));
6773 if (res < 0) {
6774 sigma_dut_print(dut, DUT_MSG_INFO,
6775 "Scan did not complete");
6776 send_resp(dut, conn, SIGMA_ERROR,
6777 "ErrorCode,scan did not complete");
6778 goto close_mon_conn;
6779 }
6780
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006781 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6782 < 0) {
6783 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6784 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006785 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306786 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006787 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306788 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006789 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306790 if (res < 0 || res >= (int) sizeof(buf) ||
6791 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006792 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306793 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306794 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006795 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006796 sigma_dut_print(dut, DUT_MSG_INFO,
6797 "sta_reassoc: Run %s successful", buf);
6798 } else if (wpa_command(intf, "REASSOCIATE")) {
6799 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6800 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306801 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006802 }
6803
6804 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6805 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306806 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006807 send_resp(dut, conn, SIGMA_ERROR,
6808 "errorCode,Connection did not complete");
6809 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306810 goto close_mon_conn;
6811 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006812 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006813
Ashwini Patil467efef2017-05-25 12:18:27 +05306814close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006815 wpa_ctrl_detach(ctrl);
6816 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306817 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006818}
6819
6820
6821static void hs2_clear_credentials(const char *intf)
6822{
6823 wpa_command(intf, "REMOVE_CRED all");
6824}
6825
6826
Lior Davidcc88b562017-01-03 18:52:09 +02006827#ifdef __linux__
6828static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6829 unsigned int *aid)
6830{
Lior David0fe101e2017-03-09 16:09:50 +02006831 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006832
Lior David0fe101e2017-03-09 16:09:50 +02006833 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006834}
6835#endif /* __linux__ */
6836
6837
6838static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6839 unsigned int *aid)
6840{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006841 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02006842#ifdef __linux__
6843 case DRIVER_WIL6210:
6844 return wil6210_get_aid(dut, bssid, aid);
6845#endif /* __linux__ */
6846 default:
6847 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6848 return -1;
6849 }
6850}
6851
6852
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006853static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6854 struct sigma_cmd *cmd)
6855{
6856 char buf[MAX_CMD_LEN];
6857 char bss_list[MAX_CMD_LEN];
6858 const char *parameter = get_param(cmd, "Parameter");
6859
6860 if (parameter == NULL)
6861 return -1;
6862
Lior Davidcc88b562017-01-03 18:52:09 +02006863 if (strcasecmp(parameter, "AID") == 0) {
6864 unsigned int aid = 0;
6865 char bssid[20];
6866
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006867 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02006868 bssid, sizeof(bssid)) < 0) {
6869 sigma_dut_print(dut, DUT_MSG_ERROR,
6870 "could not get bssid");
6871 return -2;
6872 }
6873
6874 if (sta_get_aid_60g(dut, bssid, &aid))
6875 return -2;
6876
6877 snprintf(buf, sizeof(buf), "aid,%d", aid);
6878 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6879 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6880 return 0;
6881 }
6882
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006883 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6884 char *bss_line;
6885 char *bss_id = NULL;
6886 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306887 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006888
6889 if (ifname == NULL) {
6890 sigma_dut_print(dut, DUT_MSG_INFO,
6891 "For get DiscoveredDevList need Interface name.");
6892 return -1;
6893 }
6894
6895 /*
6896 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6897 * of BSSIDs in "bssid=<BSSID>\n"
6898 */
6899 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6900 bss_list,
6901 sizeof(bss_list)) < 0) {
6902 sigma_dut_print(dut, DUT_MSG_ERROR,
6903 "Failed to get bss list");
6904 return -1;
6905 }
6906
6907 sigma_dut_print(dut, DUT_MSG_DEBUG,
6908 "bss list for ifname:%s is:%s",
6909 ifname, bss_list);
6910
6911 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306912 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006913 while (bss_line) {
6914 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6915 bss_id) {
6916 int len;
6917
6918 len = snprintf(buf + strlen(buf),
6919 sizeof(buf) - strlen(buf),
6920 ",%s", bss_id);
6921 free(bss_id);
6922 bss_id = NULL;
6923 if (len < 0) {
6924 sigma_dut_print(dut,
6925 DUT_MSG_ERROR,
6926 "Failed to read BSSID");
6927 send_resp(dut, conn, SIGMA_ERROR,
6928 "ErrorCode,Failed to read BSS ID");
6929 return 0;
6930 }
6931
6932 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6933 sigma_dut_print(dut,
6934 DUT_MSG_ERROR,
6935 "Response buf too small for list");
6936 send_resp(dut, conn,
6937 SIGMA_ERROR,
6938 "ErrorCode,Response buf too small for list");
6939 return 0;
6940 }
6941 }
6942
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306943 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006944 }
6945
6946 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6947 buf);
6948 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6949 return 0;
6950 }
6951
6952 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6953 return 0;
6954}
6955
6956
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006957static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6958 struct sigma_cmd *cmd)
6959{
6960 char buf[MAX_CMD_LEN];
6961 const char *parameter = get_param(cmd, "Parameter");
6962
6963 if (!parameter)
6964 return -1;
6965
6966 if (strcasecmp(parameter, "RSSI") == 0) {
6967 char rssi[10];
6968
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006969 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006970 rssi, sizeof(rssi)) < 0) {
6971 sigma_dut_print(dut, DUT_MSG_ERROR,
6972 "Could not get RSSI");
6973 return -2;
6974 }
6975
6976 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6977 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6978 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6979 return 0;
6980 }
6981
6982 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6983 return 0;
6984}
6985
6986
Jouni Malinenca0abd32020-02-09 20:18:10 +02006987static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
6988 struct sigma_conn *conn,
6989 struct sigma_cmd *cmd)
6990{
6991 const char *intf = get_param(cmd, "Interface");
6992 char buf[4096], bssid[20], resp[200], *pos, *tmp;
6993
6994 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
6995 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
6996 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
6997 send_resp(dut, conn, SIGMA_ERROR,
6998 "ErrorCode,PMKSA_GET not supported");
6999 return STATUS_SENT_ERROR;
7000 }
7001
7002 if (strncmp(buf, "FAIL", 4) == 0 ||
7003 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
7004 send_resp(dut, conn, SIGMA_ERROR,
7005 "ErrorCode,Could not find current network");
7006 return STATUS_SENT_ERROR;
7007 }
7008
7009 pos = buf;
7010 while (pos) {
7011 if (strncmp(pos, bssid, 17) == 0) {
7012 pos = strchr(pos, ' ');
7013 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307014 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007015 pos++;
7016 pos = strchr(pos, ' ');
7017 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307018 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007019 pos++;
7020 tmp = strchr(pos, ' ');
7021 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307022 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007023 *tmp = '\0';
7024 break;
7025 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02007026 pos = strchr(pos, '\n');
7027 if (pos)
7028 pos++;
7029 }
7030
7031 if (!pos) {
7032 send_resp(dut, conn, SIGMA_ERROR,
7033 "ErrorCode,PMK not available");
7034 return STATUS_SENT_ERROR;
7035 }
7036
7037 snprintf(resp, sizeof(resp), "PMK,%s", pos);
7038 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7039 return STATUS_SENT;
7040}
7041
7042
Jouni Malinenf7222712019-06-13 01:50:21 +03007043static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
7044 struct sigma_conn *conn,
7045 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007046{
7047 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02007048 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007049
Jouni Malinenca0abd32020-02-09 20:18:10 +02007050 if (!parameter)
7051 return INVALID_SEND_STATUS;
7052
7053 if (strcasecmp(parameter, "PMK") == 0)
7054 return sta_get_pmk(dut, conn, cmd);
7055
7056 if (!program)
7057 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007058
7059 if (strcasecmp(program, "P2PNFC") == 0)
7060 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
7061
7062 if (strcasecmp(program, "60ghz") == 0)
7063 return sta_get_parameter_60g(dut, conn, cmd);
7064
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007065 if (strcasecmp(program, "he") == 0)
7066 return sta_get_parameter_he(dut, conn, cmd);
7067
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007068#ifdef ANDROID_NAN
7069 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07007070 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007071#endif /* ANDROID_NAN */
7072
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007073#ifdef MIRACAST
7074 if (strcasecmp(program, "WFD") == 0 ||
7075 strcasecmp(program, "DisplayR2") == 0)
7076 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
7077#endif /* MIRACAST */
7078
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007079 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7080 return 0;
7081}
7082
7083
7084static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
7085 const char *type)
7086{
7087 char buf[100];
7088
7089 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007090 run_iwpriv(dut, intf, "chwidth 2");
7091 run_iwpriv(dut, intf, "mode 11ACVHT80");
7092 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007093 }
7094
7095 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007096 run_iwpriv(dut, intf, "chwidth 0");
7097 run_iwpriv(dut, intf, "mode 11naht40");
7098 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007099 }
7100
7101 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007102 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007103
7104 /* Reset CTS width */
7105 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
7106 intf);
7107 if (system(buf) != 0) {
7108 sigma_dut_print(dut, DUT_MSG_ERROR,
7109 "wifitool %s beeliner_fw_test 54 0 failed",
7110 intf);
7111 }
7112
7113 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007114 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007115
7116 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
7117 if (system(buf) != 0) {
7118 sigma_dut_print(dut, DUT_MSG_ERROR,
7119 "iwpriv rts failed");
7120 }
7121 }
7122
7123 if (type && strcasecmp(type, "Testbed") == 0) {
7124 dut->testbed_flag_txsp = 1;
7125 dut->testbed_flag_rxsp = 1;
7126 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007127 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007128
7129 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007130 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007131
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007132 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007133
7134 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007135 run_iwpriv(dut, intf, "tx_stbc 0");
7136 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007137
7138 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007139 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007140 }
7141
7142 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007143 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07007144 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007145
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007146 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007147 }
7148}
7149
7150
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007151#ifdef NL80211_SUPPORT
7152static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
7153 enum he_mcs_config mcs)
7154{
7155 struct nl_msg *msg;
7156 int ret = 0;
7157 struct nlattr *params;
7158 int ifindex;
7159
7160 ifindex = if_nametoindex(intf);
7161 if (ifindex == 0) {
7162 sigma_dut_print(dut, DUT_MSG_ERROR,
7163 "%s: Index for interface %s failed",
7164 __func__, intf);
7165 return -1;
7166 }
7167
7168 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7169 NL80211_CMD_VENDOR)) ||
7170 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7171 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7172 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7173 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7174 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7175 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
7176 mcs)) {
7177 sigma_dut_print(dut, DUT_MSG_ERROR,
7178 "%s: err in adding vendor_cmd and vendor_data",
7179 __func__);
7180 nlmsg_free(msg);
7181 return -1;
7182 }
7183 nla_nest_end(msg, params);
7184
7185 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7186 if (ret) {
7187 sigma_dut_print(dut, DUT_MSG_ERROR,
7188 "%s: err in send_and_recv_msgs, ret=%d",
7189 __func__, ret);
7190 }
7191 return ret;
7192}
7193#endif /* NL80211_SUPPORT */
7194
7195
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007196static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
7197 const char *intf, int enable)
7198{
7199#ifdef NL80211_SUPPORT
7200 struct nl_msg *msg;
7201 int ret = 0;
7202 struct nlattr *params;
7203 int ifindex;
7204
7205 ifindex = if_nametoindex(intf);
7206 if (ifindex == 0) {
7207 sigma_dut_print(dut, DUT_MSG_ERROR,
7208 "%s: Index for interface %s failed",
7209 __func__, intf);
7210 return -1;
7211 }
7212
7213 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7214 NL80211_CMD_VENDOR)) ||
7215 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7216 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7217 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7218 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7219 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7220 nla_put_u8(msg,
7221 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
7222 enable)) {
7223 sigma_dut_print(dut, DUT_MSG_ERROR,
7224 "%s: err in adding vendor_cmd and vendor_data",
7225 __func__);
7226 nlmsg_free(msg);
7227 return -1;
7228 }
7229 nla_nest_end(msg, params);
7230
7231 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7232 if (ret) {
7233 sigma_dut_print(dut, DUT_MSG_ERROR,
7234 "%s: err in send_and_recv_msgs, ret=%d",
7235 __func__, ret);
7236 }
7237 return ret;
7238#else /* NL80211_SUPPORT */
7239 sigma_dut_print(dut, DUT_MSG_ERROR,
7240 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
7241 return -1;
7242#endif /* NL80211_SUPPORT */
7243}
7244
7245
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007246static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
7247 const char *intf, int enable)
7248{
7249#ifdef NL80211_SUPPORT
7250 struct nl_msg *msg;
7251 int ret = 0;
7252 struct nlattr *params;
7253 int ifindex;
7254
7255 ifindex = if_nametoindex(intf);
7256 if (ifindex == 0) {
7257 sigma_dut_print(dut, DUT_MSG_ERROR,
7258 "%s: Index for interface %s failed",
7259 __func__, intf);
7260 return -1;
7261 }
7262
7263 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7264 NL80211_CMD_VENDOR)) ||
7265 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7266 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7267 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7268 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7269 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7270 nla_put_u8(msg,
7271 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7272 enable)) {
7273 sigma_dut_print(dut, DUT_MSG_ERROR,
7274 "%s: err in adding vendor_cmd and vendor_data",
7275 __func__);
7276 nlmsg_free(msg);
7277 return -1;
7278 }
7279 nla_nest_end(msg, params);
7280
7281 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7282 if (ret) {
7283 sigma_dut_print(dut, DUT_MSG_ERROR,
7284 "%s: err in send_and_recv_msgs, ret=%d",
7285 __func__, ret);
7286 }
7287 return ret;
7288#else /* NL80211_SUPPORT */
7289 sigma_dut_print(dut, DUT_MSG_ERROR,
7290 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7291 return -1;
7292#endif /* NL80211_SUPPORT */
7293}
7294
7295
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007296#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007297
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007298static int sta_set_he_testbed_def(struct sigma_dut *dut,
7299 const char *intf, int cfg)
7300{
7301 struct nl_msg *msg;
7302 int ret = 0;
7303 struct nlattr *params;
7304 int ifindex;
7305
7306 ifindex = if_nametoindex(intf);
7307 if (ifindex == 0) {
7308 sigma_dut_print(dut, DUT_MSG_ERROR,
7309 "%s: Index for interface %s failed",
7310 __func__, intf);
7311 return -1;
7312 }
7313
7314 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7315 NL80211_CMD_VENDOR)) ||
7316 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7317 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7318 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7319 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7320 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7321 nla_put_u8(msg,
7322 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7323 cfg)) {
7324 sigma_dut_print(dut, DUT_MSG_ERROR,
7325 "%s: err in adding vendor_cmd and vendor_data",
7326 __func__);
7327 nlmsg_free(msg);
7328 return -1;
7329 }
7330 nla_nest_end(msg, params);
7331
7332 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7333 if (ret) {
7334 sigma_dut_print(dut, DUT_MSG_ERROR,
7335 "%s: err in send_and_recv_msgs, ret=%d",
7336 __func__, ret);
7337 }
7338 return ret;
7339}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007340
7341
7342static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7343{
7344 struct nl_msg *msg;
7345 int ret = 0;
7346 struct nlattr *params;
7347 int ifindex;
7348
7349 ifindex = if_nametoindex(intf);
7350 if (ifindex == 0) {
7351 sigma_dut_print(dut, DUT_MSG_ERROR,
7352 "%s: Index for interface %s failed",
7353 __func__, intf);
7354 return -1;
7355 }
7356
7357 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7358 NL80211_CMD_VENDOR)) ||
7359 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7360 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7361 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7362 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7363 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7364 nla_put_u8(msg,
7365 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7366 cfg)) {
7367 sigma_dut_print(dut, DUT_MSG_ERROR,
7368 "%s: err in adding vendor_cmd and vendor_data",
7369 __func__);
7370 nlmsg_free(msg);
7371 return -1;
7372 }
7373 nla_nest_end(msg, params);
7374
7375 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7376 if (ret) {
7377 sigma_dut_print(dut, DUT_MSG_ERROR,
7378 "%s: err in send_and_recv_msgs, ret=%d",
7379 __func__, ret);
7380 }
7381 return ret;
7382}
7383
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007384#endif /* NL80211_SUPPORT */
7385
7386
Qiwei Caib6806972020-01-15 13:52:11 +08007387int sta_set_addba_buf_size(struct sigma_dut *dut,
7388 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007389{
7390#ifdef NL80211_SUPPORT
7391 struct nl_msg *msg;
7392 int ret = 0;
7393 struct nlattr *params;
7394 int ifindex;
7395
7396 ifindex = if_nametoindex(intf);
7397 if (ifindex == 0) {
7398 sigma_dut_print(dut, DUT_MSG_ERROR,
7399 "%s: Index for interface %s failed",
7400 __func__, intf);
7401 return -1;
7402 }
7403
7404 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7405 NL80211_CMD_VENDOR)) ||
7406 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7407 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7408 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7409 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7410 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07007411 nla_put_u16(msg,
7412 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
7413 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007414 sigma_dut_print(dut, DUT_MSG_ERROR,
7415 "%s: err in adding vendor_cmd and vendor_data",
7416 __func__);
7417 nlmsg_free(msg);
7418 return -1;
7419 }
7420 nla_nest_end(msg, params);
7421
7422 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7423 if (ret) {
7424 sigma_dut_print(dut, DUT_MSG_ERROR,
7425 "%s: err in send_and_recv_msgs, ret=%d",
7426 __func__, ret);
7427 }
7428 return ret;
7429#else /* NL80211_SUPPORT */
7430 sigma_dut_print(dut, DUT_MSG_ERROR,
7431 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7432 return -1;
7433#endif /* NL80211_SUPPORT */
7434}
7435
7436
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007437static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
7438 int enable)
7439{
7440#ifdef NL80211_SUPPORT
7441 struct nl_msg *msg;
7442 int ret = 0;
7443 struct nlattr *params;
7444 int ifindex;
7445
7446 ifindex = if_nametoindex(intf);
7447 if (ifindex == 0) {
7448 sigma_dut_print(dut, DUT_MSG_ERROR,
7449 "%s: Index for interface %s failed",
7450 __func__, intf);
7451 return -1;
7452 }
7453
7454 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7455 NL80211_CMD_VENDOR)) ||
7456 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7457 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7458 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7459 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7460 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7461 nla_put_u8(msg,
7462 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7463 enable)) {
7464 sigma_dut_print(dut, DUT_MSG_ERROR,
7465 "%s: err in adding vendor_cmd and vendor_data",
7466 __func__);
7467 nlmsg_free(msg);
7468 return -1;
7469 }
7470 nla_nest_end(msg, params);
7471
7472 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7473 if (ret) {
7474 sigma_dut_print(dut, DUT_MSG_ERROR,
7475 "%s: err in send_and_recv_msgs, ret=%d",
7476 __func__, ret);
7477 }
7478 return ret;
7479#else /* NL80211_SUPPORT */
7480 sigma_dut_print(dut, DUT_MSG_ERROR,
7481 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7482 return -1;
7483#endif /* NL80211_SUPPORT */
7484}
7485
7486
Arif Hussain9765f7d2018-07-03 08:28:26 -07007487static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7488 int val)
7489{
7490#ifdef NL80211_SUPPORT
7491 struct nl_msg *msg;
7492 int ret = 0;
7493 struct nlattr *params;
7494 int ifindex;
7495
7496 ifindex = if_nametoindex(intf);
7497 if (ifindex == 0) {
7498 sigma_dut_print(dut, DUT_MSG_ERROR,
7499 "%s: Index for interface %s failed, val:%d",
7500 __func__, intf, val);
7501 return -1;
7502 }
7503
7504 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7505 NL80211_CMD_VENDOR)) ||
7506 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7507 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7508 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7509 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7510 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7511 nla_put_u8(msg,
7512 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7513 val)) {
7514 sigma_dut_print(dut, DUT_MSG_ERROR,
7515 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7516 __func__, val);
7517 nlmsg_free(msg);
7518 return -1;
7519 }
7520 nla_nest_end(msg, params);
7521
7522 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7523 if (ret) {
7524 sigma_dut_print(dut, DUT_MSG_ERROR,
7525 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7526 __func__, ret, val);
7527 }
7528 return ret;
7529#else /* NL80211_SUPPORT */
7530 sigma_dut_print(dut, DUT_MSG_ERROR,
7531 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7532 return -1;
7533#endif /* NL80211_SUPPORT */
7534}
7535
7536
Arif Hussain68d23f52018-07-11 13:39:08 -07007537#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007538static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7539 enum qca_wlan_he_mac_padding_dur val)
7540{
Arif Hussain68d23f52018-07-11 13:39:08 -07007541 struct nl_msg *msg;
7542 int ret = 0;
7543 struct nlattr *params;
7544 int ifindex;
7545
7546 ifindex = if_nametoindex(intf);
7547 if (ifindex == 0) {
7548 sigma_dut_print(dut, DUT_MSG_ERROR,
7549 "%s: Index for interface %s failed, val:%d",
7550 __func__, intf, val);
7551 return -1;
7552 }
7553
7554 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7555 NL80211_CMD_VENDOR)) ||
7556 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7557 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7558 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7559 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7560 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7561 nla_put_u8(msg,
7562 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
7563 val)) {
7564 sigma_dut_print(dut, DUT_MSG_ERROR,
7565 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7566 __func__, val);
7567 nlmsg_free(msg);
7568 return -1;
7569 }
7570 nla_nest_end(msg, params);
7571
7572 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7573 if (ret) {
7574 sigma_dut_print(dut, DUT_MSG_ERROR,
7575 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7576 __func__, ret, val);
7577 }
7578 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07007579}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007580#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007581
7582
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007583static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7584 int val)
7585{
7586#ifdef NL80211_SUPPORT
7587 struct nl_msg *msg;
7588 int ret = 0;
7589 struct nlattr *params;
7590 int ifindex;
7591
7592 ifindex = if_nametoindex(intf);
7593 if (ifindex == 0) {
7594 sigma_dut_print(dut, DUT_MSG_ERROR,
7595 "%s: Index for interface %s failed, val:%d",
7596 __func__, intf, val);
7597 return -1;
7598 }
7599
7600 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7601 NL80211_CMD_VENDOR)) ||
7602 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7603 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7604 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7605 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7606 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7607 nla_put_u8(msg,
7608 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7609 val)) {
7610 sigma_dut_print(dut, DUT_MSG_ERROR,
7611 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7612 __func__, val);
7613 nlmsg_free(msg);
7614 return -1;
7615 }
7616 nla_nest_end(msg, params);
7617
7618 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7619 if (ret) {
7620 sigma_dut_print(dut, DUT_MSG_ERROR,
7621 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7622 __func__, ret, val);
7623 }
7624 return ret;
7625#else /* NL80211_SUPPORT */
7626 sigma_dut_print(dut, DUT_MSG_ERROR,
7627 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7628 return -1;
7629#endif /* NL80211_SUPPORT */
7630}
7631
7632
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007633#ifdef NL80211_SUPPORT
7634static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7635{
7636 struct nl_msg *msg;
7637 int ret = 0;
7638 struct nlattr *params;
7639 int ifindex;
7640
7641 ifindex = if_nametoindex(intf);
7642 if (ifindex == 0) {
7643 sigma_dut_print(dut, DUT_MSG_ERROR,
7644 "%s: Index for interface %s failed",
7645 __func__, intf);
7646 return -1;
7647 }
7648
7649 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7650 NL80211_CMD_VENDOR)) ||
7651 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7652 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7653 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7654 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7655 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7656 nla_put_flag(msg,
7657 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
7658 sigma_dut_print(dut, DUT_MSG_ERROR,
7659 "%s: err in adding vendor_cmd and vendor_data",
7660 __func__);
7661 nlmsg_free(msg);
7662 return -1;
7663 }
7664 nla_nest_end(msg, params);
7665
7666 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7667 if (ret) {
7668 sigma_dut_print(dut, DUT_MSG_ERROR,
7669 "%s: err in send_and_recv_msgs, ret=%d",
7670 __func__, ret);
7671 }
7672 return ret;
7673}
7674#endif /* NL80211_SUPPORT */
7675
7676
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007677static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7678 int val)
7679{
7680#ifdef NL80211_SUPPORT
7681 struct nl_msg *msg;
7682 int ret = 0;
7683 struct nlattr *params;
7684 int ifindex;
7685
7686 ifindex = if_nametoindex(intf);
7687 if (ifindex == 0) {
7688 sigma_dut_print(dut, DUT_MSG_ERROR,
7689 "%s: Index for interface %s failed, val:%d",
7690 __func__, intf, val);
7691 return -1;
7692 }
7693
7694 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7695 NL80211_CMD_VENDOR)) ||
7696 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7697 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7698 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7699 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7700 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7701 nla_put_u8(msg,
7702 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
7703 val)) {
7704 sigma_dut_print(dut, DUT_MSG_ERROR,
7705 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7706 __func__, val);
7707 nlmsg_free(msg);
7708 return -1;
7709 }
7710 nla_nest_end(msg, params);
7711
7712 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7713 if (ret) {
7714 sigma_dut_print(dut, DUT_MSG_ERROR,
7715 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7716 __func__, ret, val);
7717 }
7718 return ret;
7719#else /* NL80211_SUPPORT */
7720 sigma_dut_print(dut, DUT_MSG_ERROR,
7721 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7722 return -1;
7723#endif /* NL80211_SUPPORT */
7724}
7725
7726
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007727static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7728 int val)
7729{
7730#ifdef NL80211_SUPPORT
7731 struct nl_msg *msg;
7732 int ret = 0;
7733 struct nlattr *params;
7734 int ifindex;
7735
7736 ifindex = if_nametoindex(intf);
7737 if (ifindex == 0) {
7738 sigma_dut_print(dut, DUT_MSG_ERROR,
7739 "%s: Index for interface %s failed, val:%d",
7740 __func__, intf, val);
7741 return -1;
7742 }
7743
7744 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7745 NL80211_CMD_VENDOR)) ||
7746 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7747 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7748 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7749 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7750 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7751 nla_put_u8(msg,
7752 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
7753 val)) {
7754 sigma_dut_print(dut, DUT_MSG_ERROR,
7755 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7756 __func__, val);
7757 nlmsg_free(msg);
7758 return -1;
7759 }
7760 nla_nest_end(msg, params);
7761
7762 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7763 if (ret) {
7764 sigma_dut_print(dut, DUT_MSG_ERROR,
7765 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7766 __func__, ret, val);
7767 }
7768 return ret;
7769#else /* NL80211_SUPPORT */
7770 sigma_dut_print(dut, DUT_MSG_ERROR,
7771 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7772 return -1;
7773#endif /* NL80211_SUPPORT */
7774}
7775
7776
Arif Hussain480d5f42019-03-12 14:40:42 -07007777static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7778 int val)
7779{
7780#ifdef NL80211_SUPPORT
7781 struct nl_msg *msg;
7782 int ret;
7783 struct nlattr *params;
7784 int ifindex;
7785
7786 ifindex = if_nametoindex(intf);
7787 if (ifindex == 0) {
7788 sigma_dut_print(dut, DUT_MSG_ERROR,
7789 "%s: Index for interface %s failed, val:%d",
7790 __func__, intf, val);
7791 return -1;
7792 }
7793
7794 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7795 NL80211_CMD_VENDOR)) ||
7796 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7797 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7798 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7799 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7800 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7801 nla_put_u8(msg,
7802 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT,
7803 val)) {
7804 sigma_dut_print(dut, DUT_MSG_ERROR,
7805 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7806 __func__, val);
7807 nlmsg_free(msg);
7808 return -1;
7809 }
7810 nla_nest_end(msg, params);
7811
7812 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7813 if (ret) {
7814 sigma_dut_print(dut, DUT_MSG_ERROR,
7815 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7816 __func__, ret, val);
7817 }
7818 return ret;
7819#else /* NL80211_SUPPORT */
7820 sigma_dut_print(dut, DUT_MSG_ERROR,
7821 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7822 return -1;
7823#endif /* NL80211_SUPPORT */
7824}
7825
7826
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007827static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7828 const char *type)
7829{
7830 char buf[60];
7831
7832 if (dut->program == PROGRAM_HE) {
7833 /* resetting phymode to auto in case of HE program */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05307834 sta_set_phymode(dut, intf, "auto");
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007835
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007836 /* reset the rate to Auto rate */
7837 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7838 intf);
7839 if (system(buf) != 0) {
7840 sigma_dut_print(dut, DUT_MSG_ERROR,
7841 "iwpriv %s set_11ax_rate 0xff failed",
7842 intf);
7843 }
7844
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007845 /* reset the LDPC setting */
7846 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7847 if (system(buf) != 0) {
7848 sigma_dut_print(dut, DUT_MSG_ERROR,
7849 "iwpriv %s ldpc 1 failed", intf);
7850 }
7851
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007852 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05307853 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007854
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007855 /* remove all network profiles */
7856 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007857
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007858 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7859 sta_set_addba_buf_size(dut, intf, 64);
7860
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007861#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007862 /* Reset the device HE capabilities to its default supported
7863 * configuration. */
7864 sta_set_he_testbed_def(dut, intf, 0);
7865
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007866 /* Disable noackpolicy for all AC */
7867 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7868 sigma_dut_print(dut, DUT_MSG_ERROR,
7869 "Disable of noackpolicy for all AC failed");
7870 }
7871#endif /* NL80211_SUPPORT */
7872
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007873 /* Enable WMM by default */
7874 if (wcn_sta_set_wmm(dut, intf, "on")) {
7875 sigma_dut_print(dut, DUT_MSG_ERROR,
7876 "Enable of WMM in sta_reset_default_wcn failed");
7877 }
7878
7879 /* Disable ADDBA_REJECT by default */
7880 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7881 sigma_dut_print(dut, DUT_MSG_ERROR,
7882 "Disable of addba_reject in sta_reset_default_wcn failed");
7883 }
7884
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007885 /* Enable sending of ADDBA by default */
7886 if (nlvendor_config_send_addba(dut, intf, 1)) {
7887 sigma_dut_print(dut, DUT_MSG_ERROR,
7888 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7889 }
7890
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007891 /* Enable AMPDU by default */
7892 iwpriv_sta_set_ampdu(dut, intf, 1);
7893
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007894#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08007895 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007896 sigma_dut_print(dut, DUT_MSG_ERROR,
7897 "Set LTF config to default in sta_reset_default_wcn failed");
7898 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007899
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007900 /* set the beamformee NSTS(maximum number of
7901 * space-time streams) to default DUT config
7902 */
7903 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007904 sigma_dut_print(dut, DUT_MSG_ERROR,
7905 "Failed to set BeamformeeSTS");
7906 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007907
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007908 if (sta_set_mac_padding_duration(
7909 dut, intf,
7910 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007911 sigma_dut_print(dut, DUT_MSG_ERROR,
7912 "Failed to set MAC padding duration");
7913 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007914
7915 if (sta_set_mu_edca_override(dut, intf, 0)) {
7916 sigma_dut_print(dut, DUT_MSG_ERROR,
7917 "ErrorCode,Failed to set MU EDCA override disable");
7918 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007919
7920 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7921 sigma_dut_print(dut, DUT_MSG_ERROR,
7922 "Failed to set OM ctrl supp");
7923 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007924
7925 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7926 sigma_dut_print(dut, DUT_MSG_ERROR,
7927 "Failed to set Tx SU PPDU enable");
7928 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007929
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007930 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7931 sigma_dut_print(dut, DUT_MSG_ERROR,
7932 "failed to send TB PPDU Tx cfg");
7933 }
7934
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007935 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7936 sigma_dut_print(dut, DUT_MSG_ERROR,
7937 "Failed to set OM ctrl reset");
7938 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007939
7940 /* +HTC-HE support default on */
7941 if (sta_set_he_htc_supp(dut, intf, 1)) {
7942 sigma_dut_print(dut, DUT_MSG_ERROR,
7943 "Setting of +HTC-HE support failed");
7944 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007945#endif /* NL80211_SUPPORT */
7946
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007947 if (sta_set_tx_beamformee(dut, intf, 1)) {
7948 sigma_dut_print(dut, DUT_MSG_ERROR,
7949 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7950 }
7951
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007952 wpa_command(intf, "SET oce 1");
7953
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007954 /* Set nss to 1 and MCS 0-7 in case of testbed */
7955 if (type && strcasecmp(type, "Testbed") == 0) {
7956#ifdef NL80211_SUPPORT
7957 int ret;
7958#endif /* NL80211_SUPPORT */
7959
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007960 wpa_command(intf, "SET oce 0");
7961
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007962 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7963 if (system(buf) != 0) {
7964 sigma_dut_print(dut, DUT_MSG_ERROR,
7965 "iwpriv %s nss failed", intf);
7966 }
7967
7968#ifdef NL80211_SUPPORT
7969 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7970 if (ret) {
7971 sigma_dut_print(dut, DUT_MSG_ERROR,
7972 "Setting of MCS failed, ret:%d",
7973 ret);
7974 }
7975#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007976
7977 /* Disable STBC as default */
7978 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007979
7980 /* Disable AMSDU as default */
7981 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007982
7983#ifdef NL80211_SUPPORT
7984 /* HE fragmentation default off */
7985 if (sta_set_he_fragmentation(dut, intf,
7986 HE_FRAG_DISABLE)) {
7987 sigma_dut_print(dut, DUT_MSG_ERROR,
7988 "Setting of HE fragmentation failed");
7989 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007990
7991 /* set the beamformee NSTS(maximum number of
7992 * space-time streams) to default testbed config
7993 */
7994 if (sta_set_beamformee_sts(dut, intf, 3)) {
7995 sigma_dut_print(dut, DUT_MSG_ERROR,
7996 "Failed to set BeamformeeSTS");
7997 }
7998
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007999 /* +HTC-HE support default off */
8000 if (sta_set_he_htc_supp(dut, intf, 0)) {
8001 sigma_dut_print(dut, DUT_MSG_ERROR,
8002 "Setting of +HTC-HE support failed");
8003 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008004
8005 /* Set device HE capabilities to testbed default
8006 * configuration. */
8007 if (sta_set_he_testbed_def(dut, intf, 1)) {
8008 sigma_dut_print(dut, DUT_MSG_DEBUG,
8009 "Failed to set HE defaults");
8010 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08008011
8012 /* Disable VHT support in 2.4 GHz for testbed */
8013 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08008014#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08008015
8016 /* Enable WEP/TKIP with HE capability in testbed */
8017 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
8018 sigma_dut_print(dut, DUT_MSG_ERROR,
8019 "Enabling HE config with WEP/TKIP failed");
8020 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008021 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008022
8023 /* Defaults in case of DUT */
8024 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07008025 /* Enable STBC by default */
8026 wcn_sta_set_stbc(dut, intf, "1");
8027
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008028 /* set nss to 2 */
8029 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
8030 if (system(buf) != 0) {
8031 sigma_dut_print(dut, DUT_MSG_ERROR,
8032 "iwpriv %s nss 2 failed", intf);
8033 }
Arif Hussainac6c5112018-05-25 17:34:00 -07008034 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008035
8036#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07008037 /* Set HE_MCS to 0-11 */
8038 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008039 sigma_dut_print(dut, DUT_MSG_ERROR,
8040 "Setting of MCS failed");
8041 }
8042#endif /* NL80211_SUPPORT */
8043
8044 /* Disable WEP/TKIP with HE capability in DUT */
8045 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
8046 sigma_dut_print(dut, DUT_MSG_ERROR,
8047 "Enabling HE config with WEP/TKIP failed");
8048 }
8049 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008050 }
8051}
8052
8053
Jouni Malinenf7222712019-06-13 01:50:21 +03008054static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
8055 struct sigma_conn *conn,
8056 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008057{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008058 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008059 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008060 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008061 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308062 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008063
Jouni Malinenb21f0542019-11-04 17:53:38 +02008064 if (dut->station_ifname_2g &&
8065 strcmp(dut->station_ifname_2g, intf) == 0)
8066 dut->use_5g = 0;
8067 else if (dut->station_ifname_5g &&
8068 strcmp(dut->station_ifname_5g, intf) == 0)
8069 dut->use_5g = 1;
8070
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008071 if (!program)
8072 program = get_param(cmd, "prog");
8073 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008074 dut->device_type = STA_unknown;
8075 type = get_param(cmd, "type");
8076 if (type && strcasecmp(type, "Testbed") == 0)
8077 dut->device_type = STA_testbed;
8078 if (type && strcasecmp(type, "DUT") == 0)
8079 dut->device_type = STA_dut;
8080
8081 if (dut->program == PROGRAM_TDLS) {
8082 /* Clear TDLS testing mode */
8083 wpa_command(intf, "SET tdls_disabled 0");
8084 wpa_command(intf, "SET tdls_testing 0");
8085 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008086 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05308087 /* Enable the WCN driver in TDLS Explicit trigger mode
8088 */
8089 wpa_command(intf, "SET tdls_external_control 0");
8090 wpa_command(intf, "SET tdls_trigger_control 0");
8091 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008092 }
8093
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008094#ifdef MIRACAST
8095 if (dut->program == PROGRAM_WFD ||
8096 dut->program == PROGRAM_DISPLAYR2)
8097 miracast_sta_reset_default(dut, conn, cmd);
8098#endif /* MIRACAST */
8099
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008100 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008101 case DRIVER_ATHEROS:
8102 sta_reset_default_ath(dut, intf, type);
8103 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008104 case DRIVER_WCN:
8105 sta_reset_default_wcn(dut, intf, type);
8106 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008107 default:
8108 break;
8109 }
8110
8111#ifdef ANDROID_NAN
8112 if (dut->program == PROGRAM_NAN)
8113 nan_cmd_sta_reset_default(dut, conn, cmd);
8114#endif /* ANDROID_NAN */
8115
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05308116 if (dut->program == PROGRAM_LOC &&
8117 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
8118 return ERROR_SEND_STATUS;
8119
Jouni Malinenba630452018-06-22 11:49:59 +03008120 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008121 unlink("SP/wi-fi.org/pps.xml");
8122 if (system("rm -r SP/*") != 0) {
8123 }
8124 unlink("next-client-cert.pem");
8125 unlink("next-client-key.pem");
8126 }
8127
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008128 /* For WPS program of the 60 GHz band the band type needs to be saved */
8129 if (dut->program == PROGRAM_WPS) {
8130 if (band && strcasecmp(band, "60GHz") == 0) {
8131 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008132 /* For 60 GHz enable WPS for WPS TCs */
8133 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008134 } else {
8135 dut->band = WPS_BAND_NON_60G;
8136 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008137 } else if (dut->program == PROGRAM_60GHZ) {
8138 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
8139 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008140 }
8141
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02008142 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008143 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008144 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008145
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008146 sigma_dut_print(dut, DUT_MSG_INFO,
8147 "WPS 60 GHz program, wps_disable = %d",
8148 dut->wps_disable);
8149
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008150 if (!dev_role) {
8151 send_resp(dut, conn, SIGMA_ERROR,
8152 "errorCode,Missing DevRole argument");
8153 return 0;
8154 }
8155
8156 if (strcasecmp(dev_role, "STA") == 0)
8157 dut->dev_role = DEVROLE_STA;
8158 else if (strcasecmp(dev_role, "PCP") == 0)
8159 dut->dev_role = DEVROLE_PCP;
8160 else {
8161 send_resp(dut, conn, SIGMA_ERROR,
8162 "errorCode,Unknown DevRole");
8163 return 0;
8164 }
8165
8166 if (dut->device_type == STA_unknown) {
8167 sigma_dut_print(dut, DUT_MSG_ERROR,
8168 "Device type is not STA testbed or DUT");
8169 send_resp(dut, conn, SIGMA_ERROR,
8170 "errorCode,Unknown device type");
8171 return 0;
8172 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008173
8174 sigma_dut_print(dut, DUT_MSG_DEBUG,
8175 "Setting msdu_size to MAX: 7912");
8176 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008177 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008178
8179 if (system(buf) != 0) {
8180 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
8181 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008182 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008183 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008184
8185 if (sta_set_force_mcs(dut, 0, 1)) {
8186 sigma_dut_print(dut, DUT_MSG_ERROR,
8187 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008188 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008189 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008190 }
8191
8192 wpa_command(intf, "WPS_ER_STOP");
8193 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05308194 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008195 wpa_command(intf, "SET radio_disabled 0");
8196
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02008197 dut->wps_forced_version = 0;
8198
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008199 if (dut->wsc_fragment) {
8200 dut->wsc_fragment = 0;
8201 wpa_command(intf, "SET device_name Test client");
8202 wpa_command(intf, "SET manufacturer ");
8203 wpa_command(intf, "SET model_name ");
8204 wpa_command(intf, "SET model_number ");
8205 wpa_command(intf, "SET serial_number ");
8206 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02008207 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
8208 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
8209 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
8210 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008211
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008212 if (dut->tmp_mac_addr && dut->set_macaddr) {
8213 dut->tmp_mac_addr = 0;
8214 if (system(dut->set_macaddr) != 0) {
8215 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
8216 "temporary MAC address");
8217 }
8218 }
8219
8220 set_ps(intf, dut, 0);
8221
Jouni Malinenba630452018-06-22 11:49:59 +03008222 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
8223 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008224 wpa_command(intf, "SET interworking 1");
8225 wpa_command(intf, "SET hs20 1");
8226 }
8227
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008228 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03008229 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008230 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008231 wpa_command(intf, "SET pmf 1");
8232 } else {
8233 wpa_command(intf, "SET pmf 0");
8234 }
8235
8236 hs2_clear_credentials(intf);
8237 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
8238 wpa_command(intf, "SET access_network_type 15");
8239
8240 static_ip_file(0, NULL, NULL, NULL);
8241 kill_dhcp_client(dut, intf);
8242 clear_ip_addr(dut, intf);
8243
8244 dut->er_oper_performed = 0;
8245 dut->er_oper_bssid[0] = '\0';
8246
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008247 if (dut->program == PROGRAM_LOC) {
8248 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008249 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008250 }
8251
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07008252 if (dut->program == PROGRAM_MBO || dut->program == PROGRAM_HE) {
Ashwini Patil00402582017-04-13 12:29:39 +05308253 free(dut->non_pref_ch_list);
8254 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05308255 free(dut->btm_query_cand_list);
8256 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05308257 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05308258 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05308259 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05308260 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05308261 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05308262 }
8263
Jouni Malinen3c367e82017-06-23 17:01:47 +03008264 free(dut->rsne_override);
8265 dut->rsne_override = NULL;
8266
Jouni Malinen68143132017-09-02 02:34:08 +03008267 free(dut->sae_commit_override);
8268 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03008269 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02008270 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03008271
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008272 dut->sta_associate_wait_connect = 0;
8273 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03008274 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008275 dut->sta_tod_policy = 0;
8276
Jouni Malinend86e5822017-08-29 03:55:32 +03008277 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02008278 free(dut->dpp_peer_uri);
8279 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02008280 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02008281 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03008282 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03008283
Jouni Malinenfac9cad2017-10-10 18:35:55 +03008284 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
8285
vamsi krishnaa2799492017-12-05 14:28:01 +05308286 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308287 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05308288 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05308289 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
8290 dut->fils_hlp = 0;
8291#ifdef ANDROID
8292 hlp_thread_cleanup(dut);
8293#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05308294 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308295
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308296 if (dut->program == PROGRAM_QM)
8297 wpa_command(intf, "SET interworking 1");
8298
Jouni Malinen8179fee2019-03-28 03:19:47 +02008299 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03008300 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02008301
Sunil Dutt076081f2018-02-05 19:45:50 +05308302#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008303 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05308304 dut->config_rsnie == 1) {
8305 dut->config_rsnie = 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308306 sta_config_params(dut, intf, STA_SET_RSNIE, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05308307 }
8308#endif /* NL80211_SUPPORT */
8309
Sunil Duttfebf8a82018-02-09 18:50:13 +05308310 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
8311 dut->dev_role = DEVROLE_STA_CFON;
8312 return sta_cfon_reset_default(dut, conn, cmd);
8313 }
8314
Jouni Malinen439352d2018-09-13 03:42:23 +03008315 wpa_command(intf, "SET setband AUTO");
8316
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308317 dut->ocvc = 0;
Jouni Malinen67433fc2020-06-26 22:50:33 +03008318 dut->client_privacy = 0;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05308319 dut->saquery_oci_freq = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308320
Sunil Duttfebf8a82018-02-09 18:50:13 +05308321 if (dut->program != PROGRAM_VHT)
8322 return cmd_sta_p2p_reset(dut, conn, cmd);
8323
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08008324 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008325}
8326
8327
Jouni Malinenf7222712019-06-13 01:50:21 +03008328static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
8329 struct sigma_conn *conn,
8330 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008331{
8332 const char *program = get_param(cmd, "Program");
8333
8334 if (program == NULL)
8335 return -1;
8336#ifdef ANDROID_NAN
8337 if (strcasecmp(program, "NAN") == 0)
8338 return nan_cmd_sta_get_events(dut, conn, cmd);
8339#endif /* ANDROID_NAN */
8340 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8341 return 0;
8342}
8343
8344
Jouni Malinen82905202018-04-29 17:20:10 +03008345static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
8346 struct sigma_cmd *cmd)
8347{
8348 const char *url = get_param(cmd, "url");
8349 const char *method = get_param(cmd, "method");
8350 pid_t pid;
8351 int status;
8352
8353 if (!url || !method)
8354 return -1;
8355
8356 /* TODO: Add support for method,post */
8357 if (strcasecmp(method, "get") != 0) {
8358 send_resp(dut, conn, SIGMA_ERROR,
8359 "ErrorCode,Unsupported method");
8360 return 0;
8361 }
8362
8363 pid = fork();
8364 if (pid < 0) {
8365 perror("fork");
8366 return -1;
8367 }
8368
8369 if (pid == 0) {
8370 char * argv[5] = { "wget", "-O", "/dev/null",
8371 (char *) url, NULL };
8372
8373 execv("/usr/bin/wget", argv);
8374 perror("execv");
8375 exit(0);
8376 return -1;
8377 }
8378
8379 if (waitpid(pid, &status, 0) < 0) {
8380 perror("waitpid");
8381 return -1;
8382 }
8383
8384 if (WIFEXITED(status)) {
8385 const char *errmsg;
8386
8387 if (WEXITSTATUS(status) == 0)
8388 return 1;
8389 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
8390 WEXITSTATUS(status));
8391 switch (WEXITSTATUS(status)) {
8392 case 4:
8393 errmsg = "errmsg,Network failure";
8394 break;
8395 case 8:
8396 errmsg = "errmsg,Server issued an error response";
8397 break;
8398 default:
8399 errmsg = "errmsg,Unknown failure from wget";
8400 break;
8401 }
8402 send_resp(dut, conn, SIGMA_ERROR, errmsg);
8403 return 0;
8404 }
8405
8406 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
8407 return 0;
8408}
8409
8410
Jouni Malinenf7222712019-06-13 01:50:21 +03008411static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
8412 struct sigma_conn *conn,
8413 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008414{
8415 const char *program = get_param(cmd, "Prog");
8416
Jouni Malinen82905202018-04-29 17:20:10 +03008417 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008418 return -1;
8419#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03008420 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008421 return nan_cmd_sta_exec_action(dut, conn, cmd);
8422#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03008423
8424 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07008425 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03008426
8427 if (get_param(cmd, "url"))
8428 return sta_exec_action_url(dut, conn, cmd);
8429
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008430 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8431 return 0;
8432}
8433
8434
Jouni Malinenf7222712019-06-13 01:50:21 +03008435static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
8436 struct sigma_conn *conn,
8437 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008438{
8439 const char *intf = get_param(cmd, "Interface");
8440 const char *val, *mcs32, *rate;
8441
8442 val = get_param(cmd, "GREENFIELD");
8443 if (val) {
8444 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
8445 /* Enable GD */
8446 send_resp(dut, conn, SIGMA_ERROR,
8447 "ErrorCode,GF not supported");
8448 return 0;
8449 }
8450 }
8451
8452 val = get_param(cmd, "SGI20");
8453 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008454 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008455 case DRIVER_ATHEROS:
8456 ath_sta_set_sgi(dut, intf, val);
8457 break;
8458 default:
8459 send_resp(dut, conn, SIGMA_ERROR,
8460 "ErrorCode,SGI20 not supported");
8461 return 0;
8462 }
8463 }
8464
8465 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
8466 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
8467 if (mcs32 && rate) {
8468 /* TODO */
8469 send_resp(dut, conn, SIGMA_ERROR,
8470 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
8471 return 0;
8472 } else if (mcs32 && !rate) {
8473 /* TODO */
8474 send_resp(dut, conn, SIGMA_ERROR,
8475 "ErrorCode,MCS32 not supported");
8476 return 0;
8477 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008478 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008479 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008480 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008481 ath_sta_set_11nrates(dut, intf, rate);
8482 break;
8483 default:
8484 send_resp(dut, conn, SIGMA_ERROR,
8485 "ErrorCode,MCS32_FIXEDRATE not supported");
8486 return 0;
8487 }
8488 }
8489
8490 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8491}
8492
8493
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008494static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8495 int mcs_config)
8496{
8497#ifdef NL80211_SUPPORT
8498 int ret;
8499
8500 switch (mcs_config) {
8501 case HE_80_MCS0_7:
8502 case HE_80_MCS0_9:
8503 case HE_80_MCS0_11:
8504 ret = sta_set_he_mcs(dut, intf, mcs_config);
8505 if (ret) {
8506 sigma_dut_print(dut, DUT_MSG_ERROR,
8507 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8508 mcs_config, ret);
8509 }
8510 break;
8511 default:
8512 sigma_dut_print(dut, DUT_MSG_ERROR,
8513 "cmd_set_max_he_mcs: Invalid mcs %d",
8514 mcs_config);
8515 break;
8516 }
8517#else /* NL80211_SUPPORT */
8518 sigma_dut_print(dut, DUT_MSG_ERROR,
8519 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8520#endif /* NL80211_SUPPORT */
8521}
8522
8523
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008524#define TWT_REQUEST_CMD 0
8525#define TWT_SUGGEST_CMD 1
8526#define TWT_DEMAND_CMD 2
8527
Arif Hussain480d5f42019-03-12 14:40:42 -07008528static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8529 struct sigma_cmd *cmd)
8530{
8531#ifdef NL80211_SUPPORT
8532 struct nlattr *params;
8533 struct nlattr *attr;
8534 struct nlattr *attr1;
8535 struct nl_msg *msg;
8536 int ifindex, ret;
8537 const char *val;
8538 const char *intf = get_param(cmd, "Interface");
8539 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8540 wake_interval_mantissa = 512;
8541 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008542 protection = 0, cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
Arif Hussain480d5f42019-03-12 14:40:42 -07008543
8544 ifindex = if_nametoindex(intf);
8545 if (ifindex == 0) {
8546 sigma_dut_print(dut, DUT_MSG_ERROR,
8547 "%s: Index for interface %s failed",
8548 __func__, intf);
8549 return -1;
8550 }
8551
8552 val = get_param(cmd, "FlowType");
8553 if (val) {
8554 flow_type = atoi(val);
8555 if (flow_type != 0 && flow_type != 1) {
8556 sigma_dut_print(dut, DUT_MSG_ERROR,
8557 "TWT: Invalid FlowType %d", flow_type);
8558 return -1;
8559 }
8560 }
8561
8562 val = get_param(cmd, "TWT_Trigger");
8563 if (val) {
8564 twt_trigger = atoi(val);
8565 if (twt_trigger != 0 && twt_trigger != 1) {
8566 sigma_dut_print(dut, DUT_MSG_ERROR,
8567 "TWT: Invalid TWT_Trigger %d",
8568 twt_trigger);
8569 return -1;
8570 }
8571 }
8572
8573 val = get_param(cmd, "Protection");
8574 if (val) {
8575 protection = atoi(val);
8576 if (protection != 0 && protection != 1) {
8577 sigma_dut_print(dut, DUT_MSG_ERROR,
8578 "TWT: Invalid Protection %d",
8579 protection);
8580 return -1;
8581 }
8582 }
8583
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008584 val = get_param(cmd, "SetupCommand");
8585 if (val) {
8586 cmd_type = atoi(val);
8587 if (cmd_type == TWT_REQUEST_CMD)
8588 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_REQUEST;
8589 else if (cmd_type == TWT_SUGGEST_CMD)
8590 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
8591 else if (cmd_type == TWT_DEMAND_CMD)
8592 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_DEMAND;
8593 else
8594 sigma_dut_print(dut, DUT_MSG_ERROR,
8595 "Default suggest is used for cmd %d",
8596 cmd_type);
8597 }
8598
Arif Hussain480d5f42019-03-12 14:40:42 -07008599 val = get_param(cmd, "TargetWakeTime");
8600 if (val)
8601 target_wake_time = atoi(val);
8602
8603 val = get_param(cmd, "WakeIntervalMantissa");
8604 if (val)
8605 wake_interval_mantissa = atoi(val);
8606
8607 val = get_param(cmd, "WakeIntervalExp");
8608 if (val)
8609 wake_interval_exp = atoi(val);
8610
8611 val = get_param(cmd, "NominalMinWakeDur");
8612 if (val)
8613 nominal_min_wake_dur = atoi(val);
8614
8615 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8616 NL80211_CMD_VENDOR)) ||
8617 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8618 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8619 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8620 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8621 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8622 !(params = nla_nest_start(
8623 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
8624 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8625 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8626 wake_interval_exp) ||
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008627 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, cmd_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008628 (twt_trigger &&
8629 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008630 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8631 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008632 (protection &&
8633 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008634 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8635 target_wake_time) ||
8636 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8637 nominal_min_wake_dur) ||
8638 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8639 wake_interval_mantissa)) {
8640 sigma_dut_print(dut, DUT_MSG_ERROR,
8641 "%s: err in adding vendor_cmd and vendor_data",
8642 __func__);
8643 nlmsg_free(msg);
8644 return -1;
8645 }
8646 nla_nest_end(msg, attr1);
8647 nla_nest_end(msg, params);
8648 nla_nest_end(msg, attr);
8649
8650 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8651 if (ret) {
8652 sigma_dut_print(dut, DUT_MSG_ERROR,
8653 "%s: err in send_and_recv_msgs, ret=%d",
8654 __func__, ret);
8655 }
8656
8657 return ret;
8658#else /* NL80211_SUPPORT */
8659 sigma_dut_print(dut, DUT_MSG_ERROR,
8660 "TWT request cannot be done without NL80211_SUPPORT defined");
8661 return -1;
8662#endif /* NL80211_SUPPORT */
8663}
8664
8665
8666static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8667 struct sigma_cmd *cmd)
8668{
8669 #ifdef NL80211_SUPPORT
8670 struct nlattr *params;
8671 struct nlattr *attr;
8672 struct nlattr *attr1;
8673 int ifindex, ret;
8674 struct nl_msg *msg;
8675 const char *intf = get_param(cmd, "Interface");
8676
8677 ifindex = if_nametoindex(intf);
8678 if (ifindex == 0) {
8679 sigma_dut_print(dut, DUT_MSG_ERROR,
8680 "%s: Index for interface %s failed",
8681 __func__, intf);
8682 return -1;
8683 }
8684
8685 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8686 NL80211_CMD_VENDOR)) ||
8687 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8688 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8689 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8690 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8691 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8692 !(params = nla_nest_start(
8693 msg,
8694 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8695 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8696 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8697 sigma_dut_print(dut, DUT_MSG_ERROR,
8698 "%s: err in adding vendor_cmd and vendor_data",
8699 __func__);
8700 nlmsg_free(msg);
8701 return -1;
8702 }
8703 nla_nest_end(msg, attr1);
8704 nla_nest_end(msg, params);
8705 nla_nest_end(msg, attr);
8706
8707 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8708 if (ret) {
8709 sigma_dut_print(dut, DUT_MSG_ERROR,
8710 "%s: err in send_and_recv_msgs, ret=%d",
8711 __func__, ret);
8712 }
8713
8714 return ret;
8715#else /* NL80211_SUPPORT */
8716 sigma_dut_print(dut, DUT_MSG_ERROR,
8717 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8718 return -1;
8719#endif /* NL80211_SUPPORT */
8720}
8721
8722
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008723static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8724 struct sigma_cmd *cmd)
8725{
8726#ifdef NL80211_SUPPORT
8727 struct nlattr *params;
8728 struct nlattr *attr;
8729 struct nlattr *attr1;
8730 struct nl_msg *msg;
8731 int ifindex, ret;
8732 const char *val;
8733 const char *intf = get_param(cmd, "Interface");
8734 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8735 ulmu_data_dis = 0;
8736
8737 ifindex = if_nametoindex(intf);
8738 if (ifindex == 0) {
8739 sigma_dut_print(dut, DUT_MSG_ERROR,
8740 "%s: Index for interface %s failed",
8741 __func__, intf);
8742 return -1;
8743 }
8744 val = get_param(cmd, "OMCtrl_RxNSS");
8745 if (val)
8746 rx_nss = atoi(val);
8747
8748 val = get_param(cmd, "OMCtrl_ChnlWidth");
8749 if (val)
8750 ch_bw = atoi(val);
8751
8752 val = get_param(cmd, "OMCtrl_ULMUDisable");
8753 if (val)
8754 ulmu_dis = atoi(val);
8755
8756 val = get_param(cmd, "OMCtrl_TxNSTS");
8757 if (val)
8758 tx_nsts = atoi(val);
8759
8760 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8761 if (val)
8762 ulmu_data_dis = atoi(val);
8763
8764 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8765 NL80211_CMD_VENDOR)) ||
8766 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8767 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8768 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8769 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8770 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8771 !(params = nla_nest_start(
8772 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8773 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8774 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8775 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8776 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8777 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8778 ulmu_data_dis) ||
8779 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8780 ulmu_dis)) {
8781 sigma_dut_print(dut, DUT_MSG_ERROR,
8782 "%s: err in adding vendor_cmd and vendor_data",
8783 __func__);
8784 nlmsg_free(msg);
8785 return -1;
8786 }
8787 nla_nest_end(msg, attr1);
8788 nla_nest_end(msg, params);
8789 nla_nest_end(msg, attr);
8790
8791 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8792 if (ret) {
8793 sigma_dut_print(dut, DUT_MSG_ERROR,
8794 "%s: err in send_and_recv_msgs, ret=%d",
8795 __func__, ret);
8796 }
8797
8798 return ret;
8799#else /* NL80211_SUPPORT */
8800 sigma_dut_print(dut, DUT_MSG_ERROR,
8801 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8802 return -1;
8803#endif /* NL80211_SUPPORT */
8804}
8805
8806
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008807static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8808 struct sigma_conn *conn,
8809 struct sigma_cmd *cmd)
8810{
8811 const char *intf = get_param(cmd, "Interface");
8812 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008813 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008814 int tkip = -1;
8815 int wep = -1;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308816 int iwpriv_status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008817
Arif Hussaina37e9552018-06-20 17:05:59 -07008818 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008819 val = get_param(cmd, "SGI80");
8820 if (val) {
8821 int sgi80;
8822
8823 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008824 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008825 }
8826
8827 val = get_param(cmd, "TxBF");
8828 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008829 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008830 case DRIVER_WCN:
8831 if (sta_set_tx_beamformee(dut, intf, 1)) {
8832 send_resp(dut, conn, SIGMA_ERROR,
8833 "ErrorCode,Failed to set TX beamformee enable");
8834 return 0;
8835 }
8836 break;
8837 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008838 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008839 send_resp(dut, conn, SIGMA_ERROR,
8840 "ErrorCode,Setting vhtsubfee failed");
8841 return 0;
8842 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008843 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008844 send_resp(dut, conn, SIGMA_ERROR,
8845 "ErrorCode,Setting vhtsubfer failed");
8846 return 0;
8847 }
8848 break;
8849 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008850 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008851 "Unsupported driver type");
8852 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008853 }
8854 }
8855
8856 val = get_param(cmd, "MU_TxBF");
8857 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008858 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008859 case DRIVER_ATHEROS:
8860 ath_sta_set_txsp_stream(dut, intf, "1SS");
8861 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008862 run_iwpriv(dut, intf, "vhtmubfee 1");
8863 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308864 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008865 case DRIVER_WCN:
8866 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8867 send_resp(dut, conn, SIGMA_ERROR,
8868 "ErrorCode,Failed to set RX/TXSP_STREAM");
8869 return 0;
8870 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308871 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008872 default:
8873 sigma_dut_print(dut, DUT_MSG_ERROR,
8874 "Setting SP_STREAM not supported");
8875 break;
8876 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008877 }
8878
8879 val = get_param(cmd, "LDPC");
8880 if (val) {
8881 int ldpc;
8882
8883 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308884 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", ldpc);
8885 if (iwpriv_status)
8886 sta_config_params(dut, intf, STA_SET_LDPC, ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008887 }
8888
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008889 val = get_param(cmd, "BCC");
8890 if (val) {
8891 int bcc;
8892
8893 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8894 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8895 * is mutually exclusive to bcc */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308896 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", !bcc);
8897 if (iwpriv_status)
8898 sta_config_params(dut, intf, STA_SET_LDPC, !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008899 }
8900
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008901 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8902 if (val && dut->sta_nss == 1)
8903 cmd_set_max_he_mcs(dut, intf, atoi(val));
8904
8905 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8906 if (val && dut->sta_nss == 2)
8907 cmd_set_max_he_mcs(dut, intf, atoi(val));
8908
Arif Hussainac6c5112018-05-25 17:34:00 -07008909 val = get_param(cmd, "MCS_FixedRate");
8910 if (val) {
8911#ifdef NL80211_SUPPORT
8912 int mcs, ratecode = 0;
8913 enum he_mcs_config mcs_config;
8914 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008915 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008916
8917 ratecode = (0x07 & dut->sta_nss) << 5;
8918 mcs = atoi(val);
8919 /* Add the MCS to the ratecode */
8920 if (mcs >= 0 && mcs <= 11) {
8921 ratecode += mcs;
8922 if (dut->device_type == STA_testbed &&
8923 mcs > 7 && mcs <= 11) {
8924 if (mcs <= 9)
8925 mcs_config = HE_80_MCS0_9;
8926 else
8927 mcs_config = HE_80_MCS0_11;
8928 ret = sta_set_he_mcs(dut, intf, mcs_config);
8929 if (ret) {
8930 sigma_dut_print(dut, DUT_MSG_ERROR,
8931 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8932 mcs, mcs_config, ret);
8933 }
8934 }
8935 snprintf(buf, sizeof(buf),
8936 "iwpriv %s set_11ax_rate 0x%03x",
8937 intf, ratecode);
8938 if (system(buf) != 0) {
8939 sigma_dut_print(dut, DUT_MSG_ERROR,
8940 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8941 ratecode);
8942 }
8943 } else {
8944 sigma_dut_print(dut, DUT_MSG_ERROR,
8945 "MCS_FixedRate: HE MCS %d not supported",
8946 mcs);
8947 }
8948#else /* NL80211_SUPPORT */
8949 sigma_dut_print(dut, DUT_MSG_ERROR,
8950 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8951#endif /* NL80211_SUPPORT */
8952 }
8953
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008954 val = get_param(cmd, "opt_md_notif_ie");
8955 if (val) {
8956 char *result = NULL;
8957 char delim[] = ";";
8958 char token[30];
8959 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308960 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008961
Peng Xub8fc5cc2017-05-10 17:27:28 -07008962 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308963 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008964
8965 /* Extract the NSS information */
8966 if (result) {
8967 value = atoi(result);
8968 switch (value) {
8969 case 1:
8970 config_val = 1;
8971 break;
8972 case 2:
8973 config_val = 3;
8974 break;
8975 case 3:
8976 config_val = 7;
8977 break;
8978 case 4:
8979 config_val = 15;
8980 break;
8981 default:
8982 config_val = 3;
8983 break;
8984 }
8985
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008986 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8987 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008988
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008989 }
8990
8991 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308992 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008993 if (result) {
8994 value = atoi(result);
8995 switch (value) {
8996 case 20:
8997 config_val = 0;
8998 break;
8999 case 40:
9000 config_val = 1;
9001 break;
9002 case 80:
9003 config_val = 2;
9004 break;
9005 case 160:
9006 config_val = 3;
9007 break;
9008 default:
9009 config_val = 2;
9010 break;
9011 }
9012
9013 dut->chwidth = config_val;
9014
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009015 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009016 }
9017
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009018 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009019 }
9020
9021 val = get_param(cmd, "nss_mcs_cap");
9022 if (val) {
9023 int nss, mcs;
9024 char token[20];
9025 char *result = NULL;
9026 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309027 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009028
Peng Xub8fc5cc2017-05-10 17:27:28 -07009029 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309030 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309031 if (!result) {
9032 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009033 "NSS not specified");
9034 send_resp(dut, conn, SIGMA_ERROR,
9035 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309036 return 0;
9037 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009038 nss = atoi(result);
9039
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009040 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07009041 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009042
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309043 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009044 if (result == NULL) {
9045 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009046 "MCS not specified");
9047 send_resp(dut, conn, SIGMA_ERROR,
9048 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009049 return 0;
9050 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309051 result = strtok_r(result, "-", &saveptr);
9052 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309053 if (!result) {
9054 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009055 "MCS not specified");
9056 send_resp(dut, conn, SIGMA_ERROR,
9057 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309058 return 0;
9059 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009060 mcs = atoi(result);
9061
Arif Hussaina37e9552018-06-20 17:05:59 -07009062 if (program && strcasecmp(program, "HE") == 0) {
9063#ifdef NL80211_SUPPORT
9064 enum he_mcs_config mcs_config;
9065 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009066
Arif Hussaina37e9552018-06-20 17:05:59 -07009067 if (mcs >= 0 && mcs <= 7) {
9068 mcs_config = HE_80_MCS0_7;
9069 } else if (mcs > 7 && mcs <= 9) {
9070 mcs_config = HE_80_MCS0_9;
9071 } else if (mcs > 9 && mcs <= 11) {
9072 mcs_config = HE_80_MCS0_11;
9073 } else {
9074 sigma_dut_print(dut, DUT_MSG_ERROR,
9075 "nss_mcs_cap: HE: Invalid mcs: %d",
9076 mcs);
9077 send_resp(dut, conn, SIGMA_ERROR,
9078 "errorCode,Invalid MCS");
9079 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009080 }
Arif Hussaina37e9552018-06-20 17:05:59 -07009081
9082 ret = sta_set_he_mcs(dut, intf, mcs_config);
9083 if (ret) {
9084 sigma_dut_print(dut, DUT_MSG_ERROR,
9085 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
9086 mcs_config, ret);
9087 send_resp(dut, conn, SIGMA_ERROR,
9088 "errorCode,Failed to set MCS");
9089 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009090 }
Arif Hussaina37e9552018-06-20 17:05:59 -07009091#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009092 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009093 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
9094#endif /* NL80211_SUPPORT */
9095 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009096 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07009097
9098 switch (nss) {
9099 case 1:
9100 switch (mcs) {
9101 case 7:
9102 vht_mcsmap = 0xfffc;
9103 break;
9104 case 8:
9105 vht_mcsmap = 0xfffd;
9106 break;
9107 case 9:
9108 vht_mcsmap = 0xfffe;
9109 break;
9110 default:
9111 vht_mcsmap = 0xfffe;
9112 break;
9113 }
9114 break;
9115 case 2:
9116 switch (mcs) {
9117 case 7:
9118 vht_mcsmap = 0xfff0;
9119 break;
9120 case 8:
9121 vht_mcsmap = 0xfff5;
9122 break;
9123 case 9:
9124 vht_mcsmap = 0xfffa;
9125 break;
9126 default:
9127 vht_mcsmap = 0xfffa;
9128 break;
9129 }
9130 break;
9131 case 3:
9132 switch (mcs) {
9133 case 7:
9134 vht_mcsmap = 0xffc0;
9135 break;
9136 case 8:
9137 vht_mcsmap = 0xffd5;
9138 break;
9139 case 9:
9140 vht_mcsmap = 0xffea;
9141 break;
9142 default:
9143 vht_mcsmap = 0xffea;
9144 break;
9145 }
9146 break;
9147 default:
9148 vht_mcsmap = 0xffea;
9149 break;
9150 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009151 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009152 }
9153 }
9154
9155 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
9156
9157 val = get_param(cmd, "Vht_tkip");
9158 if (val)
9159 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9160
9161 val = get_param(cmd, "Vht_wep");
9162 if (val)
9163 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9164
9165 if (tkip != -1 || wep != -1) {
9166 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009167 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009168 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009169 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009170 } else {
9171 sigma_dut_print(dut, DUT_MSG_ERROR,
9172 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
9173 return 0;
9174 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009175 }
9176
Arif Hussain55f00da2018-07-03 08:28:26 -07009177 val = get_param(cmd, "txBandwidth");
9178 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009179 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07009180 case DRIVER_WCN:
9181 if (wcn_sta_set_width(dut, intf, val) < 0) {
9182 send_resp(dut, conn, SIGMA_ERROR,
9183 "ErrorCode,Failed to set txBandwidth");
9184 return 0;
9185 }
9186 break;
9187 case DRIVER_ATHEROS:
9188 if (ath_set_width(dut, conn, intf, val) < 0) {
9189 send_resp(dut, conn, SIGMA_ERROR,
9190 "ErrorCode,Failed to set txBandwidth");
9191 return 0;
9192 }
9193 break;
9194 default:
9195 sigma_dut_print(dut, DUT_MSG_ERROR,
9196 "Setting txBandwidth not supported");
9197 break;
9198 }
9199 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009200
Arif Hussain9765f7d2018-07-03 08:28:26 -07009201 val = get_param(cmd, "BeamformeeSTS");
9202 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07009203 if (sta_set_tx_beamformee(dut, intf, 1)) {
9204 send_resp(dut, conn, SIGMA_ERROR,
9205 "ErrorCode,Failed to set TX beamformee enable");
9206 return 0;
9207 }
9208
Arif Hussain9765f7d2018-07-03 08:28:26 -07009209 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
9210 send_resp(dut, conn, SIGMA_ERROR,
9211 "ErrorCode,Failed to set BeamformeeSTS");
9212 return 0;
9213 }
9214 }
9215
Arif Hussain68d23f52018-07-11 13:39:08 -07009216 val = get_param(cmd, "Trig_MAC_Padding_Dur");
9217 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07009218#ifdef NL80211_SUPPORT
9219 enum qca_wlan_he_mac_padding_dur set_val;
9220
9221 switch (atoi(val)) {
9222 case 16:
9223 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
9224 break;
9225 case 8:
9226 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
9227 break;
9228 default:
9229 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
9230 break;
9231 }
9232 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07009233 send_resp(dut, conn, SIGMA_ERROR,
9234 "ErrorCode,Failed to set MAC padding duration");
9235 return 0;
9236 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07009237#else /* NL80211_SUPPORT */
9238 sigma_dut_print(dut, DUT_MSG_ERROR,
9239 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
9240#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07009241 }
9242
Arif Hussain480d5f42019-03-12 14:40:42 -07009243 val = get_param(cmd, "TWT_ReqSupport");
9244 if (val) {
9245 int set_val;
9246
9247 if (strcasecmp(val, "Enable") == 0) {
9248 set_val = 1;
9249 } else if (strcasecmp(val, "Disable") == 0) {
9250 set_val = 0;
9251 } else {
9252 send_resp(dut, conn, SIGMA_ERROR,
9253 "ErrorCode,Invalid TWT_ReqSupport");
9254 return STATUS_SENT;
9255 }
9256
9257 if (sta_set_twt_req_support(dut, intf, set_val)) {
9258 sigma_dut_print(dut, DUT_MSG_ERROR,
9259 "Failed to set TWT req support %d",
9260 set_val);
9261 send_resp(dut, conn, SIGMA_ERROR,
9262 "ErrorCode,Failed to set TWT_ReqSupport");
9263 return STATUS_SENT;
9264 }
9265 }
9266
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07009267 val = get_param(cmd, "MU_EDCA");
9268 if (val && (strcasecmp(val, "Override") == 0)) {
9269 if (sta_set_mu_edca_override(dut, intf, 1)) {
9270 send_resp(dut, conn, SIGMA_ERROR,
9271 "ErrorCode,Failed to set MU EDCA override");
9272 return 0;
9273 }
9274 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009275
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07009276 val = get_param(cmd, "OMControl");
9277 if (val) {
9278 int set_val = 1;
9279
9280 if (strcasecmp(val, "Enable") == 0)
9281 set_val = 1;
9282 else if (strcasecmp(val, "Disable") == 0)
9283 set_val = 0;
9284
9285 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
9286 send_resp(dut, conn, SIGMA_ERROR,
9287 "ErrorCode,Failed to set OM ctrl supp");
9288 return 0;
9289 }
9290 }
9291
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009292 val = get_param(cmd, "ADDBAResp_BufSize");
9293 if (val) {
9294 int buf_size;
9295
9296 if (strcasecmp(val, "gt64") == 0)
9297 buf_size = 256;
9298 else
9299 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009300 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009301 sta_set_addba_buf_size(dut, intf, buf_size)) {
9302 send_resp(dut, conn, SIGMA_ERROR,
9303 "ErrorCode,set addbaresp_buff_size failed");
9304 return 0;
9305 }
9306 }
9307
9308 val = get_param(cmd, "ADDBAReq_BufSize");
9309 if (val) {
9310 int buf_size;
9311
9312 if (strcasecmp(val, "gt64") == 0)
9313 buf_size = 256;
9314 else
9315 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009316 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009317 sta_set_addba_buf_size(dut, intf, buf_size)) {
9318 send_resp(dut, conn, SIGMA_ERROR,
9319 "ErrorCode,set addbareq_buff_size failed");
9320 return 0;
9321 }
9322 }
9323
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009324 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9325}
9326
9327
9328static int sta_set_wireless_60g(struct sigma_dut *dut,
9329 struct sigma_conn *conn,
9330 struct sigma_cmd *cmd)
9331{
9332 const char *dev_role = get_param(cmd, "DevRole");
9333
9334 if (!dev_role) {
9335 send_resp(dut, conn, SIGMA_INVALID,
9336 "ErrorCode,DevRole not specified");
9337 return 0;
9338 }
9339
9340 if (strcasecmp(dev_role, "PCP") == 0)
9341 return sta_set_60g_pcp(dut, conn, cmd);
9342 if (strcasecmp(dev_role, "STA") == 0)
9343 return sta_set_60g_sta(dut, conn, cmd);
9344 send_resp(dut, conn, SIGMA_INVALID,
9345 "ErrorCode,DevRole not supported");
9346 return 0;
9347}
9348
9349
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309350static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
9351 struct sigma_cmd *cmd)
9352{
9353 int status;
9354 const char *intf = get_param(cmd, "Interface");
9355 const char *val = get_param(cmd, "DevRole");
9356
9357 if (val && strcasecmp(val, "STA-CFON") == 0) {
9358 status = sta_cfon_set_wireless(dut, conn, cmd);
9359 if (status)
9360 return status;
9361 }
9362 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9363}
9364
9365
Jouni Malinen67433fc2020-06-26 22:50:33 +03009366static enum sigma_cmd_result
9367sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
9368 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309369{
9370 const char *intf = get_param(cmd, "Interface");
9371 const char *val;
9372
9373 val = get_param(cmd, "ocvc");
9374 if (val)
9375 dut->ocvc = atoi(val);
9376
Jouni Malinen67433fc2020-06-26 22:50:33 +03009377 val = get_param(cmd, "ClientPrivacy");
9378 if (val) {
9379 dut->client_privacy = atoi(val);
9380 if (dut->client_privacy &&
9381 (wpa_command(intf, "SET mac_addr 1") < 0 ||
9382 wpa_command(intf, "SET rand_addr_lifetime 1") < 0 ||
9383 wpa_command(intf, "SET preassoc_mac_addr 1") < 0 ||
9384 wpa_command(intf, "SET gas_rand_mac_addr 1") < 0 ||
9385 wpa_command(intf, "SET gas_rand_addr_lifetime 1") < 0)) {
9386 send_resp(dut, conn, SIGMA_ERROR,
9387 "errorCode,Failed to enable random MAC address use");
9388 return STATUS_SENT_ERROR;
9389 }
9390 }
9391
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309392 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9393}
9394
9395
Jouni Malinenf7222712019-06-13 01:50:21 +03009396static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
9397 struct sigma_conn *conn,
9398 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009399{
9400 const char *val;
9401
9402 val = get_param(cmd, "Program");
9403 if (val) {
9404 if (strcasecmp(val, "11n") == 0)
9405 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08009406 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009407 return cmd_sta_set_wireless_vht(dut, conn, cmd);
9408 if (strcasecmp(val, "60ghz") == 0)
9409 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309410 if (strcasecmp(val, "OCE") == 0)
9411 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02009412 /* sta_set_wireless in WPS program is only used for 60G */
9413 if (is_60g_sigma_dut(dut))
9414 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309415 if (strcasecmp(val, "WPA3") == 0)
9416 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009417 send_resp(dut, conn, SIGMA_ERROR,
9418 "ErrorCode,Program value not supported");
9419 } else {
9420 send_resp(dut, conn, SIGMA_ERROR,
9421 "ErrorCode,Program argument not available");
9422 }
9423
9424 return 0;
9425}
9426
9427
9428static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
9429 int tid)
9430{
9431 char buf[100];
9432 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
9433
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05309434 if (tid < 0 ||
9435 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
9436 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
9437 return;
9438 }
9439
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009440 /*
9441 * Two ways to ensure that addba request with a
9442 * non zero TID could be sent out. EV 117296
9443 */
9444 snprintf(buf, sizeof(buf),
9445 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
9446 tid);
9447 if (system(buf) != 0) {
9448 sigma_dut_print(dut, DUT_MSG_ERROR,
9449 "Ping did not send out");
9450 }
9451
9452 snprintf(buf, sizeof(buf),
9453 "iwconfig %s | grep Access | awk '{print $6}' > %s",
9454 intf, VI_QOS_TMP_FILE);
9455 if (system(buf) != 0)
9456 return;
9457
9458 snprintf(buf, sizeof(buf),
9459 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
9460 intf, VI_QOS_TMP_FILE);
9461 if (system(buf) != 0)
9462 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
9463
9464 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
9465 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
9466 if (system(buf) != 0) {
9467 sigma_dut_print(dut, DUT_MSG_ERROR,
9468 "VI_QOS_TEMP_FILE generation error failed");
9469 }
9470 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9471 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9472 if (system(buf) != 0) {
9473 sigma_dut_print(dut, DUT_MSG_ERROR,
9474 "VI_QOS_FILE generation failed");
9475 }
9476
9477 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9478 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9479 if (system(buf) != 0) {
9480 sigma_dut_print(dut, DUT_MSG_ERROR,
9481 "VI_QOS_FILE generation failed");
9482 }
9483
9484 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
9485 if (system(buf) != 0) {
9486 }
9487}
9488
9489
9490static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9491 struct sigma_cmd *cmd)
9492{
9493 const char *intf = get_param(cmd, "Interface");
9494 const char *val;
9495 int tid = 0;
9496 char buf[100];
9497
9498 val = get_param(cmd, "TID");
9499 if (val) {
9500 tid = atoi(val);
9501 if (tid)
9502 ath_sta_inject_frame(dut, intf, tid);
9503 }
9504
9505 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009506 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009507
9508 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
9509 if (system(buf) != 0) {
9510 sigma_dut_print(dut, DUT_MSG_ERROR,
9511 "wifitool senddelba failed");
9512 }
9513
9514 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
9515 if (system(buf) != 0) {
9516 sigma_dut_print(dut, DUT_MSG_ERROR,
9517 "wifitool sendaddba failed");
9518 }
9519
9520 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9521
9522 return 1;
9523}
9524
9525
Lior David9981b512017-01-20 13:16:40 +02009526#ifdef __linux__
9527
9528static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
9529 int agg_size)
9530{
9531 char dir[128], buf[128];
9532 FILE *f;
9533 regex_t re;
9534 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03009535 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02009536
9537 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
9538 sigma_dut_print(dut, DUT_MSG_ERROR,
9539 "failed to get wil6210 debugfs dir");
9540 return -1;
9541 }
9542
Jouni Malinen3aa72862019-05-29 23:14:51 +03009543 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
9544 if (res < 0 || res >= sizeof(buf))
9545 return -1;
Lior David9981b512017-01-20 13:16:40 +02009546 f = fopen(buf, "r");
9547 if (!f) {
9548 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009549 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009550 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9551 if (res < 0 || res >= sizeof(buf))
9552 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009553 f = fopen(buf, "r");
9554 if (!f) {
9555 sigma_dut_print(dut, DUT_MSG_ERROR,
9556 "failed to open: %s", buf);
9557 return -1;
9558 }
Lior David9981b512017-01-20 13:16:40 +02009559 }
9560
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009561 /* can be either VRING tx... or RING... */
9562 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009563 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9564 goto out;
9565 }
9566
9567 /* find TX VRING for the mac address */
9568 found = 0;
9569 while (fgets(buf, sizeof(buf), f)) {
9570 if (strcasestr(buf, dest_mac)) {
9571 found = 1;
9572 break;
9573 }
9574 }
9575
9576 if (!found) {
9577 sigma_dut_print(dut, DUT_MSG_ERROR,
9578 "no TX VRING for %s", dest_mac);
9579 goto out;
9580 }
9581
9582 /* extract VRING ID, "VRING tx_<id> = {" */
9583 if (!fgets(buf, sizeof(buf), f)) {
9584 sigma_dut_print(dut, DUT_MSG_ERROR,
9585 "no VRING start line for %s", dest_mac);
9586 goto out;
9587 }
9588
9589 rc = regexec(&re, buf, 2, m, 0);
9590 regfree(&re);
9591 if (rc || m[1].rm_so < 0) {
9592 sigma_dut_print(dut, DUT_MSG_ERROR,
9593 "no VRING TX ID for %s", dest_mac);
9594 goto out;
9595 }
9596 buf[m[1].rm_eo] = 0;
9597 vring_id = atoi(&buf[m[1].rm_so]);
9598
9599 /* send the addba command */
9600 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009601 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9602 if (res < 0 || res >= sizeof(buf))
9603 return -1;
Lior David9981b512017-01-20 13:16:40 +02009604 f = fopen(buf, "w");
9605 if (!f) {
9606 sigma_dut_print(dut, DUT_MSG_ERROR,
9607 "failed to open: %s", buf);
9608 return -1;
9609 }
9610
9611 fprintf(f, "add %d %d\n", vring_id, agg_size);
9612
9613 ret = 0;
9614
9615out:
9616 fclose(f);
9617
9618 return ret;
9619}
9620
9621
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009622int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9623 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009624{
9625 const char *val;
9626 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009627
9628 val = get_param(cmd, "TID");
9629 if (val) {
9630 tid = atoi(val);
9631 if (tid != 0) {
9632 sigma_dut_print(dut, DUT_MSG_ERROR,
9633 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9634 tid);
9635 }
9636 }
9637
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009638 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009639 if (!val) {
9640 sigma_dut_print(dut, DUT_MSG_ERROR,
9641 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009642 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009643 }
9644
Lior David9981b512017-01-20 13:16:40 +02009645 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009646 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009647
9648 return 1;
9649}
9650
Lior David9981b512017-01-20 13:16:40 +02009651#endif /* __linux__ */
9652
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009653
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009654static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9655 struct sigma_cmd *cmd)
9656{
9657#ifdef NL80211_SUPPORT
9658 const char *intf = get_param(cmd, "Interface");
9659 const char *val;
9660 int tid = -1;
9661 int bufsize = 64;
9662 struct nl_msg *msg;
9663 int ret = 0;
9664 struct nlattr *params;
9665 int ifindex;
9666
9667 val = get_param(cmd, "TID");
9668 if (val)
9669 tid = atoi(val);
9670
9671 if (tid == -1) {
9672 send_resp(dut, conn, SIGMA_ERROR,
9673 "ErrorCode,sta_send_addba tid invalid");
9674 return 0;
9675 }
9676
9677 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9678
9679 ifindex = if_nametoindex(intf);
9680 if (ifindex == 0) {
9681 sigma_dut_print(dut, DUT_MSG_ERROR,
9682 "%s: Index for interface %s failed",
9683 __func__, intf);
9684 send_resp(dut, conn, SIGMA_ERROR,
9685 "ErrorCode,sta_send_addba interface invalid");
9686 return 0;
9687 }
9688
9689 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9690 NL80211_CMD_VENDOR)) ||
9691 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9692 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9693 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9694 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9695 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9696 nla_put_u8(msg,
9697 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9698 QCA_WLAN_ADD_BA) ||
9699 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9700 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009701 nla_put_u16(msg,
9702 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9703 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009704 sigma_dut_print(dut, DUT_MSG_ERROR,
9705 "%s: err in adding vendor_cmd and vendor_data",
9706 __func__);
9707 nlmsg_free(msg);
9708 send_resp(dut, conn, SIGMA_ERROR,
9709 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9710 return 0;
9711 }
9712 nla_nest_end(msg, params);
9713
9714 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9715 if (ret) {
9716 sigma_dut_print(dut, DUT_MSG_ERROR,
9717 "%s: err in send_and_recv_msgs, ret=%d",
9718 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309719 if (ret == -EOPNOTSUPP)
9720 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009721 send_resp(dut, conn, SIGMA_ERROR,
9722 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9723 return 0;
9724 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009725#else /* NL80211_SUPPORT */
9726 sigma_dut_print(dut, DUT_MSG_ERROR,
9727 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009728#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309729
9730 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009731}
9732
9733
Jouni Malinenf7222712019-06-13 01:50:21 +03009734static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9735 struct sigma_conn *conn,
9736 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009737{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009738 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009739 case DRIVER_ATHEROS:
9740 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009741 case DRIVER_WCN:
9742 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009743#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009744 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009745 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009746#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009747 default:
9748 /*
9749 * There is no driver specific implementation for other drivers.
9750 * Ignore the command and report COMPLETE since the following
9751 * throughput test operation will end up sending ADDBA anyway.
9752 */
9753 return 1;
9754 }
9755}
9756
9757
9758int inject_eth_frame(int s, const void *data, size_t len,
9759 unsigned short ethtype, char *dst, char *src)
9760{
9761 struct iovec iov[4] = {
9762 {
9763 .iov_base = dst,
9764 .iov_len = ETH_ALEN,
9765 },
9766 {
9767 .iov_base = src,
9768 .iov_len = ETH_ALEN,
9769 },
9770 {
9771 .iov_base = &ethtype,
9772 .iov_len = sizeof(unsigned short),
9773 },
9774 {
9775 .iov_base = (void *) data,
9776 .iov_len = len,
9777 }
9778 };
9779 struct msghdr msg = {
9780 .msg_name = NULL,
9781 .msg_namelen = 0,
9782 .msg_iov = iov,
9783 .msg_iovlen = 4,
9784 .msg_control = NULL,
9785 .msg_controllen = 0,
9786 .msg_flags = 0,
9787 };
9788
9789 return sendmsg(s, &msg, 0);
9790}
9791
9792#if defined(__linux__) || defined(__QNXNTO__)
9793
9794int inject_frame(int s, const void *data, size_t len, int encrypt)
9795{
9796#define IEEE80211_RADIOTAP_F_WEP 0x04
9797#define IEEE80211_RADIOTAP_F_FRAG 0x08
9798 unsigned char rtap_hdr[] = {
9799 0x00, 0x00, /* radiotap version */
9800 0x0e, 0x00, /* radiotap length */
9801 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9802 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9803 0x00, /* padding */
9804 0x00, 0x00, /* RX and TX flags to indicate that */
9805 0x00, 0x00, /* this is the injected frame directly */
9806 };
9807 struct iovec iov[2] = {
9808 {
9809 .iov_base = &rtap_hdr,
9810 .iov_len = sizeof(rtap_hdr),
9811 },
9812 {
9813 .iov_base = (void *) data,
9814 .iov_len = len,
9815 }
9816 };
9817 struct msghdr msg = {
9818 .msg_name = NULL,
9819 .msg_namelen = 0,
9820 .msg_iov = iov,
9821 .msg_iovlen = 2,
9822 .msg_control = NULL,
9823 .msg_controllen = 0,
9824 .msg_flags = 0,
9825 };
9826
9827 if (encrypt)
9828 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9829
9830 return sendmsg(s, &msg, 0);
9831}
9832
9833
9834int open_monitor(const char *ifname)
9835{
9836#ifdef __QNXNTO__
9837 struct sockaddr_dl ll;
9838 int s;
9839
9840 memset(&ll, 0, sizeof(ll));
9841 ll.sdl_family = AF_LINK;
9842 ll.sdl_index = if_nametoindex(ifname);
9843 if (ll.sdl_index == 0) {
9844 perror("if_nametoindex");
9845 return -1;
9846 }
9847 s = socket(PF_INET, SOCK_RAW, 0);
9848#else /* __QNXNTO__ */
9849 struct sockaddr_ll ll;
9850 int s;
9851
9852 memset(&ll, 0, sizeof(ll));
9853 ll.sll_family = AF_PACKET;
9854 ll.sll_ifindex = if_nametoindex(ifname);
9855 if (ll.sll_ifindex == 0) {
9856 perror("if_nametoindex");
9857 return -1;
9858 }
9859 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9860#endif /* __QNXNTO__ */
9861 if (s < 0) {
9862 perror("socket[PF_PACKET,SOCK_RAW]");
9863 return -1;
9864 }
9865
9866 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9867 perror("monitor socket bind");
9868 close(s);
9869 return -1;
9870 }
9871
9872 return s;
9873}
9874
9875
9876static int hex2num(char c)
9877{
9878 if (c >= '0' && c <= '9')
9879 return c - '0';
9880 if (c >= 'a' && c <= 'f')
9881 return c - 'a' + 10;
9882 if (c >= 'A' && c <= 'F')
9883 return c - 'A' + 10;
9884 return -1;
9885}
9886
9887
9888int hwaddr_aton(const char *txt, unsigned char *addr)
9889{
9890 int i;
9891
9892 for (i = 0; i < 6; i++) {
9893 int a, b;
9894
9895 a = hex2num(*txt++);
9896 if (a < 0)
9897 return -1;
9898 b = hex2num(*txt++);
9899 if (b < 0)
9900 return -1;
9901 *addr++ = (a << 4) | b;
9902 if (i < 5 && *txt++ != ':')
9903 return -1;
9904 }
9905
9906 return 0;
9907}
9908
9909#endif /* defined(__linux__) || defined(__QNXNTO__) */
9910
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309911
9912#ifdef NL80211_SUPPORT
9913static int nl80211_send_frame_cmd(struct sigma_dut *dut, const char *intf,
9914 const u8 *data, size_t data_len, int freq)
9915{
9916 struct nl_msg *msg;
9917 int ret = 0;
9918 int ifindex;
9919
9920 ifindex = if_nametoindex(intf);
9921 if (ifindex == 0) {
9922 sigma_dut_print(dut, DUT_MSG_ERROR,
9923 "%s: Index for interface %s failed",
9924 __func__, intf);
9925 return -1;
9926 }
9927
9928 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9929 NL80211_CMD_FRAME)) ||
9930 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
9931 nla_put(msg, NL80211_ATTR_FRAME, data_len, data)) {
9932 sigma_dut_print(dut, DUT_MSG_ERROR,
9933 "%s: Error in adding NL80211_CMD_FRAME",
9934 __func__);
9935 nlmsg_free(msg);
9936 return -1;
9937 }
9938
9939 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9940 if (ret) {
9941 sigma_dut_print(dut, DUT_MSG_ERROR,
9942 "nl80211: Frame command failed: ret=%d (%s) req=%u",
9943 ret, strerror(-ret), freq);
9944 return -1;
9945 }
9946
9947 return 0;
9948}
9949#endif /* NL80211_SUPPORT */
9950
9951
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009952enum send_frame_type {
9953 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9954};
9955enum send_frame_protection {
9956 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9957};
9958
9959
9960static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309961 const char *intf, enum send_frame_type frame,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009962 enum send_frame_protection protected,
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309963 const char *dest, int use_monitor)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009964{
9965#ifdef __linux__
9966 unsigned char buf[1000], *pos;
9967 int s, res;
9968 char bssid[20], addr[20];
9969 char result[32], ssid[100];
9970 size_t ssid_len;
9971
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009972 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009973 sizeof(result)) < 0 ||
9974 strncmp(result, "COMPLETED", 9) != 0) {
9975 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9976 return 0;
9977 }
9978
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009979 if (get_wpa_status(get_station_ifname(dut), "bssid",
9980 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009981 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9982 "current BSSID");
9983 return 0;
9984 }
9985
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009986 if (get_wpa_status(get_station_ifname(dut), "address",
9987 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009988 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9989 "own MAC address");
9990 return 0;
9991 }
9992
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009993 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009994 < 0) {
9995 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9996 "current SSID");
9997 return 0;
9998 }
9999 ssid_len = strlen(ssid);
10000
10001 pos = buf;
10002
10003 /* Frame Control */
10004 switch (frame) {
10005 case DISASSOC:
10006 *pos++ = 0xa0;
10007 break;
10008 case DEAUTH:
10009 *pos++ = 0xc0;
10010 break;
10011 case SAQUERY:
10012 *pos++ = 0xd0;
10013 break;
10014 case AUTH:
10015 *pos++ = 0xb0;
10016 break;
10017 case ASSOCREQ:
10018 *pos++ = 0x00;
10019 break;
10020 case REASSOCREQ:
10021 *pos++ = 0x20;
10022 break;
10023 case DLS_REQ:
10024 *pos++ = 0xd0;
10025 break;
10026 }
10027
10028 if (protected == INCORRECT_KEY)
10029 *pos++ = 0x40; /* Set Protected field to 1 */
10030 else
10031 *pos++ = 0x00;
10032
10033 /* Duration */
10034 *pos++ = 0x00;
10035 *pos++ = 0x00;
10036
10037 /* addr1 = DA (current AP) */
10038 hwaddr_aton(bssid, pos);
10039 pos += 6;
10040 /* addr2 = SA (own address) */
10041 hwaddr_aton(addr, pos);
10042 pos += 6;
10043 /* addr3 = BSSID (current AP) */
10044 hwaddr_aton(bssid, pos);
10045 pos += 6;
10046
10047 /* Seq# (to be filled by driver/mac80211) */
10048 *pos++ = 0x00;
10049 *pos++ = 0x00;
10050
10051 if (protected == INCORRECT_KEY) {
10052 /* CCMP parameters */
10053 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
10054 pos += 8;
10055 }
10056
10057 if (protected == INCORRECT_KEY) {
10058 switch (frame) {
10059 case DEAUTH:
10060 /* Reason code (encrypted) */
10061 memcpy(pos, "\xa7\x39", 2);
10062 pos += 2;
10063 break;
10064 case DISASSOC:
10065 /* Reason code (encrypted) */
10066 memcpy(pos, "\xa7\x39", 2);
10067 pos += 2;
10068 break;
10069 case SAQUERY:
10070 /* Category|Action|TransID (encrypted) */
10071 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
10072 pos += 4;
10073 break;
10074 default:
10075 return -1;
10076 }
10077
10078 /* CCMP MIC */
10079 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
10080 pos += 8;
10081 } else {
10082 switch (frame) {
10083 case DEAUTH:
10084 /* reason code = 8 */
10085 *pos++ = 0x08;
10086 *pos++ = 0x00;
10087 break;
10088 case DISASSOC:
10089 /* reason code = 8 */
10090 *pos++ = 0x08;
10091 *pos++ = 0x00;
10092 break;
10093 case SAQUERY:
10094 /* Category - SA Query */
10095 *pos++ = 0x08;
10096 /* SA query Action - Request */
10097 *pos++ = 0x00;
10098 /* Transaction ID */
10099 *pos++ = 0x12;
10100 *pos++ = 0x34;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053010101 if (dut->saquery_oci_freq) {
10102 /* OCI IE - Extended ID */
10103 *pos++ = 0xFF;
10104 *pos++ = 0x04;
10105 *pos++ = 0x36;
10106 /* Operating Class */
10107 *pos++ = 0x74;
10108 /* Primary Channel */
10109 *pos++ = freq_to_channel(dut->saquery_oci_freq);
10110 /* Frequency Segment 1 Channel Number */
10111 *pos++ = 0x00;
10112 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010113 break;
10114 case AUTH:
10115 /* Auth Alg (Open) */
10116 *pos++ = 0x00;
10117 *pos++ = 0x00;
10118 /* Seq# */
10119 *pos++ = 0x01;
10120 *pos++ = 0x00;
10121 /* Status code */
10122 *pos++ = 0x00;
10123 *pos++ = 0x00;
10124 break;
10125 case ASSOCREQ:
10126 /* Capability Information */
10127 *pos++ = 0x31;
10128 *pos++ = 0x04;
10129 /* Listen Interval */
10130 *pos++ = 0x0a;
10131 *pos++ = 0x00;
10132 /* SSID */
10133 *pos++ = 0x00;
10134 *pos++ = ssid_len;
10135 memcpy(pos, ssid, ssid_len);
10136 pos += ssid_len;
10137 /* Supported Rates */
10138 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
10139 10);
10140 pos += 10;
10141 /* Extended Supported Rates */
10142 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
10143 pos += 6;
10144 /* RSN */
10145 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
10146 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
10147 "\x00\x00\x00\x00\x0f\xac\x06", 28);
10148 pos += 28;
10149 break;
10150 case REASSOCREQ:
10151 /* Capability Information */
10152 *pos++ = 0x31;
10153 *pos++ = 0x04;
10154 /* Listen Interval */
10155 *pos++ = 0x0a;
10156 *pos++ = 0x00;
10157 /* Current AP */
10158 hwaddr_aton(bssid, pos);
10159 pos += 6;
10160 /* SSID */
10161 *pos++ = 0x00;
10162 *pos++ = ssid_len;
10163 memcpy(pos, ssid, ssid_len);
10164 pos += ssid_len;
10165 /* Supported Rates */
10166 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
10167 10);
10168 pos += 10;
10169 /* Extended Supported Rates */
10170 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
10171 pos += 6;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053010172 /* RSNE - Group and Pairwise ciphers */
10173 memcpy(pos,
10174 "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04",
10175 14);
10176 pos += 14;
10177 /* RSNE - AKM Suite count */
10178 *pos++ = 0x01;
10179 *pos++ = 0x00;
10180 /* RSNE - AKM Suites */
10181 if (dut->program == PROGRAM_WPA3)
10182 memcpy(pos, "\x00\x0f\xac\x08", 4);
10183 else
10184 memcpy(pos, "\x00\x0f\xac\x02", 4);
10185 pos += 4;
10186 /* RSNE - Capabilities */
10187 *pos++ = 0xc0;
10188 if (dut->ocvc)
10189 *pos++ = 0x40;
10190 else
10191 *pos++ = 0x00;
10192 /* RSNE - PMKID list and Group Management Ciphers */
10193 memcpy(pos, "\x00\x00\x00\x0f\xac\x06", 6);
10194 pos += 6;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010195 break;
10196 case DLS_REQ:
10197 /* Category - DLS */
10198 *pos++ = 0x02;
10199 /* DLS Action - Request */
10200 *pos++ = 0x00;
10201 /* Destination MACAddress */
10202 if (dest)
10203 hwaddr_aton(dest, pos);
10204 else
10205 memset(pos, 0, 6);
10206 pos += 6;
10207 /* Source MACAddress */
10208 hwaddr_aton(addr, pos);
10209 pos += 6;
10210 /* Capability Information */
10211 *pos++ = 0x10; /* Privacy */
10212 *pos++ = 0x06; /* QoS */
10213 /* DLS Timeout Value */
10214 *pos++ = 0x00;
10215 *pos++ = 0x01;
10216 /* Supported rates */
10217 *pos++ = 0x01;
10218 *pos++ = 0x08;
10219 *pos++ = 0x0c; /* 6 Mbps */
10220 *pos++ = 0x12; /* 9 Mbps */
10221 *pos++ = 0x18; /* 12 Mbps */
10222 *pos++ = 0x24; /* 18 Mbps */
10223 *pos++ = 0x30; /* 24 Mbps */
10224 *pos++ = 0x48; /* 36 Mbps */
10225 *pos++ = 0x60; /* 48 Mbps */
10226 *pos++ = 0x6c; /* 54 Mbps */
10227 /* TODO: Extended Supported Rates */
10228 /* TODO: HT Capabilities */
10229 break;
10230 }
10231 }
10232
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010233 if (use_monitor) {
10234 s = open_monitor("sigmadut");
10235 if (s < 0) {
10236 send_resp(dut, conn, SIGMA_ERROR,
10237 "errorCode,Failed to open monitor socket");
10238 return 0;
10239 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010240
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010241 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
10242 if (res < 0) {
10243 send_resp(dut, conn, SIGMA_ERROR,
10244 "errorCode,Failed to inject frame");
10245 close(s);
10246 return 0;
10247 }
10248 if (res < pos - buf) {
10249 send_resp(dut, conn, SIGMA_ERROR,
10250 "errorCode,Only partial frame sent");
10251 close(s);
10252 return 0;
10253 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010254
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010255 close(s);
10256 } else {
10257#ifdef NL80211_SUPPORT
10258 int freq;
10259 char freq_str[10];
10260
10261 if (get_wpa_status(get_station_ifname(dut), "freq",
10262 freq_str, sizeof(freq_str)) < 0) {
10263 send_resp(dut, conn, SIGMA_ERROR,
10264 "errorCode,Could not get current operating frequency");
10265 return 0;
10266 }
10267 freq = atoi(freq_str);
10268
10269 if (nl80211_send_frame_cmd(dut, intf, buf, pos - buf, freq)) {
10270 send_resp(dut, conn, SIGMA_ERROR,
10271 "errorCode,Failed to inject frame");
10272 return 0;
10273 }
10274#else /* NL80211_SUPPORT */
10275 send_resp(dut, conn, SIGMA_ERROR,
10276 "errorCode,Failed to inject frame (no NL80211_SUPPORT)");
10277 return 0;
10278#endif /* NL80211_SUPPORT */
10279 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010280
10281 return 1;
10282#else /* __linux__ */
10283 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
10284 "yet supported");
10285 return 0;
10286#endif /* __linux__ */
10287}
10288
10289
10290static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
10291 struct sigma_conn *conn,
10292 struct sigma_cmd *cmd)
10293{
10294 const char *intf = get_param(cmd, "Interface");
10295 const char *sta, *val;
10296 unsigned char addr[ETH_ALEN];
10297 char buf[100];
10298
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010299 if (!intf)
10300 return -1;
10301
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010302 sta = get_param(cmd, "peer");
10303 if (sta == NULL)
10304 sta = get_param(cmd, "station");
10305 if (sta == NULL) {
10306 send_resp(dut, conn, SIGMA_ERROR,
10307 "ErrorCode,Missing peer address");
10308 return 0;
10309 }
10310 if (hwaddr_aton(sta, addr) < 0) {
10311 send_resp(dut, conn, SIGMA_ERROR,
10312 "ErrorCode,Invalid peer address");
10313 return 0;
10314 }
10315
10316 val = get_param(cmd, "type");
10317 if (val == NULL)
10318 return -1;
10319
10320 if (strcasecmp(val, "DISCOVERY") == 0) {
10321 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
10322 if (wpa_command(intf, buf) < 0) {
10323 send_resp(dut, conn, SIGMA_ERROR,
10324 "ErrorCode,Failed to send TDLS discovery");
10325 return 0;
10326 }
10327 return 1;
10328 }
10329
10330 if (strcasecmp(val, "SETUP") == 0) {
10331 int status = 0, timeout = 0;
10332
10333 val = get_param(cmd, "Status");
10334 if (val)
10335 status = atoi(val);
10336
10337 val = get_param(cmd, "Timeout");
10338 if (val)
10339 timeout = atoi(val);
10340
10341 if (status != 0 && status != 37) {
10342 send_resp(dut, conn, SIGMA_ERROR,
10343 "ErrorCode,Unsupported status value");
10344 return 0;
10345 }
10346
10347 if (timeout != 0 && timeout != 301) {
10348 send_resp(dut, conn, SIGMA_ERROR,
10349 "ErrorCode,Unsupported timeout value");
10350 return 0;
10351 }
10352
10353 if (status && timeout) {
10354 send_resp(dut, conn, SIGMA_ERROR,
10355 "ErrorCode,Unsupported timeout+status "
10356 "combination");
10357 return 0;
10358 }
10359
10360 if (status == 37 &&
10361 wpa_command(intf, "SET tdls_testing 0x200")) {
10362 send_resp(dut, conn, SIGMA_ERROR,
10363 "ErrorCode,Failed to enable "
10364 "decline setup response test mode");
10365 return 0;
10366 }
10367
10368 if (timeout == 301) {
10369 int res;
10370 if (dut->no_tpk_expiration)
10371 res = wpa_command(intf,
10372 "SET tdls_testing 0x108");
10373 else
10374 res = wpa_command(intf,
10375 "SET tdls_testing 0x8");
10376 if (res) {
10377 send_resp(dut, conn, SIGMA_ERROR,
10378 "ErrorCode,Failed to set short TPK "
10379 "lifetime");
10380 return 0;
10381 }
10382 }
10383
10384 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
10385 if (wpa_command(intf, buf) < 0) {
10386 send_resp(dut, conn, SIGMA_ERROR,
10387 "ErrorCode,Failed to send TDLS setup");
10388 return 0;
10389 }
10390 return 1;
10391 }
10392
10393 if (strcasecmp(val, "TEARDOWN") == 0) {
10394 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
10395 if (wpa_command(intf, buf) < 0) {
10396 send_resp(dut, conn, SIGMA_ERROR,
10397 "ErrorCode,Failed to send TDLS teardown");
10398 return 0;
10399 }
10400 return 1;
10401 }
10402
10403 send_resp(dut, conn, SIGMA_ERROR,
10404 "ErrorCode,Unsupported TDLS frame");
10405 return 0;
10406}
10407
10408
10409static int sta_ap_known(const char *ifname, const char *bssid)
10410{
10411 char buf[4096];
10412
Jouni Malinendd32f192018-09-15 02:55:19 +030010413 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010414 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
10415 return 0;
10416 if (strncmp(buf, "id=", 3) != 0)
10417 return 0;
10418 return 1;
10419}
10420
10421
10422static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
10423 const char *bssid)
10424{
10425 int res;
10426 struct wpa_ctrl *ctrl;
10427 char buf[256];
10428
10429 if (sta_ap_known(ifname, bssid))
10430 return 0;
10431 sigma_dut_print(dut, DUT_MSG_DEBUG,
10432 "AP not in BSS table - start scan");
10433
10434 ctrl = open_wpa_mon(ifname);
10435 if (ctrl == NULL) {
10436 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10437 "wpa_supplicant monitor connection");
10438 return -1;
10439 }
10440
10441 if (wpa_command(ifname, "SCAN") < 0) {
10442 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
10443 wpa_ctrl_detach(ctrl);
10444 wpa_ctrl_close(ctrl);
10445 return -1;
10446 }
10447
10448 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
10449 buf, sizeof(buf));
10450
10451 wpa_ctrl_detach(ctrl);
10452 wpa_ctrl_close(ctrl);
10453
10454 if (res < 0) {
10455 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
10456 return -1;
10457 }
10458
10459 if (sta_ap_known(ifname, bssid))
10460 return 0;
10461 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
10462 return -1;
10463}
10464
10465
10466static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
10467 struct sigma_conn *conn,
10468 struct sigma_cmd *cmd,
10469 const char *intf)
10470{
10471 char buf[200];
10472
10473 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
10474 if (system(buf) != 0) {
10475 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
10476 "ndsend");
10477 return 0;
10478 }
10479
10480 return 1;
10481}
10482
10483
10484static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
10485 struct sigma_conn *conn,
10486 struct sigma_cmd *cmd,
10487 const char *intf)
10488{
10489 char buf[200];
10490 const char *ip = get_param(cmd, "SenderIP");
10491
Peng Xu26b356d2017-10-04 17:58:16 -070010492 if (!ip)
10493 return 0;
10494
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010495 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
10496 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10497 if (system(buf) == 0) {
10498 sigma_dut_print(dut, DUT_MSG_INFO,
10499 "Neighbor Solicitation got a response "
10500 "for %s@%s", ip, intf);
10501 }
10502
10503 return 1;
10504}
10505
10506
10507static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
10508 struct sigma_conn *conn,
10509 struct sigma_cmd *cmd,
10510 const char *ifname)
10511{
10512 char buf[200];
10513 const char *ip = get_param(cmd, "SenderIP");
10514
10515 if (ip == NULL) {
10516 send_resp(dut, conn, SIGMA_ERROR,
10517 "ErrorCode,Missing SenderIP parameter");
10518 return 0;
10519 }
10520 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
10521 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10522 if (system(buf) != 0) {
10523 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
10524 "for %s@%s", ip, ifname);
10525 }
10526
10527 return 1;
10528}
10529
10530
10531static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
10532 struct sigma_conn *conn,
10533 struct sigma_cmd *cmd,
10534 const char *ifname)
10535{
10536 char buf[200];
10537 char ip[16];
10538 int s;
Peng Xub3756882017-10-04 14:39:09 -070010539 struct ifreq ifr;
10540 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010541
10542 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070010543 if (s < 0) {
10544 perror("socket");
10545 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010546 }
10547
Peng Xub3756882017-10-04 14:39:09 -070010548 memset(&ifr, 0, sizeof(ifr));
10549 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
10550 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
10551 sigma_dut_print(dut, DUT_MSG_INFO,
10552 "Failed to get %s IP address: %s",
10553 ifname, strerror(errno));
10554 close(s);
10555 return -1;
10556 }
10557 close(s);
10558
10559 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
10560 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
10561
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010562 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
10563 ip);
10564 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10565 if (system(buf) != 0) {
10566 }
10567
10568 return 1;
10569}
10570
10571
10572static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
10573 struct sigma_conn *conn,
10574 struct sigma_cmd *cmd,
10575 const char *ifname)
10576{
10577 char buf[200], addr[20];
10578 char dst[ETH_ALEN], src[ETH_ALEN];
10579 short ethtype = htons(ETH_P_ARP);
10580 char *pos;
10581 int s, res;
10582 const char *val;
10583 struct sockaddr_in taddr;
10584
10585 val = get_param(cmd, "dest");
10586 if (val)
10587 hwaddr_aton(val, (unsigned char *) dst);
10588
10589 val = get_param(cmd, "DestIP");
10590 if (val)
10591 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070010592 else
10593 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010594
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010595 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010596 sizeof(addr)) < 0)
10597 return -2;
10598 hwaddr_aton(addr, (unsigned char *) src);
10599
10600 pos = buf;
10601 *pos++ = 0x00;
10602 *pos++ = 0x01;
10603 *pos++ = 0x08;
10604 *pos++ = 0x00;
10605 *pos++ = 0x06;
10606 *pos++ = 0x04;
10607 *pos++ = 0x00;
10608 *pos++ = 0x02;
10609 memcpy(pos, src, ETH_ALEN);
10610 pos += ETH_ALEN;
10611 memcpy(pos, &taddr.sin_addr, 4);
10612 pos += 4;
10613 memcpy(pos, dst, ETH_ALEN);
10614 pos += ETH_ALEN;
10615 memcpy(pos, &taddr.sin_addr, 4);
10616 pos += 4;
10617
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010618 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010619 if (s < 0) {
10620 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
10621 "monitor socket");
10622 return 0;
10623 }
10624
10625 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
10626 if (res < 0) {
10627 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
10628 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053010629 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010630 return 0;
10631 }
10632
10633 close(s);
10634
10635 return 1;
10636}
10637
10638
10639static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
10640 struct sigma_conn *conn,
10641 struct sigma_cmd *cmd,
10642 const char *intf, const char *dest)
10643{
10644 char buf[100];
10645
10646 if (if_nametoindex("sigmadut") == 0) {
10647 snprintf(buf, sizeof(buf),
10648 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010649 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010650 if (system(buf) != 0 ||
10651 if_nametoindex("sigmadut") == 0) {
10652 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10653 "monitor interface with '%s'", buf);
10654 return -2;
10655 }
10656 }
10657
10658 if (system("ifconfig sigmadut up") != 0) {
10659 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10660 "monitor interface up");
10661 return -2;
10662 }
10663
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010664 return sta_inject_frame(dut, conn, intf, DLS_REQ, UNPROTECTED, dest, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010665}
10666
10667
10668static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10669 struct sigma_conn *conn,
10670 struct sigma_cmd *cmd)
10671{
10672 const char *intf = get_param(cmd, "Interface");
10673 const char *dest = get_param(cmd, "Dest");
10674 const char *type = get_param(cmd, "FrameName");
10675 const char *val;
10676 char buf[200], *pos, *end;
10677 int count, count2;
10678
10679 if (type == NULL)
10680 type = get_param(cmd, "Type");
10681
10682 if (intf == NULL || dest == NULL || type == NULL)
10683 return -1;
10684
10685 if (strcasecmp(type, "NeighAdv") == 0)
10686 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10687
10688 if (strcasecmp(type, "NeighSolicitReq") == 0)
10689 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10690
10691 if (strcasecmp(type, "ARPProbe") == 0)
10692 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10693
10694 if (strcasecmp(type, "ARPAnnounce") == 0)
10695 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10696
10697 if (strcasecmp(type, "ARPReply") == 0)
10698 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10699
10700 if (strcasecmp(type, "DLS-request") == 0 ||
10701 strcasecmp(type, "DLSrequest") == 0)
10702 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10703 dest);
10704
10705 if (strcasecmp(type, "ANQPQuery") != 0 &&
10706 strcasecmp(type, "Query") != 0) {
10707 send_resp(dut, conn, SIGMA_ERROR,
10708 "ErrorCode,Unsupported HS 2.0 send frame type");
10709 return 0;
10710 }
10711
10712 if (sta_scan_ap(dut, intf, dest) < 0) {
10713 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10714 "the requested AP");
10715 return 0;
10716 }
10717
10718 pos = buf;
10719 end = buf + sizeof(buf);
10720 count = 0;
10721 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10722
10723 val = get_param(cmd, "ANQP_CAP_LIST");
10724 if (val && atoi(val)) {
10725 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10726 count++;
10727 }
10728
10729 val = get_param(cmd, "VENUE_NAME");
10730 if (val && atoi(val)) {
10731 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10732 count++;
10733 }
10734
10735 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10736 if (val && atoi(val)) {
10737 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10738 count++;
10739 }
10740
10741 val = get_param(cmd, "ROAMING_CONS");
10742 if (val && atoi(val)) {
10743 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10744 count++;
10745 }
10746
10747 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10748 if (val && atoi(val)) {
10749 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10750 count++;
10751 }
10752
10753 val = get_param(cmd, "NAI_REALM_LIST");
10754 if (val && atoi(val)) {
10755 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10756 count++;
10757 }
10758
10759 val = get_param(cmd, "3GPP_INFO");
10760 if (val && atoi(val)) {
10761 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10762 count++;
10763 }
10764
10765 val = get_param(cmd, "DOMAIN_LIST");
10766 if (val && atoi(val)) {
10767 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10768 count++;
10769 }
10770
Jouni Malinen34cf9532018-04-29 19:26:33 +030010771 val = get_param(cmd, "Venue_URL");
10772 if (val && atoi(val)) {
10773 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10774 count++;
10775 }
10776
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010777 val = get_param(cmd, "Advice_Of_Charge");
10778 if (val && atoi(val)) {
10779 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10780 count++;
10781 }
10782
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010783 if (count && wpa_command(intf, buf)) {
10784 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10785 return 0;
10786 }
10787
10788 pos = buf;
10789 end = buf + sizeof(buf);
10790 count2 = 0;
10791 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
10792
10793 val = get_param(cmd, "HS_CAP_LIST");
10794 if (val && atoi(val)) {
10795 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
10796 count2++;
10797 }
10798
10799 val = get_param(cmd, "OPER_NAME");
10800 if (val && atoi(val)) {
10801 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
10802 count2++;
10803 }
10804
10805 val = get_param(cmd, "WAN_METRICS");
10806 if (!val)
10807 val = get_param(cmd, "WAN_MAT");
10808 if (!val)
10809 val = get_param(cmd, "WAN_MET");
10810 if (val && atoi(val)) {
10811 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10812 count2++;
10813 }
10814
10815 val = get_param(cmd, "CONNECTION_CAPABILITY");
10816 if (val && atoi(val)) {
10817 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10818 count2++;
10819 }
10820
10821 val = get_param(cmd, "OP_CLASS");
10822 if (val && atoi(val)) {
10823 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10824 count2++;
10825 }
10826
10827 val = get_param(cmd, "OSU_PROVIDER_LIST");
10828 if (val && atoi(val)) {
10829 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10830 count2++;
10831 }
10832
Jouni Malinenf67afec2018-04-29 19:24:58 +030010833 val = get_param(cmd, "OPER_ICON_METADATA");
10834 if (!val)
10835 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10836 if (val && atoi(val)) {
10837 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10838 count2++;
10839 }
10840
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010841 if (count && count2) {
10842 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10843 "second query");
10844 sleep(1);
10845 }
10846
10847 if (count2 && wpa_command(intf, buf)) {
10848 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10849 "failed");
10850 return 0;
10851 }
10852
10853 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10854 if (val) {
10855 if (count || count2) {
10856 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10857 "sending out second query");
10858 sleep(1);
10859 }
10860
10861 if (strcmp(val, "1") == 0)
10862 val = "mail.example.com";
10863 snprintf(buf, end - pos,
10864 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10865 dest, val);
10866 if (wpa_command(intf, buf)) {
10867 send_resp(dut, conn, SIGMA_ERROR,
10868 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10869 "failed");
10870 return 0;
10871 }
10872 }
10873
10874 val = get_param(cmd, "ICON_REQUEST");
10875 if (val) {
10876 if (count || count2) {
10877 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10878 "sending out second query");
10879 sleep(1);
10880 }
10881
10882 snprintf(buf, end - pos,
10883 "HS20_ICON_REQUEST %s %s", dest, val);
10884 if (wpa_command(intf, buf)) {
10885 send_resp(dut, conn, SIGMA_ERROR,
10886 "ErrorCode,HS20_ICON_REQUEST failed");
10887 return 0;
10888 }
10889 }
10890
10891 return 1;
10892}
10893
10894
10895static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10896 struct sigma_conn *conn,
10897 struct sigma_cmd *cmd)
10898{
10899 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010900 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010901 int chwidth, nss;
10902
10903 val = get_param(cmd, "framename");
10904 if (!val)
10905 return -1;
10906 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10907
10908 /* Command sequence to generate Op mode notification */
10909 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010910 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010911
10912 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010913 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010914
10915 /* Extract Channel width */
10916 val = get_param(cmd, "Channel_width");
10917 if (val) {
10918 switch (atoi(val)) {
10919 case 20:
10920 chwidth = 0;
10921 break;
10922 case 40:
10923 chwidth = 1;
10924 break;
10925 case 80:
10926 chwidth = 2;
10927 break;
10928 case 160:
10929 chwidth = 3;
10930 break;
10931 default:
10932 chwidth = 2;
10933 break;
10934 }
10935
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010936 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010937 }
10938
10939 /* Extract NSS */
10940 val = get_param(cmd, "NSS");
10941 if (val) {
10942 switch (atoi(val)) {
10943 case 1:
10944 nss = 1;
10945 break;
10946 case 2:
10947 nss = 3;
10948 break;
10949 case 3:
10950 nss = 7;
10951 break;
10952 default:
10953 /* We do not support NSS > 3 */
10954 nss = 3;
10955 break;
10956 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010957 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010958 }
10959
10960 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010961 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010962 }
10963
10964 return 1;
10965}
10966
10967
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010968static int wcn_sta_set_pmf_config(struct sigma_dut *dut, const char *intf,
10969 enum send_frame_protection protected)
10970{
10971#ifdef NL80211_SUPPORT
10972 struct nl_msg *msg;
10973 int ret = 0;
10974 struct nlattr *params;
10975 int ifindex;
10976
10977 ifindex = if_nametoindex(intf);
10978 if (ifindex == 0) {
10979 sigma_dut_print(dut, DUT_MSG_ERROR,
10980 "%s: Index for interface %s failed",
10981 __func__, intf);
10982 return -1;
10983 }
10984
10985 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10986 NL80211_CMD_VENDOR)) ||
10987 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
10988 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10989 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10990 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
10991 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10992 nla_put_u8(msg,
10993 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PMF_PROTECTION,
10994 protected)) {
10995 sigma_dut_print(dut, DUT_MSG_ERROR,
10996 "%s: err in adding vendor_cmd and vendor_data",
10997 __func__);
10998 nlmsg_free(msg);
10999 return -1;
11000 }
11001 nla_nest_end(msg, params);
11002
11003 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
11004 if (ret) {
11005 sigma_dut_print(dut, DUT_MSG_ERROR,
11006 "%s: err in send_and_recv_msgs, ret=%d",
11007 __func__, ret);
11008 }
11009 return ret;
11010#else /* NL80211_SUPPORT */
11011 sigma_dut_print(dut, DUT_MSG_ERROR,
11012 "PMF config cannot be set without NL80211_SUPPORT defined");
11013 return -1;
11014#endif /* NL80211_SUPPORT */
11015}
11016
11017
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011018static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
11019 struct sigma_conn *conn,
11020 struct sigma_cmd *cmd)
11021{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011022 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011023 case DRIVER_ATHEROS:
11024 return ath_sta_send_frame_vht(dut, conn, cmd);
11025 default:
11026 send_resp(dut, conn, SIGMA_ERROR,
11027 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
11028 return 0;
11029 }
11030}
11031
11032
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011033static int wcn_sta_send_disassoc(struct sigma_dut *dut, const char *intf)
11034{
11035#ifdef NL80211_SUPPORT
11036 struct nl_msg *msg;
11037 int ret = 0;
11038 struct nlattr *params;
11039 int ifindex;
11040
11041 ifindex = if_nametoindex(intf);
11042 if (ifindex == 0) {
11043 sigma_dut_print(dut, DUT_MSG_ERROR,
11044 "%s: Index for interface %s failed",
11045 __func__, intf);
11046 return -1;
11047 }
11048
11049 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
11050 NL80211_CMD_VENDOR)) ||
11051 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
11052 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
11053 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
11054 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
11055 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
11056 nla_put_flag(msg,
11057 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISASSOC_TX)) {
11058 sigma_dut_print(dut, DUT_MSG_ERROR,
11059 "%s: err in adding vendor_cmd and vendor_data",
11060 __func__);
11061 nlmsg_free(msg);
11062 return -1;
11063 }
11064 nla_nest_end(msg, params);
11065
11066 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
11067 if (ret) {
11068 sigma_dut_print(dut, DUT_MSG_ERROR,
11069 "%s: err in send_and_recv_msgs, ret=%d",
11070 __func__, ret);
11071 }
11072 return ret;
11073#else /* NL80211_SUPPORT */
11074 sigma_dut_print(dut, DUT_MSG_ERROR,
11075 "Disassoc Tx cannot be done without NL80211_SUPPORT defined");
11076 return -1;
11077#endif /* NL80211_SUPPORT */
11078}
11079
11080
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011081static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
11082 struct sigma_cmd *cmd)
11083{
11084 const char *val;
11085 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011086 enum send_frame_protection protected;
11087 const char *pmf;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011088
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011089 if (!intf)
11090 return -1;
11091
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011092 val = get_param(cmd, "framename");
11093 if (!val)
11094 return -1;
11095 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
11096
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011097 pmf = get_param(cmd, "PMFProtected");
11098 if (!pmf)
11099 pmf = get_param(cmd, "Protected");
11100 if (pmf) {
11101 if (strcasecmp(pmf, "Correct-key") == 0 ||
11102 strcasecmp(pmf, "CorrectKey") == 0) {
11103 protected = CORRECT_KEY;
11104 } else if (strcasecmp(pmf, "IncorrectKey") == 0) {
11105 protected = INCORRECT_KEY;
11106 } else if (strcasecmp(pmf, "Unprotected") == 0) {
11107 protected = UNPROTECTED;
11108 } else {
11109 send_resp(dut, conn, SIGMA_ERROR,
11110 "errorCode,Unsupported PMFProtected");
11111 return STATUS_SENT_ERROR;
11112 }
11113 sigma_dut_print(dut, DUT_MSG_DEBUG, "Config PMF protection %d",
11114 protected);
11115 wcn_sta_set_pmf_config(dut, intf, protected);
11116 }
11117
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011118 /* Command sequence to generate Op mode notification */
11119 if (val && strcasecmp(val, "action") == 0) {
11120 val = get_param(cmd, "PPDUTxType");
11121 if (val && strcasecmp(val, "TB") == 0) {
11122 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
11123 sigma_dut_print(dut, DUT_MSG_ERROR,
11124 "failed to send TB PPDU Tx cfg");
11125 send_resp(dut, conn, SIGMA_ERROR,
11126 "ErrorCode,set TB PPDU Tx cfg failed");
11127 return 0;
11128 }
11129 return 1;
11130 }
11131
11132 sigma_dut_print(dut, DUT_MSG_ERROR,
11133 "Action Tx type is not defined");
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011134
11135 return SUCCESS_SEND_STATUS;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011136 }
11137
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011138 if (strcasecmp(val, "disassoc") == 0)
11139 wcn_sta_send_disassoc(dut, intf);
11140
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011141 return 1;
11142}
11143
11144
11145static int cmd_sta_send_frame_he(struct sigma_dut *dut,
11146 struct sigma_conn *conn,
11147 struct sigma_cmd *cmd)
11148{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011149 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011150 case DRIVER_WCN:
11151 return wcn_sta_send_frame_he(dut, conn, cmd);
11152 default:
11153 send_resp(dut, conn, SIGMA_ERROR,
11154 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
11155 return 0;
11156 }
11157}
11158
11159
Lior David0fe101e2017-03-09 16:09:50 +020011160#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011161
11162static int
11163wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
11164 const char *frame_name, const char *dest_mac)
11165{
11166 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
11167 const char *ssid = get_param(cmd, "ssid");
11168 const char *countstr = get_param(cmd, "count");
11169 const char *channelstr = get_param(cmd, "channel");
11170 const char *group_id = get_param(cmd, "groupid");
11171 const char *client_id = get_param(cmd, "clientmac");
11172 int count, channel, freq, i;
11173 const char *fname;
11174 char frame[1024], src_mac[20], group_id_attr[25],
11175 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
11176 const char *group_ssid;
11177 const int group_ssid_prefix_len = 9;
11178 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
11179 size_t framelen = sizeof(frame);
11180 struct template_frame_tag tags[2];
11181 size_t tags_total = ARRAY_SIZE(tags);
11182 int tag_index, len, dst_len;
11183
11184 if (!countstr || !channelstr) {
11185 sigma_dut_print(dut, DUT_MSG_ERROR,
11186 "Missing argument: count, channel");
11187 return -1;
11188 }
11189 if (isprobereq && !ssid) {
11190 sigma_dut_print(dut, DUT_MSG_ERROR,
11191 "Missing argument: ssid");
11192 return -1;
11193 }
11194 if (!isprobereq && (!group_id || !client_id)) {
11195 sigma_dut_print(dut, DUT_MSG_ERROR,
11196 "Missing argument: group_id, client_id");
11197 return -1;
11198 }
11199
11200 count = atoi(countstr);
11201 channel = atoi(channelstr);
11202 freq = channel_to_freq(dut, channel);
11203
11204 if (!freq) {
11205 sigma_dut_print(dut, DUT_MSG_ERROR,
11206 "invalid channel: %s", channelstr);
11207 return -1;
11208 }
11209
11210 if (isprobereq) {
11211 if (strcasecmp(ssid, "wildcard") == 0) {
11212 fname = "probe_req_wildcard.txt";
11213 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
11214 fname = "probe_req_P2P_Wildcard.txt";
11215 } else {
11216 sigma_dut_print(dut, DUT_MSG_ERROR,
11217 "invalid probe request type");
11218 return -1;
11219 }
11220 } else {
11221 fname = "P2P_device_discovery_req.txt";
11222 }
11223
11224 if (parse_template_frame_file(dut, fname, frame, &framelen,
11225 tags, &tags_total)) {
11226 sigma_dut_print(dut, DUT_MSG_ERROR,
11227 "invalid frame template: %s", fname);
11228 return -1;
11229 }
11230
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011231 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011232 src_mac, sizeof(src_mac)) < 0 ||
11233 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
11234 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
11235 return -1;
11236 /* Use wildcard BSSID, since we are in PBSS */
11237 memset(&hdr->addr3, 0xFF, ETH_ALEN);
11238
11239 if (!isprobereq) {
11240 tag_index = find_template_frame_tag(tags, tags_total, 1);
11241 if (tag_index < 0) {
11242 sigma_dut_print(dut, DUT_MSG_ERROR,
11243 "can't find device id attribute");
11244 return -1;
11245 }
11246 if (parse_mac_address(dut, client_id,
11247 (unsigned char *) client_mac)) {
11248 sigma_dut_print(dut, DUT_MSG_ERROR,
11249 "invalid client_id: %s", client_id);
11250 return -1;
11251 }
11252 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11253 framelen - tags[tag_index].offset,
11254 IEEE80211_P2P_ATTR_DEVICE_ID,
11255 client_mac, ETH_ALEN)) {
11256 sigma_dut_print(dut, DUT_MSG_ERROR,
11257 "fail to replace device id attribute");
11258 return -1;
11259 }
11260
11261 /*
11262 * group_id arg contains device MAC address followed by
11263 * space and SSID (DIRECT-somessid).
11264 * group id attribute contains device address (6 bytes)
11265 * followed by SSID prefix DIRECT-XX (9 bytes)
11266 */
11267 if (strlen(group_id) < sizeof(device_macstr)) {
11268 sigma_dut_print(dut, DUT_MSG_ERROR,
11269 "group_id arg too short");
11270 return -1;
11271 }
11272 memcpy(device_macstr, group_id, sizeof(device_macstr));
11273 device_macstr[sizeof(device_macstr) - 1] = '\0';
11274 if (parse_mac_address(dut, device_macstr,
11275 (unsigned char *) group_id_attr)) {
11276 sigma_dut_print(dut, DUT_MSG_ERROR,
11277 "fail to parse device address from group_id");
11278 return -1;
11279 }
11280 group_ssid = strchr(group_id, ' ');
11281 if (!group_ssid) {
11282 sigma_dut_print(dut, DUT_MSG_ERROR,
11283 "invalid group_id arg, no ssid");
11284 return -1;
11285 }
11286 group_ssid++;
11287 len = strlen(group_ssid);
11288 if (len < group_ssid_prefix_len) {
11289 sigma_dut_print(dut, DUT_MSG_ERROR,
11290 "group_id SSID too short");
11291 return -1;
11292 }
11293 dst_len = sizeof(group_id_attr) - ETH_ALEN;
11294 if (len > dst_len) {
11295 sigma_dut_print(dut, DUT_MSG_ERROR,
11296 "group_id SSID (%s) too long",
11297 group_ssid);
11298 return -1;
11299 }
11300
11301 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
11302 tag_index = find_template_frame_tag(tags, tags_total, 2);
11303 if (tag_index < 0) {
11304 sigma_dut_print(dut, DUT_MSG_ERROR,
11305 "can't find group id attribute");
11306 return -1;
11307 }
11308 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11309 framelen - tags[tag_index].offset,
11310 IEEE80211_P2P_ATTR_GROUP_ID,
11311 group_id_attr,
11312 sizeof(group_id_attr))) {
11313 sigma_dut_print(dut, DUT_MSG_ERROR,
11314 "fail to replace group id attribute");
11315 return -1;
11316 }
11317 }
11318
11319 for (i = 0; i < count; i++) {
11320 if (wil6210_transmit_frame(dut, freq,
11321 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
11322 frame, framelen)) {
11323 sigma_dut_print(dut, DUT_MSG_ERROR,
11324 "fail to transmit probe request frame");
11325 return -1;
11326 }
11327 }
11328
11329 return 0;
11330}
11331
11332
Lior David0fe101e2017-03-09 16:09:50 +020011333int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
11334 struct sigma_cmd *cmd)
11335{
11336 const char *frame_name = get_param(cmd, "framename");
11337 const char *mac = get_param(cmd, "dest_mac");
11338
11339 if (!frame_name || !mac) {
11340 sigma_dut_print(dut, DUT_MSG_ERROR,
11341 "framename and dest_mac must be provided");
11342 return -1;
11343 }
11344
11345 if (strcasecmp(frame_name, "brp") == 0) {
11346 const char *l_rx = get_param(cmd, "L-RX");
11347 int l_rx_i;
11348
11349 if (!l_rx) {
11350 sigma_dut_print(dut, DUT_MSG_ERROR,
11351 "L-RX must be provided");
11352 return -1;
11353 }
11354 l_rx_i = atoi(l_rx);
11355
11356 sigma_dut_print(dut, DUT_MSG_INFO,
11357 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
11358 mac, l_rx);
11359 if (l_rx_i != 16) {
11360 sigma_dut_print(dut, DUT_MSG_ERROR,
11361 "unsupported L-RX: %s", l_rx);
11362 return -1;
11363 }
11364
11365 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
11366 return -1;
11367 } else if (strcasecmp(frame_name, "ssw") == 0) {
11368 sigma_dut_print(dut, DUT_MSG_INFO,
11369 "dev_send_frame: SLS, dest_mac %s", mac);
11370 if (wil6210_send_sls(dut, mac))
11371 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011372 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
11373 (strcasecmp(frame_name, "devdiscreq") == 0)) {
11374 sigma_dut_print(dut, DUT_MSG_INFO,
11375 "dev_send_frame: %s, dest_mac %s", frame_name,
11376 mac);
11377 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
11378 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020011379 } else {
11380 sigma_dut_print(dut, DUT_MSG_ERROR,
11381 "unsupported frame type: %s", frame_name);
11382 return -1;
11383 }
11384
11385 return 1;
11386}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011387
Lior David0fe101e2017-03-09 16:09:50 +020011388#endif /* __linux__ */
11389
11390
11391static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
11392 struct sigma_conn *conn,
11393 struct sigma_cmd *cmd)
11394{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011395 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020011396#ifdef __linux__
11397 case DRIVER_WIL6210:
11398 return wil6210_send_frame_60g(dut, conn, cmd);
11399#endif /* __linux__ */
11400 default:
11401 send_resp(dut, conn, SIGMA_ERROR,
11402 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
11403 return 0;
11404 }
11405}
11406
11407
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011408static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
11409 const char *intf, struct sigma_cmd *cmd)
11410{
11411 const char *val, *addr;
11412 char buf[100];
11413
11414 addr = get_param(cmd, "DestMac");
11415 if (!addr) {
11416 send_resp(dut, conn, SIGMA_INVALID,
11417 "ErrorCode,AP MAC address is missing");
11418 return 0;
11419 }
11420
11421 val = get_param(cmd, "ANQPQuery_ID");
11422 if (!val) {
11423 send_resp(dut, conn, SIGMA_INVALID,
11424 "ErrorCode,Missing ANQPQuery_ID");
11425 return 0;
11426 }
11427
11428 if (strcasecmp(val, "NeighborReportReq") == 0) {
11429 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
11430 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
11431 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
11432 } else {
11433 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
11434 val);
11435 send_resp(dut, conn, SIGMA_INVALID,
11436 "ErrorCode,Invalid ANQPQuery_ID");
11437 return 0;
11438 }
11439
Ashwini Patild174f2c2017-04-13 16:49:46 +053011440 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
11441 * (Address3 = Wildcard BSSID when sent to not-associated AP;
11442 * if associated, AP BSSID).
11443 */
11444 if (wpa_command(intf, "SET gas_address3 1") < 0) {
11445 send_resp(dut, conn, SIGMA_ERROR,
11446 "ErrorCode,Failed to set gas_address3");
11447 return 0;
11448 }
11449
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011450 if (wpa_command(intf, buf) < 0) {
11451 send_resp(dut, conn, SIGMA_ERROR,
11452 "ErrorCode,Failed to send ANQP query");
11453 return 0;
11454 }
11455
11456 return 1;
11457}
11458
11459
11460static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
11461 struct sigma_conn *conn,
11462 const char *intf,
11463 struct sigma_cmd *cmd)
11464{
11465 const char *val = get_param(cmd, "FrameName");
11466
11467 if (val && strcasecmp(val, "ANQPQuery") == 0)
11468 return mbo_send_anqp_query(dut, conn, intf, cmd);
11469
11470 return 2;
11471}
11472
11473
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011474static enum sigma_cmd_result cmd_sta_send_frame_wpa3(struct sigma_dut *dut,
11475 struct sigma_conn *conn,
11476 const char *intf,
11477 struct sigma_cmd *cmd)
11478{
11479 const char *val = get_param(cmd, "framename");
11480
11481 if (!val)
11482 return INVALID_SEND_STATUS;
11483
11484 if (strcasecmp(val, "SAQueryReq") == 0) {
11485 val = get_param(cmd, "OCIChannel");
11486
11487 if (!val) {
11488 send_resp(dut, conn, SIGMA_ERROR,
11489 "errorCode,OCIChannel not present");
11490 return STATUS_SENT_ERROR;
11491 }
11492
11493 dut->saquery_oci_freq = channel_to_freq(dut, atoi(val));
11494 if (!dut->saquery_oci_freq) {
11495 send_resp(dut, conn, SIGMA_ERROR,
11496 "errorCode,Invalid OCIChannel number");
11497 return STATUS_SENT_ERROR;
11498 }
11499
11500 return sta_inject_frame(dut, conn, intf, SAQUERY, CORRECT_KEY,
11501 NULL, 0);
11502 }
11503
11504 if (strcasecmp(val, "reassocreq") == 0)
11505 return sta_inject_frame(dut, conn, intf, REASSOCREQ,
11506 CORRECT_KEY, NULL, 0);
11507
11508 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported framename");
11509 return STATUS_SENT_ERROR;
11510}
11511
11512
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011513static enum sigma_cmd_result
11514cmd_sta_send_frame_mscs(struct sigma_dut *dut, struct sigma_conn *conn,
11515 const char *intf, struct sigma_cmd *cmd)
11516{
11517 char buf[128], *pos;
11518 const char *val, *classifier_type = "04", *type;
11519 int len, rem_len;
11520 u8 up_bitmap;
11521
11522 val = get_param(cmd, "FrameName");
11523 type = get_param(cmd, "Request_Type");
11524 if (!val || !type || strcasecmp(val, "MSCSReq") != 0) {
11525 sigma_dut_print(dut, DUT_MSG_ERROR,
11526 "%s: frame name or type not valid", __func__);
11527 return INVALID_SEND_STATUS;
11528 }
11529
11530 rem_len = sizeof(buf);
11531 pos = buf;
11532 if (strcasecmp(type, "add") == 0) {
11533 len = snprintf(pos, rem_len, "MSCS add");
11534 } else if (strcasecmp(type, "update") == 0) {
11535 len = snprintf(pos, rem_len, "MSCS change");
11536 } else if (strcasecmp(type, "remove") == 0) {
11537 if (wpa_command(intf, "MSCS remove") != 0) {
11538 send_resp(dut, conn, SIGMA_ERROR,
11539 "ErrorCode,Failed to send MSCS frame req");
11540 return STATUS_SENT_ERROR;
11541 }
11542 return SUCCESS_SEND_STATUS;
11543 } else {
11544 sigma_dut_print(dut, DUT_MSG_ERROR,
11545 "%s: request type invalid", __func__);
11546 return INVALID_SEND_STATUS;
11547 }
11548
11549 if (len < 0 || len >= rem_len)
11550 goto fail;
11551
11552 pos += len;
11553 rem_len -= len;
11554
11555 val = get_param(cmd, "User_Priority_Bitmap");
11556 if (!val) {
11557 sigma_dut_print(dut, DUT_MSG_ERROR,
11558 "%s: user priority bitmap empty", __func__);
11559 return INVALID_SEND_STATUS;
11560 }
11561
11562 switch (atoi(val)) {
11563 case 0:
11564 up_bitmap = 0x00;
11565 break;
11566 case 1:
11567 up_bitmap = 0xF0;
11568 break;
11569 case 2:
11570 up_bitmap = 0xF6;
11571 break;
11572 default:
11573 sigma_dut_print(dut, DUT_MSG_ERROR,
11574 "%s: Unknown User_Priority_Bitmap value %d",
11575 __func__, atoi(val));
11576 return INVALID_SEND_STATUS;
11577 }
11578
11579 len = snprintf(pos, rem_len, " up_bitmap=%02x", up_bitmap);
11580 if (len < 0 || len >= rem_len)
11581 goto fail;
11582
11583 pos += len;
11584 rem_len -= len;
11585
11586 val = get_param(cmd, "User_Priority_Limit");
11587 if (!val) {
11588 sigma_dut_print(dut, DUT_MSG_ERROR,
11589 "%s: invalid user priority limit", __func__);
11590 return INVALID_SEND_STATUS;
11591 }
11592
11593 len = snprintf(pos, rem_len, " up_limit=%s", val);
11594 if (len < 0 || len >= rem_len)
11595 goto fail;
11596
11597 pos += len;
11598 rem_len -= len;
11599
11600 val = get_param(cmd, "Stream_Timeout");
11601 if (!val)
11602 val = get_param(cmd, "Stream_Timtout");
11603 if (!val) {
11604 sigma_dut_print(dut, DUT_MSG_ERROR,
11605 "%s: invalid stream timeout", __func__);
11606 return INVALID_SEND_STATUS;
11607 }
11608
11609 len = snprintf(pos, rem_len, " stream_timeout=%s", val);
11610 if (len < 0 || len >= rem_len)
11611 goto fail;
11612
11613 pos += len;
11614 rem_len -= len;
11615
11616 val = get_param(cmd, "TCLAS_Mask");
11617 if (!val) {
11618 sigma_dut_print(dut, DUT_MSG_ERROR,
11619 "%s: invalid tclas mask", __func__);
11620 return INVALID_SEND_STATUS;
11621 }
11622
11623 len = snprintf(pos, rem_len, " frame_classifier=%s%lx%032x",
11624 classifier_type, strtol(val, NULL, 2), 0);
11625 if (len < 0 || len >= rem_len)
11626 goto fail;
11627
11628 if (wpa_command(intf, buf) != 0) {
11629 send_resp(dut, conn, SIGMA_ERROR,
11630 "ErrorCode,Failed to send MSCS frame req");
11631 return STATUS_SENT_ERROR;
11632 }
11633
11634 sigma_dut_print(dut, DUT_MSG_DEBUG,
11635 "MSCS frame request sent: %s", buf);
11636
11637 return SUCCESS_SEND_STATUS;
11638fail:
11639 sigma_dut_print(dut, DUT_MSG_ERROR,
11640 "Failed to create MSCS frame req");
11641 return ERROR_SEND_STATUS;
11642}
11643
11644
Jouni Malinenf7222712019-06-13 01:50:21 +030011645enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
11646 struct sigma_conn *conn,
11647 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011648{
11649 const char *intf = get_param(cmd, "Interface");
11650 const char *val;
11651 enum send_frame_type frame;
11652 enum send_frame_protection protected;
11653 char buf[100];
11654 unsigned char addr[ETH_ALEN];
11655 int res;
11656
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011657 if (!intf)
11658 return -1;
11659
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011660 val = get_param(cmd, "program");
11661 if (val == NULL)
11662 val = get_param(cmd, "frame");
11663 if (val && strcasecmp(val, "TDLS") == 0)
11664 return cmd_sta_send_frame_tdls(dut, conn, cmd);
11665 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011666 strcasecmp(val, "HS2-R2") == 0 ||
11667 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011668 return cmd_sta_send_frame_hs2(dut, conn, cmd);
11669 if (val && strcasecmp(val, "VHT") == 0)
11670 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011671 if (val && strcasecmp(val, "HE") == 0)
11672 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070011673 if (val && strcasecmp(val, "LOC") == 0)
11674 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020011675 if (val && strcasecmp(val, "60GHz") == 0)
11676 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011677 if (val && strcasecmp(val, "MBO") == 0) {
11678 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
11679 if (res != 2)
11680 return res;
11681 }
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011682 if (val && strcasecmp(val, "WPA3") == 0)
11683 return cmd_sta_send_frame_wpa3(dut, conn, intf, cmd);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011684 if (val && strcasecmp(val, "QM") == 0)
11685 return cmd_sta_send_frame_mscs(dut, conn, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011686
11687 val = get_param(cmd, "TD_DISC");
11688 if (val) {
11689 if (hwaddr_aton(val, addr) < 0)
11690 return -1;
11691 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
11692 if (wpa_command(intf, buf) < 0) {
11693 send_resp(dut, conn, SIGMA_ERROR,
11694 "ErrorCode,Failed to send TDLS discovery");
11695 return 0;
11696 }
11697 return 1;
11698 }
11699
11700 val = get_param(cmd, "TD_Setup");
11701 if (val) {
11702 if (hwaddr_aton(val, addr) < 0)
11703 return -1;
11704 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
11705 if (wpa_command(intf, buf) < 0) {
11706 send_resp(dut, conn, SIGMA_ERROR,
11707 "ErrorCode,Failed to start TDLS setup");
11708 return 0;
11709 }
11710 return 1;
11711 }
11712
11713 val = get_param(cmd, "TD_TearDown");
11714 if (val) {
11715 if (hwaddr_aton(val, addr) < 0)
11716 return -1;
11717 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
11718 if (wpa_command(intf, buf) < 0) {
11719 send_resp(dut, conn, SIGMA_ERROR,
11720 "ErrorCode,Failed to tear down TDLS link");
11721 return 0;
11722 }
11723 return 1;
11724 }
11725
11726 val = get_param(cmd, "TD_ChannelSwitch");
11727 if (val) {
11728 /* TODO */
11729 send_resp(dut, conn, SIGMA_ERROR,
11730 "ErrorCode,TD_ChannelSwitch not yet supported");
11731 return 0;
11732 }
11733
11734 val = get_param(cmd, "TD_NF");
11735 if (val) {
11736 /* TODO */
11737 send_resp(dut, conn, SIGMA_ERROR,
11738 "ErrorCode,TD_NF not yet supported");
11739 return 0;
11740 }
11741
11742 val = get_param(cmd, "PMFFrameType");
11743 if (val == NULL)
11744 val = get_param(cmd, "FrameName");
11745 if (val == NULL)
11746 val = get_param(cmd, "Type");
11747 if (val == NULL)
11748 return -1;
11749 if (strcasecmp(val, "disassoc") == 0)
11750 frame = DISASSOC;
11751 else if (strcasecmp(val, "deauth") == 0)
11752 frame = DEAUTH;
11753 else if (strcasecmp(val, "saquery") == 0)
11754 frame = SAQUERY;
11755 else if (strcasecmp(val, "auth") == 0)
11756 frame = AUTH;
11757 else if (strcasecmp(val, "assocreq") == 0)
11758 frame = ASSOCREQ;
11759 else if (strcasecmp(val, "reassocreq") == 0)
11760 frame = REASSOCREQ;
11761 else if (strcasecmp(val, "neigreq") == 0) {
11762 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
11763
11764 val = get_param(cmd, "ssid");
11765 if (val == NULL)
11766 return -1;
11767
11768 res = send_neighbor_request(dut, intf, val);
11769 if (res) {
11770 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11771 "Failed to send neighbor report request");
11772 return 0;
11773 }
11774
11775 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053011776 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
11777 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011778 sigma_dut_print(dut, DUT_MSG_DEBUG,
11779 "Got Transition Management Query");
11780
Ashwini Patil5acd7382017-04-13 15:55:04 +053011781 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011782 if (res) {
11783 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11784 "Failed to send Transition Management Query");
11785 return 0;
11786 }
11787
11788 return 1;
11789 } else {
11790 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11791 "PMFFrameType");
11792 return 0;
11793 }
11794
11795 val = get_param(cmd, "PMFProtected");
11796 if (val == NULL)
11797 val = get_param(cmd, "Protected");
11798 if (val == NULL)
11799 return -1;
11800 if (strcasecmp(val, "Correct-key") == 0 ||
11801 strcasecmp(val, "CorrectKey") == 0)
11802 protected = CORRECT_KEY;
11803 else if (strcasecmp(val, "IncorrectKey") == 0)
11804 protected = INCORRECT_KEY;
11805 else if (strcasecmp(val, "Unprotected") == 0)
11806 protected = UNPROTECTED;
11807 else {
11808 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11809 "PMFProtected");
11810 return 0;
11811 }
11812
11813 if (protected != UNPROTECTED &&
11814 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
11815 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
11816 "PMFProtected for auth/assocreq/reassocreq");
11817 return 0;
11818 }
11819
11820 if (if_nametoindex("sigmadut") == 0) {
11821 snprintf(buf, sizeof(buf),
11822 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011823 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011824 if (system(buf) != 0 ||
11825 if_nametoindex("sigmadut") == 0) {
11826 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11827 "monitor interface with '%s'", buf);
11828 return -2;
11829 }
11830 }
11831
11832 if (system("ifconfig sigmadut up") != 0) {
11833 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11834 "monitor interface up");
11835 return -2;
11836 }
11837
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011838 return sta_inject_frame(dut, conn, intf, frame, protected, NULL, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011839}
11840
11841
11842static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
11843 struct sigma_conn *conn,
11844 struct sigma_cmd *cmd,
11845 const char *ifname)
11846{
11847 char buf[200];
11848 const char *val;
11849
11850 val = get_param(cmd, "ClearARP");
11851 if (val && atoi(val) == 1) {
11852 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
11853 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11854 if (system(buf) != 0) {
11855 send_resp(dut, conn, SIGMA_ERROR,
11856 "errorCode,Failed to clear ARP cache");
11857 return 0;
11858 }
11859 }
11860
11861 return 1;
11862}
11863
11864
11865int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
11866 struct sigma_cmd *cmd)
11867{
11868 const char *intf = get_param(cmd, "Interface");
11869 const char *val;
11870
11871 if (intf == NULL)
11872 return -1;
11873
11874 val = get_param(cmd, "program");
11875 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011876 strcasecmp(val, "HS2-R2") == 0 ||
11877 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011878 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
11879
11880 return -1;
11881}
11882
11883
Jouni Malinenf7222712019-06-13 01:50:21 +030011884static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
11885 struct sigma_conn *conn,
11886 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011887{
11888 const char *intf = get_param(cmd, "Interface");
11889 const char *mac = get_param(cmd, "MAC");
11890
11891 if (intf == NULL || mac == NULL)
11892 return -1;
11893
11894 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
11895 "interface %s to %s", intf, mac);
11896
11897 if (dut->set_macaddr) {
11898 char buf[128];
11899 int res;
11900 if (strcasecmp(mac, "default") == 0) {
11901 res = snprintf(buf, sizeof(buf), "%s",
11902 dut->set_macaddr);
11903 dut->tmp_mac_addr = 0;
11904 } else {
11905 res = snprintf(buf, sizeof(buf), "%s %s",
11906 dut->set_macaddr, mac);
11907 dut->tmp_mac_addr = 1;
11908 }
11909 if (res < 0 || res >= (int) sizeof(buf))
11910 return -1;
11911 if (system(buf) != 0) {
11912 send_resp(dut, conn, SIGMA_ERROR,
11913 "errorCode,Failed to set MAC "
11914 "address");
11915 return 0;
11916 }
11917 return 1;
11918 }
11919
11920 if (strcasecmp(mac, "default") == 0)
11921 return 1;
11922
11923 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11924 "command");
11925 return 0;
11926}
11927
11928
11929static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
11930 struct sigma_conn *conn, const char *intf,
11931 int val)
11932{
11933 char buf[200];
11934 int res;
11935
11936 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
11937 intf, val);
11938 if (res < 0 || res >= (int) sizeof(buf))
11939 return -1;
11940 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11941 if (system(buf) != 0) {
11942 send_resp(dut, conn, SIGMA_ERROR,
11943 "errorCode,Failed to configure offchannel mode");
11944 return 0;
11945 }
11946
11947 return 1;
11948}
11949
11950
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011951static int off_chan_val(enum sec_ch_offset off)
11952{
11953 switch (off) {
11954 case SEC_CH_NO:
11955 return 0;
11956 case SEC_CH_40ABOVE:
11957 return 40;
11958 case SEC_CH_40BELOW:
11959 return -40;
11960 }
11961
11962 return 0;
11963}
11964
11965
11966static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
11967 const char *intf, int off_ch_num,
11968 enum sec_ch_offset sec)
11969{
11970 char buf[200];
11971 int res;
11972
11973 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
11974 intf, off_ch_num);
11975 if (res < 0 || res >= (int) sizeof(buf))
11976 return -1;
11977 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11978 if (system(buf) != 0) {
11979 send_resp(dut, conn, SIGMA_ERROR,
11980 "errorCode,Failed to set offchan");
11981 return 0;
11982 }
11983
11984 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
11985 intf, off_chan_val(sec));
11986 if (res < 0 || res >= (int) sizeof(buf))
11987 return -1;
11988 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11989 if (system(buf) != 0) {
11990 send_resp(dut, conn, SIGMA_ERROR,
11991 "errorCode,Failed to set sec chan offset");
11992 return 0;
11993 }
11994
11995 return 1;
11996}
11997
11998
11999static int tdls_set_offchannel_offset(struct sigma_dut *dut,
12000 struct sigma_conn *conn,
12001 const char *intf, int off_ch_num,
12002 enum sec_ch_offset sec)
12003{
12004 char buf[200];
12005 int res;
12006
12007 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
12008 off_ch_num);
12009 if (res < 0 || res >= (int) sizeof(buf))
12010 return -1;
12011 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12012
12013 if (wpa_command(intf, buf) < 0) {
12014 send_resp(dut, conn, SIGMA_ERROR,
12015 "ErrorCode,Failed to set offchan");
12016 return 0;
12017 }
12018 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
12019 off_chan_val(sec));
12020 if (res < 0 || res >= (int) sizeof(buf))
12021 return -1;
12022
12023 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12024
12025 if (wpa_command(intf, buf) < 0) {
12026 send_resp(dut, conn, SIGMA_ERROR,
12027 "ErrorCode,Failed to set sec chan offset");
12028 return 0;
12029 }
12030
12031 return 1;
12032}
12033
12034
12035static int tdls_set_offchannel_mode(struct sigma_dut *dut,
12036 struct sigma_conn *conn,
12037 const char *intf, int val)
12038{
12039 char buf[200];
12040 int res;
12041
12042 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
12043 val);
12044 if (res < 0 || res >= (int) sizeof(buf))
12045 return -1;
12046 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12047
12048 if (wpa_command(intf, buf) < 0) {
12049 send_resp(dut, conn, SIGMA_ERROR,
12050 "ErrorCode,Failed to configure offchannel mode");
12051 return 0;
12052 }
12053
12054 return 1;
12055}
12056
12057
12058static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
12059 struct sigma_conn *conn,
12060 struct sigma_cmd *cmd)
12061{
12062 const char *val;
12063 enum {
12064 CHSM_NOT_SET,
12065 CHSM_ENABLE,
12066 CHSM_DISABLE,
12067 CHSM_REJREQ,
12068 CHSM_UNSOLRESP
12069 } chsm = CHSM_NOT_SET;
12070 int off_ch_num = -1;
12071 enum sec_ch_offset sec_ch = SEC_CH_NO;
12072 int res;
12073
12074 val = get_param(cmd, "Uapsd");
12075 if (val) {
12076 char buf[100];
12077 if (strcasecmp(val, "Enable") == 0)
12078 snprintf(buf, sizeof(buf), "SET ps 99");
12079 else if (strcasecmp(val, "Disable") == 0)
12080 snprintf(buf, sizeof(buf), "SET ps 98");
12081 else {
12082 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
12083 "Unsupported uapsd parameter value");
12084 return 0;
12085 }
12086 if (wpa_command(intf, buf)) {
12087 send_resp(dut, conn, SIGMA_ERROR,
12088 "ErrorCode,Failed to change U-APSD "
12089 "powersave mode");
12090 return 0;
12091 }
12092 }
12093
12094 val = get_param(cmd, "TPKTIMER");
12095 if (val && strcasecmp(val, "DISABLE") == 0) {
12096 if (wpa_command(intf, "SET tdls_testing 0x100")) {
12097 send_resp(dut, conn, SIGMA_ERROR,
12098 "ErrorCode,Failed to enable no TPK "
12099 "expiration test mode");
12100 return 0;
12101 }
12102 dut->no_tpk_expiration = 1;
12103 }
12104
12105 val = get_param(cmd, "ChSwitchMode");
12106 if (val) {
12107 if (strcasecmp(val, "Enable") == 0 ||
12108 strcasecmp(val, "Initiate") == 0)
12109 chsm = CHSM_ENABLE;
12110 else if (strcasecmp(val, "Disable") == 0 ||
12111 strcasecmp(val, "passive") == 0)
12112 chsm = CHSM_DISABLE;
12113 else if (strcasecmp(val, "RejReq") == 0)
12114 chsm = CHSM_REJREQ;
12115 else if (strcasecmp(val, "UnSolResp") == 0)
12116 chsm = CHSM_UNSOLRESP;
12117 else {
12118 send_resp(dut, conn, SIGMA_ERROR,
12119 "ErrorCode,Unknown ChSwitchMode value");
12120 return 0;
12121 }
12122 }
12123
12124 val = get_param(cmd, "OffChNum");
12125 if (val) {
12126 off_ch_num = atoi(val);
12127 if (off_ch_num == 0) {
12128 send_resp(dut, conn, SIGMA_ERROR,
12129 "ErrorCode,Invalid OffChNum");
12130 return 0;
12131 }
12132 }
12133
12134 val = get_param(cmd, "SecChOffset");
12135 if (val) {
12136 if (strcmp(val, "20") == 0)
12137 sec_ch = SEC_CH_NO;
12138 else if (strcasecmp(val, "40above") == 0)
12139 sec_ch = SEC_CH_40ABOVE;
12140 else if (strcasecmp(val, "40below") == 0)
12141 sec_ch = SEC_CH_40BELOW;
12142 else {
12143 send_resp(dut, conn, SIGMA_ERROR,
12144 "ErrorCode,Unknown SecChOffset value");
12145 return 0;
12146 }
12147 }
12148
12149 if (chsm == CHSM_NOT_SET) {
12150 /* no offchannel changes requested */
12151 return 1;
12152 }
12153
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012154 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
12155 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012156 send_resp(dut, conn, SIGMA_ERROR,
12157 "ErrorCode,Unknown interface");
12158 return 0;
12159 }
12160
12161 switch (chsm) {
12162 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030012163 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012164 break;
12165 case CHSM_ENABLE:
12166 if (off_ch_num < 0) {
12167 send_resp(dut, conn, SIGMA_ERROR,
12168 "ErrorCode,Missing OffChNum argument");
12169 return 0;
12170 }
12171 if (wifi_chip_type == DRIVER_WCN) {
12172 res = tdls_set_offchannel_offset(dut, conn, intf,
12173 off_ch_num, sec_ch);
12174 } else {
12175 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
12176 sec_ch);
12177 }
12178 if (res != 1)
12179 return res;
12180 if (wifi_chip_type == DRIVER_WCN)
12181 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
12182 else
12183 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
12184 break;
12185 case CHSM_DISABLE:
12186 if (wifi_chip_type == DRIVER_WCN)
12187 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
12188 else
12189 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
12190 break;
12191 case CHSM_REJREQ:
12192 if (wifi_chip_type == DRIVER_WCN)
12193 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
12194 else
12195 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
12196 break;
12197 case CHSM_UNSOLRESP:
12198 if (off_ch_num < 0) {
12199 send_resp(dut, conn, SIGMA_ERROR,
12200 "ErrorCode,Missing OffChNum argument");
12201 return 0;
12202 }
12203 if (wifi_chip_type == DRIVER_WCN) {
12204 res = tdls_set_offchannel_offset(dut, conn, intf,
12205 off_ch_num, sec_ch);
12206 } else {
12207 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
12208 sec_ch);
12209 }
12210 if (res != 1)
12211 return res;
12212 if (wifi_chip_type == DRIVER_WCN)
12213 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
12214 else
12215 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
12216 break;
12217 }
12218
12219 return res;
12220}
12221
12222
12223static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
12224 struct sigma_conn *conn,
12225 struct sigma_cmd *cmd)
12226{
12227 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053012228 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012229
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070012230 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080012231
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012232 val = get_param(cmd, "nss_mcs_opt");
12233 if (val) {
12234 /* String (nss_operating_mode; mcs_operating_mode) */
12235 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012236 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012237
12238 token = strdup(val);
12239 if (!token)
12240 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012241 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053012242 if (!result) {
12243 sigma_dut_print(dut, DUT_MSG_ERROR,
12244 "VHT NSS not specified");
12245 goto failed;
12246 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012247 if (strcasecmp(result, "def") != 0) {
12248 nss = atoi(result);
12249 if (nss == 4)
12250 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012251 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012252 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012253
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012254 }
12255
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012256 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053012257 if (!result) {
12258 sigma_dut_print(dut, DUT_MSG_ERROR,
12259 "VHT MCS not specified");
12260 goto failed;
12261 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012262 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012263 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012264 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012265 } else {
12266 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012267 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012268 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012269 }
12270 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012271 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012272 }
12273
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053012274 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012275 return 1;
12276failed:
12277 free(token);
12278 return 0;
12279}
12280
12281
12282static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
12283 struct sigma_conn *conn,
12284 struct sigma_cmd *cmd)
12285{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012286 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012287 case DRIVER_ATHEROS:
12288 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
12289 default:
12290 send_resp(dut, conn, SIGMA_ERROR,
12291 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
12292 return 0;
12293 }
12294}
12295
12296
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012297static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12298 struct sigma_conn *conn,
12299 struct sigma_cmd *cmd)
12300{
12301 const char *val;
12302 char *token = NULL, *result;
12303 char buf[60];
12304
12305 val = get_param(cmd, "nss_mcs_opt");
12306 if (val) {
12307 /* String (nss_operating_mode; mcs_operating_mode) */
12308 int nss, mcs, ratecode;
12309 char *saveptr;
12310
12311 token = strdup(val);
12312 if (!token)
12313 return -2;
12314
12315 result = strtok_r(token, ";", &saveptr);
12316 if (!result) {
12317 sigma_dut_print(dut, DUT_MSG_ERROR,
12318 "HE NSS not specified");
12319 goto failed;
12320 }
12321 nss = 1;
12322 if (strcasecmp(result, "def") != 0)
12323 nss = atoi(result);
12324
12325 result = strtok_r(NULL, ";", &saveptr);
12326 if (!result) {
12327 sigma_dut_print(dut, DUT_MSG_ERROR,
12328 "HE MCS not specified");
12329 goto failed;
12330 }
12331 mcs = 7;
12332 if (strcasecmp(result, "def") != 0)
12333 mcs = atoi(result);
12334
Arif Hussain557bf412018-05-25 17:29:36 -070012335 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012336 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070012337 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012338 } else if (nss > 2) {
12339 sigma_dut_print(dut, DUT_MSG_ERROR,
12340 "HE NSS %d not supported", nss);
12341 goto failed;
12342 }
12343
Arif Hussain557bf412018-05-25 17:29:36 -070012344 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
12345 if (system(buf) != 0) {
12346 sigma_dut_print(dut, DUT_MSG_ERROR,
12347 "nss_mcs_opt: iwpriv %s nss %d failed",
12348 intf, nss);
12349 goto failed;
12350 }
Arif Hussainac6c5112018-05-25 17:34:00 -070012351 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070012352
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012353 /* Add the MCS to the ratecode */
12354 if (mcs >= 0 && mcs <= 11) {
12355 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070012356#ifdef NL80211_SUPPORT
12357 if (dut->device_type == STA_testbed) {
12358 enum he_mcs_config mcs_config;
12359 int ret;
12360
12361 if (mcs <= 7)
12362 mcs_config = HE_80_MCS0_7;
12363 else if (mcs <= 9)
12364 mcs_config = HE_80_MCS0_9;
12365 else
12366 mcs_config = HE_80_MCS0_11;
12367 ret = sta_set_he_mcs(dut, intf, mcs_config);
12368 if (ret) {
12369 sigma_dut_print(dut, DUT_MSG_ERROR,
12370 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
12371 mcs, mcs_config, ret);
12372 goto failed;
12373 }
12374 }
12375#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012376 } else {
12377 sigma_dut_print(dut, DUT_MSG_ERROR,
12378 "HE MCS %d not supported", mcs);
12379 goto failed;
12380 }
12381 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
12382 intf, ratecode);
12383 if (system(buf) != 0) {
12384 sigma_dut_print(dut, DUT_MSG_ERROR,
12385 "iwpriv setting of 11ax rates failed");
12386 goto failed;
12387 }
12388 free(token);
12389 }
12390
12391 val = get_param(cmd, "GI");
12392 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012393 int fix_rate_sgi;
12394
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012395 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012396 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012397 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012398 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012399 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
12400 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012401 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012402 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012403 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
12404 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012405 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012406 } else {
12407 send_resp(dut, conn, SIGMA_ERROR,
12408 "errorCode,GI value not supported");
12409 return 0;
12410 }
12411 if (system(buf) != 0) {
12412 send_resp(dut, conn, SIGMA_ERROR,
12413 "errorCode,Failed to set shortgi");
12414 return 0;
12415 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012416 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
12417 intf, fix_rate_sgi);
12418 if (system(buf) != 0) {
12419 send_resp(dut, conn, SIGMA_ERROR,
12420 "errorCode,Failed to set fix rate shortgi");
12421 return STATUS_SENT;
12422 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012423 }
12424
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012425 val = get_param(cmd, "LTF");
12426 if (val) {
12427#ifdef NL80211_SUPPORT
12428 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012429 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012430 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012431 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012432 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012433 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012434 } else {
12435 send_resp(dut, conn, SIGMA_ERROR,
12436 "errorCode, LTF value not supported");
12437 return 0;
12438 }
12439#else /* NL80211_SUPPORT */
12440 sigma_dut_print(dut, DUT_MSG_ERROR,
12441 "LTF cannot be set without NL80211_SUPPORT defined");
12442 return -2;
12443#endif /* NL80211_SUPPORT */
12444 }
12445
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070012446 val = get_param(cmd, "TxSUPPDU");
12447 if (val) {
12448 int set_val = 1;
12449
12450 if (strcasecmp(val, "Enable") == 0)
12451 set_val = 1;
12452 else if (strcasecmp(val, "Disable") == 0)
12453 set_val = 0;
12454
12455 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
12456 send_resp(dut, conn, SIGMA_ERROR,
12457 "ErrorCode,Failed to set Tx SU PPDU config");
12458 return 0;
12459 }
12460 }
12461
Arif Hussain480d5f42019-03-12 14:40:42 -070012462 val = get_param(cmd, "TWT_Setup");
12463 if (val) {
12464 if (strcasecmp(val, "Request") == 0) {
12465 if (sta_twt_request(dut, conn, cmd)) {
12466 send_resp(dut, conn, SIGMA_ERROR,
12467 "ErrorCode,sta_twt_request failed");
12468 return STATUS_SENT;
12469 }
12470 } else if (strcasecmp(val, "Teardown") == 0) {
12471 if (sta_twt_teardown(dut, conn, cmd)) {
12472 send_resp(dut, conn, SIGMA_ERROR,
12473 "ErrorCode,sta_twt_teardown failed");
12474 return STATUS_SENT;
12475 }
12476 }
12477 }
12478
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080012479 val = get_param(cmd, "transmitOMI");
12480 if (val && sta_transmit_omi(dut, conn, cmd)) {
12481 send_resp(dut, conn, SIGMA_ERROR,
12482 "ErrorCode,sta_transmit_omi failed");
12483 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070012484 }
12485
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012486 val = get_param(cmd, "Powersave");
12487 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012488 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012489
12490 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012491 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012492 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012493 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012494 } else {
12495 sigma_dut_print(dut, DUT_MSG_ERROR,
12496 "Unsupported Powersave value '%s'",
12497 val);
12498 return -1;
12499 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012500 if (set_power_save_wcn(dut, intf, ps) < 0)
12501 return 0;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012502 }
12503
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080012504 val = get_param(cmd, "MU_EDCA");
12505 if (val) {
12506 if (strcasecmp(val, "Override") == 0) {
12507 if (sta_set_mu_edca_override(dut, intf, 1)) {
12508 send_resp(dut, conn, SIGMA_ERROR,
12509 "errorCode,MU EDCA override set failed");
12510 return STATUS_SENT;
12511 }
12512 } else if (strcasecmp(val, "Disable") == 0) {
12513 if (sta_set_mu_edca_override(dut, intf, 0)) {
12514 send_resp(dut, conn, SIGMA_ERROR,
12515 "errorCode,MU EDCA override disable failed");
12516 return STATUS_SENT;
12517 }
12518 }
12519 }
12520
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -070012521 val = get_param(cmd, "Ch_Pref");
12522 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12523 return STATUS_SENT;
12524
12525 val = get_param(cmd, "Cellular_Data_Cap");
12526 if (val && mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12527 return STATUS_SENT;
12528
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012529 return 1;
12530
12531failed:
12532 free(token);
12533 return -2;
12534}
12535
12536
12537static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12538 struct sigma_conn *conn,
12539 struct sigma_cmd *cmd)
12540{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012541 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012542 case DRIVER_WCN:
12543 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
12544 default:
12545 send_resp(dut, conn, SIGMA_ERROR,
12546 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
12547 return 0;
12548 }
12549}
12550
12551
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012552static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
12553 struct sigma_conn *conn,
12554 struct sigma_cmd *cmd)
12555{
12556 const char *val;
12557
12558 val = get_param(cmd, "powersave");
12559 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012560 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012561
12562 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012563 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012564 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012565 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012566 } else {
12567 sigma_dut_print(dut, DUT_MSG_ERROR,
12568 "Unsupported power save config");
12569 return -1;
12570 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012571 if (set_power_save_wcn(dut, intf, ps) < 0)
12572 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012573 return 1;
12574 }
12575
12576 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
12577
12578 return 0;
12579}
12580
12581
Ashwini Patil5acd7382017-04-13 15:55:04 +053012582static int btm_query_candidate_list(struct sigma_dut *dut,
12583 struct sigma_conn *conn,
12584 struct sigma_cmd *cmd)
12585{
12586 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
12587 int len, ret;
12588 char buf[10];
12589
12590 /*
12591 * Neighbor Report elements format:
12592 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
12593 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
12594 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
12595 */
12596
12597 bssid = get_param(cmd, "Nebor_BSSID");
12598 if (!bssid) {
12599 send_resp(dut, conn, SIGMA_INVALID,
12600 "errorCode,Nebor_BSSID is missing");
12601 return 0;
12602 }
12603
12604 info = get_param(cmd, "Nebor_Bssid_Info");
12605 if (!info) {
12606 sigma_dut_print(dut, DUT_MSG_INFO,
12607 "Using default value for Nebor_Bssid_Info: %s",
12608 DEFAULT_NEIGHBOR_BSSID_INFO);
12609 info = DEFAULT_NEIGHBOR_BSSID_INFO;
12610 }
12611
12612 op_class = get_param(cmd, "Nebor_Op_Class");
12613 if (!op_class) {
12614 send_resp(dut, conn, SIGMA_INVALID,
12615 "errorCode,Nebor_Op_Class is missing");
12616 return 0;
12617 }
12618
12619 ch = get_param(cmd, "Nebor_Op_Ch");
12620 if (!ch) {
12621 send_resp(dut, conn, SIGMA_INVALID,
12622 "errorCode,Nebor_Op_Ch is missing");
12623 return 0;
12624 }
12625
12626 phy_type = get_param(cmd, "Nebor_Phy_Type");
12627 if (!phy_type) {
12628 sigma_dut_print(dut, DUT_MSG_INFO,
12629 "Using default value for Nebor_Phy_Type: %s",
12630 DEFAULT_NEIGHBOR_PHY_TYPE);
12631 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
12632 }
12633
12634 /* Parse optional subelements */
12635 buf[0] = '\0';
12636 pref = get_param(cmd, "Nebor_Pref");
12637 if (pref) {
12638 /* hexdump for preferrence subelement */
12639 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
12640 if (ret < 0 || ret >= (int) sizeof(buf)) {
12641 sigma_dut_print(dut, DUT_MSG_ERROR,
12642 "snprintf failed for optional subelement ret: %d",
12643 ret);
12644 send_resp(dut, conn, SIGMA_ERROR,
12645 "errorCode,snprintf failed for subelement");
12646 return 0;
12647 }
12648 }
12649
12650 if (!dut->btm_query_cand_list) {
12651 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
12652 if (!dut->btm_query_cand_list) {
12653 send_resp(dut, conn, SIGMA_ERROR,
12654 "errorCode,Failed to allocate memory for btm_query_cand_list");
12655 return 0;
12656 }
12657 }
12658
12659 len = strlen(dut->btm_query_cand_list);
12660 ret = snprintf(dut->btm_query_cand_list + len,
12661 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
12662 bssid, info, op_class, ch, phy_type, buf);
12663 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
12664 sigma_dut_print(dut, DUT_MSG_ERROR,
12665 "snprintf failed for neighbor report list ret: %d",
12666 ret);
12667 send_resp(dut, conn, SIGMA_ERROR,
12668 "errorCode,snprintf failed for neighbor report");
12669 free(dut->btm_query_cand_list);
12670 dut->btm_query_cand_list = NULL;
12671 return 0;
12672 }
12673
12674 return 1;
12675}
12676
12677
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012678int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
12679 struct sigma_ese_alloc *allocs, int *allocs_size)
12680{
12681 int max_count = *allocs_size;
12682 int count = 0, i;
12683 const char *val;
12684
12685 do {
12686 val = get_param_indexed(cmd, "AllocID", count);
12687 if (val)
12688 count++;
12689 } while (val);
12690
12691 if (count == 0 || count > max_count) {
12692 sigma_dut_print(dut, DUT_MSG_ERROR,
12693 "Invalid number of allocations(%d)", count);
12694 return -1;
12695 }
12696
12697 for (i = 0; i < count; i++) {
12698 val = get_param_indexed(cmd, "PercentBI", i);
12699 if (!val) {
12700 sigma_dut_print(dut, DUT_MSG_ERROR,
12701 "Missing PercentBI parameter at index %d",
12702 i);
12703 return -1;
12704 }
12705 allocs[i].percent_bi = atoi(val);
12706
12707 val = get_param_indexed(cmd, "SrcAID", i);
12708 if (val)
12709 allocs[i].src_aid = strtol(val, NULL, 0);
12710 else
12711 allocs[i].src_aid = ESE_BCAST_AID;
12712
12713 val = get_param_indexed(cmd, "DestAID", i);
12714 if (val)
12715 allocs[i].dst_aid = strtol(val, NULL, 0);
12716 else
12717 allocs[i].dst_aid = ESE_BCAST_AID;
12718
12719 allocs[i].type = ESE_CBAP;
12720 sigma_dut_print(dut, DUT_MSG_INFO,
12721 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
12722 i, allocs[i].percent_bi, allocs[i].src_aid,
12723 allocs[i].dst_aid);
12724 }
12725
12726 *allocs_size = count;
12727 return 0;
12728}
12729
12730
12731static int sta_set_60g_ese(struct sigma_dut *dut, int count,
12732 struct sigma_ese_alloc *allocs)
12733{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012734 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012735#ifdef __linux__
12736 case DRIVER_WIL6210:
12737 if (wil6210_set_ese(dut, count, allocs))
12738 return -1;
12739 return 1;
12740#endif /* __linux__ */
12741 default:
12742 sigma_dut_print(dut, DUT_MSG_ERROR,
12743 "Unsupported sta_set_60g_ese with the current driver");
12744 return -1;
12745 }
12746}
12747
12748
12749static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
12750 struct sigma_conn *conn,
12751 struct sigma_cmd *cmd)
12752{
12753 const char *val;
12754
12755 val = get_param(cmd, "ExtSchIE");
12756 if (val && !strcasecmp(val, "Enable")) {
12757 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
12758 int count = MAX_ESE_ALLOCS;
12759
12760 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
12761 return -1;
12762 return sta_set_60g_ese(dut, count, allocs);
12763 }
12764
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012765 val = get_param(cmd, "MCS_FixedRate");
12766 if (val) {
12767 int sta_mcs = atoi(val);
12768
12769 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
12770 sta_mcs);
12771 wil6210_set_force_mcs(dut, 1, sta_mcs);
12772
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012773 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012774 }
12775
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012776 send_resp(dut, conn, SIGMA_ERROR,
12777 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012778 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012779}
12780
12781
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012782static int wcn_sta_override_oci(struct sigma_dut *dut, const char *intf,
12783 const char *oci_frametype, uint32_t oci_freq)
12784{
12785#ifdef NL80211_SUPPORT
12786 struct nl_msg *msg;
12787 int ret = 0;
12788 struct nlattr *params;
12789 struct nlattr *attr;
12790 int ifindex;
12791 u8 frame_type;
12792
12793 ifindex = if_nametoindex(intf);
12794 if (ifindex == 0) {
12795 sigma_dut_print(dut, DUT_MSG_ERROR,
12796 "%s: Index for interface %s failed",
12797 __func__, intf);
12798 return -1;
12799 }
12800
12801 if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12802 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_REQ;
12803 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12804 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_RESP;
12805 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
12806 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_FT_REASSOC_REQ;
12807 } else {
12808 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: Unknown frametype %s",
12809 __func__, oci_frametype);
12810 return -1;
12811 }
12812
12813
12814 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
12815 NL80211_CMD_VENDOR)) ||
12816 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
12817 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
12818 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
12819 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
12820 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
12821 !(params = nla_nest_start(
12822 msg,
12823 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OCI_OVERRIDE)) ||
12824 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FRAME_TYPE,
12825 frame_type) ||
12826 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FREQUENCY,
12827 oci_freq)) {
12828 sigma_dut_print(dut, DUT_MSG_ERROR,
12829 "%s: err in adding vendor_cmd and vendor_data",
12830 __func__);
12831 nlmsg_free(msg);
12832 return -1;
12833 }
12834 nla_nest_end(msg, params);
12835 nla_nest_end(msg, attr);
12836
12837 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
12838 if (ret) {
12839 sigma_dut_print(dut, DUT_MSG_ERROR,
12840 "%s: err in send_and_recv_msgs, ret=%d",
12841 __func__, ret);
12842 }
12843 return ret;
12844#else /* NL80211_SUPPORT */
12845 sigma_dut_print(dut, DUT_MSG_ERROR,
12846 "OCI override not possible without NL80211_SUPPORT defined");
12847 return -1;
12848#endif /* NL80211_SUPPORT */
12849}
12850
12851
Jouni Malinen6250cb02020-04-15 13:54:45 +030012852static enum sigma_cmd_result
12853cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
12854 struct sigma_conn *conn,
12855 struct sigma_cmd *cmd)
12856{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012857 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030012858
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053012859 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030012860 if (val && atoi(val) == 1) {
12861 if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
12862 send_resp(dut, conn, SIGMA_ERROR,
12863 "errorCode,Failed to set ft_rsnxe_used");
12864 return STATUS_SENT_ERROR;
12865 }
12866 return SUCCESS_SEND_STATUS;
12867 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012868
12869 oci_chan = get_param(cmd, "OCIChannel");
12870 oci_frametype = get_param(cmd, "OCIFrameType");
12871 if (oci_chan && oci_frametype) {
12872 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
12873 char buf[100];
12874
12875 if (!oci_freq) {
12876 send_resp(dut, conn, SIGMA_ERROR,
12877 "errorCode,Invalid OCIChannel number");
12878 return STATUS_SENT_ERROR;
12879 }
12880
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012881 if (wifi_chip_type == DRIVER_WCN &&
12882 (strcasecmp(oci_frametype, "SAQueryReq") == 0 ||
12883 strcasecmp(oci_frametype, "SAQueryResp") == 0 ||
12884 strcasecmp(oci_frametype, "Reassocreq") == 0)) {
12885 if (wcn_sta_override_oci(dut, intf, oci_frametype,
12886 oci_freq)) {
12887 send_resp(dut, conn, SIGMA_ERROR,
12888 "errorCode,Failed to override OCI");
12889 return STATUS_SENT_ERROR;
12890 }
12891 return SUCCESS_SEND_STATUS;
12892 }
12893
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012894 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
12895 snprintf(buf, sizeof(buf),
12896 "SET oci_freq_override_eapol %d", oci_freq);
12897 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12898 snprintf(buf, sizeof(buf),
12899 "SET oci_freq_override_saquery_req %d",
12900 oci_freq);
12901 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12902 snprintf(buf, sizeof(buf),
12903 "SET oci_freq_override_saquery_resp %d",
12904 oci_freq);
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012905 } else if (strcasecmp(oci_frametype, "GrpKeyM2") == 0) {
12906 snprintf(buf, sizeof(buf),
12907 "SET oci_freq_override_eapol_g2 %d",
12908 oci_freq);
12909 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
12910 snprintf(buf, sizeof(buf),
12911 "SET oci_freq_override_ft_assoc %d",
12912 oci_freq);
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012913 } else {
12914 send_resp(dut, conn, SIGMA_ERROR,
12915 "errorCode,Unsupported OCIFrameType");
12916 return STATUS_SENT_ERROR;
12917 }
12918 if (wpa_command(intf, buf) < 0) {
12919 send_resp(dut, conn, SIGMA_ERROR,
12920 "errorCode,Failed to set oci_freq_override");
12921 return STATUS_SENT_ERROR;
12922 }
12923 return SUCCESS_SEND_STATUS;
12924 }
12925
Jouni Malinen6250cb02020-04-15 13:54:45 +030012926 send_resp(dut, conn, SIGMA_ERROR,
12927 "errorCode,Unsupported WPA3 rfeature");
12928 return STATUS_SENT_ERROR;
12929}
12930
12931
Jouni Malinenf7222712019-06-13 01:50:21 +030012932static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
12933 struct sigma_conn *conn,
12934 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012935{
12936 const char *intf = get_param(cmd, "Interface");
12937 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012938 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012939
12940 if (intf == NULL || prog == NULL)
12941 return -1;
12942
Ashwini Patil5acd7382017-04-13 15:55:04 +053012943 /* BSS Transition candidate list for BTM query */
12944 val = get_param(cmd, "Nebor_BSSID");
12945 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
12946 return 0;
12947
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012948 if (strcasecmp(prog, "TDLS") == 0)
12949 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
12950
12951 if (strcasecmp(prog, "VHT") == 0)
12952 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
12953
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012954 if (strcasecmp(prog, "HE") == 0)
12955 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
12956
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012957 if (strcasecmp(prog, "MBO") == 0) {
12958 val = get_param(cmd, "Cellular_Data_Cap");
12959 if (val &&
12960 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12961 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053012962
12963 val = get_param(cmd, "Ch_Pref");
12964 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12965 return 0;
12966
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012967 return 1;
12968 }
12969
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012970 if (strcasecmp(prog, "60GHz") == 0)
12971 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
12972
Jouni Malinen6250cb02020-04-15 13:54:45 +030012973 if (strcasecmp(prog, "WPA3") == 0)
12974 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
12975
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012976 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
12977 return 0;
12978}
12979
12980
Jouni Malinenf7222712019-06-13 01:50:21 +030012981static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
12982 struct sigma_conn *conn,
12983 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012984{
12985 const char *intf = get_param(cmd, "Interface");
12986 const char *mode = get_param(cmd, "Mode");
12987 int res;
12988
12989 if (intf == NULL || mode == NULL)
12990 return -1;
12991
12992 if (strcasecmp(mode, "On") == 0)
12993 res = wpa_command(intf, "SET radio_disabled 0");
12994 else if (strcasecmp(mode, "Off") == 0)
12995 res = wpa_command(intf, "SET radio_disabled 1");
12996 else
12997 return -1;
12998
12999 if (res) {
13000 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
13001 "radio mode");
13002 return 0;
13003 }
13004
13005 return 1;
13006}
13007
13008
Jouni Malinenf7222712019-06-13 01:50:21 +030013009static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
13010 struct sigma_conn *conn,
13011 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013012{
13013 const char *intf = get_param(cmd, "Interface");
13014 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013015 const char *prog = get_param(cmd, "program");
13016 const char *powersave = get_param(cmd, "powersave");
13017 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013018
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013019 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013020 return -1;
13021
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013022 if (prog && strcasecmp(prog, "60GHz") == 0) {
13023 /*
13024 * The CAPI mode parameter does not exist in 60G
13025 * unscheduled PS.
13026 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080013027 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013028 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013029 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020013030 strcasecmp(prog, "HE") == 0) {
13031 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013032 } else {
13033 if (mode == NULL)
13034 return -1;
13035
13036 if (strcasecmp(mode, "On") == 0)
13037 res = set_ps(intf, dut, 1);
13038 else if (strcasecmp(mode, "Off") == 0)
13039 res = set_ps(intf, dut, 0);
13040 else
13041 return -1;
13042 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013043
13044 if (res) {
13045 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
13046 "power save mode");
13047 return 0;
13048 }
13049
13050 return 1;
13051}
13052
13053
Jouni Malinenf7222712019-06-13 01:50:21 +030013054static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
13055 struct sigma_conn *conn,
13056 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013057{
13058 const char *intf = get_param(cmd, "Interface");
13059 const char *val, *bssid;
13060 int res;
13061 char *buf;
13062 size_t buf_len;
13063
13064 val = get_param(cmd, "BSSID_FILTER");
13065 if (val == NULL)
13066 return -1;
13067
13068 bssid = get_param(cmd, "BSSID_List");
13069 if (atoi(val) == 0 || bssid == NULL) {
13070 /* Disable BSSID filter */
13071 if (wpa_command(intf, "SET bssid_filter ")) {
13072 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
13073 "to disable BSSID filter");
13074 return 0;
13075 }
13076
13077 return 1;
13078 }
13079
13080 buf_len = 100 + strlen(bssid);
13081 buf = malloc(buf_len);
13082 if (buf == NULL)
13083 return -1;
13084
13085 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
13086 res = wpa_command(intf, buf);
13087 free(buf);
13088 if (res) {
13089 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
13090 "BSSID filter");
13091 return 0;
13092 }
13093
13094 return 1;
13095}
13096
13097
Jouni Malinenf7222712019-06-13 01:50:21 +030013098static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
13099 struct sigma_conn *conn,
13100 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013101{
13102 const char *intf = get_param(cmd, "Interface");
13103 const char *val;
13104
13105 /* TODO: ARP */
13106
13107 val = get_param(cmd, "HS2_CACHE_PROFILE");
13108 if (val && strcasecmp(val, "All") == 0)
13109 hs2_clear_credentials(intf);
13110
13111 return 1;
13112}
13113
13114
Jouni Malinenf7222712019-06-13 01:50:21 +030013115static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
13116 struct sigma_conn *conn,
13117 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013118{
13119 const char *intf = get_param(cmd, "Interface");
13120 const char *key_type = get_param(cmd, "KeyType");
13121 char buf[100], resp[200];
13122
13123 if (key_type == NULL)
13124 return -1;
13125
13126 if (strcasecmp(key_type, "GTK") == 0) {
13127 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
13128 strncmp(buf, "FAIL", 4) == 0) {
13129 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13130 "not fetch current GTK");
13131 return 0;
13132 }
13133 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
13134 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13135 return 0;
13136 } else {
13137 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13138 "KeyType");
13139 return 0;
13140 }
13141
13142 return 1;
13143}
13144
13145
13146static int hs2_set_policy(struct sigma_dut *dut)
13147{
13148#ifdef ANDROID
13149 system("ip rule del prio 23000");
13150 if (system("ip rule add from all lookup main prio 23000") != 0) {
13151 sigma_dut_print(dut, DUT_MSG_ERROR,
13152 "Failed to run:ip rule add from all lookup main prio");
13153 return -1;
13154 }
13155 if (system("ip route flush cache") != 0) {
13156 sigma_dut_print(dut, DUT_MSG_ERROR,
13157 "Failed to run ip route flush cache");
13158 return -1;
13159 }
13160 return 1;
13161#else /* ANDROID */
13162 return 0;
13163#endif /* ANDROID */
13164}
13165
13166
Jouni Malinenf7222712019-06-13 01:50:21 +030013167static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
13168 struct sigma_conn *conn,
13169 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013170{
13171 const char *intf = get_param(cmd, "Interface");
13172 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030013173 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013174 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030013175 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013176 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
13177 int tries = 0;
13178 int ignore_blacklist = 0;
13179 const char *events[] = {
13180 "CTRL-EVENT-CONNECTED",
13181 "INTERWORKING-BLACKLISTED",
13182 "INTERWORKING-NO-MATCH",
13183 NULL
13184 };
13185
13186 start_sta_mode(dut);
13187
Jouni Malinen439352d2018-09-13 03:42:23 +030013188 if (band) {
13189 if (strcmp(band, "2.4") == 0) {
13190 wpa_command(intf, "SET setband 2G");
13191 } else if (strcmp(band, "5") == 0) {
13192 wpa_command(intf, "SET setband 5G");
13193 } else {
13194 send_resp(dut, conn, SIGMA_ERROR,
13195 "errorCode,Unsupported band");
13196 return 0;
13197 }
13198 }
13199
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013200 blacklisted[0] = '\0';
13201 if (val && atoi(val))
13202 ignore_blacklist = 1;
13203
13204try_again:
13205 ctrl = open_wpa_mon(intf);
13206 if (ctrl == NULL) {
13207 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13208 "wpa_supplicant monitor connection");
13209 return -2;
13210 }
13211
13212 tries++;
13213 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
13214 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
13215 "Interworking connection");
13216 wpa_ctrl_detach(ctrl);
13217 wpa_ctrl_close(ctrl);
13218 return 0;
13219 }
13220
13221 buf[0] = '\0';
13222 while (1) {
13223 char *pos;
13224 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13225 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
13226 if (!pos)
13227 break;
13228 pos += 25;
13229 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
13230 pos);
13231 if (!blacklisted[0])
13232 memcpy(blacklisted, pos, strlen(pos) + 1);
13233 }
13234
13235 if (ignore_blacklist && blacklisted[0]) {
13236 char *end;
13237 end = strchr(blacklisted, ' ');
13238 if (end)
13239 *end = '\0';
13240 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
13241 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030013242 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
13243 blacklisted);
13244 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013245 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
13246 wpa_ctrl_detach(ctrl);
13247 wpa_ctrl_close(ctrl);
13248 return 0;
13249 }
13250 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13251 buf, sizeof(buf));
13252 }
13253
13254 wpa_ctrl_detach(ctrl);
13255 wpa_ctrl_close(ctrl);
13256
13257 if (res < 0) {
13258 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
13259 "connect");
13260 return 0;
13261 }
13262
13263 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
13264 strstr(buf, "INTERWORKING-BLACKLISTED")) {
13265 if (tries < 2) {
13266 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
13267 goto try_again;
13268 }
13269 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
13270 "matching credentials found");
13271 return 0;
13272 }
13273
13274 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13275 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13276 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
13277 "get current BSSID/SSID");
13278 return 0;
13279 }
13280
13281 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
13282 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13283 hs2_set_policy(dut);
13284 return 0;
13285}
13286
13287
Jouni Malinenf7222712019-06-13 01:50:21 +030013288static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
13289 struct sigma_conn *conn,
13290 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013291{
13292 const char *intf = get_param(cmd, "Interface");
13293 const char *display = get_param(cmd, "Display");
13294 struct wpa_ctrl *ctrl;
13295 char buf[300], params[400], *pos;
13296 char bssid[20];
13297 int info_avail = 0;
13298 unsigned int old_timeout;
13299 int res;
13300
13301 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
13302 send_resp(dut, conn, SIGMA_ERROR,
13303 "ErrorCode,Could not get current BSSID");
13304 return 0;
13305 }
13306 ctrl = open_wpa_mon(intf);
13307 if (!ctrl) {
13308 sigma_dut_print(dut, DUT_MSG_ERROR,
13309 "Failed to open wpa_supplicant monitor connection");
13310 return -2;
13311 }
13312
13313 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
13314 wpa_command(intf, buf);
13315
13316 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
13317 if (res < 0) {
13318 send_resp(dut, conn, SIGMA_ERROR,
13319 "ErrorCode,Could not complete GAS query");
13320 goto fail;
13321 }
13322
13323 old_timeout = dut->default_timeout;
13324 dut->default_timeout = 2;
13325 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
13326 dut->default_timeout = old_timeout;
13327 if (res < 0)
13328 goto done;
13329 pos = strchr(buf, ' ');
13330 if (!pos)
13331 goto done;
13332 pos++;
13333 pos = strchr(pos, ' ');
13334 if (!pos)
13335 goto done;
13336 pos++;
13337 info_avail = 1;
13338 snprintf(params, sizeof(params), "browser %s", pos);
13339
13340 if (display && strcasecmp(display, "Yes") == 0) {
13341 pid_t pid;
13342
13343 pid = fork();
13344 if (pid < 0) {
13345 perror("fork");
13346 return -1;
13347 }
13348
13349 if (pid == 0) {
13350 run_hs20_osu(dut, params);
13351 exit(0);
13352 }
13353 }
13354
13355done:
13356 snprintf(buf, sizeof(buf), "Info_available,%s",
13357 info_avail ? "Yes" : "No");
13358 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13359fail:
13360 wpa_ctrl_detach(ctrl);
13361 wpa_ctrl_close(ctrl);
13362 return 0;
13363}
13364
13365
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013366static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
13367 struct sigma_conn *conn,
13368 const char *ifname,
13369 struct sigma_cmd *cmd)
13370{
13371 const char *val;
13372 int id;
13373
13374 id = add_cred(ifname);
13375 if (id < 0)
13376 return -2;
13377 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13378
13379 val = get_param(cmd, "prefer");
13380 if (val && atoi(val) > 0)
13381 set_cred(ifname, id, "priority", "1");
13382
13383 val = get_param(cmd, "REALM");
13384 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13385 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13386 "realm");
13387 return 0;
13388 }
13389
13390 val = get_param(cmd, "HOME_FQDN");
13391 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13392 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13393 "home_fqdn");
13394 return 0;
13395 }
13396
13397 val = get_param(cmd, "Username");
13398 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13399 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13400 "username");
13401 return 0;
13402 }
13403
13404 val = get_param(cmd, "Password");
13405 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
13406 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13407 "password");
13408 return 0;
13409 }
13410
13411 val = get_param(cmd, "ROOT_CA");
13412 if (val) {
13413 char fname[200];
13414 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13415#ifdef __linux__
13416 if (!file_exists(fname)) {
13417 char msg[300];
13418 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13419 "file (%s) not found", fname);
13420 send_resp(dut, conn, SIGMA_ERROR, msg);
13421 return 0;
13422 }
13423#endif /* __linux__ */
13424 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13425 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13426 "not set root CA");
13427 return 0;
13428 }
13429 }
13430
13431 return 1;
13432}
13433
13434
13435static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
13436{
13437 FILE *in, *out;
13438 char buf[500];
13439 int found = 0;
13440
13441 in = fopen("devdetail.xml", "r");
13442 if (in == NULL)
13443 return -1;
13444 out = fopen("devdetail.xml.tmp", "w");
13445 if (out == NULL) {
13446 fclose(in);
13447 return -1;
13448 }
13449
13450 while (fgets(buf, sizeof(buf), in)) {
13451 char *pos = strstr(buf, "<IMSI>");
13452 if (pos) {
13453 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
13454 imsi);
13455 pos += 6;
13456 *pos = '\0';
13457 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
13458 found++;
13459 } else {
13460 fprintf(out, "%s", buf);
13461 }
13462 }
13463
13464 fclose(out);
13465 fclose(in);
13466 if (found)
13467 rename("devdetail.xml.tmp", "devdetail.xml");
13468 else
13469 unlink("devdetail.xml.tmp");
13470
13471 return 0;
13472}
13473
13474
13475static int sta_add_credential_sim(struct sigma_dut *dut,
13476 struct sigma_conn *conn,
13477 const char *ifname, struct sigma_cmd *cmd)
13478{
13479 const char *val, *imsi = NULL;
13480 int id;
13481 char buf[200];
13482 int res;
13483 const char *pos;
13484 size_t mnc_len;
13485 char plmn_mcc[4];
13486 char plmn_mnc[4];
13487
13488 id = add_cred(ifname);
13489 if (id < 0)
13490 return -2;
13491 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13492
13493 val = get_param(cmd, "prefer");
13494 if (val && atoi(val) > 0)
13495 set_cred(ifname, id, "priority", "1");
13496
13497 val = get_param(cmd, "PLMN_MCC");
13498 if (val == NULL) {
13499 send_resp(dut, conn, SIGMA_ERROR,
13500 "errorCode,Missing PLMN_MCC");
13501 return 0;
13502 }
13503 if (strlen(val) != 3) {
13504 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
13505 return 0;
13506 }
13507 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
13508
13509 val = get_param(cmd, "PLMN_MNC");
13510 if (val == NULL) {
13511 send_resp(dut, conn, SIGMA_ERROR,
13512 "errorCode,Missing PLMN_MNC");
13513 return 0;
13514 }
13515 if (strlen(val) != 2 && strlen(val) != 3) {
13516 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
13517 return 0;
13518 }
13519 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
13520
13521 val = get_param(cmd, "IMSI");
13522 if (val == NULL) {
13523 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
13524 "IMSI");
13525 return 0;
13526 }
13527
13528 imsi = pos = val;
13529
13530 if (strncmp(plmn_mcc, pos, 3) != 0) {
13531 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
13532 return 0;
13533 }
13534 pos += 3;
13535
13536 mnc_len = strlen(plmn_mnc);
13537 if (mnc_len < 2) {
13538 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
13539 return 0;
13540 }
13541
13542 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
13543 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
13544 return 0;
13545 }
13546 pos += mnc_len;
13547
13548 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
13549 if (res < 0 || res >= (int) sizeof(buf))
13550 return -1;
13551 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
13552 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13553 "not set IMSI");
13554 return 0;
13555 }
13556
13557 val = get_param(cmd, "Password");
13558 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
13559 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13560 "not set password");
13561 return 0;
13562 }
13563
Jouni Malinenba630452018-06-22 11:49:59 +030013564 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013565 /*
13566 * Set provisioning_sp for the test cases where SIM/USIM
13567 * provisioning is used.
13568 */
13569 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
13570 "wi-fi.org") < 0) {
13571 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13572 "not set provisioning_sp");
13573 return 0;
13574 }
13575
13576 update_devdetail_imsi(dut, imsi);
13577 }
13578
13579 return 1;
13580}
13581
13582
13583static int sta_add_credential_cert(struct sigma_dut *dut,
13584 struct sigma_conn *conn,
13585 const char *ifname,
13586 struct sigma_cmd *cmd)
13587{
13588 const char *val;
13589 int id;
13590
13591 id = add_cred(ifname);
13592 if (id < 0)
13593 return -2;
13594 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13595
13596 val = get_param(cmd, "prefer");
13597 if (val && atoi(val) > 0)
13598 set_cred(ifname, id, "priority", "1");
13599
13600 val = get_param(cmd, "REALM");
13601 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13602 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13603 "realm");
13604 return 0;
13605 }
13606
13607 val = get_param(cmd, "HOME_FQDN");
13608 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13609 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13610 "home_fqdn");
13611 return 0;
13612 }
13613
13614 val = get_param(cmd, "Username");
13615 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13616 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13617 "username");
13618 return 0;
13619 }
13620
13621 val = get_param(cmd, "clientCertificate");
13622 if (val) {
13623 char fname[200];
13624 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13625#ifdef __linux__
13626 if (!file_exists(fname)) {
13627 char msg[300];
13628 snprintf(msg, sizeof(msg),
13629 "ErrorCode,clientCertificate "
13630 "file (%s) not found", fname);
13631 send_resp(dut, conn, SIGMA_ERROR, msg);
13632 return 0;
13633 }
13634#endif /* __linux__ */
13635 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
13636 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13637 "not set client_cert");
13638 return 0;
13639 }
13640 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
13641 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13642 "not set private_key");
13643 return 0;
13644 }
13645 }
13646
13647 val = get_param(cmd, "ROOT_CA");
13648 if (val) {
13649 char fname[200];
13650 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13651#ifdef __linux__
13652 if (!file_exists(fname)) {
13653 char msg[300];
13654 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13655 "file (%s) not found", fname);
13656 send_resp(dut, conn, SIGMA_ERROR, msg);
13657 return 0;
13658 }
13659#endif /* __linux__ */
13660 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13661 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13662 "not set root CA");
13663 return 0;
13664 }
13665 }
13666
13667 return 1;
13668}
13669
13670
Jouni Malinenf7222712019-06-13 01:50:21 +030013671static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
13672 struct sigma_conn *conn,
13673 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013674{
13675 const char *intf = get_param(cmd, "Interface");
13676 const char *type;
13677
13678 start_sta_mode(dut);
13679
13680 type = get_param(cmd, "Type");
13681 if (!type)
13682 return -1;
13683
13684 if (strcasecmp(type, "uname_pwd") == 0)
13685 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
13686
13687 if (strcasecmp(type, "sim") == 0)
13688 return sta_add_credential_sim(dut, conn, intf, cmd);
13689
13690 if (strcasecmp(type, "cert") == 0)
13691 return sta_add_credential_cert(dut, conn, intf, cmd);
13692
13693 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
13694 "type");
13695 return 0;
13696}
13697
13698
Jouni Malinenf7222712019-06-13 01:50:21 +030013699static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
13700 struct sigma_conn *conn,
13701 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013702{
13703 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013704 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Arif Hussain66a4af02019-02-07 15:04:51 -080013705 char buf[4096];
vamsi krishna89ad8c62017-09-19 12:51:18 +053013706 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013707 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013708 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013709 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013710 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013711
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020013712 start_sta_mode(dut);
13713
Arif Hussain66a4af02019-02-07 15:04:51 -080013714 val = get_param(cmd, "GetParameter");
13715 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013716 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080013717 buf, sizeof(buf)) < 0) {
13718 sigma_dut_print(dut, DUT_MSG_ERROR,
13719 "Could not get ssid bssid");
13720 return ERROR_SEND_STATUS;
13721 }
13722
13723 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
13724 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13725 return STATUS_SENT;
13726 }
13727
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013728 val = get_param(cmd, "HESSID");
13729 if (val) {
13730 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
13731 if (res < 0 || res >= (int) sizeof(buf))
13732 return -1;
13733 wpa_command(intf, buf);
13734 }
13735
13736 val = get_param(cmd, "ACCS_NET_TYPE");
13737 if (val) {
13738 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
13739 val);
13740 if (res < 0 || res >= (int) sizeof(buf))
13741 return -1;
13742 wpa_command(intf, buf);
13743 }
13744
vamsi krishna89ad8c62017-09-19 12:51:18 +053013745 bssid = get_param(cmd, "Bssid");
13746 ssid = get_param(cmd, "Ssid");
13747
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013748 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
13749 dut->device_type == STA_testbed) {
13750 ssid = NULL;
13751 wildcard_ssid = 1;
13752 }
13753
vamsi krishna89ad8c62017-09-19 12:51:18 +053013754 if (ssid) {
13755 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
13756 send_resp(dut, conn, SIGMA_ERROR,
13757 "ErrorCode,Too long SSID");
13758 return 0;
13759 }
13760 ascii2hexstr(ssid, ssid_hex);
13761 }
13762
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013763 short_ssid = get_param(cmd, "ShortSSID");
13764 if (short_ssid) {
13765 uint32_t short_ssid_hex;
13766
13767 short_ssid_hex = strtoul(short_ssid, NULL, 16);
13768 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
13769 (((short_ssid_hex >> 8) & 0xFF) << 16) |
13770 (((short_ssid_hex >> 16) & 0xFF) << 8) |
13771 ((short_ssid_hex >> 24) & 0xFF);
13772
13773 res = snprintf(buf, sizeof(buf),
13774 "VENDOR_ELEM_ADD 14 ff053a%08x",
13775 short_ssid_hex);
13776 if (res < 0 || res >= (int) sizeof(buf) ||
13777 wpa_command(intf, buf)) {
13778 send_resp(dut, conn, SIGMA_ERROR,
13779 "errorCode,Failed to add short SSID");
13780 return STATUS_SENT_ERROR;
13781 }
13782 }
13783
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013784 scan_freq = get_param(cmd, "ChnlFreq");
13785
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013786 val = get_param(cmd, "WaitCompletion");
13787 if (val && atoi(val) == 1) {
13788 ctrl = open_wpa_mon(intf);
13789 if (!ctrl) {
13790 send_resp(dut, conn, SIGMA_ERROR,
13791 "errorCode,Failed to open monitor socket");
13792 return STATUS_SENT_ERROR;
13793 }
13794 }
13795
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013796 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053013797 bssid ? " bssid=": "",
13798 bssid ? bssid : "",
13799 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013800 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013801 wildcard_ssid ? " wildcard_ssid=1" : "",
13802 scan_freq ? " freq=" : "",
13803 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013804 if (res < 0 || res >= (int) sizeof(buf)) {
13805 send_resp(dut, conn, SIGMA_ERROR,
13806 "errorCode,Could not build scan command");
13807 status = STATUS_SENT_ERROR;
13808 goto remove_s_ssid;
13809 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053013810
13811 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013812 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
13813 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013814 status = STATUS_SENT_ERROR;
13815 } else {
13816 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013817 }
13818
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013819remove_s_ssid:
13820 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
13821 sigma_dut_print(dut, DUT_MSG_ERROR,
13822 "Failed to delete vendor element");
13823
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013824 if (ctrl) {
13825 if (status == SUCCESS_SEND_STATUS) {
13826 res = get_wpa_cli_event(dut, ctrl,
13827 "CTRL-EVENT-SCAN-RESULTS",
13828 buf, sizeof(buf));
13829 if (res < 0) {
13830 send_resp(dut, conn, SIGMA_ERROR,
13831 "ErrorCode,scan did not complete");
13832 status = STATUS_SENT_ERROR;
13833 }
13834 }
13835
13836 wpa_ctrl_detach(ctrl);
13837 wpa_ctrl_close(ctrl);
13838 }
13839
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013840 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013841}
13842
13843
Jouni Malinenf7222712019-06-13 01:50:21 +030013844static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
13845 struct sigma_conn *conn,
13846 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013847{
13848 const char *intf = get_param(cmd, "Interface");
13849 const char *bssid;
13850 char buf[4096], *pos;
13851 int freq, chan;
13852 char *ssid;
13853 char resp[100];
13854 int res;
13855 struct wpa_ctrl *ctrl;
13856
13857 bssid = get_param(cmd, "BSSID");
13858 if (!bssid) {
13859 send_resp(dut, conn, SIGMA_INVALID,
13860 "errorCode,BSSID argument is missing");
13861 return 0;
13862 }
13863
13864 ctrl = open_wpa_mon(intf);
13865 if (!ctrl) {
13866 sigma_dut_print(dut, DUT_MSG_ERROR,
13867 "Failed to open wpa_supplicant monitor connection");
13868 return -1;
13869 }
13870
13871 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
13872 send_resp(dut, conn, SIGMA_ERROR,
13873 "errorCode,Could not start scan");
13874 wpa_ctrl_detach(ctrl);
13875 wpa_ctrl_close(ctrl);
13876 return 0;
13877 }
13878
13879 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
13880 buf, sizeof(buf));
13881
13882 wpa_ctrl_detach(ctrl);
13883 wpa_ctrl_close(ctrl);
13884
13885 if (res < 0) {
13886 send_resp(dut, conn, SIGMA_ERROR,
13887 "errorCode,Scan did not complete");
13888 return 0;
13889 }
13890
13891 snprintf(buf, sizeof(buf), "BSS %s", bssid);
13892 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
13893 strncmp(buf, "id=", 3) != 0) {
13894 send_resp(dut, conn, SIGMA_ERROR,
13895 "errorCode,Specified BSSID not found");
13896 return 0;
13897 }
13898
13899 pos = strstr(buf, "\nfreq=");
13900 if (!pos) {
13901 send_resp(dut, conn, SIGMA_ERROR,
13902 "errorCode,Channel not found");
13903 return 0;
13904 }
13905 freq = atoi(pos + 6);
13906 chan = freq_to_channel(freq);
13907
13908 pos = strstr(buf, "\nssid=");
13909 if (!pos) {
13910 send_resp(dut, conn, SIGMA_ERROR,
13911 "errorCode,SSID not found");
13912 return 0;
13913 }
13914 ssid = pos + 6;
13915 pos = strchr(ssid, '\n');
13916 if (pos)
13917 *pos = '\0';
13918 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
13919 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13920 return 0;
13921}
13922
13923
Jouni Malinenf7222712019-06-13 01:50:21 +030013924static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
13925 struct sigma_conn *conn,
13926 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013927{
13928#ifdef __linux__
13929 struct timeval tv;
13930 struct tm tm;
13931 time_t t;
13932 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013933 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013934
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013935 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013936
13937 memset(&tm, 0, sizeof(tm));
13938 val = get_param(cmd, "seconds");
13939 if (val)
13940 tm.tm_sec = atoi(val);
13941 val = get_param(cmd, "minutes");
13942 if (val)
13943 tm.tm_min = atoi(val);
13944 val = get_param(cmd, "hours");
13945 if (val)
13946 tm.tm_hour = atoi(val);
13947 val = get_param(cmd, "date");
13948 if (val)
13949 tm.tm_mday = atoi(val);
13950 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013951 if (val) {
13952 v = atoi(val);
13953 if (v < 1 || v > 12) {
13954 send_resp(dut, conn, SIGMA_INVALID,
13955 "errorCode,Invalid month");
13956 return 0;
13957 }
13958 tm.tm_mon = v - 1;
13959 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013960 val = get_param(cmd, "year");
13961 if (val) {
13962 int year = atoi(val);
13963#ifdef ANDROID
13964 if (year > 2035)
13965 year = 2035; /* years beyond 2035 not supported */
13966#endif /* ANDROID */
13967 tm.tm_year = year - 1900;
13968 }
13969 t = mktime(&tm);
13970 if (t == (time_t) -1) {
13971 send_resp(dut, conn, SIGMA_ERROR,
13972 "errorCode,Invalid date or time");
13973 return 0;
13974 }
13975
13976 memset(&tv, 0, sizeof(tv));
13977 tv.tv_sec = t;
13978
13979 if (settimeofday(&tv, NULL) < 0) {
13980 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
13981 strerror(errno));
13982 send_resp(dut, conn, SIGMA_ERROR,
13983 "errorCode,Failed to set time");
13984 return 0;
13985 }
13986
13987 return 1;
13988#endif /* __linux__ */
13989
13990 return -1;
13991}
13992
13993
Jouni Malinenf7222712019-06-13 01:50:21 +030013994static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
13995 struct sigma_conn *conn,
13996 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013997{
13998 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013999 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014000 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014001 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014002 int res;
14003 struct wpa_ctrl *ctrl;
14004
14005 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014006 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014007
14008 val = get_param(cmd, "ProdESSAssoc");
14009 if (val)
14010 prod_ess_assoc = atoi(val);
14011
14012 kill_dhcp_client(dut, intf);
14013 if (start_dhcp_client(dut, intf) < 0)
14014 return -2;
14015
14016 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
14017 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
14018 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014019 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014020 prod_ess_assoc ? "" : "-N",
14021 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014022 name ? "'" : "",
14023 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
14024 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014025
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053014026 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014027 if (run_hs20_osu(dut, buf) < 0) {
14028 FILE *f;
14029
14030 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
14031
14032 f = fopen("hs20-osu-client.res", "r");
14033 if (f) {
14034 char resp[400], res[300], *pos;
14035 if (!fgets(res, sizeof(res), f))
14036 res[0] = '\0';
14037 pos = strchr(res, '\n');
14038 if (pos)
14039 *pos = '\0';
14040 fclose(f);
14041 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
14042 res);
14043 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
14044 if (system(resp) != 0) {
14045 }
14046 snprintf(resp, sizeof(resp),
14047 "SSID,,BSSID,,failureReason,%s", res);
14048 send_resp(dut, conn, SIGMA_COMPLETE, resp);
14049 return 0;
14050 }
14051
14052 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
14053 return 0;
14054 }
14055
14056 if (!prod_ess_assoc)
14057 goto report;
14058
14059 ctrl = open_wpa_mon(intf);
14060 if (ctrl == NULL) {
14061 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14062 "wpa_supplicant monitor connection");
14063 return -1;
14064 }
14065
14066 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
14067 buf, sizeof(buf));
14068
14069 wpa_ctrl_detach(ctrl);
14070 wpa_ctrl_close(ctrl);
14071
14072 if (res < 0) {
14073 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
14074 "network after OSU");
14075 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
14076 return 0;
14077 }
14078
14079report:
14080 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
14081 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
14082 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
14083 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
14084 return 0;
14085 }
14086
14087 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
14088 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014089 return 0;
14090}
14091
14092
Jouni Malinenf7222712019-06-13 01:50:21 +030014093static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
14094 struct sigma_conn *conn,
14095 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014096{
14097 const char *val;
14098 int timeout = 120;
14099
14100 val = get_param(cmd, "PolicyUpdate");
14101 if (val == NULL || atoi(val) == 0)
14102 return 1; /* No operation requested */
14103
14104 val = get_param(cmd, "Timeout");
14105 if (val)
14106 timeout = atoi(val);
14107
14108 if (timeout) {
14109 /* TODO: time out the command and return
14110 * PolicyUpdateStatus,TIMEOUT if needed. */
14111 }
14112
14113 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
14114 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
14115 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
14116 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
14117 return 0;
14118 }
14119
14120 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
14121 return 0;
14122}
14123
14124
Jouni Malinenf7222712019-06-13 01:50:21 +030014125static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
14126 struct sigma_conn *conn,
14127 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014128{
14129 struct wpa_ctrl *ctrl;
14130 const char *intf = get_param(cmd, "Interface");
14131 const char *bssid = get_param(cmd, "Bssid");
14132 const char *ssid = get_param(cmd, "SSID");
14133 const char *security = get_param(cmd, "Security");
14134 const char *passphrase = get_param(cmd, "Passphrase");
14135 const char *pin = get_param(cmd, "PIN");
14136 char buf[1000];
14137 char ssid_hex[200], passphrase_hex[200];
14138 const char *keymgmt, *cipher;
14139
14140 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014141 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014142
14143 if (!bssid) {
14144 send_resp(dut, conn, SIGMA_ERROR,
14145 "ErrorCode,Missing Bssid argument");
14146 return 0;
14147 }
14148
14149 if (!ssid) {
14150 send_resp(dut, conn, SIGMA_ERROR,
14151 "ErrorCode,Missing SSID argument");
14152 return 0;
14153 }
14154
14155 if (!security) {
14156 send_resp(dut, conn, SIGMA_ERROR,
14157 "ErrorCode,Missing Security argument");
14158 return 0;
14159 }
14160
14161 if (!passphrase) {
14162 send_resp(dut, conn, SIGMA_ERROR,
14163 "ErrorCode,Missing Passphrase argument");
14164 return 0;
14165 }
14166
14167 if (!pin) {
14168 send_resp(dut, conn, SIGMA_ERROR,
14169 "ErrorCode,Missing PIN argument");
14170 return 0;
14171 }
14172
vamsi krishna8c9c1562017-05-12 15:51:46 +053014173 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
14174 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014175 send_resp(dut, conn, SIGMA_ERROR,
14176 "ErrorCode,Too long SSID/passphrase");
14177 return 0;
14178 }
14179
14180 ctrl = open_wpa_mon(intf);
14181 if (ctrl == NULL) {
14182 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14183 "wpa_supplicant monitor connection");
14184 return -2;
14185 }
14186
14187 if (strcasecmp(security, "wpa2-psk") == 0) {
14188 keymgmt = "WPA2PSK";
14189 cipher = "CCMP";
14190 } else {
14191 wpa_ctrl_detach(ctrl);
14192 wpa_ctrl_close(ctrl);
14193 send_resp(dut, conn, SIGMA_ERROR,
14194 "ErrorCode,Unsupported Security value");
14195 return 0;
14196 }
14197
14198 ascii2hexstr(ssid, ssid_hex);
14199 ascii2hexstr(passphrase, passphrase_hex);
14200 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
14201 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
14202
14203 if (wpa_command(intf, buf) < 0) {
14204 wpa_ctrl_detach(ctrl);
14205 wpa_ctrl_close(ctrl);
14206 send_resp(dut, conn, SIGMA_ERROR,
14207 "ErrorCode,Failed to start registrar");
14208 return 0;
14209 }
14210
14211 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
14212 dut->er_oper_performed = 1;
14213
14214 return wps_connection_event(dut, conn, ctrl, intf, 0);
14215}
14216
14217
Jouni Malinenf7222712019-06-13 01:50:21 +030014218static enum sigma_cmd_result
14219cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
14220 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014221{
14222 struct wpa_ctrl *ctrl;
14223 const char *intf = get_param(cmd, "Interface");
14224 const char *bssid = get_param(cmd, "Bssid");
14225 char buf[100];
14226
14227 if (!bssid) {
14228 send_resp(dut, conn, SIGMA_ERROR,
14229 "ErrorCode,Missing Bssid argument");
14230 return 0;
14231 }
14232
14233 ctrl = open_wpa_mon(intf);
14234 if (ctrl == NULL) {
14235 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14236 "wpa_supplicant monitor connection");
14237 return -2;
14238 }
14239
14240 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
14241
14242 if (wpa_command(intf, buf) < 0) {
14243 wpa_ctrl_detach(ctrl);
14244 wpa_ctrl_close(ctrl);
14245 send_resp(dut, conn, SIGMA_ERROR,
14246 "ErrorCode,Failed to start registrar");
14247 return 0;
14248 }
14249
14250 return wps_connection_event(dut, conn, ctrl, intf, 0);
14251}
14252
14253
Jouni Malinenf7222712019-06-13 01:50:21 +030014254static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
14255 struct sigma_conn *conn,
14256 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053014257{
14258 struct wpa_ctrl *ctrl;
14259 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014260 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014261 const char *config_method = get_param(cmd, "WPSConfigMethod");
14262 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053014263 int res;
14264 char buf[256];
14265 const char *events[] = {
14266 "CTRL-EVENT-CONNECTED",
14267 "WPS-OVERLAP-DETECTED",
14268 "WPS-TIMEOUT",
14269 "WPS-FAIL",
14270 NULL
14271 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014272 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053014273
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014274 /* 60G WPS tests do not pass Interface parameter */
14275 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014276 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014277
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014278 if (dut->mode == SIGMA_MODE_AP)
14279 return ap_wps_registration(dut, conn, cmd);
14280
14281 if (config_method) {
14282 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
14283 * sta_wps_enter_pin before calling start_wps_registration. */
14284 if (strcasecmp(config_method, "PBC") == 0)
14285 dut->wps_method = WFA_CS_WPS_PBC;
14286 }
14287 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
14288 send_resp(dut, conn, SIGMA_ERROR,
14289 "ErrorCode,WPS parameters not yet set");
14290 return STATUS_SENT;
14291 }
14292
14293 /* Make sure WPS is enabled (also for STA mode) */
14294 dut->wps_disable = 0;
14295
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014296 if (dut->band == WPS_BAND_60G && network_mode &&
14297 strcasecmp(network_mode, "PBSS") == 0) {
14298 sigma_dut_print(dut, DUT_MSG_DEBUG,
14299 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014300 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014301 return -2;
14302 }
14303
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020014304 if (dut->force_rsn_ie) {
14305 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
14306 dut->force_rsn_ie);
14307 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
14308 sigma_dut_print(dut, DUT_MSG_INFO,
14309 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014310 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020014311 }
14312 }
14313
vamsi krishna9b144002017-09-20 13:28:13 +053014314 ctrl = open_wpa_mon(intf);
14315 if (!ctrl) {
14316 sigma_dut_print(dut, DUT_MSG_ERROR,
14317 "Failed to open wpa_supplicant monitor connection");
14318 return -2;
14319 }
14320
14321 role = get_param(cmd, "WpsRole");
14322 if (!role) {
14323 send_resp(dut, conn, SIGMA_INVALID,
14324 "ErrorCode,WpsRole not provided");
14325 goto fail;
14326 }
14327
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014328 if (strcasecmp(role, "Enrollee") != 0) {
14329 /* Registrar role for STA not supported */
14330 send_resp(dut, conn, SIGMA_ERROR,
14331 "ErrorCode,Unsupported WpsRole value");
14332 goto fail;
14333 }
14334
14335 if (is_60g_sigma_dut(dut)) {
14336 if (dut->wps_method == WFA_CS_WPS_PBC)
14337 snprintf(buf, sizeof(buf), "WPS_PBC");
14338 else /* WFA_CS_WPS_PIN_KEYPAD */
14339 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
14340 dut->wps_pin);
14341 if (wpa_command(intf, buf) < 0) {
14342 send_resp(dut, conn, SIGMA_ERROR,
14343 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053014344 goto fail;
14345 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014346 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
14347 if (res < 0) {
14348 send_resp(dut, conn, SIGMA_ERROR,
14349 "ErrorCode,WPS connection did not complete");
14350 goto fail;
14351 }
14352 if (strstr(buf, "WPS-TIMEOUT")) {
14353 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
14354 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
14355 send_resp(dut, conn, SIGMA_COMPLETE,
14356 "WpsState,OverlapSession");
14357 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
14358 send_resp(dut, conn, SIGMA_COMPLETE,
14359 "WpsState,Successful");
14360 } else {
14361 send_resp(dut, conn, SIGMA_COMPLETE,
14362 "WpsState,Failure");
14363 }
14364 } else {
14365 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053014366 if (wpa_command(intf, "WPS_PBC") < 0) {
14367 send_resp(dut, conn, SIGMA_ERROR,
14368 "ErrorCode,Failed to enable PBC");
14369 goto fail;
14370 }
14371 } else {
14372 /* TODO: PIN method */
14373 send_resp(dut, conn, SIGMA_ERROR,
14374 "ErrorCode,Unsupported WpsConfigMethod value");
14375 goto fail;
14376 }
14377 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
14378 if (res < 0) {
14379 send_resp(dut, conn, SIGMA_ERROR,
14380 "ErrorCode,WPS connection did not complete");
14381 goto fail;
14382 }
14383 if (strstr(buf, "WPS-TIMEOUT")) {
14384 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
14385 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
14386 send_resp(dut, conn, SIGMA_ERROR,
14387 "ErrorCode,OverlapSession");
14388 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
14389 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
14390 } else {
14391 send_resp(dut, conn, SIGMA_ERROR,
14392 "ErrorCode,WPS operation failed");
14393 }
vamsi krishna9b144002017-09-20 13:28:13 +053014394 }
14395
14396fail:
14397 wpa_ctrl_detach(ctrl);
14398 wpa_ctrl_close(ctrl);
14399 return 0;
14400}
14401
14402
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014403static int req_intf(struct sigma_cmd *cmd)
14404{
14405 return get_param(cmd, "interface") == NULL ? -1 : 0;
14406}
14407
14408
14409void sta_register_cmds(void)
14410{
14411 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
14412 cmd_sta_get_ip_config);
14413 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
14414 cmd_sta_set_ip_config);
14415 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
14416 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
14417 cmd_sta_get_mac_address);
14418 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
14419 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
14420 cmd_sta_verify_ip_connection);
14421 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
14422 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
14423 cmd_sta_set_encryption);
14424 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
14425 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
14426 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
14427 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
14428 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
14429 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
14430 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
14431 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
14432 cmd_sta_set_eapakaprime);
14433 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
14434 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
14435 /* TODO: sta_set_ibss */
14436 /* TODO: sta_set_mode */
14437 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
14438 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
14439 /* TODO: sta_up_load */
14440 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
14441 cmd_sta_preset_testparameters);
14442 /* TODO: sta_set_system */
14443 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
14444 /* TODO: sta_set_rifs_test */
14445 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
14446 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
14447 /* TODO: sta_send_coexist_mgmt */
14448 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
14449 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
14450 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
14451 sigma_dut_reg_cmd("sta_reset_default", req_intf,
14452 cmd_sta_reset_default);
14453 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
14454 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
14455 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
14456 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
14457 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014458 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014459 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
14460 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
14461 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
14462 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
14463 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030014464 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
14465 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014466 sigma_dut_reg_cmd("sta_add_credential", req_intf,
14467 cmd_sta_add_credential);
14468 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020014469 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014470 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
14471 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
14472 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
14473 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
14474 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
14475 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030014476 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014477 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
14478 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014479 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053014480 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014481}