blob: 4b0d4c40ab43eea841fbc248091bbadc9c94dde2 [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");
2289 return ERROR_SEND_STATUS;
2290 }
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
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002304 if (dut->program == PROGRAM_60GHZ && network_mode &&
2305 strcasecmp(network_mode, "PBSS") == 0 &&
2306 set_network(ifname, id, "pbss", "1") < 0)
2307 return -2;
2308
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002309 return 1;
2310}
2311
2312
Jouni Malinen8ac93452019-08-14 15:19:13 +03002313static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2314 struct sigma_conn *conn,
2315 const char *ifname, int id)
2316{
2317 char buf[200];
2318
2319 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2320 if (!file_exists(buf))
2321 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2322 if (!file_exists(buf))
2323 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2324 if (!file_exists(buf)) {
2325 char msg[300];
2326
2327 snprintf(msg, sizeof(msg),
2328 "ErrorCode,trustedRootCA system store (%s) not found",
2329 buf);
2330 send_resp(dut, conn, SIGMA_ERROR, msg);
2331 return STATUS_SENT_ERROR;
2332 }
2333
2334 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2335 return ERROR_SEND_STATUS;
2336
2337 return SUCCESS_SEND_STATUS;
2338}
2339
2340
2341static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2342 struct sigma_conn *conn,
2343 const char *ifname, int id,
2344 const char *val)
2345{
2346 char buf[200];
2347#ifdef ANDROID
2348 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2349 int length;
2350#endif /* ANDROID */
2351
2352 if (strcmp(val, "DEFAULT") == 0)
2353 return set_trust_root_system(dut, conn, ifname, id);
2354
2355#ifdef ANDROID
2356 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2357 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2358 if (length > 0) {
2359 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2360 buf);
2361 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2362 goto ca_cert_selected;
2363 }
2364#endif /* ANDROID */
2365
2366 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2367#ifdef __linux__
2368 if (!file_exists(buf)) {
2369 char msg[300];
2370
2371 snprintf(msg, sizeof(msg),
2372 "ErrorCode,trustedRootCA file (%s) not found", buf);
2373 send_resp(dut, conn, SIGMA_ERROR, msg);
2374 return STATUS_SENT_ERROR;
2375 }
2376#endif /* __linux__ */
2377#ifdef ANDROID
2378ca_cert_selected:
2379#endif /* ANDROID */
2380 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2381 return ERROR_SEND_STATUS;
2382
2383 return SUCCESS_SEND_STATUS;
2384}
2385
2386
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002387static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302388 const char *ifname, int username_identity,
2389 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002390{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002391 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002392 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002393 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002394 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002395 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002396
2397 id = set_wpa_common(dut, conn, ifname, cmd);
2398 if (id < 0)
2399 return id;
2400
2401 val = get_param(cmd, "keyMgmtType");
2402 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302403 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002404 trust_root = get_param(cmd, "trustedRootCA");
2405 domain = get_param(cmd, "Domain");
2406 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002407
Jouni Malinenad395a22017-09-01 21:13:46 +03002408 if (val && strcasecmp(val, "SuiteB") == 0) {
2409 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2410 0)
2411 return -2;
2412 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002413 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2414 return -2;
2415 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2416 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2417 return -2;
2418 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2419 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2420 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002421 } else if (!akm &&
2422 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2423 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002424 if (set_network(ifname, id, "key_mgmt",
2425 "WPA-EAP WPA-EAP-SHA256") < 0)
2426 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302427 } else if (akm && atoi(akm) == 14) {
2428 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2429 dut->sta_pmf == STA_PMF_REQUIRED) {
2430 if (set_network(ifname, id, "key_mgmt",
2431 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2432 return -2;
2433 } else {
2434 if (set_network(ifname, id, "key_mgmt",
2435 "WPA-EAP FILS-SHA256") < 0)
2436 return -2;
2437 }
2438
Jouni Malinen8179fee2019-03-28 03:19:47 +02002439 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302440 } else if (akm && atoi(akm) == 15) {
2441 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2442 dut->sta_pmf == STA_PMF_REQUIRED) {
2443 if (set_network(ifname, id, "key_mgmt",
2444 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2445 return -2;
2446 } else {
2447 if (set_network(ifname, id, "key_mgmt",
2448 "WPA-EAP FILS-SHA384") < 0)
2449 return -2;
2450 }
2451
Jouni Malinen8179fee2019-03-28 03:19:47 +02002452 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002453 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002454 if (set_network(ifname, id, "key_mgmt",
2455 "WPA-EAP WPA-EAP-SHA256") < 0)
2456 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002457 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002458 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2459 return -2;
2460 }
2461
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002462 if (trust_root) {
2463 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2464 !domain_suffix) {
2465 send_resp(dut, conn, SIGMA_ERROR,
2466 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2467 return STATUS_SENT_ERROR;
2468 }
2469 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002470 if (res != SUCCESS_SEND_STATUS)
2471 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002472 }
2473
Jouni Malinen53264f62019-05-03 13:04:40 +03002474 val = get_param(cmd, "ServerCert");
2475 if (val) {
2476 FILE *f;
2477 char *result = NULL, *pos;
2478
2479 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2480 val);
2481 f = fopen(buf, "r");
2482 if (f) {
2483 result = fgets(buf, sizeof(buf), f);
2484 fclose(f);
2485 }
2486 if (!result) {
2487 snprintf(buf2, sizeof(buf2),
2488 "ErrorCode,ServerCert hash could not be read from %s",
2489 buf);
2490 send_resp(dut, conn, SIGMA_ERROR, buf2);
2491 return STATUS_SENT_ERROR;
2492 }
2493 pos = strchr(buf, '\n');
2494 if (pos)
2495 *pos = '\0';
2496 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2497 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2498 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002499
2500 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2501 if (file_exists(buf)) {
2502 sigma_dut_print(dut, DUT_MSG_DEBUG,
2503 "TOD policy enabled for the configured ServerCert hash");
2504 dut->sta_tod_policy = 1;
2505 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002506 }
2507
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002508 if (domain &&
2509 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002510 return ERROR_SEND_STATUS;
2511
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002512 if (domain_suffix &&
2513 set_network_quoted(ifname, id, "domain_suffix_match",
2514 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002515 return ERROR_SEND_STATUS;
2516
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302517 if (username_identity) {
2518 val = get_param(cmd, "username");
2519 if (val) {
2520 if (set_network_quoted(ifname, id, "identity", val) < 0)
2521 return -2;
2522 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002523
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302524 val = get_param(cmd, "password");
2525 if (val) {
2526 if (set_network_quoted(ifname, id, "password", val) < 0)
2527 return -2;
2528 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002529 }
2530
Jouni Malinen8179fee2019-03-28 03:19:47 +02002531 if (dut->akm_values &
2532 ((1 << AKM_FILS_SHA256) |
2533 (1 << AKM_FILS_SHA384) |
2534 (1 << AKM_FT_FILS_SHA256) |
2535 (1 << AKM_FT_FILS_SHA384)))
2536 erp = 1;
2537 if (erp && set_network(ifname, id, "erp", "1") < 0)
2538 return ERROR_SEND_STATUS;
2539
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002540 dut->sta_associate_wait_connect = 1;
2541
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002542 return id;
2543}
2544
2545
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002546static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2547{
2548 const char *val;
2549
2550 if (!cipher)
2551 return 0;
2552
2553 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2554 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2555 else if (strcasecmp(cipher,
2556 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2557 val = "ECDHE-RSA-AES256-GCM-SHA384";
2558 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2559 val = "DHE-RSA-AES256-GCM-SHA384";
2560 else if (strcasecmp(cipher,
2561 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2562 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2563 else
2564 return -1;
2565
2566 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2567 set_network_quoted(ifname, id, "phase1", "");
2568
2569 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2570}
2571
2572
Jouni Malinenf7222712019-06-13 01:50:21 +03002573static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2574 struct sigma_conn *conn,
2575 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002576{
2577 const char *intf = get_param(cmd, "Interface");
2578 const char *ifname, *val;
2579 int id;
2580 char buf[200];
2581#ifdef ANDROID
2582 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2583 int length;
2584 int jb_or_newer = 0;
2585 char prop[PROPERTY_VALUE_MAX];
2586#endif /* ANDROID */
2587
2588 if (intf == NULL)
2589 return -1;
2590
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002591 if (strcmp(intf, get_main_ifname(dut)) == 0)
2592 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002593 else
2594 ifname = intf;
2595
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302596 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002597 if (id < 0)
2598 return id;
2599
2600 if (set_network(ifname, id, "eap", "TLS") < 0)
2601 return -2;
2602
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302603 if (!get_param(cmd, "username") &&
2604 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002605 "wifi-user@wifilabs.local") < 0)
2606 return -2;
2607
2608 val = get_param(cmd, "clientCertificate");
2609 if (val == NULL)
2610 return -1;
2611#ifdef ANDROID
2612 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2613 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2614 if (length < 0) {
2615 /*
2616 * JB started reporting keystore type mismatches, so retry with
2617 * the GET_PUBKEY command if the generic GET fails.
2618 */
2619 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2620 buf, kvalue);
2621 }
2622
2623 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2624 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2625 if (strncmp(prop, "4.0", 3) != 0)
2626 jb_or_newer = 1;
2627 } else
2628 jb_or_newer = 1; /* assume newer */
2629
2630 if (jb_or_newer && length > 0) {
2631 sigma_dut_print(dut, DUT_MSG_INFO,
2632 "Use Android keystore [%s]", buf);
2633 if (set_network(ifname, id, "engine", "1") < 0)
2634 return -2;
2635 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2636 return -2;
2637 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2638 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2639 return -2;
2640 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2641 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2642 return -2;
2643 return 1;
2644 } else if (length > 0) {
2645 sigma_dut_print(dut, DUT_MSG_INFO,
2646 "Use Android keystore [%s]", buf);
2647 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2648 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2649 return -2;
2650 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2651 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2652 return -2;
2653 return 1;
2654 }
2655#endif /* ANDROID */
2656
2657 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2658#ifdef __linux__
2659 if (!file_exists(buf)) {
2660 char msg[300];
2661 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2662 "(%s) not found", buf);
2663 send_resp(dut, conn, SIGMA_ERROR, msg);
2664 return -3;
2665 }
2666#endif /* __linux__ */
2667 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2668 return -2;
2669 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2670 return -2;
2671
2672 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2673 return -2;
2674
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002675 val = get_param(cmd, "keyMgmtType");
2676 if (val && strcasecmp(val, "SuiteB") == 0) {
2677 val = get_param(cmd, "CertType");
2678 if (val && strcasecmp(val, "RSA") == 0) {
2679 if (set_network_quoted(ifname, id, "phase1",
2680 "tls_suiteb=1") < 0)
2681 return -2;
2682 } else {
2683 if (set_network_quoted(ifname, id, "openssl_ciphers",
2684 "SUITEB192") < 0)
2685 return -2;
2686 }
2687
2688 val = get_param(cmd, "TLSCipher");
2689 if (set_tls_cipher(ifname, id, val) < 0) {
2690 send_resp(dut, conn, SIGMA_ERROR,
2691 "ErrorCode,Unsupported TLSCipher value");
2692 return -3;
2693 }
2694 }
2695
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002696 return 1;
2697}
2698
2699
Jouni Malinenf7222712019-06-13 01:50:21 +03002700static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2701 struct sigma_conn *conn,
2702 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002703{
2704 const char *intf = get_param(cmd, "Interface");
2705 const char *ifname;
2706 int id;
2707
2708 if (intf == NULL)
2709 return -1;
2710
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002711 if (strcmp(intf, get_main_ifname(dut)) == 0)
2712 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002713 else
2714 ifname = intf;
2715
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302716 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002717 if (id < 0)
2718 return id;
2719
2720 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2721 send_resp(dut, conn, SIGMA_ERROR,
2722 "errorCode,Failed to set TTLS method");
2723 return 0;
2724 }
2725
2726 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2727 send_resp(dut, conn, SIGMA_ERROR,
2728 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2729 return 0;
2730 }
2731
2732 return 1;
2733}
2734
2735
Jouni Malinenf7222712019-06-13 01:50:21 +03002736static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2737 struct sigma_conn *conn,
2738 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002739{
2740 const char *intf = get_param(cmd, "Interface");
2741 const char *ifname;
2742 int id;
2743
2744 if (intf == NULL)
2745 return -1;
2746
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002747 if (strcmp(intf, get_main_ifname(dut)) == 0)
2748 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002749 else
2750 ifname = intf;
2751
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302752 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002753 if (id < 0)
2754 return id;
2755
2756 if (set_network(ifname, id, "eap", "SIM") < 0)
2757 return -2;
2758
2759 return 1;
2760}
2761
2762
Jouni Malinenf7222712019-06-13 01:50:21 +03002763static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2764 struct sigma_conn *conn,
2765 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002766{
2767 const char *intf = get_param(cmd, "Interface");
2768 const char *ifname, *val;
2769 int id;
2770 char buf[100];
2771
2772 if (intf == NULL)
2773 return -1;
2774
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002775 if (strcmp(intf, get_main_ifname(dut)) == 0)
2776 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002777 else
2778 ifname = intf;
2779
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302780 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002781 if (id < 0)
2782 return id;
2783
2784 if (set_network(ifname, id, "eap", "PEAP") < 0)
2785 return -2;
2786
2787 val = get_param(cmd, "innerEAP");
2788 if (val) {
2789 if (strcasecmp(val, "MSCHAPv2") == 0) {
2790 if (set_network_quoted(ifname, id, "phase2",
2791 "auth=MSCHAPV2") < 0)
2792 return -2;
2793 } else if (strcasecmp(val, "GTC") == 0) {
2794 if (set_network_quoted(ifname, id, "phase2",
2795 "auth=GTC") < 0)
2796 return -2;
2797 } else
2798 return -1;
2799 }
2800
2801 val = get_param(cmd, "peapVersion");
2802 if (val) {
2803 int ver = atoi(val);
2804 if (ver < 0 || ver > 1)
2805 return -1;
2806 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2807 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2808 return -2;
2809 }
2810
2811 return 1;
2812}
2813
2814
Jouni Malinenf7222712019-06-13 01:50:21 +03002815static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2816 struct sigma_conn *conn,
2817 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002818{
2819 const char *intf = get_param(cmd, "Interface");
2820 const char *ifname, *val;
2821 int id;
2822 char buf[100];
2823
2824 if (intf == NULL)
2825 return -1;
2826
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002827 if (strcmp(intf, get_main_ifname(dut)) == 0)
2828 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002829 else
2830 ifname = intf;
2831
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302832 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002833 if (id < 0)
2834 return id;
2835
2836 if (set_network(ifname, id, "eap", "FAST") < 0)
2837 return -2;
2838
2839 val = get_param(cmd, "innerEAP");
2840 if (val) {
2841 if (strcasecmp(val, "MSCHAPV2") == 0) {
2842 if (set_network_quoted(ifname, id, "phase2",
2843 "auth=MSCHAPV2") < 0)
2844 return -2;
2845 } else if (strcasecmp(val, "GTC") == 0) {
2846 if (set_network_quoted(ifname, id, "phase2",
2847 "auth=GTC") < 0)
2848 return -2;
2849 } else
2850 return -1;
2851 }
2852
2853 val = get_param(cmd, "validateServer");
2854 if (val) {
2855 /* TODO */
2856 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2857 "validateServer=%s", val);
2858 }
2859
2860 val = get_param(cmd, "pacFile");
2861 if (val) {
2862 snprintf(buf, sizeof(buf), "blob://%s", val);
2863 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2864 return -2;
2865 }
2866
2867 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2868 0)
2869 return -2;
2870
2871 return 1;
2872}
2873
2874
Jouni Malinenf7222712019-06-13 01:50:21 +03002875static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2876 struct sigma_conn *conn,
2877 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002878{
2879 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302880 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002881 const char *ifname;
2882 int id;
2883
2884 if (intf == NULL)
2885 return -1;
2886
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002887 if (strcmp(intf, get_main_ifname(dut)) == 0)
2888 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002889 else
2890 ifname = intf;
2891
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302892 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002893 if (id < 0)
2894 return id;
2895
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302896 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2897 * hexadecimal).
2898 */
2899 if (username && username[0] == '6') {
2900 if (set_network(ifname, id, "eap", "AKA'") < 0)
2901 return -2;
2902 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002903 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302904 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002905
2906 return 1;
2907}
2908
2909
Jouni Malinenf7222712019-06-13 01:50:21 +03002910static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2911 struct sigma_conn *conn,
2912 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002913{
2914 const char *intf = get_param(cmd, "Interface");
2915 const char *ifname;
2916 int id;
2917
2918 if (intf == NULL)
2919 return -1;
2920
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002921 if (strcmp(intf, get_main_ifname(dut)) == 0)
2922 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002923 else
2924 ifname = intf;
2925
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302926 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002927 if (id < 0)
2928 return id;
2929
2930 if (set_network(ifname, id, "eap", "AKA'") < 0)
2931 return -2;
2932
2933 return 1;
2934}
2935
2936
2937static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2938 struct sigma_cmd *cmd)
2939{
2940 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002941 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002942 const char *ifname;
2943 int id;
2944
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002945 if (strcmp(intf, get_main_ifname(dut)) == 0)
2946 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002947 else
2948 ifname = intf;
2949
2950 id = add_network_common(dut, conn, ifname, cmd);
2951 if (id < 0)
2952 return id;
2953
2954 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2955 return -2;
2956
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002957 if (dut->program == PROGRAM_60GHZ && network_mode &&
2958 strcasecmp(network_mode, "PBSS") == 0 &&
2959 set_network(ifname, id, "pbss", "1") < 0)
2960 return -2;
2961
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002962 return 1;
2963}
2964
2965
Jouni Malinen47dcc952017-10-09 16:43:24 +03002966static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2967 struct sigma_cmd *cmd)
2968{
2969 const char *intf = get_param(cmd, "Interface");
2970 const char *ifname, *val;
2971 int id;
2972
2973 if (intf == NULL)
2974 return -1;
2975
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002976 if (strcmp(intf, get_main_ifname(dut)) == 0)
2977 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002978 else
2979 ifname = intf;
2980
2981 id = set_wpa_common(dut, conn, ifname, cmd);
2982 if (id < 0)
2983 return id;
2984
2985 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
2986 return -2;
2987
2988 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03002989 if (val && strcmp(val, "0") == 0) {
2990 if (wpa_command(ifname,
2991 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
2992 sigma_dut_print(dut, DUT_MSG_ERROR,
2993 "Failed to set OWE DH Param element override");
2994 return -2;
2995 }
Hu Wang6010ce72020-03-05 19:33:53 +08002996 } else if (val &&
2997 (set_network(ifname, id, "owe_group", val) < 0 ||
2998 (dut->owe_ptk_workaround &&
2999 set_network(ifname, id, "owe_ptk_workaround", "1") < 0))) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003000 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003001 "Failed to set owe_group");
Jouni Malinen47dcc952017-10-09 16:43:24 +03003002 return -2;
3003 }
3004
3005 return 1;
3006}
3007
3008
Jouni Malinenf7222712019-06-13 01:50:21 +03003009static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3010 struct sigma_conn *conn,
3011 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003012{
3013 const char *type = get_param(cmd, "Type");
3014
3015 if (type == NULL) {
3016 send_resp(dut, conn, SIGMA_ERROR,
3017 "ErrorCode,Missing Type argument");
3018 return 0;
3019 }
3020
3021 if (strcasecmp(type, "OPEN") == 0)
3022 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003023 if (strcasecmp(type, "OWE") == 0)
3024 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003025 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003026 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003027 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003028 return cmd_sta_set_psk(dut, conn, cmd);
3029 if (strcasecmp(type, "EAPTLS") == 0)
3030 return cmd_sta_set_eaptls(dut, conn, cmd);
3031 if (strcasecmp(type, "EAPTTLS") == 0)
3032 return cmd_sta_set_eapttls(dut, conn, cmd);
3033 if (strcasecmp(type, "EAPPEAP") == 0)
3034 return cmd_sta_set_peap(dut, conn, cmd);
3035 if (strcasecmp(type, "EAPSIM") == 0)
3036 return cmd_sta_set_eapsim(dut, conn, cmd);
3037 if (strcasecmp(type, "EAPFAST") == 0)
3038 return cmd_sta_set_eapfast(dut, conn, cmd);
3039 if (strcasecmp(type, "EAPAKA") == 0)
3040 return cmd_sta_set_eapaka(dut, conn, cmd);
3041 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3042 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003043 if (strcasecmp(type, "wep") == 0)
3044 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003045
3046 send_resp(dut, conn, SIGMA_ERROR,
3047 "ErrorCode,Unsupported Type value");
3048 return 0;
3049}
3050
3051
3052int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3053{
3054#ifdef __linux__
3055 /* special handling for ath6kl */
3056 char path[128], fname[128], *pos;
3057 ssize_t res;
3058 FILE *f;
3059
Jouni Malinene39cd562019-05-29 23:39:56 +03003060 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3061 intf);
3062 if (res < 0 || res >= sizeof(fname))
3063 return 0;
3064 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003065 if (res < 0)
3066 return 0; /* not ath6kl */
3067
3068 if (res >= (int) sizeof(path))
3069 res = sizeof(path) - 1;
3070 path[res] = '\0';
3071 pos = strrchr(path, '/');
3072 if (pos == NULL)
3073 pos = path;
3074 else
3075 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003076 res = snprintf(fname, sizeof(fname),
3077 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3078 "create_qos", pos);
3079 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003080 return 0; /* not ath6kl */
3081
3082 if (uapsd) {
3083 f = fopen(fname, "w");
3084 if (f == NULL)
3085 return -1;
3086
3087 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3088 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3089 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3090 "20000 0\n");
3091 fclose(f);
3092 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003093 res = snprintf(fname, sizeof(fname),
3094 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3095 "delete_qos", pos);
3096 if (res < 0 || res >= sizeof(fname))
3097 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003098
3099 f = fopen(fname, "w");
3100 if (f == NULL)
3101 return -1;
3102
3103 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3104 fprintf(f, "2 4\n");
3105 fclose(f);
3106 }
3107#endif /* __linux__ */
3108
3109 return 0;
3110}
3111
3112
Jouni Malinenf7222712019-06-13 01:50:21 +03003113static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3114 struct sigma_conn *conn,
3115 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003116{
3117 const char *intf = get_param(cmd, "Interface");
3118 /* const char *ssid = get_param(cmd, "ssid"); */
3119 const char *val;
3120 int max_sp_len = 4;
3121 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3122 char buf[100];
3123 int ret1, ret2;
3124
3125 val = get_param(cmd, "maxSPLength");
3126 if (val) {
3127 max_sp_len = atoi(val);
3128 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3129 max_sp_len != 4)
3130 return -1;
3131 }
3132
3133 val = get_param(cmd, "acBE");
3134 if (val)
3135 ac_be = atoi(val);
3136
3137 val = get_param(cmd, "acBK");
3138 if (val)
3139 ac_bk = atoi(val);
3140
3141 val = get_param(cmd, "acVI");
3142 if (val)
3143 ac_vi = atoi(val);
3144
3145 val = get_param(cmd, "acVO");
3146 if (val)
3147 ac_vo = atoi(val);
3148
3149 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3150
3151 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3152 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3153 ret1 = wpa_command(intf, buf);
3154
3155 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3156 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3157 ret2 = wpa_command(intf, buf);
3158
3159 if (ret1 && ret2) {
3160 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3161 "UAPSD parameters.");
3162 return -2;
3163 }
3164
3165 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3166 send_resp(dut, conn, SIGMA_ERROR,
3167 "ErrorCode,Failed to set ath6kl QoS parameters");
3168 return 0;
3169 }
3170
3171 return 1;
3172}
3173
3174
Jouni Malinenf7222712019-06-13 01:50:21 +03003175static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3176 struct sigma_conn *conn,
3177 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003178{
3179 char buf[1000];
3180 const char *intf = get_param(cmd, "Interface");
3181 const char *grp = get_param(cmd, "Group");
3182 const char *act = get_param(cmd, "Action");
3183 const char *tid = get_param(cmd, "Tid");
3184 const char *dir = get_param(cmd, "Direction");
3185 const char *psb = get_param(cmd, "Psb");
3186 const char *up = get_param(cmd, "Up");
3187 const char *fixed = get_param(cmd, "Fixed");
3188 const char *size = get_param(cmd, "Size");
3189 const char *msize = get_param(cmd, "Maxsize");
3190 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3191 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3192 const char *inact = get_param(cmd, "Inactivity");
3193 const char *sus = get_param(cmd, "Suspension");
3194 const char *mindr = get_param(cmd, "Mindatarate");
3195 const char *meandr = get_param(cmd, "Meandatarate");
3196 const char *peakdr = get_param(cmd, "Peakdatarate");
3197 const char *phyrate = get_param(cmd, "Phyrate");
3198 const char *burstsize = get_param(cmd, "Burstsize");
3199 const char *sba = get_param(cmd, "Sba");
3200 int direction;
3201 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003202 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003203 int fixed_int;
3204 int psb_ts;
3205
3206 if (intf == NULL || grp == NULL || act == NULL )
3207 return -1;
3208
3209 if (strcasecmp(act, "addts") == 0) {
3210 if (tid == NULL || dir == NULL || psb == NULL ||
3211 up == NULL || fixed == NULL || size == NULL)
3212 return -1;
3213
3214 /*
3215 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3216 * possible values, but WMM-AC and V-E test scripts use "UP,
3217 * "DOWN", and "BIDI".
3218 */
3219 if (strcasecmp(dir, "uplink") == 0 ||
3220 strcasecmp(dir, "up") == 0) {
3221 direction = 0;
3222 } else if (strcasecmp(dir, "downlink") == 0 ||
3223 strcasecmp(dir, "down") == 0) {
3224 direction = 1;
3225 } else if (strcasecmp(dir, "bidi") == 0) {
3226 direction = 2;
3227 } else {
3228 sigma_dut_print(dut, DUT_MSG_ERROR,
3229 "Direction %s not supported", dir);
3230 return -1;
3231 }
3232
3233 if (strcasecmp(psb, "legacy") == 0) {
3234 psb_ts = 0;
3235 } else if (strcasecmp(psb, "uapsd") == 0) {
3236 psb_ts = 1;
3237 } else {
3238 sigma_dut_print(dut, DUT_MSG_ERROR,
3239 "PSB %s not supported", psb);
3240 return -1;
3241 }
3242
3243 if (atoi(tid) < 0 || atoi(tid) > 7) {
3244 sigma_dut_print(dut, DUT_MSG_ERROR,
3245 "TID %s not supported", tid);
3246 return -1;
3247 }
3248
3249 if (strcasecmp(fixed, "true") == 0) {
3250 fixed_int = 1;
3251 } else {
3252 fixed_int = 0;
3253 }
3254
Peng Xu93319622017-10-04 17:58:16 -07003255 if (sba)
3256 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003257
3258 dut->dialog_token++;
3259 handle = 7000 + dut->dialog_token;
3260
3261 /*
3262 * size: convert to hex
3263 * maxsi: convert to hex
3264 * mindr: convert to hex
3265 * meandr: convert to hex
3266 * peakdr: convert to hex
3267 * burstsize: convert to hex
3268 * phyrate: convert to hex
3269 * sba: convert to hex with modification
3270 * minsi: convert to integer
3271 * sus: convert to integer
3272 * inact: convert to integer
3273 * maxsi: convert to integer
3274 */
3275
3276 /*
3277 * The Nominal MSDU Size field is 2 octets long and contains an
3278 * unsigned integer that specifies the nominal size, in octets,
3279 * of MSDUs belonging to the traffic under this traffic
3280 * specification and is defined in Figure 16. If the Fixed
3281 * subfield is set to 1, then the size of the MSDU is fixed and
3282 * is indicated by the Size Subfield. If the Fixed subfield is
3283 * set to 0, then the size of the MSDU might not be fixed and
3284 * the Size indicates the nominal MSDU size.
3285 *
3286 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3287 * and specifies the excess allocation of time (and bandwidth)
3288 * over and above the stated rates required to transport an MSDU
3289 * belonging to the traffic in this TSPEC. This field is
3290 * represented as an unsigned binary number with an implicit
3291 * binary point after the leftmost 3 bits. For example, an SBA
3292 * of 1.75 is represented as 0x3800. This field is included to
3293 * account for retransmissions. As such, the value of this field
3294 * must be greater than unity.
3295 */
3296
3297 snprintf(buf, sizeof(buf),
3298 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3299 " 0x%X 0x%X 0x%X"
3300 " 0x%X 0x%X 0x%X"
3301 " 0x%X %d %d %d %d"
3302 " %d %d",
3303 intf, handle, tid, direction, psb_ts, up,
3304 (unsigned int) ((fixed_int << 15) | atoi(size)),
3305 msize ? atoi(msize) : 0,
3306 mindr ? atoi(mindr) : 0,
3307 meandr ? atoi(meandr) : 0,
3308 peakdr ? atoi(peakdr) : 0,
3309 burstsize ? atoi(burstsize) : 0,
3310 phyrate ? atoi(phyrate) : 0,
3311 sba ? ((unsigned int) (((int) sba_fv << 13) |
3312 (int)((sba_fv - (int) sba_fv) *
3313 8192))) : 0,
3314 minsi ? atoi(minsi) : 0,
3315 sus ? atoi(sus) : 0,
3316 0, 0,
3317 inact ? atoi(inact) : 0,
3318 maxsi ? atoi(maxsi) : 0);
3319
3320 if (system(buf) != 0) {
3321 sigma_dut_print(dut, DUT_MSG_ERROR,
3322 "iwpriv addtspec request failed");
3323 send_resp(dut, conn, SIGMA_ERROR,
3324 "errorCode,Failed to execute addTspec command");
3325 return 0;
3326 }
3327
3328 sigma_dut_print(dut, DUT_MSG_INFO,
3329 "iwpriv addtspec request send");
3330
3331 /* Mapping handle to a TID */
3332 dut->tid_to_handle[atoi(tid)] = handle;
3333 } else if (strcasecmp(act, "delts") == 0) {
3334 if (tid == NULL)
3335 return -1;
3336
3337 if (atoi(tid) < 0 || atoi(tid) > 7) {
3338 sigma_dut_print(dut, DUT_MSG_ERROR,
3339 "TID %s not supported", tid);
3340 send_resp(dut, conn, SIGMA_ERROR,
3341 "errorCode,Unsupported TID");
3342 return 0;
3343 }
3344
3345 handle = dut->tid_to_handle[atoi(tid)];
3346
3347 if (handle < 7000 || handle > 7255) {
3348 /* Invalid handle ie no mapping for that TID */
3349 sigma_dut_print(dut, DUT_MSG_ERROR,
3350 "handle-> %d not found", handle);
3351 }
3352
3353 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3354 intf, handle);
3355
3356 if (system(buf) != 0) {
3357 sigma_dut_print(dut, DUT_MSG_ERROR,
3358 "iwpriv deltspec request failed");
3359 send_resp(dut, conn, SIGMA_ERROR,
3360 "errorCode,Failed to execute delTspec command");
3361 return 0;
3362 }
3363
3364 sigma_dut_print(dut, DUT_MSG_INFO,
3365 "iwpriv deltspec request send");
3366
3367 dut->tid_to_handle[atoi(tid)] = 0;
3368 } else {
3369 sigma_dut_print(dut, DUT_MSG_ERROR,
3370 "Action type %s not supported", act);
3371 send_resp(dut, conn, SIGMA_ERROR,
3372 "errorCode,Unsupported Action");
3373 return 0;
3374 }
3375
3376 return 1;
3377}
3378
3379
vamsi krishna52e16f92017-08-29 12:37:34 +05303380static int find_network(struct sigma_dut *dut, const char *ssid)
3381{
3382 char list[4096];
3383 char *pos;
3384
3385 sigma_dut_print(dut, DUT_MSG_DEBUG,
3386 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003387 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303388 list, sizeof(list)) < 0)
3389 return -1;
3390 pos = strstr(list, ssid);
3391 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3392 return -1;
3393
3394 while (pos > list && pos[-1] != '\n')
3395 pos--;
3396 dut->infra_network_id = atoi(pos);
3397 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3398 return 0;
3399}
3400
3401
Sunil Dutt44595082018-02-12 19:41:45 +05303402#ifdef NL80211_SUPPORT
3403static int sta_config_rsnie(struct sigma_dut *dut, int val)
3404{
3405 struct nl_msg *msg;
3406 int ret;
3407 struct nlattr *params;
3408 int ifindex;
3409
3410 ifindex = if_nametoindex("wlan0");
3411 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3412 NL80211_CMD_VENDOR)) ||
3413 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3414 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3415 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3416 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
3417 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3418 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) {
3419 sigma_dut_print(dut, DUT_MSG_ERROR,
3420 "%s: err in adding vendor_cmd and vendor_data",
3421 __func__);
3422 nlmsg_free(msg);
3423 return -1;
3424 }
3425 nla_nest_end(msg, params);
3426
3427 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3428 if (ret) {
3429 sigma_dut_print(dut, DUT_MSG_ERROR,
3430 "%s: err in send_and_recv_msgs, ret=%d",
3431 __func__, ret);
3432 return ret;
3433 }
3434
3435 return 0;
3436}
3437#endif /* NL80211_SUPPORT */
3438
3439
Jouni Malinenf7222712019-06-13 01:50:21 +03003440static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3441 struct sigma_conn *conn,
3442 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003443{
3444 /* const char *intf = get_param(cmd, "Interface"); */
3445 const char *ssid = get_param(cmd, "ssid");
3446 const char *wps_param = get_param(cmd, "WPS");
3447 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003448 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003449 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003450 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003451 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003452 int e;
3453 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3454 struct wpa_ctrl *ctrl = NULL;
3455 int num_network_not_found = 0;
3456 int num_disconnected = 0;
3457 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003458
3459 if (ssid == NULL)
3460 return -1;
3461
Jouni Malinen37d5c692019-08-19 16:56:55 +03003462 dut->server_cert_tod = 0;
3463
Jouni Malinen3c367e82017-06-23 17:01:47 +03003464 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303465#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003466 if (get_driver_type(dut) == DRIVER_WCN) {
Sunil Dutt44595082018-02-12 19:41:45 +05303467 sta_config_rsnie(dut, 1);
3468 dut->config_rsnie = 1;
3469 }
3470#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003471 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3472 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003473 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03003474 send_resp(dut, conn, SIGMA_ERROR,
3475 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3476 return 0;
3477 }
3478 }
3479
Jouni Malinen68143132017-09-02 02:34:08 +03003480 if (dut->sae_commit_override) {
3481 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3482 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003483 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03003484 send_resp(dut, conn, SIGMA_ERROR,
3485 "ErrorCode,Failed to set SAE commit override");
3486 return 0;
3487 }
3488 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303489#ifdef ANDROID
3490 if (dut->fils_hlp)
3491 process_fils_hlp(dut);
3492#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003493
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003494 if (wps_param &&
3495 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3496 wps = 1;
3497
Vamsi Krishnac1633d22020-05-06 18:31:21 +05303498 if (dut->ocvc &&
3499 set_network(get_station_ifname(dut), dut->infra_network_id,
3500 "ocv", "1") < 0)
3501 return ERROR_SEND_STATUS;
3502
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003503 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003504 if (dut->program == PROGRAM_60GHZ && network_mode &&
3505 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003506 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003507 "pbss", "1") < 0)
3508 return -2;
3509
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003510 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3511 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3512 "parameters not yet set");
3513 return 0;
3514 }
3515 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003516 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003517 return -2;
3518 } else {
3519 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3520 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003521 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003522 return -2;
3523 }
3524 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303525 if (strcmp(ssid, dut->infra_ssid) == 0) {
3526 sigma_dut_print(dut, DUT_MSG_DEBUG,
3527 "sta_associate for the most recently added network");
3528 } else if (find_network(dut, ssid) < 0) {
3529 sigma_dut_print(dut, DUT_MSG_DEBUG,
3530 "sta_associate for a previously stored network profile");
3531 send_resp(dut, conn, SIGMA_ERROR,
3532 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003533 return 0;
3534 }
3535
3536 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003537 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003538 "bssid", bssid) < 0) {
3539 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3540 "Invalid bssid argument");
3541 return 0;
3542 }
3543
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003544 if (dut->program == PROGRAM_WPA3 &&
3545 dut->sta_associate_wait_connect) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003546 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003547 if (!ctrl)
3548 return ERROR_SEND_STATUS;
3549 }
3550
Jouni Malinen46a19b62017-06-23 14:31:27 +03003551 extra[0] = '\0';
3552 if (chan)
3553 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003554 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003555 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3556 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003557 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003558 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3559 "network id %d on %s",
3560 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003561 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003562 ret = ERROR_SEND_STATUS;
3563 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003564 }
3565 }
3566
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003567 if (!ctrl)
3568 return SUCCESS_SEND_STATUS;
3569
3570 /* Wait for connection result to be able to store server certificate
3571 * hash for trust root override testing
3572 * (dev_exec_action,ServerCertTrust). */
3573
3574 for (e = 0; e < 20; e++) {
3575 const char *events[] = {
3576 "CTRL-EVENT-EAP-PEER-CERT",
3577 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3578 "CTRL-EVENT-DISCONNECTED",
3579 "CTRL-EVENT-CONNECTED",
3580 "CTRL-EVENT-NETWORK-NOT-FOUND",
3581 NULL
3582 };
3583 char buf[1024];
3584 int res;
3585
3586 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3587 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02003588 send_resp(dut, conn, SIGMA_COMPLETE,
3589 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003590 ret = STATUS_SENT_ERROR;
3591 break;
3592 }
3593 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3594 buf);
3595
3596 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3597 strstr(buf, " depth=0")) {
3598 char *pos = strstr(buf, " hash=");
3599
3600 if (pos) {
3601 char *end;
3602
Jouni Malinen34b19cb2019-08-16 16:37:17 +03003603 if (strstr(buf, " tod=1"))
3604 tod = 1;
3605 else if (strstr(buf, " tod=2"))
3606 tod = 2;
3607 else
3608 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003609 sigma_dut_print(dut, DUT_MSG_DEBUG,
3610 "Server certificate TOD policy: %d",
3611 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03003612 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003613
3614 pos += 6;
3615 end = strchr(pos, ' ');
3616 if (end)
3617 *end = '\0';
3618 strlcpy(dut->server_cert_hash, pos,
3619 sizeof(dut->server_cert_hash));
3620 sigma_dut_print(dut, DUT_MSG_DEBUG,
3621 "Server certificate hash: %s",
3622 dut->server_cert_hash);
3623 }
3624 }
3625
3626 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3627 send_resp(dut, conn, SIGMA_COMPLETE,
3628 "Result,TLS server certificate validation failed");
3629 ret = STATUS_SENT_ERROR;
3630 break;
3631 }
3632
3633 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3634 num_network_not_found++;
3635
3636 if (num_network_not_found > 2) {
3637 send_resp(dut, conn, SIGMA_COMPLETE,
3638 "Result,Network not found");
3639 ret = STATUS_SENT_ERROR;
3640 break;
3641 }
3642 }
3643
3644 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3645 num_disconnected++;
3646
3647 if (num_disconnected > 2) {
3648 send_resp(dut, conn, SIGMA_COMPLETE,
3649 "Result,Connection failed");
3650 ret = STATUS_SENT_ERROR;
3651 break;
3652 }
3653 }
3654
3655 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3656 if (tod >= 0) {
3657 sigma_dut_print(dut, DUT_MSG_DEBUG,
3658 "Network profile TOD policy update: %d -> %d",
3659 dut->sta_tod_policy, tod);
3660 dut->sta_tod_policy = tod;
3661 }
3662 break;
3663 }
3664 }
3665done:
3666 if (ctrl) {
3667 wpa_ctrl_detach(ctrl);
3668 wpa_ctrl_close(ctrl);
3669 }
3670 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003671}
3672
3673
3674static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3675{
3676 char buf[500], cmd[200];
3677 int res;
3678
3679 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3680 * default path */
3681 res = snprintf(cmd, sizeof(cmd),
3682 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3683 file_exists("./hs20-osu-client") ?
3684 "./hs20-osu-client" : "hs20-osu-client",
3685 sigma_wpas_ctrl,
3686 dut->summary_log ? "-s " : "",
3687 dut->summary_log ? dut->summary_log : "");
3688 if (res < 0 || res >= (int) sizeof(cmd))
3689 return -1;
3690
3691 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3692 if (res < 0 || res >= (int) sizeof(buf))
3693 return -1;
3694 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3695
3696 if (system(buf) != 0) {
3697 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3698 return -1;
3699 }
3700 sigma_dut_print(dut, DUT_MSG_DEBUG,
3701 "Completed hs20-osu-client operation");
3702
3703 return 0;
3704}
3705
3706
3707static int download_ppsmo(struct sigma_dut *dut,
3708 struct sigma_conn *conn,
3709 const char *intf,
3710 struct sigma_cmd *cmd)
3711{
3712 const char *name, *path, *val;
3713 char url[500], buf[600], fbuf[100];
3714 char *fqdn = NULL;
3715
3716 name = get_param(cmd, "FileName");
3717 path = get_param(cmd, "FilePath");
3718 if (name == NULL || path == NULL)
3719 return -1;
3720
3721 if (strcasecmp(path, "VendorSpecific") == 0) {
3722 snprintf(url, sizeof(url), "PPS/%s", name);
3723 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3724 "from the device (%s)", url);
3725 if (!file_exists(url)) {
3726 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3727 "PPS MO file does not exist");
3728 return 0;
3729 }
3730 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3731 if (system(buf) != 0) {
3732 send_resp(dut, conn, SIGMA_ERROR,
3733 "errorCode,Failed to copy PPS MO");
3734 return 0;
3735 }
3736 } else if (strncasecmp(path, "http:", 5) != 0 &&
3737 strncasecmp(path, "https:", 6) != 0) {
3738 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3739 "Unsupported FilePath value");
3740 return 0;
3741 } else {
3742 snprintf(url, sizeof(url), "%s/%s", path, name);
3743 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3744 url);
3745 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3746 remove("pps-tnds.xml");
3747 if (system(buf) != 0) {
3748 send_resp(dut, conn, SIGMA_ERROR,
3749 "errorCode,Failed to download PPS MO");
3750 return 0;
3751 }
3752 }
3753
3754 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3755 send_resp(dut, conn, SIGMA_ERROR,
3756 "errorCode,Failed to parse downloaded PPSMO");
3757 return 0;
3758 }
3759 unlink("pps-tnds.xml");
3760
3761 val = get_param(cmd, "managementTreeURI");
3762 if (val) {
3763 const char *pos, *end;
3764 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3765 val);
3766 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3767 send_resp(dut, conn, SIGMA_ERROR,
3768 "errorCode,Invalid managementTreeURI prefix");
3769 return 0;
3770 }
3771 pos = val + 8;
3772 end = strchr(pos, '/');
3773 if (end == NULL ||
3774 strcmp(end, "/PerProviderSubscription") != 0) {
3775 send_resp(dut, conn, SIGMA_ERROR,
3776 "errorCode,Invalid managementTreeURI postfix");
3777 return 0;
3778 }
3779 if (end - pos >= (int) sizeof(fbuf)) {
3780 send_resp(dut, conn, SIGMA_ERROR,
3781 "errorCode,Too long FQDN in managementTreeURI");
3782 return 0;
3783 }
3784 memcpy(fbuf, pos, end - pos);
3785 fbuf[end - pos] = '\0';
3786 fqdn = fbuf;
3787 sigma_dut_print(dut, DUT_MSG_INFO,
3788 "FQDN from managementTreeURI: %s", fqdn);
3789 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3790 FILE *f = fopen("pps-fqdn", "r");
3791 if (f) {
3792 if (fgets(fbuf, sizeof(fbuf), f)) {
3793 fbuf[sizeof(fbuf) - 1] = '\0';
3794 fqdn = fbuf;
3795 sigma_dut_print(dut, DUT_MSG_DEBUG,
3796 "Use FQDN %s", fqdn);
3797 }
3798 fclose(f);
3799 }
3800 }
3801
3802 if (fqdn == NULL) {
3803 send_resp(dut, conn, SIGMA_ERROR,
3804 "errorCode,No FQDN specified");
3805 return 0;
3806 }
3807
3808 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3809 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3810 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3811
3812 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3813 if (rename("pps.xml", buf) < 0) {
3814 send_resp(dut, conn, SIGMA_ERROR,
3815 "errorCode,Could not move PPS MO");
3816 return 0;
3817 }
3818
3819 if (strcasecmp(path, "VendorSpecific") == 0) {
3820 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3821 fqdn);
3822 if (system(buf)) {
3823 send_resp(dut, conn, SIGMA_ERROR,
3824 "errorCode,Failed to copy OSU CA cert");
3825 return 0;
3826 }
3827
3828 snprintf(buf, sizeof(buf),
3829 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3830 fqdn);
3831 if (system(buf)) {
3832 send_resp(dut, conn, SIGMA_ERROR,
3833 "errorCode,Failed to copy AAA CA cert");
3834 return 0;
3835 }
3836 } else {
3837 snprintf(buf, sizeof(buf),
3838 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3839 fqdn, fqdn);
3840 if (run_hs20_osu(dut, buf) < 0) {
3841 send_resp(dut, conn, SIGMA_ERROR,
3842 "errorCode,Failed to download OSU CA cert");
3843 return 0;
3844 }
3845
3846 snprintf(buf, sizeof(buf),
3847 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3848 fqdn, fqdn);
3849 if (run_hs20_osu(dut, buf) < 0) {
3850 sigma_dut_print(dut, DUT_MSG_INFO,
3851 "Failed to download AAA CA cert");
3852 }
3853 }
3854
3855 if (file_exists("next-client-cert.pem")) {
3856 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3857 if (rename("next-client-cert.pem", buf) < 0) {
3858 send_resp(dut, conn, SIGMA_ERROR,
3859 "errorCode,Could not move client certificate");
3860 return 0;
3861 }
3862 }
3863
3864 if (file_exists("next-client-key.pem")) {
3865 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3866 if (rename("next-client-key.pem", buf) < 0) {
3867 send_resp(dut, conn, SIGMA_ERROR,
3868 "errorCode,Could not move client key");
3869 return 0;
3870 }
3871 }
3872
3873 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3874 if (run_hs20_osu(dut, buf) < 0) {
3875 send_resp(dut, conn, SIGMA_ERROR,
3876 "errorCode,Failed to configure credential from "
3877 "PPSMO");
3878 return 0;
3879 }
3880
3881 return 1;
3882}
3883
3884
3885static int download_cert(struct sigma_dut *dut,
3886 struct sigma_conn *conn,
3887 const char *intf,
3888 struct sigma_cmd *cmd)
3889{
3890 const char *name, *path;
3891 char url[500], buf[600];
3892
3893 name = get_param(cmd, "FileName");
3894 path = get_param(cmd, "FilePath");
3895 if (name == NULL || path == NULL)
3896 return -1;
3897
3898 if (strcasecmp(path, "VendorSpecific") == 0) {
3899 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
3900 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3901 "certificate from the device (%s)", url);
3902 if (!file_exists(url)) {
3903 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3904 "certificate file does not exist");
3905 return 0;
3906 }
3907 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
3908 if (system(buf) != 0) {
3909 send_resp(dut, conn, SIGMA_ERROR,
3910 "errorCode,Failed to copy client "
3911 "certificate");
3912 return 0;
3913 }
3914
3915 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
3916 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3917 "private key from the device (%s)", url);
3918 if (!file_exists(url)) {
3919 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3920 "private key file does not exist");
3921 return 0;
3922 }
3923 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
3924 if (system(buf) != 0) {
3925 send_resp(dut, conn, SIGMA_ERROR,
3926 "errorCode,Failed to copy client key");
3927 return 0;
3928 }
3929 } else if (strncasecmp(path, "http:", 5) != 0 &&
3930 strncasecmp(path, "https:", 6) != 0) {
3931 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3932 "Unsupported FilePath value");
3933 return 0;
3934 } else {
3935 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
3936 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
3937 "certificate/key from %s", url);
3938 snprintf(buf, sizeof(buf),
3939 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
3940 if (system(buf) != 0) {
3941 send_resp(dut, conn, SIGMA_ERROR,
3942 "errorCode,Failed to download client "
3943 "certificate");
3944 return 0;
3945 }
3946
3947 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
3948 {
3949 send_resp(dut, conn, SIGMA_ERROR,
3950 "errorCode,Failed to copy client key");
3951 return 0;
3952 }
3953 }
3954
3955 return 1;
3956}
3957
3958
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003959static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
3960 struct sigma_conn *conn,
3961 struct sigma_cmd *cmd)
3962{
3963 const char *val;
3964 const char *intf = get_param(cmd, "interface");
3965
3966 if (!intf)
3967 return -1;
3968
3969 val = get_param(cmd, "WscIEFragment");
3970 if (val && strcasecmp(val, "enable") == 0) {
3971 sigma_dut_print(dut, DUT_MSG_DEBUG,
3972 "Enable WSC IE fragmentation");
3973
3974 dut->wsc_fragment = 1;
3975 /* set long attributes to force fragmentation */
3976 if (wpa_command(intf, "SET device_name "
3977 WPS_LONG_DEVICE_NAME) < 0)
3978 return -2;
3979 if (wpa_command(intf, "SET manufacturer "
3980 WPS_LONG_MANUFACTURER) < 0)
3981 return -2;
3982 if (wpa_command(intf, "SET model_name "
3983 WPS_LONG_MODEL_NAME) < 0)
3984 return -2;
3985 if (wpa_command(intf, "SET model_number "
3986 WPS_LONG_MODEL_NUMBER) < 0)
3987 return -2;
3988 if (wpa_command(intf, "SET serial_number "
3989 WPS_LONG_SERIAL_NUMBER) < 0)
3990 return -2;
3991 }
3992
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02003993 val = get_param(cmd, "RSN_IE");
3994 if (val) {
3995 if (strcasecmp(val, "disable") == 0)
3996 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
3997 else if (strcasecmp(val, "enable") == 0)
3998 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
3999 }
4000
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004001 val = get_param(cmd, "WpsVersion");
4002 if (val)
4003 dut->wps_forced_version = get_wps_forced_version(dut, val);
4004
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004005 val = get_param(cmd, "WscEAPFragment");
4006 if (val && strcasecmp(val, "enable") == 0)
4007 dut->eap_fragment = 1;
4008
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004009 return 1;
4010}
4011
4012
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004013static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4014 struct sigma_conn *conn,
4015 const char *intf,
4016 struct sigma_cmd *cmd)
4017{
4018 const char *val;
4019
4020 val = get_param(cmd, "FileType");
4021 if (val && strcasecmp(val, "PPSMO") == 0)
4022 return download_ppsmo(dut, conn, intf, cmd);
4023 if (val && strcasecmp(val, "CERT") == 0)
4024 return download_cert(dut, conn, intf, cmd);
4025 if (val) {
4026 send_resp(dut, conn, SIGMA_ERROR,
4027 "ErrorCode,Unsupported FileType");
4028 return 0;
4029 }
4030
4031 return 1;
4032}
4033
4034
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304035static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4036 struct sigma_conn *conn,
4037 const char *intf,
4038 struct sigma_cmd *cmd)
4039{
4040 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304041 char buf[1000];
4042 char text[20];
4043 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304044
4045 val = get_param(cmd, "OCESupport");
4046 if (val && strcasecmp(val, "Disable") == 0) {
4047 if (wpa_command(intf, "SET oce 0") < 0) {
4048 send_resp(dut, conn, SIGMA_ERROR,
4049 "ErrorCode,Failed to disable OCE");
4050 return 0;
4051 }
4052 } else if (val && strcasecmp(val, "Enable") == 0) {
4053 if (wpa_command(intf, "SET oce 1") < 0) {
4054 send_resp(dut, conn, SIGMA_ERROR,
4055 "ErrorCode,Failed to enable OCE");
4056 return 0;
4057 }
4058 }
4059
vamsi krishnaa2799492017-12-05 14:28:01 +05304060 val = get_param(cmd, "FILScap");
4061 if (val && (atoi(val) == 1)) {
4062 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4063 send_resp(dut, conn, SIGMA_ERROR,
4064 "ErrorCode,Failed to enable FILS");
4065 return 0;
4066 }
4067 } else if (val && (atoi(val) == 0)) {
4068 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4069 send_resp(dut, conn, SIGMA_ERROR,
4070 "ErrorCode,Failed to disable FILS");
4071 return 0;
4072 }
4073 }
4074
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304075 val = get_param(cmd, "FILSHLP");
4076 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004077 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304078 sizeof(text)) < 0)
4079 return -2;
4080 hwaddr_aton(text, addr);
4081 snprintf(buf, sizeof(buf),
4082 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4083 "080045100140000040004011399e00000000ffffffff00440043"
4084 "012cb30001010600fd4f46410000000000000000000000000000"
4085 "000000000000"
4086 "%02x%02x%02x%02x%02x%02x"
4087 "0000000000000000000000000000000000000000000000000000"
4088 "0000000000000000000000000000000000000000000000000000"
4089 "0000000000000000000000000000000000000000000000000000"
4090 "0000000000000000000000000000000000000000000000000000"
4091 "0000000000000000000000000000000000000000000000000000"
4092 "0000000000000000000000000000000000000000000000000000"
4093 "0000000000000000000000000000000000000000000000000000"
4094 "0000000000000000000000000000000000000000638253633501"
4095 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4096 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4097 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4098 if (wpa_command(intf, buf)) {
4099 send_resp(dut, conn, SIGMA_ERROR,
4100 "ErrorCode,Failed to add HLP");
4101 return 0;
4102 }
4103 dut->fils_hlp = 1;
4104 }
4105
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304106 return 1;
4107}
4108
4109
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004110static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4111 const char *val)
4112{
4113 int counter = 0;
4114 char token[50];
4115 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304116 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004117
Peng Xub8fc5cc2017-05-10 17:27:28 -07004118 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004119 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304120 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004121 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004122 if (strcmp(result, "disable") == 0)
4123 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4124 else
4125 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304126 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004127 counter++;
4128 }
4129}
4130
4131
4132static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4133 const char *val)
4134{
4135 char buf[100];
4136
4137 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4138 if (system(buf) != 0) {
4139 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4140 }
4141}
4142
4143
4144static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4145 const char *val)
4146{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004147 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004148 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004149 }
4150}
4151
4152
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004153static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4154 const char *val)
4155{
4156#ifdef NL80211_SUPPORT
4157 struct nl_msg *msg;
4158 int ret = 0;
4159 struct nlattr *params;
4160 int ifindex;
4161 int wmmenable = 1;
4162
4163 if (val &&
4164 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4165 wmmenable = 0;
4166
4167 ifindex = if_nametoindex(intf);
4168 if (ifindex == 0) {
4169 sigma_dut_print(dut, DUT_MSG_ERROR,
4170 "%s: Index for interface %s failed",
4171 __func__, intf);
4172 return -1;
4173 }
4174
4175 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4176 NL80211_CMD_VENDOR)) ||
4177 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4178 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4179 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4180 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4181 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4182 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4183 wmmenable)) {
4184 sigma_dut_print(dut, DUT_MSG_ERROR,
4185 "%s: err in adding vendor_cmd and vendor_data",
4186 __func__);
4187 nlmsg_free(msg);
4188 return -1;
4189 }
4190 nla_nest_end(msg, params);
4191
4192 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4193 if (ret) {
4194 sigma_dut_print(dut, DUT_MSG_ERROR,
4195 "%s: err in send_and_recv_msgs, ret=%d",
4196 __func__, ret);
4197 }
4198 return ret;
4199#else /* NL80211_SUPPORT */
4200 sigma_dut_print(dut, DUT_MSG_ERROR,
4201 "WMM cannot be changed without NL80211_SUPPORT defined");
4202 return -1;
4203#endif /* NL80211_SUPPORT */
4204}
4205
4206
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004207static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4208 const char *val)
4209{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004210 int sgi20;
4211
4212 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4213
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004214 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004215}
4216
4217
4218static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4219 const char *val)
4220{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304221 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004222
4223 /* Disable Tx Beam forming when using a fixed rate */
4224 ath_disable_txbf(dut, intf);
4225
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304226 v = atoi(val);
4227 if (v < 0 || v > 32) {
4228 sigma_dut_print(dut, DUT_MSG_ERROR,
4229 "Invalid Fixed MCS rate: %d", v);
4230 return;
4231 }
4232 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004233
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004234 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004235
4236 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004237 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004238}
4239
4240
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004241static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4242 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004243{
4244 char buf[60];
4245
4246 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4247 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4248 else
4249 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4250
4251 if (system(buf) != 0)
4252 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4253}
4254
4255
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004256static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4257 int ampdu)
4258{
4259 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004260 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004261
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004262 if (ampdu)
4263 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004264 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4265 if (system(buf) != 0) {
4266 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4267 return -1;
4268 }
4269
4270 return 0;
4271}
4272
4273
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004274static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4275 const char *val)
4276{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004277 run_iwpriv(dut, intf, "tx_stbc %s", val);
4278 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004279}
4280
4281
4282static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4283 const char *val)
4284{
4285 char buf[60];
4286
Peng Xucc317ed2017-05-18 16:44:37 -07004287 if (strcmp(val, "160") == 0) {
4288 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4289 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004290 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4291 } else if (strcmp(val, "40") == 0) {
4292 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4293 } else if (strcmp(val, "20") == 0) {
4294 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4295 } else if (strcasecmp(val, "Auto") == 0) {
4296 buf[0] = '\0';
4297 } else {
4298 sigma_dut_print(dut, DUT_MSG_ERROR,
4299 "WIDTH/CTS_WIDTH value not supported");
4300 return -1;
4301 }
4302
4303 if (buf[0] != '\0' && system(buf) != 0) {
4304 sigma_dut_print(dut, DUT_MSG_ERROR,
4305 "Failed to set WIDTH/CTS_WIDTH");
4306 return -1;
4307 }
4308
4309 return 0;
4310}
4311
4312
4313int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4314 const char *intf, const char *val)
4315{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004316 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004317 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004318 dut->chwidth = 0;
4319 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004320 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004321 dut->chwidth = 0;
4322 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004323 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004324 dut->chwidth = 1;
4325 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004326 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004327 dut->chwidth = 2;
4328 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004329 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004330 dut->chwidth = 3;
4331 } else {
4332 send_resp(dut, conn, SIGMA_ERROR,
4333 "ErrorCode,WIDTH not supported");
4334 return -1;
4335 }
4336
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004337 return 0;
4338}
4339
4340
4341static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4342 const char *val)
4343{
4344 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004345 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004346
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004347 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004348 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004349 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004350 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004351 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004352 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004353 } else {
4354 sigma_dut_print(dut, DUT_MSG_ERROR,
4355 "SP_STREAM value not supported");
4356 return -1;
4357 }
4358
4359 if (system(buf) != 0) {
4360 sigma_dut_print(dut, DUT_MSG_ERROR,
4361 "Failed to set SP_STREAM");
4362 return -1;
4363 }
4364
Arif Hussainac6c5112018-05-25 17:34:00 -07004365 dut->sta_nss = sta_nss;
4366
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004367 return 0;
4368}
4369
4370
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304371static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4372 const char *val)
4373{
4374 char buf[60];
4375
4376 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
4377 if (system(buf) != 0)
4378 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4379
4380 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
4381 if (system(buf) != 0)
4382 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4383}
4384
4385
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304386static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4387 struct sigma_conn *conn,
4388 const char *intf, int capa)
4389{
4390 char buf[32];
4391
4392 if (capa > 0 && capa < 4) {
4393 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4394 if (wpa_command(intf, buf) < 0) {
4395 send_resp(dut, conn, SIGMA_ERROR,
4396 "ErrorCode, Failed to set cellular data capability");
4397 return 0;
4398 }
4399 return 1;
4400 }
4401
4402 sigma_dut_print(dut, DUT_MSG_ERROR,
4403 "Invalid Cellular data capability: %d", capa);
4404 send_resp(dut, conn, SIGMA_INVALID,
4405 "ErrorCode,Invalid cellular data capability");
4406 return 0;
4407}
4408
4409
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304410static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4411 const char *intf, const char *val)
4412{
4413 if (strcasecmp(val, "Disable") == 0) {
4414 if (wpa_command(intf, "SET roaming 0") < 0) {
4415 send_resp(dut, conn, SIGMA_ERROR,
4416 "ErrorCode,Failed to disable roaming");
4417 return 0;
4418 }
4419 return 1;
4420 }
4421
4422 if (strcasecmp(val, "Enable") == 0) {
4423 if (wpa_command(intf, "SET roaming 1") < 0) {
4424 send_resp(dut, conn, SIGMA_ERROR,
4425 "ErrorCode,Failed to enable roaming");
4426 return 0;
4427 }
4428 return 1;
4429 }
4430
4431 sigma_dut_print(dut, DUT_MSG_ERROR,
4432 "Invalid value provided for roaming: %s", val);
4433 send_resp(dut, conn, SIGMA_INVALID,
4434 "ErrorCode,Unknown value provided for Roaming");
4435 return 0;
4436}
4437
4438
Ashwini Patila75de5a2017-04-13 16:35:05 +05304439static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4440 struct sigma_conn *conn,
4441 const char *intf, const char *val)
4442{
4443 if (strcasecmp(val, "Disable") == 0) {
4444 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4445 send_resp(dut, conn, SIGMA_ERROR,
4446 "ErrorCode,Failed to disable Assoc_disallow");
4447 return 0;
4448 }
4449 return 1;
4450 }
4451
4452 if (strcasecmp(val, "Enable") == 0) {
4453 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4454 send_resp(dut, conn, SIGMA_ERROR,
4455 "ErrorCode,Failed to enable Assoc_disallow");
4456 return 0;
4457 }
4458 return 1;
4459 }
4460
4461 sigma_dut_print(dut, DUT_MSG_ERROR,
4462 "Invalid value provided for Assoc_disallow: %s", val);
4463 send_resp(dut, conn, SIGMA_INVALID,
4464 "ErrorCode,Unknown value provided for Assoc_disallow");
4465 return 0;
4466}
4467
4468
Ashwini Patilc63161e2017-04-13 16:30:23 +05304469static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4470 const char *intf, const char *val)
4471{
4472 if (strcasecmp(val, "Reject") == 0) {
4473 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4474 send_resp(dut, conn, SIGMA_ERROR,
4475 "ErrorCode,Failed to Reject BTM Request");
4476 return 0;
4477 }
4478 return 1;
4479 }
4480
4481 if (strcasecmp(val, "Accept") == 0) {
4482 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4483 send_resp(dut, conn, SIGMA_ERROR,
4484 "ErrorCode,Failed to Accept BTM Request");
4485 return 0;
4486 }
4487 return 1;
4488 }
4489
4490 sigma_dut_print(dut, DUT_MSG_ERROR,
4491 "Invalid value provided for BSS_Transition: %s", val);
4492 send_resp(dut, conn, SIGMA_INVALID,
4493 "ErrorCode,Unknown value provided for BSS_Transition");
4494 return 0;
4495}
4496
4497
Ashwini Patil00402582017-04-13 12:29:39 +05304498static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4499 struct sigma_conn *conn,
4500 const char *intf,
4501 struct sigma_cmd *cmd)
4502{
4503 const char *ch, *pref, *op_class, *reason;
4504 char buf[120];
4505 int len, ret;
4506
4507 pref = get_param(cmd, "Ch_Pref");
4508 if (!pref)
4509 return 1;
4510
4511 if (strcasecmp(pref, "clear") == 0) {
4512 free(dut->non_pref_ch_list);
4513 dut->non_pref_ch_list = NULL;
4514 } else {
4515 op_class = get_param(cmd, "Ch_Op_Class");
4516 if (!op_class) {
4517 send_resp(dut, conn, SIGMA_INVALID,
4518 "ErrorCode,Ch_Op_Class not provided");
4519 return 0;
4520 }
4521
4522 ch = get_param(cmd, "Ch_Pref_Num");
4523 if (!ch) {
4524 send_resp(dut, conn, SIGMA_INVALID,
4525 "ErrorCode,Ch_Pref_Num not provided");
4526 return 0;
4527 }
4528
4529 reason = get_param(cmd, "Ch_Reason_Code");
4530 if (!reason) {
4531 send_resp(dut, conn, SIGMA_INVALID,
4532 "ErrorCode,Ch_Reason_Code not provided");
4533 return 0;
4534 }
4535
4536 if (!dut->non_pref_ch_list) {
4537 dut->non_pref_ch_list =
4538 calloc(1, NON_PREF_CH_LIST_SIZE);
4539 if (!dut->non_pref_ch_list) {
4540 send_resp(dut, conn, SIGMA_ERROR,
4541 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4542 return 0;
4543 }
4544 }
4545 len = strlen(dut->non_pref_ch_list);
4546 ret = snprintf(dut->non_pref_ch_list + len,
4547 NON_PREF_CH_LIST_SIZE - len,
4548 " %s:%s:%s:%s", op_class, ch, pref, reason);
4549 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4550 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4551 dut->non_pref_ch_list);
4552 } else {
4553 sigma_dut_print(dut, DUT_MSG_ERROR,
4554 "snprintf failed for non_pref_list, ret = %d",
4555 ret);
4556 send_resp(dut, conn, SIGMA_ERROR,
4557 "ErrorCode,snprintf failed");
4558 free(dut->non_pref_ch_list);
4559 dut->non_pref_ch_list = NULL;
4560 return 0;
4561 }
4562 }
4563
4564 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4565 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4566 if (ret < 0 || ret >= (int) sizeof(buf)) {
4567 sigma_dut_print(dut, DUT_MSG_DEBUG,
4568 "snprintf failed for set non_pref_chan, ret: %d",
4569 ret);
4570 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4571 return 0;
4572 }
4573
4574 if (wpa_command(intf, buf) < 0) {
4575 send_resp(dut, conn, SIGMA_ERROR,
4576 "ErrorCode,Failed to set non-preferred channel list");
4577 return 0;
4578 }
4579
4580 return 1;
4581}
4582
4583
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004584#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004585
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004586static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4587 uint8_t cfg)
4588{
4589 struct nl_msg *msg;
4590 int ret = 0;
4591 struct nlattr *params;
4592 int ifindex;
4593
4594 ifindex = if_nametoindex(intf);
4595 if (ifindex == 0) {
4596 sigma_dut_print(dut, DUT_MSG_ERROR,
4597 "%s: Index for interface %s failed",
4598 __func__, intf);
4599 return -1;
4600 }
4601
4602 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4603 NL80211_CMD_VENDOR)) ||
4604 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4605 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4606 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4607 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4608 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4609 nla_put_u8(msg,
4610 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4611 cfg)) {
4612 sigma_dut_print(dut, DUT_MSG_ERROR,
4613 "%s: err in adding vendor_cmd and vendor_data",
4614 __func__);
4615 nlmsg_free(msg);
4616 return -1;
4617 }
4618 nla_nest_end(msg, params);
4619
4620 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4621 if (ret) {
4622 sigma_dut_print(dut, DUT_MSG_ERROR,
4623 "%s: err in send_and_recv_msgs, ret=%d",
4624 __func__, ret);
4625 }
4626 return ret;
4627}
4628
4629
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004630static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4631 enum he_fragmentation_val frag)
4632{
4633 struct nl_msg *msg;
4634 int ret = 0;
4635 struct nlattr *params;
4636 int ifindex;
4637
4638 ifindex = if_nametoindex(intf);
4639 if (ifindex == 0) {
4640 sigma_dut_print(dut, DUT_MSG_ERROR,
4641 "%s: Index for interface %s failed",
4642 __func__, intf);
4643 return -1;
4644 }
4645
4646 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4647 NL80211_CMD_VENDOR)) ||
4648 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4649 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4650 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4651 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4652 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4653 nla_put_u8(msg,
4654 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
4655 frag)) {
4656 sigma_dut_print(dut, DUT_MSG_ERROR,
4657 "%s: err in adding vendor_cmd and vendor_data",
4658 __func__);
4659 nlmsg_free(msg);
4660 return -1;
4661 }
4662 nla_nest_end(msg, params);
4663
4664 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4665 if (ret) {
4666 sigma_dut_print(dut, DUT_MSG_ERROR,
4667 "%s: err in send_and_recv_msgs, ret=%d",
4668 __func__, ret);
4669 }
4670 return ret;
4671}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004672
4673
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08004674int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
4675 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004676{
4677 struct nl_msg *msg;
4678 int ret = 0;
4679 struct nlattr *params;
4680 int ifindex;
4681
4682 ifindex = if_nametoindex(intf);
4683 if (ifindex == 0) {
4684 sigma_dut_print(dut, DUT_MSG_ERROR,
4685 "%s: Index for interface %s failed",
4686 __func__, intf);
4687 return -1;
4688 }
4689
4690 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4691 NL80211_CMD_VENDOR)) ||
4692 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4693 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4694 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4695 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4696 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4697 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
4698 ltf)) {
4699 sigma_dut_print(dut, DUT_MSG_ERROR,
4700 "%s: err in adding vendor_cmd and vendor_data",
4701 __func__);
4702 nlmsg_free(msg);
4703 return -1;
4704 }
4705 nla_nest_end(msg, params);
4706
4707 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4708 if (ret) {
4709 sigma_dut_print(dut, DUT_MSG_ERROR,
4710 "%s: err in send_and_recv_msgs, ret=%d",
4711 __func__, ret);
4712 }
4713 return ret;
4714}
4715
4716
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004717static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4718 int noack, enum qca_wlan_ac_type ac)
4719{
4720 struct nl_msg *msg;
4721 int ret = 0;
4722 struct nlattr *params;
4723 int ifindex;
4724
4725 ifindex = if_nametoindex(intf);
4726 if (ifindex == 0) {
4727 sigma_dut_print(dut, DUT_MSG_ERROR,
4728 "%s: Index for interface %s failed",
4729 __func__, intf);
4730 return -1;
4731 }
4732
4733 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4734 NL80211_CMD_VENDOR)) ||
4735 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4736 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4737 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4738 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4739 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4740 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4741 noack) ||
4742 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4743 ac)) {
4744 sigma_dut_print(dut, DUT_MSG_ERROR,
4745 "%s: err in adding vendor_cmd and vendor_data",
4746 __func__);
4747 nlmsg_free(msg);
4748 return -1;
4749 }
4750 nla_nest_end(msg, params);
4751
4752 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4753 if (ret) {
4754 sigma_dut_print(dut, DUT_MSG_ERROR,
4755 "%s: err in send_and_recv_msgs, ret=%d",
4756 __func__, ret);
4757 }
4758 return ret;
4759}
4760
4761
4762static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4763 const char *val)
4764{
4765 int noack, ret;
4766 char token[100];
4767 char *result;
4768 char *saveptr;
4769 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4770
4771 strlcpy(token, val, sizeof(token));
4772 token[sizeof(token) - 1] = '\0';
4773 result = strtok_r(token, ":", &saveptr);
4774 while (result) {
4775 noack = strcasecmp(result, "Disable") != 0;
4776 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4777 if (ret) {
4778 sigma_dut_print(dut, DUT_MSG_ERROR,
4779 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4780 ac, ret);
4781 }
4782 result = strtok_r(NULL, ":", &saveptr);
4783 ac++;
4784 }
4785}
4786
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004787#endif /* NL80211_SUPPORT */
4788
4789
Jouni Malinenf7222712019-06-13 01:50:21 +03004790static enum sigma_cmd_result
4791cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
4792 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004793{
4794 const char *intf = get_param(cmd, "Interface");
4795 const char *val;
4796
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03004797 val = get_param(cmd, "FT_DS");
4798 if (val) {
4799 if (strcasecmp(val, "Enable") == 0) {
4800 dut->sta_ft_ds = 1;
4801 } else if (strcasecmp(val, "Disable") == 0) {
4802 dut->sta_ft_ds = 0;
4803 } else {
4804 send_resp(dut, conn, SIGMA_ERROR,
4805 "errorCode,Unsupported value for FT_DS");
4806 return STATUS_SENT_ERROR;
4807 }
4808 }
4809
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004810 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03004811 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
4812 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004813 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
4814 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004815
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004816 if (val && strcasecmp(val, "LOC") == 0)
4817 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02004818 if (val && strcasecmp(val, "60GHZ") == 0) {
4819 val = get_param(cmd, "WPS");
4820 if (val && strcasecmp(val, "disable") == 0) {
4821 dut->wps_disable = 1;
4822 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
4823 } else {
4824 /* wps_disable can have other value from the previous
4825 * test, so make sure it has the correct value.
4826 */
4827 dut->wps_disable = 0;
4828 }
4829
4830 val = get_param(cmd, "P2P");
4831 if (val && strcasecmp(val, "disable") == 0)
4832 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
4833 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004834
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004835 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
4836 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
4837
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004838#ifdef ANDROID_NAN
4839 if (val && strcasecmp(val, "NAN") == 0)
4840 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
4841#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004842#ifdef MIRACAST
4843 if (val && (strcasecmp(val, "WFD") == 0 ||
4844 strcasecmp(val, "DisplayR2") == 0))
4845 return miracast_preset_testparameters(dut, conn, cmd);
4846#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004847
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304848 if (val && strcasecmp(val, "MBO") == 0) {
4849 val = get_param(cmd, "Cellular_Data_Cap");
4850 if (val &&
4851 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
4852 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05304853
4854 val = get_param(cmd, "Ch_Pref");
4855 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
4856 return 0;
4857
Ashwini Patilc63161e2017-04-13 16:30:23 +05304858 val = get_param(cmd, "BSS_Transition");
4859 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
4860 return 0;
4861
Ashwini Patila75de5a2017-04-13 16:35:05 +05304862 val = get_param(cmd, "Assoc_Disallow");
4863 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
4864 return 0;
4865
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304866 val = get_param(cmd, "Roaming");
4867 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
4868 return 0;
4869
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304870 return 1;
4871 }
4872
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304873 if (val && strcasecmp(val, "OCE") == 0)
4874 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
4875
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004876#if 0
4877 val = get_param(cmd, "Supplicant");
4878 if (val && strcasecmp(val, "Default") != 0) {
4879 send_resp(dut, conn, SIGMA_ERROR,
4880 "ErrorCode,Only default(Vendor) supplicant "
4881 "supported");
4882 return 0;
4883 }
4884#endif
4885
4886 val = get_param(cmd, "RTS");
4887 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004888 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004889 case DRIVER_ATHEROS:
4890 ath_sta_set_rts(dut, intf, val);
4891 break;
4892 default:
4893#if 0
4894 send_resp(dut, conn, SIGMA_ERROR,
4895 "ErrorCode,Setting RTS not supported");
4896 return 0;
4897#else
4898 sigma_dut_print(dut, DUT_MSG_DEBUG,
4899 "Setting RTS not supported");
4900 break;
4901#endif
4902 }
4903 }
4904
4905#if 0
4906 val = get_param(cmd, "FRGMNT");
4907 if (val) {
4908 /* TODO */
4909 send_resp(dut, conn, SIGMA_ERROR,
4910 "ErrorCode,Setting FRGMNT not supported");
4911 return 0;
4912 }
4913#endif
4914
4915#if 0
4916 val = get_param(cmd, "Preamble");
4917 if (val) {
4918 /* TODO: Long/Short */
4919 send_resp(dut, conn, SIGMA_ERROR,
4920 "ErrorCode,Setting Preamble not supported");
4921 return 0;
4922 }
4923#endif
4924
4925 val = get_param(cmd, "Mode");
4926 if (val) {
4927 if (strcmp(val, "11b") == 0 ||
4928 strcmp(val, "11g") == 0 ||
4929 strcmp(val, "11a") == 0 ||
4930 strcmp(val, "11n") == 0 ||
4931 strcmp(val, "11ng") == 0 ||
4932 strcmp(val, "11nl") == 0 ||
4933 strcmp(val, "11nl(nabg)") == 0 ||
4934 strcmp(val, "AC") == 0 ||
4935 strcmp(val, "11AC") == 0 ||
4936 strcmp(val, "11ac") == 0 ||
4937 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08004938 strcmp(val, "11an") == 0 ||
4939 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004940 /* STA supports all modes by default */
4941 } else {
4942 send_resp(dut, conn, SIGMA_ERROR,
4943 "ErrorCode,Setting Mode not supported");
4944 return 0;
4945 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004946
4947 /* Change the mode only in case of testbed for HE program
4948 * and for 11a and 11g modes only. */
4949 if (dut->program == PROGRAM_HE &&
4950 dut->device_type == STA_testbed) {
4951 int phymode;
4952 char buf[60];
4953
4954 if (strcmp(val, "11a") == 0) {
Amarnath Hullur Subramanyam94dfaf02018-03-02 19:26:57 -08004955 phymode = 1; /* IEEE80211_MODE_11A */
4956 } else if (strcmp(val, "11g") == 0) {
4957 phymode = 3; /* IEEE80211_MODE_11G */
4958 } else if (strcmp(val, "11b") == 0) {
4959 phymode = 2; /* IEEE80211_MODE_11B */
4960 } else if (strcmp(val, "11n") == 0 ||
4961 strcmp(val, "11nl") == 0 ||
4962 strcmp(val, "11nl(nabg)") == 0) {
4963 phymode = 22; /* IEEE80211_MODE_11AGN */
4964 } else if (strcmp(val, "11ng") == 0) {
4965 phymode = 13; /* IEEE80211_MODE_11NG_HT40 */
4966 } else if (strcmp(val, "AC") == 0 ||
4967 strcasecmp(val, "11AC") == 0) {
4968 phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */
4969 } else if (strcmp(val, "11na") == 0 ||
4970 strcasecmp(val, "11an") == 0) {
4971 phymode = 14; /* IEEE80211_MODE_11NA_HT40 */
4972 } else if (strcmp(val, "11ax") == 0) {
4973 phymode = 0; /* IEEE80211_MODE_AUTO */
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004974 } else {
4975 sigma_dut_print(dut, DUT_MSG_DEBUG,
4976 "Ignoring mode change for mode: %s",
4977 val);
4978 phymode = -1;
4979 }
4980 if (phymode != -1) {
4981 snprintf(buf, sizeof(buf),
4982 "iwpriv %s setphymode %d",
4983 intf, phymode);
4984 if (system(buf) != 0) {
4985 sigma_dut_print(dut, DUT_MSG_ERROR,
4986 "iwpriv setting of phymode failed");
4987 }
4988 }
4989 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004990 }
4991
4992 val = get_param(cmd, "wmm");
4993 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004994 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004995 case DRIVER_ATHEROS:
4996 ath_sta_set_wmm(dut, intf, val);
4997 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004998 case DRIVER_WCN:
4999 wcn_sta_set_wmm(dut, intf, val);
5000 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005001 default:
5002 sigma_dut_print(dut, DUT_MSG_DEBUG,
5003 "Setting wmm not supported");
5004 break;
5005 }
5006 }
5007
5008 val = get_param(cmd, "Powersave");
5009 if (val) {
5010 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005011 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305012 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005013 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005014 }
5015
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005016 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005017 "P2P_SET ps 0") < 0)
5018 return -2;
5019 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005020 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5021 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005022 } else if (strcmp(val, "1") == 0 ||
5023 strcasecmp(val, "PSPoll") == 0 ||
5024 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005025 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305026 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005027 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005028 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005029 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005030 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005031 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005032 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005033 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005034 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005035 "P2P_SET ps 99") < 0)
5036 return -2;
5037 } else if (strcmp(val, "2") == 0 ||
5038 strcasecmp(val, "Fast") == 0) {
5039 /* TODO */
5040 send_resp(dut, conn, SIGMA_ERROR,
5041 "ErrorCode,Powersave=Fast not supported");
5042 return 0;
5043 } else if (strcmp(val, "3") == 0 ||
5044 strcasecmp(val, "PSNonPoll") == 0) {
5045 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005046 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5047 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005048
5049 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005050 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005051 "P2P_SET ps 1") < 0)
5052 return -2;
5053 } else
5054 return -1;
5055 }
5056
5057 val = get_param(cmd, "NoAck");
5058 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005059 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005060 case DRIVER_ATHEROS:
5061 ath_sta_set_noack(dut, intf, val);
5062 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005063#ifdef NL80211_SUPPORT
5064 case DRIVER_WCN:
5065 wcn_sta_set_noack(dut, intf, val);
5066 break;
5067#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005068 default:
5069 send_resp(dut, conn, SIGMA_ERROR,
5070 "ErrorCode,Setting NoAck not supported");
5071 return 0;
5072 }
5073 }
5074
5075 val = get_param(cmd, "IgnoreChswitchProhibit");
5076 if (val) {
5077 /* TODO: Enabled/disabled */
5078 if (strcasecmp(val, "Enabled") == 0) {
5079 send_resp(dut, conn, SIGMA_ERROR,
5080 "ErrorCode,Enabling IgnoreChswitchProhibit "
5081 "not supported");
5082 return 0;
5083 }
5084 }
5085
5086 val = get_param(cmd, "TDLS");
5087 if (val) {
5088 if (strcasecmp(val, "Disabled") == 0) {
5089 if (wpa_command(intf, "SET tdls_disabled 1")) {
5090 send_resp(dut, conn, SIGMA_ERROR,
5091 "ErrorCode,Failed to disable TDLS");
5092 return 0;
5093 }
5094 } else if (strcasecmp(val, "Enabled") == 0) {
5095 if (wpa_command(intf, "SET tdls_disabled 0")) {
5096 send_resp(dut, conn, SIGMA_ERROR,
5097 "ErrorCode,Failed to enable TDLS");
5098 return 0;
5099 }
5100 } else {
5101 send_resp(dut, conn, SIGMA_ERROR,
5102 "ErrorCode,Unsupported TDLS value");
5103 return 0;
5104 }
5105 }
5106
5107 val = get_param(cmd, "TDLSmode");
5108 if (val) {
5109 if (strcasecmp(val, "Default") == 0) {
5110 wpa_command(intf, "SET tdls_testing 0");
5111 } else if (strcasecmp(val, "APProhibit") == 0) {
5112 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5113 send_resp(dut, conn, SIGMA_ERROR,
5114 "ErrorCode,Failed to enable ignore "
5115 "APProhibit TDLS mode");
5116 return 0;
5117 }
5118 } else if (strcasecmp(val, "HiLoMac") == 0) {
5119 /* STA should respond with TDLS setup req for a TDLS
5120 * setup req */
5121 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5122 send_resp(dut, conn, SIGMA_ERROR,
5123 "ErrorCode,Failed to enable HiLoMac "
5124 "TDLS mode");
5125 return 0;
5126 }
5127 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5128 /*
5129 * Since all security modes are enabled by default when
5130 * Sigma control is used, there is no need to do
5131 * anything here.
5132 */
5133 } else if (strcasecmp(val, "ExistLink") == 0) {
5134 /*
5135 * Since we allow new TDLS Setup Request even if there
5136 * is an existing link, nothing needs to be done for
5137 * this.
5138 */
5139 } else {
5140 /* TODO:
5141 * ExistLink: STA should send TDLS setup req even if
5142 * direct link already exists
5143 */
5144 send_resp(dut, conn, SIGMA_ERROR,
5145 "ErrorCode,Unsupported TDLSmode value");
5146 return 0;
5147 }
5148 }
5149
5150 val = get_param(cmd, "FakePubKey");
5151 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5152 send_resp(dut, conn, SIGMA_ERROR,
5153 "ErrorCode,Failed to enable FakePubKey");
5154 return 0;
5155 }
5156
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005157#ifdef NL80211_SUPPORT
5158 val = get_param(cmd, "FrgmntSupport");
5159 if (val) {
5160 if (strcasecmp(val, "Enable") == 0) {
5161 if (sta_set_he_fragmentation(dut, intf,
5162 HE_FRAG_LEVEL1)) {
5163 send_resp(dut, conn, SIGMA_ERROR,
5164 "ErrorCode,Failed to enable HE Fragmentation");
5165 return 0;
5166 }
5167 } else if (strcasecmp(val, "Disable") == 0) {
5168 if (sta_set_he_fragmentation(dut, intf,
5169 HE_FRAG_DISABLE)) {
5170 send_resp(dut, conn, SIGMA_ERROR,
5171 "ErrorCode,Failed to disable HE Fragmentation");
5172 return 0;
5173 }
5174 }
5175 }
5176#endif /* NL80211_SUPPORT */
5177
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005178 return 1;
5179}
5180
5181
5182static const char * ath_get_radio_name(const char *radio_name)
5183{
5184 if (radio_name == NULL)
5185 return "wifi0";
5186 if (strcmp(radio_name, "wifi1") == 0)
5187 return "wifi1";
5188 if (strcmp(radio_name, "wifi2") == 0)
5189 return "wifi2";
5190 return "wifi0";
5191}
5192
5193
5194static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5195 const char *val)
5196{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005197 unsigned int vht_mcsmap = 0;
5198 int txchainmask = 0;
5199 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5200
5201 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5202 if (dut->testbed_flag_txsp == 1) {
5203 vht_mcsmap = 0xfffc;
5204 dut->testbed_flag_txsp = 0;
5205 } else {
5206 vht_mcsmap = 0xfffe;
5207 }
5208 txchainmask = 1;
5209 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5210 if (dut->testbed_flag_txsp == 1) {
5211 vht_mcsmap = 0xfff0;
5212 dut->testbed_flag_txsp = 0;
5213 } else {
5214 vht_mcsmap = 0xfffa;
5215 }
5216 txchainmask = 3;
5217 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5218 if (dut->testbed_flag_txsp == 1) {
5219 vht_mcsmap = 0xffc0;
5220 dut->testbed_flag_txsp = 0;
5221 } else {
5222 vht_mcsmap = 0xffea;
5223 }
5224 txchainmask = 7;
5225 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5226 if (dut->testbed_flag_txsp == 1) {
5227 vht_mcsmap = 0xff00;
5228 dut->testbed_flag_txsp = 0;
5229 } else {
5230 vht_mcsmap = 0xffaa;
5231 }
5232 txchainmask = 15;
5233 } else {
5234 if (dut->testbed_flag_txsp == 1) {
5235 vht_mcsmap = 0xffc0;
5236 dut->testbed_flag_txsp = 0;
5237 } else {
5238 vht_mcsmap = 0xffea;
5239 }
5240 }
5241
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005242 if (txchainmask)
5243 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005244
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005245 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005246}
5247
5248
5249static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5250 const char *val)
5251{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005252 unsigned int vht_mcsmap = 0;
5253 int rxchainmask = 0;
5254 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5255
5256 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5257 if (dut->testbed_flag_rxsp == 1) {
5258 vht_mcsmap = 0xfffc;
5259 dut->testbed_flag_rxsp = 0;
5260 } else {
5261 vht_mcsmap = 0xfffe;
5262 }
5263 rxchainmask = 1;
5264 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5265 if (dut->testbed_flag_rxsp == 1) {
5266 vht_mcsmap = 0xfff0;
5267 dut->testbed_flag_rxsp = 0;
5268 } else {
5269 vht_mcsmap = 0xfffa;
5270 }
5271 rxchainmask = 3;
5272 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5273 if (dut->testbed_flag_rxsp == 1) {
5274 vht_mcsmap = 0xffc0;
5275 dut->testbed_flag_rxsp = 0;
5276 } else {
5277 vht_mcsmap = 0xffea;
5278 }
5279 rxchainmask = 7;
5280 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5281 if (dut->testbed_flag_rxsp == 1) {
5282 vht_mcsmap = 0xff00;
5283 dut->testbed_flag_rxsp = 0;
5284 } else {
5285 vht_mcsmap = 0xffaa;
5286 }
5287 rxchainmask = 15;
5288 } else {
5289 if (dut->testbed_flag_rxsp == 1) {
5290 vht_mcsmap = 0xffc0;
5291 dut->testbed_flag_rxsp = 0;
5292 } else {
5293 vht_mcsmap = 0xffea;
5294 }
5295 }
5296
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005297 if (rxchainmask)
5298 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005299
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005300 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005301}
5302
5303
5304void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5305{
5306 if (strcasecmp(val, "enable") == 0) {
5307 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5308 != 0) {
5309 sigma_dut_print(dut, DUT_MSG_ERROR,
5310 "Disable BB_VHTSIGB_CRC_CALC failed");
5311 }
5312
5313 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5314 != 0) {
5315 sigma_dut_print(dut, DUT_MSG_ERROR,
5316 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5317 }
5318 } else {
5319 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5320 != 0) {
5321 sigma_dut_print(dut, DUT_MSG_ERROR,
5322 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5323 }
5324
5325 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5326 != 0) {
5327 sigma_dut_print(dut, DUT_MSG_ERROR,
5328 "Enable BB_VHTSIGB_CRC_CALC failed");
5329 }
5330 }
5331}
5332
5333
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005334static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5335 const char *val)
5336{
5337 char buf[60];
5338
5339 if (strcmp(val, "20") == 0) {
5340 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5341 dut->chwidth = 0;
5342 } else if (strcmp(val, "40") == 0) {
5343 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5344 dut->chwidth = 1;
5345 } else if (strcmp(val, "80") == 0) {
5346 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5347 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305348 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005349 buf[0] = '\0';
5350 } else {
5351 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5352 val);
5353 return -1;
5354 }
5355
5356 if (buf[0] != '\0' && system(buf) != 0) {
5357 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5358 return -1;
5359 }
5360
5361 return 0;
5362}
5363
5364
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005365static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5366 const char *intf, int addbareject)
5367{
5368#ifdef NL80211_SUPPORT
5369 struct nl_msg *msg;
5370 int ret = 0;
5371 struct nlattr *params;
5372 int ifindex;
5373
5374 ifindex = if_nametoindex(intf);
5375 if (ifindex == 0) {
5376 sigma_dut_print(dut, DUT_MSG_ERROR,
5377 "%s: Index for interface %s failed",
5378 __func__, intf);
5379 return -1;
5380 }
5381
5382 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5383 NL80211_CMD_VENDOR)) ||
5384 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5385 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5386 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5387 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5388 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5389 nla_put_u8(msg,
5390 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5391 !addbareject)) {
5392 sigma_dut_print(dut, DUT_MSG_ERROR,
5393 "%s: err in adding vendor_cmd and vendor_data",
5394 __func__);
5395 nlmsg_free(msg);
5396 return -1;
5397 }
5398 nla_nest_end(msg, params);
5399
5400 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5401 if (ret) {
5402 sigma_dut_print(dut, DUT_MSG_ERROR,
5403 "%s: err in send_and_recv_msgs, ret=%d",
5404 __func__, ret);
5405 }
5406 return ret;
5407#else /* NL80211_SUPPORT */
5408 sigma_dut_print(dut, DUT_MSG_ERROR,
5409 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5410 return -1;
5411#endif /* NL80211_SUPPORT */
5412}
5413
5414
5415static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5416 int addbareject)
5417{
5418 int ret;
5419
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005420 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005421 case DRIVER_WCN:
5422 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5423 if (ret) {
5424 sigma_dut_print(dut, DUT_MSG_ERROR,
5425 "nlvendor_sta_set_addba_reject failed, ret:%d",
5426 ret);
5427 return ret;
5428 }
5429 break;
5430 default:
5431 sigma_dut_print(dut, DUT_MSG_ERROR,
5432 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5433 ret = -1;
5434 break;
5435 }
5436
5437 return ret;
5438}
5439
5440
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005441static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5442 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005443{
5444#ifdef NL80211_SUPPORT
5445 struct nl_msg *msg;
5446 int ret = 0;
5447 struct nlattr *params;
5448 int ifindex;
5449
5450 ifindex = if_nametoindex(intf);
5451 if (ifindex == 0) {
5452 sigma_dut_print(dut, DUT_MSG_ERROR,
5453 "%s: Index for interface %s failed",
5454 __func__, intf);
5455 return -1;
5456 }
5457
5458 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5459 NL80211_CMD_VENDOR)) ||
5460 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5461 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5462 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5463 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5464 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5465 nla_put_u8(msg,
5466 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005467 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005468 sigma_dut_print(dut, DUT_MSG_ERROR,
5469 "%s: err in adding vendor_cmd and vendor_data",
5470 __func__);
5471 nlmsg_free(msg);
5472 return -1;
5473 }
5474 nla_nest_end(msg, params);
5475
5476 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5477 if (ret) {
5478 sigma_dut_print(dut, DUT_MSG_ERROR,
5479 "%s: err in send_and_recv_msgs, ret=%d",
5480 __func__, ret);
5481 }
5482 return ret;
5483#else /* NL80211_SUPPORT */
5484 sigma_dut_print(dut, DUT_MSG_ERROR,
5485 "Disable addba not possible without NL80211_SUPPORT defined");
5486 return -1;
5487#endif /* NL80211_SUPPORT */
5488}
5489
5490
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305491#ifdef NL80211_SUPPORT
5492static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5493{
5494 struct nl_msg *msg;
5495 int ret = 0;
5496 int ifindex;
5497
5498 ifindex = if_nametoindex(intf);
5499 if (ifindex == 0) {
5500 sigma_dut_print(dut, DUT_MSG_ERROR,
5501 "%s: Index for interface %s failed",
5502 __func__, intf);
5503 return -1;
5504 }
5505
5506 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5507 NL80211_CMD_SET_WIPHY)) ||
5508 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5509 sigma_dut_print(dut, DUT_MSG_ERROR,
5510 "%s: err in adding RTS threshold",
5511 __func__);
5512 nlmsg_free(msg);
5513 return -1;
5514 }
5515
5516 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5517 if (ret) {
5518 sigma_dut_print(dut, DUT_MSG_ERROR,
5519 "%s: err in send_and_recv_msgs, ret=%d",
5520 __func__, ret);
5521 }
5522 return ret;
5523}
5524#endif /* NL80211_SUPPORT */
5525
5526
5527static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5528{
5529 char buf[100];
5530
5531#ifdef NL80211_SUPPORT
5532 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5533 return 0;
5534 sigma_dut_print(dut, DUT_MSG_DEBUG,
5535 "Fall back to using iwconfig for setting RTS threshold");
5536#endif /* NL80211_SUPPORT */
5537
5538 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5539 if (system(buf) != 0) {
5540 sigma_dut_print(dut, DUT_MSG_ERROR,
5541 "Failed to set RTS threshold %d", val);
5542 return -1;
5543 }
5544 return 0;
5545}
5546
5547
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005548static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5549 struct sigma_conn *conn,
5550 struct sigma_cmd *cmd)
5551{
5552 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005553 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005554 char buf[128];
5555 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005556
5557 val = get_param(cmd, "40_INTOLERANT");
5558 if (val) {
5559 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5560 /* TODO: iwpriv ht40intol through wpa_supplicant */
5561 send_resp(dut, conn, SIGMA_ERROR,
5562 "ErrorCode,40_INTOLERANT not supported");
5563 return 0;
5564 }
5565 }
5566
5567 val = get_param(cmd, "ADDBA_REJECT");
5568 if (val) {
5569 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5570 /* reject any ADDBA with status "decline" */
5571 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005572 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005573 } else {
5574 /* accept ADDBA */
5575 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005576 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005577 }
5578 }
5579
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005580 if (addbareject >= 0 &&
5581 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5582 send_resp(dut, conn, SIGMA_ERROR,
5583 "ErrorCode,set addba_reject failed");
5584 return 0;
5585 }
5586
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005587 val = get_param(cmd, "AMPDU");
5588 if (val) {
5589 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5590 /* enable AMPDU Aggregation */
5591 if (ampdu == 0) {
5592 send_resp(dut, conn, SIGMA_ERROR,
5593 "ErrorCode,Mismatch in "
5594 "addba_reject/ampdu - "
5595 "not supported");
5596 return 0;
5597 }
5598 ampdu = 1;
5599 } else {
5600 /* disable AMPDU Aggregation */
5601 if (ampdu == 1) {
5602 send_resp(dut, conn, SIGMA_ERROR,
5603 "ErrorCode,Mismatch in "
5604 "addba_reject/ampdu - "
5605 "not supported");
5606 return 0;
5607 }
5608 ampdu = 0;
5609 }
5610 }
5611
5612 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005613 int ret;
5614
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005615 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5616 ampdu ? "Enabling" : "Disabling");
5617 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005618 if (wpa_command(intf, buf) < 0 &&
5619 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005620 send_resp(dut, conn, SIGMA_ERROR,
5621 "ErrorCode,set aggr failed");
5622 return 0;
5623 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005624
5625 if (ampdu == 0) {
5626 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005627 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005628 if (ret) {
5629 sigma_dut_print(dut, DUT_MSG_ERROR,
5630 "Failed to disable addba, ret:%d",
5631 ret);
5632 }
5633 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005634 }
5635
5636 val = get_param(cmd, "AMSDU");
5637 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005638 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005639 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005640 case DRIVER_WCN:
5641 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005642 break;
5643 default:
5644 if (strcmp(val, "1") == 0 ||
5645 strcasecmp(val, "Enable") == 0) {
5646 /* Enable AMSDU Aggregation */
5647 send_resp(dut, conn, SIGMA_ERROR,
5648 "ErrorCode,AMSDU aggregation not supported");
5649 return 0;
5650 }
5651 break;
5652 }
5653 }
5654
5655 val = get_param(cmd, "STBC_RX");
5656 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005657 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005658 case DRIVER_ATHEROS:
5659 ath_sta_set_stbc(dut, intf, val);
5660 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305661 case DRIVER_WCN:
5662 wcn_sta_set_stbc(dut, intf, val);
5663 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005664 default:
5665 send_resp(dut, conn, SIGMA_ERROR,
5666 "ErrorCode,STBC_RX not supported");
5667 return 0;
5668 }
5669 }
5670
5671 val = get_param(cmd, "WIDTH");
5672 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005673 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005674 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005675 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005676 send_resp(dut, conn, SIGMA_ERROR,
5677 "ErrorCode,Failed to set WIDTH");
5678 return 0;
5679 }
5680 break;
5681 case DRIVER_ATHEROS:
5682 if (ath_set_width(dut, conn, intf, val) < 0)
5683 return 0;
5684 break;
5685 default:
5686 sigma_dut_print(dut, DUT_MSG_ERROR,
5687 "Setting WIDTH not supported");
5688 break;
5689 }
5690 }
5691
5692 val = get_param(cmd, "SMPS");
5693 if (val) {
5694 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5695 send_resp(dut, conn, SIGMA_ERROR,
5696 "ErrorCode,SMPS not supported");
5697 return 0;
5698 }
5699
5700 val = get_param(cmd, "TXSP_STREAM");
5701 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005702 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005703 case DRIVER_WCN:
5704 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5705 send_resp(dut, conn, SIGMA_ERROR,
5706 "ErrorCode,Failed to set TXSP_STREAM");
5707 return 0;
5708 }
5709 break;
5710 case DRIVER_ATHEROS:
5711 ath_sta_set_txsp_stream(dut, intf, val);
5712 break;
5713 default:
5714 sigma_dut_print(dut, DUT_MSG_ERROR,
5715 "Setting TXSP_STREAM not supported");
5716 break;
5717 }
5718 }
5719
5720 val = get_param(cmd, "RXSP_STREAM");
5721 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005722 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005723 case DRIVER_WCN:
5724 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5725 send_resp(dut, conn, SIGMA_ERROR,
5726 "ErrorCode,Failed to set RXSP_STREAM");
5727 return 0;
5728 }
5729 break;
5730 case DRIVER_ATHEROS:
5731 ath_sta_set_rxsp_stream(dut, intf, val);
5732 break;
5733 default:
5734 sigma_dut_print(dut, DUT_MSG_ERROR,
5735 "Setting RXSP_STREAM not supported");
5736 break;
5737 }
5738 }
5739
5740 val = get_param(cmd, "DYN_BW_SGNL");
5741 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005742 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005743 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08005744 if (strcasecmp(val, "enable") == 0) {
5745 snprintf(buf, sizeof(buf),
5746 "iwpriv %s cwmenable 1", intf);
5747 if (system(buf) != 0) {
5748 sigma_dut_print(dut, DUT_MSG_ERROR,
5749 "iwpriv cwmenable 1 failed");
5750 return 0;
5751 }
5752 } else if (strcasecmp(val, "disable") == 0) {
5753 snprintf(buf, sizeof(buf),
5754 "iwpriv %s cwmenable 0", intf);
5755 if (system(buf) != 0) {
5756 sigma_dut_print(dut, DUT_MSG_ERROR,
5757 "iwpriv cwmenable 0 failed");
5758 return 0;
5759 }
5760 } else {
5761 sigma_dut_print(dut, DUT_MSG_ERROR,
5762 "Unsupported DYN_BW_SGL");
5763 }
5764
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005765 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5766 if (system(buf) != 0) {
5767 sigma_dut_print(dut, DUT_MSG_ERROR,
5768 "Failed to set cts_cbw in DYN_BW_SGNL");
5769 return 0;
5770 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005771 break;
5772 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005773 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005774 ath_config_dyn_bw_sig(dut, intf, val);
5775 break;
5776 default:
5777 sigma_dut_print(dut, DUT_MSG_ERROR,
5778 "Failed to set DYN_BW_SGNL");
5779 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005780 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005781 }
5782
5783 val = get_param(cmd, "RTS_FORCE");
5784 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005785 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005786 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305787 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005788 sigma_dut_print(dut, DUT_MSG_ERROR,
5789 "Failed to set RTS_FORCE 64");
5790 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03005791 res = snprintf(buf, sizeof(buf),
5792 "wifitool %s beeliner_fw_test 100 1",
5793 intf);
5794 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08005795 sigma_dut_print(dut, DUT_MSG_ERROR,
5796 "wifitool beeliner_fw_test 100 1 failed");
5797 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005798 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305799 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005800 sigma_dut_print(dut, DUT_MSG_ERROR,
5801 "Failed to set RTS_FORCE 2347");
5802 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005803 } else {
5804 send_resp(dut, conn, SIGMA_ERROR,
5805 "ErrorCode,RTS_FORCE value not supported");
5806 return 0;
5807 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005808 }
5809
5810 val = get_param(cmd, "CTS_WIDTH");
5811 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005812 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005813 case DRIVER_WCN:
5814 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
5815 send_resp(dut, conn, SIGMA_ERROR,
5816 "ErrorCode,Failed to set CTS_WIDTH");
5817 return 0;
5818 }
5819 break;
5820 case DRIVER_ATHEROS:
5821 ath_set_cts_width(dut, intf, val);
5822 break;
5823 default:
5824 sigma_dut_print(dut, DUT_MSG_ERROR,
5825 "Setting CTS_WIDTH not supported");
5826 break;
5827 }
5828 }
5829
5830 val = get_param(cmd, "BW_SGNL");
5831 if (val) {
5832 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005833 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005834 } else if (strcasecmp(val, "Disable") == 0) {
5835 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005836 } else {
5837 send_resp(dut, conn, SIGMA_ERROR,
5838 "ErrorCode,BW_SGNL value not supported");
5839 return 0;
5840 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005841 }
5842
5843 val = get_param(cmd, "Band");
5844 if (val) {
5845 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
5846 /* STA supports all bands by default */
5847 } else {
5848 send_resp(dut, conn, SIGMA_ERROR,
5849 "ErrorCode,Unsupported Band");
5850 return 0;
5851 }
5852 }
5853
5854 val = get_param(cmd, "zero_crc");
5855 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005856 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005857 case DRIVER_ATHEROS:
5858 ath_set_zero_crc(dut, val);
5859 break;
5860 default:
5861 break;
5862 }
5863 }
5864
5865 return 1;
5866}
5867
5868
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005869static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
5870{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005871 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005872#ifdef __linux__
5873 case DRIVER_WIL6210:
5874 return wil6210_set_force_mcs(dut, force, mcs);
5875#endif /* __linux__ */
5876 default:
5877 sigma_dut_print(dut, DUT_MSG_ERROR,
5878 "Unsupported sta_set_force_mcs with the current driver");
5879 return -1;
5880 }
5881}
5882
5883
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005884static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
5885{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005886 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005887#ifdef __linux__
5888 case DRIVER_WIL6210:
5889 return wil6210_force_rsn_ie(dut, state);
5890#endif /* __linux__ */
5891 default:
5892 sigma_dut_print(dut, DUT_MSG_ERROR,
5893 "Unsupported sta_60g_force_rsn_ie with the current driver");
5894 return -1;
5895 }
5896}
5897
5898
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005899static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
5900 struct sigma_cmd *cmd)
5901{
5902 const char *val;
5903 char buf[100];
5904
5905 val = get_param(cmd, "MSDUSize");
5906 if (val) {
5907 int mtu;
5908
5909 dut->amsdu_size = atoi(val);
5910 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
5911 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
5912 sigma_dut_print(dut, DUT_MSG_ERROR,
5913 "MSDUSize %d is above max %d or below min %d",
5914 dut->amsdu_size,
5915 IEEE80211_MAX_DATA_LEN_DMG,
5916 IEEE80211_SNAP_LEN_DMG);
5917 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005918 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005919 }
5920
5921 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
5922 sigma_dut_print(dut, DUT_MSG_DEBUG,
5923 "Setting amsdu_size to %d", mtu);
5924 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005925 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005926
5927 if (system(buf) != 0) {
5928 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
5929 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005930 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005931 }
5932 }
5933
5934 val = get_param(cmd, "BAckRcvBuf");
5935 if (val) {
5936 dut->back_rcv_buf = atoi(val);
5937 if (dut->back_rcv_buf == 0) {
5938 sigma_dut_print(dut, DUT_MSG_ERROR,
5939 "Failed to convert %s or value is 0",
5940 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005941 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005942 }
5943
5944 sigma_dut_print(dut, DUT_MSG_DEBUG,
5945 "Setting BAckRcvBuf to %s", val);
5946 }
5947
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005948 val = get_param(cmd, "MCS_FixedRate");
5949 if (val) {
5950 if (sta_set_force_mcs(dut, 1, atoi(val))) {
5951 sigma_dut_print(dut, DUT_MSG_ERROR,
5952 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005953 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005954 }
5955 }
5956
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005957 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005958}
5959
5960
5961static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
5962 struct sigma_cmd *cmd)
5963{
5964 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005965 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005966 const char *val;
5967 char buf[100];
5968
5969 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005970 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005971 if (wpa_command(ifname, "PING") != 0) {
5972 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005973 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005974 }
5975
5976 wpa_command(ifname, "FLUSH");
5977 net_id = add_network_common(dut, conn, ifname, cmd);
5978 if (net_id < 0) {
5979 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
5980 return net_id;
5981 }
5982
5983 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
5984 if (set_network(ifname, net_id, "mode", "2") < 0) {
5985 sigma_dut_print(dut, DUT_MSG_ERROR,
5986 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005987 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005988 }
5989
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02005990 if (set_network(ifname, net_id, "pbss", "1") < 0)
5991 return -2;
5992
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005993 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02005994 "Supplicant set network with mode 2. network_id %d",
5995 net_id);
5996
5997 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
5998 sigma_dut_print(dut, DUT_MSG_INFO,
5999 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006000 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006001 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006002
6003 val = get_param(cmd, "Security");
6004 if (val && strcasecmp(val, "OPEN") == 0) {
6005 dut->ap_key_mgmt = AP_OPEN;
6006 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6007 sigma_dut_print(dut, DUT_MSG_ERROR,
6008 "Failed to set supplicant to %s security",
6009 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006010 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006011 }
6012 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6013 dut->ap_key_mgmt = AP_WPA2_PSK;
6014 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6015 sigma_dut_print(dut, DUT_MSG_ERROR,
6016 "Failed to set supplicant to %s security",
6017 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006018 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006019 }
6020
6021 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6022 sigma_dut_print(dut, DUT_MSG_ERROR,
6023 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006024 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006025 }
6026 } else if (val) {
6027 sigma_dut_print(dut, DUT_MSG_ERROR,
6028 "Requested Security %s is not supported on 60GHz",
6029 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006030 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006031 }
6032
6033 val = get_param(cmd, "Encrypt");
6034 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6035 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6036 sigma_dut_print(dut, DUT_MSG_ERROR,
6037 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006038 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006039 }
6040 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6041 sigma_dut_print(dut, DUT_MSG_ERROR,
6042 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006043 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006044 }
6045 } else if (val) {
6046 sigma_dut_print(dut, DUT_MSG_ERROR,
6047 "Requested Encrypt %s is not supported on 60 GHz",
6048 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006049 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006050 }
6051
6052 val = get_param(cmd, "PSK");
6053 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6054 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6055 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006056 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006057 }
6058
6059 /* Convert 60G channel to freq */
6060 switch (dut->ap_channel) {
6061 case 1:
6062 val = "58320";
6063 break;
6064 case 2:
6065 val = "60480";
6066 break;
6067 case 3:
6068 val = "62640";
6069 break;
6070 default:
6071 sigma_dut_print(dut, DUT_MSG_ERROR,
6072 "Failed to configure channel %d. Not supported",
6073 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006074 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006075 }
6076
6077 if (set_network(ifname, net_id, "frequency", val) < 0) {
6078 sigma_dut_print(dut, DUT_MSG_ERROR,
6079 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006080 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006081 }
6082
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006083 if (dut->eap_fragment) {
6084 sigma_dut_print(dut, DUT_MSG_DEBUG,
6085 "Set EAP fragment size to 128 bytes.");
6086 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6087 return ERROR_SEND_STATUS;
6088 }
6089
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006090 sigma_dut_print(dut, DUT_MSG_DEBUG,
6091 "Supplicant set network with frequency");
6092
6093 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6094 if (wpa_command(ifname, buf) < 0) {
6095 sigma_dut_print(dut, DUT_MSG_INFO,
6096 "Failed to select network id %d on %s",
6097 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006098 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006099 }
6100
6101 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6102
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006103 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006104}
6105
6106
Lior David67543f52017-01-03 19:04:22 +02006107static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6108{
6109 char buf[128], fname[128];
6110 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006111 int res;
Lior David67543f52017-01-03 19:04:22 +02006112
6113 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6114 sigma_dut_print(dut, DUT_MSG_ERROR,
6115 "failed to get wil6210 debugfs dir");
6116 return -1;
6117 }
6118
Jouni Malinen3aa72862019-05-29 23:14:51 +03006119 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6120 if (res < 0 || res >= sizeof(fname))
6121 return -1;
Lior David67543f52017-01-03 19:04:22 +02006122 f = fopen(fname, "w");
6123 if (!f) {
6124 sigma_dut_print(dut, DUT_MSG_ERROR,
6125 "failed to open: %s", fname);
6126 return -1;
6127 }
6128
6129 fprintf(f, "%d\n", abft_len);
6130 fclose(f);
6131
6132 return 0;
6133}
6134
6135
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006136int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6137 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006138{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006139 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006140 case DRIVER_WIL6210:
6141 return wil6210_set_abft_len(dut, abft_len);
6142 default:
6143 sigma_dut_print(dut, DUT_MSG_ERROR,
6144 "set abft_len not supported");
6145 return -1;
6146 }
6147}
6148
6149
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006150static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6151 struct sigma_cmd *cmd)
6152{
6153 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006154 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006155
6156 if (dut->dev_role != DEVROLE_PCP) {
6157 send_resp(dut, conn, SIGMA_INVALID,
6158 "ErrorCode,Invalid DevRole");
6159 return 0;
6160 }
6161
6162 val = get_param(cmd, "SSID");
6163 if (val) {
6164 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6165 send_resp(dut, conn, SIGMA_INVALID,
6166 "ErrorCode,Invalid SSID");
6167 return -1;
6168 }
6169
Peng Xub8fc5cc2017-05-10 17:27:28 -07006170 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006171 }
6172
6173 val = get_param(cmd, "CHANNEL");
6174 if (val) {
6175 const char *pos;
6176
6177 dut->ap_channel = atoi(val);
6178 pos = strchr(val, ';');
6179 if (pos) {
6180 pos++;
6181 dut->ap_channel_1 = atoi(pos);
6182 }
6183 }
6184
6185 switch (dut->ap_channel) {
6186 case 1:
6187 case 2:
6188 case 3:
6189 break;
6190 default:
6191 sigma_dut_print(dut, DUT_MSG_ERROR,
6192 "Channel %d is not supported", dut->ap_channel);
6193 send_resp(dut, conn, SIGMA_ERROR,
6194 "Requested channel is not supported");
6195 return -1;
6196 }
6197
6198 val = get_param(cmd, "BCNINT");
6199 if (val)
6200 dut->ap_bcnint = atoi(val);
6201
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006202 val = get_param(cmd, "AllocType");
6203 if (val) {
6204 send_resp(dut, conn, SIGMA_ERROR,
6205 "ErrorCode,AllocType is not supported yet");
6206 return -1;
6207 }
6208
6209 val = get_param(cmd, "PercentBI");
6210 if (val) {
6211 send_resp(dut, conn, SIGMA_ERROR,
6212 "ErrorCode,PercentBI is not supported yet");
6213 return -1;
6214 }
6215
6216 val = get_param(cmd, "CBAPOnly");
6217 if (val) {
6218 send_resp(dut, conn, SIGMA_ERROR,
6219 "ErrorCode,CBAPOnly is not supported yet");
6220 return -1;
6221 }
6222
6223 val = get_param(cmd, "AMPDU");
6224 if (val) {
6225 if (strcasecmp(val, "Enable") == 0)
6226 dut->ap_ampdu = 1;
6227 else if (strcasecmp(val, "Disable") == 0)
6228 dut->ap_ampdu = 2;
6229 else {
6230 send_resp(dut, conn, SIGMA_ERROR,
6231 "ErrorCode,AMPDU value is not Enable nor Disabled");
6232 return -1;
6233 }
6234 }
6235
6236 val = get_param(cmd, "AMSDU");
6237 if (val) {
6238 if (strcasecmp(val, "Enable") == 0)
6239 dut->ap_amsdu = 1;
6240 else if (strcasecmp(val, "Disable") == 0)
6241 dut->ap_amsdu = 2;
6242 }
6243
6244 val = get_param(cmd, "NumMSDU");
6245 if (val) {
6246 send_resp(dut, conn, SIGMA_ERROR,
6247 "ErrorCode, NumMSDU is not supported yet");
6248 return -1;
6249 }
6250
6251 val = get_param(cmd, "ABFTLRang");
6252 if (val) {
6253 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006254 "ABFTLRang parameter %s", val);
6255 if (strcmp(val, "Gt1") == 0)
6256 abft_len = 2; /* 2 slots in this case */
6257 }
6258
6259 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6260 send_resp(dut, conn, SIGMA_ERROR,
6261 "ErrorCode, Can't set ABFT length");
6262 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006263 }
6264
6265 if (sta_pcp_start(dut, conn, cmd) < 0) {
6266 send_resp(dut, conn, SIGMA_ERROR,
6267 "ErrorCode, Can't start PCP role");
6268 return -1;
6269 }
6270
6271 return sta_set_60g_common(dut, conn, cmd);
6272}
6273
6274
6275static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6276 struct sigma_cmd *cmd)
6277{
6278 const char *val = get_param(cmd, "DiscoveryMode");
6279
6280 if (dut->dev_role != DEVROLE_STA) {
6281 send_resp(dut, conn, SIGMA_INVALID,
6282 "ErrorCode,Invalid DevRole");
6283 return 0;
6284 }
6285
6286 if (val) {
6287 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6288 /* Ignore Discovery mode till Driver expose API. */
6289#if 0
6290 if (strcasecmp(val, "1") == 0) {
6291 send_resp(dut, conn, SIGMA_INVALID,
6292 "ErrorCode,DiscoveryMode 1 not supported");
6293 return 0;
6294 }
6295
6296 if (strcasecmp(val, "0") == 0) {
6297 /* OK */
6298 } else {
6299 send_resp(dut, conn, SIGMA_INVALID,
6300 "ErrorCode,DiscoveryMode not supported");
6301 return 0;
6302 }
6303#endif
6304 }
6305
6306 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006307 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006308 return sta_set_60g_common(dut, conn, cmd);
6309}
6310
6311
Jouni Malinenf7222712019-06-13 01:50:21 +03006312static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6313 struct sigma_conn *conn,
6314 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006315{
6316 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006317 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306318
Jouni Malinened77e672018-01-10 16:45:13 +02006319 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006320 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006321 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306322 wpa_command(intf, "DISCONNECT");
6323 return 1;
6324 }
6325
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006326 disconnect_station(dut);
6327 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6328 * due to cached results. */
6329 wpa_command(intf, "SET ignore_old_scan_res 1");
6330 wpa_command(intf, "BSS_FLUSH");
6331 return 1;
6332}
6333
6334
Jouni Malinenf7222712019-06-13 01:50:21 +03006335static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6336 struct sigma_conn *conn,
6337 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006338{
6339 const char *intf = get_param(cmd, "Interface");
6340 const char *bssid = get_param(cmd, "bssid");
6341 const char *val = get_param(cmd, "CHANNEL");
6342 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306343 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306344 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006345 int res;
6346 int chan = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006347 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306348 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006349 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006350
6351 if (bssid == NULL) {
6352 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6353 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006354 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006355 }
6356
6357 if (val)
6358 chan = atoi(val);
6359
6360 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6361 /* The current network may be from sta_associate or
6362 * sta_hs2_associate
6363 */
6364 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6365 0 ||
6366 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006367 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006368 }
6369
6370 ctrl = open_wpa_mon(intf);
6371 if (ctrl == NULL) {
6372 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6373 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006374 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006375 }
6376
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006377 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05306378 sizeof(result)) < 0 ||
6379 strncmp(result, "COMPLETED", 9) != 0) {
6380 sigma_dut_print(dut, DUT_MSG_DEBUG,
6381 "sta_reassoc: Not connected");
6382 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006383 } else if (dut->sta_ft_ds) {
6384 sigma_dut_print(dut, DUT_MSG_DEBUG,
6385 "sta_reassoc: Use FT-over-DS");
6386 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306387 }
6388
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306389 if (dut->rsne_override) {
6390#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006391 if (get_driver_type(dut) == DRIVER_WCN &&
6392 dut->config_rsnie == 0) {
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306393 sta_config_rsnie(dut, 1);
6394 dut->config_rsnie = 1;
6395 }
6396#endif /* NL80211_SUPPORT */
6397 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6398 dut->rsne_override);
6399 if (wpa_command(intf, buf) < 0) {
6400 send_resp(dut, conn, SIGMA_ERROR,
6401 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6402 return 0;
6403 }
6404 }
6405
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006406 if (ft_ds) {
6407 if (chan) {
6408 unsigned int freq;
6409
6410 freq = channel_to_freq(dut, chan);
6411 if (!freq) {
6412 sigma_dut_print(dut, DUT_MSG_ERROR,
6413 "Invalid channel number provided: %d",
6414 chan);
6415 send_resp(dut, conn, SIGMA_INVALID,
6416 "ErrorCode,Invalid channel number");
6417 goto close_mon_conn;
6418 }
6419 res = snprintf(buf, sizeof(buf),
6420 "SCAN TYPE=ONLY freq=%d", freq);
6421 } else {
6422 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6423 }
6424 if (res < 0 || res >= (int) sizeof(buf)) {
6425 send_resp(dut, conn, SIGMA_ERROR,
6426 "ErrorCode,snprintf failed");
6427 goto close_mon_conn;
6428 }
6429 if (wpa_command(intf, buf) < 0) {
6430 sigma_dut_print(dut, DUT_MSG_INFO,
6431 "Failed to start scan");
6432 send_resp(dut, conn, SIGMA_ERROR,
6433 "ErrorCode,scan failed");
6434 goto close_mon_conn;
6435 }
6436
6437 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6438 buf, sizeof(buf));
6439 if (res < 0) {
6440 sigma_dut_print(dut, DUT_MSG_INFO,
6441 "Scan did not complete");
6442 send_resp(dut, conn, SIGMA_ERROR,
6443 "ErrorCode,scan did not complete");
6444 goto close_mon_conn;
6445 }
6446
6447 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6448 if (res > 0 && res < (int) sizeof(buf))
6449 res = wpa_command(intf, buf);
6450
6451 if (res < 0 || res >= (int) sizeof(buf)) {
6452 send_resp(dut, conn, SIGMA_ERROR,
6453 "errorCode,FT_DS command failed");
6454 status = STATUS_SENT_ERROR;
6455 goto close_mon_conn;
6456 }
6457 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306458 if (chan) {
6459 unsigned int freq;
6460
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02006461 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306462 if (!freq) {
6463 sigma_dut_print(dut, DUT_MSG_ERROR,
6464 "Invalid channel number provided: %d",
6465 chan);
6466 send_resp(dut, conn, SIGMA_INVALID,
6467 "ErrorCode,Invalid channel number");
6468 goto close_mon_conn;
6469 }
6470 res = snprintf(buf, sizeof(buf),
6471 "SCAN TYPE=ONLY freq=%d", freq);
6472 } else {
6473 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6474 }
6475 if (res < 0 || res >= (int) sizeof(buf)) {
6476 send_resp(dut, conn, SIGMA_ERROR,
6477 "ErrorCode,snprintf failed");
6478 goto close_mon_conn;
6479 }
6480 if (wpa_command(intf, buf) < 0) {
6481 sigma_dut_print(dut, DUT_MSG_INFO,
6482 "Failed to start scan");
6483 send_resp(dut, conn, SIGMA_ERROR,
6484 "ErrorCode,scan failed");
6485 goto close_mon_conn;
6486 }
6487
6488 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6489 buf, sizeof(buf));
6490 if (res < 0) {
6491 sigma_dut_print(dut, DUT_MSG_INFO,
6492 "Scan did not complete");
6493 send_resp(dut, conn, SIGMA_ERROR,
6494 "ErrorCode,scan did not complete");
6495 goto close_mon_conn;
6496 }
6497
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006498 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6499 < 0) {
6500 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6501 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006502 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306503 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006504 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306505 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006506 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306507 if (res < 0 || res >= (int) sizeof(buf) ||
6508 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006509 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306510 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306511 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006512 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006513 sigma_dut_print(dut, DUT_MSG_INFO,
6514 "sta_reassoc: Run %s successful", buf);
6515 } else if (wpa_command(intf, "REASSOCIATE")) {
6516 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6517 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306518 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006519 }
6520
6521 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6522 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306523 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006524 send_resp(dut, conn, SIGMA_ERROR,
6525 "errorCode,Connection did not complete");
6526 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306527 goto close_mon_conn;
6528 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006529 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006530
Ashwini Patil467efef2017-05-25 12:18:27 +05306531close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006532 wpa_ctrl_detach(ctrl);
6533 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306534 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006535}
6536
6537
6538static void hs2_clear_credentials(const char *intf)
6539{
6540 wpa_command(intf, "REMOVE_CRED all");
6541}
6542
6543
Lior Davidcc88b562017-01-03 18:52:09 +02006544#ifdef __linux__
6545static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6546 unsigned int *aid)
6547{
Lior David0fe101e2017-03-09 16:09:50 +02006548 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006549
Lior David0fe101e2017-03-09 16:09:50 +02006550 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006551}
6552#endif /* __linux__ */
6553
6554
6555static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6556 unsigned int *aid)
6557{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006558 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02006559#ifdef __linux__
6560 case DRIVER_WIL6210:
6561 return wil6210_get_aid(dut, bssid, aid);
6562#endif /* __linux__ */
6563 default:
6564 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6565 return -1;
6566 }
6567}
6568
6569
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006570static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6571 struct sigma_cmd *cmd)
6572{
6573 char buf[MAX_CMD_LEN];
6574 char bss_list[MAX_CMD_LEN];
6575 const char *parameter = get_param(cmd, "Parameter");
6576
6577 if (parameter == NULL)
6578 return -1;
6579
Lior Davidcc88b562017-01-03 18:52:09 +02006580 if (strcasecmp(parameter, "AID") == 0) {
6581 unsigned int aid = 0;
6582 char bssid[20];
6583
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006584 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02006585 bssid, sizeof(bssid)) < 0) {
6586 sigma_dut_print(dut, DUT_MSG_ERROR,
6587 "could not get bssid");
6588 return -2;
6589 }
6590
6591 if (sta_get_aid_60g(dut, bssid, &aid))
6592 return -2;
6593
6594 snprintf(buf, sizeof(buf), "aid,%d", aid);
6595 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6596 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6597 return 0;
6598 }
6599
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006600 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6601 char *bss_line;
6602 char *bss_id = NULL;
6603 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306604 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006605
6606 if (ifname == NULL) {
6607 sigma_dut_print(dut, DUT_MSG_INFO,
6608 "For get DiscoveredDevList need Interface name.");
6609 return -1;
6610 }
6611
6612 /*
6613 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6614 * of BSSIDs in "bssid=<BSSID>\n"
6615 */
6616 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6617 bss_list,
6618 sizeof(bss_list)) < 0) {
6619 sigma_dut_print(dut, DUT_MSG_ERROR,
6620 "Failed to get bss list");
6621 return -1;
6622 }
6623
6624 sigma_dut_print(dut, DUT_MSG_DEBUG,
6625 "bss list for ifname:%s is:%s",
6626 ifname, bss_list);
6627
6628 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306629 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006630 while (bss_line) {
6631 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6632 bss_id) {
6633 int len;
6634
6635 len = snprintf(buf + strlen(buf),
6636 sizeof(buf) - strlen(buf),
6637 ",%s", bss_id);
6638 free(bss_id);
6639 bss_id = NULL;
6640 if (len < 0) {
6641 sigma_dut_print(dut,
6642 DUT_MSG_ERROR,
6643 "Failed to read BSSID");
6644 send_resp(dut, conn, SIGMA_ERROR,
6645 "ErrorCode,Failed to read BSS ID");
6646 return 0;
6647 }
6648
6649 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6650 sigma_dut_print(dut,
6651 DUT_MSG_ERROR,
6652 "Response buf too small for list");
6653 send_resp(dut, conn,
6654 SIGMA_ERROR,
6655 "ErrorCode,Response buf too small for list");
6656 return 0;
6657 }
6658 }
6659
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306660 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006661 }
6662
6663 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6664 buf);
6665 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6666 return 0;
6667 }
6668
6669 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6670 return 0;
6671}
6672
6673
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006674static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6675 struct sigma_cmd *cmd)
6676{
6677 char buf[MAX_CMD_LEN];
6678 const char *parameter = get_param(cmd, "Parameter");
6679
6680 if (!parameter)
6681 return -1;
6682
6683 if (strcasecmp(parameter, "RSSI") == 0) {
6684 char rssi[10];
6685
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006686 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006687 rssi, sizeof(rssi)) < 0) {
6688 sigma_dut_print(dut, DUT_MSG_ERROR,
6689 "Could not get RSSI");
6690 return -2;
6691 }
6692
6693 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6694 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6695 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6696 return 0;
6697 }
6698
6699 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6700 return 0;
6701}
6702
6703
Jouni Malinenca0abd32020-02-09 20:18:10 +02006704static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
6705 struct sigma_conn *conn,
6706 struct sigma_cmd *cmd)
6707{
6708 const char *intf = get_param(cmd, "Interface");
6709 char buf[4096], bssid[20], resp[200], *pos, *tmp;
6710
6711 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
6712 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
6713 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
6714 send_resp(dut, conn, SIGMA_ERROR,
6715 "ErrorCode,PMKSA_GET not supported");
6716 return STATUS_SENT_ERROR;
6717 }
6718
6719 if (strncmp(buf, "FAIL", 4) == 0 ||
6720 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
6721 send_resp(dut, conn, SIGMA_ERROR,
6722 "ErrorCode,Could not find current network");
6723 return STATUS_SENT_ERROR;
6724 }
6725
6726 pos = buf;
6727 while (pos) {
6728 if (strncmp(pos, bssid, 17) == 0) {
6729 pos = strchr(pos, ' ');
6730 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05306731 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02006732 pos++;
6733 pos = strchr(pos, ' ');
6734 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05306735 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02006736 pos++;
6737 tmp = strchr(pos, ' ');
6738 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05306739 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02006740 *tmp = '\0';
6741 break;
6742 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02006743 pos = strchr(pos, '\n');
6744 if (pos)
6745 pos++;
6746 }
6747
6748 if (!pos) {
6749 send_resp(dut, conn, SIGMA_ERROR,
6750 "ErrorCode,PMK not available");
6751 return STATUS_SENT_ERROR;
6752 }
6753
6754 snprintf(resp, sizeof(resp), "PMK,%s", pos);
6755 send_resp(dut, conn, SIGMA_COMPLETE, resp);
6756 return STATUS_SENT;
6757}
6758
6759
Jouni Malinenf7222712019-06-13 01:50:21 +03006760static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
6761 struct sigma_conn *conn,
6762 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006763{
6764 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02006765 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006766
Jouni Malinenca0abd32020-02-09 20:18:10 +02006767 if (!parameter)
6768 return INVALID_SEND_STATUS;
6769
6770 if (strcasecmp(parameter, "PMK") == 0)
6771 return sta_get_pmk(dut, conn, cmd);
6772
6773 if (!program)
6774 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006775
6776 if (strcasecmp(program, "P2PNFC") == 0)
6777 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
6778
6779 if (strcasecmp(program, "60ghz") == 0)
6780 return sta_get_parameter_60g(dut, conn, cmd);
6781
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006782 if (strcasecmp(program, "he") == 0)
6783 return sta_get_parameter_he(dut, conn, cmd);
6784
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006785#ifdef ANDROID_NAN
6786 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07006787 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006788#endif /* ANDROID_NAN */
6789
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006790#ifdef MIRACAST
6791 if (strcasecmp(program, "WFD") == 0 ||
6792 strcasecmp(program, "DisplayR2") == 0)
6793 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
6794#endif /* MIRACAST */
6795
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006796 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6797 return 0;
6798}
6799
6800
6801static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
6802 const char *type)
6803{
6804 char buf[100];
6805
6806 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006807 run_iwpriv(dut, intf, "chwidth 2");
6808 run_iwpriv(dut, intf, "mode 11ACVHT80");
6809 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006810 }
6811
6812 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006813 run_iwpriv(dut, intf, "chwidth 0");
6814 run_iwpriv(dut, intf, "mode 11naht40");
6815 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006816 }
6817
6818 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006819 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006820
6821 /* Reset CTS width */
6822 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
6823 intf);
6824 if (system(buf) != 0) {
6825 sigma_dut_print(dut, DUT_MSG_ERROR,
6826 "wifitool %s beeliner_fw_test 54 0 failed",
6827 intf);
6828 }
6829
6830 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006831 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006832
6833 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
6834 if (system(buf) != 0) {
6835 sigma_dut_print(dut, DUT_MSG_ERROR,
6836 "iwpriv rts failed");
6837 }
6838 }
6839
6840 if (type && strcasecmp(type, "Testbed") == 0) {
6841 dut->testbed_flag_txsp = 1;
6842 dut->testbed_flag_rxsp = 1;
6843 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006844 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006845
6846 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006847 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006848
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006849 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006850
6851 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006852 run_iwpriv(dut, intf, "tx_stbc 0");
6853 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006854
6855 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006856 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006857 }
6858
6859 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006860 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07006861 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006862
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006863 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006864 }
6865}
6866
6867
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006868#ifdef NL80211_SUPPORT
6869static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
6870 enum he_mcs_config mcs)
6871{
6872 struct nl_msg *msg;
6873 int ret = 0;
6874 struct nlattr *params;
6875 int ifindex;
6876
6877 ifindex = if_nametoindex(intf);
6878 if (ifindex == 0) {
6879 sigma_dut_print(dut, DUT_MSG_ERROR,
6880 "%s: Index for interface %s failed",
6881 __func__, intf);
6882 return -1;
6883 }
6884
6885 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6886 NL80211_CMD_VENDOR)) ||
6887 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6888 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6889 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6890 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6891 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6892 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
6893 mcs)) {
6894 sigma_dut_print(dut, DUT_MSG_ERROR,
6895 "%s: err in adding vendor_cmd and vendor_data",
6896 __func__);
6897 nlmsg_free(msg);
6898 return -1;
6899 }
6900 nla_nest_end(msg, params);
6901
6902 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6903 if (ret) {
6904 sigma_dut_print(dut, DUT_MSG_ERROR,
6905 "%s: err in send_and_recv_msgs, ret=%d",
6906 __func__, ret);
6907 }
6908 return ret;
6909}
6910#endif /* NL80211_SUPPORT */
6911
6912
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07006913static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
6914 const char *intf, int enable)
6915{
6916#ifdef NL80211_SUPPORT
6917 struct nl_msg *msg;
6918 int ret = 0;
6919 struct nlattr *params;
6920 int ifindex;
6921
6922 ifindex = if_nametoindex(intf);
6923 if (ifindex == 0) {
6924 sigma_dut_print(dut, DUT_MSG_ERROR,
6925 "%s: Index for interface %s failed",
6926 __func__, intf);
6927 return -1;
6928 }
6929
6930 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6931 NL80211_CMD_VENDOR)) ||
6932 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6933 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6934 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6935 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6936 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6937 nla_put_u8(msg,
6938 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
6939 enable)) {
6940 sigma_dut_print(dut, DUT_MSG_ERROR,
6941 "%s: err in adding vendor_cmd and vendor_data",
6942 __func__);
6943 nlmsg_free(msg);
6944 return -1;
6945 }
6946 nla_nest_end(msg, params);
6947
6948 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6949 if (ret) {
6950 sigma_dut_print(dut, DUT_MSG_ERROR,
6951 "%s: err in send_and_recv_msgs, ret=%d",
6952 __func__, ret);
6953 }
6954 return ret;
6955#else /* NL80211_SUPPORT */
6956 sigma_dut_print(dut, DUT_MSG_ERROR,
6957 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
6958 return -1;
6959#endif /* NL80211_SUPPORT */
6960}
6961
6962
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08006963static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
6964 const char *intf, int enable)
6965{
6966#ifdef NL80211_SUPPORT
6967 struct nl_msg *msg;
6968 int ret = 0;
6969 struct nlattr *params;
6970 int ifindex;
6971
6972 ifindex = if_nametoindex(intf);
6973 if (ifindex == 0) {
6974 sigma_dut_print(dut, DUT_MSG_ERROR,
6975 "%s: Index for interface %s failed",
6976 __func__, intf);
6977 return -1;
6978 }
6979
6980 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6981 NL80211_CMD_VENDOR)) ||
6982 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6983 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6984 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6985 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6986 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6987 nla_put_u8(msg,
6988 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
6989 enable)) {
6990 sigma_dut_print(dut, DUT_MSG_ERROR,
6991 "%s: err in adding vendor_cmd and vendor_data",
6992 __func__);
6993 nlmsg_free(msg);
6994 return -1;
6995 }
6996 nla_nest_end(msg, params);
6997
6998 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6999 if (ret) {
7000 sigma_dut_print(dut, DUT_MSG_ERROR,
7001 "%s: err in send_and_recv_msgs, ret=%d",
7002 __func__, ret);
7003 }
7004 return ret;
7005#else /* NL80211_SUPPORT */
7006 sigma_dut_print(dut, DUT_MSG_ERROR,
7007 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7008 return -1;
7009#endif /* NL80211_SUPPORT */
7010}
7011
7012
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007013#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007014
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007015static int sta_set_he_testbed_def(struct sigma_dut *dut,
7016 const char *intf, int cfg)
7017{
7018 struct nl_msg *msg;
7019 int ret = 0;
7020 struct nlattr *params;
7021 int ifindex;
7022
7023 ifindex = if_nametoindex(intf);
7024 if (ifindex == 0) {
7025 sigma_dut_print(dut, DUT_MSG_ERROR,
7026 "%s: Index for interface %s failed",
7027 __func__, intf);
7028 return -1;
7029 }
7030
7031 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7032 NL80211_CMD_VENDOR)) ||
7033 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7034 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7035 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7036 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7037 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7038 nla_put_u8(msg,
7039 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7040 cfg)) {
7041 sigma_dut_print(dut, DUT_MSG_ERROR,
7042 "%s: err in adding vendor_cmd and vendor_data",
7043 __func__);
7044 nlmsg_free(msg);
7045 return -1;
7046 }
7047 nla_nest_end(msg, params);
7048
7049 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7050 if (ret) {
7051 sigma_dut_print(dut, DUT_MSG_ERROR,
7052 "%s: err in send_and_recv_msgs, ret=%d",
7053 __func__, ret);
7054 }
7055 return ret;
7056}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007057
7058
7059static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7060{
7061 struct nl_msg *msg;
7062 int ret = 0;
7063 struct nlattr *params;
7064 int ifindex;
7065
7066 ifindex = if_nametoindex(intf);
7067 if (ifindex == 0) {
7068 sigma_dut_print(dut, DUT_MSG_ERROR,
7069 "%s: Index for interface %s failed",
7070 __func__, intf);
7071 return -1;
7072 }
7073
7074 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7075 NL80211_CMD_VENDOR)) ||
7076 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7077 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7078 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7079 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7080 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7081 nla_put_u8(msg,
7082 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7083 cfg)) {
7084 sigma_dut_print(dut, DUT_MSG_ERROR,
7085 "%s: err in adding vendor_cmd and vendor_data",
7086 __func__);
7087 nlmsg_free(msg);
7088 return -1;
7089 }
7090 nla_nest_end(msg, params);
7091
7092 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7093 if (ret) {
7094 sigma_dut_print(dut, DUT_MSG_ERROR,
7095 "%s: err in send_and_recv_msgs, ret=%d",
7096 __func__, ret);
7097 }
7098 return ret;
7099}
7100
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007101#endif /* NL80211_SUPPORT */
7102
7103
Qiwei Caib6806972020-01-15 13:52:11 +08007104int sta_set_addba_buf_size(struct sigma_dut *dut,
7105 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007106{
7107#ifdef NL80211_SUPPORT
7108 struct nl_msg *msg;
7109 int ret = 0;
7110 struct nlattr *params;
7111 int ifindex;
7112
7113 ifindex = if_nametoindex(intf);
7114 if (ifindex == 0) {
7115 sigma_dut_print(dut, DUT_MSG_ERROR,
7116 "%s: Index for interface %s failed",
7117 __func__, intf);
7118 return -1;
7119 }
7120
7121 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7122 NL80211_CMD_VENDOR)) ||
7123 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7124 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7125 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7126 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7127 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07007128 nla_put_u16(msg,
7129 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
7130 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007131 sigma_dut_print(dut, DUT_MSG_ERROR,
7132 "%s: err in adding vendor_cmd and vendor_data",
7133 __func__);
7134 nlmsg_free(msg);
7135 return -1;
7136 }
7137 nla_nest_end(msg, params);
7138
7139 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7140 if (ret) {
7141 sigma_dut_print(dut, DUT_MSG_ERROR,
7142 "%s: err in send_and_recv_msgs, ret=%d",
7143 __func__, ret);
7144 }
7145 return ret;
7146#else /* NL80211_SUPPORT */
7147 sigma_dut_print(dut, DUT_MSG_ERROR,
7148 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7149 return -1;
7150#endif /* NL80211_SUPPORT */
7151}
7152
7153
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007154static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
7155 int enable)
7156{
7157#ifdef NL80211_SUPPORT
7158 struct nl_msg *msg;
7159 int ret = 0;
7160 struct nlattr *params;
7161 int ifindex;
7162
7163 ifindex = if_nametoindex(intf);
7164 if (ifindex == 0) {
7165 sigma_dut_print(dut, DUT_MSG_ERROR,
7166 "%s: Index for interface %s failed",
7167 __func__, intf);
7168 return -1;
7169 }
7170
7171 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7172 NL80211_CMD_VENDOR)) ||
7173 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7174 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7175 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7176 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7177 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7178 nla_put_u8(msg,
7179 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7180 enable)) {
7181 sigma_dut_print(dut, DUT_MSG_ERROR,
7182 "%s: err in adding vendor_cmd and vendor_data",
7183 __func__);
7184 nlmsg_free(msg);
7185 return -1;
7186 }
7187 nla_nest_end(msg, params);
7188
7189 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7190 if (ret) {
7191 sigma_dut_print(dut, DUT_MSG_ERROR,
7192 "%s: err in send_and_recv_msgs, ret=%d",
7193 __func__, ret);
7194 }
7195 return ret;
7196#else /* NL80211_SUPPORT */
7197 sigma_dut_print(dut, DUT_MSG_ERROR,
7198 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7199 return -1;
7200#endif /* NL80211_SUPPORT */
7201}
7202
7203
Arif Hussain9765f7d2018-07-03 08:28:26 -07007204static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7205 int val)
7206{
7207#ifdef NL80211_SUPPORT
7208 struct nl_msg *msg;
7209 int ret = 0;
7210 struct nlattr *params;
7211 int ifindex;
7212
7213 ifindex = if_nametoindex(intf);
7214 if (ifindex == 0) {
7215 sigma_dut_print(dut, DUT_MSG_ERROR,
7216 "%s: Index for interface %s failed, val:%d",
7217 __func__, intf, val);
7218 return -1;
7219 }
7220
7221 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7222 NL80211_CMD_VENDOR)) ||
7223 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7224 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7225 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7226 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7227 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7228 nla_put_u8(msg,
7229 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7230 val)) {
7231 sigma_dut_print(dut, DUT_MSG_ERROR,
7232 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7233 __func__, val);
7234 nlmsg_free(msg);
7235 return -1;
7236 }
7237 nla_nest_end(msg, params);
7238
7239 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7240 if (ret) {
7241 sigma_dut_print(dut, DUT_MSG_ERROR,
7242 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7243 __func__, ret, val);
7244 }
7245 return ret;
7246#else /* NL80211_SUPPORT */
7247 sigma_dut_print(dut, DUT_MSG_ERROR,
7248 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7249 return -1;
7250#endif /* NL80211_SUPPORT */
7251}
7252
7253
Arif Hussain68d23f52018-07-11 13:39:08 -07007254#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007255static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7256 enum qca_wlan_he_mac_padding_dur val)
7257{
Arif Hussain68d23f52018-07-11 13:39:08 -07007258 struct nl_msg *msg;
7259 int ret = 0;
7260 struct nlattr *params;
7261 int ifindex;
7262
7263 ifindex = if_nametoindex(intf);
7264 if (ifindex == 0) {
7265 sigma_dut_print(dut, DUT_MSG_ERROR,
7266 "%s: Index for interface %s failed, val:%d",
7267 __func__, intf, val);
7268 return -1;
7269 }
7270
7271 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7272 NL80211_CMD_VENDOR)) ||
7273 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7274 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7275 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7276 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7277 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7278 nla_put_u8(msg,
7279 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
7280 val)) {
7281 sigma_dut_print(dut, DUT_MSG_ERROR,
7282 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7283 __func__, val);
7284 nlmsg_free(msg);
7285 return -1;
7286 }
7287 nla_nest_end(msg, params);
7288
7289 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7290 if (ret) {
7291 sigma_dut_print(dut, DUT_MSG_ERROR,
7292 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7293 __func__, ret, val);
7294 }
7295 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07007296}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007297#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007298
7299
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007300static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7301 int val)
7302{
7303#ifdef NL80211_SUPPORT
7304 struct nl_msg *msg;
7305 int ret = 0;
7306 struct nlattr *params;
7307 int ifindex;
7308
7309 ifindex = if_nametoindex(intf);
7310 if (ifindex == 0) {
7311 sigma_dut_print(dut, DUT_MSG_ERROR,
7312 "%s: Index for interface %s failed, val:%d",
7313 __func__, intf, val);
7314 return -1;
7315 }
7316
7317 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7318 NL80211_CMD_VENDOR)) ||
7319 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7320 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7321 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7322 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7323 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7324 nla_put_u8(msg,
7325 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7326 val)) {
7327 sigma_dut_print(dut, DUT_MSG_ERROR,
7328 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7329 __func__, val);
7330 nlmsg_free(msg);
7331 return -1;
7332 }
7333 nla_nest_end(msg, params);
7334
7335 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7336 if (ret) {
7337 sigma_dut_print(dut, DUT_MSG_ERROR,
7338 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7339 __func__, ret, val);
7340 }
7341 return ret;
7342#else /* NL80211_SUPPORT */
7343 sigma_dut_print(dut, DUT_MSG_ERROR,
7344 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7345 return -1;
7346#endif /* NL80211_SUPPORT */
7347}
7348
7349
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007350#ifdef NL80211_SUPPORT
7351static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7352{
7353 struct nl_msg *msg;
7354 int ret = 0;
7355 struct nlattr *params;
7356 int ifindex;
7357
7358 ifindex = if_nametoindex(intf);
7359 if (ifindex == 0) {
7360 sigma_dut_print(dut, DUT_MSG_ERROR,
7361 "%s: Index for interface %s failed",
7362 __func__, intf);
7363 return -1;
7364 }
7365
7366 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7367 NL80211_CMD_VENDOR)) ||
7368 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7369 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7370 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7371 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7372 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7373 nla_put_flag(msg,
7374 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
7375 sigma_dut_print(dut, DUT_MSG_ERROR,
7376 "%s: err in adding vendor_cmd and vendor_data",
7377 __func__);
7378 nlmsg_free(msg);
7379 return -1;
7380 }
7381 nla_nest_end(msg, params);
7382
7383 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7384 if (ret) {
7385 sigma_dut_print(dut, DUT_MSG_ERROR,
7386 "%s: err in send_and_recv_msgs, ret=%d",
7387 __func__, ret);
7388 }
7389 return ret;
7390}
7391#endif /* NL80211_SUPPORT */
7392
7393
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007394static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7395 int val)
7396{
7397#ifdef NL80211_SUPPORT
7398 struct nl_msg *msg;
7399 int ret = 0;
7400 struct nlattr *params;
7401 int ifindex;
7402
7403 ifindex = if_nametoindex(intf);
7404 if (ifindex == 0) {
7405 sigma_dut_print(dut, DUT_MSG_ERROR,
7406 "%s: Index for interface %s failed, val:%d",
7407 __func__, intf, val);
7408 return -1;
7409 }
7410
7411 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7412 NL80211_CMD_VENDOR)) ||
7413 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7414 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7415 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7416 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7417 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7418 nla_put_u8(msg,
7419 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
7420 val)) {
7421 sigma_dut_print(dut, DUT_MSG_ERROR,
7422 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7423 __func__, val);
7424 nlmsg_free(msg);
7425 return -1;
7426 }
7427 nla_nest_end(msg, params);
7428
7429 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7430 if (ret) {
7431 sigma_dut_print(dut, DUT_MSG_ERROR,
7432 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7433 __func__, ret, val);
7434 }
7435 return ret;
7436#else /* NL80211_SUPPORT */
7437 sigma_dut_print(dut, DUT_MSG_ERROR,
7438 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7439 return -1;
7440#endif /* NL80211_SUPPORT */
7441}
7442
7443
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007444static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7445 int val)
7446{
7447#ifdef NL80211_SUPPORT
7448 struct nl_msg *msg;
7449 int ret = 0;
7450 struct nlattr *params;
7451 int ifindex;
7452
7453 ifindex = if_nametoindex(intf);
7454 if (ifindex == 0) {
7455 sigma_dut_print(dut, DUT_MSG_ERROR,
7456 "%s: Index for interface %s failed, val:%d",
7457 __func__, intf, val);
7458 return -1;
7459 }
7460
7461 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7462 NL80211_CMD_VENDOR)) ||
7463 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7464 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7465 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7466 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7467 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7468 nla_put_u8(msg,
7469 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
7470 val)) {
7471 sigma_dut_print(dut, DUT_MSG_ERROR,
7472 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7473 __func__, val);
7474 nlmsg_free(msg);
7475 return -1;
7476 }
7477 nla_nest_end(msg, params);
7478
7479 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7480 if (ret) {
7481 sigma_dut_print(dut, DUT_MSG_ERROR,
7482 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7483 __func__, ret, val);
7484 }
7485 return ret;
7486#else /* NL80211_SUPPORT */
7487 sigma_dut_print(dut, DUT_MSG_ERROR,
7488 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7489 return -1;
7490#endif /* NL80211_SUPPORT */
7491}
7492
7493
Arif Hussain480d5f42019-03-12 14:40:42 -07007494static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7495 int val)
7496{
7497#ifdef NL80211_SUPPORT
7498 struct nl_msg *msg;
7499 int ret;
7500 struct nlattr *params;
7501 int ifindex;
7502
7503 ifindex = if_nametoindex(intf);
7504 if (ifindex == 0) {
7505 sigma_dut_print(dut, DUT_MSG_ERROR,
7506 "%s: Index for interface %s failed, val:%d",
7507 __func__, intf, val);
7508 return -1;
7509 }
7510
7511 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7512 NL80211_CMD_VENDOR)) ||
7513 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7514 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7515 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7516 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7517 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7518 nla_put_u8(msg,
7519 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT,
7520 val)) {
7521 sigma_dut_print(dut, DUT_MSG_ERROR,
7522 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7523 __func__, val);
7524 nlmsg_free(msg);
7525 return -1;
7526 }
7527 nla_nest_end(msg, params);
7528
7529 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7530 if (ret) {
7531 sigma_dut_print(dut, DUT_MSG_ERROR,
7532 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7533 __func__, ret, val);
7534 }
7535 return ret;
7536#else /* NL80211_SUPPORT */
7537 sigma_dut_print(dut, DUT_MSG_ERROR,
7538 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7539 return -1;
7540#endif /* NL80211_SUPPORT */
7541}
7542
7543
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007544static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7545 const char *type)
7546{
7547 char buf[60];
7548
7549 if (dut->program == PROGRAM_HE) {
7550 /* resetting phymode to auto in case of HE program */
7551 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
7552 if (system(buf) != 0) {
7553 sigma_dut_print(dut, DUT_MSG_ERROR,
7554 "iwpriv %s setphymode failed", intf);
7555 }
7556
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007557 /* reset the rate to Auto rate */
7558 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7559 intf);
7560 if (system(buf) != 0) {
7561 sigma_dut_print(dut, DUT_MSG_ERROR,
7562 "iwpriv %s set_11ax_rate 0xff failed",
7563 intf);
7564 }
7565
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007566 /* reset the LDPC setting */
7567 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7568 if (system(buf) != 0) {
7569 sigma_dut_print(dut, DUT_MSG_ERROR,
7570 "iwpriv %s ldpc 1 failed", intf);
7571 }
7572
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007573 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05307574 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007575
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007576 /* remove all network profiles */
7577 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007578
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007579 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7580 sta_set_addba_buf_size(dut, intf, 64);
7581
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007582#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007583 /* Reset the device HE capabilities to its default supported
7584 * configuration. */
7585 sta_set_he_testbed_def(dut, intf, 0);
7586
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007587 /* Disable noackpolicy for all AC */
7588 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7589 sigma_dut_print(dut, DUT_MSG_ERROR,
7590 "Disable of noackpolicy for all AC failed");
7591 }
7592#endif /* NL80211_SUPPORT */
7593
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007594 /* Enable WMM by default */
7595 if (wcn_sta_set_wmm(dut, intf, "on")) {
7596 sigma_dut_print(dut, DUT_MSG_ERROR,
7597 "Enable of WMM in sta_reset_default_wcn failed");
7598 }
7599
7600 /* Disable ADDBA_REJECT by default */
7601 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7602 sigma_dut_print(dut, DUT_MSG_ERROR,
7603 "Disable of addba_reject in sta_reset_default_wcn failed");
7604 }
7605
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007606 /* Enable sending of ADDBA by default */
7607 if (nlvendor_config_send_addba(dut, intf, 1)) {
7608 sigma_dut_print(dut, DUT_MSG_ERROR,
7609 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7610 }
7611
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007612 /* Enable AMPDU by default */
7613 iwpriv_sta_set_ampdu(dut, intf, 1);
7614
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007615#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08007616 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007617 sigma_dut_print(dut, DUT_MSG_ERROR,
7618 "Set LTF config to default in sta_reset_default_wcn failed");
7619 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007620
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007621 /* set the beamformee NSTS(maximum number of
7622 * space-time streams) to default DUT config
7623 */
7624 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007625 sigma_dut_print(dut, DUT_MSG_ERROR,
7626 "Failed to set BeamformeeSTS");
7627 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007628
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007629 if (sta_set_mac_padding_duration(
7630 dut, intf,
7631 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007632 sigma_dut_print(dut, DUT_MSG_ERROR,
7633 "Failed to set MAC padding duration");
7634 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007635
7636 if (sta_set_mu_edca_override(dut, intf, 0)) {
7637 sigma_dut_print(dut, DUT_MSG_ERROR,
7638 "ErrorCode,Failed to set MU EDCA override disable");
7639 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007640
7641 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7642 sigma_dut_print(dut, DUT_MSG_ERROR,
7643 "Failed to set OM ctrl supp");
7644 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007645
7646 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7647 sigma_dut_print(dut, DUT_MSG_ERROR,
7648 "Failed to set Tx SU PPDU enable");
7649 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007650
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007651 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7652 sigma_dut_print(dut, DUT_MSG_ERROR,
7653 "failed to send TB PPDU Tx cfg");
7654 }
7655
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007656 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7657 sigma_dut_print(dut, DUT_MSG_ERROR,
7658 "Failed to set OM ctrl reset");
7659 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007660
7661 /* +HTC-HE support default on */
7662 if (sta_set_he_htc_supp(dut, intf, 1)) {
7663 sigma_dut_print(dut, DUT_MSG_ERROR,
7664 "Setting of +HTC-HE support failed");
7665 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007666#endif /* NL80211_SUPPORT */
7667
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007668 if (sta_set_tx_beamformee(dut, intf, 1)) {
7669 sigma_dut_print(dut, DUT_MSG_ERROR,
7670 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7671 }
7672
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007673 /* Set nss to 1 and MCS 0-7 in case of testbed */
7674 if (type && strcasecmp(type, "Testbed") == 0) {
7675#ifdef NL80211_SUPPORT
7676 int ret;
7677#endif /* NL80211_SUPPORT */
7678
7679 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7680 if (system(buf) != 0) {
7681 sigma_dut_print(dut, DUT_MSG_ERROR,
7682 "iwpriv %s nss failed", intf);
7683 }
7684
7685#ifdef NL80211_SUPPORT
7686 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7687 if (ret) {
7688 sigma_dut_print(dut, DUT_MSG_ERROR,
7689 "Setting of MCS failed, ret:%d",
7690 ret);
7691 }
7692#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007693
7694 /* Disable STBC as default */
7695 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007696
7697 /* Disable AMSDU as default */
7698 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007699
7700#ifdef NL80211_SUPPORT
7701 /* HE fragmentation default off */
7702 if (sta_set_he_fragmentation(dut, intf,
7703 HE_FRAG_DISABLE)) {
7704 sigma_dut_print(dut, DUT_MSG_ERROR,
7705 "Setting of HE fragmentation failed");
7706 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007707
7708 /* set the beamformee NSTS(maximum number of
7709 * space-time streams) to default testbed config
7710 */
7711 if (sta_set_beamformee_sts(dut, intf, 3)) {
7712 sigma_dut_print(dut, DUT_MSG_ERROR,
7713 "Failed to set BeamformeeSTS");
7714 }
7715
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007716 /* +HTC-HE support default off */
7717 if (sta_set_he_htc_supp(dut, intf, 0)) {
7718 sigma_dut_print(dut, DUT_MSG_ERROR,
7719 "Setting of +HTC-HE support failed");
7720 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007721
7722 /* Set device HE capabilities to testbed default
7723 * configuration. */
7724 if (sta_set_he_testbed_def(dut, intf, 1)) {
7725 sigma_dut_print(dut, DUT_MSG_DEBUG,
7726 "Failed to set HE defaults");
7727 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007728
7729 /* Disable VHT support in 2.4 GHz for testbed */
7730 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007731#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007732
7733 /* Enable WEP/TKIP with HE capability in testbed */
7734 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
7735 sigma_dut_print(dut, DUT_MSG_ERROR,
7736 "Enabling HE config with WEP/TKIP failed");
7737 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007738 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007739
7740 /* Defaults in case of DUT */
7741 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07007742 /* Enable STBC by default */
7743 wcn_sta_set_stbc(dut, intf, "1");
7744
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007745 /* set nss to 2 */
7746 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
7747 if (system(buf) != 0) {
7748 sigma_dut_print(dut, DUT_MSG_ERROR,
7749 "iwpriv %s nss 2 failed", intf);
7750 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007751 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007752
7753#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07007754 /* Set HE_MCS to 0-11 */
7755 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007756 sigma_dut_print(dut, DUT_MSG_ERROR,
7757 "Setting of MCS failed");
7758 }
7759#endif /* NL80211_SUPPORT */
7760
7761 /* Disable WEP/TKIP with HE capability in DUT */
7762 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
7763 sigma_dut_print(dut, DUT_MSG_ERROR,
7764 "Enabling HE config with WEP/TKIP failed");
7765 }
7766 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007767 }
7768}
7769
7770
Jouni Malinenf7222712019-06-13 01:50:21 +03007771static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
7772 struct sigma_conn *conn,
7773 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007774{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007775 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007776 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007777 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007778 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307779 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007780
Jouni Malinenb21f0542019-11-04 17:53:38 +02007781 if (dut->station_ifname_2g &&
7782 strcmp(dut->station_ifname_2g, intf) == 0)
7783 dut->use_5g = 0;
7784 else if (dut->station_ifname_5g &&
7785 strcmp(dut->station_ifname_5g, intf) == 0)
7786 dut->use_5g = 1;
7787
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007788 if (!program)
7789 program = get_param(cmd, "prog");
7790 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007791 dut->device_type = STA_unknown;
7792 type = get_param(cmd, "type");
7793 if (type && strcasecmp(type, "Testbed") == 0)
7794 dut->device_type = STA_testbed;
7795 if (type && strcasecmp(type, "DUT") == 0)
7796 dut->device_type = STA_dut;
7797
7798 if (dut->program == PROGRAM_TDLS) {
7799 /* Clear TDLS testing mode */
7800 wpa_command(intf, "SET tdls_disabled 0");
7801 wpa_command(intf, "SET tdls_testing 0");
7802 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007803 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05307804 /* Enable the WCN driver in TDLS Explicit trigger mode
7805 */
7806 wpa_command(intf, "SET tdls_external_control 0");
7807 wpa_command(intf, "SET tdls_trigger_control 0");
7808 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007809 }
7810
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007811#ifdef MIRACAST
7812 if (dut->program == PROGRAM_WFD ||
7813 dut->program == PROGRAM_DISPLAYR2)
7814 miracast_sta_reset_default(dut, conn, cmd);
7815#endif /* MIRACAST */
7816
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007817 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007818 case DRIVER_ATHEROS:
7819 sta_reset_default_ath(dut, intf, type);
7820 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007821 case DRIVER_WCN:
7822 sta_reset_default_wcn(dut, intf, type);
7823 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007824 default:
7825 break;
7826 }
7827
7828#ifdef ANDROID_NAN
7829 if (dut->program == PROGRAM_NAN)
7830 nan_cmd_sta_reset_default(dut, conn, cmd);
7831#endif /* ANDROID_NAN */
7832
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05307833 if (dut->program == PROGRAM_LOC &&
7834 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
7835 return ERROR_SEND_STATUS;
7836
Jouni Malinenba630452018-06-22 11:49:59 +03007837 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007838 unlink("SP/wi-fi.org/pps.xml");
7839 if (system("rm -r SP/*") != 0) {
7840 }
7841 unlink("next-client-cert.pem");
7842 unlink("next-client-key.pem");
7843 }
7844
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007845 /* For WPS program of the 60 GHz band the band type needs to be saved */
7846 if (dut->program == PROGRAM_WPS) {
7847 if (band && strcasecmp(band, "60GHz") == 0) {
7848 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007849 /* For 60 GHz enable WPS for WPS TCs */
7850 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007851 } else {
7852 dut->band = WPS_BAND_NON_60G;
7853 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007854 } else if (dut->program == PROGRAM_60GHZ) {
7855 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
7856 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007857 }
7858
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02007859 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007860 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007861 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007862
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007863 sigma_dut_print(dut, DUT_MSG_INFO,
7864 "WPS 60 GHz program, wps_disable = %d",
7865 dut->wps_disable);
7866
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007867 if (!dev_role) {
7868 send_resp(dut, conn, SIGMA_ERROR,
7869 "errorCode,Missing DevRole argument");
7870 return 0;
7871 }
7872
7873 if (strcasecmp(dev_role, "STA") == 0)
7874 dut->dev_role = DEVROLE_STA;
7875 else if (strcasecmp(dev_role, "PCP") == 0)
7876 dut->dev_role = DEVROLE_PCP;
7877 else {
7878 send_resp(dut, conn, SIGMA_ERROR,
7879 "errorCode,Unknown DevRole");
7880 return 0;
7881 }
7882
7883 if (dut->device_type == STA_unknown) {
7884 sigma_dut_print(dut, DUT_MSG_ERROR,
7885 "Device type is not STA testbed or DUT");
7886 send_resp(dut, conn, SIGMA_ERROR,
7887 "errorCode,Unknown device type");
7888 return 0;
7889 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007890
7891 sigma_dut_print(dut, DUT_MSG_DEBUG,
7892 "Setting msdu_size to MAX: 7912");
7893 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007894 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007895
7896 if (system(buf) != 0) {
7897 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
7898 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007899 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007900 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007901
7902 if (sta_set_force_mcs(dut, 0, 1)) {
7903 sigma_dut_print(dut, DUT_MSG_ERROR,
7904 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007905 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007906 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007907 }
7908
7909 wpa_command(intf, "WPS_ER_STOP");
7910 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05307911 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007912 wpa_command(intf, "SET radio_disabled 0");
7913
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007914 dut->wps_forced_version = 0;
7915
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007916 if (dut->wsc_fragment) {
7917 dut->wsc_fragment = 0;
7918 wpa_command(intf, "SET device_name Test client");
7919 wpa_command(intf, "SET manufacturer ");
7920 wpa_command(intf, "SET model_name ");
7921 wpa_command(intf, "SET model_number ");
7922 wpa_command(intf, "SET serial_number ");
7923 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02007924 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
7925 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
7926 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
7927 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007928
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007929 if (dut->tmp_mac_addr && dut->set_macaddr) {
7930 dut->tmp_mac_addr = 0;
7931 if (system(dut->set_macaddr) != 0) {
7932 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
7933 "temporary MAC address");
7934 }
7935 }
7936
7937 set_ps(intf, dut, 0);
7938
Jouni Malinenba630452018-06-22 11:49:59 +03007939 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
7940 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007941 wpa_command(intf, "SET interworking 1");
7942 wpa_command(intf, "SET hs20 1");
7943 }
7944
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007945 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007946 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007947 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007948 wpa_command(intf, "SET pmf 1");
7949 } else {
7950 wpa_command(intf, "SET pmf 0");
7951 }
7952
7953 hs2_clear_credentials(intf);
7954 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
7955 wpa_command(intf, "SET access_network_type 15");
7956
7957 static_ip_file(0, NULL, NULL, NULL);
7958 kill_dhcp_client(dut, intf);
7959 clear_ip_addr(dut, intf);
7960
7961 dut->er_oper_performed = 0;
7962 dut->er_oper_bssid[0] = '\0';
7963
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007964 if (dut->program == PROGRAM_LOC) {
7965 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007966 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007967 }
7968
Ashwini Patil00402582017-04-13 12:29:39 +05307969 if (dut->program == PROGRAM_MBO) {
7970 free(dut->non_pref_ch_list);
7971 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05307972 free(dut->btm_query_cand_list);
7973 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05307974 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05307975 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05307976 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05307977 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05307978 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05307979 }
7980
Jouni Malinen3c367e82017-06-23 17:01:47 +03007981 free(dut->rsne_override);
7982 dut->rsne_override = NULL;
7983
Jouni Malinen68143132017-09-02 02:34:08 +03007984 free(dut->sae_commit_override);
7985 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03007986 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02007987 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03007988
Jouni Malinen134fe3c2019-06-12 04:16:49 +03007989 dut->sta_associate_wait_connect = 0;
7990 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03007991 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03007992 dut->sta_tod_policy = 0;
7993
Jouni Malinend86e5822017-08-29 03:55:32 +03007994 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02007995 free(dut->dpp_peer_uri);
7996 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02007997 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02007998 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03007999 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03008000
Jouni Malinenfac9cad2017-10-10 18:35:55 +03008001 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
8002
vamsi krishnaa2799492017-12-05 14:28:01 +05308003 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308004 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05308005 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05308006 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
8007 dut->fils_hlp = 0;
8008#ifdef ANDROID
8009 hlp_thread_cleanup(dut);
8010#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05308011 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308012
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308013 if (dut->program == PROGRAM_QM)
8014 wpa_command(intf, "SET interworking 1");
8015
Jouni Malinen8179fee2019-03-28 03:19:47 +02008016 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03008017 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02008018
Sunil Dutt076081f2018-02-05 19:45:50 +05308019#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008020 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05308021 dut->config_rsnie == 1) {
8022 dut->config_rsnie = 0;
8023 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05308024 }
8025#endif /* NL80211_SUPPORT */
8026
Sunil Duttfebf8a82018-02-09 18:50:13 +05308027 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
8028 dut->dev_role = DEVROLE_STA_CFON;
8029 return sta_cfon_reset_default(dut, conn, cmd);
8030 }
8031
Jouni Malinen439352d2018-09-13 03:42:23 +03008032 wpa_command(intf, "SET setband AUTO");
8033
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308034 dut->ocvc = 0;
8035
Sunil Duttfebf8a82018-02-09 18:50:13 +05308036 if (dut->program != PROGRAM_VHT)
8037 return cmd_sta_p2p_reset(dut, conn, cmd);
8038
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08008039 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008040}
8041
8042
Jouni Malinenf7222712019-06-13 01:50:21 +03008043static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
8044 struct sigma_conn *conn,
8045 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008046{
8047 const char *program = get_param(cmd, "Program");
8048
8049 if (program == NULL)
8050 return -1;
8051#ifdef ANDROID_NAN
8052 if (strcasecmp(program, "NAN") == 0)
8053 return nan_cmd_sta_get_events(dut, conn, cmd);
8054#endif /* ANDROID_NAN */
8055 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8056 return 0;
8057}
8058
8059
Jouni Malinen82905202018-04-29 17:20:10 +03008060static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
8061 struct sigma_cmd *cmd)
8062{
8063 const char *url = get_param(cmd, "url");
8064 const char *method = get_param(cmd, "method");
8065 pid_t pid;
8066 int status;
8067
8068 if (!url || !method)
8069 return -1;
8070
8071 /* TODO: Add support for method,post */
8072 if (strcasecmp(method, "get") != 0) {
8073 send_resp(dut, conn, SIGMA_ERROR,
8074 "ErrorCode,Unsupported method");
8075 return 0;
8076 }
8077
8078 pid = fork();
8079 if (pid < 0) {
8080 perror("fork");
8081 return -1;
8082 }
8083
8084 if (pid == 0) {
8085 char * argv[5] = { "wget", "-O", "/dev/null",
8086 (char *) url, NULL };
8087
8088 execv("/usr/bin/wget", argv);
8089 perror("execv");
8090 exit(0);
8091 return -1;
8092 }
8093
8094 if (waitpid(pid, &status, 0) < 0) {
8095 perror("waitpid");
8096 return -1;
8097 }
8098
8099 if (WIFEXITED(status)) {
8100 const char *errmsg;
8101
8102 if (WEXITSTATUS(status) == 0)
8103 return 1;
8104 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
8105 WEXITSTATUS(status));
8106 switch (WEXITSTATUS(status)) {
8107 case 4:
8108 errmsg = "errmsg,Network failure";
8109 break;
8110 case 8:
8111 errmsg = "errmsg,Server issued an error response";
8112 break;
8113 default:
8114 errmsg = "errmsg,Unknown failure from wget";
8115 break;
8116 }
8117 send_resp(dut, conn, SIGMA_ERROR, errmsg);
8118 return 0;
8119 }
8120
8121 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
8122 return 0;
8123}
8124
8125
Jouni Malinenf7222712019-06-13 01:50:21 +03008126static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
8127 struct sigma_conn *conn,
8128 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008129{
8130 const char *program = get_param(cmd, "Prog");
8131
Jouni Malinen82905202018-04-29 17:20:10 +03008132 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008133 return -1;
8134#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03008135 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008136 return nan_cmd_sta_exec_action(dut, conn, cmd);
8137#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03008138
8139 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07008140 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03008141
8142 if (get_param(cmd, "url"))
8143 return sta_exec_action_url(dut, conn, cmd);
8144
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008145 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8146 return 0;
8147}
8148
8149
Jouni Malinenf7222712019-06-13 01:50:21 +03008150static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
8151 struct sigma_conn *conn,
8152 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008153{
8154 const char *intf = get_param(cmd, "Interface");
8155 const char *val, *mcs32, *rate;
8156
8157 val = get_param(cmd, "GREENFIELD");
8158 if (val) {
8159 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
8160 /* Enable GD */
8161 send_resp(dut, conn, SIGMA_ERROR,
8162 "ErrorCode,GF not supported");
8163 return 0;
8164 }
8165 }
8166
8167 val = get_param(cmd, "SGI20");
8168 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008169 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008170 case DRIVER_ATHEROS:
8171 ath_sta_set_sgi(dut, intf, val);
8172 break;
8173 default:
8174 send_resp(dut, conn, SIGMA_ERROR,
8175 "ErrorCode,SGI20 not supported");
8176 return 0;
8177 }
8178 }
8179
8180 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
8181 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
8182 if (mcs32 && rate) {
8183 /* TODO */
8184 send_resp(dut, conn, SIGMA_ERROR,
8185 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
8186 return 0;
8187 } else if (mcs32 && !rate) {
8188 /* TODO */
8189 send_resp(dut, conn, SIGMA_ERROR,
8190 "ErrorCode,MCS32 not supported");
8191 return 0;
8192 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008193 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008194 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008195 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008196 ath_sta_set_11nrates(dut, intf, rate);
8197 break;
8198 default:
8199 send_resp(dut, conn, SIGMA_ERROR,
8200 "ErrorCode,MCS32_FIXEDRATE not supported");
8201 return 0;
8202 }
8203 }
8204
8205 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8206}
8207
8208
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008209static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8210 int mcs_config)
8211{
8212#ifdef NL80211_SUPPORT
8213 int ret;
8214
8215 switch (mcs_config) {
8216 case HE_80_MCS0_7:
8217 case HE_80_MCS0_9:
8218 case HE_80_MCS0_11:
8219 ret = sta_set_he_mcs(dut, intf, mcs_config);
8220 if (ret) {
8221 sigma_dut_print(dut, DUT_MSG_ERROR,
8222 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8223 mcs_config, ret);
8224 }
8225 break;
8226 default:
8227 sigma_dut_print(dut, DUT_MSG_ERROR,
8228 "cmd_set_max_he_mcs: Invalid mcs %d",
8229 mcs_config);
8230 break;
8231 }
8232#else /* NL80211_SUPPORT */
8233 sigma_dut_print(dut, DUT_MSG_ERROR,
8234 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8235#endif /* NL80211_SUPPORT */
8236}
8237
8238
Arif Hussain480d5f42019-03-12 14:40:42 -07008239static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8240 struct sigma_cmd *cmd)
8241{
8242#ifdef NL80211_SUPPORT
8243 struct nlattr *params;
8244 struct nlattr *attr;
8245 struct nlattr *attr1;
8246 struct nl_msg *msg;
8247 int ifindex, ret;
8248 const char *val;
8249 const char *intf = get_param(cmd, "Interface");
8250 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8251 wake_interval_mantissa = 512;
8252 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
8253 protection = 0;
8254
8255 ifindex = if_nametoindex(intf);
8256 if (ifindex == 0) {
8257 sigma_dut_print(dut, DUT_MSG_ERROR,
8258 "%s: Index for interface %s failed",
8259 __func__, intf);
8260 return -1;
8261 }
8262
8263 val = get_param(cmd, "FlowType");
8264 if (val) {
8265 flow_type = atoi(val);
8266 if (flow_type != 0 && flow_type != 1) {
8267 sigma_dut_print(dut, DUT_MSG_ERROR,
8268 "TWT: Invalid FlowType %d", flow_type);
8269 return -1;
8270 }
8271 }
8272
8273 val = get_param(cmd, "TWT_Trigger");
8274 if (val) {
8275 twt_trigger = atoi(val);
8276 if (twt_trigger != 0 && twt_trigger != 1) {
8277 sigma_dut_print(dut, DUT_MSG_ERROR,
8278 "TWT: Invalid TWT_Trigger %d",
8279 twt_trigger);
8280 return -1;
8281 }
8282 }
8283
8284 val = get_param(cmd, "Protection");
8285 if (val) {
8286 protection = atoi(val);
8287 if (protection != 0 && protection != 1) {
8288 sigma_dut_print(dut, DUT_MSG_ERROR,
8289 "TWT: Invalid Protection %d",
8290 protection);
8291 return -1;
8292 }
8293 }
8294
8295 val = get_param(cmd, "TargetWakeTime");
8296 if (val)
8297 target_wake_time = atoi(val);
8298
8299 val = get_param(cmd, "WakeIntervalMantissa");
8300 if (val)
8301 wake_interval_mantissa = atoi(val);
8302
8303 val = get_param(cmd, "WakeIntervalExp");
8304 if (val)
8305 wake_interval_exp = atoi(val);
8306
8307 val = get_param(cmd, "NominalMinWakeDur");
8308 if (val)
8309 nominal_min_wake_dur = atoi(val);
8310
8311 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8312 NL80211_CMD_VENDOR)) ||
8313 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8314 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8315 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8316 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8317 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8318 !(params = nla_nest_start(
8319 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
8320 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8321 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8322 wake_interval_exp) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008323 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, 1) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008324 (twt_trigger &&
8325 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008326 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8327 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008328 (protection &&
8329 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008330 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8331 target_wake_time) ||
8332 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8333 nominal_min_wake_dur) ||
8334 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8335 wake_interval_mantissa)) {
8336 sigma_dut_print(dut, DUT_MSG_ERROR,
8337 "%s: err in adding vendor_cmd and vendor_data",
8338 __func__);
8339 nlmsg_free(msg);
8340 return -1;
8341 }
8342 nla_nest_end(msg, attr1);
8343 nla_nest_end(msg, params);
8344 nla_nest_end(msg, attr);
8345
8346 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8347 if (ret) {
8348 sigma_dut_print(dut, DUT_MSG_ERROR,
8349 "%s: err in send_and_recv_msgs, ret=%d",
8350 __func__, ret);
8351 }
8352
8353 return ret;
8354#else /* NL80211_SUPPORT */
8355 sigma_dut_print(dut, DUT_MSG_ERROR,
8356 "TWT request cannot be done without NL80211_SUPPORT defined");
8357 return -1;
8358#endif /* NL80211_SUPPORT */
8359}
8360
8361
8362static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8363 struct sigma_cmd *cmd)
8364{
8365 #ifdef NL80211_SUPPORT
8366 struct nlattr *params;
8367 struct nlattr *attr;
8368 struct nlattr *attr1;
8369 int ifindex, ret;
8370 struct nl_msg *msg;
8371 const char *intf = get_param(cmd, "Interface");
8372
8373 ifindex = if_nametoindex(intf);
8374 if (ifindex == 0) {
8375 sigma_dut_print(dut, DUT_MSG_ERROR,
8376 "%s: Index for interface %s failed",
8377 __func__, intf);
8378 return -1;
8379 }
8380
8381 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8382 NL80211_CMD_VENDOR)) ||
8383 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8384 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8385 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8386 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8387 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8388 !(params = nla_nest_start(
8389 msg,
8390 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8391 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8392 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8393 sigma_dut_print(dut, DUT_MSG_ERROR,
8394 "%s: err in adding vendor_cmd and vendor_data",
8395 __func__);
8396 nlmsg_free(msg);
8397 return -1;
8398 }
8399 nla_nest_end(msg, attr1);
8400 nla_nest_end(msg, params);
8401 nla_nest_end(msg, attr);
8402
8403 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8404 if (ret) {
8405 sigma_dut_print(dut, DUT_MSG_ERROR,
8406 "%s: err in send_and_recv_msgs, ret=%d",
8407 __func__, ret);
8408 }
8409
8410 return ret;
8411#else /* NL80211_SUPPORT */
8412 sigma_dut_print(dut, DUT_MSG_ERROR,
8413 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8414 return -1;
8415#endif /* NL80211_SUPPORT */
8416}
8417
8418
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008419static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8420 struct sigma_cmd *cmd)
8421{
8422#ifdef NL80211_SUPPORT
8423 struct nlattr *params;
8424 struct nlattr *attr;
8425 struct nlattr *attr1;
8426 struct nl_msg *msg;
8427 int ifindex, ret;
8428 const char *val;
8429 const char *intf = get_param(cmd, "Interface");
8430 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8431 ulmu_data_dis = 0;
8432
8433 ifindex = if_nametoindex(intf);
8434 if (ifindex == 0) {
8435 sigma_dut_print(dut, DUT_MSG_ERROR,
8436 "%s: Index for interface %s failed",
8437 __func__, intf);
8438 return -1;
8439 }
8440 val = get_param(cmd, "OMCtrl_RxNSS");
8441 if (val)
8442 rx_nss = atoi(val);
8443
8444 val = get_param(cmd, "OMCtrl_ChnlWidth");
8445 if (val)
8446 ch_bw = atoi(val);
8447
8448 val = get_param(cmd, "OMCtrl_ULMUDisable");
8449 if (val)
8450 ulmu_dis = atoi(val);
8451
8452 val = get_param(cmd, "OMCtrl_TxNSTS");
8453 if (val)
8454 tx_nsts = atoi(val);
8455
8456 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8457 if (val)
8458 ulmu_data_dis = atoi(val);
8459
8460 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8461 NL80211_CMD_VENDOR)) ||
8462 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8463 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8464 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8465 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8466 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8467 !(params = nla_nest_start(
8468 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8469 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8470 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8471 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8472 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8473 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8474 ulmu_data_dis) ||
8475 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8476 ulmu_dis)) {
8477 sigma_dut_print(dut, DUT_MSG_ERROR,
8478 "%s: err in adding vendor_cmd and vendor_data",
8479 __func__);
8480 nlmsg_free(msg);
8481 return -1;
8482 }
8483 nla_nest_end(msg, attr1);
8484 nla_nest_end(msg, params);
8485 nla_nest_end(msg, attr);
8486
8487 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8488 if (ret) {
8489 sigma_dut_print(dut, DUT_MSG_ERROR,
8490 "%s: err in send_and_recv_msgs, ret=%d",
8491 __func__, ret);
8492 }
8493
8494 return ret;
8495#else /* NL80211_SUPPORT */
8496 sigma_dut_print(dut, DUT_MSG_ERROR,
8497 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8498 return -1;
8499#endif /* NL80211_SUPPORT */
8500}
8501
8502
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008503static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8504 struct sigma_conn *conn,
8505 struct sigma_cmd *cmd)
8506{
8507 const char *intf = get_param(cmd, "Interface");
8508 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008509 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008510 int tkip = -1;
8511 int wep = -1;
8512
Arif Hussaina37e9552018-06-20 17:05:59 -07008513 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008514 val = get_param(cmd, "SGI80");
8515 if (val) {
8516 int sgi80;
8517
8518 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008519 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008520 }
8521
8522 val = get_param(cmd, "TxBF");
8523 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008524 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008525 case DRIVER_WCN:
8526 if (sta_set_tx_beamformee(dut, intf, 1)) {
8527 send_resp(dut, conn, SIGMA_ERROR,
8528 "ErrorCode,Failed to set TX beamformee enable");
8529 return 0;
8530 }
8531 break;
8532 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008533 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008534 send_resp(dut, conn, SIGMA_ERROR,
8535 "ErrorCode,Setting vhtsubfee failed");
8536 return 0;
8537 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008538 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008539 send_resp(dut, conn, SIGMA_ERROR,
8540 "ErrorCode,Setting vhtsubfer failed");
8541 return 0;
8542 }
8543 break;
8544 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008545 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008546 "Unsupported driver type");
8547 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008548 }
8549 }
8550
8551 val = get_param(cmd, "MU_TxBF");
8552 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008553 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008554 case DRIVER_ATHEROS:
8555 ath_sta_set_txsp_stream(dut, intf, "1SS");
8556 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008557 run_iwpriv(dut, intf, "vhtmubfee 1");
8558 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308559 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008560 case DRIVER_WCN:
8561 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8562 send_resp(dut, conn, SIGMA_ERROR,
8563 "ErrorCode,Failed to set RX/TXSP_STREAM");
8564 return 0;
8565 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308566 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008567 default:
8568 sigma_dut_print(dut, DUT_MSG_ERROR,
8569 "Setting SP_STREAM not supported");
8570 break;
8571 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008572 }
8573
8574 val = get_param(cmd, "LDPC");
8575 if (val) {
8576 int ldpc;
8577
8578 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008579 run_iwpriv(dut, intf, "ldpc %d", ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008580 }
8581
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008582 val = get_param(cmd, "BCC");
8583 if (val) {
8584 int bcc;
8585
8586 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8587 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8588 * is mutually exclusive to bcc */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008589 run_iwpriv(dut, intf, "ldpc %d", !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008590 }
8591
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008592 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8593 if (val && dut->sta_nss == 1)
8594 cmd_set_max_he_mcs(dut, intf, atoi(val));
8595
8596 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8597 if (val && dut->sta_nss == 2)
8598 cmd_set_max_he_mcs(dut, intf, atoi(val));
8599
Arif Hussainac6c5112018-05-25 17:34:00 -07008600 val = get_param(cmd, "MCS_FixedRate");
8601 if (val) {
8602#ifdef NL80211_SUPPORT
8603 int mcs, ratecode = 0;
8604 enum he_mcs_config mcs_config;
8605 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008606 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008607
8608 ratecode = (0x07 & dut->sta_nss) << 5;
8609 mcs = atoi(val);
8610 /* Add the MCS to the ratecode */
8611 if (mcs >= 0 && mcs <= 11) {
8612 ratecode += mcs;
8613 if (dut->device_type == STA_testbed &&
8614 mcs > 7 && mcs <= 11) {
8615 if (mcs <= 9)
8616 mcs_config = HE_80_MCS0_9;
8617 else
8618 mcs_config = HE_80_MCS0_11;
8619 ret = sta_set_he_mcs(dut, intf, mcs_config);
8620 if (ret) {
8621 sigma_dut_print(dut, DUT_MSG_ERROR,
8622 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8623 mcs, mcs_config, ret);
8624 }
8625 }
8626 snprintf(buf, sizeof(buf),
8627 "iwpriv %s set_11ax_rate 0x%03x",
8628 intf, ratecode);
8629 if (system(buf) != 0) {
8630 sigma_dut_print(dut, DUT_MSG_ERROR,
8631 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8632 ratecode);
8633 }
8634 } else {
8635 sigma_dut_print(dut, DUT_MSG_ERROR,
8636 "MCS_FixedRate: HE MCS %d not supported",
8637 mcs);
8638 }
8639#else /* NL80211_SUPPORT */
8640 sigma_dut_print(dut, DUT_MSG_ERROR,
8641 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8642#endif /* NL80211_SUPPORT */
8643 }
8644
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008645 val = get_param(cmd, "opt_md_notif_ie");
8646 if (val) {
8647 char *result = NULL;
8648 char delim[] = ";";
8649 char token[30];
8650 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308651 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008652
Peng Xub8fc5cc2017-05-10 17:27:28 -07008653 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308654 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008655
8656 /* Extract the NSS information */
8657 if (result) {
8658 value = atoi(result);
8659 switch (value) {
8660 case 1:
8661 config_val = 1;
8662 break;
8663 case 2:
8664 config_val = 3;
8665 break;
8666 case 3:
8667 config_val = 7;
8668 break;
8669 case 4:
8670 config_val = 15;
8671 break;
8672 default:
8673 config_val = 3;
8674 break;
8675 }
8676
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008677 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8678 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008679
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008680 }
8681
8682 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308683 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008684 if (result) {
8685 value = atoi(result);
8686 switch (value) {
8687 case 20:
8688 config_val = 0;
8689 break;
8690 case 40:
8691 config_val = 1;
8692 break;
8693 case 80:
8694 config_val = 2;
8695 break;
8696 case 160:
8697 config_val = 3;
8698 break;
8699 default:
8700 config_val = 2;
8701 break;
8702 }
8703
8704 dut->chwidth = config_val;
8705
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008706 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008707 }
8708
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008709 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008710 }
8711
8712 val = get_param(cmd, "nss_mcs_cap");
8713 if (val) {
8714 int nss, mcs;
8715 char token[20];
8716 char *result = NULL;
8717 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308718 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008719
Peng Xub8fc5cc2017-05-10 17:27:28 -07008720 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308721 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308722 if (!result) {
8723 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008724 "NSS not specified");
8725 send_resp(dut, conn, SIGMA_ERROR,
8726 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308727 return 0;
8728 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008729 nss = atoi(result);
8730
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008731 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07008732 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008733
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308734 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008735 if (result == NULL) {
8736 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008737 "MCS not specified");
8738 send_resp(dut, conn, SIGMA_ERROR,
8739 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008740 return 0;
8741 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308742 result = strtok_r(result, "-", &saveptr);
8743 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308744 if (!result) {
8745 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008746 "MCS not specified");
8747 send_resp(dut, conn, SIGMA_ERROR,
8748 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308749 return 0;
8750 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008751 mcs = atoi(result);
8752
Arif Hussaina37e9552018-06-20 17:05:59 -07008753 if (program && strcasecmp(program, "HE") == 0) {
8754#ifdef NL80211_SUPPORT
8755 enum he_mcs_config mcs_config;
8756 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008757
Arif Hussaina37e9552018-06-20 17:05:59 -07008758 if (mcs >= 0 && mcs <= 7) {
8759 mcs_config = HE_80_MCS0_7;
8760 } else if (mcs > 7 && mcs <= 9) {
8761 mcs_config = HE_80_MCS0_9;
8762 } else if (mcs > 9 && mcs <= 11) {
8763 mcs_config = HE_80_MCS0_11;
8764 } else {
8765 sigma_dut_print(dut, DUT_MSG_ERROR,
8766 "nss_mcs_cap: HE: Invalid mcs: %d",
8767 mcs);
8768 send_resp(dut, conn, SIGMA_ERROR,
8769 "errorCode,Invalid MCS");
8770 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008771 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008772
8773 ret = sta_set_he_mcs(dut, intf, mcs_config);
8774 if (ret) {
8775 sigma_dut_print(dut, DUT_MSG_ERROR,
8776 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
8777 mcs_config, ret);
8778 send_resp(dut, conn, SIGMA_ERROR,
8779 "errorCode,Failed to set MCS");
8780 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008781 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008782#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008783 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008784 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
8785#endif /* NL80211_SUPPORT */
8786 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008787 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07008788
8789 switch (nss) {
8790 case 1:
8791 switch (mcs) {
8792 case 7:
8793 vht_mcsmap = 0xfffc;
8794 break;
8795 case 8:
8796 vht_mcsmap = 0xfffd;
8797 break;
8798 case 9:
8799 vht_mcsmap = 0xfffe;
8800 break;
8801 default:
8802 vht_mcsmap = 0xfffe;
8803 break;
8804 }
8805 break;
8806 case 2:
8807 switch (mcs) {
8808 case 7:
8809 vht_mcsmap = 0xfff0;
8810 break;
8811 case 8:
8812 vht_mcsmap = 0xfff5;
8813 break;
8814 case 9:
8815 vht_mcsmap = 0xfffa;
8816 break;
8817 default:
8818 vht_mcsmap = 0xfffa;
8819 break;
8820 }
8821 break;
8822 case 3:
8823 switch (mcs) {
8824 case 7:
8825 vht_mcsmap = 0xffc0;
8826 break;
8827 case 8:
8828 vht_mcsmap = 0xffd5;
8829 break;
8830 case 9:
8831 vht_mcsmap = 0xffea;
8832 break;
8833 default:
8834 vht_mcsmap = 0xffea;
8835 break;
8836 }
8837 break;
8838 default:
8839 vht_mcsmap = 0xffea;
8840 break;
8841 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008842 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008843 }
8844 }
8845
8846 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
8847
8848 val = get_param(cmd, "Vht_tkip");
8849 if (val)
8850 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8851
8852 val = get_param(cmd, "Vht_wep");
8853 if (val)
8854 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8855
8856 if (tkip != -1 || wep != -1) {
8857 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008858 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008859 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008860 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008861 } else {
8862 sigma_dut_print(dut, DUT_MSG_ERROR,
8863 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
8864 return 0;
8865 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008866 }
8867
Arif Hussain55f00da2018-07-03 08:28:26 -07008868 val = get_param(cmd, "txBandwidth");
8869 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008870 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07008871 case DRIVER_WCN:
8872 if (wcn_sta_set_width(dut, intf, val) < 0) {
8873 send_resp(dut, conn, SIGMA_ERROR,
8874 "ErrorCode,Failed to set txBandwidth");
8875 return 0;
8876 }
8877 break;
8878 case DRIVER_ATHEROS:
8879 if (ath_set_width(dut, conn, intf, val) < 0) {
8880 send_resp(dut, conn, SIGMA_ERROR,
8881 "ErrorCode,Failed to set txBandwidth");
8882 return 0;
8883 }
8884 break;
8885 default:
8886 sigma_dut_print(dut, DUT_MSG_ERROR,
8887 "Setting txBandwidth not supported");
8888 break;
8889 }
8890 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008891
Arif Hussain9765f7d2018-07-03 08:28:26 -07008892 val = get_param(cmd, "BeamformeeSTS");
8893 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07008894 if (sta_set_tx_beamformee(dut, intf, 1)) {
8895 send_resp(dut, conn, SIGMA_ERROR,
8896 "ErrorCode,Failed to set TX beamformee enable");
8897 return 0;
8898 }
8899
Arif Hussain9765f7d2018-07-03 08:28:26 -07008900 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
8901 send_resp(dut, conn, SIGMA_ERROR,
8902 "ErrorCode,Failed to set BeamformeeSTS");
8903 return 0;
8904 }
8905 }
8906
Arif Hussain68d23f52018-07-11 13:39:08 -07008907 val = get_param(cmd, "Trig_MAC_Padding_Dur");
8908 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008909#ifdef NL80211_SUPPORT
8910 enum qca_wlan_he_mac_padding_dur set_val;
8911
8912 switch (atoi(val)) {
8913 case 16:
8914 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
8915 break;
8916 case 8:
8917 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
8918 break;
8919 default:
8920 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
8921 break;
8922 }
8923 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008924 send_resp(dut, conn, SIGMA_ERROR,
8925 "ErrorCode,Failed to set MAC padding duration");
8926 return 0;
8927 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008928#else /* NL80211_SUPPORT */
8929 sigma_dut_print(dut, DUT_MSG_ERROR,
8930 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
8931#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008932 }
8933
Arif Hussain480d5f42019-03-12 14:40:42 -07008934 val = get_param(cmd, "TWT_ReqSupport");
8935 if (val) {
8936 int set_val;
8937
8938 if (strcasecmp(val, "Enable") == 0) {
8939 set_val = 1;
8940 } else if (strcasecmp(val, "Disable") == 0) {
8941 set_val = 0;
8942 } else {
8943 send_resp(dut, conn, SIGMA_ERROR,
8944 "ErrorCode,Invalid TWT_ReqSupport");
8945 return STATUS_SENT;
8946 }
8947
8948 if (sta_set_twt_req_support(dut, intf, set_val)) {
8949 sigma_dut_print(dut, DUT_MSG_ERROR,
8950 "Failed to set TWT req support %d",
8951 set_val);
8952 send_resp(dut, conn, SIGMA_ERROR,
8953 "ErrorCode,Failed to set TWT_ReqSupport");
8954 return STATUS_SENT;
8955 }
8956 }
8957
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008958 val = get_param(cmd, "MU_EDCA");
8959 if (val && (strcasecmp(val, "Override") == 0)) {
8960 if (sta_set_mu_edca_override(dut, intf, 1)) {
8961 send_resp(dut, conn, SIGMA_ERROR,
8962 "ErrorCode,Failed to set MU EDCA override");
8963 return 0;
8964 }
8965 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008966
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008967 val = get_param(cmd, "OMControl");
8968 if (val) {
8969 int set_val = 1;
8970
8971 if (strcasecmp(val, "Enable") == 0)
8972 set_val = 1;
8973 else if (strcasecmp(val, "Disable") == 0)
8974 set_val = 0;
8975
8976 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
8977 send_resp(dut, conn, SIGMA_ERROR,
8978 "ErrorCode,Failed to set OM ctrl supp");
8979 return 0;
8980 }
8981 }
8982
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008983 val = get_param(cmd, "ADDBAResp_BufSize");
8984 if (val) {
8985 int buf_size;
8986
8987 if (strcasecmp(val, "gt64") == 0)
8988 buf_size = 256;
8989 else
8990 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008991 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008992 sta_set_addba_buf_size(dut, intf, buf_size)) {
8993 send_resp(dut, conn, SIGMA_ERROR,
8994 "ErrorCode,set addbaresp_buff_size failed");
8995 return 0;
8996 }
8997 }
8998
8999 val = get_param(cmd, "ADDBAReq_BufSize");
9000 if (val) {
9001 int buf_size;
9002
9003 if (strcasecmp(val, "gt64") == 0)
9004 buf_size = 256;
9005 else
9006 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009007 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009008 sta_set_addba_buf_size(dut, intf, buf_size)) {
9009 send_resp(dut, conn, SIGMA_ERROR,
9010 "ErrorCode,set addbareq_buff_size failed");
9011 return 0;
9012 }
9013 }
9014
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009015 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9016}
9017
9018
9019static int sta_set_wireless_60g(struct sigma_dut *dut,
9020 struct sigma_conn *conn,
9021 struct sigma_cmd *cmd)
9022{
9023 const char *dev_role = get_param(cmd, "DevRole");
9024
9025 if (!dev_role) {
9026 send_resp(dut, conn, SIGMA_INVALID,
9027 "ErrorCode,DevRole not specified");
9028 return 0;
9029 }
9030
9031 if (strcasecmp(dev_role, "PCP") == 0)
9032 return sta_set_60g_pcp(dut, conn, cmd);
9033 if (strcasecmp(dev_role, "STA") == 0)
9034 return sta_set_60g_sta(dut, conn, cmd);
9035 send_resp(dut, conn, SIGMA_INVALID,
9036 "ErrorCode,DevRole not supported");
9037 return 0;
9038}
9039
9040
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309041static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
9042 struct sigma_cmd *cmd)
9043{
9044 int status;
9045 const char *intf = get_param(cmd, "Interface");
9046 const char *val = get_param(cmd, "DevRole");
9047
9048 if (val && strcasecmp(val, "STA-CFON") == 0) {
9049 status = sta_cfon_set_wireless(dut, conn, cmd);
9050 if (status)
9051 return status;
9052 }
9053 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9054}
9055
9056
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309057static int sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
9058 struct sigma_cmd *cmd)
9059{
9060 const char *intf = get_param(cmd, "Interface");
9061 const char *val;
9062
9063 val = get_param(cmd, "ocvc");
9064 if (val)
9065 dut->ocvc = atoi(val);
9066
9067 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9068}
9069
9070
Jouni Malinenf7222712019-06-13 01:50:21 +03009071static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
9072 struct sigma_conn *conn,
9073 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009074{
9075 const char *val;
9076
9077 val = get_param(cmd, "Program");
9078 if (val) {
9079 if (strcasecmp(val, "11n") == 0)
9080 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08009081 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009082 return cmd_sta_set_wireless_vht(dut, conn, cmd);
9083 if (strcasecmp(val, "60ghz") == 0)
9084 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309085 if (strcasecmp(val, "OCE") == 0)
9086 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02009087 /* sta_set_wireless in WPS program is only used for 60G */
9088 if (is_60g_sigma_dut(dut))
9089 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309090 if (strcasecmp(val, "WPA3") == 0)
9091 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009092 send_resp(dut, conn, SIGMA_ERROR,
9093 "ErrorCode,Program value not supported");
9094 } else {
9095 send_resp(dut, conn, SIGMA_ERROR,
9096 "ErrorCode,Program argument not available");
9097 }
9098
9099 return 0;
9100}
9101
9102
9103static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
9104 int tid)
9105{
9106 char buf[100];
9107 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
9108
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05309109 if (tid < 0 ||
9110 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
9111 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
9112 return;
9113 }
9114
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009115 /*
9116 * Two ways to ensure that addba request with a
9117 * non zero TID could be sent out. EV 117296
9118 */
9119 snprintf(buf, sizeof(buf),
9120 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
9121 tid);
9122 if (system(buf) != 0) {
9123 sigma_dut_print(dut, DUT_MSG_ERROR,
9124 "Ping did not send out");
9125 }
9126
9127 snprintf(buf, sizeof(buf),
9128 "iwconfig %s | grep Access | awk '{print $6}' > %s",
9129 intf, VI_QOS_TMP_FILE);
9130 if (system(buf) != 0)
9131 return;
9132
9133 snprintf(buf, sizeof(buf),
9134 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
9135 intf, VI_QOS_TMP_FILE);
9136 if (system(buf) != 0)
9137 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
9138
9139 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
9140 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
9141 if (system(buf) != 0) {
9142 sigma_dut_print(dut, DUT_MSG_ERROR,
9143 "VI_QOS_TEMP_FILE generation error failed");
9144 }
9145 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9146 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9147 if (system(buf) != 0) {
9148 sigma_dut_print(dut, DUT_MSG_ERROR,
9149 "VI_QOS_FILE generation failed");
9150 }
9151
9152 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9153 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9154 if (system(buf) != 0) {
9155 sigma_dut_print(dut, DUT_MSG_ERROR,
9156 "VI_QOS_FILE generation failed");
9157 }
9158
9159 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
9160 if (system(buf) != 0) {
9161 }
9162}
9163
9164
9165static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9166 struct sigma_cmd *cmd)
9167{
9168 const char *intf = get_param(cmd, "Interface");
9169 const char *val;
9170 int tid = 0;
9171 char buf[100];
9172
9173 val = get_param(cmd, "TID");
9174 if (val) {
9175 tid = atoi(val);
9176 if (tid)
9177 ath_sta_inject_frame(dut, intf, tid);
9178 }
9179
9180 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009181 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009182
9183 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
9184 if (system(buf) != 0) {
9185 sigma_dut_print(dut, DUT_MSG_ERROR,
9186 "wifitool senddelba failed");
9187 }
9188
9189 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
9190 if (system(buf) != 0) {
9191 sigma_dut_print(dut, DUT_MSG_ERROR,
9192 "wifitool sendaddba failed");
9193 }
9194
9195 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9196
9197 return 1;
9198}
9199
9200
Lior David9981b512017-01-20 13:16:40 +02009201#ifdef __linux__
9202
9203static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
9204 int agg_size)
9205{
9206 char dir[128], buf[128];
9207 FILE *f;
9208 regex_t re;
9209 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03009210 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02009211
9212 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
9213 sigma_dut_print(dut, DUT_MSG_ERROR,
9214 "failed to get wil6210 debugfs dir");
9215 return -1;
9216 }
9217
Jouni Malinen3aa72862019-05-29 23:14:51 +03009218 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
9219 if (res < 0 || res >= sizeof(buf))
9220 return -1;
Lior David9981b512017-01-20 13:16:40 +02009221 f = fopen(buf, "r");
9222 if (!f) {
9223 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009224 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009225 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9226 if (res < 0 || res >= sizeof(buf))
9227 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009228 f = fopen(buf, "r");
9229 if (!f) {
9230 sigma_dut_print(dut, DUT_MSG_ERROR,
9231 "failed to open: %s", buf);
9232 return -1;
9233 }
Lior David9981b512017-01-20 13:16:40 +02009234 }
9235
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009236 /* can be either VRING tx... or RING... */
9237 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009238 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9239 goto out;
9240 }
9241
9242 /* find TX VRING for the mac address */
9243 found = 0;
9244 while (fgets(buf, sizeof(buf), f)) {
9245 if (strcasestr(buf, dest_mac)) {
9246 found = 1;
9247 break;
9248 }
9249 }
9250
9251 if (!found) {
9252 sigma_dut_print(dut, DUT_MSG_ERROR,
9253 "no TX VRING for %s", dest_mac);
9254 goto out;
9255 }
9256
9257 /* extract VRING ID, "VRING tx_<id> = {" */
9258 if (!fgets(buf, sizeof(buf), f)) {
9259 sigma_dut_print(dut, DUT_MSG_ERROR,
9260 "no VRING start line for %s", dest_mac);
9261 goto out;
9262 }
9263
9264 rc = regexec(&re, buf, 2, m, 0);
9265 regfree(&re);
9266 if (rc || m[1].rm_so < 0) {
9267 sigma_dut_print(dut, DUT_MSG_ERROR,
9268 "no VRING TX ID for %s", dest_mac);
9269 goto out;
9270 }
9271 buf[m[1].rm_eo] = 0;
9272 vring_id = atoi(&buf[m[1].rm_so]);
9273
9274 /* send the addba command */
9275 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009276 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9277 if (res < 0 || res >= sizeof(buf))
9278 return -1;
Lior David9981b512017-01-20 13:16:40 +02009279 f = fopen(buf, "w");
9280 if (!f) {
9281 sigma_dut_print(dut, DUT_MSG_ERROR,
9282 "failed to open: %s", buf);
9283 return -1;
9284 }
9285
9286 fprintf(f, "add %d %d\n", vring_id, agg_size);
9287
9288 ret = 0;
9289
9290out:
9291 fclose(f);
9292
9293 return ret;
9294}
9295
9296
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009297int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9298 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009299{
9300 const char *val;
9301 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009302
9303 val = get_param(cmd, "TID");
9304 if (val) {
9305 tid = atoi(val);
9306 if (tid != 0) {
9307 sigma_dut_print(dut, DUT_MSG_ERROR,
9308 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9309 tid);
9310 }
9311 }
9312
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009313 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009314 if (!val) {
9315 sigma_dut_print(dut, DUT_MSG_ERROR,
9316 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009317 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009318 }
9319
Lior David9981b512017-01-20 13:16:40 +02009320 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009321 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009322
9323 return 1;
9324}
9325
Lior David9981b512017-01-20 13:16:40 +02009326#endif /* __linux__ */
9327
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009328
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009329static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9330 struct sigma_cmd *cmd)
9331{
9332#ifdef NL80211_SUPPORT
9333 const char *intf = get_param(cmd, "Interface");
9334 const char *val;
9335 int tid = -1;
9336 int bufsize = 64;
9337 struct nl_msg *msg;
9338 int ret = 0;
9339 struct nlattr *params;
9340 int ifindex;
9341
9342 val = get_param(cmd, "TID");
9343 if (val)
9344 tid = atoi(val);
9345
9346 if (tid == -1) {
9347 send_resp(dut, conn, SIGMA_ERROR,
9348 "ErrorCode,sta_send_addba tid invalid");
9349 return 0;
9350 }
9351
9352 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9353
9354 ifindex = if_nametoindex(intf);
9355 if (ifindex == 0) {
9356 sigma_dut_print(dut, DUT_MSG_ERROR,
9357 "%s: Index for interface %s failed",
9358 __func__, intf);
9359 send_resp(dut, conn, SIGMA_ERROR,
9360 "ErrorCode,sta_send_addba interface invalid");
9361 return 0;
9362 }
9363
9364 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9365 NL80211_CMD_VENDOR)) ||
9366 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9367 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9368 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9369 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9370 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9371 nla_put_u8(msg,
9372 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9373 QCA_WLAN_ADD_BA) ||
9374 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9375 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009376 nla_put_u16(msg,
9377 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9378 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009379 sigma_dut_print(dut, DUT_MSG_ERROR,
9380 "%s: err in adding vendor_cmd and vendor_data",
9381 __func__);
9382 nlmsg_free(msg);
9383 send_resp(dut, conn, SIGMA_ERROR,
9384 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9385 return 0;
9386 }
9387 nla_nest_end(msg, params);
9388
9389 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9390 if (ret) {
9391 sigma_dut_print(dut, DUT_MSG_ERROR,
9392 "%s: err in send_and_recv_msgs, ret=%d",
9393 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309394 if (ret == -EOPNOTSUPP)
9395 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009396 send_resp(dut, conn, SIGMA_ERROR,
9397 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9398 return 0;
9399 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009400#else /* NL80211_SUPPORT */
9401 sigma_dut_print(dut, DUT_MSG_ERROR,
9402 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009403#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309404
9405 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009406}
9407
9408
Jouni Malinenf7222712019-06-13 01:50:21 +03009409static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9410 struct sigma_conn *conn,
9411 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009412{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009413 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009414 case DRIVER_ATHEROS:
9415 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009416 case DRIVER_WCN:
9417 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009418#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009419 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009420 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009421#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009422 default:
9423 /*
9424 * There is no driver specific implementation for other drivers.
9425 * Ignore the command and report COMPLETE since the following
9426 * throughput test operation will end up sending ADDBA anyway.
9427 */
9428 return 1;
9429 }
9430}
9431
9432
9433int inject_eth_frame(int s, const void *data, size_t len,
9434 unsigned short ethtype, char *dst, char *src)
9435{
9436 struct iovec iov[4] = {
9437 {
9438 .iov_base = dst,
9439 .iov_len = ETH_ALEN,
9440 },
9441 {
9442 .iov_base = src,
9443 .iov_len = ETH_ALEN,
9444 },
9445 {
9446 .iov_base = &ethtype,
9447 .iov_len = sizeof(unsigned short),
9448 },
9449 {
9450 .iov_base = (void *) data,
9451 .iov_len = len,
9452 }
9453 };
9454 struct msghdr msg = {
9455 .msg_name = NULL,
9456 .msg_namelen = 0,
9457 .msg_iov = iov,
9458 .msg_iovlen = 4,
9459 .msg_control = NULL,
9460 .msg_controllen = 0,
9461 .msg_flags = 0,
9462 };
9463
9464 return sendmsg(s, &msg, 0);
9465}
9466
9467#if defined(__linux__) || defined(__QNXNTO__)
9468
9469int inject_frame(int s, const void *data, size_t len, int encrypt)
9470{
9471#define IEEE80211_RADIOTAP_F_WEP 0x04
9472#define IEEE80211_RADIOTAP_F_FRAG 0x08
9473 unsigned char rtap_hdr[] = {
9474 0x00, 0x00, /* radiotap version */
9475 0x0e, 0x00, /* radiotap length */
9476 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9477 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9478 0x00, /* padding */
9479 0x00, 0x00, /* RX and TX flags to indicate that */
9480 0x00, 0x00, /* this is the injected frame directly */
9481 };
9482 struct iovec iov[2] = {
9483 {
9484 .iov_base = &rtap_hdr,
9485 .iov_len = sizeof(rtap_hdr),
9486 },
9487 {
9488 .iov_base = (void *) data,
9489 .iov_len = len,
9490 }
9491 };
9492 struct msghdr msg = {
9493 .msg_name = NULL,
9494 .msg_namelen = 0,
9495 .msg_iov = iov,
9496 .msg_iovlen = 2,
9497 .msg_control = NULL,
9498 .msg_controllen = 0,
9499 .msg_flags = 0,
9500 };
9501
9502 if (encrypt)
9503 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9504
9505 return sendmsg(s, &msg, 0);
9506}
9507
9508
9509int open_monitor(const char *ifname)
9510{
9511#ifdef __QNXNTO__
9512 struct sockaddr_dl ll;
9513 int s;
9514
9515 memset(&ll, 0, sizeof(ll));
9516 ll.sdl_family = AF_LINK;
9517 ll.sdl_index = if_nametoindex(ifname);
9518 if (ll.sdl_index == 0) {
9519 perror("if_nametoindex");
9520 return -1;
9521 }
9522 s = socket(PF_INET, SOCK_RAW, 0);
9523#else /* __QNXNTO__ */
9524 struct sockaddr_ll ll;
9525 int s;
9526
9527 memset(&ll, 0, sizeof(ll));
9528 ll.sll_family = AF_PACKET;
9529 ll.sll_ifindex = if_nametoindex(ifname);
9530 if (ll.sll_ifindex == 0) {
9531 perror("if_nametoindex");
9532 return -1;
9533 }
9534 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9535#endif /* __QNXNTO__ */
9536 if (s < 0) {
9537 perror("socket[PF_PACKET,SOCK_RAW]");
9538 return -1;
9539 }
9540
9541 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9542 perror("monitor socket bind");
9543 close(s);
9544 return -1;
9545 }
9546
9547 return s;
9548}
9549
9550
9551static int hex2num(char c)
9552{
9553 if (c >= '0' && c <= '9')
9554 return c - '0';
9555 if (c >= 'a' && c <= 'f')
9556 return c - 'a' + 10;
9557 if (c >= 'A' && c <= 'F')
9558 return c - 'A' + 10;
9559 return -1;
9560}
9561
9562
9563int hwaddr_aton(const char *txt, unsigned char *addr)
9564{
9565 int i;
9566
9567 for (i = 0; i < 6; i++) {
9568 int a, b;
9569
9570 a = hex2num(*txt++);
9571 if (a < 0)
9572 return -1;
9573 b = hex2num(*txt++);
9574 if (b < 0)
9575 return -1;
9576 *addr++ = (a << 4) | b;
9577 if (i < 5 && *txt++ != ':')
9578 return -1;
9579 }
9580
9581 return 0;
9582}
9583
9584#endif /* defined(__linux__) || defined(__QNXNTO__) */
9585
9586enum send_frame_type {
9587 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9588};
9589enum send_frame_protection {
9590 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9591};
9592
9593
9594static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9595 enum send_frame_type frame,
9596 enum send_frame_protection protected,
9597 const char *dest)
9598{
9599#ifdef __linux__
9600 unsigned char buf[1000], *pos;
9601 int s, res;
9602 char bssid[20], addr[20];
9603 char result[32], ssid[100];
9604 size_t ssid_len;
9605
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009606 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009607 sizeof(result)) < 0 ||
9608 strncmp(result, "COMPLETED", 9) != 0) {
9609 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9610 return 0;
9611 }
9612
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009613 if (get_wpa_status(get_station_ifname(dut), "bssid",
9614 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009615 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9616 "current BSSID");
9617 return 0;
9618 }
9619
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009620 if (get_wpa_status(get_station_ifname(dut), "address",
9621 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009622 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9623 "own MAC address");
9624 return 0;
9625 }
9626
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009627 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009628 < 0) {
9629 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9630 "current SSID");
9631 return 0;
9632 }
9633 ssid_len = strlen(ssid);
9634
9635 pos = buf;
9636
9637 /* Frame Control */
9638 switch (frame) {
9639 case DISASSOC:
9640 *pos++ = 0xa0;
9641 break;
9642 case DEAUTH:
9643 *pos++ = 0xc0;
9644 break;
9645 case SAQUERY:
9646 *pos++ = 0xd0;
9647 break;
9648 case AUTH:
9649 *pos++ = 0xb0;
9650 break;
9651 case ASSOCREQ:
9652 *pos++ = 0x00;
9653 break;
9654 case REASSOCREQ:
9655 *pos++ = 0x20;
9656 break;
9657 case DLS_REQ:
9658 *pos++ = 0xd0;
9659 break;
9660 }
9661
9662 if (protected == INCORRECT_KEY)
9663 *pos++ = 0x40; /* Set Protected field to 1 */
9664 else
9665 *pos++ = 0x00;
9666
9667 /* Duration */
9668 *pos++ = 0x00;
9669 *pos++ = 0x00;
9670
9671 /* addr1 = DA (current AP) */
9672 hwaddr_aton(bssid, pos);
9673 pos += 6;
9674 /* addr2 = SA (own address) */
9675 hwaddr_aton(addr, pos);
9676 pos += 6;
9677 /* addr3 = BSSID (current AP) */
9678 hwaddr_aton(bssid, pos);
9679 pos += 6;
9680
9681 /* Seq# (to be filled by driver/mac80211) */
9682 *pos++ = 0x00;
9683 *pos++ = 0x00;
9684
9685 if (protected == INCORRECT_KEY) {
9686 /* CCMP parameters */
9687 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9688 pos += 8;
9689 }
9690
9691 if (protected == INCORRECT_KEY) {
9692 switch (frame) {
9693 case DEAUTH:
9694 /* Reason code (encrypted) */
9695 memcpy(pos, "\xa7\x39", 2);
9696 pos += 2;
9697 break;
9698 case DISASSOC:
9699 /* Reason code (encrypted) */
9700 memcpy(pos, "\xa7\x39", 2);
9701 pos += 2;
9702 break;
9703 case SAQUERY:
9704 /* Category|Action|TransID (encrypted) */
9705 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9706 pos += 4;
9707 break;
9708 default:
9709 return -1;
9710 }
9711
9712 /* CCMP MIC */
9713 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9714 pos += 8;
9715 } else {
9716 switch (frame) {
9717 case DEAUTH:
9718 /* reason code = 8 */
9719 *pos++ = 0x08;
9720 *pos++ = 0x00;
9721 break;
9722 case DISASSOC:
9723 /* reason code = 8 */
9724 *pos++ = 0x08;
9725 *pos++ = 0x00;
9726 break;
9727 case SAQUERY:
9728 /* Category - SA Query */
9729 *pos++ = 0x08;
9730 /* SA query Action - Request */
9731 *pos++ = 0x00;
9732 /* Transaction ID */
9733 *pos++ = 0x12;
9734 *pos++ = 0x34;
9735 break;
9736 case AUTH:
9737 /* Auth Alg (Open) */
9738 *pos++ = 0x00;
9739 *pos++ = 0x00;
9740 /* Seq# */
9741 *pos++ = 0x01;
9742 *pos++ = 0x00;
9743 /* Status code */
9744 *pos++ = 0x00;
9745 *pos++ = 0x00;
9746 break;
9747 case ASSOCREQ:
9748 /* Capability Information */
9749 *pos++ = 0x31;
9750 *pos++ = 0x04;
9751 /* Listen Interval */
9752 *pos++ = 0x0a;
9753 *pos++ = 0x00;
9754 /* SSID */
9755 *pos++ = 0x00;
9756 *pos++ = ssid_len;
9757 memcpy(pos, ssid, ssid_len);
9758 pos += ssid_len;
9759 /* Supported Rates */
9760 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9761 10);
9762 pos += 10;
9763 /* Extended Supported Rates */
9764 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9765 pos += 6;
9766 /* RSN */
9767 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9768 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9769 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9770 pos += 28;
9771 break;
9772 case REASSOCREQ:
9773 /* Capability Information */
9774 *pos++ = 0x31;
9775 *pos++ = 0x04;
9776 /* Listen Interval */
9777 *pos++ = 0x0a;
9778 *pos++ = 0x00;
9779 /* Current AP */
9780 hwaddr_aton(bssid, pos);
9781 pos += 6;
9782 /* SSID */
9783 *pos++ = 0x00;
9784 *pos++ = ssid_len;
9785 memcpy(pos, ssid, ssid_len);
9786 pos += ssid_len;
9787 /* Supported Rates */
9788 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9789 10);
9790 pos += 10;
9791 /* Extended Supported Rates */
9792 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9793 pos += 6;
9794 /* RSN */
9795 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9796 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9797 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9798 pos += 28;
9799 break;
9800 case DLS_REQ:
9801 /* Category - DLS */
9802 *pos++ = 0x02;
9803 /* DLS Action - Request */
9804 *pos++ = 0x00;
9805 /* Destination MACAddress */
9806 if (dest)
9807 hwaddr_aton(dest, pos);
9808 else
9809 memset(pos, 0, 6);
9810 pos += 6;
9811 /* Source MACAddress */
9812 hwaddr_aton(addr, pos);
9813 pos += 6;
9814 /* Capability Information */
9815 *pos++ = 0x10; /* Privacy */
9816 *pos++ = 0x06; /* QoS */
9817 /* DLS Timeout Value */
9818 *pos++ = 0x00;
9819 *pos++ = 0x01;
9820 /* Supported rates */
9821 *pos++ = 0x01;
9822 *pos++ = 0x08;
9823 *pos++ = 0x0c; /* 6 Mbps */
9824 *pos++ = 0x12; /* 9 Mbps */
9825 *pos++ = 0x18; /* 12 Mbps */
9826 *pos++ = 0x24; /* 18 Mbps */
9827 *pos++ = 0x30; /* 24 Mbps */
9828 *pos++ = 0x48; /* 36 Mbps */
9829 *pos++ = 0x60; /* 48 Mbps */
9830 *pos++ = 0x6c; /* 54 Mbps */
9831 /* TODO: Extended Supported Rates */
9832 /* TODO: HT Capabilities */
9833 break;
9834 }
9835 }
9836
9837 s = open_monitor("sigmadut");
9838 if (s < 0) {
9839 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9840 "monitor socket");
9841 return 0;
9842 }
9843
9844 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
9845 if (res < 0) {
9846 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9847 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309848 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009849 return 0;
9850 }
9851 if (res < pos - buf) {
9852 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
9853 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309854 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009855 return 0;
9856 }
9857
9858 close(s);
9859
9860 return 1;
9861#else /* __linux__ */
9862 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
9863 "yet supported");
9864 return 0;
9865#endif /* __linux__ */
9866}
9867
9868
9869static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
9870 struct sigma_conn *conn,
9871 struct sigma_cmd *cmd)
9872{
9873 const char *intf = get_param(cmd, "Interface");
9874 const char *sta, *val;
9875 unsigned char addr[ETH_ALEN];
9876 char buf[100];
9877
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +03009878 if (!intf)
9879 return -1;
9880
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009881 sta = get_param(cmd, "peer");
9882 if (sta == NULL)
9883 sta = get_param(cmd, "station");
9884 if (sta == NULL) {
9885 send_resp(dut, conn, SIGMA_ERROR,
9886 "ErrorCode,Missing peer address");
9887 return 0;
9888 }
9889 if (hwaddr_aton(sta, addr) < 0) {
9890 send_resp(dut, conn, SIGMA_ERROR,
9891 "ErrorCode,Invalid peer address");
9892 return 0;
9893 }
9894
9895 val = get_param(cmd, "type");
9896 if (val == NULL)
9897 return -1;
9898
9899 if (strcasecmp(val, "DISCOVERY") == 0) {
9900 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
9901 if (wpa_command(intf, buf) < 0) {
9902 send_resp(dut, conn, SIGMA_ERROR,
9903 "ErrorCode,Failed to send TDLS discovery");
9904 return 0;
9905 }
9906 return 1;
9907 }
9908
9909 if (strcasecmp(val, "SETUP") == 0) {
9910 int status = 0, timeout = 0;
9911
9912 val = get_param(cmd, "Status");
9913 if (val)
9914 status = atoi(val);
9915
9916 val = get_param(cmd, "Timeout");
9917 if (val)
9918 timeout = atoi(val);
9919
9920 if (status != 0 && status != 37) {
9921 send_resp(dut, conn, SIGMA_ERROR,
9922 "ErrorCode,Unsupported status value");
9923 return 0;
9924 }
9925
9926 if (timeout != 0 && timeout != 301) {
9927 send_resp(dut, conn, SIGMA_ERROR,
9928 "ErrorCode,Unsupported timeout value");
9929 return 0;
9930 }
9931
9932 if (status && timeout) {
9933 send_resp(dut, conn, SIGMA_ERROR,
9934 "ErrorCode,Unsupported timeout+status "
9935 "combination");
9936 return 0;
9937 }
9938
9939 if (status == 37 &&
9940 wpa_command(intf, "SET tdls_testing 0x200")) {
9941 send_resp(dut, conn, SIGMA_ERROR,
9942 "ErrorCode,Failed to enable "
9943 "decline setup response test mode");
9944 return 0;
9945 }
9946
9947 if (timeout == 301) {
9948 int res;
9949 if (dut->no_tpk_expiration)
9950 res = wpa_command(intf,
9951 "SET tdls_testing 0x108");
9952 else
9953 res = wpa_command(intf,
9954 "SET tdls_testing 0x8");
9955 if (res) {
9956 send_resp(dut, conn, SIGMA_ERROR,
9957 "ErrorCode,Failed to set short TPK "
9958 "lifetime");
9959 return 0;
9960 }
9961 }
9962
9963 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
9964 if (wpa_command(intf, buf) < 0) {
9965 send_resp(dut, conn, SIGMA_ERROR,
9966 "ErrorCode,Failed to send TDLS setup");
9967 return 0;
9968 }
9969 return 1;
9970 }
9971
9972 if (strcasecmp(val, "TEARDOWN") == 0) {
9973 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
9974 if (wpa_command(intf, buf) < 0) {
9975 send_resp(dut, conn, SIGMA_ERROR,
9976 "ErrorCode,Failed to send TDLS teardown");
9977 return 0;
9978 }
9979 return 1;
9980 }
9981
9982 send_resp(dut, conn, SIGMA_ERROR,
9983 "ErrorCode,Unsupported TDLS frame");
9984 return 0;
9985}
9986
9987
9988static int sta_ap_known(const char *ifname, const char *bssid)
9989{
9990 char buf[4096];
9991
Jouni Malinendd32f192018-09-15 02:55:19 +03009992 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009993 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
9994 return 0;
9995 if (strncmp(buf, "id=", 3) != 0)
9996 return 0;
9997 return 1;
9998}
9999
10000
10001static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
10002 const char *bssid)
10003{
10004 int res;
10005 struct wpa_ctrl *ctrl;
10006 char buf[256];
10007
10008 if (sta_ap_known(ifname, bssid))
10009 return 0;
10010 sigma_dut_print(dut, DUT_MSG_DEBUG,
10011 "AP not in BSS table - start scan");
10012
10013 ctrl = open_wpa_mon(ifname);
10014 if (ctrl == NULL) {
10015 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10016 "wpa_supplicant monitor connection");
10017 return -1;
10018 }
10019
10020 if (wpa_command(ifname, "SCAN") < 0) {
10021 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
10022 wpa_ctrl_detach(ctrl);
10023 wpa_ctrl_close(ctrl);
10024 return -1;
10025 }
10026
10027 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
10028 buf, sizeof(buf));
10029
10030 wpa_ctrl_detach(ctrl);
10031 wpa_ctrl_close(ctrl);
10032
10033 if (res < 0) {
10034 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
10035 return -1;
10036 }
10037
10038 if (sta_ap_known(ifname, bssid))
10039 return 0;
10040 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
10041 return -1;
10042}
10043
10044
10045static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
10046 struct sigma_conn *conn,
10047 struct sigma_cmd *cmd,
10048 const char *intf)
10049{
10050 char buf[200];
10051
10052 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
10053 if (system(buf) != 0) {
10054 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
10055 "ndsend");
10056 return 0;
10057 }
10058
10059 return 1;
10060}
10061
10062
10063static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
10064 struct sigma_conn *conn,
10065 struct sigma_cmd *cmd,
10066 const char *intf)
10067{
10068 char buf[200];
10069 const char *ip = get_param(cmd, "SenderIP");
10070
Peng Xu26b356d2017-10-04 17:58:16 -070010071 if (!ip)
10072 return 0;
10073
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010074 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
10075 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10076 if (system(buf) == 0) {
10077 sigma_dut_print(dut, DUT_MSG_INFO,
10078 "Neighbor Solicitation got a response "
10079 "for %s@%s", ip, intf);
10080 }
10081
10082 return 1;
10083}
10084
10085
10086static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
10087 struct sigma_conn *conn,
10088 struct sigma_cmd *cmd,
10089 const char *ifname)
10090{
10091 char buf[200];
10092 const char *ip = get_param(cmd, "SenderIP");
10093
10094 if (ip == NULL) {
10095 send_resp(dut, conn, SIGMA_ERROR,
10096 "ErrorCode,Missing SenderIP parameter");
10097 return 0;
10098 }
10099 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
10100 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10101 if (system(buf) != 0) {
10102 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
10103 "for %s@%s", ip, ifname);
10104 }
10105
10106 return 1;
10107}
10108
10109
10110static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
10111 struct sigma_conn *conn,
10112 struct sigma_cmd *cmd,
10113 const char *ifname)
10114{
10115 char buf[200];
10116 char ip[16];
10117 int s;
Peng Xub3756882017-10-04 14:39:09 -070010118 struct ifreq ifr;
10119 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010120
10121 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070010122 if (s < 0) {
10123 perror("socket");
10124 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010125 }
10126
Peng Xub3756882017-10-04 14:39:09 -070010127 memset(&ifr, 0, sizeof(ifr));
10128 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
10129 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
10130 sigma_dut_print(dut, DUT_MSG_INFO,
10131 "Failed to get %s IP address: %s",
10132 ifname, strerror(errno));
10133 close(s);
10134 return -1;
10135 }
10136 close(s);
10137
10138 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
10139 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
10140
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010141 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
10142 ip);
10143 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10144 if (system(buf) != 0) {
10145 }
10146
10147 return 1;
10148}
10149
10150
10151static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
10152 struct sigma_conn *conn,
10153 struct sigma_cmd *cmd,
10154 const char *ifname)
10155{
10156 char buf[200], addr[20];
10157 char dst[ETH_ALEN], src[ETH_ALEN];
10158 short ethtype = htons(ETH_P_ARP);
10159 char *pos;
10160 int s, res;
10161 const char *val;
10162 struct sockaddr_in taddr;
10163
10164 val = get_param(cmd, "dest");
10165 if (val)
10166 hwaddr_aton(val, (unsigned char *) dst);
10167
10168 val = get_param(cmd, "DestIP");
10169 if (val)
10170 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070010171 else
10172 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010173
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010174 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010175 sizeof(addr)) < 0)
10176 return -2;
10177 hwaddr_aton(addr, (unsigned char *) src);
10178
10179 pos = buf;
10180 *pos++ = 0x00;
10181 *pos++ = 0x01;
10182 *pos++ = 0x08;
10183 *pos++ = 0x00;
10184 *pos++ = 0x06;
10185 *pos++ = 0x04;
10186 *pos++ = 0x00;
10187 *pos++ = 0x02;
10188 memcpy(pos, src, ETH_ALEN);
10189 pos += ETH_ALEN;
10190 memcpy(pos, &taddr.sin_addr, 4);
10191 pos += 4;
10192 memcpy(pos, dst, ETH_ALEN);
10193 pos += ETH_ALEN;
10194 memcpy(pos, &taddr.sin_addr, 4);
10195 pos += 4;
10196
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010197 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010198 if (s < 0) {
10199 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
10200 "monitor socket");
10201 return 0;
10202 }
10203
10204 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
10205 if (res < 0) {
10206 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
10207 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053010208 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010209 return 0;
10210 }
10211
10212 close(s);
10213
10214 return 1;
10215}
10216
10217
10218static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
10219 struct sigma_conn *conn,
10220 struct sigma_cmd *cmd,
10221 const char *intf, const char *dest)
10222{
10223 char buf[100];
10224
10225 if (if_nametoindex("sigmadut") == 0) {
10226 snprintf(buf, sizeof(buf),
10227 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010228 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010229 if (system(buf) != 0 ||
10230 if_nametoindex("sigmadut") == 0) {
10231 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10232 "monitor interface with '%s'", buf);
10233 return -2;
10234 }
10235 }
10236
10237 if (system("ifconfig sigmadut up") != 0) {
10238 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10239 "monitor interface up");
10240 return -2;
10241 }
10242
10243 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
10244}
10245
10246
10247static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10248 struct sigma_conn *conn,
10249 struct sigma_cmd *cmd)
10250{
10251 const char *intf = get_param(cmd, "Interface");
10252 const char *dest = get_param(cmd, "Dest");
10253 const char *type = get_param(cmd, "FrameName");
10254 const char *val;
10255 char buf[200], *pos, *end;
10256 int count, count2;
10257
10258 if (type == NULL)
10259 type = get_param(cmd, "Type");
10260
10261 if (intf == NULL || dest == NULL || type == NULL)
10262 return -1;
10263
10264 if (strcasecmp(type, "NeighAdv") == 0)
10265 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10266
10267 if (strcasecmp(type, "NeighSolicitReq") == 0)
10268 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10269
10270 if (strcasecmp(type, "ARPProbe") == 0)
10271 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10272
10273 if (strcasecmp(type, "ARPAnnounce") == 0)
10274 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10275
10276 if (strcasecmp(type, "ARPReply") == 0)
10277 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10278
10279 if (strcasecmp(type, "DLS-request") == 0 ||
10280 strcasecmp(type, "DLSrequest") == 0)
10281 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10282 dest);
10283
10284 if (strcasecmp(type, "ANQPQuery") != 0 &&
10285 strcasecmp(type, "Query") != 0) {
10286 send_resp(dut, conn, SIGMA_ERROR,
10287 "ErrorCode,Unsupported HS 2.0 send frame type");
10288 return 0;
10289 }
10290
10291 if (sta_scan_ap(dut, intf, dest) < 0) {
10292 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10293 "the requested AP");
10294 return 0;
10295 }
10296
10297 pos = buf;
10298 end = buf + sizeof(buf);
10299 count = 0;
10300 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10301
10302 val = get_param(cmd, "ANQP_CAP_LIST");
10303 if (val && atoi(val)) {
10304 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10305 count++;
10306 }
10307
10308 val = get_param(cmd, "VENUE_NAME");
10309 if (val && atoi(val)) {
10310 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10311 count++;
10312 }
10313
10314 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10315 if (val && atoi(val)) {
10316 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10317 count++;
10318 }
10319
10320 val = get_param(cmd, "ROAMING_CONS");
10321 if (val && atoi(val)) {
10322 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10323 count++;
10324 }
10325
10326 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10327 if (val && atoi(val)) {
10328 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10329 count++;
10330 }
10331
10332 val = get_param(cmd, "NAI_REALM_LIST");
10333 if (val && atoi(val)) {
10334 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10335 count++;
10336 }
10337
10338 val = get_param(cmd, "3GPP_INFO");
10339 if (val && atoi(val)) {
10340 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10341 count++;
10342 }
10343
10344 val = get_param(cmd, "DOMAIN_LIST");
10345 if (val && atoi(val)) {
10346 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10347 count++;
10348 }
10349
Jouni Malinen34cf9532018-04-29 19:26:33 +030010350 val = get_param(cmd, "Venue_URL");
10351 if (val && atoi(val)) {
10352 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10353 count++;
10354 }
10355
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010356 val = get_param(cmd, "Advice_Of_Charge");
10357 if (val && atoi(val)) {
10358 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10359 count++;
10360 }
10361
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010362 if (count && wpa_command(intf, buf)) {
10363 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10364 return 0;
10365 }
10366
10367 pos = buf;
10368 end = buf + sizeof(buf);
10369 count2 = 0;
10370 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
10371
10372 val = get_param(cmd, "HS_CAP_LIST");
10373 if (val && atoi(val)) {
10374 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
10375 count2++;
10376 }
10377
10378 val = get_param(cmd, "OPER_NAME");
10379 if (val && atoi(val)) {
10380 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
10381 count2++;
10382 }
10383
10384 val = get_param(cmd, "WAN_METRICS");
10385 if (!val)
10386 val = get_param(cmd, "WAN_MAT");
10387 if (!val)
10388 val = get_param(cmd, "WAN_MET");
10389 if (val && atoi(val)) {
10390 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10391 count2++;
10392 }
10393
10394 val = get_param(cmd, "CONNECTION_CAPABILITY");
10395 if (val && atoi(val)) {
10396 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10397 count2++;
10398 }
10399
10400 val = get_param(cmd, "OP_CLASS");
10401 if (val && atoi(val)) {
10402 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10403 count2++;
10404 }
10405
10406 val = get_param(cmd, "OSU_PROVIDER_LIST");
10407 if (val && atoi(val)) {
10408 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10409 count2++;
10410 }
10411
Jouni Malinenf67afec2018-04-29 19:24:58 +030010412 val = get_param(cmd, "OPER_ICON_METADATA");
10413 if (!val)
10414 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10415 if (val && atoi(val)) {
10416 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10417 count2++;
10418 }
10419
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010420 if (count && count2) {
10421 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10422 "second query");
10423 sleep(1);
10424 }
10425
10426 if (count2 && wpa_command(intf, buf)) {
10427 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10428 "failed");
10429 return 0;
10430 }
10431
10432 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10433 if (val) {
10434 if (count || count2) {
10435 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10436 "sending out second query");
10437 sleep(1);
10438 }
10439
10440 if (strcmp(val, "1") == 0)
10441 val = "mail.example.com";
10442 snprintf(buf, end - pos,
10443 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10444 dest, val);
10445 if (wpa_command(intf, buf)) {
10446 send_resp(dut, conn, SIGMA_ERROR,
10447 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10448 "failed");
10449 return 0;
10450 }
10451 }
10452
10453 val = get_param(cmd, "ICON_REQUEST");
10454 if (val) {
10455 if (count || count2) {
10456 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10457 "sending out second query");
10458 sleep(1);
10459 }
10460
10461 snprintf(buf, end - pos,
10462 "HS20_ICON_REQUEST %s %s", dest, val);
10463 if (wpa_command(intf, buf)) {
10464 send_resp(dut, conn, SIGMA_ERROR,
10465 "ErrorCode,HS20_ICON_REQUEST failed");
10466 return 0;
10467 }
10468 }
10469
10470 return 1;
10471}
10472
10473
10474static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10475 struct sigma_conn *conn,
10476 struct sigma_cmd *cmd)
10477{
10478 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010479 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010480 int chwidth, nss;
10481
10482 val = get_param(cmd, "framename");
10483 if (!val)
10484 return -1;
10485 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10486
10487 /* Command sequence to generate Op mode notification */
10488 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010489 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010490
10491 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010492 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010493
10494 /* Extract Channel width */
10495 val = get_param(cmd, "Channel_width");
10496 if (val) {
10497 switch (atoi(val)) {
10498 case 20:
10499 chwidth = 0;
10500 break;
10501 case 40:
10502 chwidth = 1;
10503 break;
10504 case 80:
10505 chwidth = 2;
10506 break;
10507 case 160:
10508 chwidth = 3;
10509 break;
10510 default:
10511 chwidth = 2;
10512 break;
10513 }
10514
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010515 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010516 }
10517
10518 /* Extract NSS */
10519 val = get_param(cmd, "NSS");
10520 if (val) {
10521 switch (atoi(val)) {
10522 case 1:
10523 nss = 1;
10524 break;
10525 case 2:
10526 nss = 3;
10527 break;
10528 case 3:
10529 nss = 7;
10530 break;
10531 default:
10532 /* We do not support NSS > 3 */
10533 nss = 3;
10534 break;
10535 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010536 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010537 }
10538
10539 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010540 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010541 }
10542
10543 return 1;
10544}
10545
10546
10547static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
10548 struct sigma_conn *conn,
10549 struct sigma_cmd *cmd)
10550{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010551 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010552 case DRIVER_ATHEROS:
10553 return ath_sta_send_frame_vht(dut, conn, cmd);
10554 default:
10555 send_resp(dut, conn, SIGMA_ERROR,
10556 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
10557 return 0;
10558 }
10559}
10560
10561
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010562static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
10563 struct sigma_cmd *cmd)
10564{
10565 const char *val;
10566 const char *intf = get_param(cmd, "Interface");
10567
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010568 if (!intf)
10569 return -1;
10570
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010571 val = get_param(cmd, "framename");
10572 if (!val)
10573 return -1;
10574 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10575
10576 /* Command sequence to generate Op mode notification */
10577 if (val && strcasecmp(val, "action") == 0) {
10578 val = get_param(cmd, "PPDUTxType");
10579 if (val && strcasecmp(val, "TB") == 0) {
10580 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
10581 sigma_dut_print(dut, DUT_MSG_ERROR,
10582 "failed to send TB PPDU Tx cfg");
10583 send_resp(dut, conn, SIGMA_ERROR,
10584 "ErrorCode,set TB PPDU Tx cfg failed");
10585 return 0;
10586 }
10587 return 1;
10588 }
10589
10590 sigma_dut_print(dut, DUT_MSG_ERROR,
10591 "Action Tx type is not defined");
10592 }
10593
10594 return 1;
10595}
10596
10597
10598static int cmd_sta_send_frame_he(struct sigma_dut *dut,
10599 struct sigma_conn *conn,
10600 struct sigma_cmd *cmd)
10601{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010602 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010603 case DRIVER_WCN:
10604 return wcn_sta_send_frame_he(dut, conn, cmd);
10605 default:
10606 send_resp(dut, conn, SIGMA_ERROR,
10607 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
10608 return 0;
10609 }
10610}
10611
10612
Lior David0fe101e2017-03-09 16:09:50 +020010613#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010614
10615static int
10616wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
10617 const char *frame_name, const char *dest_mac)
10618{
10619 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
10620 const char *ssid = get_param(cmd, "ssid");
10621 const char *countstr = get_param(cmd, "count");
10622 const char *channelstr = get_param(cmd, "channel");
10623 const char *group_id = get_param(cmd, "groupid");
10624 const char *client_id = get_param(cmd, "clientmac");
10625 int count, channel, freq, i;
10626 const char *fname;
10627 char frame[1024], src_mac[20], group_id_attr[25],
10628 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
10629 const char *group_ssid;
10630 const int group_ssid_prefix_len = 9;
10631 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
10632 size_t framelen = sizeof(frame);
10633 struct template_frame_tag tags[2];
10634 size_t tags_total = ARRAY_SIZE(tags);
10635 int tag_index, len, dst_len;
10636
10637 if (!countstr || !channelstr) {
10638 sigma_dut_print(dut, DUT_MSG_ERROR,
10639 "Missing argument: count, channel");
10640 return -1;
10641 }
10642 if (isprobereq && !ssid) {
10643 sigma_dut_print(dut, DUT_MSG_ERROR,
10644 "Missing argument: ssid");
10645 return -1;
10646 }
10647 if (!isprobereq && (!group_id || !client_id)) {
10648 sigma_dut_print(dut, DUT_MSG_ERROR,
10649 "Missing argument: group_id, client_id");
10650 return -1;
10651 }
10652
10653 count = atoi(countstr);
10654 channel = atoi(channelstr);
10655 freq = channel_to_freq(dut, channel);
10656
10657 if (!freq) {
10658 sigma_dut_print(dut, DUT_MSG_ERROR,
10659 "invalid channel: %s", channelstr);
10660 return -1;
10661 }
10662
10663 if (isprobereq) {
10664 if (strcasecmp(ssid, "wildcard") == 0) {
10665 fname = "probe_req_wildcard.txt";
10666 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
10667 fname = "probe_req_P2P_Wildcard.txt";
10668 } else {
10669 sigma_dut_print(dut, DUT_MSG_ERROR,
10670 "invalid probe request type");
10671 return -1;
10672 }
10673 } else {
10674 fname = "P2P_device_discovery_req.txt";
10675 }
10676
10677 if (parse_template_frame_file(dut, fname, frame, &framelen,
10678 tags, &tags_total)) {
10679 sigma_dut_print(dut, DUT_MSG_ERROR,
10680 "invalid frame template: %s", fname);
10681 return -1;
10682 }
10683
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010684 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010685 src_mac, sizeof(src_mac)) < 0 ||
10686 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
10687 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
10688 return -1;
10689 /* Use wildcard BSSID, since we are in PBSS */
10690 memset(&hdr->addr3, 0xFF, ETH_ALEN);
10691
10692 if (!isprobereq) {
10693 tag_index = find_template_frame_tag(tags, tags_total, 1);
10694 if (tag_index < 0) {
10695 sigma_dut_print(dut, DUT_MSG_ERROR,
10696 "can't find device id attribute");
10697 return -1;
10698 }
10699 if (parse_mac_address(dut, client_id,
10700 (unsigned char *) client_mac)) {
10701 sigma_dut_print(dut, DUT_MSG_ERROR,
10702 "invalid client_id: %s", client_id);
10703 return -1;
10704 }
10705 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10706 framelen - tags[tag_index].offset,
10707 IEEE80211_P2P_ATTR_DEVICE_ID,
10708 client_mac, ETH_ALEN)) {
10709 sigma_dut_print(dut, DUT_MSG_ERROR,
10710 "fail to replace device id attribute");
10711 return -1;
10712 }
10713
10714 /*
10715 * group_id arg contains device MAC address followed by
10716 * space and SSID (DIRECT-somessid).
10717 * group id attribute contains device address (6 bytes)
10718 * followed by SSID prefix DIRECT-XX (9 bytes)
10719 */
10720 if (strlen(group_id) < sizeof(device_macstr)) {
10721 sigma_dut_print(dut, DUT_MSG_ERROR,
10722 "group_id arg too short");
10723 return -1;
10724 }
10725 memcpy(device_macstr, group_id, sizeof(device_macstr));
10726 device_macstr[sizeof(device_macstr) - 1] = '\0';
10727 if (parse_mac_address(dut, device_macstr,
10728 (unsigned char *) group_id_attr)) {
10729 sigma_dut_print(dut, DUT_MSG_ERROR,
10730 "fail to parse device address from group_id");
10731 return -1;
10732 }
10733 group_ssid = strchr(group_id, ' ');
10734 if (!group_ssid) {
10735 sigma_dut_print(dut, DUT_MSG_ERROR,
10736 "invalid group_id arg, no ssid");
10737 return -1;
10738 }
10739 group_ssid++;
10740 len = strlen(group_ssid);
10741 if (len < group_ssid_prefix_len) {
10742 sigma_dut_print(dut, DUT_MSG_ERROR,
10743 "group_id SSID too short");
10744 return -1;
10745 }
10746 dst_len = sizeof(group_id_attr) - ETH_ALEN;
10747 if (len > dst_len) {
10748 sigma_dut_print(dut, DUT_MSG_ERROR,
10749 "group_id SSID (%s) too long",
10750 group_ssid);
10751 return -1;
10752 }
10753
10754 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
10755 tag_index = find_template_frame_tag(tags, tags_total, 2);
10756 if (tag_index < 0) {
10757 sigma_dut_print(dut, DUT_MSG_ERROR,
10758 "can't find group id attribute");
10759 return -1;
10760 }
10761 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10762 framelen - tags[tag_index].offset,
10763 IEEE80211_P2P_ATTR_GROUP_ID,
10764 group_id_attr,
10765 sizeof(group_id_attr))) {
10766 sigma_dut_print(dut, DUT_MSG_ERROR,
10767 "fail to replace group id attribute");
10768 return -1;
10769 }
10770 }
10771
10772 for (i = 0; i < count; i++) {
10773 if (wil6210_transmit_frame(dut, freq,
10774 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
10775 frame, framelen)) {
10776 sigma_dut_print(dut, DUT_MSG_ERROR,
10777 "fail to transmit probe request frame");
10778 return -1;
10779 }
10780 }
10781
10782 return 0;
10783}
10784
10785
Lior David0fe101e2017-03-09 16:09:50 +020010786int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10787 struct sigma_cmd *cmd)
10788{
10789 const char *frame_name = get_param(cmd, "framename");
10790 const char *mac = get_param(cmd, "dest_mac");
10791
10792 if (!frame_name || !mac) {
10793 sigma_dut_print(dut, DUT_MSG_ERROR,
10794 "framename and dest_mac must be provided");
10795 return -1;
10796 }
10797
10798 if (strcasecmp(frame_name, "brp") == 0) {
10799 const char *l_rx = get_param(cmd, "L-RX");
10800 int l_rx_i;
10801
10802 if (!l_rx) {
10803 sigma_dut_print(dut, DUT_MSG_ERROR,
10804 "L-RX must be provided");
10805 return -1;
10806 }
10807 l_rx_i = atoi(l_rx);
10808
10809 sigma_dut_print(dut, DUT_MSG_INFO,
10810 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
10811 mac, l_rx);
10812 if (l_rx_i != 16) {
10813 sigma_dut_print(dut, DUT_MSG_ERROR,
10814 "unsupported L-RX: %s", l_rx);
10815 return -1;
10816 }
10817
10818 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
10819 return -1;
10820 } else if (strcasecmp(frame_name, "ssw") == 0) {
10821 sigma_dut_print(dut, DUT_MSG_INFO,
10822 "dev_send_frame: SLS, dest_mac %s", mac);
10823 if (wil6210_send_sls(dut, mac))
10824 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010825 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
10826 (strcasecmp(frame_name, "devdiscreq") == 0)) {
10827 sigma_dut_print(dut, DUT_MSG_INFO,
10828 "dev_send_frame: %s, dest_mac %s", frame_name,
10829 mac);
10830 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
10831 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020010832 } else {
10833 sigma_dut_print(dut, DUT_MSG_ERROR,
10834 "unsupported frame type: %s", frame_name);
10835 return -1;
10836 }
10837
10838 return 1;
10839}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010840
Lior David0fe101e2017-03-09 16:09:50 +020010841#endif /* __linux__ */
10842
10843
10844static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
10845 struct sigma_conn *conn,
10846 struct sigma_cmd *cmd)
10847{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010848 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020010849#ifdef __linux__
10850 case DRIVER_WIL6210:
10851 return wil6210_send_frame_60g(dut, conn, cmd);
10852#endif /* __linux__ */
10853 default:
10854 send_resp(dut, conn, SIGMA_ERROR,
10855 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
10856 return 0;
10857 }
10858}
10859
10860
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010861static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
10862 const char *intf, struct sigma_cmd *cmd)
10863{
10864 const char *val, *addr;
10865 char buf[100];
10866
10867 addr = get_param(cmd, "DestMac");
10868 if (!addr) {
10869 send_resp(dut, conn, SIGMA_INVALID,
10870 "ErrorCode,AP MAC address is missing");
10871 return 0;
10872 }
10873
10874 val = get_param(cmd, "ANQPQuery_ID");
10875 if (!val) {
10876 send_resp(dut, conn, SIGMA_INVALID,
10877 "ErrorCode,Missing ANQPQuery_ID");
10878 return 0;
10879 }
10880
10881 if (strcasecmp(val, "NeighborReportReq") == 0) {
10882 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
10883 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
10884 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
10885 } else {
10886 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
10887 val);
10888 send_resp(dut, conn, SIGMA_INVALID,
10889 "ErrorCode,Invalid ANQPQuery_ID");
10890 return 0;
10891 }
10892
Ashwini Patild174f2c2017-04-13 16:49:46 +053010893 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
10894 * (Address3 = Wildcard BSSID when sent to not-associated AP;
10895 * if associated, AP BSSID).
10896 */
10897 if (wpa_command(intf, "SET gas_address3 1") < 0) {
10898 send_resp(dut, conn, SIGMA_ERROR,
10899 "ErrorCode,Failed to set gas_address3");
10900 return 0;
10901 }
10902
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010903 if (wpa_command(intf, buf) < 0) {
10904 send_resp(dut, conn, SIGMA_ERROR,
10905 "ErrorCode,Failed to send ANQP query");
10906 return 0;
10907 }
10908
10909 return 1;
10910}
10911
10912
10913static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
10914 struct sigma_conn *conn,
10915 const char *intf,
10916 struct sigma_cmd *cmd)
10917{
10918 const char *val = get_param(cmd, "FrameName");
10919
10920 if (val && strcasecmp(val, "ANQPQuery") == 0)
10921 return mbo_send_anqp_query(dut, conn, intf, cmd);
10922
10923 return 2;
10924}
10925
10926
Jouni Malinenf7222712019-06-13 01:50:21 +030010927enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
10928 struct sigma_conn *conn,
10929 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010930{
10931 const char *intf = get_param(cmd, "Interface");
10932 const char *val;
10933 enum send_frame_type frame;
10934 enum send_frame_protection protected;
10935 char buf[100];
10936 unsigned char addr[ETH_ALEN];
10937 int res;
10938
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010939 if (!intf)
10940 return -1;
10941
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010942 val = get_param(cmd, "program");
10943 if (val == NULL)
10944 val = get_param(cmd, "frame");
10945 if (val && strcasecmp(val, "TDLS") == 0)
10946 return cmd_sta_send_frame_tdls(dut, conn, cmd);
10947 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030010948 strcasecmp(val, "HS2-R2") == 0 ||
10949 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010950 return cmd_sta_send_frame_hs2(dut, conn, cmd);
10951 if (val && strcasecmp(val, "VHT") == 0)
10952 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010953 if (val && strcasecmp(val, "HE") == 0)
10954 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070010955 if (val && strcasecmp(val, "LOC") == 0)
10956 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020010957 if (val && strcasecmp(val, "60GHz") == 0)
10958 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010959 if (val && strcasecmp(val, "MBO") == 0) {
10960 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
10961 if (res != 2)
10962 return res;
10963 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010964
10965 val = get_param(cmd, "TD_DISC");
10966 if (val) {
10967 if (hwaddr_aton(val, addr) < 0)
10968 return -1;
10969 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
10970 if (wpa_command(intf, buf) < 0) {
10971 send_resp(dut, conn, SIGMA_ERROR,
10972 "ErrorCode,Failed to send TDLS discovery");
10973 return 0;
10974 }
10975 return 1;
10976 }
10977
10978 val = get_param(cmd, "TD_Setup");
10979 if (val) {
10980 if (hwaddr_aton(val, addr) < 0)
10981 return -1;
10982 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
10983 if (wpa_command(intf, buf) < 0) {
10984 send_resp(dut, conn, SIGMA_ERROR,
10985 "ErrorCode,Failed to start TDLS setup");
10986 return 0;
10987 }
10988 return 1;
10989 }
10990
10991 val = get_param(cmd, "TD_TearDown");
10992 if (val) {
10993 if (hwaddr_aton(val, addr) < 0)
10994 return -1;
10995 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
10996 if (wpa_command(intf, buf) < 0) {
10997 send_resp(dut, conn, SIGMA_ERROR,
10998 "ErrorCode,Failed to tear down TDLS link");
10999 return 0;
11000 }
11001 return 1;
11002 }
11003
11004 val = get_param(cmd, "TD_ChannelSwitch");
11005 if (val) {
11006 /* TODO */
11007 send_resp(dut, conn, SIGMA_ERROR,
11008 "ErrorCode,TD_ChannelSwitch not yet supported");
11009 return 0;
11010 }
11011
11012 val = get_param(cmd, "TD_NF");
11013 if (val) {
11014 /* TODO */
11015 send_resp(dut, conn, SIGMA_ERROR,
11016 "ErrorCode,TD_NF not yet supported");
11017 return 0;
11018 }
11019
11020 val = get_param(cmd, "PMFFrameType");
11021 if (val == NULL)
11022 val = get_param(cmd, "FrameName");
11023 if (val == NULL)
11024 val = get_param(cmd, "Type");
11025 if (val == NULL)
11026 return -1;
11027 if (strcasecmp(val, "disassoc") == 0)
11028 frame = DISASSOC;
11029 else if (strcasecmp(val, "deauth") == 0)
11030 frame = DEAUTH;
11031 else if (strcasecmp(val, "saquery") == 0)
11032 frame = SAQUERY;
11033 else if (strcasecmp(val, "auth") == 0)
11034 frame = AUTH;
11035 else if (strcasecmp(val, "assocreq") == 0)
11036 frame = ASSOCREQ;
11037 else if (strcasecmp(val, "reassocreq") == 0)
11038 frame = REASSOCREQ;
11039 else if (strcasecmp(val, "neigreq") == 0) {
11040 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
11041
11042 val = get_param(cmd, "ssid");
11043 if (val == NULL)
11044 return -1;
11045
11046 res = send_neighbor_request(dut, intf, val);
11047 if (res) {
11048 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11049 "Failed to send neighbor report request");
11050 return 0;
11051 }
11052
11053 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053011054 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
11055 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011056 sigma_dut_print(dut, DUT_MSG_DEBUG,
11057 "Got Transition Management Query");
11058
Ashwini Patil5acd7382017-04-13 15:55:04 +053011059 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011060 if (res) {
11061 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11062 "Failed to send Transition Management Query");
11063 return 0;
11064 }
11065
11066 return 1;
11067 } else {
11068 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11069 "PMFFrameType");
11070 return 0;
11071 }
11072
11073 val = get_param(cmd, "PMFProtected");
11074 if (val == NULL)
11075 val = get_param(cmd, "Protected");
11076 if (val == NULL)
11077 return -1;
11078 if (strcasecmp(val, "Correct-key") == 0 ||
11079 strcasecmp(val, "CorrectKey") == 0)
11080 protected = CORRECT_KEY;
11081 else if (strcasecmp(val, "IncorrectKey") == 0)
11082 protected = INCORRECT_KEY;
11083 else if (strcasecmp(val, "Unprotected") == 0)
11084 protected = UNPROTECTED;
11085 else {
11086 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11087 "PMFProtected");
11088 return 0;
11089 }
11090
11091 if (protected != UNPROTECTED &&
11092 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
11093 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
11094 "PMFProtected for auth/assocreq/reassocreq");
11095 return 0;
11096 }
11097
11098 if (if_nametoindex("sigmadut") == 0) {
11099 snprintf(buf, sizeof(buf),
11100 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011101 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011102 if (system(buf) != 0 ||
11103 if_nametoindex("sigmadut") == 0) {
11104 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11105 "monitor interface with '%s'", buf);
11106 return -2;
11107 }
11108 }
11109
11110 if (system("ifconfig sigmadut up") != 0) {
11111 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11112 "monitor interface up");
11113 return -2;
11114 }
11115
11116 return sta_inject_frame(dut, conn, frame, protected, NULL);
11117}
11118
11119
11120static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
11121 struct sigma_conn *conn,
11122 struct sigma_cmd *cmd,
11123 const char *ifname)
11124{
11125 char buf[200];
11126 const char *val;
11127
11128 val = get_param(cmd, "ClearARP");
11129 if (val && atoi(val) == 1) {
11130 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
11131 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11132 if (system(buf) != 0) {
11133 send_resp(dut, conn, SIGMA_ERROR,
11134 "errorCode,Failed to clear ARP cache");
11135 return 0;
11136 }
11137 }
11138
11139 return 1;
11140}
11141
11142
11143int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
11144 struct sigma_cmd *cmd)
11145{
11146 const char *intf = get_param(cmd, "Interface");
11147 const char *val;
11148
11149 if (intf == NULL)
11150 return -1;
11151
11152 val = get_param(cmd, "program");
11153 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011154 strcasecmp(val, "HS2-R2") == 0 ||
11155 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011156 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
11157
11158 return -1;
11159}
11160
11161
Jouni Malinenf7222712019-06-13 01:50:21 +030011162static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
11163 struct sigma_conn *conn,
11164 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011165{
11166 const char *intf = get_param(cmd, "Interface");
11167 const char *mac = get_param(cmd, "MAC");
11168
11169 if (intf == NULL || mac == NULL)
11170 return -1;
11171
11172 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
11173 "interface %s to %s", intf, mac);
11174
11175 if (dut->set_macaddr) {
11176 char buf[128];
11177 int res;
11178 if (strcasecmp(mac, "default") == 0) {
11179 res = snprintf(buf, sizeof(buf), "%s",
11180 dut->set_macaddr);
11181 dut->tmp_mac_addr = 0;
11182 } else {
11183 res = snprintf(buf, sizeof(buf), "%s %s",
11184 dut->set_macaddr, mac);
11185 dut->tmp_mac_addr = 1;
11186 }
11187 if (res < 0 || res >= (int) sizeof(buf))
11188 return -1;
11189 if (system(buf) != 0) {
11190 send_resp(dut, conn, SIGMA_ERROR,
11191 "errorCode,Failed to set MAC "
11192 "address");
11193 return 0;
11194 }
11195 return 1;
11196 }
11197
11198 if (strcasecmp(mac, "default") == 0)
11199 return 1;
11200
11201 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11202 "command");
11203 return 0;
11204}
11205
11206
11207static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
11208 struct sigma_conn *conn, const char *intf,
11209 int val)
11210{
11211 char buf[200];
11212 int res;
11213
11214 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
11215 intf, val);
11216 if (res < 0 || res >= (int) sizeof(buf))
11217 return -1;
11218 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11219 if (system(buf) != 0) {
11220 send_resp(dut, conn, SIGMA_ERROR,
11221 "errorCode,Failed to configure offchannel mode");
11222 return 0;
11223 }
11224
11225 return 1;
11226}
11227
11228
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011229static int off_chan_val(enum sec_ch_offset off)
11230{
11231 switch (off) {
11232 case SEC_CH_NO:
11233 return 0;
11234 case SEC_CH_40ABOVE:
11235 return 40;
11236 case SEC_CH_40BELOW:
11237 return -40;
11238 }
11239
11240 return 0;
11241}
11242
11243
11244static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
11245 const char *intf, int off_ch_num,
11246 enum sec_ch_offset sec)
11247{
11248 char buf[200];
11249 int res;
11250
11251 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
11252 intf, off_ch_num);
11253 if (res < 0 || res >= (int) sizeof(buf))
11254 return -1;
11255 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11256 if (system(buf) != 0) {
11257 send_resp(dut, conn, SIGMA_ERROR,
11258 "errorCode,Failed to set offchan");
11259 return 0;
11260 }
11261
11262 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
11263 intf, off_chan_val(sec));
11264 if (res < 0 || res >= (int) sizeof(buf))
11265 return -1;
11266 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11267 if (system(buf) != 0) {
11268 send_resp(dut, conn, SIGMA_ERROR,
11269 "errorCode,Failed to set sec chan offset");
11270 return 0;
11271 }
11272
11273 return 1;
11274}
11275
11276
11277static int tdls_set_offchannel_offset(struct sigma_dut *dut,
11278 struct sigma_conn *conn,
11279 const char *intf, int off_ch_num,
11280 enum sec_ch_offset sec)
11281{
11282 char buf[200];
11283 int res;
11284
11285 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
11286 off_ch_num);
11287 if (res < 0 || res >= (int) sizeof(buf))
11288 return -1;
11289 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11290
11291 if (wpa_command(intf, buf) < 0) {
11292 send_resp(dut, conn, SIGMA_ERROR,
11293 "ErrorCode,Failed to set offchan");
11294 return 0;
11295 }
11296 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
11297 off_chan_val(sec));
11298 if (res < 0 || res >= (int) sizeof(buf))
11299 return -1;
11300
11301 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11302
11303 if (wpa_command(intf, buf) < 0) {
11304 send_resp(dut, conn, SIGMA_ERROR,
11305 "ErrorCode,Failed to set sec chan offset");
11306 return 0;
11307 }
11308
11309 return 1;
11310}
11311
11312
11313static int tdls_set_offchannel_mode(struct sigma_dut *dut,
11314 struct sigma_conn *conn,
11315 const char *intf, int val)
11316{
11317 char buf[200];
11318 int res;
11319
11320 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
11321 val);
11322 if (res < 0 || res >= (int) sizeof(buf))
11323 return -1;
11324 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11325
11326 if (wpa_command(intf, buf) < 0) {
11327 send_resp(dut, conn, SIGMA_ERROR,
11328 "ErrorCode,Failed to configure offchannel mode");
11329 return 0;
11330 }
11331
11332 return 1;
11333}
11334
11335
11336static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
11337 struct sigma_conn *conn,
11338 struct sigma_cmd *cmd)
11339{
11340 const char *val;
11341 enum {
11342 CHSM_NOT_SET,
11343 CHSM_ENABLE,
11344 CHSM_DISABLE,
11345 CHSM_REJREQ,
11346 CHSM_UNSOLRESP
11347 } chsm = CHSM_NOT_SET;
11348 int off_ch_num = -1;
11349 enum sec_ch_offset sec_ch = SEC_CH_NO;
11350 int res;
11351
11352 val = get_param(cmd, "Uapsd");
11353 if (val) {
11354 char buf[100];
11355 if (strcasecmp(val, "Enable") == 0)
11356 snprintf(buf, sizeof(buf), "SET ps 99");
11357 else if (strcasecmp(val, "Disable") == 0)
11358 snprintf(buf, sizeof(buf), "SET ps 98");
11359 else {
11360 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11361 "Unsupported uapsd parameter value");
11362 return 0;
11363 }
11364 if (wpa_command(intf, buf)) {
11365 send_resp(dut, conn, SIGMA_ERROR,
11366 "ErrorCode,Failed to change U-APSD "
11367 "powersave mode");
11368 return 0;
11369 }
11370 }
11371
11372 val = get_param(cmd, "TPKTIMER");
11373 if (val && strcasecmp(val, "DISABLE") == 0) {
11374 if (wpa_command(intf, "SET tdls_testing 0x100")) {
11375 send_resp(dut, conn, SIGMA_ERROR,
11376 "ErrorCode,Failed to enable no TPK "
11377 "expiration test mode");
11378 return 0;
11379 }
11380 dut->no_tpk_expiration = 1;
11381 }
11382
11383 val = get_param(cmd, "ChSwitchMode");
11384 if (val) {
11385 if (strcasecmp(val, "Enable") == 0 ||
11386 strcasecmp(val, "Initiate") == 0)
11387 chsm = CHSM_ENABLE;
11388 else if (strcasecmp(val, "Disable") == 0 ||
11389 strcasecmp(val, "passive") == 0)
11390 chsm = CHSM_DISABLE;
11391 else if (strcasecmp(val, "RejReq") == 0)
11392 chsm = CHSM_REJREQ;
11393 else if (strcasecmp(val, "UnSolResp") == 0)
11394 chsm = CHSM_UNSOLRESP;
11395 else {
11396 send_resp(dut, conn, SIGMA_ERROR,
11397 "ErrorCode,Unknown ChSwitchMode value");
11398 return 0;
11399 }
11400 }
11401
11402 val = get_param(cmd, "OffChNum");
11403 if (val) {
11404 off_ch_num = atoi(val);
11405 if (off_ch_num == 0) {
11406 send_resp(dut, conn, SIGMA_ERROR,
11407 "ErrorCode,Invalid OffChNum");
11408 return 0;
11409 }
11410 }
11411
11412 val = get_param(cmd, "SecChOffset");
11413 if (val) {
11414 if (strcmp(val, "20") == 0)
11415 sec_ch = SEC_CH_NO;
11416 else if (strcasecmp(val, "40above") == 0)
11417 sec_ch = SEC_CH_40ABOVE;
11418 else if (strcasecmp(val, "40below") == 0)
11419 sec_ch = SEC_CH_40BELOW;
11420 else {
11421 send_resp(dut, conn, SIGMA_ERROR,
11422 "ErrorCode,Unknown SecChOffset value");
11423 return 0;
11424 }
11425 }
11426
11427 if (chsm == CHSM_NOT_SET) {
11428 /* no offchannel changes requested */
11429 return 1;
11430 }
11431
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011432 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
11433 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011434 send_resp(dut, conn, SIGMA_ERROR,
11435 "ErrorCode,Unknown interface");
11436 return 0;
11437 }
11438
11439 switch (chsm) {
11440 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030011441 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011442 break;
11443 case CHSM_ENABLE:
11444 if (off_ch_num < 0) {
11445 send_resp(dut, conn, SIGMA_ERROR,
11446 "ErrorCode,Missing OffChNum argument");
11447 return 0;
11448 }
11449 if (wifi_chip_type == DRIVER_WCN) {
11450 res = tdls_set_offchannel_offset(dut, conn, intf,
11451 off_ch_num, sec_ch);
11452 } else {
11453 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11454 sec_ch);
11455 }
11456 if (res != 1)
11457 return res;
11458 if (wifi_chip_type == DRIVER_WCN)
11459 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
11460 else
11461 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
11462 break;
11463 case CHSM_DISABLE:
11464 if (wifi_chip_type == DRIVER_WCN)
11465 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
11466 else
11467 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
11468 break;
11469 case CHSM_REJREQ:
11470 if (wifi_chip_type == DRIVER_WCN)
11471 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
11472 else
11473 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
11474 break;
11475 case CHSM_UNSOLRESP:
11476 if (off_ch_num < 0) {
11477 send_resp(dut, conn, SIGMA_ERROR,
11478 "ErrorCode,Missing OffChNum argument");
11479 return 0;
11480 }
11481 if (wifi_chip_type == DRIVER_WCN) {
11482 res = tdls_set_offchannel_offset(dut, conn, intf,
11483 off_ch_num, sec_ch);
11484 } else {
11485 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11486 sec_ch);
11487 }
11488 if (res != 1)
11489 return res;
11490 if (wifi_chip_type == DRIVER_WCN)
11491 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
11492 else
11493 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
11494 break;
11495 }
11496
11497 return res;
11498}
11499
11500
11501static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11502 struct sigma_conn *conn,
11503 struct sigma_cmd *cmd)
11504{
11505 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011506 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011507
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011508 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080011509
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011510 val = get_param(cmd, "nss_mcs_opt");
11511 if (val) {
11512 /* String (nss_operating_mode; mcs_operating_mode) */
11513 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011514 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011515
11516 token = strdup(val);
11517 if (!token)
11518 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011519 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011520 if (!result) {
11521 sigma_dut_print(dut, DUT_MSG_ERROR,
11522 "VHT NSS not specified");
11523 goto failed;
11524 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011525 if (strcasecmp(result, "def") != 0) {
11526 nss = atoi(result);
11527 if (nss == 4)
11528 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011529 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011530 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011531
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011532 }
11533
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011534 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011535 if (!result) {
11536 sigma_dut_print(dut, DUT_MSG_ERROR,
11537 "VHT MCS not specified");
11538 goto failed;
11539 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011540 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011541 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011542 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011543 } else {
11544 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011545 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011546 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011547 }
11548 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011549 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011550 }
11551
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011552 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011553 return 1;
11554failed:
11555 free(token);
11556 return 0;
11557}
11558
11559
11560static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11561 struct sigma_conn *conn,
11562 struct sigma_cmd *cmd)
11563{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011564 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011565 case DRIVER_ATHEROS:
11566 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
11567 default:
11568 send_resp(dut, conn, SIGMA_ERROR,
11569 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
11570 return 0;
11571 }
11572}
11573
11574
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011575static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11576 struct sigma_conn *conn,
11577 struct sigma_cmd *cmd)
11578{
11579 const char *val;
11580 char *token = NULL, *result;
11581 char buf[60];
11582
11583 val = get_param(cmd, "nss_mcs_opt");
11584 if (val) {
11585 /* String (nss_operating_mode; mcs_operating_mode) */
11586 int nss, mcs, ratecode;
11587 char *saveptr;
11588
11589 token = strdup(val);
11590 if (!token)
11591 return -2;
11592
11593 result = strtok_r(token, ";", &saveptr);
11594 if (!result) {
11595 sigma_dut_print(dut, DUT_MSG_ERROR,
11596 "HE NSS not specified");
11597 goto failed;
11598 }
11599 nss = 1;
11600 if (strcasecmp(result, "def") != 0)
11601 nss = atoi(result);
11602
11603 result = strtok_r(NULL, ";", &saveptr);
11604 if (!result) {
11605 sigma_dut_print(dut, DUT_MSG_ERROR,
11606 "HE MCS not specified");
11607 goto failed;
11608 }
11609 mcs = 7;
11610 if (strcasecmp(result, "def") != 0)
11611 mcs = atoi(result);
11612
Arif Hussain557bf412018-05-25 17:29:36 -070011613 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011614 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070011615 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011616 } else if (nss > 2) {
11617 sigma_dut_print(dut, DUT_MSG_ERROR,
11618 "HE NSS %d not supported", nss);
11619 goto failed;
11620 }
11621
Arif Hussain557bf412018-05-25 17:29:36 -070011622 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
11623 if (system(buf) != 0) {
11624 sigma_dut_print(dut, DUT_MSG_ERROR,
11625 "nss_mcs_opt: iwpriv %s nss %d failed",
11626 intf, nss);
11627 goto failed;
11628 }
Arif Hussainac6c5112018-05-25 17:34:00 -070011629 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070011630
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011631 /* Add the MCS to the ratecode */
11632 if (mcs >= 0 && mcs <= 11) {
11633 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070011634#ifdef NL80211_SUPPORT
11635 if (dut->device_type == STA_testbed) {
11636 enum he_mcs_config mcs_config;
11637 int ret;
11638
11639 if (mcs <= 7)
11640 mcs_config = HE_80_MCS0_7;
11641 else if (mcs <= 9)
11642 mcs_config = HE_80_MCS0_9;
11643 else
11644 mcs_config = HE_80_MCS0_11;
11645 ret = sta_set_he_mcs(dut, intf, mcs_config);
11646 if (ret) {
11647 sigma_dut_print(dut, DUT_MSG_ERROR,
11648 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
11649 mcs, mcs_config, ret);
11650 goto failed;
11651 }
11652 }
11653#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011654 } else {
11655 sigma_dut_print(dut, DUT_MSG_ERROR,
11656 "HE MCS %d not supported", mcs);
11657 goto failed;
11658 }
11659 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
11660 intf, ratecode);
11661 if (system(buf) != 0) {
11662 sigma_dut_print(dut, DUT_MSG_ERROR,
11663 "iwpriv setting of 11ax rates failed");
11664 goto failed;
11665 }
11666 free(token);
11667 }
11668
11669 val = get_param(cmd, "GI");
11670 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011671 int fix_rate_sgi;
11672
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011673 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011674 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011675 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011676 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011677 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
11678 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011679 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011680 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011681 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
11682 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011683 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011684 } else {
11685 send_resp(dut, conn, SIGMA_ERROR,
11686 "errorCode,GI value not supported");
11687 return 0;
11688 }
11689 if (system(buf) != 0) {
11690 send_resp(dut, conn, SIGMA_ERROR,
11691 "errorCode,Failed to set shortgi");
11692 return 0;
11693 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011694 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
11695 intf, fix_rate_sgi);
11696 if (system(buf) != 0) {
11697 send_resp(dut, conn, SIGMA_ERROR,
11698 "errorCode,Failed to set fix rate shortgi");
11699 return STATUS_SENT;
11700 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011701 }
11702
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011703 val = get_param(cmd, "LTF");
11704 if (val) {
11705#ifdef NL80211_SUPPORT
11706 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011707 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011708 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011709 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011710 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011711 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011712 } else {
11713 send_resp(dut, conn, SIGMA_ERROR,
11714 "errorCode, LTF value not supported");
11715 return 0;
11716 }
11717#else /* NL80211_SUPPORT */
11718 sigma_dut_print(dut, DUT_MSG_ERROR,
11719 "LTF cannot be set without NL80211_SUPPORT defined");
11720 return -2;
11721#endif /* NL80211_SUPPORT */
11722 }
11723
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070011724 val = get_param(cmd, "TxSUPPDU");
11725 if (val) {
11726 int set_val = 1;
11727
11728 if (strcasecmp(val, "Enable") == 0)
11729 set_val = 1;
11730 else if (strcasecmp(val, "Disable") == 0)
11731 set_val = 0;
11732
11733 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
11734 send_resp(dut, conn, SIGMA_ERROR,
11735 "ErrorCode,Failed to set Tx SU PPDU config");
11736 return 0;
11737 }
11738 }
11739
Arif Hussain480d5f42019-03-12 14:40:42 -070011740 val = get_param(cmd, "TWT_Setup");
11741 if (val) {
11742 if (strcasecmp(val, "Request") == 0) {
11743 if (sta_twt_request(dut, conn, cmd)) {
11744 send_resp(dut, conn, SIGMA_ERROR,
11745 "ErrorCode,sta_twt_request failed");
11746 return STATUS_SENT;
11747 }
11748 } else if (strcasecmp(val, "Teardown") == 0) {
11749 if (sta_twt_teardown(dut, conn, cmd)) {
11750 send_resp(dut, conn, SIGMA_ERROR,
11751 "ErrorCode,sta_twt_teardown failed");
11752 return STATUS_SENT;
11753 }
11754 }
11755 }
11756
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080011757 val = get_param(cmd, "transmitOMI");
11758 if (val && sta_transmit_omi(dut, conn, cmd)) {
11759 send_resp(dut, conn, SIGMA_ERROR,
11760 "ErrorCode,sta_transmit_omi failed");
11761 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070011762 }
11763
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011764 val = get_param(cmd, "Powersave");
11765 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011766 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011767
11768 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011769 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011770 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011771 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011772 } else {
11773 sigma_dut_print(dut, DUT_MSG_ERROR,
11774 "Unsupported Powersave value '%s'",
11775 val);
11776 return -1;
11777 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011778 if (set_power_save_wcn(dut, intf, ps) < 0)
11779 return 0;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011780 }
11781
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080011782 val = get_param(cmd, "MU_EDCA");
11783 if (val) {
11784 if (strcasecmp(val, "Override") == 0) {
11785 if (sta_set_mu_edca_override(dut, intf, 1)) {
11786 send_resp(dut, conn, SIGMA_ERROR,
11787 "errorCode,MU EDCA override set failed");
11788 return STATUS_SENT;
11789 }
11790 } else if (strcasecmp(val, "Disable") == 0) {
11791 if (sta_set_mu_edca_override(dut, intf, 0)) {
11792 send_resp(dut, conn, SIGMA_ERROR,
11793 "errorCode,MU EDCA override disable failed");
11794 return STATUS_SENT;
11795 }
11796 }
11797 }
11798
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011799 return 1;
11800
11801failed:
11802 free(token);
11803 return -2;
11804}
11805
11806
11807static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11808 struct sigma_conn *conn,
11809 struct sigma_cmd *cmd)
11810{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011811 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011812 case DRIVER_WCN:
11813 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
11814 default:
11815 send_resp(dut, conn, SIGMA_ERROR,
11816 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
11817 return 0;
11818 }
11819}
11820
11821
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011822static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
11823 struct sigma_conn *conn,
11824 struct sigma_cmd *cmd)
11825{
11826 const char *val;
11827
11828 val = get_param(cmd, "powersave");
11829 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011830 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011831
11832 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011833 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011834 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011835 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011836 } else {
11837 sigma_dut_print(dut, DUT_MSG_ERROR,
11838 "Unsupported power save config");
11839 return -1;
11840 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011841 if (set_power_save_wcn(dut, intf, ps) < 0)
11842 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011843 return 1;
11844 }
11845
11846 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
11847
11848 return 0;
11849}
11850
11851
Ashwini Patil5acd7382017-04-13 15:55:04 +053011852static int btm_query_candidate_list(struct sigma_dut *dut,
11853 struct sigma_conn *conn,
11854 struct sigma_cmd *cmd)
11855{
11856 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
11857 int len, ret;
11858 char buf[10];
11859
11860 /*
11861 * Neighbor Report elements format:
11862 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
11863 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
11864 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
11865 */
11866
11867 bssid = get_param(cmd, "Nebor_BSSID");
11868 if (!bssid) {
11869 send_resp(dut, conn, SIGMA_INVALID,
11870 "errorCode,Nebor_BSSID is missing");
11871 return 0;
11872 }
11873
11874 info = get_param(cmd, "Nebor_Bssid_Info");
11875 if (!info) {
11876 sigma_dut_print(dut, DUT_MSG_INFO,
11877 "Using default value for Nebor_Bssid_Info: %s",
11878 DEFAULT_NEIGHBOR_BSSID_INFO);
11879 info = DEFAULT_NEIGHBOR_BSSID_INFO;
11880 }
11881
11882 op_class = get_param(cmd, "Nebor_Op_Class");
11883 if (!op_class) {
11884 send_resp(dut, conn, SIGMA_INVALID,
11885 "errorCode,Nebor_Op_Class is missing");
11886 return 0;
11887 }
11888
11889 ch = get_param(cmd, "Nebor_Op_Ch");
11890 if (!ch) {
11891 send_resp(dut, conn, SIGMA_INVALID,
11892 "errorCode,Nebor_Op_Ch is missing");
11893 return 0;
11894 }
11895
11896 phy_type = get_param(cmd, "Nebor_Phy_Type");
11897 if (!phy_type) {
11898 sigma_dut_print(dut, DUT_MSG_INFO,
11899 "Using default value for Nebor_Phy_Type: %s",
11900 DEFAULT_NEIGHBOR_PHY_TYPE);
11901 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
11902 }
11903
11904 /* Parse optional subelements */
11905 buf[0] = '\0';
11906 pref = get_param(cmd, "Nebor_Pref");
11907 if (pref) {
11908 /* hexdump for preferrence subelement */
11909 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
11910 if (ret < 0 || ret >= (int) sizeof(buf)) {
11911 sigma_dut_print(dut, DUT_MSG_ERROR,
11912 "snprintf failed for optional subelement ret: %d",
11913 ret);
11914 send_resp(dut, conn, SIGMA_ERROR,
11915 "errorCode,snprintf failed for subelement");
11916 return 0;
11917 }
11918 }
11919
11920 if (!dut->btm_query_cand_list) {
11921 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
11922 if (!dut->btm_query_cand_list) {
11923 send_resp(dut, conn, SIGMA_ERROR,
11924 "errorCode,Failed to allocate memory for btm_query_cand_list");
11925 return 0;
11926 }
11927 }
11928
11929 len = strlen(dut->btm_query_cand_list);
11930 ret = snprintf(dut->btm_query_cand_list + len,
11931 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
11932 bssid, info, op_class, ch, phy_type, buf);
11933 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
11934 sigma_dut_print(dut, DUT_MSG_ERROR,
11935 "snprintf failed for neighbor report list ret: %d",
11936 ret);
11937 send_resp(dut, conn, SIGMA_ERROR,
11938 "errorCode,snprintf failed for neighbor report");
11939 free(dut->btm_query_cand_list);
11940 dut->btm_query_cand_list = NULL;
11941 return 0;
11942 }
11943
11944 return 1;
11945}
11946
11947
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011948int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
11949 struct sigma_ese_alloc *allocs, int *allocs_size)
11950{
11951 int max_count = *allocs_size;
11952 int count = 0, i;
11953 const char *val;
11954
11955 do {
11956 val = get_param_indexed(cmd, "AllocID", count);
11957 if (val)
11958 count++;
11959 } while (val);
11960
11961 if (count == 0 || count > max_count) {
11962 sigma_dut_print(dut, DUT_MSG_ERROR,
11963 "Invalid number of allocations(%d)", count);
11964 return -1;
11965 }
11966
11967 for (i = 0; i < count; i++) {
11968 val = get_param_indexed(cmd, "PercentBI", i);
11969 if (!val) {
11970 sigma_dut_print(dut, DUT_MSG_ERROR,
11971 "Missing PercentBI parameter at index %d",
11972 i);
11973 return -1;
11974 }
11975 allocs[i].percent_bi = atoi(val);
11976
11977 val = get_param_indexed(cmd, "SrcAID", i);
11978 if (val)
11979 allocs[i].src_aid = strtol(val, NULL, 0);
11980 else
11981 allocs[i].src_aid = ESE_BCAST_AID;
11982
11983 val = get_param_indexed(cmd, "DestAID", i);
11984 if (val)
11985 allocs[i].dst_aid = strtol(val, NULL, 0);
11986 else
11987 allocs[i].dst_aid = ESE_BCAST_AID;
11988
11989 allocs[i].type = ESE_CBAP;
11990 sigma_dut_print(dut, DUT_MSG_INFO,
11991 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
11992 i, allocs[i].percent_bi, allocs[i].src_aid,
11993 allocs[i].dst_aid);
11994 }
11995
11996 *allocs_size = count;
11997 return 0;
11998}
11999
12000
12001static int sta_set_60g_ese(struct sigma_dut *dut, int count,
12002 struct sigma_ese_alloc *allocs)
12003{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012004 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012005#ifdef __linux__
12006 case DRIVER_WIL6210:
12007 if (wil6210_set_ese(dut, count, allocs))
12008 return -1;
12009 return 1;
12010#endif /* __linux__ */
12011 default:
12012 sigma_dut_print(dut, DUT_MSG_ERROR,
12013 "Unsupported sta_set_60g_ese with the current driver");
12014 return -1;
12015 }
12016}
12017
12018
12019static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
12020 struct sigma_conn *conn,
12021 struct sigma_cmd *cmd)
12022{
12023 const char *val;
12024
12025 val = get_param(cmd, "ExtSchIE");
12026 if (val && !strcasecmp(val, "Enable")) {
12027 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
12028 int count = MAX_ESE_ALLOCS;
12029
12030 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
12031 return -1;
12032 return sta_set_60g_ese(dut, count, allocs);
12033 }
12034
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012035 val = get_param(cmd, "MCS_FixedRate");
12036 if (val) {
12037 int sta_mcs = atoi(val);
12038
12039 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
12040 sta_mcs);
12041 wil6210_set_force_mcs(dut, 1, sta_mcs);
12042
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012043 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012044 }
12045
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012046 send_resp(dut, conn, SIGMA_ERROR,
12047 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012048 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012049}
12050
12051
Jouni Malinen6250cb02020-04-15 13:54:45 +030012052static enum sigma_cmd_result
12053cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
12054 struct sigma_conn *conn,
12055 struct sigma_cmd *cmd)
12056{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012057 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030012058
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053012059 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030012060 if (val && atoi(val) == 1) {
12061 if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
12062 send_resp(dut, conn, SIGMA_ERROR,
12063 "errorCode,Failed to set ft_rsnxe_used");
12064 return STATUS_SENT_ERROR;
12065 }
12066 return SUCCESS_SEND_STATUS;
12067 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012068
12069 oci_chan = get_param(cmd, "OCIChannel");
12070 oci_frametype = get_param(cmd, "OCIFrameType");
12071 if (oci_chan && oci_frametype) {
12072 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
12073 char buf[100];
12074
12075 if (!oci_freq) {
12076 send_resp(dut, conn, SIGMA_ERROR,
12077 "errorCode,Invalid OCIChannel number");
12078 return STATUS_SENT_ERROR;
12079 }
12080
12081 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
12082 snprintf(buf, sizeof(buf),
12083 "SET oci_freq_override_eapol %d", oci_freq);
12084 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12085 snprintf(buf, sizeof(buf),
12086 "SET oci_freq_override_saquery_req %d",
12087 oci_freq);
12088 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12089 snprintf(buf, sizeof(buf),
12090 "SET oci_freq_override_saquery_resp %d",
12091 oci_freq);
12092 } else {
12093 send_resp(dut, conn, SIGMA_ERROR,
12094 "errorCode,Unsupported OCIFrameType");
12095 return STATUS_SENT_ERROR;
12096 }
12097 if (wpa_command(intf, buf) < 0) {
12098 send_resp(dut, conn, SIGMA_ERROR,
12099 "errorCode,Failed to set oci_freq_override");
12100 return STATUS_SENT_ERROR;
12101 }
12102 return SUCCESS_SEND_STATUS;
12103 }
12104
Jouni Malinen6250cb02020-04-15 13:54:45 +030012105 send_resp(dut, conn, SIGMA_ERROR,
12106 "errorCode,Unsupported WPA3 rfeature");
12107 return STATUS_SENT_ERROR;
12108}
12109
12110
Jouni Malinenf7222712019-06-13 01:50:21 +030012111static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
12112 struct sigma_conn *conn,
12113 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012114{
12115 const char *intf = get_param(cmd, "Interface");
12116 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012117 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012118
12119 if (intf == NULL || prog == NULL)
12120 return -1;
12121
Ashwini Patil5acd7382017-04-13 15:55:04 +053012122 /* BSS Transition candidate list for BTM query */
12123 val = get_param(cmd, "Nebor_BSSID");
12124 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
12125 return 0;
12126
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012127 if (strcasecmp(prog, "TDLS") == 0)
12128 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
12129
12130 if (strcasecmp(prog, "VHT") == 0)
12131 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
12132
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012133 if (strcasecmp(prog, "HE") == 0)
12134 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
12135
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012136 if (strcasecmp(prog, "MBO") == 0) {
12137 val = get_param(cmd, "Cellular_Data_Cap");
12138 if (val &&
12139 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12140 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053012141
12142 val = get_param(cmd, "Ch_Pref");
12143 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12144 return 0;
12145
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012146 return 1;
12147 }
12148
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012149 if (strcasecmp(prog, "60GHz") == 0)
12150 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
12151
Jouni Malinen6250cb02020-04-15 13:54:45 +030012152 if (strcasecmp(prog, "WPA3") == 0)
12153 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
12154
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012155 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
12156 return 0;
12157}
12158
12159
Jouni Malinenf7222712019-06-13 01:50:21 +030012160static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
12161 struct sigma_conn *conn,
12162 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012163{
12164 const char *intf = get_param(cmd, "Interface");
12165 const char *mode = get_param(cmd, "Mode");
12166 int res;
12167
12168 if (intf == NULL || mode == NULL)
12169 return -1;
12170
12171 if (strcasecmp(mode, "On") == 0)
12172 res = wpa_command(intf, "SET radio_disabled 0");
12173 else if (strcasecmp(mode, "Off") == 0)
12174 res = wpa_command(intf, "SET radio_disabled 1");
12175 else
12176 return -1;
12177
12178 if (res) {
12179 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12180 "radio mode");
12181 return 0;
12182 }
12183
12184 return 1;
12185}
12186
12187
Jouni Malinenf7222712019-06-13 01:50:21 +030012188static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
12189 struct sigma_conn *conn,
12190 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012191{
12192 const char *intf = get_param(cmd, "Interface");
12193 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012194 const char *prog = get_param(cmd, "program");
12195 const char *powersave = get_param(cmd, "powersave");
12196 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012197
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012198 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012199 return -1;
12200
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012201 if (prog && strcasecmp(prog, "60GHz") == 0) {
12202 /*
12203 * The CAPI mode parameter does not exist in 60G
12204 * unscheduled PS.
12205 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080012206 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012207 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012208 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020012209 strcasecmp(prog, "HE") == 0) {
12210 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012211 } else {
12212 if (mode == NULL)
12213 return -1;
12214
12215 if (strcasecmp(mode, "On") == 0)
12216 res = set_ps(intf, dut, 1);
12217 else if (strcasecmp(mode, "Off") == 0)
12218 res = set_ps(intf, dut, 0);
12219 else
12220 return -1;
12221 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012222
12223 if (res) {
12224 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12225 "power save mode");
12226 return 0;
12227 }
12228
12229 return 1;
12230}
12231
12232
Jouni Malinenf7222712019-06-13 01:50:21 +030012233static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
12234 struct sigma_conn *conn,
12235 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012236{
12237 const char *intf = get_param(cmd, "Interface");
12238 const char *val, *bssid;
12239 int res;
12240 char *buf;
12241 size_t buf_len;
12242
12243 val = get_param(cmd, "BSSID_FILTER");
12244 if (val == NULL)
12245 return -1;
12246
12247 bssid = get_param(cmd, "BSSID_List");
12248 if (atoi(val) == 0 || bssid == NULL) {
12249 /* Disable BSSID filter */
12250 if (wpa_command(intf, "SET bssid_filter ")) {
12251 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
12252 "to disable BSSID filter");
12253 return 0;
12254 }
12255
12256 return 1;
12257 }
12258
12259 buf_len = 100 + strlen(bssid);
12260 buf = malloc(buf_len);
12261 if (buf == NULL)
12262 return -1;
12263
12264 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
12265 res = wpa_command(intf, buf);
12266 free(buf);
12267 if (res) {
12268 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
12269 "BSSID filter");
12270 return 0;
12271 }
12272
12273 return 1;
12274}
12275
12276
Jouni Malinenf7222712019-06-13 01:50:21 +030012277static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
12278 struct sigma_conn *conn,
12279 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012280{
12281 const char *intf = get_param(cmd, "Interface");
12282 const char *val;
12283
12284 /* TODO: ARP */
12285
12286 val = get_param(cmd, "HS2_CACHE_PROFILE");
12287 if (val && strcasecmp(val, "All") == 0)
12288 hs2_clear_credentials(intf);
12289
12290 return 1;
12291}
12292
12293
Jouni Malinenf7222712019-06-13 01:50:21 +030012294static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
12295 struct sigma_conn *conn,
12296 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012297{
12298 const char *intf = get_param(cmd, "Interface");
12299 const char *key_type = get_param(cmd, "KeyType");
12300 char buf[100], resp[200];
12301
12302 if (key_type == NULL)
12303 return -1;
12304
12305 if (strcasecmp(key_type, "GTK") == 0) {
12306 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
12307 strncmp(buf, "FAIL", 4) == 0) {
12308 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12309 "not fetch current GTK");
12310 return 0;
12311 }
12312 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
12313 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12314 return 0;
12315 } else {
12316 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12317 "KeyType");
12318 return 0;
12319 }
12320
12321 return 1;
12322}
12323
12324
12325static int hs2_set_policy(struct sigma_dut *dut)
12326{
12327#ifdef ANDROID
12328 system("ip rule del prio 23000");
12329 if (system("ip rule add from all lookup main prio 23000") != 0) {
12330 sigma_dut_print(dut, DUT_MSG_ERROR,
12331 "Failed to run:ip rule add from all lookup main prio");
12332 return -1;
12333 }
12334 if (system("ip route flush cache") != 0) {
12335 sigma_dut_print(dut, DUT_MSG_ERROR,
12336 "Failed to run ip route flush cache");
12337 return -1;
12338 }
12339 return 1;
12340#else /* ANDROID */
12341 return 0;
12342#endif /* ANDROID */
12343}
12344
12345
Jouni Malinenf7222712019-06-13 01:50:21 +030012346static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
12347 struct sigma_conn *conn,
12348 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012349{
12350 const char *intf = get_param(cmd, "Interface");
12351 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030012352 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012353 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030012354 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012355 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
12356 int tries = 0;
12357 int ignore_blacklist = 0;
12358 const char *events[] = {
12359 "CTRL-EVENT-CONNECTED",
12360 "INTERWORKING-BLACKLISTED",
12361 "INTERWORKING-NO-MATCH",
12362 NULL
12363 };
12364
12365 start_sta_mode(dut);
12366
Jouni Malinen439352d2018-09-13 03:42:23 +030012367 if (band) {
12368 if (strcmp(band, "2.4") == 0) {
12369 wpa_command(intf, "SET setband 2G");
12370 } else if (strcmp(band, "5") == 0) {
12371 wpa_command(intf, "SET setband 5G");
12372 } else {
12373 send_resp(dut, conn, SIGMA_ERROR,
12374 "errorCode,Unsupported band");
12375 return 0;
12376 }
12377 }
12378
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012379 blacklisted[0] = '\0';
12380 if (val && atoi(val))
12381 ignore_blacklist = 1;
12382
12383try_again:
12384 ctrl = open_wpa_mon(intf);
12385 if (ctrl == NULL) {
12386 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12387 "wpa_supplicant monitor connection");
12388 return -2;
12389 }
12390
12391 tries++;
12392 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
12393 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
12394 "Interworking connection");
12395 wpa_ctrl_detach(ctrl);
12396 wpa_ctrl_close(ctrl);
12397 return 0;
12398 }
12399
12400 buf[0] = '\0';
12401 while (1) {
12402 char *pos;
12403 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
12404 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
12405 if (!pos)
12406 break;
12407 pos += 25;
12408 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
12409 pos);
12410 if (!blacklisted[0])
12411 memcpy(blacklisted, pos, strlen(pos) + 1);
12412 }
12413
12414 if (ignore_blacklist && blacklisted[0]) {
12415 char *end;
12416 end = strchr(blacklisted, ' ');
12417 if (end)
12418 *end = '\0';
12419 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
12420 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030012421 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
12422 blacklisted);
12423 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012424 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
12425 wpa_ctrl_detach(ctrl);
12426 wpa_ctrl_close(ctrl);
12427 return 0;
12428 }
12429 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
12430 buf, sizeof(buf));
12431 }
12432
12433 wpa_ctrl_detach(ctrl);
12434 wpa_ctrl_close(ctrl);
12435
12436 if (res < 0) {
12437 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12438 "connect");
12439 return 0;
12440 }
12441
12442 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
12443 strstr(buf, "INTERWORKING-BLACKLISTED")) {
12444 if (tries < 2) {
12445 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
12446 goto try_again;
12447 }
12448 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
12449 "matching credentials found");
12450 return 0;
12451 }
12452
12453 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12454 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12455 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12456 "get current BSSID/SSID");
12457 return 0;
12458 }
12459
12460 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
12461 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12462 hs2_set_policy(dut);
12463 return 0;
12464}
12465
12466
Jouni Malinenf7222712019-06-13 01:50:21 +030012467static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
12468 struct sigma_conn *conn,
12469 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030012470{
12471 const char *intf = get_param(cmd, "Interface");
12472 const char *display = get_param(cmd, "Display");
12473 struct wpa_ctrl *ctrl;
12474 char buf[300], params[400], *pos;
12475 char bssid[20];
12476 int info_avail = 0;
12477 unsigned int old_timeout;
12478 int res;
12479
12480 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
12481 send_resp(dut, conn, SIGMA_ERROR,
12482 "ErrorCode,Could not get current BSSID");
12483 return 0;
12484 }
12485 ctrl = open_wpa_mon(intf);
12486 if (!ctrl) {
12487 sigma_dut_print(dut, DUT_MSG_ERROR,
12488 "Failed to open wpa_supplicant monitor connection");
12489 return -2;
12490 }
12491
12492 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
12493 wpa_command(intf, buf);
12494
12495 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
12496 if (res < 0) {
12497 send_resp(dut, conn, SIGMA_ERROR,
12498 "ErrorCode,Could not complete GAS query");
12499 goto fail;
12500 }
12501
12502 old_timeout = dut->default_timeout;
12503 dut->default_timeout = 2;
12504 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
12505 dut->default_timeout = old_timeout;
12506 if (res < 0)
12507 goto done;
12508 pos = strchr(buf, ' ');
12509 if (!pos)
12510 goto done;
12511 pos++;
12512 pos = strchr(pos, ' ');
12513 if (!pos)
12514 goto done;
12515 pos++;
12516 info_avail = 1;
12517 snprintf(params, sizeof(params), "browser %s", pos);
12518
12519 if (display && strcasecmp(display, "Yes") == 0) {
12520 pid_t pid;
12521
12522 pid = fork();
12523 if (pid < 0) {
12524 perror("fork");
12525 return -1;
12526 }
12527
12528 if (pid == 0) {
12529 run_hs20_osu(dut, params);
12530 exit(0);
12531 }
12532 }
12533
12534done:
12535 snprintf(buf, sizeof(buf), "Info_available,%s",
12536 info_avail ? "Yes" : "No");
12537 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12538fail:
12539 wpa_ctrl_detach(ctrl);
12540 wpa_ctrl_close(ctrl);
12541 return 0;
12542}
12543
12544
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012545static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
12546 struct sigma_conn *conn,
12547 const char *ifname,
12548 struct sigma_cmd *cmd)
12549{
12550 const char *val;
12551 int id;
12552
12553 id = add_cred(ifname);
12554 if (id < 0)
12555 return -2;
12556 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12557
12558 val = get_param(cmd, "prefer");
12559 if (val && atoi(val) > 0)
12560 set_cred(ifname, id, "priority", "1");
12561
12562 val = get_param(cmd, "REALM");
12563 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12564 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12565 "realm");
12566 return 0;
12567 }
12568
12569 val = get_param(cmd, "HOME_FQDN");
12570 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12571 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12572 "home_fqdn");
12573 return 0;
12574 }
12575
12576 val = get_param(cmd, "Username");
12577 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12578 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12579 "username");
12580 return 0;
12581 }
12582
12583 val = get_param(cmd, "Password");
12584 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
12585 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12586 "password");
12587 return 0;
12588 }
12589
12590 val = get_param(cmd, "ROOT_CA");
12591 if (val) {
12592 char fname[200];
12593 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12594#ifdef __linux__
12595 if (!file_exists(fname)) {
12596 char msg[300];
12597 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12598 "file (%s) not found", fname);
12599 send_resp(dut, conn, SIGMA_ERROR, msg);
12600 return 0;
12601 }
12602#endif /* __linux__ */
12603 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12604 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12605 "not set root CA");
12606 return 0;
12607 }
12608 }
12609
12610 return 1;
12611}
12612
12613
12614static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
12615{
12616 FILE *in, *out;
12617 char buf[500];
12618 int found = 0;
12619
12620 in = fopen("devdetail.xml", "r");
12621 if (in == NULL)
12622 return -1;
12623 out = fopen("devdetail.xml.tmp", "w");
12624 if (out == NULL) {
12625 fclose(in);
12626 return -1;
12627 }
12628
12629 while (fgets(buf, sizeof(buf), in)) {
12630 char *pos = strstr(buf, "<IMSI>");
12631 if (pos) {
12632 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
12633 imsi);
12634 pos += 6;
12635 *pos = '\0';
12636 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
12637 found++;
12638 } else {
12639 fprintf(out, "%s", buf);
12640 }
12641 }
12642
12643 fclose(out);
12644 fclose(in);
12645 if (found)
12646 rename("devdetail.xml.tmp", "devdetail.xml");
12647 else
12648 unlink("devdetail.xml.tmp");
12649
12650 return 0;
12651}
12652
12653
12654static int sta_add_credential_sim(struct sigma_dut *dut,
12655 struct sigma_conn *conn,
12656 const char *ifname, struct sigma_cmd *cmd)
12657{
12658 const char *val, *imsi = NULL;
12659 int id;
12660 char buf[200];
12661 int res;
12662 const char *pos;
12663 size_t mnc_len;
12664 char plmn_mcc[4];
12665 char plmn_mnc[4];
12666
12667 id = add_cred(ifname);
12668 if (id < 0)
12669 return -2;
12670 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12671
12672 val = get_param(cmd, "prefer");
12673 if (val && atoi(val) > 0)
12674 set_cred(ifname, id, "priority", "1");
12675
12676 val = get_param(cmd, "PLMN_MCC");
12677 if (val == NULL) {
12678 send_resp(dut, conn, SIGMA_ERROR,
12679 "errorCode,Missing PLMN_MCC");
12680 return 0;
12681 }
12682 if (strlen(val) != 3) {
12683 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
12684 return 0;
12685 }
12686 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
12687
12688 val = get_param(cmd, "PLMN_MNC");
12689 if (val == NULL) {
12690 send_resp(dut, conn, SIGMA_ERROR,
12691 "errorCode,Missing PLMN_MNC");
12692 return 0;
12693 }
12694 if (strlen(val) != 2 && strlen(val) != 3) {
12695 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
12696 return 0;
12697 }
12698 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
12699
12700 val = get_param(cmd, "IMSI");
12701 if (val == NULL) {
12702 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
12703 "IMSI");
12704 return 0;
12705 }
12706
12707 imsi = pos = val;
12708
12709 if (strncmp(plmn_mcc, pos, 3) != 0) {
12710 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
12711 return 0;
12712 }
12713 pos += 3;
12714
12715 mnc_len = strlen(plmn_mnc);
12716 if (mnc_len < 2) {
12717 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
12718 return 0;
12719 }
12720
12721 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
12722 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
12723 return 0;
12724 }
12725 pos += mnc_len;
12726
12727 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
12728 if (res < 0 || res >= (int) sizeof(buf))
12729 return -1;
12730 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
12731 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12732 "not set IMSI");
12733 return 0;
12734 }
12735
12736 val = get_param(cmd, "Password");
12737 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
12738 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12739 "not set password");
12740 return 0;
12741 }
12742
Jouni Malinenba630452018-06-22 11:49:59 +030012743 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012744 /*
12745 * Set provisioning_sp for the test cases where SIM/USIM
12746 * provisioning is used.
12747 */
12748 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
12749 "wi-fi.org") < 0) {
12750 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12751 "not set provisioning_sp");
12752 return 0;
12753 }
12754
12755 update_devdetail_imsi(dut, imsi);
12756 }
12757
12758 return 1;
12759}
12760
12761
12762static int sta_add_credential_cert(struct sigma_dut *dut,
12763 struct sigma_conn *conn,
12764 const char *ifname,
12765 struct sigma_cmd *cmd)
12766{
12767 const char *val;
12768 int id;
12769
12770 id = add_cred(ifname);
12771 if (id < 0)
12772 return -2;
12773 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12774
12775 val = get_param(cmd, "prefer");
12776 if (val && atoi(val) > 0)
12777 set_cred(ifname, id, "priority", "1");
12778
12779 val = get_param(cmd, "REALM");
12780 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12781 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12782 "realm");
12783 return 0;
12784 }
12785
12786 val = get_param(cmd, "HOME_FQDN");
12787 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12788 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12789 "home_fqdn");
12790 return 0;
12791 }
12792
12793 val = get_param(cmd, "Username");
12794 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12795 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12796 "username");
12797 return 0;
12798 }
12799
12800 val = get_param(cmd, "clientCertificate");
12801 if (val) {
12802 char fname[200];
12803 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12804#ifdef __linux__
12805 if (!file_exists(fname)) {
12806 char msg[300];
12807 snprintf(msg, sizeof(msg),
12808 "ErrorCode,clientCertificate "
12809 "file (%s) not found", fname);
12810 send_resp(dut, conn, SIGMA_ERROR, msg);
12811 return 0;
12812 }
12813#endif /* __linux__ */
12814 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
12815 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12816 "not set client_cert");
12817 return 0;
12818 }
12819 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
12820 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12821 "not set private_key");
12822 return 0;
12823 }
12824 }
12825
12826 val = get_param(cmd, "ROOT_CA");
12827 if (val) {
12828 char fname[200];
12829 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12830#ifdef __linux__
12831 if (!file_exists(fname)) {
12832 char msg[300];
12833 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12834 "file (%s) not found", fname);
12835 send_resp(dut, conn, SIGMA_ERROR, msg);
12836 return 0;
12837 }
12838#endif /* __linux__ */
12839 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12840 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12841 "not set root CA");
12842 return 0;
12843 }
12844 }
12845
12846 return 1;
12847}
12848
12849
Jouni Malinenf7222712019-06-13 01:50:21 +030012850static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
12851 struct sigma_conn *conn,
12852 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012853{
12854 const char *intf = get_param(cmd, "Interface");
12855 const char *type;
12856
12857 start_sta_mode(dut);
12858
12859 type = get_param(cmd, "Type");
12860 if (!type)
12861 return -1;
12862
12863 if (strcasecmp(type, "uname_pwd") == 0)
12864 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
12865
12866 if (strcasecmp(type, "sim") == 0)
12867 return sta_add_credential_sim(dut, conn, intf, cmd);
12868
12869 if (strcasecmp(type, "cert") == 0)
12870 return sta_add_credential_cert(dut, conn, intf, cmd);
12871
12872 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
12873 "type");
12874 return 0;
12875}
12876
12877
Jouni Malinenf7222712019-06-13 01:50:21 +030012878static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
12879 struct sigma_conn *conn,
12880 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012881{
12882 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012883 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Arif Hussain66a4af02019-02-07 15:04:51 -080012884 char buf[4096];
vamsi krishna89ad8c62017-09-19 12:51:18 +053012885 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080012886 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012887 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012888 enum sigma_cmd_result status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012889
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020012890 start_sta_mode(dut);
12891
Arif Hussain66a4af02019-02-07 15:04:51 -080012892 val = get_param(cmd, "GetParameter");
12893 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012894 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080012895 buf, sizeof(buf)) < 0) {
12896 sigma_dut_print(dut, DUT_MSG_ERROR,
12897 "Could not get ssid bssid");
12898 return ERROR_SEND_STATUS;
12899 }
12900
12901 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
12902 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12903 return STATUS_SENT;
12904 }
12905
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012906 val = get_param(cmd, "HESSID");
12907 if (val) {
12908 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
12909 if (res < 0 || res >= (int) sizeof(buf))
12910 return -1;
12911 wpa_command(intf, buf);
12912 }
12913
12914 val = get_param(cmd, "ACCS_NET_TYPE");
12915 if (val) {
12916 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
12917 val);
12918 if (res < 0 || res >= (int) sizeof(buf))
12919 return -1;
12920 wpa_command(intf, buf);
12921 }
12922
vamsi krishna89ad8c62017-09-19 12:51:18 +053012923 bssid = get_param(cmd, "Bssid");
12924 ssid = get_param(cmd, "Ssid");
12925
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080012926 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
12927 dut->device_type == STA_testbed) {
12928 ssid = NULL;
12929 wildcard_ssid = 1;
12930 }
12931
vamsi krishna89ad8c62017-09-19 12:51:18 +053012932 if (ssid) {
12933 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
12934 send_resp(dut, conn, SIGMA_ERROR,
12935 "ErrorCode,Too long SSID");
12936 return 0;
12937 }
12938 ascii2hexstr(ssid, ssid_hex);
12939 }
12940
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012941 short_ssid = get_param(cmd, "ShortSSID");
12942 if (short_ssid) {
12943 uint32_t short_ssid_hex;
12944
12945 short_ssid_hex = strtoul(short_ssid, NULL, 16);
12946 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
12947 (((short_ssid_hex >> 8) & 0xFF) << 16) |
12948 (((short_ssid_hex >> 16) & 0xFF) << 8) |
12949 ((short_ssid_hex >> 24) & 0xFF);
12950
12951 res = snprintf(buf, sizeof(buf),
12952 "VENDOR_ELEM_ADD 14 ff053a%08x",
12953 short_ssid_hex);
12954 if (res < 0 || res >= (int) sizeof(buf) ||
12955 wpa_command(intf, buf)) {
12956 send_resp(dut, conn, SIGMA_ERROR,
12957 "errorCode,Failed to add short SSID");
12958 return STATUS_SENT_ERROR;
12959 }
12960 }
12961
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080012962 scan_freq = get_param(cmd, "ChnlFreq");
12963
12964 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053012965 bssid ? " bssid=": "",
12966 bssid ? bssid : "",
12967 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080012968 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080012969 wildcard_ssid ? " wildcard_ssid=1" : "",
12970 scan_freq ? " freq=" : "",
12971 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012972 if (res < 0 || res >= (int) sizeof(buf)) {
12973 send_resp(dut, conn, SIGMA_ERROR,
12974 "errorCode,Could not build scan command");
12975 status = STATUS_SENT_ERROR;
12976 goto remove_s_ssid;
12977 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053012978
12979 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012980 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
12981 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012982 status = STATUS_SENT_ERROR;
12983 } else {
12984 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012985 }
12986
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012987remove_s_ssid:
12988 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
12989 sigma_dut_print(dut, DUT_MSG_ERROR,
12990 "Failed to delete vendor element");
12991
12992 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012993}
12994
12995
Jouni Malinenf7222712019-06-13 01:50:21 +030012996static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
12997 struct sigma_conn *conn,
12998 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020012999{
13000 const char *intf = get_param(cmd, "Interface");
13001 const char *bssid;
13002 char buf[4096], *pos;
13003 int freq, chan;
13004 char *ssid;
13005 char resp[100];
13006 int res;
13007 struct wpa_ctrl *ctrl;
13008
13009 bssid = get_param(cmd, "BSSID");
13010 if (!bssid) {
13011 send_resp(dut, conn, SIGMA_INVALID,
13012 "errorCode,BSSID argument is missing");
13013 return 0;
13014 }
13015
13016 ctrl = open_wpa_mon(intf);
13017 if (!ctrl) {
13018 sigma_dut_print(dut, DUT_MSG_ERROR,
13019 "Failed to open wpa_supplicant monitor connection");
13020 return -1;
13021 }
13022
13023 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
13024 send_resp(dut, conn, SIGMA_ERROR,
13025 "errorCode,Could not start scan");
13026 wpa_ctrl_detach(ctrl);
13027 wpa_ctrl_close(ctrl);
13028 return 0;
13029 }
13030
13031 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
13032 buf, sizeof(buf));
13033
13034 wpa_ctrl_detach(ctrl);
13035 wpa_ctrl_close(ctrl);
13036
13037 if (res < 0) {
13038 send_resp(dut, conn, SIGMA_ERROR,
13039 "errorCode,Scan did not complete");
13040 return 0;
13041 }
13042
13043 snprintf(buf, sizeof(buf), "BSS %s", bssid);
13044 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
13045 strncmp(buf, "id=", 3) != 0) {
13046 send_resp(dut, conn, SIGMA_ERROR,
13047 "errorCode,Specified BSSID not found");
13048 return 0;
13049 }
13050
13051 pos = strstr(buf, "\nfreq=");
13052 if (!pos) {
13053 send_resp(dut, conn, SIGMA_ERROR,
13054 "errorCode,Channel not found");
13055 return 0;
13056 }
13057 freq = atoi(pos + 6);
13058 chan = freq_to_channel(freq);
13059
13060 pos = strstr(buf, "\nssid=");
13061 if (!pos) {
13062 send_resp(dut, conn, SIGMA_ERROR,
13063 "errorCode,SSID not found");
13064 return 0;
13065 }
13066 ssid = pos + 6;
13067 pos = strchr(ssid, '\n');
13068 if (pos)
13069 *pos = '\0';
13070 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
13071 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13072 return 0;
13073}
13074
13075
Jouni Malinenf7222712019-06-13 01:50:21 +030013076static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
13077 struct sigma_conn *conn,
13078 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013079{
13080#ifdef __linux__
13081 struct timeval tv;
13082 struct tm tm;
13083 time_t t;
13084 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013085 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013086
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013087 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013088
13089 memset(&tm, 0, sizeof(tm));
13090 val = get_param(cmd, "seconds");
13091 if (val)
13092 tm.tm_sec = atoi(val);
13093 val = get_param(cmd, "minutes");
13094 if (val)
13095 tm.tm_min = atoi(val);
13096 val = get_param(cmd, "hours");
13097 if (val)
13098 tm.tm_hour = atoi(val);
13099 val = get_param(cmd, "date");
13100 if (val)
13101 tm.tm_mday = atoi(val);
13102 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013103 if (val) {
13104 v = atoi(val);
13105 if (v < 1 || v > 12) {
13106 send_resp(dut, conn, SIGMA_INVALID,
13107 "errorCode,Invalid month");
13108 return 0;
13109 }
13110 tm.tm_mon = v - 1;
13111 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013112 val = get_param(cmd, "year");
13113 if (val) {
13114 int year = atoi(val);
13115#ifdef ANDROID
13116 if (year > 2035)
13117 year = 2035; /* years beyond 2035 not supported */
13118#endif /* ANDROID */
13119 tm.tm_year = year - 1900;
13120 }
13121 t = mktime(&tm);
13122 if (t == (time_t) -1) {
13123 send_resp(dut, conn, SIGMA_ERROR,
13124 "errorCode,Invalid date or time");
13125 return 0;
13126 }
13127
13128 memset(&tv, 0, sizeof(tv));
13129 tv.tv_sec = t;
13130
13131 if (settimeofday(&tv, NULL) < 0) {
13132 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
13133 strerror(errno));
13134 send_resp(dut, conn, SIGMA_ERROR,
13135 "errorCode,Failed to set time");
13136 return 0;
13137 }
13138
13139 return 1;
13140#endif /* __linux__ */
13141
13142 return -1;
13143}
13144
13145
Jouni Malinenf7222712019-06-13 01:50:21 +030013146static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
13147 struct sigma_conn *conn,
13148 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013149{
13150 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013151 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013152 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013153 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013154 int res;
13155 struct wpa_ctrl *ctrl;
13156
13157 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013158 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013159
13160 val = get_param(cmd, "ProdESSAssoc");
13161 if (val)
13162 prod_ess_assoc = atoi(val);
13163
13164 kill_dhcp_client(dut, intf);
13165 if (start_dhcp_client(dut, intf) < 0)
13166 return -2;
13167
13168 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
13169 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13170 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013171 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013172 prod_ess_assoc ? "" : "-N",
13173 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013174 name ? "'" : "",
13175 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
13176 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013177
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053013178 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013179 if (run_hs20_osu(dut, buf) < 0) {
13180 FILE *f;
13181
13182 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
13183
13184 f = fopen("hs20-osu-client.res", "r");
13185 if (f) {
13186 char resp[400], res[300], *pos;
13187 if (!fgets(res, sizeof(res), f))
13188 res[0] = '\0';
13189 pos = strchr(res, '\n');
13190 if (pos)
13191 *pos = '\0';
13192 fclose(f);
13193 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
13194 res);
13195 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
13196 if (system(resp) != 0) {
13197 }
13198 snprintf(resp, sizeof(resp),
13199 "SSID,,BSSID,,failureReason,%s", res);
13200 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13201 return 0;
13202 }
13203
13204 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13205 return 0;
13206 }
13207
13208 if (!prod_ess_assoc)
13209 goto report;
13210
13211 ctrl = open_wpa_mon(intf);
13212 if (ctrl == NULL) {
13213 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13214 "wpa_supplicant monitor connection");
13215 return -1;
13216 }
13217
13218 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13219 buf, sizeof(buf));
13220
13221 wpa_ctrl_detach(ctrl);
13222 wpa_ctrl_close(ctrl);
13223
13224 if (res < 0) {
13225 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
13226 "network after OSU");
13227 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13228 return 0;
13229 }
13230
13231report:
13232 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13233 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13234 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
13235 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13236 return 0;
13237 }
13238
13239 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
13240 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013241 return 0;
13242}
13243
13244
Jouni Malinenf7222712019-06-13 01:50:21 +030013245static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
13246 struct sigma_conn *conn,
13247 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013248{
13249 const char *val;
13250 int timeout = 120;
13251
13252 val = get_param(cmd, "PolicyUpdate");
13253 if (val == NULL || atoi(val) == 0)
13254 return 1; /* No operation requested */
13255
13256 val = get_param(cmd, "Timeout");
13257 if (val)
13258 timeout = atoi(val);
13259
13260 if (timeout) {
13261 /* TODO: time out the command and return
13262 * PolicyUpdateStatus,TIMEOUT if needed. */
13263 }
13264
13265 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
13266 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13267 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
13268 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
13269 return 0;
13270 }
13271
13272 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
13273 return 0;
13274}
13275
13276
Jouni Malinenf7222712019-06-13 01:50:21 +030013277static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
13278 struct sigma_conn *conn,
13279 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013280{
13281 struct wpa_ctrl *ctrl;
13282 const char *intf = get_param(cmd, "Interface");
13283 const char *bssid = get_param(cmd, "Bssid");
13284 const char *ssid = get_param(cmd, "SSID");
13285 const char *security = get_param(cmd, "Security");
13286 const char *passphrase = get_param(cmd, "Passphrase");
13287 const char *pin = get_param(cmd, "PIN");
13288 char buf[1000];
13289 char ssid_hex[200], passphrase_hex[200];
13290 const char *keymgmt, *cipher;
13291
13292 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013293 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013294
13295 if (!bssid) {
13296 send_resp(dut, conn, SIGMA_ERROR,
13297 "ErrorCode,Missing Bssid argument");
13298 return 0;
13299 }
13300
13301 if (!ssid) {
13302 send_resp(dut, conn, SIGMA_ERROR,
13303 "ErrorCode,Missing SSID argument");
13304 return 0;
13305 }
13306
13307 if (!security) {
13308 send_resp(dut, conn, SIGMA_ERROR,
13309 "ErrorCode,Missing Security argument");
13310 return 0;
13311 }
13312
13313 if (!passphrase) {
13314 send_resp(dut, conn, SIGMA_ERROR,
13315 "ErrorCode,Missing Passphrase argument");
13316 return 0;
13317 }
13318
13319 if (!pin) {
13320 send_resp(dut, conn, SIGMA_ERROR,
13321 "ErrorCode,Missing PIN argument");
13322 return 0;
13323 }
13324
vamsi krishna8c9c1562017-05-12 15:51:46 +053013325 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
13326 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013327 send_resp(dut, conn, SIGMA_ERROR,
13328 "ErrorCode,Too long SSID/passphrase");
13329 return 0;
13330 }
13331
13332 ctrl = open_wpa_mon(intf);
13333 if (ctrl == NULL) {
13334 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13335 "wpa_supplicant monitor connection");
13336 return -2;
13337 }
13338
13339 if (strcasecmp(security, "wpa2-psk") == 0) {
13340 keymgmt = "WPA2PSK";
13341 cipher = "CCMP";
13342 } else {
13343 wpa_ctrl_detach(ctrl);
13344 wpa_ctrl_close(ctrl);
13345 send_resp(dut, conn, SIGMA_ERROR,
13346 "ErrorCode,Unsupported Security value");
13347 return 0;
13348 }
13349
13350 ascii2hexstr(ssid, ssid_hex);
13351 ascii2hexstr(passphrase, passphrase_hex);
13352 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
13353 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
13354
13355 if (wpa_command(intf, buf) < 0) {
13356 wpa_ctrl_detach(ctrl);
13357 wpa_ctrl_close(ctrl);
13358 send_resp(dut, conn, SIGMA_ERROR,
13359 "ErrorCode,Failed to start registrar");
13360 return 0;
13361 }
13362
13363 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
13364 dut->er_oper_performed = 1;
13365
13366 return wps_connection_event(dut, conn, ctrl, intf, 0);
13367}
13368
13369
Jouni Malinenf7222712019-06-13 01:50:21 +030013370static enum sigma_cmd_result
13371cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
13372 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013373{
13374 struct wpa_ctrl *ctrl;
13375 const char *intf = get_param(cmd, "Interface");
13376 const char *bssid = get_param(cmd, "Bssid");
13377 char buf[100];
13378
13379 if (!bssid) {
13380 send_resp(dut, conn, SIGMA_ERROR,
13381 "ErrorCode,Missing Bssid argument");
13382 return 0;
13383 }
13384
13385 ctrl = open_wpa_mon(intf);
13386 if (ctrl == NULL) {
13387 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13388 "wpa_supplicant monitor connection");
13389 return -2;
13390 }
13391
13392 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
13393
13394 if (wpa_command(intf, buf) < 0) {
13395 wpa_ctrl_detach(ctrl);
13396 wpa_ctrl_close(ctrl);
13397 send_resp(dut, conn, SIGMA_ERROR,
13398 "ErrorCode,Failed to start registrar");
13399 return 0;
13400 }
13401
13402 return wps_connection_event(dut, conn, ctrl, intf, 0);
13403}
13404
13405
Jouni Malinenf7222712019-06-13 01:50:21 +030013406static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
13407 struct sigma_conn *conn,
13408 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053013409{
13410 struct wpa_ctrl *ctrl;
13411 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013412 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013413 const char *config_method = get_param(cmd, "WPSConfigMethod");
13414 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053013415 int res;
13416 char buf[256];
13417 const char *events[] = {
13418 "CTRL-EVENT-CONNECTED",
13419 "WPS-OVERLAP-DETECTED",
13420 "WPS-TIMEOUT",
13421 "WPS-FAIL",
13422 NULL
13423 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013424 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053013425
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013426 /* 60G WPS tests do not pass Interface parameter */
13427 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013428 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013429
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013430 if (dut->mode == SIGMA_MODE_AP)
13431 return ap_wps_registration(dut, conn, cmd);
13432
13433 if (config_method) {
13434 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
13435 * sta_wps_enter_pin before calling start_wps_registration. */
13436 if (strcasecmp(config_method, "PBC") == 0)
13437 dut->wps_method = WFA_CS_WPS_PBC;
13438 }
13439 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
13440 send_resp(dut, conn, SIGMA_ERROR,
13441 "ErrorCode,WPS parameters not yet set");
13442 return STATUS_SENT;
13443 }
13444
13445 /* Make sure WPS is enabled (also for STA mode) */
13446 dut->wps_disable = 0;
13447
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013448 if (dut->band == WPS_BAND_60G && network_mode &&
13449 strcasecmp(network_mode, "PBSS") == 0) {
13450 sigma_dut_print(dut, DUT_MSG_DEBUG,
13451 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013452 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013453 return -2;
13454 }
13455
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013456 if (dut->force_rsn_ie) {
13457 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
13458 dut->force_rsn_ie);
13459 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
13460 sigma_dut_print(dut, DUT_MSG_INFO,
13461 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020013462 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013463 }
13464 }
13465
vamsi krishna9b144002017-09-20 13:28:13 +053013466 ctrl = open_wpa_mon(intf);
13467 if (!ctrl) {
13468 sigma_dut_print(dut, DUT_MSG_ERROR,
13469 "Failed to open wpa_supplicant monitor connection");
13470 return -2;
13471 }
13472
13473 role = get_param(cmd, "WpsRole");
13474 if (!role) {
13475 send_resp(dut, conn, SIGMA_INVALID,
13476 "ErrorCode,WpsRole not provided");
13477 goto fail;
13478 }
13479
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013480 if (strcasecmp(role, "Enrollee") != 0) {
13481 /* Registrar role for STA not supported */
13482 send_resp(dut, conn, SIGMA_ERROR,
13483 "ErrorCode,Unsupported WpsRole value");
13484 goto fail;
13485 }
13486
13487 if (is_60g_sigma_dut(dut)) {
13488 if (dut->wps_method == WFA_CS_WPS_PBC)
13489 snprintf(buf, sizeof(buf), "WPS_PBC");
13490 else /* WFA_CS_WPS_PIN_KEYPAD */
13491 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
13492 dut->wps_pin);
13493 if (wpa_command(intf, buf) < 0) {
13494 send_resp(dut, conn, SIGMA_ERROR,
13495 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053013496 goto fail;
13497 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013498 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13499 if (res < 0) {
13500 send_resp(dut, conn, SIGMA_ERROR,
13501 "ErrorCode,WPS connection did not complete");
13502 goto fail;
13503 }
13504 if (strstr(buf, "WPS-TIMEOUT")) {
13505 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
13506 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13507 send_resp(dut, conn, SIGMA_COMPLETE,
13508 "WpsState,OverlapSession");
13509 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13510 send_resp(dut, conn, SIGMA_COMPLETE,
13511 "WpsState,Successful");
13512 } else {
13513 send_resp(dut, conn, SIGMA_COMPLETE,
13514 "WpsState,Failure");
13515 }
13516 } else {
13517 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053013518 if (wpa_command(intf, "WPS_PBC") < 0) {
13519 send_resp(dut, conn, SIGMA_ERROR,
13520 "ErrorCode,Failed to enable PBC");
13521 goto fail;
13522 }
13523 } else {
13524 /* TODO: PIN method */
13525 send_resp(dut, conn, SIGMA_ERROR,
13526 "ErrorCode,Unsupported WpsConfigMethod value");
13527 goto fail;
13528 }
13529 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13530 if (res < 0) {
13531 send_resp(dut, conn, SIGMA_ERROR,
13532 "ErrorCode,WPS connection did not complete");
13533 goto fail;
13534 }
13535 if (strstr(buf, "WPS-TIMEOUT")) {
13536 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
13537 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13538 send_resp(dut, conn, SIGMA_ERROR,
13539 "ErrorCode,OverlapSession");
13540 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13541 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
13542 } else {
13543 send_resp(dut, conn, SIGMA_ERROR,
13544 "ErrorCode,WPS operation failed");
13545 }
vamsi krishna9b144002017-09-20 13:28:13 +053013546 }
13547
13548fail:
13549 wpa_ctrl_detach(ctrl);
13550 wpa_ctrl_close(ctrl);
13551 return 0;
13552}
13553
13554
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013555static int req_intf(struct sigma_cmd *cmd)
13556{
13557 return get_param(cmd, "interface") == NULL ? -1 : 0;
13558}
13559
13560
13561void sta_register_cmds(void)
13562{
13563 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
13564 cmd_sta_get_ip_config);
13565 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
13566 cmd_sta_set_ip_config);
13567 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
13568 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
13569 cmd_sta_get_mac_address);
13570 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
13571 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
13572 cmd_sta_verify_ip_connection);
13573 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
13574 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
13575 cmd_sta_set_encryption);
13576 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
13577 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
13578 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
13579 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
13580 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
13581 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
13582 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
13583 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
13584 cmd_sta_set_eapakaprime);
13585 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
13586 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
13587 /* TODO: sta_set_ibss */
13588 /* TODO: sta_set_mode */
13589 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
13590 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
13591 /* TODO: sta_up_load */
13592 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
13593 cmd_sta_preset_testparameters);
13594 /* TODO: sta_set_system */
13595 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
13596 /* TODO: sta_set_rifs_test */
13597 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
13598 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
13599 /* TODO: sta_send_coexist_mgmt */
13600 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
13601 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
13602 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
13603 sigma_dut_reg_cmd("sta_reset_default", req_intf,
13604 cmd_sta_reset_default);
13605 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
13606 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
13607 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
13608 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
13609 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013610 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013611 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
13612 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
13613 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
13614 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
13615 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013616 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
13617 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013618 sigma_dut_reg_cmd("sta_add_credential", req_intf,
13619 cmd_sta_add_credential);
13620 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013621 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013622 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
13623 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
13624 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
13625 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
13626 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
13627 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030013628 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013629 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
13630 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013631 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053013632 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013633}