blob: 0883945e21acf8b9659aa1be2ca31665c0502578 [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 {
1550 snprintf(buf, sizeof(buf),
1551 "ip -6 addr del %s/%s dev %s",
1552 ip, mask, ifname);
1553 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1554 if (system(buf) != 0) {
1555 /*
1556 * This command may fail if the address being
1557 * deleted does not exist. Inaction here is
1558 * intentional.
1559 */
1560 }
1561
1562 snprintf(buf, sizeof(buf),
1563 "ip -6 addr add %s/%s dev %s",
1564 ip, mask, ifname);
1565 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1566 if (system(buf) != 0) {
1567 send_resp(dut, conn, SIGMA_ERROR,
1568 "ErrorCode,Failed to set IPv6 address");
1569 return 0;
1570 }
1571 }
1572
1573 dut->last_set_ip_config_ipv6 = 1;
1574 static_ip_file(6, ip, mask, NULL);
1575 return 1;
1576 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301577 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001578 return -1;
1579 }
1580
1581 kill_dhcp_client(dut, ifname);
1582
1583 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301584 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001585 send_resp(dut, conn, SIGMA_ERROR,
1586 "ErrorCode,Failed to set IP address");
1587 return 0;
1588 }
1589 }
1590
1591 gw = get_param(cmd, "defaultGateway");
1592 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301593 if (set_ipv4_gw(dut, gw) < 1) {
1594 send_resp(dut, conn, SIGMA_ERROR,
1595 "ErrorCode,Failed to set default gateway");
1596 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001597 }
1598 }
1599
1600 val = get_param(cmd, "primary-dns");
1601 if (val) {
1602 /* TODO */
1603 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1604 "setting", val);
1605 }
1606
1607 val = get_param(cmd, "secondary-dns");
1608 if (val) {
1609 /* TODO */
1610 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1611 "setting", val);
1612 }
1613
1614 static_ip_file(4, ip, mask, gw);
1615
1616 return 1;
1617}
1618
1619
Jouni Malinenf7222712019-06-13 01:50:21 +03001620static enum sigma_cmd_result cmd_sta_get_info(struct sigma_dut *dut,
1621 struct sigma_conn *conn,
1622 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001623{
1624 /* const char *intf = get_param(cmd, "Interface"); */
1625 /* TODO: could report more details here */
1626 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1627 return 0;
1628}
1629
1630
Jouni Malinenf7222712019-06-13 01:50:21 +03001631static enum sigma_cmd_result cmd_sta_get_mac_address(struct sigma_dut *dut,
1632 struct sigma_conn *conn,
1633 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001634{
1635 /* const char *intf = get_param(cmd, "Interface"); */
1636 char addr[20], resp[50];
1637
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301638 if (dut->dev_role == DEVROLE_STA_CFON)
1639 return sta_cfon_get_mac_address(dut, conn, cmd);
1640
Jouni Malinen9540e012019-11-05 17:08:42 +02001641 start_sta_mode(dut);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001642 if (get_wpa_status(get_station_ifname(dut), "address",
1643 addr, sizeof(addr)) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001644 return -2;
1645
1646 snprintf(resp, sizeof(resp), "mac,%s", addr);
1647 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1648 return 0;
1649}
1650
1651
Jouni Malinenf7222712019-06-13 01:50:21 +03001652static enum sigma_cmd_result cmd_sta_is_connected(struct sigma_dut *dut,
1653 struct sigma_conn *conn,
1654 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001655{
1656 /* const char *intf = get_param(cmd, "Interface"); */
1657 int connected = 0;
1658 char result[32];
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001659 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001660 sizeof(result)) < 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001661 sigma_dut_print(dut, DUT_MSG_INFO,
1662 "Could not get interface %s status",
1663 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001664 return -2;
1665 }
1666
1667 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1668 if (strncmp(result, "COMPLETED", 9) == 0)
1669 connected = 1;
1670
1671 if (connected)
1672 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1673 else
1674 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1675
1676 return 0;
1677}
1678
1679
Jouni Malinenf7222712019-06-13 01:50:21 +03001680static enum sigma_cmd_result
1681cmd_sta_verify_ip_connection(struct sigma_dut *dut, struct sigma_conn *conn,
1682 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001683{
1684 /* const char *intf = get_param(cmd, "Interface"); */
1685 const char *dst, *timeout;
1686 int wait_time = 90;
1687 char buf[100];
1688 int res;
1689
1690 dst = get_param(cmd, "destination");
1691 if (dst == NULL || !is_ip_addr(dst))
1692 return -1;
1693
1694 timeout = get_param(cmd, "timeout");
1695 if (timeout) {
1696 wait_time = atoi(timeout);
1697 if (wait_time < 1)
1698 wait_time = 1;
1699 }
1700
1701 /* TODO: force renewal of IP lease if DHCP is enabled */
1702
1703 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1704 res = system(buf);
1705 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1706 if (res == 0)
1707 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1708 else if (res == 256)
1709 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1710 else
1711 return -2;
1712
1713 return 0;
1714}
1715
1716
Jouni Malinenf7222712019-06-13 01:50:21 +03001717static enum sigma_cmd_result cmd_sta_get_bssid(struct sigma_dut *dut,
1718 struct sigma_conn *conn,
1719 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001720{
1721 /* const char *intf = get_param(cmd, "Interface"); */
1722 char bssid[20], resp[50];
1723
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001724 if (get_wpa_status(get_station_ifname(dut), "bssid",
1725 bssid, sizeof(bssid)) < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001726 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001727
1728 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1729 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1730 return 0;
1731}
1732
1733
1734#ifdef __SAMSUNG__
1735static int add_use_network(const char *ifname)
1736{
1737 char buf[100];
1738
1739 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1740 wpa_command(ifname, buf);
1741 return 0;
1742}
1743#endif /* __SAMSUNG__ */
1744
1745
1746static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1747 const char *ifname, struct sigma_cmd *cmd)
1748{
1749 const char *ssid = get_param(cmd, "ssid");
1750 int id;
1751 const char *val;
1752
1753 if (ssid == NULL)
1754 return -1;
1755
1756 start_sta_mode(dut);
1757
1758#ifdef __SAMSUNG__
1759 add_use_network(ifname);
1760#endif /* __SAMSUNG__ */
1761
1762 id = add_network(ifname);
1763 if (id < 0)
1764 return -2;
1765 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1766
1767 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1768 return -2;
1769
1770 dut->infra_network_id = id;
1771 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1772
1773 val = get_param(cmd, "program");
1774 if (!val)
1775 val = get_param(cmd, "prog");
1776 if (val && strcasecmp(val, "hs2") == 0) {
1777 char buf[100];
1778 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1779 wpa_command(ifname, buf);
1780
1781 val = get_param(cmd, "prefer");
1782 if (val && atoi(val) > 0)
1783 set_network(ifname, id, "priority", "1");
1784 }
1785
1786 return id;
1787}
1788
1789
Jouni Malinenf7222712019-06-13 01:50:21 +03001790static enum sigma_cmd_result cmd_sta_set_encryption(struct sigma_dut *dut,
1791 struct sigma_conn *conn,
1792 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001793{
1794 const char *intf = get_param(cmd, "Interface");
1795 const char *ssid = get_param(cmd, "ssid");
1796 const char *type = get_param(cmd, "encpType");
1797 const char *ifname;
1798 char buf[200];
1799 int id;
1800
1801 if (intf == NULL || ssid == NULL)
1802 return -1;
1803
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001804 if (strcmp(intf, get_main_ifname(dut)) == 0)
1805 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001806 else
1807 ifname = intf;
1808
1809 id = add_network_common(dut, conn, ifname, cmd);
1810 if (id < 0)
1811 return id;
1812
1813 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1814 return -2;
1815
1816 if (type && strcasecmp(type, "wep") == 0) {
1817 const char *val;
1818 int i;
1819
1820 val = get_param(cmd, "activeKey");
1821 if (val) {
1822 int keyid;
1823 keyid = atoi(val);
1824 if (keyid < 1 || keyid > 4)
1825 return -1;
1826 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1827 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1828 return -2;
1829 }
1830
1831 for (i = 0; i < 4; i++) {
1832 snprintf(buf, sizeof(buf), "key%d", i + 1);
1833 val = get_param(cmd, buf);
1834 if (val == NULL)
1835 continue;
1836 snprintf(buf, sizeof(buf), "wep_key%d", i);
1837 if (set_network(ifname, id, buf, val) < 0)
1838 return -2;
1839 }
1840 }
1841
1842 return 1;
1843}
1844
1845
Jouni Malinene4fde732019-03-25 22:29:37 +02001846static int set_akm_suites(struct sigma_dut *dut, const char *ifname,
1847 int id, const char *val)
1848{
1849 char key_mgmt[200], *end, *pos;
1850 const char *in_pos = val;
1851
Jouni Malinen8179fee2019-03-28 03:19:47 +02001852 dut->akm_values = 0;
Jouni Malinene4fde732019-03-25 22:29:37 +02001853 pos = key_mgmt;
1854 end = pos + sizeof(key_mgmt);
1855 while (*in_pos) {
1856 int res, akm = atoi(in_pos);
1857 const char *str;
1858
Jouni Malinen8179fee2019-03-28 03:19:47 +02001859 if (akm >= 0 && akm < 32)
1860 dut->akm_values |= 1 << akm;
1861
Jouni Malinene4fde732019-03-25 22:29:37 +02001862 switch (akm) {
1863 case AKM_WPA_EAP:
1864 str = "WPA-EAP";
1865 break;
1866 case AKM_WPA_PSK:
1867 str = "WPA-PSK";
1868 break;
1869 case AKM_FT_EAP:
1870 str = "FT-EAP";
1871 break;
1872 case AKM_FT_PSK:
1873 str = "FT-PSK";
1874 break;
1875 case AKM_EAP_SHA256:
1876 str = "WPA-EAP-SHA256";
1877 break;
1878 case AKM_PSK_SHA256:
1879 str = "WPA-PSK-SHA256";
1880 break;
1881 case AKM_SAE:
1882 str = "SAE";
1883 break;
1884 case AKM_FT_SAE:
1885 str = "FT-SAE";
1886 break;
1887 case AKM_SUITE_B:
1888 str = "WPA-EAP-SUITE-B-192";
1889 break;
1890 case AKM_FT_SUITE_B:
1891 str = "FT-EAP-SHA384";
1892 break;
1893 case AKM_FILS_SHA256:
1894 str = "FILS-SHA256";
1895 break;
1896 case AKM_FILS_SHA384:
1897 str = "FILS-SHA384";
1898 break;
1899 case AKM_FT_FILS_SHA256:
1900 str = "FT-FILS-SHA256";
1901 break;
1902 case AKM_FT_FILS_SHA384:
1903 str = "FT-FILS-SHA384";
1904 break;
1905 default:
1906 sigma_dut_print(dut, DUT_MSG_ERROR,
1907 "Unsupported AKMSuitetype %d", akm);
1908 return -1;
1909 }
1910
1911 res = snprintf(pos, end - pos, "%s%s",
1912 pos == key_mgmt ? "" : " ", str);
1913 if (res < 0 || res >= end - pos)
1914 return -1;
1915 pos += res;
1916
1917 in_pos = strchr(in_pos, ';');
1918 if (!in_pos)
1919 break;
1920 while (*in_pos == ';')
1921 in_pos++;
1922 }
1923 sigma_dut_print(dut, DUT_MSG_DEBUG, "AKMSuiteType %s --> %s",
1924 val, key_mgmt);
1925 return set_network(ifname, id, "key_mgmt", key_mgmt);
1926}
1927
1928
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001929static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1930 const char *ifname, struct sigma_cmd *cmd)
1931{
1932 const char *val;
1933 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001934 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001935 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301936 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001937
1938 id = add_network_common(dut, conn, ifname, cmd);
1939 if (id < 0)
1940 return id;
1941
Jouni Malinen47dcc952017-10-09 16:43:24 +03001942 val = get_param(cmd, "Type");
1943 owe = val && strcasecmp(val, "OWE") == 0;
1944
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001945 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001946 if (!val && owe)
1947 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001948 if (val == NULL) {
Jouni Malinene4fde732019-03-25 22:29:37 +02001949 /* keyMgmtType is being replaced with AKMSuiteType, so ignore
1950 * this missing parameter and assume proto=WPA2. */
1951 if (set_network(ifname, id, "proto", "WPA2") < 0)
1952 return ERROR_SEND_STATUS;
1953 } else if (strcasecmp(val, "wpa") == 0 ||
1954 strcasecmp(val, "wpa-psk") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001955 if (set_network(ifname, id, "proto", "WPA") < 0)
1956 return -2;
1957 } else if (strcasecmp(val, "wpa2") == 0 ||
1958 strcasecmp(val, "wpa2-psk") == 0 ||
1959 strcasecmp(val, "wpa2-ft") == 0 ||
1960 strcasecmp(val, "wpa2-sha256") == 0) {
1961 if (set_network(ifname, id, "proto", "WPA2") < 0)
1962 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301963 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1964 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001965 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1966 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001967 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301968 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001969 if (set_network(ifname, id, "proto", "WPA2") < 0)
1970 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001971 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001972 } else {
1973 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1974 return 0;
1975 }
1976
1977 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001978 if (val) {
1979 cipher_set = 1;
1980 if (strcasecmp(val, "tkip") == 0) {
1981 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1982 return -2;
1983 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1984 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1985 return -2;
1986 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1987 if (set_network(ifname, id, "pairwise",
1988 "CCMP TKIP") < 0)
1989 return -2;
1990 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1991 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1992 return -2;
1993 if (set_network(ifname, id, "group", "GCMP") < 0)
1994 return -2;
1995 } else {
1996 send_resp(dut, conn, SIGMA_ERROR,
1997 "errorCode,Unrecognized encpType value");
1998 return 0;
1999 }
2000 }
2001
2002 val = get_param(cmd, "PairwiseCipher");
2003 if (val) {
2004 cipher_set = 1;
2005 /* TODO: Support space separated list */
2006 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2007 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
2008 return -2;
2009 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2010 if (set_network(ifname, id, "pairwise",
2011 "CCMP-256") < 0)
2012 return -2;
2013 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2014 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
2015 return -2;
2016 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2017 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
2018 return -2;
2019 } else {
2020 send_resp(dut, conn, SIGMA_ERROR,
2021 "errorCode,Unrecognized PairwiseCipher value");
2022 return 0;
2023 }
2024 }
2025
Jouni Malinen47dcc952017-10-09 16:43:24 +03002026 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03002027 send_resp(dut, conn, SIGMA_ERROR,
2028 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002029 return 0;
2030 }
Jouni Malinenad395a22017-09-01 21:13:46 +03002031
2032 val = get_param(cmd, "GroupCipher");
2033 if (val) {
2034 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2035 if (set_network(ifname, id, "group", "GCMP-256") < 0)
2036 return -2;
2037 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2038 if (set_network(ifname, id, "group", "CCMP-256") < 0)
2039 return -2;
2040 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2041 if (set_network(ifname, id, "group", "GCMP") < 0)
2042 return -2;
2043 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2044 if (set_network(ifname, id, "group", "CCMP") < 0)
2045 return -2;
2046 } else {
2047 send_resp(dut, conn, SIGMA_ERROR,
2048 "errorCode,Unrecognized GroupCipher value");
2049 return 0;
2050 }
2051 }
2052
Jouni Malinen7b239522017-09-14 21:37:18 +03002053 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03002054 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03002055 const char *cipher;
2056
2057 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
2058 cipher = "BIP-GMAC-256";
2059 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
2060 cipher = "BIP-CMAC-256";
2061 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
2062 cipher = "BIP-GMAC-128";
2063 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
2064 cipher = "AES-128-CMAC";
2065 } else {
2066 send_resp(dut, conn, SIGMA_INVALID,
2067 "errorCode,Unsupported GroupMgntCipher");
2068 return 0;
2069 }
2070 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
2071 send_resp(dut, conn, SIGMA_INVALID,
2072 "errorCode,Failed to set GroupMgntCipher");
2073 return 0;
2074 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002075 }
2076
Jouni Malinene4fde732019-03-25 22:29:37 +02002077 val = get_param(cmd, "AKMSuiteType");
2078 if (val && set_akm_suites(dut, ifname, id, val) < 0)
2079 return ERROR_SEND_STATUS;
2080
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002081 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302082
2083 if (dut->program == PROGRAM_OCE) {
2084 dut->sta_pmf = STA_PMF_OPTIONAL;
2085 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2086 return -2;
2087 }
2088
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002089 val = get_param(cmd, "PMF");
2090 if (val) {
2091 if (strcasecmp(val, "Required") == 0 ||
2092 strcasecmp(val, "Forced_Required") == 0) {
2093 dut->sta_pmf = STA_PMF_REQUIRED;
2094 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2095 return -2;
2096 } else if (strcasecmp(val, "Optional") == 0) {
2097 dut->sta_pmf = STA_PMF_OPTIONAL;
2098 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2099 return -2;
2100 } else if (strcasecmp(val, "Disabled") == 0 ||
Kiran Kumar Lokere07da3b22018-12-16 22:42:49 -08002101 strcasecmp(val, "Disable") == 0 ||
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002102 strcasecmp(val, "Forced_Disabled") == 0) {
2103 dut->sta_pmf = STA_PMF_DISABLED;
2104 } else {
2105 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
2106 return 0;
2107 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05302108 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02002109 dut->sta_pmf = STA_PMF_REQUIRED;
2110 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2111 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002112 }
2113
Jouni Malinen0165c7f2020-03-26 11:51:58 +02002114 val = get_param(cmd, "BeaconProtection");
2115 if (val && atoi(val) == 1 &&
2116 set_network(ifname, id, "beacon_prot", "1") < 0)
2117 return ERROR_SEND_STATUS;
2118
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002119 return id;
2120}
2121
2122
Jouni Malinenf7222712019-06-13 01:50:21 +03002123static enum sigma_cmd_result cmd_sta_set_psk(struct sigma_dut *dut,
2124 struct sigma_conn *conn,
2125 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002126{
2127 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002128 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002129 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002130 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002131 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002132 const char *ifname, *val, *alg;
2133 int id;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002134 char buf[50];
Jouni Malinen11e55212019-11-22 21:46:59 +02002135 int sae_pwe = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002136
2137 if (intf == NULL)
2138 return -1;
2139
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002140 if (strcmp(intf, get_main_ifname(dut)) == 0)
2141 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002142 else
2143 ifname = intf;
2144
2145 id = set_wpa_common(dut, conn, ifname, cmd);
2146 if (id < 0)
2147 return id;
2148
2149 val = get_param(cmd, "keyMgmtType");
2150 alg = get_param(cmd, "micAlg");
2151
Jouni Malinen992a81e2017-08-22 13:57:47 +03002152 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002153 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002154 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2155 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002156 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002157 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2158 return -2;
2159 }
2160 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2161 sigma_dut_print(dut, DUT_MSG_ERROR,
2162 "Failed to clear sae_groups to default");
2163 return -2;
2164 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002165 if (!pmf) {
2166 dut->sta_pmf = STA_PMF_REQUIRED;
2167 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2168 return -2;
2169 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002170 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2171 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2172 if (set_network(ifname, id, "key_mgmt",
2173 "FT-SAE FT-PSK") < 0)
2174 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002175 } else if (!akm) {
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002176 if (set_network(ifname, id, "key_mgmt",
2177 "SAE WPA-PSK") < 0)
2178 return -2;
2179 }
2180 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2181 sigma_dut_print(dut, DUT_MSG_ERROR,
2182 "Failed to clear sae_groups to default");
2183 return -2;
2184 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002185 if (!pmf) {
2186 dut->sta_pmf = STA_PMF_OPTIONAL;
2187 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2188 return -2;
2189 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002190 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002191 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2192 return -2;
2193 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2194 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2195 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302196 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2197 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2198 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002199 } else if (!akm &&
2200 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2201 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002202 if (set_network(ifname, id, "key_mgmt",
2203 "WPA-PSK WPA-PSK-SHA256") < 0)
2204 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002205 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002206 if (set_network(ifname, id, "key_mgmt",
2207 "WPA-PSK WPA-PSK-SHA256") < 0)
2208 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002209 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002210 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2211 return -2;
2212 }
2213
2214 val = get_param(cmd, "passPhrase");
2215 if (val == NULL)
2216 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002217 if (type && strcasecmp(type, "SAE") == 0) {
2218 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2219 return -2;
2220 } else {
2221 if (set_network_quoted(ifname, id, "psk", val) < 0)
2222 return -2;
2223 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002224
Jouni Malinen78d10c42019-03-25 22:34:32 +02002225 val = get_param(cmd, "PasswordId");
2226 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2227 return ERROR_SEND_STATUS;
2228
Jouni Malinen992a81e2017-08-22 13:57:47 +03002229 val = get_param(cmd, "ECGroupID");
2230 if (val) {
Jouni Malinenb54f0df2019-12-12 01:57:29 +02002231 snprintf(buf, sizeof(buf), "SET sae_groups %s", val);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002232 if (wpa_command(ifname, buf) != 0) {
2233 sigma_dut_print(dut, DUT_MSG_ERROR,
2234 "Failed to clear sae_groups");
2235 return -2;
2236 }
2237 }
2238
Jouni Malinen68143132017-09-02 02:34:08 +03002239 val = get_param(cmd, "InvalidSAEElement");
2240 if (val) {
2241 free(dut->sae_commit_override);
2242 dut->sae_commit_override = strdup(val);
2243 }
2244
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002245 val = get_param(cmd, "PMKID_Include");
2246 if (val) {
2247 snprintf(buf, sizeof(buf), "SET sae_pmkid_in_assoc %d",
2248 get_enable_disable(val));
2249 wpa_command(intf, buf);
2250 }
2251
Jouni Malineneeb43d32019-12-06 17:40:07 +02002252 val = get_param(cmd, "IgnoreH2E_RSNXE_BSSMemSel");
2253 if (val) {
2254 snprintf(buf, sizeof(buf), "SET ignore_sae_h2e_only %d",
2255 get_enable_disable(val));
2256 wpa_command(intf, buf);
2257 }
2258
Jouni Malinenf2348d22019-12-07 11:52:55 +02002259 val = get_param(cmd, "ECGroupID_RGE");
2260 if (val) {
2261 snprintf(buf, sizeof(buf), "SET extra_sae_rejected_groups %s",
2262 val);
2263 wpa_command(intf, buf);
2264 }
2265
Jouni Malinen99e55022019-12-07 13:59:41 +02002266 val = get_param(cmd, "RSNXE_Content");
2267 if (val) {
2268 const char *param;
2269
2270 if (strncasecmp(val, "AssocReq:", 9) == 0) {
2271 val += 9;
2272 param = "rsnxe_override_assoc";
2273 } else if (strncasecmp(val, "EapolM2:", 8) == 0) {
2274 val += 8;
2275 param = "rsnxe_override_eapol";
2276 } else {
2277 send_resp(dut, conn, SIGMA_ERROR,
2278 "errorCode,Unsupported RSNXE_Content value");
2279 return STATUS_SENT_ERROR;
2280 }
2281 snprintf(buf, sizeof(buf), "SET %s %s", param, val);
2282 wpa_command(intf, buf);
2283 }
2284
Jouni Malinen11e55212019-11-22 21:46:59 +02002285 val = get_param(cmd, "sae_pwe");
2286 if (val) {
2287 if (strcasecmp(val, "h2e") == 0) {
2288 dut->sae_pwe = SAE_PWE_H2E;
Jouni Malinen7244a412019-12-07 11:54:10 +02002289 } else if (strcasecmp(val, "loop") == 0 ||
2290 strcasecmp(val, "looping") == 0) {
Jouni Malinen11e55212019-11-22 21:46:59 +02002291 dut->sae_pwe = SAE_PWE_LOOP;
2292 } else {
2293 send_resp(dut, conn, SIGMA_ERROR,
2294 "errorCode,Unsupported sae_pwe value");
2295 return STATUS_SENT_ERROR;
2296 }
2297 }
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302298
2299 val = get_param(cmd, "Clear_RSNXE");
2300 if (val && strcmp(val, "1") == 0 &&
2301 (wpa_command(intf, "SET rsnxe_override_assoc ") ||
2302 wpa_command(intf, "SET rsnxe_override_eapol "))) {
2303 send_resp(dut, conn, SIGMA_ERROR,
2304 "errorCode,Failed to clear RSNXE");
2305 return ERROR_SEND_STATUS;
2306 }
2307
Jouni Malinenc0078772020-03-04 21:23:16 +02002308 if (dut->sae_pwe == SAE_PWE_LOOP && get_param(cmd, "PasswordId"))
2309 sae_pwe = 3;
2310 else if (dut->sae_pwe == SAE_PWE_LOOP)
Jouni Malinen11e55212019-11-22 21:46:59 +02002311 sae_pwe = 0;
2312 else if (dut->sae_pwe == SAE_PWE_H2E)
2313 sae_pwe = 1;
2314 else if (dut->sae_h2e_default)
2315 sae_pwe = 2;
2316 snprintf(buf, sizeof(buf), "SET sae_pwe %d", sae_pwe);
2317 if (sae_pwe >= 0 && wpa_command(ifname, buf) != 0)
2318 return ERROR_SEND_STATUS;
2319
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002320 if (dut->program == PROGRAM_60GHZ && network_mode &&
2321 strcasecmp(network_mode, "PBSS") == 0 &&
2322 set_network(ifname, id, "pbss", "1") < 0)
2323 return -2;
2324
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002325 return 1;
2326}
2327
2328
Jouni Malinen8ac93452019-08-14 15:19:13 +03002329static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2330 struct sigma_conn *conn,
2331 const char *ifname, int id)
2332{
2333 char buf[200];
2334
2335 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2336 if (!file_exists(buf))
2337 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2338 if (!file_exists(buf))
2339 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2340 if (!file_exists(buf)) {
2341 char msg[300];
2342
2343 snprintf(msg, sizeof(msg),
2344 "ErrorCode,trustedRootCA system store (%s) not found",
2345 buf);
2346 send_resp(dut, conn, SIGMA_ERROR, msg);
2347 return STATUS_SENT_ERROR;
2348 }
2349
2350 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2351 return ERROR_SEND_STATUS;
2352
2353 return SUCCESS_SEND_STATUS;
2354}
2355
2356
2357static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2358 struct sigma_conn *conn,
2359 const char *ifname, int id,
2360 const char *val)
2361{
2362 char buf[200];
2363#ifdef ANDROID
2364 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2365 int length;
2366#endif /* ANDROID */
2367
2368 if (strcmp(val, "DEFAULT") == 0)
2369 return set_trust_root_system(dut, conn, ifname, id);
2370
2371#ifdef ANDROID
2372 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2373 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2374 if (length > 0) {
2375 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2376 buf);
2377 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2378 goto ca_cert_selected;
2379 }
2380#endif /* ANDROID */
2381
2382 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2383#ifdef __linux__
2384 if (!file_exists(buf)) {
2385 char msg[300];
2386
2387 snprintf(msg, sizeof(msg),
2388 "ErrorCode,trustedRootCA file (%s) not found", buf);
2389 send_resp(dut, conn, SIGMA_ERROR, msg);
2390 return STATUS_SENT_ERROR;
2391 }
2392#endif /* __linux__ */
2393#ifdef ANDROID
2394ca_cert_selected:
2395#endif /* ANDROID */
2396 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2397 return ERROR_SEND_STATUS;
2398
2399 return SUCCESS_SEND_STATUS;
2400}
2401
2402
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002403static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302404 const char *ifname, int username_identity,
2405 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002406{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002407 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002408 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002409 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002410 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002411 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002412
2413 id = set_wpa_common(dut, conn, ifname, cmd);
2414 if (id < 0)
2415 return id;
2416
2417 val = get_param(cmd, "keyMgmtType");
2418 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302419 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002420 trust_root = get_param(cmd, "trustedRootCA");
2421 domain = get_param(cmd, "Domain");
2422 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002423
Jouni Malinenad395a22017-09-01 21:13:46 +03002424 if (val && strcasecmp(val, "SuiteB") == 0) {
2425 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2426 0)
2427 return -2;
2428 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002429 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2430 return -2;
2431 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2432 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2433 return -2;
2434 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2435 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2436 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002437 } else if (!akm &&
2438 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2439 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002440 if (set_network(ifname, id, "key_mgmt",
2441 "WPA-EAP WPA-EAP-SHA256") < 0)
2442 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302443 } else if (akm && atoi(akm) == 14) {
2444 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2445 dut->sta_pmf == STA_PMF_REQUIRED) {
2446 if (set_network(ifname, id, "key_mgmt",
2447 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2448 return -2;
2449 } else {
2450 if (set_network(ifname, id, "key_mgmt",
2451 "WPA-EAP FILS-SHA256") < 0)
2452 return -2;
2453 }
2454
Jouni Malinen8179fee2019-03-28 03:19:47 +02002455 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302456 } else if (akm && atoi(akm) == 15) {
2457 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2458 dut->sta_pmf == STA_PMF_REQUIRED) {
2459 if (set_network(ifname, id, "key_mgmt",
2460 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2461 return -2;
2462 } else {
2463 if (set_network(ifname, id, "key_mgmt",
2464 "WPA-EAP FILS-SHA384") < 0)
2465 return -2;
2466 }
2467
Jouni Malinen8179fee2019-03-28 03:19:47 +02002468 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002469 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002470 if (set_network(ifname, id, "key_mgmt",
2471 "WPA-EAP WPA-EAP-SHA256") < 0)
2472 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002473 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002474 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2475 return -2;
2476 }
2477
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002478 if (trust_root) {
2479 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2480 !domain_suffix) {
2481 send_resp(dut, conn, SIGMA_ERROR,
2482 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2483 return STATUS_SENT_ERROR;
2484 }
2485 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002486 if (res != SUCCESS_SEND_STATUS)
2487 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002488 }
2489
Jouni Malinen53264f62019-05-03 13:04:40 +03002490 val = get_param(cmd, "ServerCert");
2491 if (val) {
2492 FILE *f;
2493 char *result = NULL, *pos;
2494
2495 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2496 val);
2497 f = fopen(buf, "r");
2498 if (f) {
2499 result = fgets(buf, sizeof(buf), f);
2500 fclose(f);
2501 }
2502 if (!result) {
2503 snprintf(buf2, sizeof(buf2),
2504 "ErrorCode,ServerCert hash could not be read from %s",
2505 buf);
2506 send_resp(dut, conn, SIGMA_ERROR, buf2);
2507 return STATUS_SENT_ERROR;
2508 }
2509 pos = strchr(buf, '\n');
2510 if (pos)
2511 *pos = '\0';
2512 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2513 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2514 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002515
2516 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2517 if (file_exists(buf)) {
2518 sigma_dut_print(dut, DUT_MSG_DEBUG,
2519 "TOD policy enabled for the configured ServerCert hash");
2520 dut->sta_tod_policy = 1;
2521 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002522 }
2523
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002524 if (domain &&
2525 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002526 return ERROR_SEND_STATUS;
2527
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002528 if (domain_suffix &&
2529 set_network_quoted(ifname, id, "domain_suffix_match",
2530 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002531 return ERROR_SEND_STATUS;
2532
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302533 if (username_identity) {
2534 val = get_param(cmd, "username");
2535 if (val) {
2536 if (set_network_quoted(ifname, id, "identity", val) < 0)
2537 return -2;
2538 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002539
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302540 val = get_param(cmd, "password");
2541 if (val) {
2542 if (set_network_quoted(ifname, id, "password", val) < 0)
2543 return -2;
2544 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002545 }
2546
Jouni Malinen8179fee2019-03-28 03:19:47 +02002547 if (dut->akm_values &
2548 ((1 << AKM_FILS_SHA256) |
2549 (1 << AKM_FILS_SHA384) |
2550 (1 << AKM_FT_FILS_SHA256) |
2551 (1 << AKM_FT_FILS_SHA384)))
2552 erp = 1;
2553 if (erp && set_network(ifname, id, "erp", "1") < 0)
2554 return ERROR_SEND_STATUS;
2555
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002556 dut->sta_associate_wait_connect = 1;
2557
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002558 return id;
2559}
2560
2561
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002562static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2563{
2564 const char *val;
2565
2566 if (!cipher)
2567 return 0;
2568
2569 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2570 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2571 else if (strcasecmp(cipher,
2572 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2573 val = "ECDHE-RSA-AES256-GCM-SHA384";
2574 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2575 val = "DHE-RSA-AES256-GCM-SHA384";
2576 else if (strcasecmp(cipher,
2577 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2578 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2579 else
2580 return -1;
2581
2582 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2583 set_network_quoted(ifname, id, "phase1", "");
2584
2585 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2586}
2587
2588
Jouni Malinenf7222712019-06-13 01:50:21 +03002589static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2590 struct sigma_conn *conn,
2591 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002592{
2593 const char *intf = get_param(cmd, "Interface");
2594 const char *ifname, *val;
2595 int id;
2596 char buf[200];
2597#ifdef ANDROID
2598 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2599 int length;
2600 int jb_or_newer = 0;
2601 char prop[PROPERTY_VALUE_MAX];
2602#endif /* ANDROID */
2603
2604 if (intf == NULL)
2605 return -1;
2606
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002607 if (strcmp(intf, get_main_ifname(dut)) == 0)
2608 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002609 else
2610 ifname = intf;
2611
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302612 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002613 if (id < 0)
2614 return id;
2615
2616 if (set_network(ifname, id, "eap", "TLS") < 0)
2617 return -2;
2618
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302619 if (!get_param(cmd, "username") &&
2620 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002621 "wifi-user@wifilabs.local") < 0)
2622 return -2;
2623
2624 val = get_param(cmd, "clientCertificate");
2625 if (val == NULL)
2626 return -1;
2627#ifdef ANDROID
2628 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2629 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2630 if (length < 0) {
2631 /*
2632 * JB started reporting keystore type mismatches, so retry with
2633 * the GET_PUBKEY command if the generic GET fails.
2634 */
2635 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2636 buf, kvalue);
2637 }
2638
2639 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2640 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2641 if (strncmp(prop, "4.0", 3) != 0)
2642 jb_or_newer = 1;
2643 } else
2644 jb_or_newer = 1; /* assume newer */
2645
2646 if (jb_or_newer && length > 0) {
2647 sigma_dut_print(dut, DUT_MSG_INFO,
2648 "Use Android keystore [%s]", buf);
2649 if (set_network(ifname, id, "engine", "1") < 0)
2650 return -2;
2651 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2652 return -2;
2653 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2654 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2655 return -2;
2656 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2657 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2658 return -2;
2659 return 1;
2660 } else if (length > 0) {
2661 sigma_dut_print(dut, DUT_MSG_INFO,
2662 "Use Android keystore [%s]", buf);
2663 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2664 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2665 return -2;
2666 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2667 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2668 return -2;
2669 return 1;
2670 }
2671#endif /* ANDROID */
2672
2673 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2674#ifdef __linux__
2675 if (!file_exists(buf)) {
2676 char msg[300];
2677 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2678 "(%s) not found", buf);
2679 send_resp(dut, conn, SIGMA_ERROR, msg);
2680 return -3;
2681 }
2682#endif /* __linux__ */
2683 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2684 return -2;
2685 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2686 return -2;
2687
2688 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2689 return -2;
2690
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002691 val = get_param(cmd, "keyMgmtType");
2692 if (val && strcasecmp(val, "SuiteB") == 0) {
2693 val = get_param(cmd, "CertType");
2694 if (val && strcasecmp(val, "RSA") == 0) {
2695 if (set_network_quoted(ifname, id, "phase1",
2696 "tls_suiteb=1") < 0)
2697 return -2;
2698 } else {
2699 if (set_network_quoted(ifname, id, "openssl_ciphers",
2700 "SUITEB192") < 0)
2701 return -2;
2702 }
2703
2704 val = get_param(cmd, "TLSCipher");
2705 if (set_tls_cipher(ifname, id, val) < 0) {
2706 send_resp(dut, conn, SIGMA_ERROR,
2707 "ErrorCode,Unsupported TLSCipher value");
2708 return -3;
2709 }
2710 }
2711
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002712 return 1;
2713}
2714
2715
Jouni Malinenf7222712019-06-13 01:50:21 +03002716static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2717 struct sigma_conn *conn,
2718 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002719{
2720 const char *intf = get_param(cmd, "Interface");
2721 const char *ifname;
2722 int id;
2723
2724 if (intf == NULL)
2725 return -1;
2726
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002727 if (strcmp(intf, get_main_ifname(dut)) == 0)
2728 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002729 else
2730 ifname = intf;
2731
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302732 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002733 if (id < 0)
2734 return id;
2735
2736 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2737 send_resp(dut, conn, SIGMA_ERROR,
2738 "errorCode,Failed to set TTLS method");
2739 return 0;
2740 }
2741
2742 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2743 send_resp(dut, conn, SIGMA_ERROR,
2744 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2745 return 0;
2746 }
2747
2748 return 1;
2749}
2750
2751
Jouni Malinenf7222712019-06-13 01:50:21 +03002752static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2753 struct sigma_conn *conn,
2754 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002755{
2756 const char *intf = get_param(cmd, "Interface");
2757 const char *ifname;
2758 int id;
2759
2760 if (intf == NULL)
2761 return -1;
2762
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002763 if (strcmp(intf, get_main_ifname(dut)) == 0)
2764 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002765 else
2766 ifname = intf;
2767
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302768 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002769 if (id < 0)
2770 return id;
2771
2772 if (set_network(ifname, id, "eap", "SIM") < 0)
2773 return -2;
2774
2775 return 1;
2776}
2777
2778
Jouni Malinenf7222712019-06-13 01:50:21 +03002779static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2780 struct sigma_conn *conn,
2781 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002782{
2783 const char *intf = get_param(cmd, "Interface");
2784 const char *ifname, *val;
2785 int id;
2786 char buf[100];
2787
2788 if (intf == NULL)
2789 return -1;
2790
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002791 if (strcmp(intf, get_main_ifname(dut)) == 0)
2792 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002793 else
2794 ifname = intf;
2795
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302796 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002797 if (id < 0)
2798 return id;
2799
2800 if (set_network(ifname, id, "eap", "PEAP") < 0)
2801 return -2;
2802
2803 val = get_param(cmd, "innerEAP");
2804 if (val) {
2805 if (strcasecmp(val, "MSCHAPv2") == 0) {
2806 if (set_network_quoted(ifname, id, "phase2",
2807 "auth=MSCHAPV2") < 0)
2808 return -2;
2809 } else if (strcasecmp(val, "GTC") == 0) {
2810 if (set_network_quoted(ifname, id, "phase2",
2811 "auth=GTC") < 0)
2812 return -2;
2813 } else
2814 return -1;
2815 }
2816
2817 val = get_param(cmd, "peapVersion");
2818 if (val) {
2819 int ver = atoi(val);
2820 if (ver < 0 || ver > 1)
2821 return -1;
2822 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2823 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2824 return -2;
2825 }
2826
2827 return 1;
2828}
2829
2830
Jouni Malinenf7222712019-06-13 01:50:21 +03002831static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2832 struct sigma_conn *conn,
2833 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002834{
2835 const char *intf = get_param(cmd, "Interface");
2836 const char *ifname, *val;
2837 int id;
2838 char buf[100];
2839
2840 if (intf == NULL)
2841 return -1;
2842
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002843 if (strcmp(intf, get_main_ifname(dut)) == 0)
2844 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002845 else
2846 ifname = intf;
2847
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302848 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002849 if (id < 0)
2850 return id;
2851
2852 if (set_network(ifname, id, "eap", "FAST") < 0)
2853 return -2;
2854
2855 val = get_param(cmd, "innerEAP");
2856 if (val) {
2857 if (strcasecmp(val, "MSCHAPV2") == 0) {
2858 if (set_network_quoted(ifname, id, "phase2",
2859 "auth=MSCHAPV2") < 0)
2860 return -2;
2861 } else if (strcasecmp(val, "GTC") == 0) {
2862 if (set_network_quoted(ifname, id, "phase2",
2863 "auth=GTC") < 0)
2864 return -2;
2865 } else
2866 return -1;
2867 }
2868
2869 val = get_param(cmd, "validateServer");
2870 if (val) {
2871 /* TODO */
2872 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2873 "validateServer=%s", val);
2874 }
2875
2876 val = get_param(cmd, "pacFile");
2877 if (val) {
2878 snprintf(buf, sizeof(buf), "blob://%s", val);
2879 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2880 return -2;
2881 }
2882
2883 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2884 0)
2885 return -2;
2886
2887 return 1;
2888}
2889
2890
Jouni Malinenf7222712019-06-13 01:50:21 +03002891static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2892 struct sigma_conn *conn,
2893 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002894{
2895 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302896 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002897 const char *ifname;
2898 int id;
2899
2900 if (intf == NULL)
2901 return -1;
2902
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002903 if (strcmp(intf, get_main_ifname(dut)) == 0)
2904 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002905 else
2906 ifname = intf;
2907
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302908 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002909 if (id < 0)
2910 return id;
2911
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302912 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2913 * hexadecimal).
2914 */
2915 if (username && username[0] == '6') {
2916 if (set_network(ifname, id, "eap", "AKA'") < 0)
2917 return -2;
2918 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002919 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302920 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002921
2922 return 1;
2923}
2924
2925
Jouni Malinenf7222712019-06-13 01:50:21 +03002926static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2927 struct sigma_conn *conn,
2928 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002929{
2930 const char *intf = get_param(cmd, "Interface");
2931 const char *ifname;
2932 int id;
2933
2934 if (intf == NULL)
2935 return -1;
2936
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002937 if (strcmp(intf, get_main_ifname(dut)) == 0)
2938 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002939 else
2940 ifname = intf;
2941
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302942 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002943 if (id < 0)
2944 return id;
2945
2946 if (set_network(ifname, id, "eap", "AKA'") < 0)
2947 return -2;
2948
2949 return 1;
2950}
2951
2952
2953static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2954 struct sigma_cmd *cmd)
2955{
2956 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002957 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002958 const char *ifname;
2959 int id;
2960
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002961 if (strcmp(intf, get_main_ifname(dut)) == 0)
2962 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002963 else
2964 ifname = intf;
2965
2966 id = add_network_common(dut, conn, ifname, cmd);
2967 if (id < 0)
2968 return id;
2969
2970 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2971 return -2;
2972
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002973 if (dut->program == PROGRAM_60GHZ && network_mode &&
2974 strcasecmp(network_mode, "PBSS") == 0 &&
2975 set_network(ifname, id, "pbss", "1") < 0)
2976 return -2;
2977
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002978 return 1;
2979}
2980
2981
Jouni Malinen47dcc952017-10-09 16:43:24 +03002982static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2983 struct sigma_cmd *cmd)
2984{
2985 const char *intf = get_param(cmd, "Interface");
2986 const char *ifname, *val;
2987 int id;
2988
2989 if (intf == NULL)
2990 return -1;
2991
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002992 if (strcmp(intf, get_main_ifname(dut)) == 0)
2993 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002994 else
2995 ifname = intf;
2996
2997 id = set_wpa_common(dut, conn, ifname, cmd);
2998 if (id < 0)
2999 return id;
3000
3001 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
3002 return -2;
3003
3004 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003005 if (val && strcmp(val, "0") == 0) {
3006 if (wpa_command(ifname,
3007 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
3008 sigma_dut_print(dut, DUT_MSG_ERROR,
3009 "Failed to set OWE DH Param element override");
3010 return -2;
3011 }
Hu Wang6010ce72020-03-05 19:33:53 +08003012 } else if (val &&
3013 (set_network(ifname, id, "owe_group", val) < 0 ||
3014 (dut->owe_ptk_workaround &&
3015 set_network(ifname, id, "owe_ptk_workaround", "1") < 0))) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003016 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003017 "Failed to set owe_group");
Jouni Malinen47dcc952017-10-09 16:43:24 +03003018 return -2;
3019 }
3020
3021 return 1;
3022}
3023
3024
Jouni Malinenf7222712019-06-13 01:50:21 +03003025static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3026 struct sigma_conn *conn,
3027 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003028{
3029 const char *type = get_param(cmd, "Type");
3030
3031 if (type == NULL) {
3032 send_resp(dut, conn, SIGMA_ERROR,
3033 "ErrorCode,Missing Type argument");
3034 return 0;
3035 }
3036
3037 if (strcasecmp(type, "OPEN") == 0)
3038 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003039 if (strcasecmp(type, "OWE") == 0)
3040 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003041 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003042 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003043 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003044 return cmd_sta_set_psk(dut, conn, cmd);
3045 if (strcasecmp(type, "EAPTLS") == 0)
3046 return cmd_sta_set_eaptls(dut, conn, cmd);
3047 if (strcasecmp(type, "EAPTTLS") == 0)
3048 return cmd_sta_set_eapttls(dut, conn, cmd);
3049 if (strcasecmp(type, "EAPPEAP") == 0)
3050 return cmd_sta_set_peap(dut, conn, cmd);
3051 if (strcasecmp(type, "EAPSIM") == 0)
3052 return cmd_sta_set_eapsim(dut, conn, cmd);
3053 if (strcasecmp(type, "EAPFAST") == 0)
3054 return cmd_sta_set_eapfast(dut, conn, cmd);
3055 if (strcasecmp(type, "EAPAKA") == 0)
3056 return cmd_sta_set_eapaka(dut, conn, cmd);
3057 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3058 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003059 if (strcasecmp(type, "wep") == 0)
3060 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003061
3062 send_resp(dut, conn, SIGMA_ERROR,
3063 "ErrorCode,Unsupported Type value");
3064 return 0;
3065}
3066
3067
3068int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3069{
3070#ifdef __linux__
3071 /* special handling for ath6kl */
3072 char path[128], fname[128], *pos;
3073 ssize_t res;
3074 FILE *f;
3075
Jouni Malinene39cd562019-05-29 23:39:56 +03003076 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3077 intf);
3078 if (res < 0 || res >= sizeof(fname))
3079 return 0;
3080 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003081 if (res < 0)
3082 return 0; /* not ath6kl */
3083
3084 if (res >= (int) sizeof(path))
3085 res = sizeof(path) - 1;
3086 path[res] = '\0';
3087 pos = strrchr(path, '/');
3088 if (pos == NULL)
3089 pos = path;
3090 else
3091 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003092 res = snprintf(fname, sizeof(fname),
3093 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3094 "create_qos", pos);
3095 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003096 return 0; /* not ath6kl */
3097
3098 if (uapsd) {
3099 f = fopen(fname, "w");
3100 if (f == NULL)
3101 return -1;
3102
3103 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3104 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3105 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3106 "20000 0\n");
3107 fclose(f);
3108 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003109 res = snprintf(fname, sizeof(fname),
3110 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3111 "delete_qos", pos);
3112 if (res < 0 || res >= sizeof(fname))
3113 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003114
3115 f = fopen(fname, "w");
3116 if (f == NULL)
3117 return -1;
3118
3119 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3120 fprintf(f, "2 4\n");
3121 fclose(f);
3122 }
3123#endif /* __linux__ */
3124
3125 return 0;
3126}
3127
3128
Jouni Malinenf7222712019-06-13 01:50:21 +03003129static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3130 struct sigma_conn *conn,
3131 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003132{
3133 const char *intf = get_param(cmd, "Interface");
3134 /* const char *ssid = get_param(cmd, "ssid"); */
3135 const char *val;
3136 int max_sp_len = 4;
3137 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3138 char buf[100];
3139 int ret1, ret2;
3140
3141 val = get_param(cmd, "maxSPLength");
3142 if (val) {
3143 max_sp_len = atoi(val);
3144 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3145 max_sp_len != 4)
3146 return -1;
3147 }
3148
3149 val = get_param(cmd, "acBE");
3150 if (val)
3151 ac_be = atoi(val);
3152
3153 val = get_param(cmd, "acBK");
3154 if (val)
3155 ac_bk = atoi(val);
3156
3157 val = get_param(cmd, "acVI");
3158 if (val)
3159 ac_vi = atoi(val);
3160
3161 val = get_param(cmd, "acVO");
3162 if (val)
3163 ac_vo = atoi(val);
3164
3165 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3166
3167 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3168 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3169 ret1 = wpa_command(intf, buf);
3170
3171 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3172 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3173 ret2 = wpa_command(intf, buf);
3174
3175 if (ret1 && ret2) {
3176 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3177 "UAPSD parameters.");
3178 return -2;
3179 }
3180
3181 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3182 send_resp(dut, conn, SIGMA_ERROR,
3183 "ErrorCode,Failed to set ath6kl QoS parameters");
3184 return 0;
3185 }
3186
3187 return 1;
3188}
3189
3190
Jouni Malinenf7222712019-06-13 01:50:21 +03003191static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3192 struct sigma_conn *conn,
3193 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003194{
3195 char buf[1000];
3196 const char *intf = get_param(cmd, "Interface");
3197 const char *grp = get_param(cmd, "Group");
3198 const char *act = get_param(cmd, "Action");
3199 const char *tid = get_param(cmd, "Tid");
3200 const char *dir = get_param(cmd, "Direction");
3201 const char *psb = get_param(cmd, "Psb");
3202 const char *up = get_param(cmd, "Up");
3203 const char *fixed = get_param(cmd, "Fixed");
3204 const char *size = get_param(cmd, "Size");
3205 const char *msize = get_param(cmd, "Maxsize");
3206 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3207 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3208 const char *inact = get_param(cmd, "Inactivity");
3209 const char *sus = get_param(cmd, "Suspension");
3210 const char *mindr = get_param(cmd, "Mindatarate");
3211 const char *meandr = get_param(cmd, "Meandatarate");
3212 const char *peakdr = get_param(cmd, "Peakdatarate");
3213 const char *phyrate = get_param(cmd, "Phyrate");
3214 const char *burstsize = get_param(cmd, "Burstsize");
3215 const char *sba = get_param(cmd, "Sba");
3216 int direction;
3217 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003218 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003219 int fixed_int;
3220 int psb_ts;
3221
3222 if (intf == NULL || grp == NULL || act == NULL )
3223 return -1;
3224
3225 if (strcasecmp(act, "addts") == 0) {
3226 if (tid == NULL || dir == NULL || psb == NULL ||
3227 up == NULL || fixed == NULL || size == NULL)
3228 return -1;
3229
3230 /*
3231 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3232 * possible values, but WMM-AC and V-E test scripts use "UP,
3233 * "DOWN", and "BIDI".
3234 */
3235 if (strcasecmp(dir, "uplink") == 0 ||
3236 strcasecmp(dir, "up") == 0) {
3237 direction = 0;
3238 } else if (strcasecmp(dir, "downlink") == 0 ||
3239 strcasecmp(dir, "down") == 0) {
3240 direction = 1;
3241 } else if (strcasecmp(dir, "bidi") == 0) {
3242 direction = 2;
3243 } else {
3244 sigma_dut_print(dut, DUT_MSG_ERROR,
3245 "Direction %s not supported", dir);
3246 return -1;
3247 }
3248
3249 if (strcasecmp(psb, "legacy") == 0) {
3250 psb_ts = 0;
3251 } else if (strcasecmp(psb, "uapsd") == 0) {
3252 psb_ts = 1;
3253 } else {
3254 sigma_dut_print(dut, DUT_MSG_ERROR,
3255 "PSB %s not supported", psb);
3256 return -1;
3257 }
3258
3259 if (atoi(tid) < 0 || atoi(tid) > 7) {
3260 sigma_dut_print(dut, DUT_MSG_ERROR,
3261 "TID %s not supported", tid);
3262 return -1;
3263 }
3264
3265 if (strcasecmp(fixed, "true") == 0) {
3266 fixed_int = 1;
3267 } else {
3268 fixed_int = 0;
3269 }
3270
Peng Xu93319622017-10-04 17:58:16 -07003271 if (sba)
3272 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003273
3274 dut->dialog_token++;
3275 handle = 7000 + dut->dialog_token;
3276
3277 /*
3278 * size: convert to hex
3279 * maxsi: convert to hex
3280 * mindr: convert to hex
3281 * meandr: convert to hex
3282 * peakdr: convert to hex
3283 * burstsize: convert to hex
3284 * phyrate: convert to hex
3285 * sba: convert to hex with modification
3286 * minsi: convert to integer
3287 * sus: convert to integer
3288 * inact: convert to integer
3289 * maxsi: convert to integer
3290 */
3291
3292 /*
3293 * The Nominal MSDU Size field is 2 octets long and contains an
3294 * unsigned integer that specifies the nominal size, in octets,
3295 * of MSDUs belonging to the traffic under this traffic
3296 * specification and is defined in Figure 16. If the Fixed
3297 * subfield is set to 1, then the size of the MSDU is fixed and
3298 * is indicated by the Size Subfield. If the Fixed subfield is
3299 * set to 0, then the size of the MSDU might not be fixed and
3300 * the Size indicates the nominal MSDU size.
3301 *
3302 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3303 * and specifies the excess allocation of time (and bandwidth)
3304 * over and above the stated rates required to transport an MSDU
3305 * belonging to the traffic in this TSPEC. This field is
3306 * represented as an unsigned binary number with an implicit
3307 * binary point after the leftmost 3 bits. For example, an SBA
3308 * of 1.75 is represented as 0x3800. This field is included to
3309 * account for retransmissions. As such, the value of this field
3310 * must be greater than unity.
3311 */
3312
3313 snprintf(buf, sizeof(buf),
3314 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3315 " 0x%X 0x%X 0x%X"
3316 " 0x%X 0x%X 0x%X"
3317 " 0x%X %d %d %d %d"
3318 " %d %d",
3319 intf, handle, tid, direction, psb_ts, up,
3320 (unsigned int) ((fixed_int << 15) | atoi(size)),
3321 msize ? atoi(msize) : 0,
3322 mindr ? atoi(mindr) : 0,
3323 meandr ? atoi(meandr) : 0,
3324 peakdr ? atoi(peakdr) : 0,
3325 burstsize ? atoi(burstsize) : 0,
3326 phyrate ? atoi(phyrate) : 0,
3327 sba ? ((unsigned int) (((int) sba_fv << 13) |
3328 (int)((sba_fv - (int) sba_fv) *
3329 8192))) : 0,
3330 minsi ? atoi(minsi) : 0,
3331 sus ? atoi(sus) : 0,
3332 0, 0,
3333 inact ? atoi(inact) : 0,
3334 maxsi ? atoi(maxsi) : 0);
3335
3336 if (system(buf) != 0) {
3337 sigma_dut_print(dut, DUT_MSG_ERROR,
3338 "iwpriv addtspec request failed");
3339 send_resp(dut, conn, SIGMA_ERROR,
3340 "errorCode,Failed to execute addTspec command");
3341 return 0;
3342 }
3343
3344 sigma_dut_print(dut, DUT_MSG_INFO,
3345 "iwpriv addtspec request send");
3346
3347 /* Mapping handle to a TID */
3348 dut->tid_to_handle[atoi(tid)] = handle;
3349 } else if (strcasecmp(act, "delts") == 0) {
3350 if (tid == NULL)
3351 return -1;
3352
3353 if (atoi(tid) < 0 || atoi(tid) > 7) {
3354 sigma_dut_print(dut, DUT_MSG_ERROR,
3355 "TID %s not supported", tid);
3356 send_resp(dut, conn, SIGMA_ERROR,
3357 "errorCode,Unsupported TID");
3358 return 0;
3359 }
3360
3361 handle = dut->tid_to_handle[atoi(tid)];
3362
3363 if (handle < 7000 || handle > 7255) {
3364 /* Invalid handle ie no mapping for that TID */
3365 sigma_dut_print(dut, DUT_MSG_ERROR,
3366 "handle-> %d not found", handle);
3367 }
3368
3369 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3370 intf, handle);
3371
3372 if (system(buf) != 0) {
3373 sigma_dut_print(dut, DUT_MSG_ERROR,
3374 "iwpriv deltspec request failed");
3375 send_resp(dut, conn, SIGMA_ERROR,
3376 "errorCode,Failed to execute delTspec command");
3377 return 0;
3378 }
3379
3380 sigma_dut_print(dut, DUT_MSG_INFO,
3381 "iwpriv deltspec request send");
3382
3383 dut->tid_to_handle[atoi(tid)] = 0;
3384 } else {
3385 sigma_dut_print(dut, DUT_MSG_ERROR,
3386 "Action type %s not supported", act);
3387 send_resp(dut, conn, SIGMA_ERROR,
3388 "errorCode,Unsupported Action");
3389 return 0;
3390 }
3391
3392 return 1;
3393}
3394
3395
vamsi krishna52e16f92017-08-29 12:37:34 +05303396static int find_network(struct sigma_dut *dut, const char *ssid)
3397{
3398 char list[4096];
3399 char *pos;
3400
3401 sigma_dut_print(dut, DUT_MSG_DEBUG,
3402 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003403 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303404 list, sizeof(list)) < 0)
3405 return -1;
3406 pos = strstr(list, ssid);
3407 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3408 return -1;
3409
3410 while (pos > list && pos[-1] != '\n')
3411 pos--;
3412 dut->infra_network_id = atoi(pos);
3413 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3414 return 0;
3415}
3416
3417
Sunil Dutt44595082018-02-12 19:41:45 +05303418#ifdef NL80211_SUPPORT
3419static int sta_config_rsnie(struct sigma_dut *dut, int val)
3420{
3421 struct nl_msg *msg;
3422 int ret;
3423 struct nlattr *params;
3424 int ifindex;
3425
3426 ifindex = if_nametoindex("wlan0");
3427 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3428 NL80211_CMD_VENDOR)) ||
3429 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3430 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3431 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3432 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
3433 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3434 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) {
3435 sigma_dut_print(dut, DUT_MSG_ERROR,
3436 "%s: err in adding vendor_cmd and vendor_data",
3437 __func__);
3438 nlmsg_free(msg);
3439 return -1;
3440 }
3441 nla_nest_end(msg, params);
3442
3443 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3444 if (ret) {
3445 sigma_dut_print(dut, DUT_MSG_ERROR,
3446 "%s: err in send_and_recv_msgs, ret=%d",
3447 __func__, ret);
3448 return ret;
3449 }
3450
3451 return 0;
3452}
3453#endif /* NL80211_SUPPORT */
3454
3455
Jouni Malinenf7222712019-06-13 01:50:21 +03003456static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3457 struct sigma_conn *conn,
3458 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003459{
3460 /* const char *intf = get_param(cmd, "Interface"); */
3461 const char *ssid = get_param(cmd, "ssid");
3462 const char *wps_param = get_param(cmd, "WPS");
3463 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003464 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003465 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003466 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003467 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003468 int e;
3469 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3470 struct wpa_ctrl *ctrl = NULL;
3471 int num_network_not_found = 0;
3472 int num_disconnected = 0;
3473 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003474
3475 if (ssid == NULL)
3476 return -1;
3477
Jouni Malinen37d5c692019-08-19 16:56:55 +03003478 dut->server_cert_tod = 0;
3479
Jouni Malinen3c367e82017-06-23 17:01:47 +03003480 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303481#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003482 if (get_driver_type(dut) == DRIVER_WCN) {
Sunil Dutt44595082018-02-12 19:41:45 +05303483 sta_config_rsnie(dut, 1);
3484 dut->config_rsnie = 1;
3485 }
3486#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003487 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3488 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003489 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03003490 send_resp(dut, conn, SIGMA_ERROR,
3491 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3492 return 0;
3493 }
3494 }
3495
Jouni Malinen68143132017-09-02 02:34:08 +03003496 if (dut->sae_commit_override) {
3497 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3498 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003499 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03003500 send_resp(dut, conn, SIGMA_ERROR,
3501 "ErrorCode,Failed to set SAE commit override");
3502 return 0;
3503 }
3504 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303505#ifdef ANDROID
3506 if (dut->fils_hlp)
3507 process_fils_hlp(dut);
3508#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003509
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003510 if (wps_param &&
3511 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3512 wps = 1;
3513
3514 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003515 if (dut->program == PROGRAM_60GHZ && network_mode &&
3516 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003517 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003518 "pbss", "1") < 0)
3519 return -2;
3520
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003521 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3522 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3523 "parameters not yet set");
3524 return 0;
3525 }
3526 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003527 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003528 return -2;
3529 } else {
3530 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3531 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003532 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003533 return -2;
3534 }
3535 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303536 if (strcmp(ssid, dut->infra_ssid) == 0) {
3537 sigma_dut_print(dut, DUT_MSG_DEBUG,
3538 "sta_associate for the most recently added network");
3539 } else if (find_network(dut, ssid) < 0) {
3540 sigma_dut_print(dut, DUT_MSG_DEBUG,
3541 "sta_associate for a previously stored network profile");
3542 send_resp(dut, conn, SIGMA_ERROR,
3543 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003544 return 0;
3545 }
3546
3547 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003548 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003549 "bssid", bssid) < 0) {
3550 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3551 "Invalid bssid argument");
3552 return 0;
3553 }
3554
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003555 if (dut->program == PROGRAM_WPA3 &&
3556 dut->sta_associate_wait_connect) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003557 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003558 if (!ctrl)
3559 return ERROR_SEND_STATUS;
3560 }
3561
Jouni Malinen46a19b62017-06-23 14:31:27 +03003562 extra[0] = '\0';
3563 if (chan)
3564 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003565 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003566 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3567 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003568 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003569 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3570 "network id %d on %s",
3571 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003572 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003573 ret = ERROR_SEND_STATUS;
3574 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003575 }
3576 }
3577
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003578 if (!ctrl)
3579 return SUCCESS_SEND_STATUS;
3580
3581 /* Wait for connection result to be able to store server certificate
3582 * hash for trust root override testing
3583 * (dev_exec_action,ServerCertTrust). */
3584
3585 for (e = 0; e < 20; e++) {
3586 const char *events[] = {
3587 "CTRL-EVENT-EAP-PEER-CERT",
3588 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3589 "CTRL-EVENT-DISCONNECTED",
3590 "CTRL-EVENT-CONNECTED",
3591 "CTRL-EVENT-NETWORK-NOT-FOUND",
3592 NULL
3593 };
3594 char buf[1024];
3595 int res;
3596
3597 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3598 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02003599 send_resp(dut, conn, SIGMA_COMPLETE,
3600 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003601 ret = STATUS_SENT_ERROR;
3602 break;
3603 }
3604 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3605 buf);
3606
3607 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3608 strstr(buf, " depth=0")) {
3609 char *pos = strstr(buf, " hash=");
3610
3611 if (pos) {
3612 char *end;
3613
Jouni Malinen34b19cb2019-08-16 16:37:17 +03003614 if (strstr(buf, " tod=1"))
3615 tod = 1;
3616 else if (strstr(buf, " tod=2"))
3617 tod = 2;
3618 else
3619 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003620 sigma_dut_print(dut, DUT_MSG_DEBUG,
3621 "Server certificate TOD policy: %d",
3622 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03003623 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003624
3625 pos += 6;
3626 end = strchr(pos, ' ');
3627 if (end)
3628 *end = '\0';
3629 strlcpy(dut->server_cert_hash, pos,
3630 sizeof(dut->server_cert_hash));
3631 sigma_dut_print(dut, DUT_MSG_DEBUG,
3632 "Server certificate hash: %s",
3633 dut->server_cert_hash);
3634 }
3635 }
3636
3637 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3638 send_resp(dut, conn, SIGMA_COMPLETE,
3639 "Result,TLS server certificate validation failed");
3640 ret = STATUS_SENT_ERROR;
3641 break;
3642 }
3643
3644 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3645 num_network_not_found++;
3646
3647 if (num_network_not_found > 2) {
3648 send_resp(dut, conn, SIGMA_COMPLETE,
3649 "Result,Network not found");
3650 ret = STATUS_SENT_ERROR;
3651 break;
3652 }
3653 }
3654
3655 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3656 num_disconnected++;
3657
3658 if (num_disconnected > 2) {
3659 send_resp(dut, conn, SIGMA_COMPLETE,
3660 "Result,Connection failed");
3661 ret = STATUS_SENT_ERROR;
3662 break;
3663 }
3664 }
3665
3666 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3667 if (tod >= 0) {
3668 sigma_dut_print(dut, DUT_MSG_DEBUG,
3669 "Network profile TOD policy update: %d -> %d",
3670 dut->sta_tod_policy, tod);
3671 dut->sta_tod_policy = tod;
3672 }
3673 break;
3674 }
3675 }
3676done:
3677 if (ctrl) {
3678 wpa_ctrl_detach(ctrl);
3679 wpa_ctrl_close(ctrl);
3680 }
3681 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003682}
3683
3684
3685static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3686{
3687 char buf[500], cmd[200];
3688 int res;
3689
3690 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3691 * default path */
3692 res = snprintf(cmd, sizeof(cmd),
3693 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3694 file_exists("./hs20-osu-client") ?
3695 "./hs20-osu-client" : "hs20-osu-client",
3696 sigma_wpas_ctrl,
3697 dut->summary_log ? "-s " : "",
3698 dut->summary_log ? dut->summary_log : "");
3699 if (res < 0 || res >= (int) sizeof(cmd))
3700 return -1;
3701
3702 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3703 if (res < 0 || res >= (int) sizeof(buf))
3704 return -1;
3705 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3706
3707 if (system(buf) != 0) {
3708 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3709 return -1;
3710 }
3711 sigma_dut_print(dut, DUT_MSG_DEBUG,
3712 "Completed hs20-osu-client operation");
3713
3714 return 0;
3715}
3716
3717
3718static int download_ppsmo(struct sigma_dut *dut,
3719 struct sigma_conn *conn,
3720 const char *intf,
3721 struct sigma_cmd *cmd)
3722{
3723 const char *name, *path, *val;
3724 char url[500], buf[600], fbuf[100];
3725 char *fqdn = NULL;
3726
3727 name = get_param(cmd, "FileName");
3728 path = get_param(cmd, "FilePath");
3729 if (name == NULL || path == NULL)
3730 return -1;
3731
3732 if (strcasecmp(path, "VendorSpecific") == 0) {
3733 snprintf(url, sizeof(url), "PPS/%s", name);
3734 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3735 "from the device (%s)", url);
3736 if (!file_exists(url)) {
3737 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3738 "PPS MO file does not exist");
3739 return 0;
3740 }
3741 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3742 if (system(buf) != 0) {
3743 send_resp(dut, conn, SIGMA_ERROR,
3744 "errorCode,Failed to copy PPS MO");
3745 return 0;
3746 }
3747 } else if (strncasecmp(path, "http:", 5) != 0 &&
3748 strncasecmp(path, "https:", 6) != 0) {
3749 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3750 "Unsupported FilePath value");
3751 return 0;
3752 } else {
3753 snprintf(url, sizeof(url), "%s/%s", path, name);
3754 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3755 url);
3756 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3757 remove("pps-tnds.xml");
3758 if (system(buf) != 0) {
3759 send_resp(dut, conn, SIGMA_ERROR,
3760 "errorCode,Failed to download PPS MO");
3761 return 0;
3762 }
3763 }
3764
3765 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3766 send_resp(dut, conn, SIGMA_ERROR,
3767 "errorCode,Failed to parse downloaded PPSMO");
3768 return 0;
3769 }
3770 unlink("pps-tnds.xml");
3771
3772 val = get_param(cmd, "managementTreeURI");
3773 if (val) {
3774 const char *pos, *end;
3775 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3776 val);
3777 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3778 send_resp(dut, conn, SIGMA_ERROR,
3779 "errorCode,Invalid managementTreeURI prefix");
3780 return 0;
3781 }
3782 pos = val + 8;
3783 end = strchr(pos, '/');
3784 if (end == NULL ||
3785 strcmp(end, "/PerProviderSubscription") != 0) {
3786 send_resp(dut, conn, SIGMA_ERROR,
3787 "errorCode,Invalid managementTreeURI postfix");
3788 return 0;
3789 }
3790 if (end - pos >= (int) sizeof(fbuf)) {
3791 send_resp(dut, conn, SIGMA_ERROR,
3792 "errorCode,Too long FQDN in managementTreeURI");
3793 return 0;
3794 }
3795 memcpy(fbuf, pos, end - pos);
3796 fbuf[end - pos] = '\0';
3797 fqdn = fbuf;
3798 sigma_dut_print(dut, DUT_MSG_INFO,
3799 "FQDN from managementTreeURI: %s", fqdn);
3800 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3801 FILE *f = fopen("pps-fqdn", "r");
3802 if (f) {
3803 if (fgets(fbuf, sizeof(fbuf), f)) {
3804 fbuf[sizeof(fbuf) - 1] = '\0';
3805 fqdn = fbuf;
3806 sigma_dut_print(dut, DUT_MSG_DEBUG,
3807 "Use FQDN %s", fqdn);
3808 }
3809 fclose(f);
3810 }
3811 }
3812
3813 if (fqdn == NULL) {
3814 send_resp(dut, conn, SIGMA_ERROR,
3815 "errorCode,No FQDN specified");
3816 return 0;
3817 }
3818
3819 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3820 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3821 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3822
3823 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3824 if (rename("pps.xml", buf) < 0) {
3825 send_resp(dut, conn, SIGMA_ERROR,
3826 "errorCode,Could not move PPS MO");
3827 return 0;
3828 }
3829
3830 if (strcasecmp(path, "VendorSpecific") == 0) {
3831 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3832 fqdn);
3833 if (system(buf)) {
3834 send_resp(dut, conn, SIGMA_ERROR,
3835 "errorCode,Failed to copy OSU CA cert");
3836 return 0;
3837 }
3838
3839 snprintf(buf, sizeof(buf),
3840 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3841 fqdn);
3842 if (system(buf)) {
3843 send_resp(dut, conn, SIGMA_ERROR,
3844 "errorCode,Failed to copy AAA CA cert");
3845 return 0;
3846 }
3847 } else {
3848 snprintf(buf, sizeof(buf),
3849 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3850 fqdn, fqdn);
3851 if (run_hs20_osu(dut, buf) < 0) {
3852 send_resp(dut, conn, SIGMA_ERROR,
3853 "errorCode,Failed to download OSU CA cert");
3854 return 0;
3855 }
3856
3857 snprintf(buf, sizeof(buf),
3858 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3859 fqdn, fqdn);
3860 if (run_hs20_osu(dut, buf) < 0) {
3861 sigma_dut_print(dut, DUT_MSG_INFO,
3862 "Failed to download AAA CA cert");
3863 }
3864 }
3865
3866 if (file_exists("next-client-cert.pem")) {
3867 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3868 if (rename("next-client-cert.pem", buf) < 0) {
3869 send_resp(dut, conn, SIGMA_ERROR,
3870 "errorCode,Could not move client certificate");
3871 return 0;
3872 }
3873 }
3874
3875 if (file_exists("next-client-key.pem")) {
3876 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3877 if (rename("next-client-key.pem", buf) < 0) {
3878 send_resp(dut, conn, SIGMA_ERROR,
3879 "errorCode,Could not move client key");
3880 return 0;
3881 }
3882 }
3883
3884 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3885 if (run_hs20_osu(dut, buf) < 0) {
3886 send_resp(dut, conn, SIGMA_ERROR,
3887 "errorCode,Failed to configure credential from "
3888 "PPSMO");
3889 return 0;
3890 }
3891
3892 return 1;
3893}
3894
3895
3896static int download_cert(struct sigma_dut *dut,
3897 struct sigma_conn *conn,
3898 const char *intf,
3899 struct sigma_cmd *cmd)
3900{
3901 const char *name, *path;
3902 char url[500], buf[600];
3903
3904 name = get_param(cmd, "FileName");
3905 path = get_param(cmd, "FilePath");
3906 if (name == NULL || path == NULL)
3907 return -1;
3908
3909 if (strcasecmp(path, "VendorSpecific") == 0) {
3910 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
3911 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3912 "certificate from the device (%s)", url);
3913 if (!file_exists(url)) {
3914 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3915 "certificate file does not exist");
3916 return 0;
3917 }
3918 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
3919 if (system(buf) != 0) {
3920 send_resp(dut, conn, SIGMA_ERROR,
3921 "errorCode,Failed to copy client "
3922 "certificate");
3923 return 0;
3924 }
3925
3926 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
3927 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3928 "private key from the device (%s)", url);
3929 if (!file_exists(url)) {
3930 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3931 "private key file does not exist");
3932 return 0;
3933 }
3934 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
3935 if (system(buf) != 0) {
3936 send_resp(dut, conn, SIGMA_ERROR,
3937 "errorCode,Failed to copy client key");
3938 return 0;
3939 }
3940 } else if (strncasecmp(path, "http:", 5) != 0 &&
3941 strncasecmp(path, "https:", 6) != 0) {
3942 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3943 "Unsupported FilePath value");
3944 return 0;
3945 } else {
3946 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
3947 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
3948 "certificate/key from %s", url);
3949 snprintf(buf, sizeof(buf),
3950 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
3951 if (system(buf) != 0) {
3952 send_resp(dut, conn, SIGMA_ERROR,
3953 "errorCode,Failed to download client "
3954 "certificate");
3955 return 0;
3956 }
3957
3958 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
3959 {
3960 send_resp(dut, conn, SIGMA_ERROR,
3961 "errorCode,Failed to copy client key");
3962 return 0;
3963 }
3964 }
3965
3966 return 1;
3967}
3968
3969
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003970static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
3971 struct sigma_conn *conn,
3972 struct sigma_cmd *cmd)
3973{
3974 const char *val;
3975 const char *intf = get_param(cmd, "interface");
3976
3977 if (!intf)
3978 return -1;
3979
3980 val = get_param(cmd, "WscIEFragment");
3981 if (val && strcasecmp(val, "enable") == 0) {
3982 sigma_dut_print(dut, DUT_MSG_DEBUG,
3983 "Enable WSC IE fragmentation");
3984
3985 dut->wsc_fragment = 1;
3986 /* set long attributes to force fragmentation */
3987 if (wpa_command(intf, "SET device_name "
3988 WPS_LONG_DEVICE_NAME) < 0)
3989 return -2;
3990 if (wpa_command(intf, "SET manufacturer "
3991 WPS_LONG_MANUFACTURER) < 0)
3992 return -2;
3993 if (wpa_command(intf, "SET model_name "
3994 WPS_LONG_MODEL_NAME) < 0)
3995 return -2;
3996 if (wpa_command(intf, "SET model_number "
3997 WPS_LONG_MODEL_NUMBER) < 0)
3998 return -2;
3999 if (wpa_command(intf, "SET serial_number "
4000 WPS_LONG_SERIAL_NUMBER) < 0)
4001 return -2;
4002 }
4003
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02004004 val = get_param(cmd, "RSN_IE");
4005 if (val) {
4006 if (strcasecmp(val, "disable") == 0)
4007 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
4008 else if (strcasecmp(val, "enable") == 0)
4009 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
4010 }
4011
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004012 val = get_param(cmd, "WpsVersion");
4013 if (val)
4014 dut->wps_forced_version = get_wps_forced_version(dut, val);
4015
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004016 val = get_param(cmd, "WscEAPFragment");
4017 if (val && strcasecmp(val, "enable") == 0)
4018 dut->eap_fragment = 1;
4019
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004020 return 1;
4021}
4022
4023
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004024static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4025 struct sigma_conn *conn,
4026 const char *intf,
4027 struct sigma_cmd *cmd)
4028{
4029 const char *val;
4030
4031 val = get_param(cmd, "FileType");
4032 if (val && strcasecmp(val, "PPSMO") == 0)
4033 return download_ppsmo(dut, conn, intf, cmd);
4034 if (val && strcasecmp(val, "CERT") == 0)
4035 return download_cert(dut, conn, intf, cmd);
4036 if (val) {
4037 send_resp(dut, conn, SIGMA_ERROR,
4038 "ErrorCode,Unsupported FileType");
4039 return 0;
4040 }
4041
4042 return 1;
4043}
4044
4045
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304046static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4047 struct sigma_conn *conn,
4048 const char *intf,
4049 struct sigma_cmd *cmd)
4050{
4051 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304052 char buf[1000];
4053 char text[20];
4054 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304055
4056 val = get_param(cmd, "OCESupport");
4057 if (val && strcasecmp(val, "Disable") == 0) {
4058 if (wpa_command(intf, "SET oce 0") < 0) {
4059 send_resp(dut, conn, SIGMA_ERROR,
4060 "ErrorCode,Failed to disable OCE");
4061 return 0;
4062 }
4063 } else if (val && strcasecmp(val, "Enable") == 0) {
4064 if (wpa_command(intf, "SET oce 1") < 0) {
4065 send_resp(dut, conn, SIGMA_ERROR,
4066 "ErrorCode,Failed to enable OCE");
4067 return 0;
4068 }
4069 }
4070
vamsi krishnaa2799492017-12-05 14:28:01 +05304071 val = get_param(cmd, "FILScap");
4072 if (val && (atoi(val) == 1)) {
4073 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4074 send_resp(dut, conn, SIGMA_ERROR,
4075 "ErrorCode,Failed to enable FILS");
4076 return 0;
4077 }
4078 } else if (val && (atoi(val) == 0)) {
4079 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4080 send_resp(dut, conn, SIGMA_ERROR,
4081 "ErrorCode,Failed to disable FILS");
4082 return 0;
4083 }
4084 }
4085
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304086 val = get_param(cmd, "FILSHLP");
4087 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004088 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304089 sizeof(text)) < 0)
4090 return -2;
4091 hwaddr_aton(text, addr);
4092 snprintf(buf, sizeof(buf),
4093 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4094 "080045100140000040004011399e00000000ffffffff00440043"
4095 "012cb30001010600fd4f46410000000000000000000000000000"
4096 "000000000000"
4097 "%02x%02x%02x%02x%02x%02x"
4098 "0000000000000000000000000000000000000000000000000000"
4099 "0000000000000000000000000000000000000000000000000000"
4100 "0000000000000000000000000000000000000000000000000000"
4101 "0000000000000000000000000000000000000000000000000000"
4102 "0000000000000000000000000000000000000000000000000000"
4103 "0000000000000000000000000000000000000000000000000000"
4104 "0000000000000000000000000000000000000000000000000000"
4105 "0000000000000000000000000000000000000000638253633501"
4106 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4107 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4108 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4109 if (wpa_command(intf, buf)) {
4110 send_resp(dut, conn, SIGMA_ERROR,
4111 "ErrorCode,Failed to add HLP");
4112 return 0;
4113 }
4114 dut->fils_hlp = 1;
4115 }
4116
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304117 return 1;
4118}
4119
4120
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004121static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4122 const char *val)
4123{
4124 int counter = 0;
4125 char token[50];
4126 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304127 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004128
Peng Xub8fc5cc2017-05-10 17:27:28 -07004129 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004130 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304131 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004132 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004133 if (strcmp(result, "disable") == 0)
4134 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4135 else
4136 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304137 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004138 counter++;
4139 }
4140}
4141
4142
4143static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4144 const char *val)
4145{
4146 char buf[100];
4147
4148 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4149 if (system(buf) != 0) {
4150 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4151 }
4152}
4153
4154
4155static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4156 const char *val)
4157{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004158 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004159 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004160 }
4161}
4162
4163
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004164static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4165 const char *val)
4166{
4167#ifdef NL80211_SUPPORT
4168 struct nl_msg *msg;
4169 int ret = 0;
4170 struct nlattr *params;
4171 int ifindex;
4172 int wmmenable = 1;
4173
4174 if (val &&
4175 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4176 wmmenable = 0;
4177
4178 ifindex = if_nametoindex(intf);
4179 if (ifindex == 0) {
4180 sigma_dut_print(dut, DUT_MSG_ERROR,
4181 "%s: Index for interface %s failed",
4182 __func__, intf);
4183 return -1;
4184 }
4185
4186 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4187 NL80211_CMD_VENDOR)) ||
4188 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4189 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4190 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4191 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4192 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4193 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4194 wmmenable)) {
4195 sigma_dut_print(dut, DUT_MSG_ERROR,
4196 "%s: err in adding vendor_cmd and vendor_data",
4197 __func__);
4198 nlmsg_free(msg);
4199 return -1;
4200 }
4201 nla_nest_end(msg, params);
4202
4203 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4204 if (ret) {
4205 sigma_dut_print(dut, DUT_MSG_ERROR,
4206 "%s: err in send_and_recv_msgs, ret=%d",
4207 __func__, ret);
4208 }
4209 return ret;
4210#else /* NL80211_SUPPORT */
4211 sigma_dut_print(dut, DUT_MSG_ERROR,
4212 "WMM cannot be changed without NL80211_SUPPORT defined");
4213 return -1;
4214#endif /* NL80211_SUPPORT */
4215}
4216
4217
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004218static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4219 const char *val)
4220{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004221 int sgi20;
4222
4223 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4224
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004225 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004226}
4227
4228
4229static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4230 const char *val)
4231{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304232 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004233
4234 /* Disable Tx Beam forming when using a fixed rate */
4235 ath_disable_txbf(dut, intf);
4236
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304237 v = atoi(val);
4238 if (v < 0 || v > 32) {
4239 sigma_dut_print(dut, DUT_MSG_ERROR,
4240 "Invalid Fixed MCS rate: %d", v);
4241 return;
4242 }
4243 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004244
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004245 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004246
4247 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004248 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004249}
4250
4251
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004252static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4253 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004254{
4255 char buf[60];
4256
4257 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4258 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4259 else
4260 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4261
4262 if (system(buf) != 0)
4263 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4264}
4265
4266
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004267static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4268 int ampdu)
4269{
4270 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004271 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004272
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004273 if (ampdu)
4274 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004275 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4276 if (system(buf) != 0) {
4277 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4278 return -1;
4279 }
4280
4281 return 0;
4282}
4283
4284
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004285static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4286 const char *val)
4287{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004288 run_iwpriv(dut, intf, "tx_stbc %s", val);
4289 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004290}
4291
4292
4293static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4294 const char *val)
4295{
4296 char buf[60];
4297
Peng Xucc317ed2017-05-18 16:44:37 -07004298 if (strcmp(val, "160") == 0) {
4299 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4300 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004301 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4302 } else if (strcmp(val, "40") == 0) {
4303 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4304 } else if (strcmp(val, "20") == 0) {
4305 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4306 } else if (strcasecmp(val, "Auto") == 0) {
4307 buf[0] = '\0';
4308 } else {
4309 sigma_dut_print(dut, DUT_MSG_ERROR,
4310 "WIDTH/CTS_WIDTH value not supported");
4311 return -1;
4312 }
4313
4314 if (buf[0] != '\0' && system(buf) != 0) {
4315 sigma_dut_print(dut, DUT_MSG_ERROR,
4316 "Failed to set WIDTH/CTS_WIDTH");
4317 return -1;
4318 }
4319
4320 return 0;
4321}
4322
4323
4324int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4325 const char *intf, const char *val)
4326{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004327 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004328 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004329 dut->chwidth = 0;
4330 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004331 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004332 dut->chwidth = 0;
4333 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004334 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004335 dut->chwidth = 1;
4336 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004337 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004338 dut->chwidth = 2;
4339 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004340 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004341 dut->chwidth = 3;
4342 } else {
4343 send_resp(dut, conn, SIGMA_ERROR,
4344 "ErrorCode,WIDTH not supported");
4345 return -1;
4346 }
4347
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004348 return 0;
4349}
4350
4351
4352static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4353 const char *val)
4354{
4355 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004356 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004357
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004358 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004359 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004360 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004361 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004362 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004363 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004364 } else {
4365 sigma_dut_print(dut, DUT_MSG_ERROR,
4366 "SP_STREAM value not supported");
4367 return -1;
4368 }
4369
4370 if (system(buf) != 0) {
4371 sigma_dut_print(dut, DUT_MSG_ERROR,
4372 "Failed to set SP_STREAM");
4373 return -1;
4374 }
4375
Arif Hussainac6c5112018-05-25 17:34:00 -07004376 dut->sta_nss = sta_nss;
4377
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004378 return 0;
4379}
4380
4381
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304382static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4383 const char *val)
4384{
4385 char buf[60];
4386
4387 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
4388 if (system(buf) != 0)
4389 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4390
4391 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
4392 if (system(buf) != 0)
4393 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4394}
4395
4396
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304397static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4398 struct sigma_conn *conn,
4399 const char *intf, int capa)
4400{
4401 char buf[32];
4402
4403 if (capa > 0 && capa < 4) {
4404 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4405 if (wpa_command(intf, buf) < 0) {
4406 send_resp(dut, conn, SIGMA_ERROR,
4407 "ErrorCode, Failed to set cellular data capability");
4408 return 0;
4409 }
4410 return 1;
4411 }
4412
4413 sigma_dut_print(dut, DUT_MSG_ERROR,
4414 "Invalid Cellular data capability: %d", capa);
4415 send_resp(dut, conn, SIGMA_INVALID,
4416 "ErrorCode,Invalid cellular data capability");
4417 return 0;
4418}
4419
4420
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304421static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4422 const char *intf, const char *val)
4423{
4424 if (strcasecmp(val, "Disable") == 0) {
4425 if (wpa_command(intf, "SET roaming 0") < 0) {
4426 send_resp(dut, conn, SIGMA_ERROR,
4427 "ErrorCode,Failed to disable roaming");
4428 return 0;
4429 }
4430 return 1;
4431 }
4432
4433 if (strcasecmp(val, "Enable") == 0) {
4434 if (wpa_command(intf, "SET roaming 1") < 0) {
4435 send_resp(dut, conn, SIGMA_ERROR,
4436 "ErrorCode,Failed to enable roaming");
4437 return 0;
4438 }
4439 return 1;
4440 }
4441
4442 sigma_dut_print(dut, DUT_MSG_ERROR,
4443 "Invalid value provided for roaming: %s", val);
4444 send_resp(dut, conn, SIGMA_INVALID,
4445 "ErrorCode,Unknown value provided for Roaming");
4446 return 0;
4447}
4448
4449
Ashwini Patila75de5a2017-04-13 16:35:05 +05304450static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4451 struct sigma_conn *conn,
4452 const char *intf, const char *val)
4453{
4454 if (strcasecmp(val, "Disable") == 0) {
4455 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4456 send_resp(dut, conn, SIGMA_ERROR,
4457 "ErrorCode,Failed to disable Assoc_disallow");
4458 return 0;
4459 }
4460 return 1;
4461 }
4462
4463 if (strcasecmp(val, "Enable") == 0) {
4464 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4465 send_resp(dut, conn, SIGMA_ERROR,
4466 "ErrorCode,Failed to enable Assoc_disallow");
4467 return 0;
4468 }
4469 return 1;
4470 }
4471
4472 sigma_dut_print(dut, DUT_MSG_ERROR,
4473 "Invalid value provided for Assoc_disallow: %s", val);
4474 send_resp(dut, conn, SIGMA_INVALID,
4475 "ErrorCode,Unknown value provided for Assoc_disallow");
4476 return 0;
4477}
4478
4479
Ashwini Patilc63161e2017-04-13 16:30:23 +05304480static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4481 const char *intf, const char *val)
4482{
4483 if (strcasecmp(val, "Reject") == 0) {
4484 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4485 send_resp(dut, conn, SIGMA_ERROR,
4486 "ErrorCode,Failed to Reject BTM Request");
4487 return 0;
4488 }
4489 return 1;
4490 }
4491
4492 if (strcasecmp(val, "Accept") == 0) {
4493 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4494 send_resp(dut, conn, SIGMA_ERROR,
4495 "ErrorCode,Failed to Accept BTM Request");
4496 return 0;
4497 }
4498 return 1;
4499 }
4500
4501 sigma_dut_print(dut, DUT_MSG_ERROR,
4502 "Invalid value provided for BSS_Transition: %s", val);
4503 send_resp(dut, conn, SIGMA_INVALID,
4504 "ErrorCode,Unknown value provided for BSS_Transition");
4505 return 0;
4506}
4507
4508
Ashwini Patil00402582017-04-13 12:29:39 +05304509static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4510 struct sigma_conn *conn,
4511 const char *intf,
4512 struct sigma_cmd *cmd)
4513{
4514 const char *ch, *pref, *op_class, *reason;
4515 char buf[120];
4516 int len, ret;
4517
4518 pref = get_param(cmd, "Ch_Pref");
4519 if (!pref)
4520 return 1;
4521
4522 if (strcasecmp(pref, "clear") == 0) {
4523 free(dut->non_pref_ch_list);
4524 dut->non_pref_ch_list = NULL;
4525 } else {
4526 op_class = get_param(cmd, "Ch_Op_Class");
4527 if (!op_class) {
4528 send_resp(dut, conn, SIGMA_INVALID,
4529 "ErrorCode,Ch_Op_Class not provided");
4530 return 0;
4531 }
4532
4533 ch = get_param(cmd, "Ch_Pref_Num");
4534 if (!ch) {
4535 send_resp(dut, conn, SIGMA_INVALID,
4536 "ErrorCode,Ch_Pref_Num not provided");
4537 return 0;
4538 }
4539
4540 reason = get_param(cmd, "Ch_Reason_Code");
4541 if (!reason) {
4542 send_resp(dut, conn, SIGMA_INVALID,
4543 "ErrorCode,Ch_Reason_Code not provided");
4544 return 0;
4545 }
4546
4547 if (!dut->non_pref_ch_list) {
4548 dut->non_pref_ch_list =
4549 calloc(1, NON_PREF_CH_LIST_SIZE);
4550 if (!dut->non_pref_ch_list) {
4551 send_resp(dut, conn, SIGMA_ERROR,
4552 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4553 return 0;
4554 }
4555 }
4556 len = strlen(dut->non_pref_ch_list);
4557 ret = snprintf(dut->non_pref_ch_list + len,
4558 NON_PREF_CH_LIST_SIZE - len,
4559 " %s:%s:%s:%s", op_class, ch, pref, reason);
4560 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4561 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4562 dut->non_pref_ch_list);
4563 } else {
4564 sigma_dut_print(dut, DUT_MSG_ERROR,
4565 "snprintf failed for non_pref_list, ret = %d",
4566 ret);
4567 send_resp(dut, conn, SIGMA_ERROR,
4568 "ErrorCode,snprintf failed");
4569 free(dut->non_pref_ch_list);
4570 dut->non_pref_ch_list = NULL;
4571 return 0;
4572 }
4573 }
4574
4575 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4576 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4577 if (ret < 0 || ret >= (int) sizeof(buf)) {
4578 sigma_dut_print(dut, DUT_MSG_DEBUG,
4579 "snprintf failed for set non_pref_chan, ret: %d",
4580 ret);
4581 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4582 return 0;
4583 }
4584
4585 if (wpa_command(intf, buf) < 0) {
4586 send_resp(dut, conn, SIGMA_ERROR,
4587 "ErrorCode,Failed to set non-preferred channel list");
4588 return 0;
4589 }
4590
4591 return 1;
4592}
4593
4594
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004595#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004596
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004597static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4598 uint8_t cfg)
4599{
4600 struct nl_msg *msg;
4601 int ret = 0;
4602 struct nlattr *params;
4603 int ifindex;
4604
4605 ifindex = if_nametoindex(intf);
4606 if (ifindex == 0) {
4607 sigma_dut_print(dut, DUT_MSG_ERROR,
4608 "%s: Index for interface %s failed",
4609 __func__, intf);
4610 return -1;
4611 }
4612
4613 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4614 NL80211_CMD_VENDOR)) ||
4615 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4616 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4617 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4618 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4619 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4620 nla_put_u8(msg,
4621 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4622 cfg)) {
4623 sigma_dut_print(dut, DUT_MSG_ERROR,
4624 "%s: err in adding vendor_cmd and vendor_data",
4625 __func__);
4626 nlmsg_free(msg);
4627 return -1;
4628 }
4629 nla_nest_end(msg, params);
4630
4631 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4632 if (ret) {
4633 sigma_dut_print(dut, DUT_MSG_ERROR,
4634 "%s: err in send_and_recv_msgs, ret=%d",
4635 __func__, ret);
4636 }
4637 return ret;
4638}
4639
4640
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004641static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4642 enum he_fragmentation_val frag)
4643{
4644 struct nl_msg *msg;
4645 int ret = 0;
4646 struct nlattr *params;
4647 int ifindex;
4648
4649 ifindex = if_nametoindex(intf);
4650 if (ifindex == 0) {
4651 sigma_dut_print(dut, DUT_MSG_ERROR,
4652 "%s: Index for interface %s failed",
4653 __func__, intf);
4654 return -1;
4655 }
4656
4657 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4658 NL80211_CMD_VENDOR)) ||
4659 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4660 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4661 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4662 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4663 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4664 nla_put_u8(msg,
4665 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
4666 frag)) {
4667 sigma_dut_print(dut, DUT_MSG_ERROR,
4668 "%s: err in adding vendor_cmd and vendor_data",
4669 __func__);
4670 nlmsg_free(msg);
4671 return -1;
4672 }
4673 nla_nest_end(msg, params);
4674
4675 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4676 if (ret) {
4677 sigma_dut_print(dut, DUT_MSG_ERROR,
4678 "%s: err in send_and_recv_msgs, ret=%d",
4679 __func__, ret);
4680 }
4681 return ret;
4682}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004683
4684
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08004685int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
4686 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004687{
4688 struct nl_msg *msg;
4689 int ret = 0;
4690 struct nlattr *params;
4691 int ifindex;
4692
4693 ifindex = if_nametoindex(intf);
4694 if (ifindex == 0) {
4695 sigma_dut_print(dut, DUT_MSG_ERROR,
4696 "%s: Index for interface %s failed",
4697 __func__, intf);
4698 return -1;
4699 }
4700
4701 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4702 NL80211_CMD_VENDOR)) ||
4703 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4704 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4705 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4706 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4707 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4708 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
4709 ltf)) {
4710 sigma_dut_print(dut, DUT_MSG_ERROR,
4711 "%s: err in adding vendor_cmd and vendor_data",
4712 __func__);
4713 nlmsg_free(msg);
4714 return -1;
4715 }
4716 nla_nest_end(msg, params);
4717
4718 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4719 if (ret) {
4720 sigma_dut_print(dut, DUT_MSG_ERROR,
4721 "%s: err in send_and_recv_msgs, ret=%d",
4722 __func__, ret);
4723 }
4724 return ret;
4725}
4726
4727
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004728static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4729 int noack, enum qca_wlan_ac_type ac)
4730{
4731 struct nl_msg *msg;
4732 int ret = 0;
4733 struct nlattr *params;
4734 int ifindex;
4735
4736 ifindex = if_nametoindex(intf);
4737 if (ifindex == 0) {
4738 sigma_dut_print(dut, DUT_MSG_ERROR,
4739 "%s: Index for interface %s failed",
4740 __func__, intf);
4741 return -1;
4742 }
4743
4744 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4745 NL80211_CMD_VENDOR)) ||
4746 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4747 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4748 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4749 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4750 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4751 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4752 noack) ||
4753 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4754 ac)) {
4755 sigma_dut_print(dut, DUT_MSG_ERROR,
4756 "%s: err in adding vendor_cmd and vendor_data",
4757 __func__);
4758 nlmsg_free(msg);
4759 return -1;
4760 }
4761 nla_nest_end(msg, params);
4762
4763 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4764 if (ret) {
4765 sigma_dut_print(dut, DUT_MSG_ERROR,
4766 "%s: err in send_and_recv_msgs, ret=%d",
4767 __func__, ret);
4768 }
4769 return ret;
4770}
4771
4772
4773static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4774 const char *val)
4775{
4776 int noack, ret;
4777 char token[100];
4778 char *result;
4779 char *saveptr;
4780 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4781
4782 strlcpy(token, val, sizeof(token));
4783 token[sizeof(token) - 1] = '\0';
4784 result = strtok_r(token, ":", &saveptr);
4785 while (result) {
4786 noack = strcasecmp(result, "Disable") != 0;
4787 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4788 if (ret) {
4789 sigma_dut_print(dut, DUT_MSG_ERROR,
4790 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4791 ac, ret);
4792 }
4793 result = strtok_r(NULL, ":", &saveptr);
4794 ac++;
4795 }
4796}
4797
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004798#endif /* NL80211_SUPPORT */
4799
4800
Jouni Malinenf7222712019-06-13 01:50:21 +03004801static enum sigma_cmd_result
4802cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
4803 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004804{
4805 const char *intf = get_param(cmd, "Interface");
4806 const char *val;
4807
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03004808 val = get_param(cmd, "FT_DS");
4809 if (val) {
4810 if (strcasecmp(val, "Enable") == 0) {
4811 dut->sta_ft_ds = 1;
4812 } else if (strcasecmp(val, "Disable") == 0) {
4813 dut->sta_ft_ds = 0;
4814 } else {
4815 send_resp(dut, conn, SIGMA_ERROR,
4816 "errorCode,Unsupported value for FT_DS");
4817 return STATUS_SENT_ERROR;
4818 }
4819 }
4820
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004821 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03004822 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
4823 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004824 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
4825 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004826
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004827 if (val && strcasecmp(val, "LOC") == 0)
4828 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02004829 if (val && strcasecmp(val, "60GHZ") == 0) {
4830 val = get_param(cmd, "WPS");
4831 if (val && strcasecmp(val, "disable") == 0) {
4832 dut->wps_disable = 1;
4833 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
4834 } else {
4835 /* wps_disable can have other value from the previous
4836 * test, so make sure it has the correct value.
4837 */
4838 dut->wps_disable = 0;
4839 }
4840
4841 val = get_param(cmd, "P2P");
4842 if (val && strcasecmp(val, "disable") == 0)
4843 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
4844 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004845
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004846 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
4847 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
4848
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004849#ifdef ANDROID_NAN
4850 if (val && strcasecmp(val, "NAN") == 0)
4851 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
4852#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004853#ifdef MIRACAST
4854 if (val && (strcasecmp(val, "WFD") == 0 ||
4855 strcasecmp(val, "DisplayR2") == 0))
4856 return miracast_preset_testparameters(dut, conn, cmd);
4857#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004858
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304859 if (val && strcasecmp(val, "MBO") == 0) {
4860 val = get_param(cmd, "Cellular_Data_Cap");
4861 if (val &&
4862 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
4863 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05304864
4865 val = get_param(cmd, "Ch_Pref");
4866 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
4867 return 0;
4868
Ashwini Patilc63161e2017-04-13 16:30:23 +05304869 val = get_param(cmd, "BSS_Transition");
4870 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
4871 return 0;
4872
Ashwini Patila75de5a2017-04-13 16:35:05 +05304873 val = get_param(cmd, "Assoc_Disallow");
4874 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
4875 return 0;
4876
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304877 val = get_param(cmd, "Roaming");
4878 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
4879 return 0;
4880
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304881 return 1;
4882 }
4883
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304884 if (val && strcasecmp(val, "OCE") == 0)
4885 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
4886
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004887#if 0
4888 val = get_param(cmd, "Supplicant");
4889 if (val && strcasecmp(val, "Default") != 0) {
4890 send_resp(dut, conn, SIGMA_ERROR,
4891 "ErrorCode,Only default(Vendor) supplicant "
4892 "supported");
4893 return 0;
4894 }
4895#endif
4896
4897 val = get_param(cmd, "RTS");
4898 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004899 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004900 case DRIVER_ATHEROS:
4901 ath_sta_set_rts(dut, intf, val);
4902 break;
4903 default:
4904#if 0
4905 send_resp(dut, conn, SIGMA_ERROR,
4906 "ErrorCode,Setting RTS not supported");
4907 return 0;
4908#else
4909 sigma_dut_print(dut, DUT_MSG_DEBUG,
4910 "Setting RTS not supported");
4911 break;
4912#endif
4913 }
4914 }
4915
4916#if 0
4917 val = get_param(cmd, "FRGMNT");
4918 if (val) {
4919 /* TODO */
4920 send_resp(dut, conn, SIGMA_ERROR,
4921 "ErrorCode,Setting FRGMNT not supported");
4922 return 0;
4923 }
4924#endif
4925
4926#if 0
4927 val = get_param(cmd, "Preamble");
4928 if (val) {
4929 /* TODO: Long/Short */
4930 send_resp(dut, conn, SIGMA_ERROR,
4931 "ErrorCode,Setting Preamble not supported");
4932 return 0;
4933 }
4934#endif
4935
4936 val = get_param(cmd, "Mode");
4937 if (val) {
4938 if (strcmp(val, "11b") == 0 ||
4939 strcmp(val, "11g") == 0 ||
4940 strcmp(val, "11a") == 0 ||
4941 strcmp(val, "11n") == 0 ||
4942 strcmp(val, "11ng") == 0 ||
4943 strcmp(val, "11nl") == 0 ||
4944 strcmp(val, "11nl(nabg)") == 0 ||
4945 strcmp(val, "AC") == 0 ||
4946 strcmp(val, "11AC") == 0 ||
4947 strcmp(val, "11ac") == 0 ||
4948 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08004949 strcmp(val, "11an") == 0 ||
4950 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004951 /* STA supports all modes by default */
4952 } else {
4953 send_resp(dut, conn, SIGMA_ERROR,
4954 "ErrorCode,Setting Mode not supported");
4955 return 0;
4956 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004957
4958 /* Change the mode only in case of testbed for HE program
4959 * and for 11a and 11g modes only. */
4960 if (dut->program == PROGRAM_HE &&
4961 dut->device_type == STA_testbed) {
4962 int phymode;
4963 char buf[60];
4964
4965 if (strcmp(val, "11a") == 0) {
Amarnath Hullur Subramanyam94dfaf02018-03-02 19:26:57 -08004966 phymode = 1; /* IEEE80211_MODE_11A */
4967 } else if (strcmp(val, "11g") == 0) {
4968 phymode = 3; /* IEEE80211_MODE_11G */
4969 } else if (strcmp(val, "11b") == 0) {
4970 phymode = 2; /* IEEE80211_MODE_11B */
4971 } else if (strcmp(val, "11n") == 0 ||
4972 strcmp(val, "11nl") == 0 ||
4973 strcmp(val, "11nl(nabg)") == 0) {
4974 phymode = 22; /* IEEE80211_MODE_11AGN */
4975 } else if (strcmp(val, "11ng") == 0) {
4976 phymode = 13; /* IEEE80211_MODE_11NG_HT40 */
4977 } else if (strcmp(val, "AC") == 0 ||
4978 strcasecmp(val, "11AC") == 0) {
4979 phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */
4980 } else if (strcmp(val, "11na") == 0 ||
4981 strcasecmp(val, "11an") == 0) {
4982 phymode = 14; /* IEEE80211_MODE_11NA_HT40 */
4983 } else if (strcmp(val, "11ax") == 0) {
4984 phymode = 0; /* IEEE80211_MODE_AUTO */
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004985 } else {
4986 sigma_dut_print(dut, DUT_MSG_DEBUG,
4987 "Ignoring mode change for mode: %s",
4988 val);
4989 phymode = -1;
4990 }
4991 if (phymode != -1) {
4992 snprintf(buf, sizeof(buf),
4993 "iwpriv %s setphymode %d",
4994 intf, phymode);
4995 if (system(buf) != 0) {
4996 sigma_dut_print(dut, DUT_MSG_ERROR,
4997 "iwpriv setting of phymode failed");
4998 }
4999 }
5000 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005001 }
5002
5003 val = get_param(cmd, "wmm");
5004 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005005 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005006 case DRIVER_ATHEROS:
5007 ath_sta_set_wmm(dut, intf, val);
5008 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005009 case DRIVER_WCN:
5010 wcn_sta_set_wmm(dut, intf, val);
5011 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005012 default:
5013 sigma_dut_print(dut, DUT_MSG_DEBUG,
5014 "Setting wmm not supported");
5015 break;
5016 }
5017 }
5018
5019 val = get_param(cmd, "Powersave");
5020 if (val) {
5021 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005022 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305023 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005024 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005025 }
5026
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005027 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005028 "P2P_SET ps 0") < 0)
5029 return -2;
5030 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005031 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5032 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005033 } else if (strcmp(val, "1") == 0 ||
5034 strcasecmp(val, "PSPoll") == 0 ||
5035 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005036 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305037 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005038 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005039 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005040 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005041 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005042 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005043 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005044 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005045 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005046 "P2P_SET ps 99") < 0)
5047 return -2;
5048 } else if (strcmp(val, "2") == 0 ||
5049 strcasecmp(val, "Fast") == 0) {
5050 /* TODO */
5051 send_resp(dut, conn, SIGMA_ERROR,
5052 "ErrorCode,Powersave=Fast not supported");
5053 return 0;
5054 } else if (strcmp(val, "3") == 0 ||
5055 strcasecmp(val, "PSNonPoll") == 0) {
5056 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005057 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5058 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005059
5060 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005061 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005062 "P2P_SET ps 1") < 0)
5063 return -2;
5064 } else
5065 return -1;
5066 }
5067
5068 val = get_param(cmd, "NoAck");
5069 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005070 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005071 case DRIVER_ATHEROS:
5072 ath_sta_set_noack(dut, intf, val);
5073 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005074#ifdef NL80211_SUPPORT
5075 case DRIVER_WCN:
5076 wcn_sta_set_noack(dut, intf, val);
5077 break;
5078#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005079 default:
5080 send_resp(dut, conn, SIGMA_ERROR,
5081 "ErrorCode,Setting NoAck not supported");
5082 return 0;
5083 }
5084 }
5085
5086 val = get_param(cmd, "IgnoreChswitchProhibit");
5087 if (val) {
5088 /* TODO: Enabled/disabled */
5089 if (strcasecmp(val, "Enabled") == 0) {
5090 send_resp(dut, conn, SIGMA_ERROR,
5091 "ErrorCode,Enabling IgnoreChswitchProhibit "
5092 "not supported");
5093 return 0;
5094 }
5095 }
5096
5097 val = get_param(cmd, "TDLS");
5098 if (val) {
5099 if (strcasecmp(val, "Disabled") == 0) {
5100 if (wpa_command(intf, "SET tdls_disabled 1")) {
5101 send_resp(dut, conn, SIGMA_ERROR,
5102 "ErrorCode,Failed to disable TDLS");
5103 return 0;
5104 }
5105 } else if (strcasecmp(val, "Enabled") == 0) {
5106 if (wpa_command(intf, "SET tdls_disabled 0")) {
5107 send_resp(dut, conn, SIGMA_ERROR,
5108 "ErrorCode,Failed to enable TDLS");
5109 return 0;
5110 }
5111 } else {
5112 send_resp(dut, conn, SIGMA_ERROR,
5113 "ErrorCode,Unsupported TDLS value");
5114 return 0;
5115 }
5116 }
5117
5118 val = get_param(cmd, "TDLSmode");
5119 if (val) {
5120 if (strcasecmp(val, "Default") == 0) {
5121 wpa_command(intf, "SET tdls_testing 0");
5122 } else if (strcasecmp(val, "APProhibit") == 0) {
5123 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5124 send_resp(dut, conn, SIGMA_ERROR,
5125 "ErrorCode,Failed to enable ignore "
5126 "APProhibit TDLS mode");
5127 return 0;
5128 }
5129 } else if (strcasecmp(val, "HiLoMac") == 0) {
5130 /* STA should respond with TDLS setup req for a TDLS
5131 * setup req */
5132 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5133 send_resp(dut, conn, SIGMA_ERROR,
5134 "ErrorCode,Failed to enable HiLoMac "
5135 "TDLS mode");
5136 return 0;
5137 }
5138 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5139 /*
5140 * Since all security modes are enabled by default when
5141 * Sigma control is used, there is no need to do
5142 * anything here.
5143 */
5144 } else if (strcasecmp(val, "ExistLink") == 0) {
5145 /*
5146 * Since we allow new TDLS Setup Request even if there
5147 * is an existing link, nothing needs to be done for
5148 * this.
5149 */
5150 } else {
5151 /* TODO:
5152 * ExistLink: STA should send TDLS setup req even if
5153 * direct link already exists
5154 */
5155 send_resp(dut, conn, SIGMA_ERROR,
5156 "ErrorCode,Unsupported TDLSmode value");
5157 return 0;
5158 }
5159 }
5160
5161 val = get_param(cmd, "FakePubKey");
5162 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5163 send_resp(dut, conn, SIGMA_ERROR,
5164 "ErrorCode,Failed to enable FakePubKey");
5165 return 0;
5166 }
5167
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005168#ifdef NL80211_SUPPORT
5169 val = get_param(cmd, "FrgmntSupport");
5170 if (val) {
5171 if (strcasecmp(val, "Enable") == 0) {
5172 if (sta_set_he_fragmentation(dut, intf,
5173 HE_FRAG_LEVEL1)) {
5174 send_resp(dut, conn, SIGMA_ERROR,
5175 "ErrorCode,Failed to enable HE Fragmentation");
5176 return 0;
5177 }
5178 } else if (strcasecmp(val, "Disable") == 0) {
5179 if (sta_set_he_fragmentation(dut, intf,
5180 HE_FRAG_DISABLE)) {
5181 send_resp(dut, conn, SIGMA_ERROR,
5182 "ErrorCode,Failed to disable HE Fragmentation");
5183 return 0;
5184 }
5185 }
5186 }
5187#endif /* NL80211_SUPPORT */
5188
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005189 return 1;
5190}
5191
5192
5193static const char * ath_get_radio_name(const char *radio_name)
5194{
5195 if (radio_name == NULL)
5196 return "wifi0";
5197 if (strcmp(radio_name, "wifi1") == 0)
5198 return "wifi1";
5199 if (strcmp(radio_name, "wifi2") == 0)
5200 return "wifi2";
5201 return "wifi0";
5202}
5203
5204
5205static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5206 const char *val)
5207{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005208 unsigned int vht_mcsmap = 0;
5209 int txchainmask = 0;
5210 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5211
5212 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5213 if (dut->testbed_flag_txsp == 1) {
5214 vht_mcsmap = 0xfffc;
5215 dut->testbed_flag_txsp = 0;
5216 } else {
5217 vht_mcsmap = 0xfffe;
5218 }
5219 txchainmask = 1;
5220 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5221 if (dut->testbed_flag_txsp == 1) {
5222 vht_mcsmap = 0xfff0;
5223 dut->testbed_flag_txsp = 0;
5224 } else {
5225 vht_mcsmap = 0xfffa;
5226 }
5227 txchainmask = 3;
5228 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5229 if (dut->testbed_flag_txsp == 1) {
5230 vht_mcsmap = 0xffc0;
5231 dut->testbed_flag_txsp = 0;
5232 } else {
5233 vht_mcsmap = 0xffea;
5234 }
5235 txchainmask = 7;
5236 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5237 if (dut->testbed_flag_txsp == 1) {
5238 vht_mcsmap = 0xff00;
5239 dut->testbed_flag_txsp = 0;
5240 } else {
5241 vht_mcsmap = 0xffaa;
5242 }
5243 txchainmask = 15;
5244 } else {
5245 if (dut->testbed_flag_txsp == 1) {
5246 vht_mcsmap = 0xffc0;
5247 dut->testbed_flag_txsp = 0;
5248 } else {
5249 vht_mcsmap = 0xffea;
5250 }
5251 }
5252
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005253 if (txchainmask)
5254 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005255
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005256 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005257}
5258
5259
5260static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5261 const char *val)
5262{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005263 unsigned int vht_mcsmap = 0;
5264 int rxchainmask = 0;
5265 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5266
5267 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5268 if (dut->testbed_flag_rxsp == 1) {
5269 vht_mcsmap = 0xfffc;
5270 dut->testbed_flag_rxsp = 0;
5271 } else {
5272 vht_mcsmap = 0xfffe;
5273 }
5274 rxchainmask = 1;
5275 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5276 if (dut->testbed_flag_rxsp == 1) {
5277 vht_mcsmap = 0xfff0;
5278 dut->testbed_flag_rxsp = 0;
5279 } else {
5280 vht_mcsmap = 0xfffa;
5281 }
5282 rxchainmask = 3;
5283 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5284 if (dut->testbed_flag_rxsp == 1) {
5285 vht_mcsmap = 0xffc0;
5286 dut->testbed_flag_rxsp = 0;
5287 } else {
5288 vht_mcsmap = 0xffea;
5289 }
5290 rxchainmask = 7;
5291 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5292 if (dut->testbed_flag_rxsp == 1) {
5293 vht_mcsmap = 0xff00;
5294 dut->testbed_flag_rxsp = 0;
5295 } else {
5296 vht_mcsmap = 0xffaa;
5297 }
5298 rxchainmask = 15;
5299 } else {
5300 if (dut->testbed_flag_rxsp == 1) {
5301 vht_mcsmap = 0xffc0;
5302 dut->testbed_flag_rxsp = 0;
5303 } else {
5304 vht_mcsmap = 0xffea;
5305 }
5306 }
5307
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005308 if (rxchainmask)
5309 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005310
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005311 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005312}
5313
5314
5315void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5316{
5317 if (strcasecmp(val, "enable") == 0) {
5318 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5319 != 0) {
5320 sigma_dut_print(dut, DUT_MSG_ERROR,
5321 "Disable BB_VHTSIGB_CRC_CALC failed");
5322 }
5323
5324 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5325 != 0) {
5326 sigma_dut_print(dut, DUT_MSG_ERROR,
5327 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5328 }
5329 } else {
5330 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5331 != 0) {
5332 sigma_dut_print(dut, DUT_MSG_ERROR,
5333 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5334 }
5335
5336 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5337 != 0) {
5338 sigma_dut_print(dut, DUT_MSG_ERROR,
5339 "Enable BB_VHTSIGB_CRC_CALC failed");
5340 }
5341 }
5342}
5343
5344
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005345static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5346 const char *val)
5347{
5348 char buf[60];
5349
5350 if (strcmp(val, "20") == 0) {
5351 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5352 dut->chwidth = 0;
5353 } else if (strcmp(val, "40") == 0) {
5354 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5355 dut->chwidth = 1;
5356 } else if (strcmp(val, "80") == 0) {
5357 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5358 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305359 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005360 buf[0] = '\0';
5361 } else {
5362 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5363 val);
5364 return -1;
5365 }
5366
5367 if (buf[0] != '\0' && system(buf) != 0) {
5368 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5369 return -1;
5370 }
5371
5372 return 0;
5373}
5374
5375
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005376static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5377 const char *intf, int addbareject)
5378{
5379#ifdef NL80211_SUPPORT
5380 struct nl_msg *msg;
5381 int ret = 0;
5382 struct nlattr *params;
5383 int ifindex;
5384
5385 ifindex = if_nametoindex(intf);
5386 if (ifindex == 0) {
5387 sigma_dut_print(dut, DUT_MSG_ERROR,
5388 "%s: Index for interface %s failed",
5389 __func__, intf);
5390 return -1;
5391 }
5392
5393 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5394 NL80211_CMD_VENDOR)) ||
5395 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5396 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5397 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5398 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5399 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5400 nla_put_u8(msg,
5401 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5402 !addbareject)) {
5403 sigma_dut_print(dut, DUT_MSG_ERROR,
5404 "%s: err in adding vendor_cmd and vendor_data",
5405 __func__);
5406 nlmsg_free(msg);
5407 return -1;
5408 }
5409 nla_nest_end(msg, params);
5410
5411 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5412 if (ret) {
5413 sigma_dut_print(dut, DUT_MSG_ERROR,
5414 "%s: err in send_and_recv_msgs, ret=%d",
5415 __func__, ret);
5416 }
5417 return ret;
5418#else /* NL80211_SUPPORT */
5419 sigma_dut_print(dut, DUT_MSG_ERROR,
5420 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5421 return -1;
5422#endif /* NL80211_SUPPORT */
5423}
5424
5425
5426static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5427 int addbareject)
5428{
5429 int ret;
5430
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005431 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005432 case DRIVER_WCN:
5433 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5434 if (ret) {
5435 sigma_dut_print(dut, DUT_MSG_ERROR,
5436 "nlvendor_sta_set_addba_reject failed, ret:%d",
5437 ret);
5438 return ret;
5439 }
5440 break;
5441 default:
5442 sigma_dut_print(dut, DUT_MSG_ERROR,
5443 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5444 ret = -1;
5445 break;
5446 }
5447
5448 return ret;
5449}
5450
5451
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005452static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5453 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005454{
5455#ifdef NL80211_SUPPORT
5456 struct nl_msg *msg;
5457 int ret = 0;
5458 struct nlattr *params;
5459 int ifindex;
5460
5461 ifindex = if_nametoindex(intf);
5462 if (ifindex == 0) {
5463 sigma_dut_print(dut, DUT_MSG_ERROR,
5464 "%s: Index for interface %s failed",
5465 __func__, intf);
5466 return -1;
5467 }
5468
5469 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5470 NL80211_CMD_VENDOR)) ||
5471 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5472 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5473 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5474 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5475 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5476 nla_put_u8(msg,
5477 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005478 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005479 sigma_dut_print(dut, DUT_MSG_ERROR,
5480 "%s: err in adding vendor_cmd and vendor_data",
5481 __func__);
5482 nlmsg_free(msg);
5483 return -1;
5484 }
5485 nla_nest_end(msg, params);
5486
5487 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5488 if (ret) {
5489 sigma_dut_print(dut, DUT_MSG_ERROR,
5490 "%s: err in send_and_recv_msgs, ret=%d",
5491 __func__, ret);
5492 }
5493 return ret;
5494#else /* NL80211_SUPPORT */
5495 sigma_dut_print(dut, DUT_MSG_ERROR,
5496 "Disable addba not possible without NL80211_SUPPORT defined");
5497 return -1;
5498#endif /* NL80211_SUPPORT */
5499}
5500
5501
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305502#ifdef NL80211_SUPPORT
5503static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5504{
5505 struct nl_msg *msg;
5506 int ret = 0;
5507 int ifindex;
5508
5509 ifindex = if_nametoindex(intf);
5510 if (ifindex == 0) {
5511 sigma_dut_print(dut, DUT_MSG_ERROR,
5512 "%s: Index for interface %s failed",
5513 __func__, intf);
5514 return -1;
5515 }
5516
5517 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5518 NL80211_CMD_SET_WIPHY)) ||
5519 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5520 sigma_dut_print(dut, DUT_MSG_ERROR,
5521 "%s: err in adding RTS threshold",
5522 __func__);
5523 nlmsg_free(msg);
5524 return -1;
5525 }
5526
5527 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5528 if (ret) {
5529 sigma_dut_print(dut, DUT_MSG_ERROR,
5530 "%s: err in send_and_recv_msgs, ret=%d",
5531 __func__, ret);
5532 }
5533 return ret;
5534}
5535#endif /* NL80211_SUPPORT */
5536
5537
5538static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5539{
5540 char buf[100];
5541
5542#ifdef NL80211_SUPPORT
5543 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5544 return 0;
5545 sigma_dut_print(dut, DUT_MSG_DEBUG,
5546 "Fall back to using iwconfig for setting RTS threshold");
5547#endif /* NL80211_SUPPORT */
5548
5549 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5550 if (system(buf) != 0) {
5551 sigma_dut_print(dut, DUT_MSG_ERROR,
5552 "Failed to set RTS threshold %d", val);
5553 return -1;
5554 }
5555 return 0;
5556}
5557
5558
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005559static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5560 struct sigma_conn *conn,
5561 struct sigma_cmd *cmd)
5562{
5563 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005564 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005565 char buf[128];
5566 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005567
5568 val = get_param(cmd, "40_INTOLERANT");
5569 if (val) {
5570 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5571 /* TODO: iwpriv ht40intol through wpa_supplicant */
5572 send_resp(dut, conn, SIGMA_ERROR,
5573 "ErrorCode,40_INTOLERANT not supported");
5574 return 0;
5575 }
5576 }
5577
5578 val = get_param(cmd, "ADDBA_REJECT");
5579 if (val) {
5580 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5581 /* reject any ADDBA with status "decline" */
5582 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005583 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005584 } else {
5585 /* accept ADDBA */
5586 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005587 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005588 }
5589 }
5590
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005591 if (addbareject >= 0 &&
5592 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5593 send_resp(dut, conn, SIGMA_ERROR,
5594 "ErrorCode,set addba_reject failed");
5595 return 0;
5596 }
5597
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005598 val = get_param(cmd, "AMPDU");
5599 if (val) {
5600 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5601 /* enable AMPDU Aggregation */
5602 if (ampdu == 0) {
5603 send_resp(dut, conn, SIGMA_ERROR,
5604 "ErrorCode,Mismatch in "
5605 "addba_reject/ampdu - "
5606 "not supported");
5607 return 0;
5608 }
5609 ampdu = 1;
5610 } else {
5611 /* disable AMPDU Aggregation */
5612 if (ampdu == 1) {
5613 send_resp(dut, conn, SIGMA_ERROR,
5614 "ErrorCode,Mismatch in "
5615 "addba_reject/ampdu - "
5616 "not supported");
5617 return 0;
5618 }
5619 ampdu = 0;
5620 }
5621 }
5622
5623 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005624 int ret;
5625
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005626 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5627 ampdu ? "Enabling" : "Disabling");
5628 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005629 if (wpa_command(intf, buf) < 0 &&
5630 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005631 send_resp(dut, conn, SIGMA_ERROR,
5632 "ErrorCode,set aggr failed");
5633 return 0;
5634 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005635
5636 if (ampdu == 0) {
5637 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005638 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005639 if (ret) {
5640 sigma_dut_print(dut, DUT_MSG_ERROR,
5641 "Failed to disable addba, ret:%d",
5642 ret);
5643 }
5644 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005645 }
5646
5647 val = get_param(cmd, "AMSDU");
5648 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005649 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005650 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005651 case DRIVER_WCN:
5652 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005653 break;
5654 default:
5655 if (strcmp(val, "1") == 0 ||
5656 strcasecmp(val, "Enable") == 0) {
5657 /* Enable AMSDU Aggregation */
5658 send_resp(dut, conn, SIGMA_ERROR,
5659 "ErrorCode,AMSDU aggregation not supported");
5660 return 0;
5661 }
5662 break;
5663 }
5664 }
5665
5666 val = get_param(cmd, "STBC_RX");
5667 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005668 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005669 case DRIVER_ATHEROS:
5670 ath_sta_set_stbc(dut, intf, val);
5671 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305672 case DRIVER_WCN:
5673 wcn_sta_set_stbc(dut, intf, val);
5674 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005675 default:
5676 send_resp(dut, conn, SIGMA_ERROR,
5677 "ErrorCode,STBC_RX not supported");
5678 return 0;
5679 }
5680 }
5681
5682 val = get_param(cmd, "WIDTH");
5683 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005684 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005685 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005686 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005687 send_resp(dut, conn, SIGMA_ERROR,
5688 "ErrorCode,Failed to set WIDTH");
5689 return 0;
5690 }
5691 break;
5692 case DRIVER_ATHEROS:
5693 if (ath_set_width(dut, conn, intf, val) < 0)
5694 return 0;
5695 break;
5696 default:
5697 sigma_dut_print(dut, DUT_MSG_ERROR,
5698 "Setting WIDTH not supported");
5699 break;
5700 }
5701 }
5702
5703 val = get_param(cmd, "SMPS");
5704 if (val) {
5705 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5706 send_resp(dut, conn, SIGMA_ERROR,
5707 "ErrorCode,SMPS not supported");
5708 return 0;
5709 }
5710
5711 val = get_param(cmd, "TXSP_STREAM");
5712 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005713 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005714 case DRIVER_WCN:
5715 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5716 send_resp(dut, conn, SIGMA_ERROR,
5717 "ErrorCode,Failed to set TXSP_STREAM");
5718 return 0;
5719 }
5720 break;
5721 case DRIVER_ATHEROS:
5722 ath_sta_set_txsp_stream(dut, intf, val);
5723 break;
5724 default:
5725 sigma_dut_print(dut, DUT_MSG_ERROR,
5726 "Setting TXSP_STREAM not supported");
5727 break;
5728 }
5729 }
5730
5731 val = get_param(cmd, "RXSP_STREAM");
5732 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005733 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005734 case DRIVER_WCN:
5735 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5736 send_resp(dut, conn, SIGMA_ERROR,
5737 "ErrorCode,Failed to set RXSP_STREAM");
5738 return 0;
5739 }
5740 break;
5741 case DRIVER_ATHEROS:
5742 ath_sta_set_rxsp_stream(dut, intf, val);
5743 break;
5744 default:
5745 sigma_dut_print(dut, DUT_MSG_ERROR,
5746 "Setting RXSP_STREAM not supported");
5747 break;
5748 }
5749 }
5750
5751 val = get_param(cmd, "DYN_BW_SGNL");
5752 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005753 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005754 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08005755 if (strcasecmp(val, "enable") == 0) {
5756 snprintf(buf, sizeof(buf),
5757 "iwpriv %s cwmenable 1", intf);
5758 if (system(buf) != 0) {
5759 sigma_dut_print(dut, DUT_MSG_ERROR,
5760 "iwpriv cwmenable 1 failed");
5761 return 0;
5762 }
5763 } else if (strcasecmp(val, "disable") == 0) {
5764 snprintf(buf, sizeof(buf),
5765 "iwpriv %s cwmenable 0", intf);
5766 if (system(buf) != 0) {
5767 sigma_dut_print(dut, DUT_MSG_ERROR,
5768 "iwpriv cwmenable 0 failed");
5769 return 0;
5770 }
5771 } else {
5772 sigma_dut_print(dut, DUT_MSG_ERROR,
5773 "Unsupported DYN_BW_SGL");
5774 }
5775
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005776 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5777 if (system(buf) != 0) {
5778 sigma_dut_print(dut, DUT_MSG_ERROR,
5779 "Failed to set cts_cbw in DYN_BW_SGNL");
5780 return 0;
5781 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005782 break;
5783 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005784 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005785 ath_config_dyn_bw_sig(dut, intf, val);
5786 break;
5787 default:
5788 sigma_dut_print(dut, DUT_MSG_ERROR,
5789 "Failed to set DYN_BW_SGNL");
5790 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005791 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005792 }
5793
5794 val = get_param(cmd, "RTS_FORCE");
5795 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005796 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005797 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305798 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005799 sigma_dut_print(dut, DUT_MSG_ERROR,
5800 "Failed to set RTS_FORCE 64");
5801 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03005802 res = snprintf(buf, sizeof(buf),
5803 "wifitool %s beeliner_fw_test 100 1",
5804 intf);
5805 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08005806 sigma_dut_print(dut, DUT_MSG_ERROR,
5807 "wifitool beeliner_fw_test 100 1 failed");
5808 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005809 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305810 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005811 sigma_dut_print(dut, DUT_MSG_ERROR,
5812 "Failed to set RTS_FORCE 2347");
5813 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005814 } else {
5815 send_resp(dut, conn, SIGMA_ERROR,
5816 "ErrorCode,RTS_FORCE value not supported");
5817 return 0;
5818 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005819 }
5820
5821 val = get_param(cmd, "CTS_WIDTH");
5822 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005823 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005824 case DRIVER_WCN:
5825 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
5826 send_resp(dut, conn, SIGMA_ERROR,
5827 "ErrorCode,Failed to set CTS_WIDTH");
5828 return 0;
5829 }
5830 break;
5831 case DRIVER_ATHEROS:
5832 ath_set_cts_width(dut, intf, val);
5833 break;
5834 default:
5835 sigma_dut_print(dut, DUT_MSG_ERROR,
5836 "Setting CTS_WIDTH not supported");
5837 break;
5838 }
5839 }
5840
5841 val = get_param(cmd, "BW_SGNL");
5842 if (val) {
5843 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005844 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005845 } else if (strcasecmp(val, "Disable") == 0) {
5846 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005847 } else {
5848 send_resp(dut, conn, SIGMA_ERROR,
5849 "ErrorCode,BW_SGNL value not supported");
5850 return 0;
5851 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005852 }
5853
5854 val = get_param(cmd, "Band");
5855 if (val) {
5856 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
5857 /* STA supports all bands by default */
5858 } else {
5859 send_resp(dut, conn, SIGMA_ERROR,
5860 "ErrorCode,Unsupported Band");
5861 return 0;
5862 }
5863 }
5864
5865 val = get_param(cmd, "zero_crc");
5866 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005867 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005868 case DRIVER_ATHEROS:
5869 ath_set_zero_crc(dut, val);
5870 break;
5871 default:
5872 break;
5873 }
5874 }
5875
5876 return 1;
5877}
5878
5879
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005880static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
5881{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005882 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005883#ifdef __linux__
5884 case DRIVER_WIL6210:
5885 return wil6210_set_force_mcs(dut, force, mcs);
5886#endif /* __linux__ */
5887 default:
5888 sigma_dut_print(dut, DUT_MSG_ERROR,
5889 "Unsupported sta_set_force_mcs with the current driver");
5890 return -1;
5891 }
5892}
5893
5894
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005895static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
5896{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005897 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005898#ifdef __linux__
5899 case DRIVER_WIL6210:
5900 return wil6210_force_rsn_ie(dut, state);
5901#endif /* __linux__ */
5902 default:
5903 sigma_dut_print(dut, DUT_MSG_ERROR,
5904 "Unsupported sta_60g_force_rsn_ie with the current driver");
5905 return -1;
5906 }
5907}
5908
5909
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005910static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
5911 struct sigma_cmd *cmd)
5912{
5913 const char *val;
5914 char buf[100];
5915
5916 val = get_param(cmd, "MSDUSize");
5917 if (val) {
5918 int mtu;
5919
5920 dut->amsdu_size = atoi(val);
5921 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
5922 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
5923 sigma_dut_print(dut, DUT_MSG_ERROR,
5924 "MSDUSize %d is above max %d or below min %d",
5925 dut->amsdu_size,
5926 IEEE80211_MAX_DATA_LEN_DMG,
5927 IEEE80211_SNAP_LEN_DMG);
5928 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005929 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005930 }
5931
5932 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
5933 sigma_dut_print(dut, DUT_MSG_DEBUG,
5934 "Setting amsdu_size to %d", mtu);
5935 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005936 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005937
5938 if (system(buf) != 0) {
5939 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
5940 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005941 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005942 }
5943 }
5944
5945 val = get_param(cmd, "BAckRcvBuf");
5946 if (val) {
5947 dut->back_rcv_buf = atoi(val);
5948 if (dut->back_rcv_buf == 0) {
5949 sigma_dut_print(dut, DUT_MSG_ERROR,
5950 "Failed to convert %s or value is 0",
5951 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005952 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005953 }
5954
5955 sigma_dut_print(dut, DUT_MSG_DEBUG,
5956 "Setting BAckRcvBuf to %s", val);
5957 }
5958
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005959 val = get_param(cmd, "MCS_FixedRate");
5960 if (val) {
5961 if (sta_set_force_mcs(dut, 1, atoi(val))) {
5962 sigma_dut_print(dut, DUT_MSG_ERROR,
5963 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005964 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005965 }
5966 }
5967
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005968 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005969}
5970
5971
5972static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
5973 struct sigma_cmd *cmd)
5974{
5975 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005976 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005977 const char *val;
5978 char buf[100];
5979
5980 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005981 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005982 if (wpa_command(ifname, "PING") != 0) {
5983 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005984 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005985 }
5986
5987 wpa_command(ifname, "FLUSH");
5988 net_id = add_network_common(dut, conn, ifname, cmd);
5989 if (net_id < 0) {
5990 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
5991 return net_id;
5992 }
5993
5994 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
5995 if (set_network(ifname, net_id, "mode", "2") < 0) {
5996 sigma_dut_print(dut, DUT_MSG_ERROR,
5997 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005998 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005999 }
6000
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006001 if (set_network(ifname, net_id, "pbss", "1") < 0)
6002 return -2;
6003
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006004 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006005 "Supplicant set network with mode 2. network_id %d",
6006 net_id);
6007
6008 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6009 sigma_dut_print(dut, DUT_MSG_INFO,
6010 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006011 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006012 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006013
6014 val = get_param(cmd, "Security");
6015 if (val && strcasecmp(val, "OPEN") == 0) {
6016 dut->ap_key_mgmt = AP_OPEN;
6017 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6018 sigma_dut_print(dut, DUT_MSG_ERROR,
6019 "Failed to set supplicant to %s security",
6020 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006021 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006022 }
6023 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6024 dut->ap_key_mgmt = AP_WPA2_PSK;
6025 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6026 sigma_dut_print(dut, DUT_MSG_ERROR,
6027 "Failed to set supplicant to %s security",
6028 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006029 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006030 }
6031
6032 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6033 sigma_dut_print(dut, DUT_MSG_ERROR,
6034 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006035 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006036 }
6037 } else if (val) {
6038 sigma_dut_print(dut, DUT_MSG_ERROR,
6039 "Requested Security %s is not supported on 60GHz",
6040 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006041 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006042 }
6043
6044 val = get_param(cmd, "Encrypt");
6045 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6046 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6047 sigma_dut_print(dut, DUT_MSG_ERROR,
6048 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006049 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006050 }
6051 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6052 sigma_dut_print(dut, DUT_MSG_ERROR,
6053 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006054 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006055 }
6056 } else if (val) {
6057 sigma_dut_print(dut, DUT_MSG_ERROR,
6058 "Requested Encrypt %s is not supported on 60 GHz",
6059 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006060 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006061 }
6062
6063 val = get_param(cmd, "PSK");
6064 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6065 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6066 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006067 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006068 }
6069
6070 /* Convert 60G channel to freq */
6071 switch (dut->ap_channel) {
6072 case 1:
6073 val = "58320";
6074 break;
6075 case 2:
6076 val = "60480";
6077 break;
6078 case 3:
6079 val = "62640";
6080 break;
6081 default:
6082 sigma_dut_print(dut, DUT_MSG_ERROR,
6083 "Failed to configure channel %d. Not supported",
6084 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006085 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006086 }
6087
6088 if (set_network(ifname, net_id, "frequency", val) < 0) {
6089 sigma_dut_print(dut, DUT_MSG_ERROR,
6090 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006091 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006092 }
6093
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006094 if (dut->eap_fragment) {
6095 sigma_dut_print(dut, DUT_MSG_DEBUG,
6096 "Set EAP fragment size to 128 bytes.");
6097 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6098 return ERROR_SEND_STATUS;
6099 }
6100
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006101 sigma_dut_print(dut, DUT_MSG_DEBUG,
6102 "Supplicant set network with frequency");
6103
6104 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6105 if (wpa_command(ifname, buf) < 0) {
6106 sigma_dut_print(dut, DUT_MSG_INFO,
6107 "Failed to select network id %d on %s",
6108 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006109 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006110 }
6111
6112 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6113
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006114 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006115}
6116
6117
Lior David67543f52017-01-03 19:04:22 +02006118static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6119{
6120 char buf[128], fname[128];
6121 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006122 int res;
Lior David67543f52017-01-03 19:04:22 +02006123
6124 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6125 sigma_dut_print(dut, DUT_MSG_ERROR,
6126 "failed to get wil6210 debugfs dir");
6127 return -1;
6128 }
6129
Jouni Malinen3aa72862019-05-29 23:14:51 +03006130 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6131 if (res < 0 || res >= sizeof(fname))
6132 return -1;
Lior David67543f52017-01-03 19:04:22 +02006133 f = fopen(fname, "w");
6134 if (!f) {
6135 sigma_dut_print(dut, DUT_MSG_ERROR,
6136 "failed to open: %s", fname);
6137 return -1;
6138 }
6139
6140 fprintf(f, "%d\n", abft_len);
6141 fclose(f);
6142
6143 return 0;
6144}
6145
6146
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006147int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6148 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006149{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006150 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006151 case DRIVER_WIL6210:
6152 return wil6210_set_abft_len(dut, abft_len);
6153 default:
6154 sigma_dut_print(dut, DUT_MSG_ERROR,
6155 "set abft_len not supported");
6156 return -1;
6157 }
6158}
6159
6160
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006161static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6162 struct sigma_cmd *cmd)
6163{
6164 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006165 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006166
6167 if (dut->dev_role != DEVROLE_PCP) {
6168 send_resp(dut, conn, SIGMA_INVALID,
6169 "ErrorCode,Invalid DevRole");
6170 return 0;
6171 }
6172
6173 val = get_param(cmd, "SSID");
6174 if (val) {
6175 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6176 send_resp(dut, conn, SIGMA_INVALID,
6177 "ErrorCode,Invalid SSID");
6178 return -1;
6179 }
6180
Peng Xub8fc5cc2017-05-10 17:27:28 -07006181 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006182 }
6183
6184 val = get_param(cmd, "CHANNEL");
6185 if (val) {
6186 const char *pos;
6187
6188 dut->ap_channel = atoi(val);
6189 pos = strchr(val, ';');
6190 if (pos) {
6191 pos++;
6192 dut->ap_channel_1 = atoi(pos);
6193 }
6194 }
6195
6196 switch (dut->ap_channel) {
6197 case 1:
6198 case 2:
6199 case 3:
6200 break;
6201 default:
6202 sigma_dut_print(dut, DUT_MSG_ERROR,
6203 "Channel %d is not supported", dut->ap_channel);
6204 send_resp(dut, conn, SIGMA_ERROR,
6205 "Requested channel is not supported");
6206 return -1;
6207 }
6208
6209 val = get_param(cmd, "BCNINT");
6210 if (val)
6211 dut->ap_bcnint = atoi(val);
6212
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006213 val = get_param(cmd, "AllocType");
6214 if (val) {
6215 send_resp(dut, conn, SIGMA_ERROR,
6216 "ErrorCode,AllocType is not supported yet");
6217 return -1;
6218 }
6219
6220 val = get_param(cmd, "PercentBI");
6221 if (val) {
6222 send_resp(dut, conn, SIGMA_ERROR,
6223 "ErrorCode,PercentBI is not supported yet");
6224 return -1;
6225 }
6226
6227 val = get_param(cmd, "CBAPOnly");
6228 if (val) {
6229 send_resp(dut, conn, SIGMA_ERROR,
6230 "ErrorCode,CBAPOnly is not supported yet");
6231 return -1;
6232 }
6233
6234 val = get_param(cmd, "AMPDU");
6235 if (val) {
6236 if (strcasecmp(val, "Enable") == 0)
6237 dut->ap_ampdu = 1;
6238 else if (strcasecmp(val, "Disable") == 0)
6239 dut->ap_ampdu = 2;
6240 else {
6241 send_resp(dut, conn, SIGMA_ERROR,
6242 "ErrorCode,AMPDU value is not Enable nor Disabled");
6243 return -1;
6244 }
6245 }
6246
6247 val = get_param(cmd, "AMSDU");
6248 if (val) {
6249 if (strcasecmp(val, "Enable") == 0)
6250 dut->ap_amsdu = 1;
6251 else if (strcasecmp(val, "Disable") == 0)
6252 dut->ap_amsdu = 2;
6253 }
6254
6255 val = get_param(cmd, "NumMSDU");
6256 if (val) {
6257 send_resp(dut, conn, SIGMA_ERROR,
6258 "ErrorCode, NumMSDU is not supported yet");
6259 return -1;
6260 }
6261
6262 val = get_param(cmd, "ABFTLRang");
6263 if (val) {
6264 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006265 "ABFTLRang parameter %s", val);
6266 if (strcmp(val, "Gt1") == 0)
6267 abft_len = 2; /* 2 slots in this case */
6268 }
6269
6270 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6271 send_resp(dut, conn, SIGMA_ERROR,
6272 "ErrorCode, Can't set ABFT length");
6273 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006274 }
6275
6276 if (sta_pcp_start(dut, conn, cmd) < 0) {
6277 send_resp(dut, conn, SIGMA_ERROR,
6278 "ErrorCode, Can't start PCP role");
6279 return -1;
6280 }
6281
6282 return sta_set_60g_common(dut, conn, cmd);
6283}
6284
6285
6286static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6287 struct sigma_cmd *cmd)
6288{
6289 const char *val = get_param(cmd, "DiscoveryMode");
6290
6291 if (dut->dev_role != DEVROLE_STA) {
6292 send_resp(dut, conn, SIGMA_INVALID,
6293 "ErrorCode,Invalid DevRole");
6294 return 0;
6295 }
6296
6297 if (val) {
6298 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6299 /* Ignore Discovery mode till Driver expose API. */
6300#if 0
6301 if (strcasecmp(val, "1") == 0) {
6302 send_resp(dut, conn, SIGMA_INVALID,
6303 "ErrorCode,DiscoveryMode 1 not supported");
6304 return 0;
6305 }
6306
6307 if (strcasecmp(val, "0") == 0) {
6308 /* OK */
6309 } else {
6310 send_resp(dut, conn, SIGMA_INVALID,
6311 "ErrorCode,DiscoveryMode not supported");
6312 return 0;
6313 }
6314#endif
6315 }
6316
6317 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006318 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006319 return sta_set_60g_common(dut, conn, cmd);
6320}
6321
6322
Jouni Malinenf7222712019-06-13 01:50:21 +03006323static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6324 struct sigma_conn *conn,
6325 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006326{
6327 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006328 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306329
Jouni Malinened77e672018-01-10 16:45:13 +02006330 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006331 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006332 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306333 wpa_command(intf, "DISCONNECT");
6334 return 1;
6335 }
6336
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006337 disconnect_station(dut);
6338 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6339 * due to cached results. */
6340 wpa_command(intf, "SET ignore_old_scan_res 1");
6341 wpa_command(intf, "BSS_FLUSH");
6342 return 1;
6343}
6344
6345
Jouni Malinenf7222712019-06-13 01:50:21 +03006346static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6347 struct sigma_conn *conn,
6348 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006349{
6350 const char *intf = get_param(cmd, "Interface");
6351 const char *bssid = get_param(cmd, "bssid");
6352 const char *val = get_param(cmd, "CHANNEL");
6353 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306354 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306355 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006356 int res;
6357 int chan = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006358 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306359 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006360 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006361
6362 if (bssid == NULL) {
6363 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6364 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006365 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006366 }
6367
6368 if (val)
6369 chan = atoi(val);
6370
6371 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6372 /* The current network may be from sta_associate or
6373 * sta_hs2_associate
6374 */
6375 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6376 0 ||
6377 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006378 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006379 }
6380
6381 ctrl = open_wpa_mon(intf);
6382 if (ctrl == NULL) {
6383 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6384 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006385 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006386 }
6387
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006388 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05306389 sizeof(result)) < 0 ||
6390 strncmp(result, "COMPLETED", 9) != 0) {
6391 sigma_dut_print(dut, DUT_MSG_DEBUG,
6392 "sta_reassoc: Not connected");
6393 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006394 } else if (dut->sta_ft_ds) {
6395 sigma_dut_print(dut, DUT_MSG_DEBUG,
6396 "sta_reassoc: Use FT-over-DS");
6397 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306398 }
6399
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306400 if (dut->rsne_override) {
6401#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006402 if (get_driver_type(dut) == DRIVER_WCN &&
6403 dut->config_rsnie == 0) {
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306404 sta_config_rsnie(dut, 1);
6405 dut->config_rsnie = 1;
6406 }
6407#endif /* NL80211_SUPPORT */
6408 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6409 dut->rsne_override);
6410 if (wpa_command(intf, buf) < 0) {
6411 send_resp(dut, conn, SIGMA_ERROR,
6412 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6413 return 0;
6414 }
6415 }
6416
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006417 if (ft_ds) {
6418 if (chan) {
6419 unsigned int freq;
6420
6421 freq = channel_to_freq(dut, chan);
6422 if (!freq) {
6423 sigma_dut_print(dut, DUT_MSG_ERROR,
6424 "Invalid channel number provided: %d",
6425 chan);
6426 send_resp(dut, conn, SIGMA_INVALID,
6427 "ErrorCode,Invalid channel number");
6428 goto close_mon_conn;
6429 }
6430 res = snprintf(buf, sizeof(buf),
6431 "SCAN TYPE=ONLY freq=%d", freq);
6432 } else {
6433 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6434 }
6435 if (res < 0 || res >= (int) sizeof(buf)) {
6436 send_resp(dut, conn, SIGMA_ERROR,
6437 "ErrorCode,snprintf failed");
6438 goto close_mon_conn;
6439 }
6440 if (wpa_command(intf, buf) < 0) {
6441 sigma_dut_print(dut, DUT_MSG_INFO,
6442 "Failed to start scan");
6443 send_resp(dut, conn, SIGMA_ERROR,
6444 "ErrorCode,scan failed");
6445 goto close_mon_conn;
6446 }
6447
6448 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6449 buf, sizeof(buf));
6450 if (res < 0) {
6451 sigma_dut_print(dut, DUT_MSG_INFO,
6452 "Scan did not complete");
6453 send_resp(dut, conn, SIGMA_ERROR,
6454 "ErrorCode,scan did not complete");
6455 goto close_mon_conn;
6456 }
6457
6458 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6459 if (res > 0 && res < (int) sizeof(buf))
6460 res = wpa_command(intf, buf);
6461
6462 if (res < 0 || res >= (int) sizeof(buf)) {
6463 send_resp(dut, conn, SIGMA_ERROR,
6464 "errorCode,FT_DS command failed");
6465 status = STATUS_SENT_ERROR;
6466 goto close_mon_conn;
6467 }
6468 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306469 if (chan) {
6470 unsigned int freq;
6471
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02006472 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306473 if (!freq) {
6474 sigma_dut_print(dut, DUT_MSG_ERROR,
6475 "Invalid channel number provided: %d",
6476 chan);
6477 send_resp(dut, conn, SIGMA_INVALID,
6478 "ErrorCode,Invalid channel number");
6479 goto close_mon_conn;
6480 }
6481 res = snprintf(buf, sizeof(buf),
6482 "SCAN TYPE=ONLY freq=%d", freq);
6483 } else {
6484 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6485 }
6486 if (res < 0 || res >= (int) sizeof(buf)) {
6487 send_resp(dut, conn, SIGMA_ERROR,
6488 "ErrorCode,snprintf failed");
6489 goto close_mon_conn;
6490 }
6491 if (wpa_command(intf, buf) < 0) {
6492 sigma_dut_print(dut, DUT_MSG_INFO,
6493 "Failed to start scan");
6494 send_resp(dut, conn, SIGMA_ERROR,
6495 "ErrorCode,scan failed");
6496 goto close_mon_conn;
6497 }
6498
6499 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6500 buf, sizeof(buf));
6501 if (res < 0) {
6502 sigma_dut_print(dut, DUT_MSG_INFO,
6503 "Scan did not complete");
6504 send_resp(dut, conn, SIGMA_ERROR,
6505 "ErrorCode,scan did not complete");
6506 goto close_mon_conn;
6507 }
6508
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006509 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6510 < 0) {
6511 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6512 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006513 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306514 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006515 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306516 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006517 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306518 if (res < 0 || res >= (int) sizeof(buf) ||
6519 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006520 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306521 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306522 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006523 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006524 sigma_dut_print(dut, DUT_MSG_INFO,
6525 "sta_reassoc: Run %s successful", buf);
6526 } else if (wpa_command(intf, "REASSOCIATE")) {
6527 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6528 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306529 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006530 }
6531
6532 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6533 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306534 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006535 send_resp(dut, conn, SIGMA_ERROR,
6536 "errorCode,Connection did not complete");
6537 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306538 goto close_mon_conn;
6539 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006540 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006541
Ashwini Patil467efef2017-05-25 12:18:27 +05306542close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006543 wpa_ctrl_detach(ctrl);
6544 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306545 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006546}
6547
6548
6549static void hs2_clear_credentials(const char *intf)
6550{
6551 wpa_command(intf, "REMOVE_CRED all");
6552}
6553
6554
Lior Davidcc88b562017-01-03 18:52:09 +02006555#ifdef __linux__
6556static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6557 unsigned int *aid)
6558{
Lior David0fe101e2017-03-09 16:09:50 +02006559 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006560
Lior David0fe101e2017-03-09 16:09:50 +02006561 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006562}
6563#endif /* __linux__ */
6564
6565
6566static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6567 unsigned int *aid)
6568{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006569 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02006570#ifdef __linux__
6571 case DRIVER_WIL6210:
6572 return wil6210_get_aid(dut, bssid, aid);
6573#endif /* __linux__ */
6574 default:
6575 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6576 return -1;
6577 }
6578}
6579
6580
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006581static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6582 struct sigma_cmd *cmd)
6583{
6584 char buf[MAX_CMD_LEN];
6585 char bss_list[MAX_CMD_LEN];
6586 const char *parameter = get_param(cmd, "Parameter");
6587
6588 if (parameter == NULL)
6589 return -1;
6590
Lior Davidcc88b562017-01-03 18:52:09 +02006591 if (strcasecmp(parameter, "AID") == 0) {
6592 unsigned int aid = 0;
6593 char bssid[20];
6594
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006595 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02006596 bssid, sizeof(bssid)) < 0) {
6597 sigma_dut_print(dut, DUT_MSG_ERROR,
6598 "could not get bssid");
6599 return -2;
6600 }
6601
6602 if (sta_get_aid_60g(dut, bssid, &aid))
6603 return -2;
6604
6605 snprintf(buf, sizeof(buf), "aid,%d", aid);
6606 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6607 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6608 return 0;
6609 }
6610
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006611 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6612 char *bss_line;
6613 char *bss_id = NULL;
6614 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306615 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006616
6617 if (ifname == NULL) {
6618 sigma_dut_print(dut, DUT_MSG_INFO,
6619 "For get DiscoveredDevList need Interface name.");
6620 return -1;
6621 }
6622
6623 /*
6624 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6625 * of BSSIDs in "bssid=<BSSID>\n"
6626 */
6627 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6628 bss_list,
6629 sizeof(bss_list)) < 0) {
6630 sigma_dut_print(dut, DUT_MSG_ERROR,
6631 "Failed to get bss list");
6632 return -1;
6633 }
6634
6635 sigma_dut_print(dut, DUT_MSG_DEBUG,
6636 "bss list for ifname:%s is:%s",
6637 ifname, bss_list);
6638
6639 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306640 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006641 while (bss_line) {
6642 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6643 bss_id) {
6644 int len;
6645
6646 len = snprintf(buf + strlen(buf),
6647 sizeof(buf) - strlen(buf),
6648 ",%s", bss_id);
6649 free(bss_id);
6650 bss_id = NULL;
6651 if (len < 0) {
6652 sigma_dut_print(dut,
6653 DUT_MSG_ERROR,
6654 "Failed to read BSSID");
6655 send_resp(dut, conn, SIGMA_ERROR,
6656 "ErrorCode,Failed to read BSS ID");
6657 return 0;
6658 }
6659
6660 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6661 sigma_dut_print(dut,
6662 DUT_MSG_ERROR,
6663 "Response buf too small for list");
6664 send_resp(dut, conn,
6665 SIGMA_ERROR,
6666 "ErrorCode,Response buf too small for list");
6667 return 0;
6668 }
6669 }
6670
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306671 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006672 }
6673
6674 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6675 buf);
6676 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6677 return 0;
6678 }
6679
6680 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6681 return 0;
6682}
6683
6684
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006685static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6686 struct sigma_cmd *cmd)
6687{
6688 char buf[MAX_CMD_LEN];
6689 const char *parameter = get_param(cmd, "Parameter");
6690
6691 if (!parameter)
6692 return -1;
6693
6694 if (strcasecmp(parameter, "RSSI") == 0) {
6695 char rssi[10];
6696
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006697 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006698 rssi, sizeof(rssi)) < 0) {
6699 sigma_dut_print(dut, DUT_MSG_ERROR,
6700 "Could not get RSSI");
6701 return -2;
6702 }
6703
6704 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6705 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6706 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6707 return 0;
6708 }
6709
6710 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6711 return 0;
6712}
6713
6714
Jouni Malinenca0abd32020-02-09 20:18:10 +02006715static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
6716 struct sigma_conn *conn,
6717 struct sigma_cmd *cmd)
6718{
6719 const char *intf = get_param(cmd, "Interface");
6720 char buf[4096], bssid[20], resp[200], *pos, *tmp;
6721
6722 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
6723 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
6724 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
6725 send_resp(dut, conn, SIGMA_ERROR,
6726 "ErrorCode,PMKSA_GET not supported");
6727 return STATUS_SENT_ERROR;
6728 }
6729
6730 if (strncmp(buf, "FAIL", 4) == 0 ||
6731 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
6732 send_resp(dut, conn, SIGMA_ERROR,
6733 "ErrorCode,Could not find current network");
6734 return STATUS_SENT_ERROR;
6735 }
6736
6737 pos = buf;
6738 while (pos) {
6739 if (strncmp(pos, bssid, 17) == 0) {
6740 pos = strchr(pos, ' ');
6741 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05306742 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02006743 pos++;
6744 pos = strchr(pos, ' ');
6745 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05306746 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02006747 pos++;
6748 tmp = strchr(pos, ' ');
6749 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05306750 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02006751 *tmp = '\0';
6752 break;
6753 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02006754 pos = strchr(pos, '\n');
6755 if (pos)
6756 pos++;
6757 }
6758
6759 if (!pos) {
6760 send_resp(dut, conn, SIGMA_ERROR,
6761 "ErrorCode,PMK not available");
6762 return STATUS_SENT_ERROR;
6763 }
6764
6765 snprintf(resp, sizeof(resp), "PMK,%s", pos);
6766 send_resp(dut, conn, SIGMA_COMPLETE, resp);
6767 return STATUS_SENT;
6768}
6769
6770
Jouni Malinenf7222712019-06-13 01:50:21 +03006771static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
6772 struct sigma_conn *conn,
6773 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006774{
6775 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02006776 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006777
Jouni Malinenca0abd32020-02-09 20:18:10 +02006778 if (!parameter)
6779 return INVALID_SEND_STATUS;
6780
6781 if (strcasecmp(parameter, "PMK") == 0)
6782 return sta_get_pmk(dut, conn, cmd);
6783
6784 if (!program)
6785 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006786
6787 if (strcasecmp(program, "P2PNFC") == 0)
6788 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
6789
6790 if (strcasecmp(program, "60ghz") == 0)
6791 return sta_get_parameter_60g(dut, conn, cmd);
6792
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006793 if (strcasecmp(program, "he") == 0)
6794 return sta_get_parameter_he(dut, conn, cmd);
6795
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006796#ifdef ANDROID_NAN
6797 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07006798 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006799#endif /* ANDROID_NAN */
6800
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006801#ifdef MIRACAST
6802 if (strcasecmp(program, "WFD") == 0 ||
6803 strcasecmp(program, "DisplayR2") == 0)
6804 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
6805#endif /* MIRACAST */
6806
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006807 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6808 return 0;
6809}
6810
6811
6812static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
6813 const char *type)
6814{
6815 char buf[100];
6816
6817 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006818 run_iwpriv(dut, intf, "chwidth 2");
6819 run_iwpriv(dut, intf, "mode 11ACVHT80");
6820 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006821 }
6822
6823 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006824 run_iwpriv(dut, intf, "chwidth 0");
6825 run_iwpriv(dut, intf, "mode 11naht40");
6826 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006827 }
6828
6829 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006830 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006831
6832 /* Reset CTS width */
6833 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
6834 intf);
6835 if (system(buf) != 0) {
6836 sigma_dut_print(dut, DUT_MSG_ERROR,
6837 "wifitool %s beeliner_fw_test 54 0 failed",
6838 intf);
6839 }
6840
6841 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006842 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006843
6844 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
6845 if (system(buf) != 0) {
6846 sigma_dut_print(dut, DUT_MSG_ERROR,
6847 "iwpriv rts failed");
6848 }
6849 }
6850
6851 if (type && strcasecmp(type, "Testbed") == 0) {
6852 dut->testbed_flag_txsp = 1;
6853 dut->testbed_flag_rxsp = 1;
6854 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006855 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006856
6857 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006858 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006859
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006860 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006861
6862 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006863 run_iwpriv(dut, intf, "tx_stbc 0");
6864 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006865
6866 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006867 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006868 }
6869
6870 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006871 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07006872 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006873
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006874 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006875 }
6876}
6877
6878
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006879#ifdef NL80211_SUPPORT
6880static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
6881 enum he_mcs_config mcs)
6882{
6883 struct nl_msg *msg;
6884 int ret = 0;
6885 struct nlattr *params;
6886 int ifindex;
6887
6888 ifindex = if_nametoindex(intf);
6889 if (ifindex == 0) {
6890 sigma_dut_print(dut, DUT_MSG_ERROR,
6891 "%s: Index for interface %s failed",
6892 __func__, intf);
6893 return -1;
6894 }
6895
6896 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6897 NL80211_CMD_VENDOR)) ||
6898 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6899 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6900 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6901 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6902 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6903 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
6904 mcs)) {
6905 sigma_dut_print(dut, DUT_MSG_ERROR,
6906 "%s: err in adding vendor_cmd and vendor_data",
6907 __func__);
6908 nlmsg_free(msg);
6909 return -1;
6910 }
6911 nla_nest_end(msg, params);
6912
6913 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6914 if (ret) {
6915 sigma_dut_print(dut, DUT_MSG_ERROR,
6916 "%s: err in send_and_recv_msgs, ret=%d",
6917 __func__, ret);
6918 }
6919 return ret;
6920}
6921#endif /* NL80211_SUPPORT */
6922
6923
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07006924static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
6925 const char *intf, int enable)
6926{
6927#ifdef NL80211_SUPPORT
6928 struct nl_msg *msg;
6929 int ret = 0;
6930 struct nlattr *params;
6931 int ifindex;
6932
6933 ifindex = if_nametoindex(intf);
6934 if (ifindex == 0) {
6935 sigma_dut_print(dut, DUT_MSG_ERROR,
6936 "%s: Index for interface %s failed",
6937 __func__, intf);
6938 return -1;
6939 }
6940
6941 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6942 NL80211_CMD_VENDOR)) ||
6943 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6944 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6945 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6946 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6947 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6948 nla_put_u8(msg,
6949 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
6950 enable)) {
6951 sigma_dut_print(dut, DUT_MSG_ERROR,
6952 "%s: err in adding vendor_cmd and vendor_data",
6953 __func__);
6954 nlmsg_free(msg);
6955 return -1;
6956 }
6957 nla_nest_end(msg, params);
6958
6959 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6960 if (ret) {
6961 sigma_dut_print(dut, DUT_MSG_ERROR,
6962 "%s: err in send_and_recv_msgs, ret=%d",
6963 __func__, ret);
6964 }
6965 return ret;
6966#else /* NL80211_SUPPORT */
6967 sigma_dut_print(dut, DUT_MSG_ERROR,
6968 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
6969 return -1;
6970#endif /* NL80211_SUPPORT */
6971}
6972
6973
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08006974static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
6975 const char *intf, int enable)
6976{
6977#ifdef NL80211_SUPPORT
6978 struct nl_msg *msg;
6979 int ret = 0;
6980 struct nlattr *params;
6981 int ifindex;
6982
6983 ifindex = if_nametoindex(intf);
6984 if (ifindex == 0) {
6985 sigma_dut_print(dut, DUT_MSG_ERROR,
6986 "%s: Index for interface %s failed",
6987 __func__, intf);
6988 return -1;
6989 }
6990
6991 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6992 NL80211_CMD_VENDOR)) ||
6993 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6994 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6995 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6996 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6997 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6998 nla_put_u8(msg,
6999 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7000 enable)) {
7001 sigma_dut_print(dut, DUT_MSG_ERROR,
7002 "%s: err in adding vendor_cmd and vendor_data",
7003 __func__);
7004 nlmsg_free(msg);
7005 return -1;
7006 }
7007 nla_nest_end(msg, params);
7008
7009 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7010 if (ret) {
7011 sigma_dut_print(dut, DUT_MSG_ERROR,
7012 "%s: err in send_and_recv_msgs, ret=%d",
7013 __func__, ret);
7014 }
7015 return ret;
7016#else /* NL80211_SUPPORT */
7017 sigma_dut_print(dut, DUT_MSG_ERROR,
7018 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7019 return -1;
7020#endif /* NL80211_SUPPORT */
7021}
7022
7023
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007024#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007025
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007026static int sta_set_he_testbed_def(struct sigma_dut *dut,
7027 const char *intf, int cfg)
7028{
7029 struct nl_msg *msg;
7030 int ret = 0;
7031 struct nlattr *params;
7032 int ifindex;
7033
7034 ifindex = if_nametoindex(intf);
7035 if (ifindex == 0) {
7036 sigma_dut_print(dut, DUT_MSG_ERROR,
7037 "%s: Index for interface %s failed",
7038 __func__, intf);
7039 return -1;
7040 }
7041
7042 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7043 NL80211_CMD_VENDOR)) ||
7044 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7045 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7046 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7047 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7048 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7049 nla_put_u8(msg,
7050 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7051 cfg)) {
7052 sigma_dut_print(dut, DUT_MSG_ERROR,
7053 "%s: err in adding vendor_cmd and vendor_data",
7054 __func__);
7055 nlmsg_free(msg);
7056 return -1;
7057 }
7058 nla_nest_end(msg, params);
7059
7060 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7061 if (ret) {
7062 sigma_dut_print(dut, DUT_MSG_ERROR,
7063 "%s: err in send_and_recv_msgs, ret=%d",
7064 __func__, ret);
7065 }
7066 return ret;
7067}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007068
7069
7070static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7071{
7072 struct nl_msg *msg;
7073 int ret = 0;
7074 struct nlattr *params;
7075 int ifindex;
7076
7077 ifindex = if_nametoindex(intf);
7078 if (ifindex == 0) {
7079 sigma_dut_print(dut, DUT_MSG_ERROR,
7080 "%s: Index for interface %s failed",
7081 __func__, intf);
7082 return -1;
7083 }
7084
7085 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7086 NL80211_CMD_VENDOR)) ||
7087 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7088 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7089 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7090 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7091 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7092 nla_put_u8(msg,
7093 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7094 cfg)) {
7095 sigma_dut_print(dut, DUT_MSG_ERROR,
7096 "%s: err in adding vendor_cmd and vendor_data",
7097 __func__);
7098 nlmsg_free(msg);
7099 return -1;
7100 }
7101 nla_nest_end(msg, params);
7102
7103 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7104 if (ret) {
7105 sigma_dut_print(dut, DUT_MSG_ERROR,
7106 "%s: err in send_and_recv_msgs, ret=%d",
7107 __func__, ret);
7108 }
7109 return ret;
7110}
7111
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007112#endif /* NL80211_SUPPORT */
7113
7114
Qiwei Caib6806972020-01-15 13:52:11 +08007115int sta_set_addba_buf_size(struct sigma_dut *dut,
7116 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007117{
7118#ifdef NL80211_SUPPORT
7119 struct nl_msg *msg;
7120 int ret = 0;
7121 struct nlattr *params;
7122 int ifindex;
7123
7124 ifindex = if_nametoindex(intf);
7125 if (ifindex == 0) {
7126 sigma_dut_print(dut, DUT_MSG_ERROR,
7127 "%s: Index for interface %s failed",
7128 __func__, intf);
7129 return -1;
7130 }
7131
7132 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7133 NL80211_CMD_VENDOR)) ||
7134 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7135 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7136 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7137 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7138 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07007139 nla_put_u16(msg,
7140 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
7141 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007142 sigma_dut_print(dut, DUT_MSG_ERROR,
7143 "%s: err in adding vendor_cmd and vendor_data",
7144 __func__);
7145 nlmsg_free(msg);
7146 return -1;
7147 }
7148 nla_nest_end(msg, params);
7149
7150 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7151 if (ret) {
7152 sigma_dut_print(dut, DUT_MSG_ERROR,
7153 "%s: err in send_and_recv_msgs, ret=%d",
7154 __func__, ret);
7155 }
7156 return ret;
7157#else /* NL80211_SUPPORT */
7158 sigma_dut_print(dut, DUT_MSG_ERROR,
7159 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7160 return -1;
7161#endif /* NL80211_SUPPORT */
7162}
7163
7164
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007165static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
7166 int enable)
7167{
7168#ifdef NL80211_SUPPORT
7169 struct nl_msg *msg;
7170 int ret = 0;
7171 struct nlattr *params;
7172 int ifindex;
7173
7174 ifindex = if_nametoindex(intf);
7175 if (ifindex == 0) {
7176 sigma_dut_print(dut, DUT_MSG_ERROR,
7177 "%s: Index for interface %s failed",
7178 __func__, intf);
7179 return -1;
7180 }
7181
7182 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7183 NL80211_CMD_VENDOR)) ||
7184 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7185 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7186 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7187 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7188 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7189 nla_put_u8(msg,
7190 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7191 enable)) {
7192 sigma_dut_print(dut, DUT_MSG_ERROR,
7193 "%s: err in adding vendor_cmd and vendor_data",
7194 __func__);
7195 nlmsg_free(msg);
7196 return -1;
7197 }
7198 nla_nest_end(msg, params);
7199
7200 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7201 if (ret) {
7202 sigma_dut_print(dut, DUT_MSG_ERROR,
7203 "%s: err in send_and_recv_msgs, ret=%d",
7204 __func__, ret);
7205 }
7206 return ret;
7207#else /* NL80211_SUPPORT */
7208 sigma_dut_print(dut, DUT_MSG_ERROR,
7209 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7210 return -1;
7211#endif /* NL80211_SUPPORT */
7212}
7213
7214
Arif Hussain9765f7d2018-07-03 08:28:26 -07007215static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7216 int val)
7217{
7218#ifdef NL80211_SUPPORT
7219 struct nl_msg *msg;
7220 int ret = 0;
7221 struct nlattr *params;
7222 int ifindex;
7223
7224 ifindex = if_nametoindex(intf);
7225 if (ifindex == 0) {
7226 sigma_dut_print(dut, DUT_MSG_ERROR,
7227 "%s: Index for interface %s failed, val:%d",
7228 __func__, intf, val);
7229 return -1;
7230 }
7231
7232 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7233 NL80211_CMD_VENDOR)) ||
7234 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7235 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7236 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7237 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7238 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7239 nla_put_u8(msg,
7240 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7241 val)) {
7242 sigma_dut_print(dut, DUT_MSG_ERROR,
7243 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7244 __func__, val);
7245 nlmsg_free(msg);
7246 return -1;
7247 }
7248 nla_nest_end(msg, params);
7249
7250 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7251 if (ret) {
7252 sigma_dut_print(dut, DUT_MSG_ERROR,
7253 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7254 __func__, ret, val);
7255 }
7256 return ret;
7257#else /* NL80211_SUPPORT */
7258 sigma_dut_print(dut, DUT_MSG_ERROR,
7259 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7260 return -1;
7261#endif /* NL80211_SUPPORT */
7262}
7263
7264
Arif Hussain68d23f52018-07-11 13:39:08 -07007265#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007266static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7267 enum qca_wlan_he_mac_padding_dur val)
7268{
Arif Hussain68d23f52018-07-11 13:39:08 -07007269 struct nl_msg *msg;
7270 int ret = 0;
7271 struct nlattr *params;
7272 int ifindex;
7273
7274 ifindex = if_nametoindex(intf);
7275 if (ifindex == 0) {
7276 sigma_dut_print(dut, DUT_MSG_ERROR,
7277 "%s: Index for interface %s failed, val:%d",
7278 __func__, intf, val);
7279 return -1;
7280 }
7281
7282 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7283 NL80211_CMD_VENDOR)) ||
7284 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7285 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7286 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7287 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7288 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7289 nla_put_u8(msg,
7290 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
7291 val)) {
7292 sigma_dut_print(dut, DUT_MSG_ERROR,
7293 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7294 __func__, val);
7295 nlmsg_free(msg);
7296 return -1;
7297 }
7298 nla_nest_end(msg, params);
7299
7300 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7301 if (ret) {
7302 sigma_dut_print(dut, DUT_MSG_ERROR,
7303 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7304 __func__, ret, val);
7305 }
7306 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07007307}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007308#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007309
7310
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007311static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7312 int val)
7313{
7314#ifdef NL80211_SUPPORT
7315 struct nl_msg *msg;
7316 int ret = 0;
7317 struct nlattr *params;
7318 int ifindex;
7319
7320 ifindex = if_nametoindex(intf);
7321 if (ifindex == 0) {
7322 sigma_dut_print(dut, DUT_MSG_ERROR,
7323 "%s: Index for interface %s failed, val:%d",
7324 __func__, intf, val);
7325 return -1;
7326 }
7327
7328 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7329 NL80211_CMD_VENDOR)) ||
7330 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7331 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7332 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7333 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7334 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7335 nla_put_u8(msg,
7336 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7337 val)) {
7338 sigma_dut_print(dut, DUT_MSG_ERROR,
7339 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7340 __func__, val);
7341 nlmsg_free(msg);
7342 return -1;
7343 }
7344 nla_nest_end(msg, params);
7345
7346 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7347 if (ret) {
7348 sigma_dut_print(dut, DUT_MSG_ERROR,
7349 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7350 __func__, ret, val);
7351 }
7352 return ret;
7353#else /* NL80211_SUPPORT */
7354 sigma_dut_print(dut, DUT_MSG_ERROR,
7355 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7356 return -1;
7357#endif /* NL80211_SUPPORT */
7358}
7359
7360
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007361#ifdef NL80211_SUPPORT
7362static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7363{
7364 struct nl_msg *msg;
7365 int ret = 0;
7366 struct nlattr *params;
7367 int ifindex;
7368
7369 ifindex = if_nametoindex(intf);
7370 if (ifindex == 0) {
7371 sigma_dut_print(dut, DUT_MSG_ERROR,
7372 "%s: Index for interface %s failed",
7373 __func__, intf);
7374 return -1;
7375 }
7376
7377 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7378 NL80211_CMD_VENDOR)) ||
7379 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7380 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7381 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7382 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7383 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7384 nla_put_flag(msg,
7385 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
7386 sigma_dut_print(dut, DUT_MSG_ERROR,
7387 "%s: err in adding vendor_cmd and vendor_data",
7388 __func__);
7389 nlmsg_free(msg);
7390 return -1;
7391 }
7392 nla_nest_end(msg, params);
7393
7394 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7395 if (ret) {
7396 sigma_dut_print(dut, DUT_MSG_ERROR,
7397 "%s: err in send_and_recv_msgs, ret=%d",
7398 __func__, ret);
7399 }
7400 return ret;
7401}
7402#endif /* NL80211_SUPPORT */
7403
7404
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007405static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7406 int val)
7407{
7408#ifdef NL80211_SUPPORT
7409 struct nl_msg *msg;
7410 int ret = 0;
7411 struct nlattr *params;
7412 int ifindex;
7413
7414 ifindex = if_nametoindex(intf);
7415 if (ifindex == 0) {
7416 sigma_dut_print(dut, DUT_MSG_ERROR,
7417 "%s: Index for interface %s failed, val:%d",
7418 __func__, intf, val);
7419 return -1;
7420 }
7421
7422 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7423 NL80211_CMD_VENDOR)) ||
7424 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7425 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7426 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7427 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7428 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7429 nla_put_u8(msg,
7430 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
7431 val)) {
7432 sigma_dut_print(dut, DUT_MSG_ERROR,
7433 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7434 __func__, val);
7435 nlmsg_free(msg);
7436 return -1;
7437 }
7438 nla_nest_end(msg, params);
7439
7440 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7441 if (ret) {
7442 sigma_dut_print(dut, DUT_MSG_ERROR,
7443 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7444 __func__, ret, val);
7445 }
7446 return ret;
7447#else /* NL80211_SUPPORT */
7448 sigma_dut_print(dut, DUT_MSG_ERROR,
7449 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7450 return -1;
7451#endif /* NL80211_SUPPORT */
7452}
7453
7454
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007455static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7456 int val)
7457{
7458#ifdef NL80211_SUPPORT
7459 struct nl_msg *msg;
7460 int ret = 0;
7461 struct nlattr *params;
7462 int ifindex;
7463
7464 ifindex = if_nametoindex(intf);
7465 if (ifindex == 0) {
7466 sigma_dut_print(dut, DUT_MSG_ERROR,
7467 "%s: Index for interface %s failed, val:%d",
7468 __func__, intf, val);
7469 return -1;
7470 }
7471
7472 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7473 NL80211_CMD_VENDOR)) ||
7474 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7475 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7476 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7477 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7478 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7479 nla_put_u8(msg,
7480 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
7481 val)) {
7482 sigma_dut_print(dut, DUT_MSG_ERROR,
7483 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7484 __func__, val);
7485 nlmsg_free(msg);
7486 return -1;
7487 }
7488 nla_nest_end(msg, params);
7489
7490 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7491 if (ret) {
7492 sigma_dut_print(dut, DUT_MSG_ERROR,
7493 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7494 __func__, ret, val);
7495 }
7496 return ret;
7497#else /* NL80211_SUPPORT */
7498 sigma_dut_print(dut, DUT_MSG_ERROR,
7499 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7500 return -1;
7501#endif /* NL80211_SUPPORT */
7502}
7503
7504
Arif Hussain480d5f42019-03-12 14:40:42 -07007505static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7506 int val)
7507{
7508#ifdef NL80211_SUPPORT
7509 struct nl_msg *msg;
7510 int ret;
7511 struct nlattr *params;
7512 int ifindex;
7513
7514 ifindex = if_nametoindex(intf);
7515 if (ifindex == 0) {
7516 sigma_dut_print(dut, DUT_MSG_ERROR,
7517 "%s: Index for interface %s failed, val:%d",
7518 __func__, intf, val);
7519 return -1;
7520 }
7521
7522 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7523 NL80211_CMD_VENDOR)) ||
7524 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7525 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7526 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7527 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7528 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7529 nla_put_u8(msg,
7530 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT,
7531 val)) {
7532 sigma_dut_print(dut, DUT_MSG_ERROR,
7533 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7534 __func__, val);
7535 nlmsg_free(msg);
7536 return -1;
7537 }
7538 nla_nest_end(msg, params);
7539
7540 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7541 if (ret) {
7542 sigma_dut_print(dut, DUT_MSG_ERROR,
7543 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7544 __func__, ret, val);
7545 }
7546 return ret;
7547#else /* NL80211_SUPPORT */
7548 sigma_dut_print(dut, DUT_MSG_ERROR,
7549 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7550 return -1;
7551#endif /* NL80211_SUPPORT */
7552}
7553
7554
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007555static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7556 const char *type)
7557{
7558 char buf[60];
7559
7560 if (dut->program == PROGRAM_HE) {
7561 /* resetting phymode to auto in case of HE program */
7562 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
7563 if (system(buf) != 0) {
7564 sigma_dut_print(dut, DUT_MSG_ERROR,
7565 "iwpriv %s setphymode failed", intf);
7566 }
7567
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007568 /* reset the rate to Auto rate */
7569 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7570 intf);
7571 if (system(buf) != 0) {
7572 sigma_dut_print(dut, DUT_MSG_ERROR,
7573 "iwpriv %s set_11ax_rate 0xff failed",
7574 intf);
7575 }
7576
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007577 /* reset the LDPC setting */
7578 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7579 if (system(buf) != 0) {
7580 sigma_dut_print(dut, DUT_MSG_ERROR,
7581 "iwpriv %s ldpc 1 failed", intf);
7582 }
7583
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007584 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05307585 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007586
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007587 /* remove all network profiles */
7588 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007589
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007590 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7591 sta_set_addba_buf_size(dut, intf, 64);
7592
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007593#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007594 /* Reset the device HE capabilities to its default supported
7595 * configuration. */
7596 sta_set_he_testbed_def(dut, intf, 0);
7597
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007598 /* Disable noackpolicy for all AC */
7599 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7600 sigma_dut_print(dut, DUT_MSG_ERROR,
7601 "Disable of noackpolicy for all AC failed");
7602 }
7603#endif /* NL80211_SUPPORT */
7604
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007605 /* Enable WMM by default */
7606 if (wcn_sta_set_wmm(dut, intf, "on")) {
7607 sigma_dut_print(dut, DUT_MSG_ERROR,
7608 "Enable of WMM in sta_reset_default_wcn failed");
7609 }
7610
7611 /* Disable ADDBA_REJECT by default */
7612 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7613 sigma_dut_print(dut, DUT_MSG_ERROR,
7614 "Disable of addba_reject in sta_reset_default_wcn failed");
7615 }
7616
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007617 /* Enable sending of ADDBA by default */
7618 if (nlvendor_config_send_addba(dut, intf, 1)) {
7619 sigma_dut_print(dut, DUT_MSG_ERROR,
7620 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7621 }
7622
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007623 /* Enable AMPDU by default */
7624 iwpriv_sta_set_ampdu(dut, intf, 1);
7625
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007626#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08007627 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007628 sigma_dut_print(dut, DUT_MSG_ERROR,
7629 "Set LTF config to default in sta_reset_default_wcn failed");
7630 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007631
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007632 /* set the beamformee NSTS(maximum number of
7633 * space-time streams) to default DUT config
7634 */
7635 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007636 sigma_dut_print(dut, DUT_MSG_ERROR,
7637 "Failed to set BeamformeeSTS");
7638 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007639
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007640 if (sta_set_mac_padding_duration(
7641 dut, intf,
7642 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007643 sigma_dut_print(dut, DUT_MSG_ERROR,
7644 "Failed to set MAC padding duration");
7645 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007646
7647 if (sta_set_mu_edca_override(dut, intf, 0)) {
7648 sigma_dut_print(dut, DUT_MSG_ERROR,
7649 "ErrorCode,Failed to set MU EDCA override disable");
7650 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007651
7652 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7653 sigma_dut_print(dut, DUT_MSG_ERROR,
7654 "Failed to set OM ctrl supp");
7655 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007656
7657 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7658 sigma_dut_print(dut, DUT_MSG_ERROR,
7659 "Failed to set Tx SU PPDU enable");
7660 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007661
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007662 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7663 sigma_dut_print(dut, DUT_MSG_ERROR,
7664 "failed to send TB PPDU Tx cfg");
7665 }
7666
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007667 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7668 sigma_dut_print(dut, DUT_MSG_ERROR,
7669 "Failed to set OM ctrl reset");
7670 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007671
7672 /* +HTC-HE support default on */
7673 if (sta_set_he_htc_supp(dut, intf, 1)) {
7674 sigma_dut_print(dut, DUT_MSG_ERROR,
7675 "Setting of +HTC-HE support failed");
7676 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007677#endif /* NL80211_SUPPORT */
7678
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007679 if (sta_set_tx_beamformee(dut, intf, 1)) {
7680 sigma_dut_print(dut, DUT_MSG_ERROR,
7681 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7682 }
7683
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007684 /* Set nss to 1 and MCS 0-7 in case of testbed */
7685 if (type && strcasecmp(type, "Testbed") == 0) {
7686#ifdef NL80211_SUPPORT
7687 int ret;
7688#endif /* NL80211_SUPPORT */
7689
7690 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7691 if (system(buf) != 0) {
7692 sigma_dut_print(dut, DUT_MSG_ERROR,
7693 "iwpriv %s nss failed", intf);
7694 }
7695
7696#ifdef NL80211_SUPPORT
7697 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7698 if (ret) {
7699 sigma_dut_print(dut, DUT_MSG_ERROR,
7700 "Setting of MCS failed, ret:%d",
7701 ret);
7702 }
7703#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007704
7705 /* Disable STBC as default */
7706 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007707
7708 /* Disable AMSDU as default */
7709 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007710
7711#ifdef NL80211_SUPPORT
7712 /* HE fragmentation default off */
7713 if (sta_set_he_fragmentation(dut, intf,
7714 HE_FRAG_DISABLE)) {
7715 sigma_dut_print(dut, DUT_MSG_ERROR,
7716 "Setting of HE fragmentation failed");
7717 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007718
7719 /* set the beamformee NSTS(maximum number of
7720 * space-time streams) to default testbed config
7721 */
7722 if (sta_set_beamformee_sts(dut, intf, 3)) {
7723 sigma_dut_print(dut, DUT_MSG_ERROR,
7724 "Failed to set BeamformeeSTS");
7725 }
7726
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007727 /* +HTC-HE support default off */
7728 if (sta_set_he_htc_supp(dut, intf, 0)) {
7729 sigma_dut_print(dut, DUT_MSG_ERROR,
7730 "Setting of +HTC-HE support failed");
7731 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007732
7733 /* Set device HE capabilities to testbed default
7734 * configuration. */
7735 if (sta_set_he_testbed_def(dut, intf, 1)) {
7736 sigma_dut_print(dut, DUT_MSG_DEBUG,
7737 "Failed to set HE defaults");
7738 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007739
7740 /* Disable VHT support in 2.4 GHz for testbed */
7741 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007742#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007743
7744 /* Enable WEP/TKIP with HE capability in testbed */
7745 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
7746 sigma_dut_print(dut, DUT_MSG_ERROR,
7747 "Enabling HE config with WEP/TKIP failed");
7748 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007749 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007750
7751 /* Defaults in case of DUT */
7752 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07007753 /* Enable STBC by default */
7754 wcn_sta_set_stbc(dut, intf, "1");
7755
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007756 /* set nss to 2 */
7757 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
7758 if (system(buf) != 0) {
7759 sigma_dut_print(dut, DUT_MSG_ERROR,
7760 "iwpriv %s nss 2 failed", intf);
7761 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007762 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007763
7764#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07007765 /* Set HE_MCS to 0-11 */
7766 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007767 sigma_dut_print(dut, DUT_MSG_ERROR,
7768 "Setting of MCS failed");
7769 }
7770#endif /* NL80211_SUPPORT */
7771
7772 /* Disable WEP/TKIP with HE capability in DUT */
7773 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
7774 sigma_dut_print(dut, DUT_MSG_ERROR,
7775 "Enabling HE config with WEP/TKIP failed");
7776 }
7777 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007778 }
7779}
7780
7781
Jouni Malinenf7222712019-06-13 01:50:21 +03007782static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
7783 struct sigma_conn *conn,
7784 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007785{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007786 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007787 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007788 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007789 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307790 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007791
Jouni Malinenb21f0542019-11-04 17:53:38 +02007792 if (dut->station_ifname_2g &&
7793 strcmp(dut->station_ifname_2g, intf) == 0)
7794 dut->use_5g = 0;
7795 else if (dut->station_ifname_5g &&
7796 strcmp(dut->station_ifname_5g, intf) == 0)
7797 dut->use_5g = 1;
7798
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007799 if (!program)
7800 program = get_param(cmd, "prog");
7801 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007802 dut->device_type = STA_unknown;
7803 type = get_param(cmd, "type");
7804 if (type && strcasecmp(type, "Testbed") == 0)
7805 dut->device_type = STA_testbed;
7806 if (type && strcasecmp(type, "DUT") == 0)
7807 dut->device_type = STA_dut;
7808
7809 if (dut->program == PROGRAM_TDLS) {
7810 /* Clear TDLS testing mode */
7811 wpa_command(intf, "SET tdls_disabled 0");
7812 wpa_command(intf, "SET tdls_testing 0");
7813 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007814 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05307815 /* Enable the WCN driver in TDLS Explicit trigger mode
7816 */
7817 wpa_command(intf, "SET tdls_external_control 0");
7818 wpa_command(intf, "SET tdls_trigger_control 0");
7819 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007820 }
7821
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007822#ifdef MIRACAST
7823 if (dut->program == PROGRAM_WFD ||
7824 dut->program == PROGRAM_DISPLAYR2)
7825 miracast_sta_reset_default(dut, conn, cmd);
7826#endif /* MIRACAST */
7827
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007828 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007829 case DRIVER_ATHEROS:
7830 sta_reset_default_ath(dut, intf, type);
7831 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007832 case DRIVER_WCN:
7833 sta_reset_default_wcn(dut, intf, type);
7834 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007835 default:
7836 break;
7837 }
7838
7839#ifdef ANDROID_NAN
7840 if (dut->program == PROGRAM_NAN)
7841 nan_cmd_sta_reset_default(dut, conn, cmd);
7842#endif /* ANDROID_NAN */
7843
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05307844 if (dut->program == PROGRAM_LOC &&
7845 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
7846 return ERROR_SEND_STATUS;
7847
Jouni Malinenba630452018-06-22 11:49:59 +03007848 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007849 unlink("SP/wi-fi.org/pps.xml");
7850 if (system("rm -r SP/*") != 0) {
7851 }
7852 unlink("next-client-cert.pem");
7853 unlink("next-client-key.pem");
7854 }
7855
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007856 /* For WPS program of the 60 GHz band the band type needs to be saved */
7857 if (dut->program == PROGRAM_WPS) {
7858 if (band && strcasecmp(band, "60GHz") == 0) {
7859 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007860 /* For 60 GHz enable WPS for WPS TCs */
7861 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007862 } else {
7863 dut->band = WPS_BAND_NON_60G;
7864 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007865 } else if (dut->program == PROGRAM_60GHZ) {
7866 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
7867 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007868 }
7869
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02007870 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007871 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007872 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007873
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007874 sigma_dut_print(dut, DUT_MSG_INFO,
7875 "WPS 60 GHz program, wps_disable = %d",
7876 dut->wps_disable);
7877
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007878 if (!dev_role) {
7879 send_resp(dut, conn, SIGMA_ERROR,
7880 "errorCode,Missing DevRole argument");
7881 return 0;
7882 }
7883
7884 if (strcasecmp(dev_role, "STA") == 0)
7885 dut->dev_role = DEVROLE_STA;
7886 else if (strcasecmp(dev_role, "PCP") == 0)
7887 dut->dev_role = DEVROLE_PCP;
7888 else {
7889 send_resp(dut, conn, SIGMA_ERROR,
7890 "errorCode,Unknown DevRole");
7891 return 0;
7892 }
7893
7894 if (dut->device_type == STA_unknown) {
7895 sigma_dut_print(dut, DUT_MSG_ERROR,
7896 "Device type is not STA testbed or DUT");
7897 send_resp(dut, conn, SIGMA_ERROR,
7898 "errorCode,Unknown device type");
7899 return 0;
7900 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007901
7902 sigma_dut_print(dut, DUT_MSG_DEBUG,
7903 "Setting msdu_size to MAX: 7912");
7904 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007905 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007906
7907 if (system(buf) != 0) {
7908 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
7909 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007910 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007911 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007912
7913 if (sta_set_force_mcs(dut, 0, 1)) {
7914 sigma_dut_print(dut, DUT_MSG_ERROR,
7915 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007916 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007917 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007918 }
7919
7920 wpa_command(intf, "WPS_ER_STOP");
7921 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05307922 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007923 wpa_command(intf, "SET radio_disabled 0");
7924
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007925 dut->wps_forced_version = 0;
7926
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007927 if (dut->wsc_fragment) {
7928 dut->wsc_fragment = 0;
7929 wpa_command(intf, "SET device_name Test client");
7930 wpa_command(intf, "SET manufacturer ");
7931 wpa_command(intf, "SET model_name ");
7932 wpa_command(intf, "SET model_number ");
7933 wpa_command(intf, "SET serial_number ");
7934 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02007935 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
7936 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
7937 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
7938 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007939
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007940 if (dut->tmp_mac_addr && dut->set_macaddr) {
7941 dut->tmp_mac_addr = 0;
7942 if (system(dut->set_macaddr) != 0) {
7943 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
7944 "temporary MAC address");
7945 }
7946 }
7947
7948 set_ps(intf, dut, 0);
7949
Jouni Malinenba630452018-06-22 11:49:59 +03007950 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
7951 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007952 wpa_command(intf, "SET interworking 1");
7953 wpa_command(intf, "SET hs20 1");
7954 }
7955
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007956 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007957 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007958 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007959 wpa_command(intf, "SET pmf 1");
7960 } else {
7961 wpa_command(intf, "SET pmf 0");
7962 }
7963
7964 hs2_clear_credentials(intf);
7965 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
7966 wpa_command(intf, "SET access_network_type 15");
7967
7968 static_ip_file(0, NULL, NULL, NULL);
7969 kill_dhcp_client(dut, intf);
7970 clear_ip_addr(dut, intf);
7971
7972 dut->er_oper_performed = 0;
7973 dut->er_oper_bssid[0] = '\0';
7974
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007975 if (dut->program == PROGRAM_LOC) {
7976 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007977 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007978 }
7979
Ashwini Patil00402582017-04-13 12:29:39 +05307980 if (dut->program == PROGRAM_MBO) {
7981 free(dut->non_pref_ch_list);
7982 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05307983 free(dut->btm_query_cand_list);
7984 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05307985 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05307986 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05307987 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05307988 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05307989 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05307990 }
7991
Jouni Malinen3c367e82017-06-23 17:01:47 +03007992 free(dut->rsne_override);
7993 dut->rsne_override = NULL;
7994
Jouni Malinen68143132017-09-02 02:34:08 +03007995 free(dut->sae_commit_override);
7996 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03007997 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02007998 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03007999
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008000 dut->sta_associate_wait_connect = 0;
8001 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03008002 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008003 dut->sta_tod_policy = 0;
8004
Jouni Malinend86e5822017-08-29 03:55:32 +03008005 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02008006 free(dut->dpp_peer_uri);
8007 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02008008 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02008009 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03008010 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03008011
Jouni Malinenfac9cad2017-10-10 18:35:55 +03008012 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
8013
vamsi krishnaa2799492017-12-05 14:28:01 +05308014 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308015 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05308016 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05308017 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
8018 dut->fils_hlp = 0;
8019#ifdef ANDROID
8020 hlp_thread_cleanup(dut);
8021#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05308022 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308023
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308024 if (dut->program == PROGRAM_QM)
8025 wpa_command(intf, "SET interworking 1");
8026
Jouni Malinen8179fee2019-03-28 03:19:47 +02008027 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03008028 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02008029
Sunil Dutt076081f2018-02-05 19:45:50 +05308030#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008031 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05308032 dut->config_rsnie == 1) {
8033 dut->config_rsnie = 0;
8034 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05308035 }
8036#endif /* NL80211_SUPPORT */
8037
Sunil Duttfebf8a82018-02-09 18:50:13 +05308038 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
8039 dut->dev_role = DEVROLE_STA_CFON;
8040 return sta_cfon_reset_default(dut, conn, cmd);
8041 }
8042
Jouni Malinen439352d2018-09-13 03:42:23 +03008043 wpa_command(intf, "SET setband AUTO");
8044
Sunil Duttfebf8a82018-02-09 18:50:13 +05308045 if (dut->program != PROGRAM_VHT)
8046 return cmd_sta_p2p_reset(dut, conn, cmd);
8047
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08008048 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008049}
8050
8051
Jouni Malinenf7222712019-06-13 01:50:21 +03008052static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
8053 struct sigma_conn *conn,
8054 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008055{
8056 const char *program = get_param(cmd, "Program");
8057
8058 if (program == NULL)
8059 return -1;
8060#ifdef ANDROID_NAN
8061 if (strcasecmp(program, "NAN") == 0)
8062 return nan_cmd_sta_get_events(dut, conn, cmd);
8063#endif /* ANDROID_NAN */
8064 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8065 return 0;
8066}
8067
8068
Jouni Malinen82905202018-04-29 17:20:10 +03008069static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
8070 struct sigma_cmd *cmd)
8071{
8072 const char *url = get_param(cmd, "url");
8073 const char *method = get_param(cmd, "method");
8074 pid_t pid;
8075 int status;
8076
8077 if (!url || !method)
8078 return -1;
8079
8080 /* TODO: Add support for method,post */
8081 if (strcasecmp(method, "get") != 0) {
8082 send_resp(dut, conn, SIGMA_ERROR,
8083 "ErrorCode,Unsupported method");
8084 return 0;
8085 }
8086
8087 pid = fork();
8088 if (pid < 0) {
8089 perror("fork");
8090 return -1;
8091 }
8092
8093 if (pid == 0) {
8094 char * argv[5] = { "wget", "-O", "/dev/null",
8095 (char *) url, NULL };
8096
8097 execv("/usr/bin/wget", argv);
8098 perror("execv");
8099 exit(0);
8100 return -1;
8101 }
8102
8103 if (waitpid(pid, &status, 0) < 0) {
8104 perror("waitpid");
8105 return -1;
8106 }
8107
8108 if (WIFEXITED(status)) {
8109 const char *errmsg;
8110
8111 if (WEXITSTATUS(status) == 0)
8112 return 1;
8113 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
8114 WEXITSTATUS(status));
8115 switch (WEXITSTATUS(status)) {
8116 case 4:
8117 errmsg = "errmsg,Network failure";
8118 break;
8119 case 8:
8120 errmsg = "errmsg,Server issued an error response";
8121 break;
8122 default:
8123 errmsg = "errmsg,Unknown failure from wget";
8124 break;
8125 }
8126 send_resp(dut, conn, SIGMA_ERROR, errmsg);
8127 return 0;
8128 }
8129
8130 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
8131 return 0;
8132}
8133
8134
Jouni Malinenf7222712019-06-13 01:50:21 +03008135static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
8136 struct sigma_conn *conn,
8137 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008138{
8139 const char *program = get_param(cmd, "Prog");
8140
Jouni Malinen82905202018-04-29 17:20:10 +03008141 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008142 return -1;
8143#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03008144 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008145 return nan_cmd_sta_exec_action(dut, conn, cmd);
8146#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03008147
8148 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07008149 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03008150
8151 if (get_param(cmd, "url"))
8152 return sta_exec_action_url(dut, conn, cmd);
8153
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008154 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8155 return 0;
8156}
8157
8158
Jouni Malinenf7222712019-06-13 01:50:21 +03008159static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
8160 struct sigma_conn *conn,
8161 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008162{
8163 const char *intf = get_param(cmd, "Interface");
8164 const char *val, *mcs32, *rate;
8165
8166 val = get_param(cmd, "GREENFIELD");
8167 if (val) {
8168 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
8169 /* Enable GD */
8170 send_resp(dut, conn, SIGMA_ERROR,
8171 "ErrorCode,GF not supported");
8172 return 0;
8173 }
8174 }
8175
8176 val = get_param(cmd, "SGI20");
8177 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008178 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008179 case DRIVER_ATHEROS:
8180 ath_sta_set_sgi(dut, intf, val);
8181 break;
8182 default:
8183 send_resp(dut, conn, SIGMA_ERROR,
8184 "ErrorCode,SGI20 not supported");
8185 return 0;
8186 }
8187 }
8188
8189 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
8190 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
8191 if (mcs32 && rate) {
8192 /* TODO */
8193 send_resp(dut, conn, SIGMA_ERROR,
8194 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
8195 return 0;
8196 } else if (mcs32 && !rate) {
8197 /* TODO */
8198 send_resp(dut, conn, SIGMA_ERROR,
8199 "ErrorCode,MCS32 not supported");
8200 return 0;
8201 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008202 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008203 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008204 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008205 ath_sta_set_11nrates(dut, intf, rate);
8206 break;
8207 default:
8208 send_resp(dut, conn, SIGMA_ERROR,
8209 "ErrorCode,MCS32_FIXEDRATE not supported");
8210 return 0;
8211 }
8212 }
8213
8214 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8215}
8216
8217
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008218static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8219 int mcs_config)
8220{
8221#ifdef NL80211_SUPPORT
8222 int ret;
8223
8224 switch (mcs_config) {
8225 case HE_80_MCS0_7:
8226 case HE_80_MCS0_9:
8227 case HE_80_MCS0_11:
8228 ret = sta_set_he_mcs(dut, intf, mcs_config);
8229 if (ret) {
8230 sigma_dut_print(dut, DUT_MSG_ERROR,
8231 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8232 mcs_config, ret);
8233 }
8234 break;
8235 default:
8236 sigma_dut_print(dut, DUT_MSG_ERROR,
8237 "cmd_set_max_he_mcs: Invalid mcs %d",
8238 mcs_config);
8239 break;
8240 }
8241#else /* NL80211_SUPPORT */
8242 sigma_dut_print(dut, DUT_MSG_ERROR,
8243 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8244#endif /* NL80211_SUPPORT */
8245}
8246
8247
Arif Hussain480d5f42019-03-12 14:40:42 -07008248static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8249 struct sigma_cmd *cmd)
8250{
8251#ifdef NL80211_SUPPORT
8252 struct nlattr *params;
8253 struct nlattr *attr;
8254 struct nlattr *attr1;
8255 struct nl_msg *msg;
8256 int ifindex, ret;
8257 const char *val;
8258 const char *intf = get_param(cmd, "Interface");
8259 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8260 wake_interval_mantissa = 512;
8261 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
8262 protection = 0;
8263
8264 ifindex = if_nametoindex(intf);
8265 if (ifindex == 0) {
8266 sigma_dut_print(dut, DUT_MSG_ERROR,
8267 "%s: Index for interface %s failed",
8268 __func__, intf);
8269 return -1;
8270 }
8271
8272 val = get_param(cmd, "FlowType");
8273 if (val) {
8274 flow_type = atoi(val);
8275 if (flow_type != 0 && flow_type != 1) {
8276 sigma_dut_print(dut, DUT_MSG_ERROR,
8277 "TWT: Invalid FlowType %d", flow_type);
8278 return -1;
8279 }
8280 }
8281
8282 val = get_param(cmd, "TWT_Trigger");
8283 if (val) {
8284 twt_trigger = atoi(val);
8285 if (twt_trigger != 0 && twt_trigger != 1) {
8286 sigma_dut_print(dut, DUT_MSG_ERROR,
8287 "TWT: Invalid TWT_Trigger %d",
8288 twt_trigger);
8289 return -1;
8290 }
8291 }
8292
8293 val = get_param(cmd, "Protection");
8294 if (val) {
8295 protection = atoi(val);
8296 if (protection != 0 && protection != 1) {
8297 sigma_dut_print(dut, DUT_MSG_ERROR,
8298 "TWT: Invalid Protection %d",
8299 protection);
8300 return -1;
8301 }
8302 }
8303
8304 val = get_param(cmd, "TargetWakeTime");
8305 if (val)
8306 target_wake_time = atoi(val);
8307
8308 val = get_param(cmd, "WakeIntervalMantissa");
8309 if (val)
8310 wake_interval_mantissa = atoi(val);
8311
8312 val = get_param(cmd, "WakeIntervalExp");
8313 if (val)
8314 wake_interval_exp = atoi(val);
8315
8316 val = get_param(cmd, "NominalMinWakeDur");
8317 if (val)
8318 nominal_min_wake_dur = atoi(val);
8319
8320 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8321 NL80211_CMD_VENDOR)) ||
8322 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8323 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8324 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8325 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8326 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8327 !(params = nla_nest_start(
8328 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
8329 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8330 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8331 wake_interval_exp) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008332 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, 1) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008333 (twt_trigger &&
8334 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008335 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8336 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008337 (protection &&
8338 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008339 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8340 target_wake_time) ||
8341 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8342 nominal_min_wake_dur) ||
8343 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8344 wake_interval_mantissa)) {
8345 sigma_dut_print(dut, DUT_MSG_ERROR,
8346 "%s: err in adding vendor_cmd and vendor_data",
8347 __func__);
8348 nlmsg_free(msg);
8349 return -1;
8350 }
8351 nla_nest_end(msg, attr1);
8352 nla_nest_end(msg, params);
8353 nla_nest_end(msg, attr);
8354
8355 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8356 if (ret) {
8357 sigma_dut_print(dut, DUT_MSG_ERROR,
8358 "%s: err in send_and_recv_msgs, ret=%d",
8359 __func__, ret);
8360 }
8361
8362 return ret;
8363#else /* NL80211_SUPPORT */
8364 sigma_dut_print(dut, DUT_MSG_ERROR,
8365 "TWT request cannot be done without NL80211_SUPPORT defined");
8366 return -1;
8367#endif /* NL80211_SUPPORT */
8368}
8369
8370
8371static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8372 struct sigma_cmd *cmd)
8373{
8374 #ifdef NL80211_SUPPORT
8375 struct nlattr *params;
8376 struct nlattr *attr;
8377 struct nlattr *attr1;
8378 int ifindex, ret;
8379 struct nl_msg *msg;
8380 const char *intf = get_param(cmd, "Interface");
8381
8382 ifindex = if_nametoindex(intf);
8383 if (ifindex == 0) {
8384 sigma_dut_print(dut, DUT_MSG_ERROR,
8385 "%s: Index for interface %s failed",
8386 __func__, intf);
8387 return -1;
8388 }
8389
8390 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8391 NL80211_CMD_VENDOR)) ||
8392 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8393 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8394 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8395 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8396 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8397 !(params = nla_nest_start(
8398 msg,
8399 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8400 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8401 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8402 sigma_dut_print(dut, DUT_MSG_ERROR,
8403 "%s: err in adding vendor_cmd and vendor_data",
8404 __func__);
8405 nlmsg_free(msg);
8406 return -1;
8407 }
8408 nla_nest_end(msg, attr1);
8409 nla_nest_end(msg, params);
8410 nla_nest_end(msg, attr);
8411
8412 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8413 if (ret) {
8414 sigma_dut_print(dut, DUT_MSG_ERROR,
8415 "%s: err in send_and_recv_msgs, ret=%d",
8416 __func__, ret);
8417 }
8418
8419 return ret;
8420#else /* NL80211_SUPPORT */
8421 sigma_dut_print(dut, DUT_MSG_ERROR,
8422 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8423 return -1;
8424#endif /* NL80211_SUPPORT */
8425}
8426
8427
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008428static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8429 struct sigma_cmd *cmd)
8430{
8431#ifdef NL80211_SUPPORT
8432 struct nlattr *params;
8433 struct nlattr *attr;
8434 struct nlattr *attr1;
8435 struct nl_msg *msg;
8436 int ifindex, ret;
8437 const char *val;
8438 const char *intf = get_param(cmd, "Interface");
8439 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8440 ulmu_data_dis = 0;
8441
8442 ifindex = if_nametoindex(intf);
8443 if (ifindex == 0) {
8444 sigma_dut_print(dut, DUT_MSG_ERROR,
8445 "%s: Index for interface %s failed",
8446 __func__, intf);
8447 return -1;
8448 }
8449 val = get_param(cmd, "OMCtrl_RxNSS");
8450 if (val)
8451 rx_nss = atoi(val);
8452
8453 val = get_param(cmd, "OMCtrl_ChnlWidth");
8454 if (val)
8455 ch_bw = atoi(val);
8456
8457 val = get_param(cmd, "OMCtrl_ULMUDisable");
8458 if (val)
8459 ulmu_dis = atoi(val);
8460
8461 val = get_param(cmd, "OMCtrl_TxNSTS");
8462 if (val)
8463 tx_nsts = atoi(val);
8464
8465 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8466 if (val)
8467 ulmu_data_dis = atoi(val);
8468
8469 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8470 NL80211_CMD_VENDOR)) ||
8471 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8472 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8473 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8474 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8475 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8476 !(params = nla_nest_start(
8477 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8478 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8479 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8480 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8481 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8482 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8483 ulmu_data_dis) ||
8484 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8485 ulmu_dis)) {
8486 sigma_dut_print(dut, DUT_MSG_ERROR,
8487 "%s: err in adding vendor_cmd and vendor_data",
8488 __func__);
8489 nlmsg_free(msg);
8490 return -1;
8491 }
8492 nla_nest_end(msg, attr1);
8493 nla_nest_end(msg, params);
8494 nla_nest_end(msg, attr);
8495
8496 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8497 if (ret) {
8498 sigma_dut_print(dut, DUT_MSG_ERROR,
8499 "%s: err in send_and_recv_msgs, ret=%d",
8500 __func__, ret);
8501 }
8502
8503 return ret;
8504#else /* NL80211_SUPPORT */
8505 sigma_dut_print(dut, DUT_MSG_ERROR,
8506 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8507 return -1;
8508#endif /* NL80211_SUPPORT */
8509}
8510
8511
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008512static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8513 struct sigma_conn *conn,
8514 struct sigma_cmd *cmd)
8515{
8516 const char *intf = get_param(cmd, "Interface");
8517 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008518 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008519 int tkip = -1;
8520 int wep = -1;
8521
Arif Hussaina37e9552018-06-20 17:05:59 -07008522 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008523 val = get_param(cmd, "SGI80");
8524 if (val) {
8525 int sgi80;
8526
8527 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008528 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008529 }
8530
8531 val = get_param(cmd, "TxBF");
8532 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008533 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008534 case DRIVER_WCN:
8535 if (sta_set_tx_beamformee(dut, intf, 1)) {
8536 send_resp(dut, conn, SIGMA_ERROR,
8537 "ErrorCode,Failed to set TX beamformee enable");
8538 return 0;
8539 }
8540 break;
8541 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008542 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008543 send_resp(dut, conn, SIGMA_ERROR,
8544 "ErrorCode,Setting vhtsubfee failed");
8545 return 0;
8546 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008547 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008548 send_resp(dut, conn, SIGMA_ERROR,
8549 "ErrorCode,Setting vhtsubfer failed");
8550 return 0;
8551 }
8552 break;
8553 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008554 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008555 "Unsupported driver type");
8556 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008557 }
8558 }
8559
8560 val = get_param(cmd, "MU_TxBF");
8561 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008562 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008563 case DRIVER_ATHEROS:
8564 ath_sta_set_txsp_stream(dut, intf, "1SS");
8565 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008566 run_iwpriv(dut, intf, "vhtmubfee 1");
8567 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308568 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008569 case DRIVER_WCN:
8570 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8571 send_resp(dut, conn, SIGMA_ERROR,
8572 "ErrorCode,Failed to set RX/TXSP_STREAM");
8573 return 0;
8574 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308575 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008576 default:
8577 sigma_dut_print(dut, DUT_MSG_ERROR,
8578 "Setting SP_STREAM not supported");
8579 break;
8580 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008581 }
8582
8583 val = get_param(cmd, "LDPC");
8584 if (val) {
8585 int ldpc;
8586
8587 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008588 run_iwpriv(dut, intf, "ldpc %d", ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008589 }
8590
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008591 val = get_param(cmd, "BCC");
8592 if (val) {
8593 int bcc;
8594
8595 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8596 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8597 * is mutually exclusive to bcc */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008598 run_iwpriv(dut, intf, "ldpc %d", !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008599 }
8600
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008601 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8602 if (val && dut->sta_nss == 1)
8603 cmd_set_max_he_mcs(dut, intf, atoi(val));
8604
8605 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8606 if (val && dut->sta_nss == 2)
8607 cmd_set_max_he_mcs(dut, intf, atoi(val));
8608
Arif Hussainac6c5112018-05-25 17:34:00 -07008609 val = get_param(cmd, "MCS_FixedRate");
8610 if (val) {
8611#ifdef NL80211_SUPPORT
8612 int mcs, ratecode = 0;
8613 enum he_mcs_config mcs_config;
8614 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008615 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008616
8617 ratecode = (0x07 & dut->sta_nss) << 5;
8618 mcs = atoi(val);
8619 /* Add the MCS to the ratecode */
8620 if (mcs >= 0 && mcs <= 11) {
8621 ratecode += mcs;
8622 if (dut->device_type == STA_testbed &&
8623 mcs > 7 && mcs <= 11) {
8624 if (mcs <= 9)
8625 mcs_config = HE_80_MCS0_9;
8626 else
8627 mcs_config = HE_80_MCS0_11;
8628 ret = sta_set_he_mcs(dut, intf, mcs_config);
8629 if (ret) {
8630 sigma_dut_print(dut, DUT_MSG_ERROR,
8631 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8632 mcs, mcs_config, ret);
8633 }
8634 }
8635 snprintf(buf, sizeof(buf),
8636 "iwpriv %s set_11ax_rate 0x%03x",
8637 intf, ratecode);
8638 if (system(buf) != 0) {
8639 sigma_dut_print(dut, DUT_MSG_ERROR,
8640 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8641 ratecode);
8642 }
8643 } else {
8644 sigma_dut_print(dut, DUT_MSG_ERROR,
8645 "MCS_FixedRate: HE MCS %d not supported",
8646 mcs);
8647 }
8648#else /* NL80211_SUPPORT */
8649 sigma_dut_print(dut, DUT_MSG_ERROR,
8650 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8651#endif /* NL80211_SUPPORT */
8652 }
8653
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008654 val = get_param(cmd, "opt_md_notif_ie");
8655 if (val) {
8656 char *result = NULL;
8657 char delim[] = ";";
8658 char token[30];
8659 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308660 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008661
Peng Xub8fc5cc2017-05-10 17:27:28 -07008662 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308663 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008664
8665 /* Extract the NSS information */
8666 if (result) {
8667 value = atoi(result);
8668 switch (value) {
8669 case 1:
8670 config_val = 1;
8671 break;
8672 case 2:
8673 config_val = 3;
8674 break;
8675 case 3:
8676 config_val = 7;
8677 break;
8678 case 4:
8679 config_val = 15;
8680 break;
8681 default:
8682 config_val = 3;
8683 break;
8684 }
8685
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008686 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8687 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008688
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008689 }
8690
8691 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308692 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008693 if (result) {
8694 value = atoi(result);
8695 switch (value) {
8696 case 20:
8697 config_val = 0;
8698 break;
8699 case 40:
8700 config_val = 1;
8701 break;
8702 case 80:
8703 config_val = 2;
8704 break;
8705 case 160:
8706 config_val = 3;
8707 break;
8708 default:
8709 config_val = 2;
8710 break;
8711 }
8712
8713 dut->chwidth = config_val;
8714
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008715 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008716 }
8717
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008718 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008719 }
8720
8721 val = get_param(cmd, "nss_mcs_cap");
8722 if (val) {
8723 int nss, mcs;
8724 char token[20];
8725 char *result = NULL;
8726 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308727 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008728
Peng Xub8fc5cc2017-05-10 17:27:28 -07008729 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308730 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308731 if (!result) {
8732 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008733 "NSS not specified");
8734 send_resp(dut, conn, SIGMA_ERROR,
8735 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308736 return 0;
8737 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008738 nss = atoi(result);
8739
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008740 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07008741 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008742
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308743 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008744 if (result == NULL) {
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");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008749 return 0;
8750 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308751 result = strtok_r(result, "-", &saveptr);
8752 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308753 if (!result) {
8754 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008755 "MCS not specified");
8756 send_resp(dut, conn, SIGMA_ERROR,
8757 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308758 return 0;
8759 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008760 mcs = atoi(result);
8761
Arif Hussaina37e9552018-06-20 17:05:59 -07008762 if (program && strcasecmp(program, "HE") == 0) {
8763#ifdef NL80211_SUPPORT
8764 enum he_mcs_config mcs_config;
8765 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008766
Arif Hussaina37e9552018-06-20 17:05:59 -07008767 if (mcs >= 0 && mcs <= 7) {
8768 mcs_config = HE_80_MCS0_7;
8769 } else if (mcs > 7 && mcs <= 9) {
8770 mcs_config = HE_80_MCS0_9;
8771 } else if (mcs > 9 && mcs <= 11) {
8772 mcs_config = HE_80_MCS0_11;
8773 } else {
8774 sigma_dut_print(dut, DUT_MSG_ERROR,
8775 "nss_mcs_cap: HE: Invalid mcs: %d",
8776 mcs);
8777 send_resp(dut, conn, SIGMA_ERROR,
8778 "errorCode,Invalid MCS");
8779 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008780 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008781
8782 ret = sta_set_he_mcs(dut, intf, mcs_config);
8783 if (ret) {
8784 sigma_dut_print(dut, DUT_MSG_ERROR,
8785 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
8786 mcs_config, ret);
8787 send_resp(dut, conn, SIGMA_ERROR,
8788 "errorCode,Failed to set MCS");
8789 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008790 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008791#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008792 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008793 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
8794#endif /* NL80211_SUPPORT */
8795 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008796 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07008797
8798 switch (nss) {
8799 case 1:
8800 switch (mcs) {
8801 case 7:
8802 vht_mcsmap = 0xfffc;
8803 break;
8804 case 8:
8805 vht_mcsmap = 0xfffd;
8806 break;
8807 case 9:
8808 vht_mcsmap = 0xfffe;
8809 break;
8810 default:
8811 vht_mcsmap = 0xfffe;
8812 break;
8813 }
8814 break;
8815 case 2:
8816 switch (mcs) {
8817 case 7:
8818 vht_mcsmap = 0xfff0;
8819 break;
8820 case 8:
8821 vht_mcsmap = 0xfff5;
8822 break;
8823 case 9:
8824 vht_mcsmap = 0xfffa;
8825 break;
8826 default:
8827 vht_mcsmap = 0xfffa;
8828 break;
8829 }
8830 break;
8831 case 3:
8832 switch (mcs) {
8833 case 7:
8834 vht_mcsmap = 0xffc0;
8835 break;
8836 case 8:
8837 vht_mcsmap = 0xffd5;
8838 break;
8839 case 9:
8840 vht_mcsmap = 0xffea;
8841 break;
8842 default:
8843 vht_mcsmap = 0xffea;
8844 break;
8845 }
8846 break;
8847 default:
8848 vht_mcsmap = 0xffea;
8849 break;
8850 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008851 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008852 }
8853 }
8854
8855 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
8856
8857 val = get_param(cmd, "Vht_tkip");
8858 if (val)
8859 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8860
8861 val = get_param(cmd, "Vht_wep");
8862 if (val)
8863 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8864
8865 if (tkip != -1 || wep != -1) {
8866 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008867 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008868 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008869 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008870 } else {
8871 sigma_dut_print(dut, DUT_MSG_ERROR,
8872 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
8873 return 0;
8874 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008875 }
8876
Arif Hussain55f00da2018-07-03 08:28:26 -07008877 val = get_param(cmd, "txBandwidth");
8878 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008879 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07008880 case DRIVER_WCN:
8881 if (wcn_sta_set_width(dut, intf, val) < 0) {
8882 send_resp(dut, conn, SIGMA_ERROR,
8883 "ErrorCode,Failed to set txBandwidth");
8884 return 0;
8885 }
8886 break;
8887 case DRIVER_ATHEROS:
8888 if (ath_set_width(dut, conn, intf, val) < 0) {
8889 send_resp(dut, conn, SIGMA_ERROR,
8890 "ErrorCode,Failed to set txBandwidth");
8891 return 0;
8892 }
8893 break;
8894 default:
8895 sigma_dut_print(dut, DUT_MSG_ERROR,
8896 "Setting txBandwidth not supported");
8897 break;
8898 }
8899 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008900
Arif Hussain9765f7d2018-07-03 08:28:26 -07008901 val = get_param(cmd, "BeamformeeSTS");
8902 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07008903 if (sta_set_tx_beamformee(dut, intf, 1)) {
8904 send_resp(dut, conn, SIGMA_ERROR,
8905 "ErrorCode,Failed to set TX beamformee enable");
8906 return 0;
8907 }
8908
Arif Hussain9765f7d2018-07-03 08:28:26 -07008909 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
8910 send_resp(dut, conn, SIGMA_ERROR,
8911 "ErrorCode,Failed to set BeamformeeSTS");
8912 return 0;
8913 }
8914 }
8915
Arif Hussain68d23f52018-07-11 13:39:08 -07008916 val = get_param(cmd, "Trig_MAC_Padding_Dur");
8917 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008918#ifdef NL80211_SUPPORT
8919 enum qca_wlan_he_mac_padding_dur set_val;
8920
8921 switch (atoi(val)) {
8922 case 16:
8923 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
8924 break;
8925 case 8:
8926 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
8927 break;
8928 default:
8929 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
8930 break;
8931 }
8932 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008933 send_resp(dut, conn, SIGMA_ERROR,
8934 "ErrorCode,Failed to set MAC padding duration");
8935 return 0;
8936 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008937#else /* NL80211_SUPPORT */
8938 sigma_dut_print(dut, DUT_MSG_ERROR,
8939 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
8940#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008941 }
8942
Arif Hussain480d5f42019-03-12 14:40:42 -07008943 val = get_param(cmd, "TWT_ReqSupport");
8944 if (val) {
8945 int set_val;
8946
8947 if (strcasecmp(val, "Enable") == 0) {
8948 set_val = 1;
8949 } else if (strcasecmp(val, "Disable") == 0) {
8950 set_val = 0;
8951 } else {
8952 send_resp(dut, conn, SIGMA_ERROR,
8953 "ErrorCode,Invalid TWT_ReqSupport");
8954 return STATUS_SENT;
8955 }
8956
8957 if (sta_set_twt_req_support(dut, intf, set_val)) {
8958 sigma_dut_print(dut, DUT_MSG_ERROR,
8959 "Failed to set TWT req support %d",
8960 set_val);
8961 send_resp(dut, conn, SIGMA_ERROR,
8962 "ErrorCode,Failed to set TWT_ReqSupport");
8963 return STATUS_SENT;
8964 }
8965 }
8966
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008967 val = get_param(cmd, "MU_EDCA");
8968 if (val && (strcasecmp(val, "Override") == 0)) {
8969 if (sta_set_mu_edca_override(dut, intf, 1)) {
8970 send_resp(dut, conn, SIGMA_ERROR,
8971 "ErrorCode,Failed to set MU EDCA override");
8972 return 0;
8973 }
8974 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008975
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008976 val = get_param(cmd, "OMControl");
8977 if (val) {
8978 int set_val = 1;
8979
8980 if (strcasecmp(val, "Enable") == 0)
8981 set_val = 1;
8982 else if (strcasecmp(val, "Disable") == 0)
8983 set_val = 0;
8984
8985 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
8986 send_resp(dut, conn, SIGMA_ERROR,
8987 "ErrorCode,Failed to set OM ctrl supp");
8988 return 0;
8989 }
8990 }
8991
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008992 val = get_param(cmd, "ADDBAResp_BufSize");
8993 if (val) {
8994 int buf_size;
8995
8996 if (strcasecmp(val, "gt64") == 0)
8997 buf_size = 256;
8998 else
8999 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009000 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009001 sta_set_addba_buf_size(dut, intf, buf_size)) {
9002 send_resp(dut, conn, SIGMA_ERROR,
9003 "ErrorCode,set addbaresp_buff_size failed");
9004 return 0;
9005 }
9006 }
9007
9008 val = get_param(cmd, "ADDBAReq_BufSize");
9009 if (val) {
9010 int buf_size;
9011
9012 if (strcasecmp(val, "gt64") == 0)
9013 buf_size = 256;
9014 else
9015 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009016 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009017 sta_set_addba_buf_size(dut, intf, buf_size)) {
9018 send_resp(dut, conn, SIGMA_ERROR,
9019 "ErrorCode,set addbareq_buff_size failed");
9020 return 0;
9021 }
9022 }
9023
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009024 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9025}
9026
9027
9028static int sta_set_wireless_60g(struct sigma_dut *dut,
9029 struct sigma_conn *conn,
9030 struct sigma_cmd *cmd)
9031{
9032 const char *dev_role = get_param(cmd, "DevRole");
9033
9034 if (!dev_role) {
9035 send_resp(dut, conn, SIGMA_INVALID,
9036 "ErrorCode,DevRole not specified");
9037 return 0;
9038 }
9039
9040 if (strcasecmp(dev_role, "PCP") == 0)
9041 return sta_set_60g_pcp(dut, conn, cmd);
9042 if (strcasecmp(dev_role, "STA") == 0)
9043 return sta_set_60g_sta(dut, conn, cmd);
9044 send_resp(dut, conn, SIGMA_INVALID,
9045 "ErrorCode,DevRole not supported");
9046 return 0;
9047}
9048
9049
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309050static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
9051 struct sigma_cmd *cmd)
9052{
9053 int status;
9054 const char *intf = get_param(cmd, "Interface");
9055 const char *val = get_param(cmd, "DevRole");
9056
9057 if (val && strcasecmp(val, "STA-CFON") == 0) {
9058 status = sta_cfon_set_wireless(dut, conn, cmd);
9059 if (status)
9060 return status;
9061 }
9062 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9063}
9064
9065
Jouni Malinenf7222712019-06-13 01:50:21 +03009066static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
9067 struct sigma_conn *conn,
9068 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009069{
9070 const char *val;
9071
9072 val = get_param(cmd, "Program");
9073 if (val) {
9074 if (strcasecmp(val, "11n") == 0)
9075 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08009076 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009077 return cmd_sta_set_wireless_vht(dut, conn, cmd);
9078 if (strcasecmp(val, "60ghz") == 0)
9079 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309080 if (strcasecmp(val, "OCE") == 0)
9081 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02009082 /* sta_set_wireless in WPS program is only used for 60G */
9083 if (is_60g_sigma_dut(dut))
9084 return sta_set_wireless_60g(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009085 send_resp(dut, conn, SIGMA_ERROR,
9086 "ErrorCode,Program value not supported");
9087 } else {
9088 send_resp(dut, conn, SIGMA_ERROR,
9089 "ErrorCode,Program argument not available");
9090 }
9091
9092 return 0;
9093}
9094
9095
9096static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
9097 int tid)
9098{
9099 char buf[100];
9100 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
9101
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05309102 if (tid < 0 ||
9103 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
9104 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
9105 return;
9106 }
9107
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009108 /*
9109 * Two ways to ensure that addba request with a
9110 * non zero TID could be sent out. EV 117296
9111 */
9112 snprintf(buf, sizeof(buf),
9113 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
9114 tid);
9115 if (system(buf) != 0) {
9116 sigma_dut_print(dut, DUT_MSG_ERROR,
9117 "Ping did not send out");
9118 }
9119
9120 snprintf(buf, sizeof(buf),
9121 "iwconfig %s | grep Access | awk '{print $6}' > %s",
9122 intf, VI_QOS_TMP_FILE);
9123 if (system(buf) != 0)
9124 return;
9125
9126 snprintf(buf, sizeof(buf),
9127 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
9128 intf, VI_QOS_TMP_FILE);
9129 if (system(buf) != 0)
9130 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
9131
9132 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
9133 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
9134 if (system(buf) != 0) {
9135 sigma_dut_print(dut, DUT_MSG_ERROR,
9136 "VI_QOS_TEMP_FILE generation error failed");
9137 }
9138 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9139 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9140 if (system(buf) != 0) {
9141 sigma_dut_print(dut, DUT_MSG_ERROR,
9142 "VI_QOS_FILE generation failed");
9143 }
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), "ethinject %s %s", intf, VI_QOS_FILE);
9153 if (system(buf) != 0) {
9154 }
9155}
9156
9157
9158static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9159 struct sigma_cmd *cmd)
9160{
9161 const char *intf = get_param(cmd, "Interface");
9162 const char *val;
9163 int tid = 0;
9164 char buf[100];
9165
9166 val = get_param(cmd, "TID");
9167 if (val) {
9168 tid = atoi(val);
9169 if (tid)
9170 ath_sta_inject_frame(dut, intf, tid);
9171 }
9172
9173 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009174 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009175
9176 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
9177 if (system(buf) != 0) {
9178 sigma_dut_print(dut, DUT_MSG_ERROR,
9179 "wifitool senddelba failed");
9180 }
9181
9182 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
9183 if (system(buf) != 0) {
9184 sigma_dut_print(dut, DUT_MSG_ERROR,
9185 "wifitool sendaddba failed");
9186 }
9187
9188 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9189
9190 return 1;
9191}
9192
9193
Lior David9981b512017-01-20 13:16:40 +02009194#ifdef __linux__
9195
9196static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
9197 int agg_size)
9198{
9199 char dir[128], buf[128];
9200 FILE *f;
9201 regex_t re;
9202 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03009203 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02009204
9205 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
9206 sigma_dut_print(dut, DUT_MSG_ERROR,
9207 "failed to get wil6210 debugfs dir");
9208 return -1;
9209 }
9210
Jouni Malinen3aa72862019-05-29 23:14:51 +03009211 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
9212 if (res < 0 || res >= sizeof(buf))
9213 return -1;
Lior David9981b512017-01-20 13:16:40 +02009214 f = fopen(buf, "r");
9215 if (!f) {
9216 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009217 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009218 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9219 if (res < 0 || res >= sizeof(buf))
9220 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009221 f = fopen(buf, "r");
9222 if (!f) {
9223 sigma_dut_print(dut, DUT_MSG_ERROR,
9224 "failed to open: %s", buf);
9225 return -1;
9226 }
Lior David9981b512017-01-20 13:16:40 +02009227 }
9228
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009229 /* can be either VRING tx... or RING... */
9230 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009231 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9232 goto out;
9233 }
9234
9235 /* find TX VRING for the mac address */
9236 found = 0;
9237 while (fgets(buf, sizeof(buf), f)) {
9238 if (strcasestr(buf, dest_mac)) {
9239 found = 1;
9240 break;
9241 }
9242 }
9243
9244 if (!found) {
9245 sigma_dut_print(dut, DUT_MSG_ERROR,
9246 "no TX VRING for %s", dest_mac);
9247 goto out;
9248 }
9249
9250 /* extract VRING ID, "VRING tx_<id> = {" */
9251 if (!fgets(buf, sizeof(buf), f)) {
9252 sigma_dut_print(dut, DUT_MSG_ERROR,
9253 "no VRING start line for %s", dest_mac);
9254 goto out;
9255 }
9256
9257 rc = regexec(&re, buf, 2, m, 0);
9258 regfree(&re);
9259 if (rc || m[1].rm_so < 0) {
9260 sigma_dut_print(dut, DUT_MSG_ERROR,
9261 "no VRING TX ID for %s", dest_mac);
9262 goto out;
9263 }
9264 buf[m[1].rm_eo] = 0;
9265 vring_id = atoi(&buf[m[1].rm_so]);
9266
9267 /* send the addba command */
9268 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009269 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9270 if (res < 0 || res >= sizeof(buf))
9271 return -1;
Lior David9981b512017-01-20 13:16:40 +02009272 f = fopen(buf, "w");
9273 if (!f) {
9274 sigma_dut_print(dut, DUT_MSG_ERROR,
9275 "failed to open: %s", buf);
9276 return -1;
9277 }
9278
9279 fprintf(f, "add %d %d\n", vring_id, agg_size);
9280
9281 ret = 0;
9282
9283out:
9284 fclose(f);
9285
9286 return ret;
9287}
9288
9289
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009290int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9291 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009292{
9293 const char *val;
9294 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009295
9296 val = get_param(cmd, "TID");
9297 if (val) {
9298 tid = atoi(val);
9299 if (tid != 0) {
9300 sigma_dut_print(dut, DUT_MSG_ERROR,
9301 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9302 tid);
9303 }
9304 }
9305
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009306 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009307 if (!val) {
9308 sigma_dut_print(dut, DUT_MSG_ERROR,
9309 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009310 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009311 }
9312
Lior David9981b512017-01-20 13:16:40 +02009313 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009314 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009315
9316 return 1;
9317}
9318
Lior David9981b512017-01-20 13:16:40 +02009319#endif /* __linux__ */
9320
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009321
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009322static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9323 struct sigma_cmd *cmd)
9324{
9325#ifdef NL80211_SUPPORT
9326 const char *intf = get_param(cmd, "Interface");
9327 const char *val;
9328 int tid = -1;
9329 int bufsize = 64;
9330 struct nl_msg *msg;
9331 int ret = 0;
9332 struct nlattr *params;
9333 int ifindex;
9334
9335 val = get_param(cmd, "TID");
9336 if (val)
9337 tid = atoi(val);
9338
9339 if (tid == -1) {
9340 send_resp(dut, conn, SIGMA_ERROR,
9341 "ErrorCode,sta_send_addba tid invalid");
9342 return 0;
9343 }
9344
9345 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9346
9347 ifindex = if_nametoindex(intf);
9348 if (ifindex == 0) {
9349 sigma_dut_print(dut, DUT_MSG_ERROR,
9350 "%s: Index for interface %s failed",
9351 __func__, intf);
9352 send_resp(dut, conn, SIGMA_ERROR,
9353 "ErrorCode,sta_send_addba interface invalid");
9354 return 0;
9355 }
9356
9357 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9358 NL80211_CMD_VENDOR)) ||
9359 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9360 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9361 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9362 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9363 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9364 nla_put_u8(msg,
9365 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9366 QCA_WLAN_ADD_BA) ||
9367 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9368 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009369 nla_put_u16(msg,
9370 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9371 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009372 sigma_dut_print(dut, DUT_MSG_ERROR,
9373 "%s: err in adding vendor_cmd and vendor_data",
9374 __func__);
9375 nlmsg_free(msg);
9376 send_resp(dut, conn, SIGMA_ERROR,
9377 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9378 return 0;
9379 }
9380 nla_nest_end(msg, params);
9381
9382 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9383 if (ret) {
9384 sigma_dut_print(dut, DUT_MSG_ERROR,
9385 "%s: err in send_and_recv_msgs, ret=%d",
9386 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309387 if (ret == -EOPNOTSUPP)
9388 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009389 send_resp(dut, conn, SIGMA_ERROR,
9390 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9391 return 0;
9392 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009393#else /* NL80211_SUPPORT */
9394 sigma_dut_print(dut, DUT_MSG_ERROR,
9395 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009396#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309397
9398 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009399}
9400
9401
Jouni Malinenf7222712019-06-13 01:50:21 +03009402static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9403 struct sigma_conn *conn,
9404 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009405{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009406 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009407 case DRIVER_ATHEROS:
9408 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009409 case DRIVER_WCN:
9410 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009411#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009412 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009413 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009414#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009415 default:
9416 /*
9417 * There is no driver specific implementation for other drivers.
9418 * Ignore the command and report COMPLETE since the following
9419 * throughput test operation will end up sending ADDBA anyway.
9420 */
9421 return 1;
9422 }
9423}
9424
9425
9426int inject_eth_frame(int s, const void *data, size_t len,
9427 unsigned short ethtype, char *dst, char *src)
9428{
9429 struct iovec iov[4] = {
9430 {
9431 .iov_base = dst,
9432 .iov_len = ETH_ALEN,
9433 },
9434 {
9435 .iov_base = src,
9436 .iov_len = ETH_ALEN,
9437 },
9438 {
9439 .iov_base = &ethtype,
9440 .iov_len = sizeof(unsigned short),
9441 },
9442 {
9443 .iov_base = (void *) data,
9444 .iov_len = len,
9445 }
9446 };
9447 struct msghdr msg = {
9448 .msg_name = NULL,
9449 .msg_namelen = 0,
9450 .msg_iov = iov,
9451 .msg_iovlen = 4,
9452 .msg_control = NULL,
9453 .msg_controllen = 0,
9454 .msg_flags = 0,
9455 };
9456
9457 return sendmsg(s, &msg, 0);
9458}
9459
9460#if defined(__linux__) || defined(__QNXNTO__)
9461
9462int inject_frame(int s, const void *data, size_t len, int encrypt)
9463{
9464#define IEEE80211_RADIOTAP_F_WEP 0x04
9465#define IEEE80211_RADIOTAP_F_FRAG 0x08
9466 unsigned char rtap_hdr[] = {
9467 0x00, 0x00, /* radiotap version */
9468 0x0e, 0x00, /* radiotap length */
9469 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9470 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9471 0x00, /* padding */
9472 0x00, 0x00, /* RX and TX flags to indicate that */
9473 0x00, 0x00, /* this is the injected frame directly */
9474 };
9475 struct iovec iov[2] = {
9476 {
9477 .iov_base = &rtap_hdr,
9478 .iov_len = sizeof(rtap_hdr),
9479 },
9480 {
9481 .iov_base = (void *) data,
9482 .iov_len = len,
9483 }
9484 };
9485 struct msghdr msg = {
9486 .msg_name = NULL,
9487 .msg_namelen = 0,
9488 .msg_iov = iov,
9489 .msg_iovlen = 2,
9490 .msg_control = NULL,
9491 .msg_controllen = 0,
9492 .msg_flags = 0,
9493 };
9494
9495 if (encrypt)
9496 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9497
9498 return sendmsg(s, &msg, 0);
9499}
9500
9501
9502int open_monitor(const char *ifname)
9503{
9504#ifdef __QNXNTO__
9505 struct sockaddr_dl ll;
9506 int s;
9507
9508 memset(&ll, 0, sizeof(ll));
9509 ll.sdl_family = AF_LINK;
9510 ll.sdl_index = if_nametoindex(ifname);
9511 if (ll.sdl_index == 0) {
9512 perror("if_nametoindex");
9513 return -1;
9514 }
9515 s = socket(PF_INET, SOCK_RAW, 0);
9516#else /* __QNXNTO__ */
9517 struct sockaddr_ll ll;
9518 int s;
9519
9520 memset(&ll, 0, sizeof(ll));
9521 ll.sll_family = AF_PACKET;
9522 ll.sll_ifindex = if_nametoindex(ifname);
9523 if (ll.sll_ifindex == 0) {
9524 perror("if_nametoindex");
9525 return -1;
9526 }
9527 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9528#endif /* __QNXNTO__ */
9529 if (s < 0) {
9530 perror("socket[PF_PACKET,SOCK_RAW]");
9531 return -1;
9532 }
9533
9534 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9535 perror("monitor socket bind");
9536 close(s);
9537 return -1;
9538 }
9539
9540 return s;
9541}
9542
9543
9544static int hex2num(char c)
9545{
9546 if (c >= '0' && c <= '9')
9547 return c - '0';
9548 if (c >= 'a' && c <= 'f')
9549 return c - 'a' + 10;
9550 if (c >= 'A' && c <= 'F')
9551 return c - 'A' + 10;
9552 return -1;
9553}
9554
9555
9556int hwaddr_aton(const char *txt, unsigned char *addr)
9557{
9558 int i;
9559
9560 for (i = 0; i < 6; i++) {
9561 int a, b;
9562
9563 a = hex2num(*txt++);
9564 if (a < 0)
9565 return -1;
9566 b = hex2num(*txt++);
9567 if (b < 0)
9568 return -1;
9569 *addr++ = (a << 4) | b;
9570 if (i < 5 && *txt++ != ':')
9571 return -1;
9572 }
9573
9574 return 0;
9575}
9576
9577#endif /* defined(__linux__) || defined(__QNXNTO__) */
9578
9579enum send_frame_type {
9580 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9581};
9582enum send_frame_protection {
9583 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9584};
9585
9586
9587static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9588 enum send_frame_type frame,
9589 enum send_frame_protection protected,
9590 const char *dest)
9591{
9592#ifdef __linux__
9593 unsigned char buf[1000], *pos;
9594 int s, res;
9595 char bssid[20], addr[20];
9596 char result[32], ssid[100];
9597 size_t ssid_len;
9598
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009599 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009600 sizeof(result)) < 0 ||
9601 strncmp(result, "COMPLETED", 9) != 0) {
9602 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9603 return 0;
9604 }
9605
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009606 if (get_wpa_status(get_station_ifname(dut), "bssid",
9607 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009608 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9609 "current BSSID");
9610 return 0;
9611 }
9612
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009613 if (get_wpa_status(get_station_ifname(dut), "address",
9614 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009615 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9616 "own MAC address");
9617 return 0;
9618 }
9619
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009620 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009621 < 0) {
9622 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9623 "current SSID");
9624 return 0;
9625 }
9626 ssid_len = strlen(ssid);
9627
9628 pos = buf;
9629
9630 /* Frame Control */
9631 switch (frame) {
9632 case DISASSOC:
9633 *pos++ = 0xa0;
9634 break;
9635 case DEAUTH:
9636 *pos++ = 0xc0;
9637 break;
9638 case SAQUERY:
9639 *pos++ = 0xd0;
9640 break;
9641 case AUTH:
9642 *pos++ = 0xb0;
9643 break;
9644 case ASSOCREQ:
9645 *pos++ = 0x00;
9646 break;
9647 case REASSOCREQ:
9648 *pos++ = 0x20;
9649 break;
9650 case DLS_REQ:
9651 *pos++ = 0xd0;
9652 break;
9653 }
9654
9655 if (protected == INCORRECT_KEY)
9656 *pos++ = 0x40; /* Set Protected field to 1 */
9657 else
9658 *pos++ = 0x00;
9659
9660 /* Duration */
9661 *pos++ = 0x00;
9662 *pos++ = 0x00;
9663
9664 /* addr1 = DA (current AP) */
9665 hwaddr_aton(bssid, pos);
9666 pos += 6;
9667 /* addr2 = SA (own address) */
9668 hwaddr_aton(addr, pos);
9669 pos += 6;
9670 /* addr3 = BSSID (current AP) */
9671 hwaddr_aton(bssid, pos);
9672 pos += 6;
9673
9674 /* Seq# (to be filled by driver/mac80211) */
9675 *pos++ = 0x00;
9676 *pos++ = 0x00;
9677
9678 if (protected == INCORRECT_KEY) {
9679 /* CCMP parameters */
9680 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9681 pos += 8;
9682 }
9683
9684 if (protected == INCORRECT_KEY) {
9685 switch (frame) {
9686 case DEAUTH:
9687 /* Reason code (encrypted) */
9688 memcpy(pos, "\xa7\x39", 2);
9689 pos += 2;
9690 break;
9691 case DISASSOC:
9692 /* Reason code (encrypted) */
9693 memcpy(pos, "\xa7\x39", 2);
9694 pos += 2;
9695 break;
9696 case SAQUERY:
9697 /* Category|Action|TransID (encrypted) */
9698 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9699 pos += 4;
9700 break;
9701 default:
9702 return -1;
9703 }
9704
9705 /* CCMP MIC */
9706 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9707 pos += 8;
9708 } else {
9709 switch (frame) {
9710 case DEAUTH:
9711 /* reason code = 8 */
9712 *pos++ = 0x08;
9713 *pos++ = 0x00;
9714 break;
9715 case DISASSOC:
9716 /* reason code = 8 */
9717 *pos++ = 0x08;
9718 *pos++ = 0x00;
9719 break;
9720 case SAQUERY:
9721 /* Category - SA Query */
9722 *pos++ = 0x08;
9723 /* SA query Action - Request */
9724 *pos++ = 0x00;
9725 /* Transaction ID */
9726 *pos++ = 0x12;
9727 *pos++ = 0x34;
9728 break;
9729 case AUTH:
9730 /* Auth Alg (Open) */
9731 *pos++ = 0x00;
9732 *pos++ = 0x00;
9733 /* Seq# */
9734 *pos++ = 0x01;
9735 *pos++ = 0x00;
9736 /* Status code */
9737 *pos++ = 0x00;
9738 *pos++ = 0x00;
9739 break;
9740 case ASSOCREQ:
9741 /* Capability Information */
9742 *pos++ = 0x31;
9743 *pos++ = 0x04;
9744 /* Listen Interval */
9745 *pos++ = 0x0a;
9746 *pos++ = 0x00;
9747 /* SSID */
9748 *pos++ = 0x00;
9749 *pos++ = ssid_len;
9750 memcpy(pos, ssid, ssid_len);
9751 pos += ssid_len;
9752 /* Supported Rates */
9753 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9754 10);
9755 pos += 10;
9756 /* Extended Supported Rates */
9757 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9758 pos += 6;
9759 /* RSN */
9760 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9761 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9762 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9763 pos += 28;
9764 break;
9765 case REASSOCREQ:
9766 /* Capability Information */
9767 *pos++ = 0x31;
9768 *pos++ = 0x04;
9769 /* Listen Interval */
9770 *pos++ = 0x0a;
9771 *pos++ = 0x00;
9772 /* Current AP */
9773 hwaddr_aton(bssid, pos);
9774 pos += 6;
9775 /* SSID */
9776 *pos++ = 0x00;
9777 *pos++ = ssid_len;
9778 memcpy(pos, ssid, ssid_len);
9779 pos += ssid_len;
9780 /* Supported Rates */
9781 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9782 10);
9783 pos += 10;
9784 /* Extended Supported Rates */
9785 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9786 pos += 6;
9787 /* RSN */
9788 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9789 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9790 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9791 pos += 28;
9792 break;
9793 case DLS_REQ:
9794 /* Category - DLS */
9795 *pos++ = 0x02;
9796 /* DLS Action - Request */
9797 *pos++ = 0x00;
9798 /* Destination MACAddress */
9799 if (dest)
9800 hwaddr_aton(dest, pos);
9801 else
9802 memset(pos, 0, 6);
9803 pos += 6;
9804 /* Source MACAddress */
9805 hwaddr_aton(addr, pos);
9806 pos += 6;
9807 /* Capability Information */
9808 *pos++ = 0x10; /* Privacy */
9809 *pos++ = 0x06; /* QoS */
9810 /* DLS Timeout Value */
9811 *pos++ = 0x00;
9812 *pos++ = 0x01;
9813 /* Supported rates */
9814 *pos++ = 0x01;
9815 *pos++ = 0x08;
9816 *pos++ = 0x0c; /* 6 Mbps */
9817 *pos++ = 0x12; /* 9 Mbps */
9818 *pos++ = 0x18; /* 12 Mbps */
9819 *pos++ = 0x24; /* 18 Mbps */
9820 *pos++ = 0x30; /* 24 Mbps */
9821 *pos++ = 0x48; /* 36 Mbps */
9822 *pos++ = 0x60; /* 48 Mbps */
9823 *pos++ = 0x6c; /* 54 Mbps */
9824 /* TODO: Extended Supported Rates */
9825 /* TODO: HT Capabilities */
9826 break;
9827 }
9828 }
9829
9830 s = open_monitor("sigmadut");
9831 if (s < 0) {
9832 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9833 "monitor socket");
9834 return 0;
9835 }
9836
9837 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
9838 if (res < 0) {
9839 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9840 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309841 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009842 return 0;
9843 }
9844 if (res < pos - buf) {
9845 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
9846 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309847 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009848 return 0;
9849 }
9850
9851 close(s);
9852
9853 return 1;
9854#else /* __linux__ */
9855 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
9856 "yet supported");
9857 return 0;
9858#endif /* __linux__ */
9859}
9860
9861
9862static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
9863 struct sigma_conn *conn,
9864 struct sigma_cmd *cmd)
9865{
9866 const char *intf = get_param(cmd, "Interface");
9867 const char *sta, *val;
9868 unsigned char addr[ETH_ALEN];
9869 char buf[100];
9870
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +03009871 if (!intf)
9872 return -1;
9873
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009874 sta = get_param(cmd, "peer");
9875 if (sta == NULL)
9876 sta = get_param(cmd, "station");
9877 if (sta == NULL) {
9878 send_resp(dut, conn, SIGMA_ERROR,
9879 "ErrorCode,Missing peer address");
9880 return 0;
9881 }
9882 if (hwaddr_aton(sta, addr) < 0) {
9883 send_resp(dut, conn, SIGMA_ERROR,
9884 "ErrorCode,Invalid peer address");
9885 return 0;
9886 }
9887
9888 val = get_param(cmd, "type");
9889 if (val == NULL)
9890 return -1;
9891
9892 if (strcasecmp(val, "DISCOVERY") == 0) {
9893 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
9894 if (wpa_command(intf, buf) < 0) {
9895 send_resp(dut, conn, SIGMA_ERROR,
9896 "ErrorCode,Failed to send TDLS discovery");
9897 return 0;
9898 }
9899 return 1;
9900 }
9901
9902 if (strcasecmp(val, "SETUP") == 0) {
9903 int status = 0, timeout = 0;
9904
9905 val = get_param(cmd, "Status");
9906 if (val)
9907 status = atoi(val);
9908
9909 val = get_param(cmd, "Timeout");
9910 if (val)
9911 timeout = atoi(val);
9912
9913 if (status != 0 && status != 37) {
9914 send_resp(dut, conn, SIGMA_ERROR,
9915 "ErrorCode,Unsupported status value");
9916 return 0;
9917 }
9918
9919 if (timeout != 0 && timeout != 301) {
9920 send_resp(dut, conn, SIGMA_ERROR,
9921 "ErrorCode,Unsupported timeout value");
9922 return 0;
9923 }
9924
9925 if (status && timeout) {
9926 send_resp(dut, conn, SIGMA_ERROR,
9927 "ErrorCode,Unsupported timeout+status "
9928 "combination");
9929 return 0;
9930 }
9931
9932 if (status == 37 &&
9933 wpa_command(intf, "SET tdls_testing 0x200")) {
9934 send_resp(dut, conn, SIGMA_ERROR,
9935 "ErrorCode,Failed to enable "
9936 "decline setup response test mode");
9937 return 0;
9938 }
9939
9940 if (timeout == 301) {
9941 int res;
9942 if (dut->no_tpk_expiration)
9943 res = wpa_command(intf,
9944 "SET tdls_testing 0x108");
9945 else
9946 res = wpa_command(intf,
9947 "SET tdls_testing 0x8");
9948 if (res) {
9949 send_resp(dut, conn, SIGMA_ERROR,
9950 "ErrorCode,Failed to set short TPK "
9951 "lifetime");
9952 return 0;
9953 }
9954 }
9955
9956 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
9957 if (wpa_command(intf, buf) < 0) {
9958 send_resp(dut, conn, SIGMA_ERROR,
9959 "ErrorCode,Failed to send TDLS setup");
9960 return 0;
9961 }
9962 return 1;
9963 }
9964
9965 if (strcasecmp(val, "TEARDOWN") == 0) {
9966 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
9967 if (wpa_command(intf, buf) < 0) {
9968 send_resp(dut, conn, SIGMA_ERROR,
9969 "ErrorCode,Failed to send TDLS teardown");
9970 return 0;
9971 }
9972 return 1;
9973 }
9974
9975 send_resp(dut, conn, SIGMA_ERROR,
9976 "ErrorCode,Unsupported TDLS frame");
9977 return 0;
9978}
9979
9980
9981static int sta_ap_known(const char *ifname, const char *bssid)
9982{
9983 char buf[4096];
9984
Jouni Malinendd32f192018-09-15 02:55:19 +03009985 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009986 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
9987 return 0;
9988 if (strncmp(buf, "id=", 3) != 0)
9989 return 0;
9990 return 1;
9991}
9992
9993
9994static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
9995 const char *bssid)
9996{
9997 int res;
9998 struct wpa_ctrl *ctrl;
9999 char buf[256];
10000
10001 if (sta_ap_known(ifname, bssid))
10002 return 0;
10003 sigma_dut_print(dut, DUT_MSG_DEBUG,
10004 "AP not in BSS table - start scan");
10005
10006 ctrl = open_wpa_mon(ifname);
10007 if (ctrl == NULL) {
10008 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10009 "wpa_supplicant monitor connection");
10010 return -1;
10011 }
10012
10013 if (wpa_command(ifname, "SCAN") < 0) {
10014 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
10015 wpa_ctrl_detach(ctrl);
10016 wpa_ctrl_close(ctrl);
10017 return -1;
10018 }
10019
10020 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
10021 buf, sizeof(buf));
10022
10023 wpa_ctrl_detach(ctrl);
10024 wpa_ctrl_close(ctrl);
10025
10026 if (res < 0) {
10027 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
10028 return -1;
10029 }
10030
10031 if (sta_ap_known(ifname, bssid))
10032 return 0;
10033 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
10034 return -1;
10035}
10036
10037
10038static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
10039 struct sigma_conn *conn,
10040 struct sigma_cmd *cmd,
10041 const char *intf)
10042{
10043 char buf[200];
10044
10045 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
10046 if (system(buf) != 0) {
10047 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
10048 "ndsend");
10049 return 0;
10050 }
10051
10052 return 1;
10053}
10054
10055
10056static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
10057 struct sigma_conn *conn,
10058 struct sigma_cmd *cmd,
10059 const char *intf)
10060{
10061 char buf[200];
10062 const char *ip = get_param(cmd, "SenderIP");
10063
Peng Xu26b356d2017-10-04 17:58:16 -070010064 if (!ip)
10065 return 0;
10066
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010067 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
10068 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10069 if (system(buf) == 0) {
10070 sigma_dut_print(dut, DUT_MSG_INFO,
10071 "Neighbor Solicitation got a response "
10072 "for %s@%s", ip, intf);
10073 }
10074
10075 return 1;
10076}
10077
10078
10079static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
10080 struct sigma_conn *conn,
10081 struct sigma_cmd *cmd,
10082 const char *ifname)
10083{
10084 char buf[200];
10085 const char *ip = get_param(cmd, "SenderIP");
10086
10087 if (ip == NULL) {
10088 send_resp(dut, conn, SIGMA_ERROR,
10089 "ErrorCode,Missing SenderIP parameter");
10090 return 0;
10091 }
10092 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
10093 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10094 if (system(buf) != 0) {
10095 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
10096 "for %s@%s", ip, ifname);
10097 }
10098
10099 return 1;
10100}
10101
10102
10103static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
10104 struct sigma_conn *conn,
10105 struct sigma_cmd *cmd,
10106 const char *ifname)
10107{
10108 char buf[200];
10109 char ip[16];
10110 int s;
Peng Xub3756882017-10-04 14:39:09 -070010111 struct ifreq ifr;
10112 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010113
10114 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070010115 if (s < 0) {
10116 perror("socket");
10117 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010118 }
10119
Peng Xub3756882017-10-04 14:39:09 -070010120 memset(&ifr, 0, sizeof(ifr));
10121 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
10122 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
10123 sigma_dut_print(dut, DUT_MSG_INFO,
10124 "Failed to get %s IP address: %s",
10125 ifname, strerror(errno));
10126 close(s);
10127 return -1;
10128 }
10129 close(s);
10130
10131 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
10132 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
10133
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010134 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
10135 ip);
10136 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10137 if (system(buf) != 0) {
10138 }
10139
10140 return 1;
10141}
10142
10143
10144static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
10145 struct sigma_conn *conn,
10146 struct sigma_cmd *cmd,
10147 const char *ifname)
10148{
10149 char buf[200], addr[20];
10150 char dst[ETH_ALEN], src[ETH_ALEN];
10151 short ethtype = htons(ETH_P_ARP);
10152 char *pos;
10153 int s, res;
10154 const char *val;
10155 struct sockaddr_in taddr;
10156
10157 val = get_param(cmd, "dest");
10158 if (val)
10159 hwaddr_aton(val, (unsigned char *) dst);
10160
10161 val = get_param(cmd, "DestIP");
10162 if (val)
10163 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070010164 else
10165 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010166
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010167 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010168 sizeof(addr)) < 0)
10169 return -2;
10170 hwaddr_aton(addr, (unsigned char *) src);
10171
10172 pos = buf;
10173 *pos++ = 0x00;
10174 *pos++ = 0x01;
10175 *pos++ = 0x08;
10176 *pos++ = 0x00;
10177 *pos++ = 0x06;
10178 *pos++ = 0x04;
10179 *pos++ = 0x00;
10180 *pos++ = 0x02;
10181 memcpy(pos, src, ETH_ALEN);
10182 pos += ETH_ALEN;
10183 memcpy(pos, &taddr.sin_addr, 4);
10184 pos += 4;
10185 memcpy(pos, dst, ETH_ALEN);
10186 pos += ETH_ALEN;
10187 memcpy(pos, &taddr.sin_addr, 4);
10188 pos += 4;
10189
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010190 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010191 if (s < 0) {
10192 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
10193 "monitor socket");
10194 return 0;
10195 }
10196
10197 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
10198 if (res < 0) {
10199 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
10200 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053010201 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010202 return 0;
10203 }
10204
10205 close(s);
10206
10207 return 1;
10208}
10209
10210
10211static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
10212 struct sigma_conn *conn,
10213 struct sigma_cmd *cmd,
10214 const char *intf, const char *dest)
10215{
10216 char buf[100];
10217
10218 if (if_nametoindex("sigmadut") == 0) {
10219 snprintf(buf, sizeof(buf),
10220 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010221 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010222 if (system(buf) != 0 ||
10223 if_nametoindex("sigmadut") == 0) {
10224 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10225 "monitor interface with '%s'", buf);
10226 return -2;
10227 }
10228 }
10229
10230 if (system("ifconfig sigmadut up") != 0) {
10231 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10232 "monitor interface up");
10233 return -2;
10234 }
10235
10236 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
10237}
10238
10239
10240static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10241 struct sigma_conn *conn,
10242 struct sigma_cmd *cmd)
10243{
10244 const char *intf = get_param(cmd, "Interface");
10245 const char *dest = get_param(cmd, "Dest");
10246 const char *type = get_param(cmd, "FrameName");
10247 const char *val;
10248 char buf[200], *pos, *end;
10249 int count, count2;
10250
10251 if (type == NULL)
10252 type = get_param(cmd, "Type");
10253
10254 if (intf == NULL || dest == NULL || type == NULL)
10255 return -1;
10256
10257 if (strcasecmp(type, "NeighAdv") == 0)
10258 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10259
10260 if (strcasecmp(type, "NeighSolicitReq") == 0)
10261 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10262
10263 if (strcasecmp(type, "ARPProbe") == 0)
10264 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10265
10266 if (strcasecmp(type, "ARPAnnounce") == 0)
10267 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10268
10269 if (strcasecmp(type, "ARPReply") == 0)
10270 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10271
10272 if (strcasecmp(type, "DLS-request") == 0 ||
10273 strcasecmp(type, "DLSrequest") == 0)
10274 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10275 dest);
10276
10277 if (strcasecmp(type, "ANQPQuery") != 0 &&
10278 strcasecmp(type, "Query") != 0) {
10279 send_resp(dut, conn, SIGMA_ERROR,
10280 "ErrorCode,Unsupported HS 2.0 send frame type");
10281 return 0;
10282 }
10283
10284 if (sta_scan_ap(dut, intf, dest) < 0) {
10285 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10286 "the requested AP");
10287 return 0;
10288 }
10289
10290 pos = buf;
10291 end = buf + sizeof(buf);
10292 count = 0;
10293 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10294
10295 val = get_param(cmd, "ANQP_CAP_LIST");
10296 if (val && atoi(val)) {
10297 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10298 count++;
10299 }
10300
10301 val = get_param(cmd, "VENUE_NAME");
10302 if (val && atoi(val)) {
10303 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10304 count++;
10305 }
10306
10307 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10308 if (val && atoi(val)) {
10309 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10310 count++;
10311 }
10312
10313 val = get_param(cmd, "ROAMING_CONS");
10314 if (val && atoi(val)) {
10315 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10316 count++;
10317 }
10318
10319 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10320 if (val && atoi(val)) {
10321 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10322 count++;
10323 }
10324
10325 val = get_param(cmd, "NAI_REALM_LIST");
10326 if (val && atoi(val)) {
10327 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10328 count++;
10329 }
10330
10331 val = get_param(cmd, "3GPP_INFO");
10332 if (val && atoi(val)) {
10333 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10334 count++;
10335 }
10336
10337 val = get_param(cmd, "DOMAIN_LIST");
10338 if (val && atoi(val)) {
10339 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10340 count++;
10341 }
10342
Jouni Malinen34cf9532018-04-29 19:26:33 +030010343 val = get_param(cmd, "Venue_URL");
10344 if (val && atoi(val)) {
10345 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10346 count++;
10347 }
10348
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010349 val = get_param(cmd, "Advice_Of_Charge");
10350 if (val && atoi(val)) {
10351 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10352 count++;
10353 }
10354
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010355 if (count && wpa_command(intf, buf)) {
10356 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10357 return 0;
10358 }
10359
10360 pos = buf;
10361 end = buf + sizeof(buf);
10362 count2 = 0;
10363 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
10364
10365 val = get_param(cmd, "HS_CAP_LIST");
10366 if (val && atoi(val)) {
10367 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
10368 count2++;
10369 }
10370
10371 val = get_param(cmd, "OPER_NAME");
10372 if (val && atoi(val)) {
10373 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
10374 count2++;
10375 }
10376
10377 val = get_param(cmd, "WAN_METRICS");
10378 if (!val)
10379 val = get_param(cmd, "WAN_MAT");
10380 if (!val)
10381 val = get_param(cmd, "WAN_MET");
10382 if (val && atoi(val)) {
10383 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10384 count2++;
10385 }
10386
10387 val = get_param(cmd, "CONNECTION_CAPABILITY");
10388 if (val && atoi(val)) {
10389 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10390 count2++;
10391 }
10392
10393 val = get_param(cmd, "OP_CLASS");
10394 if (val && atoi(val)) {
10395 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10396 count2++;
10397 }
10398
10399 val = get_param(cmd, "OSU_PROVIDER_LIST");
10400 if (val && atoi(val)) {
10401 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10402 count2++;
10403 }
10404
Jouni Malinenf67afec2018-04-29 19:24:58 +030010405 val = get_param(cmd, "OPER_ICON_METADATA");
10406 if (!val)
10407 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10408 if (val && atoi(val)) {
10409 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10410 count2++;
10411 }
10412
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010413 if (count && count2) {
10414 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10415 "second query");
10416 sleep(1);
10417 }
10418
10419 if (count2 && wpa_command(intf, buf)) {
10420 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10421 "failed");
10422 return 0;
10423 }
10424
10425 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10426 if (val) {
10427 if (count || count2) {
10428 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10429 "sending out second query");
10430 sleep(1);
10431 }
10432
10433 if (strcmp(val, "1") == 0)
10434 val = "mail.example.com";
10435 snprintf(buf, end - pos,
10436 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10437 dest, val);
10438 if (wpa_command(intf, buf)) {
10439 send_resp(dut, conn, SIGMA_ERROR,
10440 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10441 "failed");
10442 return 0;
10443 }
10444 }
10445
10446 val = get_param(cmd, "ICON_REQUEST");
10447 if (val) {
10448 if (count || count2) {
10449 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10450 "sending out second query");
10451 sleep(1);
10452 }
10453
10454 snprintf(buf, end - pos,
10455 "HS20_ICON_REQUEST %s %s", dest, val);
10456 if (wpa_command(intf, buf)) {
10457 send_resp(dut, conn, SIGMA_ERROR,
10458 "ErrorCode,HS20_ICON_REQUEST failed");
10459 return 0;
10460 }
10461 }
10462
10463 return 1;
10464}
10465
10466
10467static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10468 struct sigma_conn *conn,
10469 struct sigma_cmd *cmd)
10470{
10471 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010472 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010473 int chwidth, nss;
10474
10475 val = get_param(cmd, "framename");
10476 if (!val)
10477 return -1;
10478 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10479
10480 /* Command sequence to generate Op mode notification */
10481 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010482 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010483
10484 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010485 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010486
10487 /* Extract Channel width */
10488 val = get_param(cmd, "Channel_width");
10489 if (val) {
10490 switch (atoi(val)) {
10491 case 20:
10492 chwidth = 0;
10493 break;
10494 case 40:
10495 chwidth = 1;
10496 break;
10497 case 80:
10498 chwidth = 2;
10499 break;
10500 case 160:
10501 chwidth = 3;
10502 break;
10503 default:
10504 chwidth = 2;
10505 break;
10506 }
10507
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010508 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010509 }
10510
10511 /* Extract NSS */
10512 val = get_param(cmd, "NSS");
10513 if (val) {
10514 switch (atoi(val)) {
10515 case 1:
10516 nss = 1;
10517 break;
10518 case 2:
10519 nss = 3;
10520 break;
10521 case 3:
10522 nss = 7;
10523 break;
10524 default:
10525 /* We do not support NSS > 3 */
10526 nss = 3;
10527 break;
10528 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010529 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010530 }
10531
10532 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010533 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010534 }
10535
10536 return 1;
10537}
10538
10539
10540static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
10541 struct sigma_conn *conn,
10542 struct sigma_cmd *cmd)
10543{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010544 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010545 case DRIVER_ATHEROS:
10546 return ath_sta_send_frame_vht(dut, conn, cmd);
10547 default:
10548 send_resp(dut, conn, SIGMA_ERROR,
10549 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
10550 return 0;
10551 }
10552}
10553
10554
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010555static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
10556 struct sigma_cmd *cmd)
10557{
10558 const char *val;
10559 const char *intf = get_param(cmd, "Interface");
10560
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010561 if (!intf)
10562 return -1;
10563
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010564 val = get_param(cmd, "framename");
10565 if (!val)
10566 return -1;
10567 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10568
10569 /* Command sequence to generate Op mode notification */
10570 if (val && strcasecmp(val, "action") == 0) {
10571 val = get_param(cmd, "PPDUTxType");
10572 if (val && strcasecmp(val, "TB") == 0) {
10573 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
10574 sigma_dut_print(dut, DUT_MSG_ERROR,
10575 "failed to send TB PPDU Tx cfg");
10576 send_resp(dut, conn, SIGMA_ERROR,
10577 "ErrorCode,set TB PPDU Tx cfg failed");
10578 return 0;
10579 }
10580 return 1;
10581 }
10582
10583 sigma_dut_print(dut, DUT_MSG_ERROR,
10584 "Action Tx type is not defined");
10585 }
10586
10587 return 1;
10588}
10589
10590
10591static int cmd_sta_send_frame_he(struct sigma_dut *dut,
10592 struct sigma_conn *conn,
10593 struct sigma_cmd *cmd)
10594{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010595 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010596 case DRIVER_WCN:
10597 return wcn_sta_send_frame_he(dut, conn, cmd);
10598 default:
10599 send_resp(dut, conn, SIGMA_ERROR,
10600 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
10601 return 0;
10602 }
10603}
10604
10605
Lior David0fe101e2017-03-09 16:09:50 +020010606#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010607
10608static int
10609wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
10610 const char *frame_name, const char *dest_mac)
10611{
10612 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
10613 const char *ssid = get_param(cmd, "ssid");
10614 const char *countstr = get_param(cmd, "count");
10615 const char *channelstr = get_param(cmd, "channel");
10616 const char *group_id = get_param(cmd, "groupid");
10617 const char *client_id = get_param(cmd, "clientmac");
10618 int count, channel, freq, i;
10619 const char *fname;
10620 char frame[1024], src_mac[20], group_id_attr[25],
10621 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
10622 const char *group_ssid;
10623 const int group_ssid_prefix_len = 9;
10624 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
10625 size_t framelen = sizeof(frame);
10626 struct template_frame_tag tags[2];
10627 size_t tags_total = ARRAY_SIZE(tags);
10628 int tag_index, len, dst_len;
10629
10630 if (!countstr || !channelstr) {
10631 sigma_dut_print(dut, DUT_MSG_ERROR,
10632 "Missing argument: count, channel");
10633 return -1;
10634 }
10635 if (isprobereq && !ssid) {
10636 sigma_dut_print(dut, DUT_MSG_ERROR,
10637 "Missing argument: ssid");
10638 return -1;
10639 }
10640 if (!isprobereq && (!group_id || !client_id)) {
10641 sigma_dut_print(dut, DUT_MSG_ERROR,
10642 "Missing argument: group_id, client_id");
10643 return -1;
10644 }
10645
10646 count = atoi(countstr);
10647 channel = atoi(channelstr);
10648 freq = channel_to_freq(dut, channel);
10649
10650 if (!freq) {
10651 sigma_dut_print(dut, DUT_MSG_ERROR,
10652 "invalid channel: %s", channelstr);
10653 return -1;
10654 }
10655
10656 if (isprobereq) {
10657 if (strcasecmp(ssid, "wildcard") == 0) {
10658 fname = "probe_req_wildcard.txt";
10659 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
10660 fname = "probe_req_P2P_Wildcard.txt";
10661 } else {
10662 sigma_dut_print(dut, DUT_MSG_ERROR,
10663 "invalid probe request type");
10664 return -1;
10665 }
10666 } else {
10667 fname = "P2P_device_discovery_req.txt";
10668 }
10669
10670 if (parse_template_frame_file(dut, fname, frame, &framelen,
10671 tags, &tags_total)) {
10672 sigma_dut_print(dut, DUT_MSG_ERROR,
10673 "invalid frame template: %s", fname);
10674 return -1;
10675 }
10676
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010677 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010678 src_mac, sizeof(src_mac)) < 0 ||
10679 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
10680 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
10681 return -1;
10682 /* Use wildcard BSSID, since we are in PBSS */
10683 memset(&hdr->addr3, 0xFF, ETH_ALEN);
10684
10685 if (!isprobereq) {
10686 tag_index = find_template_frame_tag(tags, tags_total, 1);
10687 if (tag_index < 0) {
10688 sigma_dut_print(dut, DUT_MSG_ERROR,
10689 "can't find device id attribute");
10690 return -1;
10691 }
10692 if (parse_mac_address(dut, client_id,
10693 (unsigned char *) client_mac)) {
10694 sigma_dut_print(dut, DUT_MSG_ERROR,
10695 "invalid client_id: %s", client_id);
10696 return -1;
10697 }
10698 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10699 framelen - tags[tag_index].offset,
10700 IEEE80211_P2P_ATTR_DEVICE_ID,
10701 client_mac, ETH_ALEN)) {
10702 sigma_dut_print(dut, DUT_MSG_ERROR,
10703 "fail to replace device id attribute");
10704 return -1;
10705 }
10706
10707 /*
10708 * group_id arg contains device MAC address followed by
10709 * space and SSID (DIRECT-somessid).
10710 * group id attribute contains device address (6 bytes)
10711 * followed by SSID prefix DIRECT-XX (9 bytes)
10712 */
10713 if (strlen(group_id) < sizeof(device_macstr)) {
10714 sigma_dut_print(dut, DUT_MSG_ERROR,
10715 "group_id arg too short");
10716 return -1;
10717 }
10718 memcpy(device_macstr, group_id, sizeof(device_macstr));
10719 device_macstr[sizeof(device_macstr) - 1] = '\0';
10720 if (parse_mac_address(dut, device_macstr,
10721 (unsigned char *) group_id_attr)) {
10722 sigma_dut_print(dut, DUT_MSG_ERROR,
10723 "fail to parse device address from group_id");
10724 return -1;
10725 }
10726 group_ssid = strchr(group_id, ' ');
10727 if (!group_ssid) {
10728 sigma_dut_print(dut, DUT_MSG_ERROR,
10729 "invalid group_id arg, no ssid");
10730 return -1;
10731 }
10732 group_ssid++;
10733 len = strlen(group_ssid);
10734 if (len < group_ssid_prefix_len) {
10735 sigma_dut_print(dut, DUT_MSG_ERROR,
10736 "group_id SSID too short");
10737 return -1;
10738 }
10739 dst_len = sizeof(group_id_attr) - ETH_ALEN;
10740 if (len > dst_len) {
10741 sigma_dut_print(dut, DUT_MSG_ERROR,
10742 "group_id SSID (%s) too long",
10743 group_ssid);
10744 return -1;
10745 }
10746
10747 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
10748 tag_index = find_template_frame_tag(tags, tags_total, 2);
10749 if (tag_index < 0) {
10750 sigma_dut_print(dut, DUT_MSG_ERROR,
10751 "can't find group id attribute");
10752 return -1;
10753 }
10754 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10755 framelen - tags[tag_index].offset,
10756 IEEE80211_P2P_ATTR_GROUP_ID,
10757 group_id_attr,
10758 sizeof(group_id_attr))) {
10759 sigma_dut_print(dut, DUT_MSG_ERROR,
10760 "fail to replace group id attribute");
10761 return -1;
10762 }
10763 }
10764
10765 for (i = 0; i < count; i++) {
10766 if (wil6210_transmit_frame(dut, freq,
10767 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
10768 frame, framelen)) {
10769 sigma_dut_print(dut, DUT_MSG_ERROR,
10770 "fail to transmit probe request frame");
10771 return -1;
10772 }
10773 }
10774
10775 return 0;
10776}
10777
10778
Lior David0fe101e2017-03-09 16:09:50 +020010779int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10780 struct sigma_cmd *cmd)
10781{
10782 const char *frame_name = get_param(cmd, "framename");
10783 const char *mac = get_param(cmd, "dest_mac");
10784
10785 if (!frame_name || !mac) {
10786 sigma_dut_print(dut, DUT_MSG_ERROR,
10787 "framename and dest_mac must be provided");
10788 return -1;
10789 }
10790
10791 if (strcasecmp(frame_name, "brp") == 0) {
10792 const char *l_rx = get_param(cmd, "L-RX");
10793 int l_rx_i;
10794
10795 if (!l_rx) {
10796 sigma_dut_print(dut, DUT_MSG_ERROR,
10797 "L-RX must be provided");
10798 return -1;
10799 }
10800 l_rx_i = atoi(l_rx);
10801
10802 sigma_dut_print(dut, DUT_MSG_INFO,
10803 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
10804 mac, l_rx);
10805 if (l_rx_i != 16) {
10806 sigma_dut_print(dut, DUT_MSG_ERROR,
10807 "unsupported L-RX: %s", l_rx);
10808 return -1;
10809 }
10810
10811 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
10812 return -1;
10813 } else if (strcasecmp(frame_name, "ssw") == 0) {
10814 sigma_dut_print(dut, DUT_MSG_INFO,
10815 "dev_send_frame: SLS, dest_mac %s", mac);
10816 if (wil6210_send_sls(dut, mac))
10817 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010818 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
10819 (strcasecmp(frame_name, "devdiscreq") == 0)) {
10820 sigma_dut_print(dut, DUT_MSG_INFO,
10821 "dev_send_frame: %s, dest_mac %s", frame_name,
10822 mac);
10823 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
10824 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020010825 } else {
10826 sigma_dut_print(dut, DUT_MSG_ERROR,
10827 "unsupported frame type: %s", frame_name);
10828 return -1;
10829 }
10830
10831 return 1;
10832}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010833
Lior David0fe101e2017-03-09 16:09:50 +020010834#endif /* __linux__ */
10835
10836
10837static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
10838 struct sigma_conn *conn,
10839 struct sigma_cmd *cmd)
10840{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010841 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020010842#ifdef __linux__
10843 case DRIVER_WIL6210:
10844 return wil6210_send_frame_60g(dut, conn, cmd);
10845#endif /* __linux__ */
10846 default:
10847 send_resp(dut, conn, SIGMA_ERROR,
10848 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
10849 return 0;
10850 }
10851}
10852
10853
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010854static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
10855 const char *intf, struct sigma_cmd *cmd)
10856{
10857 const char *val, *addr;
10858 char buf[100];
10859
10860 addr = get_param(cmd, "DestMac");
10861 if (!addr) {
10862 send_resp(dut, conn, SIGMA_INVALID,
10863 "ErrorCode,AP MAC address is missing");
10864 return 0;
10865 }
10866
10867 val = get_param(cmd, "ANQPQuery_ID");
10868 if (!val) {
10869 send_resp(dut, conn, SIGMA_INVALID,
10870 "ErrorCode,Missing ANQPQuery_ID");
10871 return 0;
10872 }
10873
10874 if (strcasecmp(val, "NeighborReportReq") == 0) {
10875 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
10876 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
10877 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
10878 } else {
10879 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
10880 val);
10881 send_resp(dut, conn, SIGMA_INVALID,
10882 "ErrorCode,Invalid ANQPQuery_ID");
10883 return 0;
10884 }
10885
Ashwini Patild174f2c2017-04-13 16:49:46 +053010886 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
10887 * (Address3 = Wildcard BSSID when sent to not-associated AP;
10888 * if associated, AP BSSID).
10889 */
10890 if (wpa_command(intf, "SET gas_address3 1") < 0) {
10891 send_resp(dut, conn, SIGMA_ERROR,
10892 "ErrorCode,Failed to set gas_address3");
10893 return 0;
10894 }
10895
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010896 if (wpa_command(intf, buf) < 0) {
10897 send_resp(dut, conn, SIGMA_ERROR,
10898 "ErrorCode,Failed to send ANQP query");
10899 return 0;
10900 }
10901
10902 return 1;
10903}
10904
10905
10906static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
10907 struct sigma_conn *conn,
10908 const char *intf,
10909 struct sigma_cmd *cmd)
10910{
10911 const char *val = get_param(cmd, "FrameName");
10912
10913 if (val && strcasecmp(val, "ANQPQuery") == 0)
10914 return mbo_send_anqp_query(dut, conn, intf, cmd);
10915
10916 return 2;
10917}
10918
10919
Jouni Malinenf7222712019-06-13 01:50:21 +030010920enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
10921 struct sigma_conn *conn,
10922 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010923{
10924 const char *intf = get_param(cmd, "Interface");
10925 const char *val;
10926 enum send_frame_type frame;
10927 enum send_frame_protection protected;
10928 char buf[100];
10929 unsigned char addr[ETH_ALEN];
10930 int res;
10931
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010932 if (!intf)
10933 return -1;
10934
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010935 val = get_param(cmd, "program");
10936 if (val == NULL)
10937 val = get_param(cmd, "frame");
10938 if (val && strcasecmp(val, "TDLS") == 0)
10939 return cmd_sta_send_frame_tdls(dut, conn, cmd);
10940 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030010941 strcasecmp(val, "HS2-R2") == 0 ||
10942 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010943 return cmd_sta_send_frame_hs2(dut, conn, cmd);
10944 if (val && strcasecmp(val, "VHT") == 0)
10945 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010946 if (val && strcasecmp(val, "HE") == 0)
10947 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070010948 if (val && strcasecmp(val, "LOC") == 0)
10949 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020010950 if (val && strcasecmp(val, "60GHz") == 0)
10951 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010952 if (val && strcasecmp(val, "MBO") == 0) {
10953 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
10954 if (res != 2)
10955 return res;
10956 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010957
10958 val = get_param(cmd, "TD_DISC");
10959 if (val) {
10960 if (hwaddr_aton(val, addr) < 0)
10961 return -1;
10962 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
10963 if (wpa_command(intf, buf) < 0) {
10964 send_resp(dut, conn, SIGMA_ERROR,
10965 "ErrorCode,Failed to send TDLS discovery");
10966 return 0;
10967 }
10968 return 1;
10969 }
10970
10971 val = get_param(cmd, "TD_Setup");
10972 if (val) {
10973 if (hwaddr_aton(val, addr) < 0)
10974 return -1;
10975 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
10976 if (wpa_command(intf, buf) < 0) {
10977 send_resp(dut, conn, SIGMA_ERROR,
10978 "ErrorCode,Failed to start TDLS setup");
10979 return 0;
10980 }
10981 return 1;
10982 }
10983
10984 val = get_param(cmd, "TD_TearDown");
10985 if (val) {
10986 if (hwaddr_aton(val, addr) < 0)
10987 return -1;
10988 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
10989 if (wpa_command(intf, buf) < 0) {
10990 send_resp(dut, conn, SIGMA_ERROR,
10991 "ErrorCode,Failed to tear down TDLS link");
10992 return 0;
10993 }
10994 return 1;
10995 }
10996
10997 val = get_param(cmd, "TD_ChannelSwitch");
10998 if (val) {
10999 /* TODO */
11000 send_resp(dut, conn, SIGMA_ERROR,
11001 "ErrorCode,TD_ChannelSwitch not yet supported");
11002 return 0;
11003 }
11004
11005 val = get_param(cmd, "TD_NF");
11006 if (val) {
11007 /* TODO */
11008 send_resp(dut, conn, SIGMA_ERROR,
11009 "ErrorCode,TD_NF not yet supported");
11010 return 0;
11011 }
11012
11013 val = get_param(cmd, "PMFFrameType");
11014 if (val == NULL)
11015 val = get_param(cmd, "FrameName");
11016 if (val == NULL)
11017 val = get_param(cmd, "Type");
11018 if (val == NULL)
11019 return -1;
11020 if (strcasecmp(val, "disassoc") == 0)
11021 frame = DISASSOC;
11022 else if (strcasecmp(val, "deauth") == 0)
11023 frame = DEAUTH;
11024 else if (strcasecmp(val, "saquery") == 0)
11025 frame = SAQUERY;
11026 else if (strcasecmp(val, "auth") == 0)
11027 frame = AUTH;
11028 else if (strcasecmp(val, "assocreq") == 0)
11029 frame = ASSOCREQ;
11030 else if (strcasecmp(val, "reassocreq") == 0)
11031 frame = REASSOCREQ;
11032 else if (strcasecmp(val, "neigreq") == 0) {
11033 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
11034
11035 val = get_param(cmd, "ssid");
11036 if (val == NULL)
11037 return -1;
11038
11039 res = send_neighbor_request(dut, intf, val);
11040 if (res) {
11041 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11042 "Failed to send neighbor report request");
11043 return 0;
11044 }
11045
11046 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053011047 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
11048 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011049 sigma_dut_print(dut, DUT_MSG_DEBUG,
11050 "Got Transition Management Query");
11051
Ashwini Patil5acd7382017-04-13 15:55:04 +053011052 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011053 if (res) {
11054 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11055 "Failed to send Transition Management Query");
11056 return 0;
11057 }
11058
11059 return 1;
11060 } else {
11061 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11062 "PMFFrameType");
11063 return 0;
11064 }
11065
11066 val = get_param(cmd, "PMFProtected");
11067 if (val == NULL)
11068 val = get_param(cmd, "Protected");
11069 if (val == NULL)
11070 return -1;
11071 if (strcasecmp(val, "Correct-key") == 0 ||
11072 strcasecmp(val, "CorrectKey") == 0)
11073 protected = CORRECT_KEY;
11074 else if (strcasecmp(val, "IncorrectKey") == 0)
11075 protected = INCORRECT_KEY;
11076 else if (strcasecmp(val, "Unprotected") == 0)
11077 protected = UNPROTECTED;
11078 else {
11079 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11080 "PMFProtected");
11081 return 0;
11082 }
11083
11084 if (protected != UNPROTECTED &&
11085 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
11086 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
11087 "PMFProtected for auth/assocreq/reassocreq");
11088 return 0;
11089 }
11090
11091 if (if_nametoindex("sigmadut") == 0) {
11092 snprintf(buf, sizeof(buf),
11093 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011094 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011095 if (system(buf) != 0 ||
11096 if_nametoindex("sigmadut") == 0) {
11097 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11098 "monitor interface with '%s'", buf);
11099 return -2;
11100 }
11101 }
11102
11103 if (system("ifconfig sigmadut up") != 0) {
11104 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11105 "monitor interface up");
11106 return -2;
11107 }
11108
11109 return sta_inject_frame(dut, conn, frame, protected, NULL);
11110}
11111
11112
11113static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
11114 struct sigma_conn *conn,
11115 struct sigma_cmd *cmd,
11116 const char *ifname)
11117{
11118 char buf[200];
11119 const char *val;
11120
11121 val = get_param(cmd, "ClearARP");
11122 if (val && atoi(val) == 1) {
11123 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
11124 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11125 if (system(buf) != 0) {
11126 send_resp(dut, conn, SIGMA_ERROR,
11127 "errorCode,Failed to clear ARP cache");
11128 return 0;
11129 }
11130 }
11131
11132 return 1;
11133}
11134
11135
11136int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
11137 struct sigma_cmd *cmd)
11138{
11139 const char *intf = get_param(cmd, "Interface");
11140 const char *val;
11141
11142 if (intf == NULL)
11143 return -1;
11144
11145 val = get_param(cmd, "program");
11146 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011147 strcasecmp(val, "HS2-R2") == 0 ||
11148 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011149 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
11150
11151 return -1;
11152}
11153
11154
Jouni Malinenf7222712019-06-13 01:50:21 +030011155static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
11156 struct sigma_conn *conn,
11157 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011158{
11159 const char *intf = get_param(cmd, "Interface");
11160 const char *mac = get_param(cmd, "MAC");
11161
11162 if (intf == NULL || mac == NULL)
11163 return -1;
11164
11165 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
11166 "interface %s to %s", intf, mac);
11167
11168 if (dut->set_macaddr) {
11169 char buf[128];
11170 int res;
11171 if (strcasecmp(mac, "default") == 0) {
11172 res = snprintf(buf, sizeof(buf), "%s",
11173 dut->set_macaddr);
11174 dut->tmp_mac_addr = 0;
11175 } else {
11176 res = snprintf(buf, sizeof(buf), "%s %s",
11177 dut->set_macaddr, mac);
11178 dut->tmp_mac_addr = 1;
11179 }
11180 if (res < 0 || res >= (int) sizeof(buf))
11181 return -1;
11182 if (system(buf) != 0) {
11183 send_resp(dut, conn, SIGMA_ERROR,
11184 "errorCode,Failed to set MAC "
11185 "address");
11186 return 0;
11187 }
11188 return 1;
11189 }
11190
11191 if (strcasecmp(mac, "default") == 0)
11192 return 1;
11193
11194 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11195 "command");
11196 return 0;
11197}
11198
11199
11200static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
11201 struct sigma_conn *conn, const char *intf,
11202 int val)
11203{
11204 char buf[200];
11205 int res;
11206
11207 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
11208 intf, val);
11209 if (res < 0 || res >= (int) sizeof(buf))
11210 return -1;
11211 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11212 if (system(buf) != 0) {
11213 send_resp(dut, conn, SIGMA_ERROR,
11214 "errorCode,Failed to configure offchannel mode");
11215 return 0;
11216 }
11217
11218 return 1;
11219}
11220
11221
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011222static int off_chan_val(enum sec_ch_offset off)
11223{
11224 switch (off) {
11225 case SEC_CH_NO:
11226 return 0;
11227 case SEC_CH_40ABOVE:
11228 return 40;
11229 case SEC_CH_40BELOW:
11230 return -40;
11231 }
11232
11233 return 0;
11234}
11235
11236
11237static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
11238 const char *intf, int off_ch_num,
11239 enum sec_ch_offset sec)
11240{
11241 char buf[200];
11242 int res;
11243
11244 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
11245 intf, off_ch_num);
11246 if (res < 0 || res >= (int) sizeof(buf))
11247 return -1;
11248 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11249 if (system(buf) != 0) {
11250 send_resp(dut, conn, SIGMA_ERROR,
11251 "errorCode,Failed to set offchan");
11252 return 0;
11253 }
11254
11255 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
11256 intf, off_chan_val(sec));
11257 if (res < 0 || res >= (int) sizeof(buf))
11258 return -1;
11259 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11260 if (system(buf) != 0) {
11261 send_resp(dut, conn, SIGMA_ERROR,
11262 "errorCode,Failed to set sec chan offset");
11263 return 0;
11264 }
11265
11266 return 1;
11267}
11268
11269
11270static int tdls_set_offchannel_offset(struct sigma_dut *dut,
11271 struct sigma_conn *conn,
11272 const char *intf, int off_ch_num,
11273 enum sec_ch_offset sec)
11274{
11275 char buf[200];
11276 int res;
11277
11278 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
11279 off_ch_num);
11280 if (res < 0 || res >= (int) sizeof(buf))
11281 return -1;
11282 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11283
11284 if (wpa_command(intf, buf) < 0) {
11285 send_resp(dut, conn, SIGMA_ERROR,
11286 "ErrorCode,Failed to set offchan");
11287 return 0;
11288 }
11289 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
11290 off_chan_val(sec));
11291 if (res < 0 || res >= (int) sizeof(buf))
11292 return -1;
11293
11294 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11295
11296 if (wpa_command(intf, buf) < 0) {
11297 send_resp(dut, conn, SIGMA_ERROR,
11298 "ErrorCode,Failed to set sec chan offset");
11299 return 0;
11300 }
11301
11302 return 1;
11303}
11304
11305
11306static int tdls_set_offchannel_mode(struct sigma_dut *dut,
11307 struct sigma_conn *conn,
11308 const char *intf, int val)
11309{
11310 char buf[200];
11311 int res;
11312
11313 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
11314 val);
11315 if (res < 0 || res >= (int) sizeof(buf))
11316 return -1;
11317 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11318
11319 if (wpa_command(intf, buf) < 0) {
11320 send_resp(dut, conn, SIGMA_ERROR,
11321 "ErrorCode,Failed to configure offchannel mode");
11322 return 0;
11323 }
11324
11325 return 1;
11326}
11327
11328
11329static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
11330 struct sigma_conn *conn,
11331 struct sigma_cmd *cmd)
11332{
11333 const char *val;
11334 enum {
11335 CHSM_NOT_SET,
11336 CHSM_ENABLE,
11337 CHSM_DISABLE,
11338 CHSM_REJREQ,
11339 CHSM_UNSOLRESP
11340 } chsm = CHSM_NOT_SET;
11341 int off_ch_num = -1;
11342 enum sec_ch_offset sec_ch = SEC_CH_NO;
11343 int res;
11344
11345 val = get_param(cmd, "Uapsd");
11346 if (val) {
11347 char buf[100];
11348 if (strcasecmp(val, "Enable") == 0)
11349 snprintf(buf, sizeof(buf), "SET ps 99");
11350 else if (strcasecmp(val, "Disable") == 0)
11351 snprintf(buf, sizeof(buf), "SET ps 98");
11352 else {
11353 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11354 "Unsupported uapsd parameter value");
11355 return 0;
11356 }
11357 if (wpa_command(intf, buf)) {
11358 send_resp(dut, conn, SIGMA_ERROR,
11359 "ErrorCode,Failed to change U-APSD "
11360 "powersave mode");
11361 return 0;
11362 }
11363 }
11364
11365 val = get_param(cmd, "TPKTIMER");
11366 if (val && strcasecmp(val, "DISABLE") == 0) {
11367 if (wpa_command(intf, "SET tdls_testing 0x100")) {
11368 send_resp(dut, conn, SIGMA_ERROR,
11369 "ErrorCode,Failed to enable no TPK "
11370 "expiration test mode");
11371 return 0;
11372 }
11373 dut->no_tpk_expiration = 1;
11374 }
11375
11376 val = get_param(cmd, "ChSwitchMode");
11377 if (val) {
11378 if (strcasecmp(val, "Enable") == 0 ||
11379 strcasecmp(val, "Initiate") == 0)
11380 chsm = CHSM_ENABLE;
11381 else if (strcasecmp(val, "Disable") == 0 ||
11382 strcasecmp(val, "passive") == 0)
11383 chsm = CHSM_DISABLE;
11384 else if (strcasecmp(val, "RejReq") == 0)
11385 chsm = CHSM_REJREQ;
11386 else if (strcasecmp(val, "UnSolResp") == 0)
11387 chsm = CHSM_UNSOLRESP;
11388 else {
11389 send_resp(dut, conn, SIGMA_ERROR,
11390 "ErrorCode,Unknown ChSwitchMode value");
11391 return 0;
11392 }
11393 }
11394
11395 val = get_param(cmd, "OffChNum");
11396 if (val) {
11397 off_ch_num = atoi(val);
11398 if (off_ch_num == 0) {
11399 send_resp(dut, conn, SIGMA_ERROR,
11400 "ErrorCode,Invalid OffChNum");
11401 return 0;
11402 }
11403 }
11404
11405 val = get_param(cmd, "SecChOffset");
11406 if (val) {
11407 if (strcmp(val, "20") == 0)
11408 sec_ch = SEC_CH_NO;
11409 else if (strcasecmp(val, "40above") == 0)
11410 sec_ch = SEC_CH_40ABOVE;
11411 else if (strcasecmp(val, "40below") == 0)
11412 sec_ch = SEC_CH_40BELOW;
11413 else {
11414 send_resp(dut, conn, SIGMA_ERROR,
11415 "ErrorCode,Unknown SecChOffset value");
11416 return 0;
11417 }
11418 }
11419
11420 if (chsm == CHSM_NOT_SET) {
11421 /* no offchannel changes requested */
11422 return 1;
11423 }
11424
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011425 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
11426 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011427 send_resp(dut, conn, SIGMA_ERROR,
11428 "ErrorCode,Unknown interface");
11429 return 0;
11430 }
11431
11432 switch (chsm) {
11433 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030011434 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011435 break;
11436 case CHSM_ENABLE:
11437 if (off_ch_num < 0) {
11438 send_resp(dut, conn, SIGMA_ERROR,
11439 "ErrorCode,Missing OffChNum argument");
11440 return 0;
11441 }
11442 if (wifi_chip_type == DRIVER_WCN) {
11443 res = tdls_set_offchannel_offset(dut, conn, intf,
11444 off_ch_num, sec_ch);
11445 } else {
11446 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11447 sec_ch);
11448 }
11449 if (res != 1)
11450 return res;
11451 if (wifi_chip_type == DRIVER_WCN)
11452 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
11453 else
11454 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
11455 break;
11456 case CHSM_DISABLE:
11457 if (wifi_chip_type == DRIVER_WCN)
11458 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
11459 else
11460 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
11461 break;
11462 case CHSM_REJREQ:
11463 if (wifi_chip_type == DRIVER_WCN)
11464 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
11465 else
11466 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
11467 break;
11468 case CHSM_UNSOLRESP:
11469 if (off_ch_num < 0) {
11470 send_resp(dut, conn, SIGMA_ERROR,
11471 "ErrorCode,Missing OffChNum argument");
11472 return 0;
11473 }
11474 if (wifi_chip_type == DRIVER_WCN) {
11475 res = tdls_set_offchannel_offset(dut, conn, intf,
11476 off_ch_num, sec_ch);
11477 } else {
11478 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11479 sec_ch);
11480 }
11481 if (res != 1)
11482 return res;
11483 if (wifi_chip_type == DRIVER_WCN)
11484 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
11485 else
11486 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
11487 break;
11488 }
11489
11490 return res;
11491}
11492
11493
11494static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11495 struct sigma_conn *conn,
11496 struct sigma_cmd *cmd)
11497{
11498 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011499 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011500
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011501 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080011502
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011503 val = get_param(cmd, "nss_mcs_opt");
11504 if (val) {
11505 /* String (nss_operating_mode; mcs_operating_mode) */
11506 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011507 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011508
11509 token = strdup(val);
11510 if (!token)
11511 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011512 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011513 if (!result) {
11514 sigma_dut_print(dut, DUT_MSG_ERROR,
11515 "VHT NSS not specified");
11516 goto failed;
11517 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011518 if (strcasecmp(result, "def") != 0) {
11519 nss = atoi(result);
11520 if (nss == 4)
11521 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011522 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011523 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011524
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011525 }
11526
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011527 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011528 if (!result) {
11529 sigma_dut_print(dut, DUT_MSG_ERROR,
11530 "VHT MCS not specified");
11531 goto failed;
11532 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011533 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011534 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011535 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011536 } else {
11537 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011538 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011539 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011540 }
11541 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011542 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011543 }
11544
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011545 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011546 return 1;
11547failed:
11548 free(token);
11549 return 0;
11550}
11551
11552
11553static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11554 struct sigma_conn *conn,
11555 struct sigma_cmd *cmd)
11556{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011557 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011558 case DRIVER_ATHEROS:
11559 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
11560 default:
11561 send_resp(dut, conn, SIGMA_ERROR,
11562 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
11563 return 0;
11564 }
11565}
11566
11567
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011568static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11569 struct sigma_conn *conn,
11570 struct sigma_cmd *cmd)
11571{
11572 const char *val;
11573 char *token = NULL, *result;
11574 char buf[60];
11575
11576 val = get_param(cmd, "nss_mcs_opt");
11577 if (val) {
11578 /* String (nss_operating_mode; mcs_operating_mode) */
11579 int nss, mcs, ratecode;
11580 char *saveptr;
11581
11582 token = strdup(val);
11583 if (!token)
11584 return -2;
11585
11586 result = strtok_r(token, ";", &saveptr);
11587 if (!result) {
11588 sigma_dut_print(dut, DUT_MSG_ERROR,
11589 "HE NSS not specified");
11590 goto failed;
11591 }
11592 nss = 1;
11593 if (strcasecmp(result, "def") != 0)
11594 nss = atoi(result);
11595
11596 result = strtok_r(NULL, ";", &saveptr);
11597 if (!result) {
11598 sigma_dut_print(dut, DUT_MSG_ERROR,
11599 "HE MCS not specified");
11600 goto failed;
11601 }
11602 mcs = 7;
11603 if (strcasecmp(result, "def") != 0)
11604 mcs = atoi(result);
11605
Arif Hussain557bf412018-05-25 17:29:36 -070011606 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011607 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070011608 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011609 } else if (nss > 2) {
11610 sigma_dut_print(dut, DUT_MSG_ERROR,
11611 "HE NSS %d not supported", nss);
11612 goto failed;
11613 }
11614
Arif Hussain557bf412018-05-25 17:29:36 -070011615 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
11616 if (system(buf) != 0) {
11617 sigma_dut_print(dut, DUT_MSG_ERROR,
11618 "nss_mcs_opt: iwpriv %s nss %d failed",
11619 intf, nss);
11620 goto failed;
11621 }
Arif Hussainac6c5112018-05-25 17:34:00 -070011622 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070011623
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011624 /* Add the MCS to the ratecode */
11625 if (mcs >= 0 && mcs <= 11) {
11626 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070011627#ifdef NL80211_SUPPORT
11628 if (dut->device_type == STA_testbed) {
11629 enum he_mcs_config mcs_config;
11630 int ret;
11631
11632 if (mcs <= 7)
11633 mcs_config = HE_80_MCS0_7;
11634 else if (mcs <= 9)
11635 mcs_config = HE_80_MCS0_9;
11636 else
11637 mcs_config = HE_80_MCS0_11;
11638 ret = sta_set_he_mcs(dut, intf, mcs_config);
11639 if (ret) {
11640 sigma_dut_print(dut, DUT_MSG_ERROR,
11641 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
11642 mcs, mcs_config, ret);
11643 goto failed;
11644 }
11645 }
11646#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011647 } else {
11648 sigma_dut_print(dut, DUT_MSG_ERROR,
11649 "HE MCS %d not supported", mcs);
11650 goto failed;
11651 }
11652 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
11653 intf, ratecode);
11654 if (system(buf) != 0) {
11655 sigma_dut_print(dut, DUT_MSG_ERROR,
11656 "iwpriv setting of 11ax rates failed");
11657 goto failed;
11658 }
11659 free(token);
11660 }
11661
11662 val = get_param(cmd, "GI");
11663 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011664 int fix_rate_sgi;
11665
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011666 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011667 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011668 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011669 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011670 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
11671 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011672 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011673 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011674 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
11675 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011676 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011677 } else {
11678 send_resp(dut, conn, SIGMA_ERROR,
11679 "errorCode,GI value not supported");
11680 return 0;
11681 }
11682 if (system(buf) != 0) {
11683 send_resp(dut, conn, SIGMA_ERROR,
11684 "errorCode,Failed to set shortgi");
11685 return 0;
11686 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011687 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
11688 intf, fix_rate_sgi);
11689 if (system(buf) != 0) {
11690 send_resp(dut, conn, SIGMA_ERROR,
11691 "errorCode,Failed to set fix rate shortgi");
11692 return STATUS_SENT;
11693 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011694 }
11695
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011696 val = get_param(cmd, "LTF");
11697 if (val) {
11698#ifdef NL80211_SUPPORT
11699 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011700 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011701 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011702 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011703 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011704 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011705 } else {
11706 send_resp(dut, conn, SIGMA_ERROR,
11707 "errorCode, LTF value not supported");
11708 return 0;
11709 }
11710#else /* NL80211_SUPPORT */
11711 sigma_dut_print(dut, DUT_MSG_ERROR,
11712 "LTF cannot be set without NL80211_SUPPORT defined");
11713 return -2;
11714#endif /* NL80211_SUPPORT */
11715 }
11716
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070011717 val = get_param(cmd, "TxSUPPDU");
11718 if (val) {
11719 int set_val = 1;
11720
11721 if (strcasecmp(val, "Enable") == 0)
11722 set_val = 1;
11723 else if (strcasecmp(val, "Disable") == 0)
11724 set_val = 0;
11725
11726 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
11727 send_resp(dut, conn, SIGMA_ERROR,
11728 "ErrorCode,Failed to set Tx SU PPDU config");
11729 return 0;
11730 }
11731 }
11732
Arif Hussain480d5f42019-03-12 14:40:42 -070011733 val = get_param(cmd, "TWT_Setup");
11734 if (val) {
11735 if (strcasecmp(val, "Request") == 0) {
11736 if (sta_twt_request(dut, conn, cmd)) {
11737 send_resp(dut, conn, SIGMA_ERROR,
11738 "ErrorCode,sta_twt_request failed");
11739 return STATUS_SENT;
11740 }
11741 } else if (strcasecmp(val, "Teardown") == 0) {
11742 if (sta_twt_teardown(dut, conn, cmd)) {
11743 send_resp(dut, conn, SIGMA_ERROR,
11744 "ErrorCode,sta_twt_teardown failed");
11745 return STATUS_SENT;
11746 }
11747 }
11748 }
11749
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080011750 val = get_param(cmd, "transmitOMI");
11751 if (val && sta_transmit_omi(dut, conn, cmd)) {
11752 send_resp(dut, conn, SIGMA_ERROR,
11753 "ErrorCode,sta_transmit_omi failed");
11754 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070011755 }
11756
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011757 val = get_param(cmd, "Powersave");
11758 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011759 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011760
11761 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011762 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011763 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011764 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011765 } else {
11766 sigma_dut_print(dut, DUT_MSG_ERROR,
11767 "Unsupported Powersave value '%s'",
11768 val);
11769 return -1;
11770 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011771 if (set_power_save_wcn(dut, intf, ps) < 0)
11772 return 0;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011773 }
11774
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080011775 val = get_param(cmd, "MU_EDCA");
11776 if (val) {
11777 if (strcasecmp(val, "Override") == 0) {
11778 if (sta_set_mu_edca_override(dut, intf, 1)) {
11779 send_resp(dut, conn, SIGMA_ERROR,
11780 "errorCode,MU EDCA override set failed");
11781 return STATUS_SENT;
11782 }
11783 } else if (strcasecmp(val, "Disable") == 0) {
11784 if (sta_set_mu_edca_override(dut, intf, 0)) {
11785 send_resp(dut, conn, SIGMA_ERROR,
11786 "errorCode,MU EDCA override disable failed");
11787 return STATUS_SENT;
11788 }
11789 }
11790 }
11791
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011792 return 1;
11793
11794failed:
11795 free(token);
11796 return -2;
11797}
11798
11799
11800static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11801 struct sigma_conn *conn,
11802 struct sigma_cmd *cmd)
11803{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011804 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011805 case DRIVER_WCN:
11806 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
11807 default:
11808 send_resp(dut, conn, SIGMA_ERROR,
11809 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
11810 return 0;
11811 }
11812}
11813
11814
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011815static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
11816 struct sigma_conn *conn,
11817 struct sigma_cmd *cmd)
11818{
11819 const char *val;
11820
11821 val = get_param(cmd, "powersave");
11822 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011823 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011824
11825 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011826 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011827 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011828 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011829 } else {
11830 sigma_dut_print(dut, DUT_MSG_ERROR,
11831 "Unsupported power save config");
11832 return -1;
11833 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053011834 if (set_power_save_wcn(dut, intf, ps) < 0)
11835 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011836 return 1;
11837 }
11838
11839 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
11840
11841 return 0;
11842}
11843
11844
Ashwini Patil5acd7382017-04-13 15:55:04 +053011845static int btm_query_candidate_list(struct sigma_dut *dut,
11846 struct sigma_conn *conn,
11847 struct sigma_cmd *cmd)
11848{
11849 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
11850 int len, ret;
11851 char buf[10];
11852
11853 /*
11854 * Neighbor Report elements format:
11855 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
11856 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
11857 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
11858 */
11859
11860 bssid = get_param(cmd, "Nebor_BSSID");
11861 if (!bssid) {
11862 send_resp(dut, conn, SIGMA_INVALID,
11863 "errorCode,Nebor_BSSID is missing");
11864 return 0;
11865 }
11866
11867 info = get_param(cmd, "Nebor_Bssid_Info");
11868 if (!info) {
11869 sigma_dut_print(dut, DUT_MSG_INFO,
11870 "Using default value for Nebor_Bssid_Info: %s",
11871 DEFAULT_NEIGHBOR_BSSID_INFO);
11872 info = DEFAULT_NEIGHBOR_BSSID_INFO;
11873 }
11874
11875 op_class = get_param(cmd, "Nebor_Op_Class");
11876 if (!op_class) {
11877 send_resp(dut, conn, SIGMA_INVALID,
11878 "errorCode,Nebor_Op_Class is missing");
11879 return 0;
11880 }
11881
11882 ch = get_param(cmd, "Nebor_Op_Ch");
11883 if (!ch) {
11884 send_resp(dut, conn, SIGMA_INVALID,
11885 "errorCode,Nebor_Op_Ch is missing");
11886 return 0;
11887 }
11888
11889 phy_type = get_param(cmd, "Nebor_Phy_Type");
11890 if (!phy_type) {
11891 sigma_dut_print(dut, DUT_MSG_INFO,
11892 "Using default value for Nebor_Phy_Type: %s",
11893 DEFAULT_NEIGHBOR_PHY_TYPE);
11894 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
11895 }
11896
11897 /* Parse optional subelements */
11898 buf[0] = '\0';
11899 pref = get_param(cmd, "Nebor_Pref");
11900 if (pref) {
11901 /* hexdump for preferrence subelement */
11902 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
11903 if (ret < 0 || ret >= (int) sizeof(buf)) {
11904 sigma_dut_print(dut, DUT_MSG_ERROR,
11905 "snprintf failed for optional subelement ret: %d",
11906 ret);
11907 send_resp(dut, conn, SIGMA_ERROR,
11908 "errorCode,snprintf failed for subelement");
11909 return 0;
11910 }
11911 }
11912
11913 if (!dut->btm_query_cand_list) {
11914 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
11915 if (!dut->btm_query_cand_list) {
11916 send_resp(dut, conn, SIGMA_ERROR,
11917 "errorCode,Failed to allocate memory for btm_query_cand_list");
11918 return 0;
11919 }
11920 }
11921
11922 len = strlen(dut->btm_query_cand_list);
11923 ret = snprintf(dut->btm_query_cand_list + len,
11924 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
11925 bssid, info, op_class, ch, phy_type, buf);
11926 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
11927 sigma_dut_print(dut, DUT_MSG_ERROR,
11928 "snprintf failed for neighbor report list ret: %d",
11929 ret);
11930 send_resp(dut, conn, SIGMA_ERROR,
11931 "errorCode,snprintf failed for neighbor report");
11932 free(dut->btm_query_cand_list);
11933 dut->btm_query_cand_list = NULL;
11934 return 0;
11935 }
11936
11937 return 1;
11938}
11939
11940
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011941int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
11942 struct sigma_ese_alloc *allocs, int *allocs_size)
11943{
11944 int max_count = *allocs_size;
11945 int count = 0, i;
11946 const char *val;
11947
11948 do {
11949 val = get_param_indexed(cmd, "AllocID", count);
11950 if (val)
11951 count++;
11952 } while (val);
11953
11954 if (count == 0 || count > max_count) {
11955 sigma_dut_print(dut, DUT_MSG_ERROR,
11956 "Invalid number of allocations(%d)", count);
11957 return -1;
11958 }
11959
11960 for (i = 0; i < count; i++) {
11961 val = get_param_indexed(cmd, "PercentBI", i);
11962 if (!val) {
11963 sigma_dut_print(dut, DUT_MSG_ERROR,
11964 "Missing PercentBI parameter at index %d",
11965 i);
11966 return -1;
11967 }
11968 allocs[i].percent_bi = atoi(val);
11969
11970 val = get_param_indexed(cmd, "SrcAID", i);
11971 if (val)
11972 allocs[i].src_aid = strtol(val, NULL, 0);
11973 else
11974 allocs[i].src_aid = ESE_BCAST_AID;
11975
11976 val = get_param_indexed(cmd, "DestAID", i);
11977 if (val)
11978 allocs[i].dst_aid = strtol(val, NULL, 0);
11979 else
11980 allocs[i].dst_aid = ESE_BCAST_AID;
11981
11982 allocs[i].type = ESE_CBAP;
11983 sigma_dut_print(dut, DUT_MSG_INFO,
11984 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
11985 i, allocs[i].percent_bi, allocs[i].src_aid,
11986 allocs[i].dst_aid);
11987 }
11988
11989 *allocs_size = count;
11990 return 0;
11991}
11992
11993
11994static int sta_set_60g_ese(struct sigma_dut *dut, int count,
11995 struct sigma_ese_alloc *allocs)
11996{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011997 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011998#ifdef __linux__
11999 case DRIVER_WIL6210:
12000 if (wil6210_set_ese(dut, count, allocs))
12001 return -1;
12002 return 1;
12003#endif /* __linux__ */
12004 default:
12005 sigma_dut_print(dut, DUT_MSG_ERROR,
12006 "Unsupported sta_set_60g_ese with the current driver");
12007 return -1;
12008 }
12009}
12010
12011
12012static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
12013 struct sigma_conn *conn,
12014 struct sigma_cmd *cmd)
12015{
12016 const char *val;
12017
12018 val = get_param(cmd, "ExtSchIE");
12019 if (val && !strcasecmp(val, "Enable")) {
12020 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
12021 int count = MAX_ESE_ALLOCS;
12022
12023 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
12024 return -1;
12025 return sta_set_60g_ese(dut, count, allocs);
12026 }
12027
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012028 val = get_param(cmd, "MCS_FixedRate");
12029 if (val) {
12030 int sta_mcs = atoi(val);
12031
12032 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
12033 sta_mcs);
12034 wil6210_set_force_mcs(dut, 1, sta_mcs);
12035
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012036 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012037 }
12038
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012039 send_resp(dut, conn, SIGMA_ERROR,
12040 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012041 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012042}
12043
12044
Jouni Malinen6250cb02020-04-15 13:54:45 +030012045static enum sigma_cmd_result
12046cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
12047 struct sigma_conn *conn,
12048 struct sigma_cmd *cmd)
12049{
12050 const char *val;
12051
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053012052 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030012053 if (val && atoi(val) == 1) {
12054 if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
12055 send_resp(dut, conn, SIGMA_ERROR,
12056 "errorCode,Failed to set ft_rsnxe_used");
12057 return STATUS_SENT_ERROR;
12058 }
12059 return SUCCESS_SEND_STATUS;
12060 }
12061 send_resp(dut, conn, SIGMA_ERROR,
12062 "errorCode,Unsupported WPA3 rfeature");
12063 return STATUS_SENT_ERROR;
12064}
12065
12066
Jouni Malinenf7222712019-06-13 01:50:21 +030012067static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
12068 struct sigma_conn *conn,
12069 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012070{
12071 const char *intf = get_param(cmd, "Interface");
12072 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012073 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012074
12075 if (intf == NULL || prog == NULL)
12076 return -1;
12077
Ashwini Patil5acd7382017-04-13 15:55:04 +053012078 /* BSS Transition candidate list for BTM query */
12079 val = get_param(cmd, "Nebor_BSSID");
12080 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
12081 return 0;
12082
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012083 if (strcasecmp(prog, "TDLS") == 0)
12084 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
12085
12086 if (strcasecmp(prog, "VHT") == 0)
12087 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
12088
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012089 if (strcasecmp(prog, "HE") == 0)
12090 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
12091
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012092 if (strcasecmp(prog, "MBO") == 0) {
12093 val = get_param(cmd, "Cellular_Data_Cap");
12094 if (val &&
12095 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12096 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053012097
12098 val = get_param(cmd, "Ch_Pref");
12099 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12100 return 0;
12101
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012102 return 1;
12103 }
12104
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012105 if (strcasecmp(prog, "60GHz") == 0)
12106 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
12107
Jouni Malinen6250cb02020-04-15 13:54:45 +030012108 if (strcasecmp(prog, "WPA3") == 0)
12109 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
12110
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012111 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
12112 return 0;
12113}
12114
12115
Jouni Malinenf7222712019-06-13 01:50:21 +030012116static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
12117 struct sigma_conn *conn,
12118 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012119{
12120 const char *intf = get_param(cmd, "Interface");
12121 const char *mode = get_param(cmd, "Mode");
12122 int res;
12123
12124 if (intf == NULL || mode == NULL)
12125 return -1;
12126
12127 if (strcasecmp(mode, "On") == 0)
12128 res = wpa_command(intf, "SET radio_disabled 0");
12129 else if (strcasecmp(mode, "Off") == 0)
12130 res = wpa_command(intf, "SET radio_disabled 1");
12131 else
12132 return -1;
12133
12134 if (res) {
12135 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12136 "radio mode");
12137 return 0;
12138 }
12139
12140 return 1;
12141}
12142
12143
Jouni Malinenf7222712019-06-13 01:50:21 +030012144static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
12145 struct sigma_conn *conn,
12146 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012147{
12148 const char *intf = get_param(cmd, "Interface");
12149 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012150 const char *prog = get_param(cmd, "program");
12151 const char *powersave = get_param(cmd, "powersave");
12152 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012153
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012154 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012155 return -1;
12156
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012157 if (prog && strcasecmp(prog, "60GHz") == 0) {
12158 /*
12159 * The CAPI mode parameter does not exist in 60G
12160 * unscheduled PS.
12161 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080012162 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012163 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012164 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020012165 strcasecmp(prog, "HE") == 0) {
12166 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012167 } else {
12168 if (mode == NULL)
12169 return -1;
12170
12171 if (strcasecmp(mode, "On") == 0)
12172 res = set_ps(intf, dut, 1);
12173 else if (strcasecmp(mode, "Off") == 0)
12174 res = set_ps(intf, dut, 0);
12175 else
12176 return -1;
12177 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012178
12179 if (res) {
12180 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12181 "power save mode");
12182 return 0;
12183 }
12184
12185 return 1;
12186}
12187
12188
Jouni Malinenf7222712019-06-13 01:50:21 +030012189static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
12190 struct sigma_conn *conn,
12191 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012192{
12193 const char *intf = get_param(cmd, "Interface");
12194 const char *val, *bssid;
12195 int res;
12196 char *buf;
12197 size_t buf_len;
12198
12199 val = get_param(cmd, "BSSID_FILTER");
12200 if (val == NULL)
12201 return -1;
12202
12203 bssid = get_param(cmd, "BSSID_List");
12204 if (atoi(val) == 0 || bssid == NULL) {
12205 /* Disable BSSID filter */
12206 if (wpa_command(intf, "SET bssid_filter ")) {
12207 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
12208 "to disable BSSID filter");
12209 return 0;
12210 }
12211
12212 return 1;
12213 }
12214
12215 buf_len = 100 + strlen(bssid);
12216 buf = malloc(buf_len);
12217 if (buf == NULL)
12218 return -1;
12219
12220 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
12221 res = wpa_command(intf, buf);
12222 free(buf);
12223 if (res) {
12224 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
12225 "BSSID filter");
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_reset_parm(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;
12239
12240 /* TODO: ARP */
12241
12242 val = get_param(cmd, "HS2_CACHE_PROFILE");
12243 if (val && strcasecmp(val, "All") == 0)
12244 hs2_clear_credentials(intf);
12245
12246 return 1;
12247}
12248
12249
Jouni Malinenf7222712019-06-13 01:50:21 +030012250static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
12251 struct sigma_conn *conn,
12252 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012253{
12254 const char *intf = get_param(cmd, "Interface");
12255 const char *key_type = get_param(cmd, "KeyType");
12256 char buf[100], resp[200];
12257
12258 if (key_type == NULL)
12259 return -1;
12260
12261 if (strcasecmp(key_type, "GTK") == 0) {
12262 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
12263 strncmp(buf, "FAIL", 4) == 0) {
12264 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12265 "not fetch current GTK");
12266 return 0;
12267 }
12268 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
12269 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12270 return 0;
12271 } else {
12272 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12273 "KeyType");
12274 return 0;
12275 }
12276
12277 return 1;
12278}
12279
12280
12281static int hs2_set_policy(struct sigma_dut *dut)
12282{
12283#ifdef ANDROID
12284 system("ip rule del prio 23000");
12285 if (system("ip rule add from all lookup main prio 23000") != 0) {
12286 sigma_dut_print(dut, DUT_MSG_ERROR,
12287 "Failed to run:ip rule add from all lookup main prio");
12288 return -1;
12289 }
12290 if (system("ip route flush cache") != 0) {
12291 sigma_dut_print(dut, DUT_MSG_ERROR,
12292 "Failed to run ip route flush cache");
12293 return -1;
12294 }
12295 return 1;
12296#else /* ANDROID */
12297 return 0;
12298#endif /* ANDROID */
12299}
12300
12301
Jouni Malinenf7222712019-06-13 01:50:21 +030012302static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
12303 struct sigma_conn *conn,
12304 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012305{
12306 const char *intf = get_param(cmd, "Interface");
12307 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030012308 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012309 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030012310 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012311 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
12312 int tries = 0;
12313 int ignore_blacklist = 0;
12314 const char *events[] = {
12315 "CTRL-EVENT-CONNECTED",
12316 "INTERWORKING-BLACKLISTED",
12317 "INTERWORKING-NO-MATCH",
12318 NULL
12319 };
12320
12321 start_sta_mode(dut);
12322
Jouni Malinen439352d2018-09-13 03:42:23 +030012323 if (band) {
12324 if (strcmp(band, "2.4") == 0) {
12325 wpa_command(intf, "SET setband 2G");
12326 } else if (strcmp(band, "5") == 0) {
12327 wpa_command(intf, "SET setband 5G");
12328 } else {
12329 send_resp(dut, conn, SIGMA_ERROR,
12330 "errorCode,Unsupported band");
12331 return 0;
12332 }
12333 }
12334
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012335 blacklisted[0] = '\0';
12336 if (val && atoi(val))
12337 ignore_blacklist = 1;
12338
12339try_again:
12340 ctrl = open_wpa_mon(intf);
12341 if (ctrl == NULL) {
12342 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12343 "wpa_supplicant monitor connection");
12344 return -2;
12345 }
12346
12347 tries++;
12348 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
12349 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
12350 "Interworking connection");
12351 wpa_ctrl_detach(ctrl);
12352 wpa_ctrl_close(ctrl);
12353 return 0;
12354 }
12355
12356 buf[0] = '\0';
12357 while (1) {
12358 char *pos;
12359 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
12360 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
12361 if (!pos)
12362 break;
12363 pos += 25;
12364 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
12365 pos);
12366 if (!blacklisted[0])
12367 memcpy(blacklisted, pos, strlen(pos) + 1);
12368 }
12369
12370 if (ignore_blacklist && blacklisted[0]) {
12371 char *end;
12372 end = strchr(blacklisted, ' ');
12373 if (end)
12374 *end = '\0';
12375 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
12376 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030012377 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
12378 blacklisted);
12379 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012380 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
12381 wpa_ctrl_detach(ctrl);
12382 wpa_ctrl_close(ctrl);
12383 return 0;
12384 }
12385 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
12386 buf, sizeof(buf));
12387 }
12388
12389 wpa_ctrl_detach(ctrl);
12390 wpa_ctrl_close(ctrl);
12391
12392 if (res < 0) {
12393 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12394 "connect");
12395 return 0;
12396 }
12397
12398 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
12399 strstr(buf, "INTERWORKING-BLACKLISTED")) {
12400 if (tries < 2) {
12401 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
12402 goto try_again;
12403 }
12404 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
12405 "matching credentials found");
12406 return 0;
12407 }
12408
12409 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12410 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12411 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12412 "get current BSSID/SSID");
12413 return 0;
12414 }
12415
12416 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
12417 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12418 hs2_set_policy(dut);
12419 return 0;
12420}
12421
12422
Jouni Malinenf7222712019-06-13 01:50:21 +030012423static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
12424 struct sigma_conn *conn,
12425 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030012426{
12427 const char *intf = get_param(cmd, "Interface");
12428 const char *display = get_param(cmd, "Display");
12429 struct wpa_ctrl *ctrl;
12430 char buf[300], params[400], *pos;
12431 char bssid[20];
12432 int info_avail = 0;
12433 unsigned int old_timeout;
12434 int res;
12435
12436 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
12437 send_resp(dut, conn, SIGMA_ERROR,
12438 "ErrorCode,Could not get current BSSID");
12439 return 0;
12440 }
12441 ctrl = open_wpa_mon(intf);
12442 if (!ctrl) {
12443 sigma_dut_print(dut, DUT_MSG_ERROR,
12444 "Failed to open wpa_supplicant monitor connection");
12445 return -2;
12446 }
12447
12448 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
12449 wpa_command(intf, buf);
12450
12451 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
12452 if (res < 0) {
12453 send_resp(dut, conn, SIGMA_ERROR,
12454 "ErrorCode,Could not complete GAS query");
12455 goto fail;
12456 }
12457
12458 old_timeout = dut->default_timeout;
12459 dut->default_timeout = 2;
12460 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
12461 dut->default_timeout = old_timeout;
12462 if (res < 0)
12463 goto done;
12464 pos = strchr(buf, ' ');
12465 if (!pos)
12466 goto done;
12467 pos++;
12468 pos = strchr(pos, ' ');
12469 if (!pos)
12470 goto done;
12471 pos++;
12472 info_avail = 1;
12473 snprintf(params, sizeof(params), "browser %s", pos);
12474
12475 if (display && strcasecmp(display, "Yes") == 0) {
12476 pid_t pid;
12477
12478 pid = fork();
12479 if (pid < 0) {
12480 perror("fork");
12481 return -1;
12482 }
12483
12484 if (pid == 0) {
12485 run_hs20_osu(dut, params);
12486 exit(0);
12487 }
12488 }
12489
12490done:
12491 snprintf(buf, sizeof(buf), "Info_available,%s",
12492 info_avail ? "Yes" : "No");
12493 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12494fail:
12495 wpa_ctrl_detach(ctrl);
12496 wpa_ctrl_close(ctrl);
12497 return 0;
12498}
12499
12500
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012501static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
12502 struct sigma_conn *conn,
12503 const char *ifname,
12504 struct sigma_cmd *cmd)
12505{
12506 const char *val;
12507 int id;
12508
12509 id = add_cred(ifname);
12510 if (id < 0)
12511 return -2;
12512 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12513
12514 val = get_param(cmd, "prefer");
12515 if (val && atoi(val) > 0)
12516 set_cred(ifname, id, "priority", "1");
12517
12518 val = get_param(cmd, "REALM");
12519 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12520 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12521 "realm");
12522 return 0;
12523 }
12524
12525 val = get_param(cmd, "HOME_FQDN");
12526 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12527 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12528 "home_fqdn");
12529 return 0;
12530 }
12531
12532 val = get_param(cmd, "Username");
12533 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12534 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12535 "username");
12536 return 0;
12537 }
12538
12539 val = get_param(cmd, "Password");
12540 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
12541 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12542 "password");
12543 return 0;
12544 }
12545
12546 val = get_param(cmd, "ROOT_CA");
12547 if (val) {
12548 char fname[200];
12549 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12550#ifdef __linux__
12551 if (!file_exists(fname)) {
12552 char msg[300];
12553 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12554 "file (%s) not found", fname);
12555 send_resp(dut, conn, SIGMA_ERROR, msg);
12556 return 0;
12557 }
12558#endif /* __linux__ */
12559 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12560 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12561 "not set root CA");
12562 return 0;
12563 }
12564 }
12565
12566 return 1;
12567}
12568
12569
12570static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
12571{
12572 FILE *in, *out;
12573 char buf[500];
12574 int found = 0;
12575
12576 in = fopen("devdetail.xml", "r");
12577 if (in == NULL)
12578 return -1;
12579 out = fopen("devdetail.xml.tmp", "w");
12580 if (out == NULL) {
12581 fclose(in);
12582 return -1;
12583 }
12584
12585 while (fgets(buf, sizeof(buf), in)) {
12586 char *pos = strstr(buf, "<IMSI>");
12587 if (pos) {
12588 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
12589 imsi);
12590 pos += 6;
12591 *pos = '\0';
12592 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
12593 found++;
12594 } else {
12595 fprintf(out, "%s", buf);
12596 }
12597 }
12598
12599 fclose(out);
12600 fclose(in);
12601 if (found)
12602 rename("devdetail.xml.tmp", "devdetail.xml");
12603 else
12604 unlink("devdetail.xml.tmp");
12605
12606 return 0;
12607}
12608
12609
12610static int sta_add_credential_sim(struct sigma_dut *dut,
12611 struct sigma_conn *conn,
12612 const char *ifname, struct sigma_cmd *cmd)
12613{
12614 const char *val, *imsi = NULL;
12615 int id;
12616 char buf[200];
12617 int res;
12618 const char *pos;
12619 size_t mnc_len;
12620 char plmn_mcc[4];
12621 char plmn_mnc[4];
12622
12623 id = add_cred(ifname);
12624 if (id < 0)
12625 return -2;
12626 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12627
12628 val = get_param(cmd, "prefer");
12629 if (val && atoi(val) > 0)
12630 set_cred(ifname, id, "priority", "1");
12631
12632 val = get_param(cmd, "PLMN_MCC");
12633 if (val == NULL) {
12634 send_resp(dut, conn, SIGMA_ERROR,
12635 "errorCode,Missing PLMN_MCC");
12636 return 0;
12637 }
12638 if (strlen(val) != 3) {
12639 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
12640 return 0;
12641 }
12642 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
12643
12644 val = get_param(cmd, "PLMN_MNC");
12645 if (val == NULL) {
12646 send_resp(dut, conn, SIGMA_ERROR,
12647 "errorCode,Missing PLMN_MNC");
12648 return 0;
12649 }
12650 if (strlen(val) != 2 && strlen(val) != 3) {
12651 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
12652 return 0;
12653 }
12654 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
12655
12656 val = get_param(cmd, "IMSI");
12657 if (val == NULL) {
12658 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
12659 "IMSI");
12660 return 0;
12661 }
12662
12663 imsi = pos = val;
12664
12665 if (strncmp(plmn_mcc, pos, 3) != 0) {
12666 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
12667 return 0;
12668 }
12669 pos += 3;
12670
12671 mnc_len = strlen(plmn_mnc);
12672 if (mnc_len < 2) {
12673 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
12674 return 0;
12675 }
12676
12677 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
12678 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
12679 return 0;
12680 }
12681 pos += mnc_len;
12682
12683 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
12684 if (res < 0 || res >= (int) sizeof(buf))
12685 return -1;
12686 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
12687 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12688 "not set IMSI");
12689 return 0;
12690 }
12691
12692 val = get_param(cmd, "Password");
12693 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
12694 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12695 "not set password");
12696 return 0;
12697 }
12698
Jouni Malinenba630452018-06-22 11:49:59 +030012699 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012700 /*
12701 * Set provisioning_sp for the test cases where SIM/USIM
12702 * provisioning is used.
12703 */
12704 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
12705 "wi-fi.org") < 0) {
12706 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12707 "not set provisioning_sp");
12708 return 0;
12709 }
12710
12711 update_devdetail_imsi(dut, imsi);
12712 }
12713
12714 return 1;
12715}
12716
12717
12718static int sta_add_credential_cert(struct sigma_dut *dut,
12719 struct sigma_conn *conn,
12720 const char *ifname,
12721 struct sigma_cmd *cmd)
12722{
12723 const char *val;
12724 int id;
12725
12726 id = add_cred(ifname);
12727 if (id < 0)
12728 return -2;
12729 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12730
12731 val = get_param(cmd, "prefer");
12732 if (val && atoi(val) > 0)
12733 set_cred(ifname, id, "priority", "1");
12734
12735 val = get_param(cmd, "REALM");
12736 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12737 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12738 "realm");
12739 return 0;
12740 }
12741
12742 val = get_param(cmd, "HOME_FQDN");
12743 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12744 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12745 "home_fqdn");
12746 return 0;
12747 }
12748
12749 val = get_param(cmd, "Username");
12750 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12751 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12752 "username");
12753 return 0;
12754 }
12755
12756 val = get_param(cmd, "clientCertificate");
12757 if (val) {
12758 char fname[200];
12759 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12760#ifdef __linux__
12761 if (!file_exists(fname)) {
12762 char msg[300];
12763 snprintf(msg, sizeof(msg),
12764 "ErrorCode,clientCertificate "
12765 "file (%s) not found", fname);
12766 send_resp(dut, conn, SIGMA_ERROR, msg);
12767 return 0;
12768 }
12769#endif /* __linux__ */
12770 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
12771 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12772 "not set client_cert");
12773 return 0;
12774 }
12775 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
12776 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12777 "not set private_key");
12778 return 0;
12779 }
12780 }
12781
12782 val = get_param(cmd, "ROOT_CA");
12783 if (val) {
12784 char fname[200];
12785 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12786#ifdef __linux__
12787 if (!file_exists(fname)) {
12788 char msg[300];
12789 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12790 "file (%s) not found", fname);
12791 send_resp(dut, conn, SIGMA_ERROR, msg);
12792 return 0;
12793 }
12794#endif /* __linux__ */
12795 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12796 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12797 "not set root CA");
12798 return 0;
12799 }
12800 }
12801
12802 return 1;
12803}
12804
12805
Jouni Malinenf7222712019-06-13 01:50:21 +030012806static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
12807 struct sigma_conn *conn,
12808 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012809{
12810 const char *intf = get_param(cmd, "Interface");
12811 const char *type;
12812
12813 start_sta_mode(dut);
12814
12815 type = get_param(cmd, "Type");
12816 if (!type)
12817 return -1;
12818
12819 if (strcasecmp(type, "uname_pwd") == 0)
12820 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
12821
12822 if (strcasecmp(type, "sim") == 0)
12823 return sta_add_credential_sim(dut, conn, intf, cmd);
12824
12825 if (strcasecmp(type, "cert") == 0)
12826 return sta_add_credential_cert(dut, conn, intf, cmd);
12827
12828 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
12829 "type");
12830 return 0;
12831}
12832
12833
Jouni Malinenf7222712019-06-13 01:50:21 +030012834static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
12835 struct sigma_conn *conn,
12836 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012837{
12838 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012839 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Arif Hussain66a4af02019-02-07 15:04:51 -080012840 char buf[4096];
vamsi krishna89ad8c62017-09-19 12:51:18 +053012841 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080012842 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012843 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012844 enum sigma_cmd_result status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012845
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020012846 start_sta_mode(dut);
12847
Arif Hussain66a4af02019-02-07 15:04:51 -080012848 val = get_param(cmd, "GetParameter");
12849 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012850 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080012851 buf, sizeof(buf)) < 0) {
12852 sigma_dut_print(dut, DUT_MSG_ERROR,
12853 "Could not get ssid bssid");
12854 return ERROR_SEND_STATUS;
12855 }
12856
12857 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
12858 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12859 return STATUS_SENT;
12860 }
12861
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012862 val = get_param(cmd, "HESSID");
12863 if (val) {
12864 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
12865 if (res < 0 || res >= (int) sizeof(buf))
12866 return -1;
12867 wpa_command(intf, buf);
12868 }
12869
12870 val = get_param(cmd, "ACCS_NET_TYPE");
12871 if (val) {
12872 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
12873 val);
12874 if (res < 0 || res >= (int) sizeof(buf))
12875 return -1;
12876 wpa_command(intf, buf);
12877 }
12878
vamsi krishna89ad8c62017-09-19 12:51:18 +053012879 bssid = get_param(cmd, "Bssid");
12880 ssid = get_param(cmd, "Ssid");
12881
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080012882 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
12883 dut->device_type == STA_testbed) {
12884 ssid = NULL;
12885 wildcard_ssid = 1;
12886 }
12887
vamsi krishna89ad8c62017-09-19 12:51:18 +053012888 if (ssid) {
12889 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
12890 send_resp(dut, conn, SIGMA_ERROR,
12891 "ErrorCode,Too long SSID");
12892 return 0;
12893 }
12894 ascii2hexstr(ssid, ssid_hex);
12895 }
12896
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012897 short_ssid = get_param(cmd, "ShortSSID");
12898 if (short_ssid) {
12899 uint32_t short_ssid_hex;
12900
12901 short_ssid_hex = strtoul(short_ssid, NULL, 16);
12902 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
12903 (((short_ssid_hex >> 8) & 0xFF) << 16) |
12904 (((short_ssid_hex >> 16) & 0xFF) << 8) |
12905 ((short_ssid_hex >> 24) & 0xFF);
12906
12907 res = snprintf(buf, sizeof(buf),
12908 "VENDOR_ELEM_ADD 14 ff053a%08x",
12909 short_ssid_hex);
12910 if (res < 0 || res >= (int) sizeof(buf) ||
12911 wpa_command(intf, buf)) {
12912 send_resp(dut, conn, SIGMA_ERROR,
12913 "errorCode,Failed to add short SSID");
12914 return STATUS_SENT_ERROR;
12915 }
12916 }
12917
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080012918 scan_freq = get_param(cmd, "ChnlFreq");
12919
12920 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053012921 bssid ? " bssid=": "",
12922 bssid ? bssid : "",
12923 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080012924 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080012925 wildcard_ssid ? " wildcard_ssid=1" : "",
12926 scan_freq ? " freq=" : "",
12927 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012928 if (res < 0 || res >= (int) sizeof(buf)) {
12929 send_resp(dut, conn, SIGMA_ERROR,
12930 "errorCode,Could not build scan command");
12931 status = STATUS_SENT_ERROR;
12932 goto remove_s_ssid;
12933 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053012934
12935 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012936 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
12937 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012938 status = STATUS_SENT_ERROR;
12939 } else {
12940 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012941 }
12942
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012943remove_s_ssid:
12944 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
12945 sigma_dut_print(dut, DUT_MSG_ERROR,
12946 "Failed to delete vendor element");
12947
12948 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012949}
12950
12951
Jouni Malinenf7222712019-06-13 01:50:21 +030012952static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
12953 struct sigma_conn *conn,
12954 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020012955{
12956 const char *intf = get_param(cmd, "Interface");
12957 const char *bssid;
12958 char buf[4096], *pos;
12959 int freq, chan;
12960 char *ssid;
12961 char resp[100];
12962 int res;
12963 struct wpa_ctrl *ctrl;
12964
12965 bssid = get_param(cmd, "BSSID");
12966 if (!bssid) {
12967 send_resp(dut, conn, SIGMA_INVALID,
12968 "errorCode,BSSID argument is missing");
12969 return 0;
12970 }
12971
12972 ctrl = open_wpa_mon(intf);
12973 if (!ctrl) {
12974 sigma_dut_print(dut, DUT_MSG_ERROR,
12975 "Failed to open wpa_supplicant monitor connection");
12976 return -1;
12977 }
12978
12979 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
12980 send_resp(dut, conn, SIGMA_ERROR,
12981 "errorCode,Could not start scan");
12982 wpa_ctrl_detach(ctrl);
12983 wpa_ctrl_close(ctrl);
12984 return 0;
12985 }
12986
12987 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
12988 buf, sizeof(buf));
12989
12990 wpa_ctrl_detach(ctrl);
12991 wpa_ctrl_close(ctrl);
12992
12993 if (res < 0) {
12994 send_resp(dut, conn, SIGMA_ERROR,
12995 "errorCode,Scan did not complete");
12996 return 0;
12997 }
12998
12999 snprintf(buf, sizeof(buf), "BSS %s", bssid);
13000 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
13001 strncmp(buf, "id=", 3) != 0) {
13002 send_resp(dut, conn, SIGMA_ERROR,
13003 "errorCode,Specified BSSID not found");
13004 return 0;
13005 }
13006
13007 pos = strstr(buf, "\nfreq=");
13008 if (!pos) {
13009 send_resp(dut, conn, SIGMA_ERROR,
13010 "errorCode,Channel not found");
13011 return 0;
13012 }
13013 freq = atoi(pos + 6);
13014 chan = freq_to_channel(freq);
13015
13016 pos = strstr(buf, "\nssid=");
13017 if (!pos) {
13018 send_resp(dut, conn, SIGMA_ERROR,
13019 "errorCode,SSID not found");
13020 return 0;
13021 }
13022 ssid = pos + 6;
13023 pos = strchr(ssid, '\n');
13024 if (pos)
13025 *pos = '\0';
13026 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
13027 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13028 return 0;
13029}
13030
13031
Jouni Malinenf7222712019-06-13 01:50:21 +030013032static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
13033 struct sigma_conn *conn,
13034 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013035{
13036#ifdef __linux__
13037 struct timeval tv;
13038 struct tm tm;
13039 time_t t;
13040 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013041 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013042
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013043 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013044
13045 memset(&tm, 0, sizeof(tm));
13046 val = get_param(cmd, "seconds");
13047 if (val)
13048 tm.tm_sec = atoi(val);
13049 val = get_param(cmd, "minutes");
13050 if (val)
13051 tm.tm_min = atoi(val);
13052 val = get_param(cmd, "hours");
13053 if (val)
13054 tm.tm_hour = atoi(val);
13055 val = get_param(cmd, "date");
13056 if (val)
13057 tm.tm_mday = atoi(val);
13058 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013059 if (val) {
13060 v = atoi(val);
13061 if (v < 1 || v > 12) {
13062 send_resp(dut, conn, SIGMA_INVALID,
13063 "errorCode,Invalid month");
13064 return 0;
13065 }
13066 tm.tm_mon = v - 1;
13067 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013068 val = get_param(cmd, "year");
13069 if (val) {
13070 int year = atoi(val);
13071#ifdef ANDROID
13072 if (year > 2035)
13073 year = 2035; /* years beyond 2035 not supported */
13074#endif /* ANDROID */
13075 tm.tm_year = year - 1900;
13076 }
13077 t = mktime(&tm);
13078 if (t == (time_t) -1) {
13079 send_resp(dut, conn, SIGMA_ERROR,
13080 "errorCode,Invalid date or time");
13081 return 0;
13082 }
13083
13084 memset(&tv, 0, sizeof(tv));
13085 tv.tv_sec = t;
13086
13087 if (settimeofday(&tv, NULL) < 0) {
13088 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
13089 strerror(errno));
13090 send_resp(dut, conn, SIGMA_ERROR,
13091 "errorCode,Failed to set time");
13092 return 0;
13093 }
13094
13095 return 1;
13096#endif /* __linux__ */
13097
13098 return -1;
13099}
13100
13101
Jouni Malinenf7222712019-06-13 01:50:21 +030013102static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
13103 struct sigma_conn *conn,
13104 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013105{
13106 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013107 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013108 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013109 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013110 int res;
13111 struct wpa_ctrl *ctrl;
13112
13113 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013114 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013115
13116 val = get_param(cmd, "ProdESSAssoc");
13117 if (val)
13118 prod_ess_assoc = atoi(val);
13119
13120 kill_dhcp_client(dut, intf);
13121 if (start_dhcp_client(dut, intf) < 0)
13122 return -2;
13123
13124 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
13125 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13126 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013127 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013128 prod_ess_assoc ? "" : "-N",
13129 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013130 name ? "'" : "",
13131 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
13132 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013133
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053013134 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013135 if (run_hs20_osu(dut, buf) < 0) {
13136 FILE *f;
13137
13138 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
13139
13140 f = fopen("hs20-osu-client.res", "r");
13141 if (f) {
13142 char resp[400], res[300], *pos;
13143 if (!fgets(res, sizeof(res), f))
13144 res[0] = '\0';
13145 pos = strchr(res, '\n');
13146 if (pos)
13147 *pos = '\0';
13148 fclose(f);
13149 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
13150 res);
13151 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
13152 if (system(resp) != 0) {
13153 }
13154 snprintf(resp, sizeof(resp),
13155 "SSID,,BSSID,,failureReason,%s", res);
13156 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13157 return 0;
13158 }
13159
13160 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13161 return 0;
13162 }
13163
13164 if (!prod_ess_assoc)
13165 goto report;
13166
13167 ctrl = open_wpa_mon(intf);
13168 if (ctrl == NULL) {
13169 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13170 "wpa_supplicant monitor connection");
13171 return -1;
13172 }
13173
13174 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13175 buf, sizeof(buf));
13176
13177 wpa_ctrl_detach(ctrl);
13178 wpa_ctrl_close(ctrl);
13179
13180 if (res < 0) {
13181 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
13182 "network after OSU");
13183 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13184 return 0;
13185 }
13186
13187report:
13188 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13189 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13190 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
13191 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13192 return 0;
13193 }
13194
13195 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
13196 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013197 return 0;
13198}
13199
13200
Jouni Malinenf7222712019-06-13 01:50:21 +030013201static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
13202 struct sigma_conn *conn,
13203 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013204{
13205 const char *val;
13206 int timeout = 120;
13207
13208 val = get_param(cmd, "PolicyUpdate");
13209 if (val == NULL || atoi(val) == 0)
13210 return 1; /* No operation requested */
13211
13212 val = get_param(cmd, "Timeout");
13213 if (val)
13214 timeout = atoi(val);
13215
13216 if (timeout) {
13217 /* TODO: time out the command and return
13218 * PolicyUpdateStatus,TIMEOUT if needed. */
13219 }
13220
13221 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
13222 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13223 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
13224 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
13225 return 0;
13226 }
13227
13228 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
13229 return 0;
13230}
13231
13232
Jouni Malinenf7222712019-06-13 01:50:21 +030013233static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
13234 struct sigma_conn *conn,
13235 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013236{
13237 struct wpa_ctrl *ctrl;
13238 const char *intf = get_param(cmd, "Interface");
13239 const char *bssid = get_param(cmd, "Bssid");
13240 const char *ssid = get_param(cmd, "SSID");
13241 const char *security = get_param(cmd, "Security");
13242 const char *passphrase = get_param(cmd, "Passphrase");
13243 const char *pin = get_param(cmd, "PIN");
13244 char buf[1000];
13245 char ssid_hex[200], passphrase_hex[200];
13246 const char *keymgmt, *cipher;
13247
13248 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013249 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013250
13251 if (!bssid) {
13252 send_resp(dut, conn, SIGMA_ERROR,
13253 "ErrorCode,Missing Bssid argument");
13254 return 0;
13255 }
13256
13257 if (!ssid) {
13258 send_resp(dut, conn, SIGMA_ERROR,
13259 "ErrorCode,Missing SSID argument");
13260 return 0;
13261 }
13262
13263 if (!security) {
13264 send_resp(dut, conn, SIGMA_ERROR,
13265 "ErrorCode,Missing Security argument");
13266 return 0;
13267 }
13268
13269 if (!passphrase) {
13270 send_resp(dut, conn, SIGMA_ERROR,
13271 "ErrorCode,Missing Passphrase argument");
13272 return 0;
13273 }
13274
13275 if (!pin) {
13276 send_resp(dut, conn, SIGMA_ERROR,
13277 "ErrorCode,Missing PIN argument");
13278 return 0;
13279 }
13280
vamsi krishna8c9c1562017-05-12 15:51:46 +053013281 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
13282 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013283 send_resp(dut, conn, SIGMA_ERROR,
13284 "ErrorCode,Too long SSID/passphrase");
13285 return 0;
13286 }
13287
13288 ctrl = open_wpa_mon(intf);
13289 if (ctrl == NULL) {
13290 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13291 "wpa_supplicant monitor connection");
13292 return -2;
13293 }
13294
13295 if (strcasecmp(security, "wpa2-psk") == 0) {
13296 keymgmt = "WPA2PSK";
13297 cipher = "CCMP";
13298 } else {
13299 wpa_ctrl_detach(ctrl);
13300 wpa_ctrl_close(ctrl);
13301 send_resp(dut, conn, SIGMA_ERROR,
13302 "ErrorCode,Unsupported Security value");
13303 return 0;
13304 }
13305
13306 ascii2hexstr(ssid, ssid_hex);
13307 ascii2hexstr(passphrase, passphrase_hex);
13308 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
13309 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
13310
13311 if (wpa_command(intf, buf) < 0) {
13312 wpa_ctrl_detach(ctrl);
13313 wpa_ctrl_close(ctrl);
13314 send_resp(dut, conn, SIGMA_ERROR,
13315 "ErrorCode,Failed to start registrar");
13316 return 0;
13317 }
13318
13319 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
13320 dut->er_oper_performed = 1;
13321
13322 return wps_connection_event(dut, conn, ctrl, intf, 0);
13323}
13324
13325
Jouni Malinenf7222712019-06-13 01:50:21 +030013326static enum sigma_cmd_result
13327cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
13328 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013329{
13330 struct wpa_ctrl *ctrl;
13331 const char *intf = get_param(cmd, "Interface");
13332 const char *bssid = get_param(cmd, "Bssid");
13333 char buf[100];
13334
13335 if (!bssid) {
13336 send_resp(dut, conn, SIGMA_ERROR,
13337 "ErrorCode,Missing Bssid argument");
13338 return 0;
13339 }
13340
13341 ctrl = open_wpa_mon(intf);
13342 if (ctrl == NULL) {
13343 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13344 "wpa_supplicant monitor connection");
13345 return -2;
13346 }
13347
13348 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
13349
13350 if (wpa_command(intf, buf) < 0) {
13351 wpa_ctrl_detach(ctrl);
13352 wpa_ctrl_close(ctrl);
13353 send_resp(dut, conn, SIGMA_ERROR,
13354 "ErrorCode,Failed to start registrar");
13355 return 0;
13356 }
13357
13358 return wps_connection_event(dut, conn, ctrl, intf, 0);
13359}
13360
13361
Jouni Malinenf7222712019-06-13 01:50:21 +030013362static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
13363 struct sigma_conn *conn,
13364 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053013365{
13366 struct wpa_ctrl *ctrl;
13367 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013368 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013369 const char *config_method = get_param(cmd, "WPSConfigMethod");
13370 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053013371 int res;
13372 char buf[256];
13373 const char *events[] = {
13374 "CTRL-EVENT-CONNECTED",
13375 "WPS-OVERLAP-DETECTED",
13376 "WPS-TIMEOUT",
13377 "WPS-FAIL",
13378 NULL
13379 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013380 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053013381
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013382 /* 60G WPS tests do not pass Interface parameter */
13383 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013384 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013385
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013386 if (dut->mode == SIGMA_MODE_AP)
13387 return ap_wps_registration(dut, conn, cmd);
13388
13389 if (config_method) {
13390 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
13391 * sta_wps_enter_pin before calling start_wps_registration. */
13392 if (strcasecmp(config_method, "PBC") == 0)
13393 dut->wps_method = WFA_CS_WPS_PBC;
13394 }
13395 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
13396 send_resp(dut, conn, SIGMA_ERROR,
13397 "ErrorCode,WPS parameters not yet set");
13398 return STATUS_SENT;
13399 }
13400
13401 /* Make sure WPS is enabled (also for STA mode) */
13402 dut->wps_disable = 0;
13403
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013404 if (dut->band == WPS_BAND_60G && network_mode &&
13405 strcasecmp(network_mode, "PBSS") == 0) {
13406 sigma_dut_print(dut, DUT_MSG_DEBUG,
13407 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013408 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013409 return -2;
13410 }
13411
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013412 if (dut->force_rsn_ie) {
13413 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
13414 dut->force_rsn_ie);
13415 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
13416 sigma_dut_print(dut, DUT_MSG_INFO,
13417 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020013418 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013419 }
13420 }
13421
vamsi krishna9b144002017-09-20 13:28:13 +053013422 ctrl = open_wpa_mon(intf);
13423 if (!ctrl) {
13424 sigma_dut_print(dut, DUT_MSG_ERROR,
13425 "Failed to open wpa_supplicant monitor connection");
13426 return -2;
13427 }
13428
13429 role = get_param(cmd, "WpsRole");
13430 if (!role) {
13431 send_resp(dut, conn, SIGMA_INVALID,
13432 "ErrorCode,WpsRole not provided");
13433 goto fail;
13434 }
13435
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013436 if (strcasecmp(role, "Enrollee") != 0) {
13437 /* Registrar role for STA not supported */
13438 send_resp(dut, conn, SIGMA_ERROR,
13439 "ErrorCode,Unsupported WpsRole value");
13440 goto fail;
13441 }
13442
13443 if (is_60g_sigma_dut(dut)) {
13444 if (dut->wps_method == WFA_CS_WPS_PBC)
13445 snprintf(buf, sizeof(buf), "WPS_PBC");
13446 else /* WFA_CS_WPS_PIN_KEYPAD */
13447 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
13448 dut->wps_pin);
13449 if (wpa_command(intf, buf) < 0) {
13450 send_resp(dut, conn, SIGMA_ERROR,
13451 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053013452 goto fail;
13453 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013454 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13455 if (res < 0) {
13456 send_resp(dut, conn, SIGMA_ERROR,
13457 "ErrorCode,WPS connection did not complete");
13458 goto fail;
13459 }
13460 if (strstr(buf, "WPS-TIMEOUT")) {
13461 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
13462 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13463 send_resp(dut, conn, SIGMA_COMPLETE,
13464 "WpsState,OverlapSession");
13465 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13466 send_resp(dut, conn, SIGMA_COMPLETE,
13467 "WpsState,Successful");
13468 } else {
13469 send_resp(dut, conn, SIGMA_COMPLETE,
13470 "WpsState,Failure");
13471 }
13472 } else {
13473 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053013474 if (wpa_command(intf, "WPS_PBC") < 0) {
13475 send_resp(dut, conn, SIGMA_ERROR,
13476 "ErrorCode,Failed to enable PBC");
13477 goto fail;
13478 }
13479 } else {
13480 /* TODO: PIN method */
13481 send_resp(dut, conn, SIGMA_ERROR,
13482 "ErrorCode,Unsupported WpsConfigMethod value");
13483 goto fail;
13484 }
13485 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13486 if (res < 0) {
13487 send_resp(dut, conn, SIGMA_ERROR,
13488 "ErrorCode,WPS connection did not complete");
13489 goto fail;
13490 }
13491 if (strstr(buf, "WPS-TIMEOUT")) {
13492 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
13493 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13494 send_resp(dut, conn, SIGMA_ERROR,
13495 "ErrorCode,OverlapSession");
13496 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13497 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
13498 } else {
13499 send_resp(dut, conn, SIGMA_ERROR,
13500 "ErrorCode,WPS operation failed");
13501 }
vamsi krishna9b144002017-09-20 13:28:13 +053013502 }
13503
13504fail:
13505 wpa_ctrl_detach(ctrl);
13506 wpa_ctrl_close(ctrl);
13507 return 0;
13508}
13509
13510
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013511static int req_intf(struct sigma_cmd *cmd)
13512{
13513 return get_param(cmd, "interface") == NULL ? -1 : 0;
13514}
13515
13516
13517void sta_register_cmds(void)
13518{
13519 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
13520 cmd_sta_get_ip_config);
13521 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
13522 cmd_sta_set_ip_config);
13523 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
13524 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
13525 cmd_sta_get_mac_address);
13526 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
13527 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
13528 cmd_sta_verify_ip_connection);
13529 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
13530 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
13531 cmd_sta_set_encryption);
13532 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
13533 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
13534 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
13535 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
13536 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
13537 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
13538 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
13539 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
13540 cmd_sta_set_eapakaprime);
13541 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
13542 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
13543 /* TODO: sta_set_ibss */
13544 /* TODO: sta_set_mode */
13545 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
13546 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
13547 /* TODO: sta_up_load */
13548 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
13549 cmd_sta_preset_testparameters);
13550 /* TODO: sta_set_system */
13551 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
13552 /* TODO: sta_set_rifs_test */
13553 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
13554 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
13555 /* TODO: sta_send_coexist_mgmt */
13556 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
13557 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
13558 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
13559 sigma_dut_reg_cmd("sta_reset_default", req_intf,
13560 cmd_sta_reset_default);
13561 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
13562 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
13563 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
13564 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
13565 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013566 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013567 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
13568 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
13569 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
13570 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
13571 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013572 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
13573 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013574 sigma_dut_reg_cmd("sta_add_credential", req_intf,
13575 cmd_sta_add_credential);
13576 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013577 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013578 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
13579 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
13580 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
13581 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
13582 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
13583 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030013584 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013585 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
13586 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013587 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053013588 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013589}