blob: d5b1736cbcfbac82f95cba11fcc5f660cd3bd6a9 [file] [log] [blame]
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001/*
2 * Sigma Control API DUT (station/AP)
3 * Copyright (c) 2010-2011, Atheros Communications, Inc.
Jouni Malinen9d7e31d2017-12-22 18:55:04 +02004 * Copyright (c) 2011-2017, Qualcomm Atheros, Inc.
Jouni Malinenc12ea4a2018-01-05 21:07:10 +02005 * Copyright (c) 2018, The Linux Foundation
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006 * All Rights Reserved.
7 * Licensed under the Clear BSD license. See README for more details.
8 */
9
10#include "sigma_dut.h"
11#include <sys/ioctl.h>
12#include <sys/stat.h>
Jouni Malinen82905202018-04-29 17:20:10 +030013#include <sys/wait.h>
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030014#include <ctype.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015#ifdef __linux__
Lior Davidcc88b562017-01-03 18:52:09 +020016#include <regex.h>
17#include <dirent.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020018#include <sys/time.h>
19#include <netpacket/packet.h>
20#include <linux/if_ether.h>
21#ifdef ANDROID
22#include <cutils/properties.h>
23#include <android/log.h>
24#include "keystore_get.h"
25#else /* ANDROID */
26#include <ifaddrs.h>
27#endif /* ANDROID */
28#include <netdb.h>
29#endif /* __linux__ */
30#ifdef __QNXNTO__
31#include <net/if_dl.h>
32#endif /* __QNXNTO__ */
33#include "wpa_ctrl.h"
34#include "wpa_helpers.h"
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070035#include "miracast.h"
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070036#include "qca-vendor_copy.h"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020037
38/* Temporary files for sta_send_addba */
39#define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp"
40#define VI_QOS_FILE "/tmp/vi-qos.txt"
41#define VI_QOS_REFFILE "/etc/vi-qos.txt"
42
43/*
44 * MTU for Ethernet need to take into account 8-byte SNAP header
45 * to be added when encapsulating Ethernet frame into 802.11
46 */
47#ifndef IEEE80211_MAX_DATA_LEN_DMG
48#define IEEE80211_MAX_DATA_LEN_DMG 7920
49#endif
50#ifndef IEEE80211_SNAP_LEN_DMG
51#define IEEE80211_SNAP_LEN_DMG 8
52#endif
53
Ashwini Patil00402582017-04-13 12:29:39 +053054#define NON_PREF_CH_LIST_SIZE 100
Ashwini Patil5acd7382017-04-13 15:55:04 +053055#define NEIGHBOR_REPORT_SIZE 1000
56#define DEFAULT_NEIGHBOR_BSSID_INFO "17"
57#define DEFAULT_NEIGHBOR_PHY_TYPE "1"
Ashwini Patil00402582017-04-13 12:29:39 +053058
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030059#define WIL_DEFAULT_BI 100
60
61/* default remain on channel time for transmitting frames (milliseconds) */
62#define WIL_TRANSMIT_FRAME_DEFAULT_ROC 500
63#define IEEE80211_P2P_ATTR_DEVICE_ID 3
64#define IEEE80211_P2P_ATTR_GROUP_ID 15
65
66/* describes tagged bytes in template frame file */
67struct template_frame_tag {
68 int num;
69 int offset;
70 size_t len;
71};
72
Jouni Malinencd4e3c32015-10-29 12:39:56 +020073extern char *sigma_wpas_ctrl;
74extern char *sigma_cert_path;
75extern enum driver_type wifi_chip_type;
76extern char *sigma_radio_ifname[];
77
Lior David0fe101e2017-03-09 16:09:50 +020078#ifdef __linux__
79#define WIL_WMI_MAX_PAYLOAD 248
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020080#define WIL_WMI_ESE_CFG_CMDID 0xa01
Lior David0fe101e2017-03-09 16:09:50 +020081#define WIL_WMI_BF_TRIG_CMDID 0x83a
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020082#define WIL_WMI_UNIT_TEST_CMDID 0x900
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030083#define WIL_WMI_P2P_CFG_CMDID 0x910
84#define WIL_WMI_START_LISTEN_CMDID 0x914
85#define WIL_WMI_DISCOVERY_STOP_CMDID 0x917
Lior David0fe101e2017-03-09 16:09:50 +020086
87struct wil_wmi_header {
88 uint8_t mid;
89 uint8_t reserved;
90 uint16_t cmd;
91 uint32_t ts;
92} __attribute__((packed));
93
94enum wil_wmi_bf_trig_type {
95 WIL_WMI_SLS,
96 WIL_WMI_BRP_RX,
97 WIL_WMI_BRP_TX,
98};
99
100struct wil_wmi_bf_trig_cmd {
101 /* enum wil_wmi_bf_trig_type */
102 uint32_t bf_type;
103 /* cid when type == WMI_BRP_RX */
104 uint32_t sta_id;
105 uint32_t reserved;
106 /* mac address when type = WIL_WMI_SLS */
107 uint8_t dest_mac[6];
108} __attribute__((packed));
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200109
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200110enum wil_wmi_sched_scheme_advertisment {
111 WIL_WMI_ADVERTISE_ESE_DISABLED,
112 WIL_WMI_ADVERTISE_ESE_IN_BEACON,
113 WIL_WMI_ADVERTISE_ESE_IN_ANNOUNCE_FRAME,
114};
115
116enum wil_wmi_ese_slot_type {
117 WIL_WMI_ESE_SP,
118 WIL_WMI_ESE_CBAP,
119 WIL_WMI_ESE_ANNOUNCE_NO_ACK,
120};
121
122struct wil_wmi_ese_slot {
123 /* offset from start of BI in microseconds */
124 uint32_t tbtt_offset;
125 uint8_t flags;
126 /* enum wil_wmi_ese_slot_type */
127 uint8_t slot_type;
128 /* duration in microseconds */
129 uint16_t duration;
130 /* frame exchange sequence duration, microseconds */
131 uint16_t tx_op;
132 /* time between 2 blocks for periodic allocation(microseconds) */
133 uint16_t period;
134 /* number of blocks in periodic allocation */
135 uint8_t num_blocks;
136 /* for semi-active allocations */
137 uint8_t idle_period;
138 uint8_t src_aid;
139 uint8_t dst_aid;
140 uint32_t reserved;
141} __attribute__((packed));
142
143#define WIL_WMI_MAX_ESE_SLOTS 4
144struct wil_wmi_ese_cfg {
145 uint8_t serial_num;
146 /* wil_wmi_sched_scheme_advertisment */
147 uint8_t ese_advertisment;
148 uint16_t flags;
149 uint8_t num_allocs;
150 uint8_t reserved[3];
151 uint64_t start_tbtt;
152 /* allocations list */
153 struct wil_wmi_ese_slot slots[WIL_WMI_MAX_ESE_SLOTS];
154} __attribute__((packed));
155
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200156#define WIL_WMI_UT_FORCE_MCS 6
157struct wil_wmi_force_mcs {
158 /* WIL_WMI_UT_HW_SYSAPI */
159 uint16_t module_id;
160 /* WIL_WMI_UT_FORCE_MCS */
161 uint16_t subtype_id;
162 /* cid (ignored in oob_mode, affects all stations) */
163 uint32_t cid;
164 /* 1 to force MCS, 0 to restore default behavior */
165 uint32_t force_enable;
166 /* MCS index, 0-12 */
167 uint32_t mcs;
168} __attribute__((packed));
169
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200170#define WIL_WMI_UT_HW_SYSAPI 10
171#define WIL_WMI_UT_FORCE_RSN_IE 0x29
172struct wil_wmi_force_rsn_ie {
173 /* WIL_WMI_UT_HW_SYSAPI */
174 uint16_t module_id;
175 /* WIL_WMI_UT_FORCE_RSN_IE */
176 uint16_t subtype_id;
177 /* 0 = no change, 1 = remove if exists, 2 = add if does not exist */
178 uint32_t state;
179} __attribute__((packed));
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300180
181enum wil_wmi_discovery_mode {
182 WMI_DISCOVERY_MODE_NON_OFFLOAD,
183 WMI_DISCOVERY_MODE_OFFLOAD,
184 WMI_DISCOVERY_MODE_PEER2PEER,
185};
186
187struct wil_wmi_p2p_cfg_cmd {
188 /* enum wil_wmi_discovery_mode */
189 uint8_t discovery_mode;
190 /* 0-based (wireless channel - 1) */
191 uint8_t channel;
192 /* set to WIL_DEFAULT_BI */
193 uint16_t bcon_interval;
194} __attribute__((packed));
Lior David0fe101e2017-03-09 16:09:50 +0200195#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200196
197#ifdef ANDROID
198
199static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname);
200
201#define ANDROID_KEYSTORE_GET 'g'
202#define ANDROID_KEYSTORE_GET_PUBKEY 'b'
203
204static int android_keystore_get(char cmd, const char *key, unsigned char *val)
205{
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200206 /* Android 4.3 changed keystore design, so need to use keystore_get() */
207#ifndef KEYSTORE_MESSAGE_SIZE
208#define KEYSTORE_MESSAGE_SIZE 65535
209#endif /* KEYSTORE_MESSAGE_SIZE */
210
211 ssize_t len;
212 uint8_t *value = NULL;
213
214 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
215 "keystore command '%c' key '%s' --> keystore_get",
216 cmd, key);
217
218 len = keystore_get(key, strlen(key), &value);
219 if (len < 0) {
220 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
221 "keystore_get() failed");
222 return -1;
223 }
224
225 if (len > KEYSTORE_MESSAGE_SIZE)
226 len = KEYSTORE_MESSAGE_SIZE;
227 memcpy(val, value, len);
228 free(value);
229 return len;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200230}
231#endif /* ANDROID */
232
233
Vinita S. Maloo0fcb57d2020-04-24 14:03:56 +0530234#ifdef NL80211_SUPPORT
235static int nl80211_sta_set_power_save(struct sigma_dut *dut,
236 const char *intf,
237 enum nl80211_ps_state ps_state)
238{
239 struct nl_msg *msg;
240 int ifindex, ret;
241
242 ifindex = if_nametoindex(intf);
243 if (ifindex == 0) {
244 sigma_dut_print(dut, DUT_MSG_ERROR,
245 "%s: Index for interface %s not found",
246 __func__, intf);
247 return -1;
248 }
249
250 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
251 NL80211_CMD_SET_POWER_SAVE);
252 if (!msg) {
253 sigma_dut_print(dut, DUT_MSG_ERROR,
254 "%s: err in creating nl80211 msg", __func__);
255 return -1;
256 }
257
258 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) {
259 sigma_dut_print(dut, DUT_MSG_ERROR,
260 "%s: err in populating nl80211 msg", __func__);
261 nlmsg_free(msg);
262 return -1;
263 }
264
265 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
266 if (ret) {
267 sigma_dut_print(dut, DUT_MSG_ERROR,
268 "%s: err in send_and_recv_msgs, ret=%d (%s)",
269 __func__, ret, strerror(-ret));
270 return -1;
271 }
272
273 return 0;
274}
275#endif /* NL80211_SUPPORT */
276
277
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530278static int set_power_save_wcn(struct sigma_dut *dut, const char *intf, int ps)
279{
280 char buf[100];
Vinita S. Maloo0fcb57d2020-04-24 14:03:56 +0530281#ifdef NL80211_SUPPORT
282 enum nl80211_ps_state ps_state;
283
284 ps_state = ps == 1 ? NL80211_PS_ENABLED : NL80211_PS_DISABLED;
285 if (nl80211_sta_set_power_save(dut, intf, ps_state) == 0)
286 return 0;
287#endif /* NL80211_SUPPORT */
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530288
289 snprintf(buf, sizeof(buf), "iwpriv %s setPower %d", intf, ps);
290 if (system(buf) != 0) {
291 sigma_dut_print(dut, DUT_MSG_ERROR,
292 "iwpriv setPower %d failed", ps);
293 return -1;
294 }
295 return 0;
296}
297
298
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200299int set_ps(const char *intf, struct sigma_dut *dut, int enabled)
300{
301#ifdef __linux__
302 char buf[100];
303
304 if (wifi_chip_type == DRIVER_WCN) {
305 if (enabled) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530306 if (set_power_save_wcn(dut, intf, 1) < 0) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530307 snprintf(buf, sizeof(buf),
308 "iwpriv wlan0 dump 906");
309 if (system(buf) != 0)
310 goto set_power_save;
311 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200312 } else {
Vinita S. Malooa8b62722020-04-23 01:45:41 +0530313 if (set_power_save_wcn(dut, intf, 2) < 0) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530314 snprintf(buf, sizeof(buf),
315 "iwpriv wlan0 dump 905");
316 if (system(buf) != 0)
317 goto set_power_save;
318 snprintf(buf, sizeof(buf),
319 "iwpriv wlan0 dump 912");
320 if (system(buf) != 0)
321 goto set_power_save;
322 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200323 }
324
325 return 0;
326 }
327
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530328set_power_save:
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200329 snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s",
330 intf, enabled ? "on" : "off");
331 if (system(buf) != 0) {
332 snprintf(buf, sizeof(buf), "iw dev %s set power_save %s",
333 intf, enabled ? "on" : "off");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530334 if (system(buf) != 0) {
335 sigma_dut_print(dut, DUT_MSG_ERROR,
336 "Failed to set power save %s",
337 enabled ? "on" : "off");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200338 return -1;
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530339 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200340 }
341
342 return 0;
343#else /* __linux__ */
344 return -1;
345#endif /* __linux__ */
346}
347
348
Lior Davidcc88b562017-01-03 18:52:09 +0200349#ifdef __linux__
Lior David0fe101e2017-03-09 16:09:50 +0200350
Lior Davidcc88b562017-01-03 18:52:09 +0200351static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path,
352 size_t len)
353{
354 DIR *dir, *wil_dir;
355 struct dirent *entry;
356 int ret = -1;
357 const char *root_path = "/sys/kernel/debug/ieee80211";
358
359 dir = opendir(root_path);
360 if (!dir)
361 return -2;
362
363 while ((entry = readdir(dir))) {
364 if (strcmp(entry->d_name, ".") == 0 ||
365 strcmp(entry->d_name, "..") == 0)
366 continue;
367
368 if (snprintf(path, len, "%s/%s/wil6210",
369 root_path, entry->d_name) >= (int) len) {
370 ret = -3;
371 break;
372 }
373
374 wil_dir = opendir(path);
375 if (wil_dir) {
376 closedir(wil_dir);
377 ret = 0;
378 break;
379 }
380 }
381
382 closedir(dir);
383 return ret;
384}
Lior David0fe101e2017-03-09 16:09:50 +0200385
386
387static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command,
388 void *payload, uint16_t length)
389{
390 struct {
391 struct wil_wmi_header hdr;
392 char payload[WIL_WMI_MAX_PAYLOAD];
393 } __attribute__((packed)) cmd;
394 char buf[128], fname[128];
395 size_t towrite, written;
396 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300397 int res;
Lior David0fe101e2017-03-09 16:09:50 +0200398
399 if (length > WIL_WMI_MAX_PAYLOAD) {
400 sigma_dut_print(dut, DUT_MSG_ERROR,
401 "payload too large(%u, max %u)",
402 length, WIL_WMI_MAX_PAYLOAD);
403 return -1;
404 }
405
406 memset(&cmd.hdr, 0, sizeof(cmd.hdr));
407 cmd.hdr.cmd = command;
408 memcpy(cmd.payload, payload, length);
409
410 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
411 sigma_dut_print(dut, DUT_MSG_ERROR,
412 "failed to get wil6210 debugfs dir");
413 return -1;
414 }
415
Jouni Malinen3aa72862019-05-29 23:14:51 +0300416 res = snprintf(fname, sizeof(fname), "%s/wmi_send", buf);
417 if (res < 0 || res >= sizeof(fname))
418 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200419 f = fopen(fname, "wb");
420 if (!f) {
421 sigma_dut_print(dut, DUT_MSG_ERROR,
422 "failed to open: %s", fname);
423 return -1;
424 }
425
426 towrite = sizeof(cmd.hdr) + length;
427 written = fwrite(&cmd, 1, towrite, f);
428 fclose(f);
429 if (written != towrite) {
430 sigma_dut_print(dut, DUT_MSG_ERROR,
431 "failed to send wmi %u", command);
432 return -1;
433 }
434
435 return 0;
436}
437
438
439static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid,
440 const char *pattern, unsigned int *field)
441{
442 char buf[128], fname[128];
443 FILE *f;
444 regex_t re;
445 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +0300446 int rc, ret = -1, res;
Lior David0fe101e2017-03-09 16:09:50 +0200447
448 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
449 sigma_dut_print(dut, DUT_MSG_ERROR,
450 "failed to get wil6210 debugfs dir");
451 return -1;
452 }
453
Jouni Malinen3aa72862019-05-29 23:14:51 +0300454 res = snprintf(fname, sizeof(fname), "%s/stations", buf);
455 if (res < 0 || res >= sizeof(fname))
456 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200457 f = fopen(fname, "r");
458 if (!f) {
459 sigma_dut_print(dut, DUT_MSG_ERROR,
460 "failed to open: %s", fname);
461 return -1;
462 }
463
464 if (regcomp(&re, pattern, REG_EXTENDED)) {
465 sigma_dut_print(dut, DUT_MSG_ERROR,
466 "regcomp failed: %s", pattern);
467 goto out;
468 }
469
470 /*
471 * find the entry for the mac address
472 * line is of the form: [n] 11:22:33:44:55:66 state AID aid
473 */
474 while (fgets(buf, sizeof(buf), f)) {
475 if (strcasestr(buf, bssid)) {
476 /* extract the field (CID/AID/state) */
477 rc = regexec(&re, buf, 2, m, 0);
478 if (!rc && (m[1].rm_so >= 0)) {
479 buf[m[1].rm_eo] = 0;
480 *field = atoi(&buf[m[1].rm_so]);
481 ret = 0;
482 break;
483 }
484 }
485 }
486
487 regfree(&re);
488 if (ret)
489 sigma_dut_print(dut, DUT_MSG_ERROR,
490 "could not extract field");
491
492out:
493 fclose(f);
494
495 return ret;
496}
497
498
499static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid,
500 unsigned int *cid)
501{
502 const char *pattern = "\\[([0-9]+)\\]";
503
504 return wil6210_get_sta_info_field(dut, bssid, pattern, cid);
505}
506
507
508static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac,
509 int l_rx)
510{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700511 struct wil_wmi_bf_trig_cmd cmd;
Lior David0fe101e2017-03-09 16:09:50 +0200512 unsigned int cid;
513
Rakesh Sunki556237d2017-03-30 14:49:31 -0700514 memset(&cmd, 0, sizeof(cmd));
515
Lior David0fe101e2017-03-09 16:09:50 +0200516 if (wil6210_get_cid(dut, mac, &cid))
517 return -1;
518
519 cmd.bf_type = WIL_WMI_BRP_RX;
520 cmd.sta_id = cid;
521 /* training length (l_rx) is ignored, FW always uses length 16 */
522 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
523 &cmd, sizeof(cmd));
524}
525
526
527static int wil6210_send_sls(struct sigma_dut *dut, const char *mac)
528{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700529 struct wil_wmi_bf_trig_cmd cmd;
530
531 memset(&cmd, 0, sizeof(cmd));
Lior David0fe101e2017-03-09 16:09:50 +0200532
533 if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac))
534 return -1;
535
536 cmd.bf_type = WIL_WMI_SLS;
537 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
538 &cmd, sizeof(cmd));
539}
540
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200541
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200542int wil6210_set_ese(struct sigma_dut *dut, int count,
543 struct sigma_ese_alloc *allocs)
544{
545 struct wil_wmi_ese_cfg cmd = { };
546 int i;
547
548 if (count == 0 || count > WIL_WMI_MAX_ESE_SLOTS)
549 return -1;
550
551 if (dut->ap_bcnint <= 0) {
552 sigma_dut_print(dut, DUT_MSG_ERROR,
553 "invalid beacon interval(%d), check test",
554 dut->ap_bcnint);
555 return -1;
556 }
557
558 cmd.ese_advertisment = WIL_WMI_ADVERTISE_ESE_IN_BEACON;
559 cmd.flags = 0x1d;
560 cmd.num_allocs = count;
561 for (i = 0; i < count; i++) {
562 /*
563 * Convert percent from BI (BI specified in milliseconds)
564 * to absolute duration in microseconds.
565 */
566 cmd.slots[i].duration =
567 (allocs[i].percent_bi * dut->ap_bcnint * 1000) / 100;
568 switch (allocs[i].type) {
569 case ESE_CBAP:
570 cmd.slots[i].slot_type = WIL_WMI_ESE_CBAP;
571 break;
572 case ESE_SP:
573 cmd.slots[i].slot_type = WIL_WMI_ESE_SP;
574 break;
575 default:
576 sigma_dut_print(dut, DUT_MSG_ERROR,
577 "invalid slot type(%d) at index %d",
578 allocs[i].type, i);
579 return -1;
580 }
581 cmd.slots[i].src_aid = allocs[i].src_aid;
582 cmd.slots[i].dst_aid = allocs[i].dst_aid;
583 sigma_dut_print(dut, DUT_MSG_INFO,
584 "slot %d, duration %u, type %d, srcAID %u dstAID %u",
585 i, cmd.slots[i].duration,
586 cmd.slots[i].slot_type, cmd.slots[i].src_aid,
587 cmd.slots[i].dst_aid);
588 }
589
590 return wil6210_wmi_send(dut, WIL_WMI_ESE_CFG_CMDID, &cmd, sizeof(cmd));
591}
592
593
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200594int wil6210_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
595{
596 struct wil_wmi_force_mcs cmd = { };
597
598 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
599 cmd.subtype_id = WIL_WMI_UT_FORCE_MCS;
600 cmd.force_enable = (uint32_t) force;
601 cmd.mcs = (uint32_t) mcs;
602
603 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
604 &cmd, sizeof(cmd));
605}
606
607
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200608static int wil6210_force_rsn_ie(struct sigma_dut *dut, int state)
609{
610 struct wil_wmi_force_rsn_ie cmd = { };
611
612 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
613 cmd.subtype_id = WIL_WMI_UT_FORCE_RSN_IE;
614 cmd.state = (uint32_t) state;
615
616 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
617 &cmd, sizeof(cmd));
618}
619
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300620
621/*
622 * this function is also used to configure generic remain-on-channel
623 */
624static int wil6210_p2p_cfg(struct sigma_dut *dut, int freq)
625{
626 struct wil_wmi_p2p_cfg_cmd cmd = { };
627 int channel = freq_to_channel(freq);
628
629 if (channel < 0)
630 return -1;
631 cmd.discovery_mode = WMI_DISCOVERY_MODE_NON_OFFLOAD;
632 cmd.channel = channel - 1;
633 cmd.bcon_interval = WIL_DEFAULT_BI;
634 cmd.discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER;
635
636 return wil6210_wmi_send(dut, WIL_WMI_P2P_CFG_CMDID,
637 &cmd, sizeof(cmd));
638}
639
640
641static int wil6210_remain_on_channel(struct sigma_dut *dut, int freq)
642{
643 int ret = wil6210_p2p_cfg(dut, freq);
644
645 if (ret)
646 return ret;
647
648 ret = wil6210_wmi_send(dut, WIL_WMI_START_LISTEN_CMDID, NULL, 0);
649 if (!ret) {
650 /*
651 * wait a bit to allow FW to setup the radio
652 * especially important if we switch channels
653 */
654 usleep(500000);
655 }
656
657 return ret;
658}
659
660
661static int wil6210_stop_discovery(struct sigma_dut *dut)
662{
663 return wil6210_wmi_send(dut, WIL_WMI_DISCOVERY_STOP_CMDID, NULL, 0);
664}
665
666
667static int wil6210_transmit_frame(struct sigma_dut *dut, int freq,
668 int wait_duration,
669 const char *frame, size_t frame_len)
670{
671 char buf[128], fname[128];
672 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300673 int res = 0, r;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300674 size_t written;
675
676 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
677 sigma_dut_print(dut, DUT_MSG_ERROR,
678 "failed to get wil6210 debugfs dir");
679 return -1;
680 }
Jouni Malinen3aa72862019-05-29 23:14:51 +0300681 r = snprintf(fname, sizeof(fname), "%s/tx_mgmt", buf);
682 if (r < 0 || r >= sizeof(fname))
683 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300684
685 if (wil6210_remain_on_channel(dut, freq)) {
686 sigma_dut_print(dut, DUT_MSG_ERROR,
687 "failed to listen on channel");
688 return -1;
689 }
690
691 f = fopen(fname, "wb");
692 if (!f) {
693 sigma_dut_print(dut, DUT_MSG_ERROR,
694 "failed to open: %s", fname);
695 res = -1;
696 goto out_stop;
697 }
698 written = fwrite(frame, 1, frame_len, f);
699 fclose(f);
700
701 if (written != frame_len) {
702 sigma_dut_print(dut, DUT_MSG_ERROR,
703 "failed to transmit frame (got %zd, expected %zd)",
704 written, frame_len);
705 res = -1;
706 goto out_stop;
707 }
708
709 usleep(wait_duration * 1000);
710
711out_stop:
712 wil6210_stop_discovery(dut);
713 return res;
714}
715
716
717static int find_template_frame_tag(struct template_frame_tag *tags,
718 int total_tags, int tag_num)
719{
720 int i;
721
722 for (i = 0; i < total_tags; i++) {
723 if (tag_num == tags[i].num)
724 return i;
725 }
726
727 return -1;
728}
729
730
731static int replace_p2p_attribute(struct sigma_dut *dut, char *buf, size_t len,
732 int id, const char *value, size_t val_len)
733{
734 struct wfa_p2p_attribute *attr = (struct wfa_p2p_attribute *) buf;
735
736 if (len < 3 + val_len) {
737 sigma_dut_print(dut, DUT_MSG_ERROR,
738 "not enough space to replace P2P attribute");
739 return -1;
740 }
741
742 if (attr->len != val_len) {
743 sigma_dut_print(dut, DUT_MSG_ERROR,
744 "attribute length mismatch (need %zu have %hu)",
745 val_len, attr->len);
746 return -1;
747 }
748
749 if (attr->id != id) {
750 sigma_dut_print(dut, DUT_MSG_ERROR,
751 "incorrect attribute id (expected %d actual %d)",
752 id, attr->id);
753 return -1;
754 }
755
756 memcpy(attr->variable, value, val_len);
757
758 return 0;
759}
760
761
762static int parse_template_frame_file(struct sigma_dut *dut, const char *fname,
763 char *buf, size_t *length,
764 struct template_frame_tag *tags,
765 size_t *num_tags)
766{
767 char line[512];
768 FILE *f;
769 size_t offset = 0, tag_index = 0;
770 int num, index;
771 int in_tag = 0, tag_num = 0, tag_offset = 0;
772
773 if (*length < sizeof(struct ieee80211_hdr_3addr)) {
774 sigma_dut_print(dut, DUT_MSG_ERROR,
775 "supplied buffer is too small");
776 return -1;
777 }
778
779 f = fopen(fname, "r");
780 if (!f) {
781 sigma_dut_print(dut, DUT_MSG_ERROR,
782 "failed to open template file %s", fname);
783 return -1;
784 }
785
786 /*
787 * template file format: lines beginning with # are comments and
788 * ignored.
789 * It is possible to tag bytes in the frame to make it easy
790 * to replace fields in the template, espcially if they appear
791 * in variable-sized sections (such as IEs)
792 * This is done by a line beginning with $NUM where NUM is an integer
793 * tag number. It can be followed by space(s) and comment.
794 * The next line is considered the tagged bytes. The parser will fill
795 * the tag number, offset and length of the tagged bytes.
796 * rest of the lines contain frame bytes as sequence of hex digits,
797 * 2 digits for each byte. Spaces are allowed between bytes.
798 * On bytes lines only hex digits and spaces are allowed
799 */
800 while (!feof(f)) {
801 if (!fgets(line, sizeof(line), f))
802 break;
803 index = 0;
804 while (isspace((unsigned char) line[index]))
805 index++;
806 if (!line[index] || line[index] == '#')
807 continue;
808 if (line[index] == '$') {
809 if (tags) {
810 index++;
811 tag_num = strtol(&line[index], NULL, 0);
812 tag_offset = offset;
813 in_tag = 1;
814 }
815 continue;
816 }
817 while (line[index]) {
818 if (isspace((unsigned char) line[index])) {
819 index++;
820 continue;
821 }
822 num = hex_byte(&line[index]);
823 if (num < 0)
824 break;
825 buf[offset++] = num;
826 if (offset == *length)
827 goto out;
828 index += 2;
829 }
830
831 if (in_tag) {
832 if (tag_index < *num_tags) {
833 tags[tag_index].num = tag_num;
834 tags[tag_index].offset = tag_offset;
835 tags[tag_index].len = offset - tag_offset;
836 tag_index++;
837 } else {
838 sigma_dut_print(dut, DUT_MSG_INFO,
839 "too many tags, tag ignored");
840 }
841 in_tag = 0;
842 }
843 }
844
845 if (num_tags)
846 *num_tags = tag_index;
847out:
848 fclose(f);
849 if (offset < sizeof(struct ieee80211_hdr_3addr)) {
850 sigma_dut_print(dut, DUT_MSG_ERROR,
851 "template frame is too small");
852 return -1;
853 }
854
855 *length = offset;
856 return 0;
857}
858
Lior Davidcc88b562017-01-03 18:52:09 +0200859#endif /* __linux__ */
860
861
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200862static void static_ip_file(int proto, const char *addr, const char *mask,
863 const char *gw)
864{
865 if (proto) {
866 FILE *f = fopen("static-ip", "w");
867 if (f) {
868 fprintf(f, "%d %s %s %s\n", proto, addr,
869 mask ? mask : "N/A",
870 gw ? gw : "N/A");
871 fclose(f);
872 }
873 } else {
874 unlink("static-ip");
875 }
876}
877
878
879static int send_neighbor_request(struct sigma_dut *dut, const char *intf,
880 const char *ssid)
881{
882#ifdef __linux__
883 char buf[100];
884
885 snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s",
886 intf, ssid);
887 sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf);
888
889 if (system(buf) != 0) {
890 sigma_dut_print(dut, DUT_MSG_ERROR,
891 "iwpriv neighbor request failed");
892 return -1;
893 }
894
895 sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send");
896
897 return 0;
898#else /* __linux__ */
899 return -1;
900#endif /* __linux__ */
901}
902
903
904static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf,
Ashwini Patil5acd7382017-04-13 15:55:04 +0530905 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200906{
Ashwini Patil5acd7382017-04-13 15:55:04 +0530907 const char *val;
908 int reason_code = 0;
909 char buf[1024];
910
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200911 /*
912 * In the earlier builds we used WNM_QUERY and in later
913 * builds used WNM_BSS_QUERY.
914 */
915
Ashwini Patil5acd7382017-04-13 15:55:04 +0530916 val = get_param(cmd, "BTMQuery_Reason_Code");
917 if (val)
918 reason_code = atoi(val);
919
920 val = get_param(cmd, "Cand_List");
921 if (val && atoi(val) == 1 && dut->btm_query_cand_list) {
922 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code,
923 dut->btm_query_cand_list);
924 free(dut->btm_query_cand_list);
925 dut->btm_query_cand_list = NULL;
926 } else {
927 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code);
928 }
929
930 if (wpa_command(intf, buf) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200931 sigma_dut_print(dut, DUT_MSG_ERROR,
932 "transition management query failed");
933 return -1;
934 }
935
936 sigma_dut_print(dut, DUT_MSG_DEBUG,
937 "transition management query sent");
938
939 return 0;
940}
941
942
943int is_ip_addr(const char *str)
944{
945 const char *pos = str;
946 struct in_addr addr;
947
948 while (*pos) {
949 if (*pos != '.' && (*pos < '0' || *pos > '9'))
950 return 0;
951 pos++;
952 }
953
954 return inet_aton(str, &addr);
955}
956
957
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200958int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
959 size_t buf_len)
960{
vamsi krishnaa11d0732018-05-16 12:19:48 +0530961 char tmp[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200962 char ip[16], mask[15], dns[16], sec_dns[16];
963 int is_dhcp = 0;
964 int s;
965#ifdef ANDROID
966 char prop[PROPERTY_VALUE_MAX];
vamsi krishnaa11d0732018-05-16 12:19:48 +0530967#else /* ANDROID */
968 FILE *f;
969#ifdef __linux__
970 const char *str_ps;
971#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200972#endif /* ANDROID */
973
974 ip[0] = '\0';
975 mask[0] = '\0';
976 dns[0] = '\0';
977 sec_dns[0] = '\0';
978
979 s = socket(PF_INET, SOCK_DGRAM, 0);
980 if (s >= 0) {
981 struct ifreq ifr;
982 struct sockaddr_in saddr;
983
984 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700985 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200986 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
987 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
988 "%s IP address: %s",
989 ifname, strerror(errno));
990 } else {
991 memcpy(&saddr, &ifr.ifr_addr,
992 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700993 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200994 }
995
996 if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) {
997 memcpy(&saddr, &ifr.ifr_addr,
998 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700999 strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001000 }
1001 close(s);
1002 }
1003
1004#ifdef ANDROID
1005 snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname);
1006 if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) {
1007 snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname);
1008 if (property_get(tmp, prop, NULL) != 0 &&
1009 strcmp(prop, "ok") == 0) {
1010 snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress",
1011 ifname);
1012 if (property_get(tmp, prop, NULL) != 0 &&
1013 strcmp(ip, prop) == 0)
1014 is_dhcp = 1;
1015 }
1016 }
1017
1018 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -07001019 if (property_get(tmp, prop, NULL) != 0)
1020 strlcpy(dns, prop, sizeof(dns));
1021 else if (property_get("net.dns1", prop, NULL) != 0)
1022 strlcpy(dns, prop, sizeof(dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001023
1024 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -07001025 if (property_get(tmp, prop, NULL) != 0)
1026 strlcpy(sec_dns, prop, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001027#else /* ANDROID */
1028#ifdef __linux__
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001029 if (get_driver_type(dut) == DRIVER_OPENWRT)
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301030 str_ps = "ps -w";
1031 else
1032 str_ps = "ps ax";
1033 snprintf(tmp, sizeof(tmp),
1034 "%s | grep dhclient | grep -v grep | grep -q %s",
1035 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001036 if (system(tmp) == 0)
1037 is_dhcp = 1;
1038 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301039 snprintf(tmp, sizeof(tmp),
1040 "%s | grep udhcpc | grep -v grep | grep -q %s",
1041 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001042 if (system(tmp) == 0)
1043 is_dhcp = 1;
1044 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +05301045 snprintf(tmp, sizeof(tmp),
1046 "%s | grep dhcpcd | grep -v grep | grep -q %s",
1047 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001048 if (system(tmp) == 0)
1049 is_dhcp = 1;
1050 }
1051 }
1052#endif /* __linux__ */
1053
1054 f = fopen("/etc/resolv.conf", "r");
1055 if (f) {
vamsi krishnaa11d0732018-05-16 12:19:48 +05301056 char *pos, *pos2;
1057
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001058 while (fgets(tmp, sizeof(tmp), f)) {
1059 if (strncmp(tmp, "nameserver", 10) != 0)
1060 continue;
1061 pos = tmp + 10;
1062 while (*pos == ' ' || *pos == '\t')
1063 pos++;
1064 pos2 = pos;
1065 while (*pos2) {
1066 if (*pos2 == '\n' || *pos2 == '\r') {
1067 *pos2 = '\0';
1068 break;
1069 }
1070 pos2++;
1071 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07001072 if (!dns[0])
1073 strlcpy(dns, pos, sizeof(dns));
1074 else if (!sec_dns[0])
1075 strlcpy(sec_dns, pos, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001076 }
1077 fclose(f);
1078 }
1079#endif /* ANDROID */
1080
1081 snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s",
1082 is_dhcp, ip, mask, dns);
1083 buf[buf_len - 1] = '\0';
1084
1085 return 0;
1086}
1087
1088
1089
1090
1091int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf,
1092 size_t buf_len)
1093{
1094#ifdef __linux__
1095#ifdef ANDROID
1096 char cmd[200], result[1000], *pos, *end;
1097 FILE *f;
1098 size_t len;
1099
1100 snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname);
1101 f = popen(cmd, "r");
1102 if (f == NULL)
1103 return -1;
1104 len = fread(result, 1, sizeof(result) - 1, f);
1105 pclose(f);
1106 if (len == 0)
1107 return -1;
1108 result[len] = '\0';
1109 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result);
1110
1111 pos = strstr(result, "inet6 ");
1112 if (pos == NULL)
1113 return -1;
1114 pos += 6;
1115 end = strchr(pos, ' ');
1116 if (end)
1117 *end = '\0';
1118 end = strchr(pos, '/');
1119 if (end)
1120 *end = '\0';
1121 snprintf(buf, buf_len, "ip,%s", pos);
1122 buf[buf_len - 1] = '\0';
1123 return 0;
1124#else /* ANDROID */
1125 struct ifaddrs *ifaddr, *ifa;
1126 int res, found = 0;
1127 char host[NI_MAXHOST];
1128
1129 if (getifaddrs(&ifaddr) < 0) {
1130 perror("getifaddrs");
1131 return -1;
1132 }
1133
1134 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
1135 if (strcasecmp(ifname, ifa->ifa_name) != 0)
1136 continue;
1137 if (ifa->ifa_addr == NULL ||
1138 ifa->ifa_addr->sa_family != AF_INET6)
1139 continue;
1140
1141 res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
1142 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
1143 if (res != 0) {
1144 sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s",
1145 gai_strerror(res));
1146 continue;
1147 }
1148 if (strncmp(host, "fe80::", 6) == 0)
1149 continue; /* skip link-local */
1150
1151 sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host);
1152 found = 1;
1153 break;
1154 }
1155
1156 freeifaddrs(ifaddr);
1157
1158 if (found) {
1159 char *pos;
1160 pos = strchr(host, '%');
1161 if (pos)
1162 *pos = '\0';
1163 snprintf(buf, buf_len, "ip,%s", host);
1164 buf[buf_len - 1] = '\0';
1165 return 0;
1166 }
1167
1168#endif /* ANDROID */
1169#endif /* __linux__ */
1170 return -1;
1171}
1172
1173
Jouni Malinenf7222712019-06-13 01:50:21 +03001174static enum sigma_cmd_result cmd_sta_get_ip_config(struct sigma_dut *dut,
1175 struct sigma_conn *conn,
1176 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001177{
1178 const char *intf = get_param(cmd, "Interface");
1179 const char *ifname;
1180 char buf[200];
1181 const char *val;
1182 int type = 1;
1183
1184 if (intf == NULL)
1185 return -1;
1186
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001187 if (strcmp(intf, get_main_ifname(dut)) == 0)
1188 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001189 else
1190 ifname = intf;
1191
1192 /*
1193 * UCC may assume the IP address to be available immediately after
1194 * association without trying to run sta_get_ip_config multiple times.
1195 * Sigma CAPI does not specify this command as a block command that
1196 * would wait for the address to become available, but to pass tests
1197 * more reliably, it looks like such a wait may be needed here.
1198 */
1199 if (wait_ip_addr(dut, ifname, 15) < 0) {
1200 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address "
1201 "for sta_get_ip_config");
1202 /*
1203 * Try to continue anyway since many UCC tests do not really
1204 * care about the return value from here..
1205 */
1206 }
1207
1208 val = get_param(cmd, "Type");
1209 if (val)
1210 type = atoi(val);
1211 if (type == 2 || dut->last_set_ip_config_ipv6) {
1212 int i;
1213
1214 /*
1215 * Since we do not have proper wait for IPv6 addresses, use a
1216 * fixed two second delay here as a workaround for UCC script
1217 * assuming IPv6 address is available when this command returns.
1218 * Some scripts did not use Type,2 properly for IPv6, so include
1219 * also the cases where the previous sta_set_ip_config indicated
1220 * use of IPv6.
1221 */
1222 sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address");
1223 for (i = 0; i < 10; i++) {
1224 sleep(1);
1225 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0)
1226 {
1227 sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address");
1228 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1229#ifdef ANDROID
1230 sigma_dut_print(dut, DUT_MSG_INFO,
1231 "Adding IPv6 rule on Android");
1232 add_ipv6_rule(dut, intf);
1233#endif /* ANDROID */
1234
1235 return 0;
1236 }
1237 }
1238 }
1239 if (type == 1) {
1240 if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0)
1241 return -2;
1242 } else if (type == 2) {
1243 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0)
1244 return -2;
1245 } else {
1246 send_resp(dut, conn, SIGMA_ERROR,
1247 "errorCode,Unsupported address type");
1248 return 0;
1249 }
1250
1251 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1252 return 0;
1253}
1254
1255
1256static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname)
1257{
1258#ifdef __linux__
1259 char buf[200];
1260 char path[128];
1261 struct stat s;
1262
1263#ifdef ANDROID
1264 snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname);
1265#else /* ANDROID */
1266 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname);
1267#endif /* ANDROID */
1268 if (stat(path, &s) == 0) {
1269 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1270 sigma_dut_print(dut, DUT_MSG_INFO,
1271 "Kill previous DHCP client: %s", buf);
1272 if (system(buf) != 0)
1273 sigma_dut_print(dut, DUT_MSG_INFO,
1274 "Failed to kill DHCP client");
1275 unlink(path);
1276 sleep(1);
1277 } else {
1278 snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname);
1279
1280 if (stat(path, &s) == 0) {
1281 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1282 sigma_dut_print(dut, DUT_MSG_INFO,
1283 "Kill previous DHCP client: %s", buf);
1284 if (system(buf) != 0)
1285 sigma_dut_print(dut, DUT_MSG_INFO,
1286 "Failed to kill DHCP client");
1287 unlink(path);
1288 sleep(1);
1289 }
1290 }
1291#endif /* __linux__ */
1292}
1293
1294
1295static int start_dhcp_client(struct sigma_dut *dut, const char *ifname)
1296{
1297#ifdef __linux__
1298 char buf[200];
1299
1300#ifdef ANDROID
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301301 if (access("/system/bin/dhcpcd", F_OK) != -1) {
1302 snprintf(buf, sizeof(buf),
1303 "/system/bin/dhcpcd -b %s", ifname);
1304 } else if (access("/system/bin/dhcptool", F_OK) != -1) {
1305 snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname);
Ankita Bajaj8454e5d2019-04-05 16:04:55 +05301306 } else if (access("/vendor/bin/dhcpcd", F_OK) != -1) {
1307 snprintf(buf, sizeof(buf), "/vendor/bin/dhcpcd -b %s", ifname);
1308 } else if (access("/vendor/bin/dhcptool", F_OK) != -1) {
1309 snprintf(buf, sizeof(buf), "/vendor/bin/dhcptool %s", ifname);
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301310 } else {
1311 sigma_dut_print(dut, DUT_MSG_ERROR,
1312 "DHCP client program missing");
1313 return 0;
1314 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001315#else /* ANDROID */
1316 snprintf(buf, sizeof(buf),
1317 "dhclient -nw -pf /var/run/dhclient-%s.pid %s",
1318 ifname, ifname);
1319#endif /* ANDROID */
1320 sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf);
1321 if (system(buf) != 0) {
1322 snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname);
1323 if (system(buf) != 0) {
1324 sigma_dut_print(dut, DUT_MSG_INFO,
1325 "Failed to start DHCP client");
1326#ifndef ANDROID
1327 return -1;
1328#endif /* ANDROID */
1329 }
1330 }
1331#endif /* __linux__ */
1332
1333 return 0;
1334}
1335
1336
1337static int clear_ip_addr(struct sigma_dut *dut, const char *ifname)
1338{
1339#ifdef __linux__
1340 char buf[200];
1341
1342 snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname);
1343 if (system(buf) != 0) {
1344 sigma_dut_print(dut, DUT_MSG_INFO,
1345 "Failed to clear IP addresses");
1346 return -1;
1347 }
1348#endif /* __linux__ */
1349
1350 return 0;
1351}
1352
1353
1354#ifdef ANDROID
1355static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname)
1356{
1357 char cmd[200], *result, *pos;
1358 FILE *fp;
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301359 int tableid;
1360 size_t len, result_len = 1000;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001361
1362 snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s",
1363 ifname);
1364 fp = popen(cmd, "r");
1365 if (fp == NULL)
1366 return -1;
1367
1368 result = malloc(result_len);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301369 if (result == NULL) {
1370 fclose(fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001371 return -1;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301372 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001373
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301374 len = fread(result, 1, result_len - 1, fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001375 fclose(fp);
1376
1377 if (len == 0) {
1378 free(result);
1379 return -1;
1380 }
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301381 result[len] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001382
1383 pos = strstr(result, "table ");
1384 if (pos == NULL) {
1385 free(result);
1386 return -1;
1387 }
1388
1389 pos += strlen("table ");
1390 tableid = atoi(pos);
1391 if (tableid != 0) {
1392 if (system("ip -6 rule del prio 22000") != 0) {
1393 /* ignore any error */
1394 }
1395 snprintf(cmd, sizeof(cmd),
1396 "ip -6 rule add from all lookup %d prio 22000",
1397 tableid);
1398 if (system(cmd) != 0) {
1399 sigma_dut_print(dut, DUT_MSG_INFO,
1400 "Failed to run %s", cmd);
1401 free(result);
1402 return -1;
1403 }
1404 } else {
1405 sigma_dut_print(dut, DUT_MSG_INFO,
1406 "No Valid Table Id found %s", pos);
1407 free(result);
1408 return -1;
1409 }
1410 free(result);
1411
1412 return 0;
1413}
1414#endif /* ANDROID */
1415
1416
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301417int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
1418 const char *ip, const char *mask)
1419{
1420 char buf[200];
1421
1422 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
1423 ifname, ip, mask);
1424 return system(buf) == 0;
1425}
1426
1427
1428int set_ipv4_gw(struct sigma_dut *dut, const char *gw)
1429{
1430 char buf[200];
1431
1432 if (!is_ip_addr(gw)) {
1433 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw);
1434 return -1;
1435 }
1436
1437 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
1438 if (!dut->no_ip_addr_set && system(buf) != 0) {
1439 snprintf(buf, sizeof(buf), "ip ro re default via %s",
1440 gw);
1441 if (system(buf) != 0)
1442 return 0;
1443 }
1444
1445 return 1;
1446}
1447
1448
Jouni Malinenf7222712019-06-13 01:50:21 +03001449static enum sigma_cmd_result cmd_sta_set_ip_config(struct sigma_dut *dut,
1450 struct sigma_conn *conn,
1451 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001452{
1453 const char *intf = get_param(cmd, "Interface");
1454 const char *ifname;
1455 char buf[200];
1456 const char *val, *ip, *mask, *gw;
1457 int type = 1;
1458
1459 if (intf == NULL)
1460 return -1;
1461
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001462 if (strcmp(intf, get_main_ifname(dut)) == 0)
1463 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001464 else
1465 ifname = intf;
1466
1467 if (if_nametoindex(ifname) == 0) {
1468 send_resp(dut, conn, SIGMA_ERROR,
1469 "ErrorCode,Unknown interface");
1470 return 0;
1471 }
1472
1473 val = get_param(cmd, "Type");
1474 if (val) {
1475 type = atoi(val);
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301476 if (type < 1 || type > 3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001477 send_resp(dut, conn, SIGMA_ERROR,
1478 "ErrorCode,Unsupported address type");
1479 return 0;
1480 }
1481 }
1482
1483 dut->last_set_ip_config_ipv6 = 0;
1484
1485 val = get_param(cmd, "dhcp");
1486 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
1487 static_ip_file(0, NULL, NULL, NULL);
1488#ifdef __linux__
1489 if (type == 2) {
1490 dut->last_set_ip_config_ipv6 = 1;
1491 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
1492 "stateless address autoconfiguration");
1493#ifdef ANDROID
1494 /*
1495 * This sleep is required as the assignment in case of
1496 * Android is taking time and is done by the kernel.
1497 * The subsequent ping for IPv6 is impacting HS20 test
1498 * case.
1499 */
1500 sleep(2);
1501 add_ipv6_rule(dut, intf);
1502#endif /* ANDROID */
1503 /* Assume this happens by default */
1504 return 1;
1505 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301506 if (type != 3) {
1507 kill_dhcp_client(dut, ifname);
1508 if (start_dhcp_client(dut, ifname) < 0)
1509 return -2;
1510 } else {
1511 sigma_dut_print(dut, DUT_MSG_DEBUG,
1512 "Using FILS HLP DHCPv4 Rapid Commit");
1513 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001514
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001515 return 1;
1516#endif /* __linux__ */
1517 return -2;
1518 }
1519
1520 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301521 if (!ip) {
1522 send_resp(dut, conn, SIGMA_INVALID,
1523 "ErrorCode,Missing IP address");
1524 return 0;
1525 }
1526
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001527 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301528 if (!mask) {
1529 send_resp(dut, conn, SIGMA_INVALID,
1530 "ErrorCode,Missing subnet mask");
1531 return 0;
1532 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001533
1534 if (type == 2) {
1535 int net = atoi(mask);
1536
1537 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
1538 return -1;
1539
1540 if (dut->no_ip_addr_set) {
1541 snprintf(buf, sizeof(buf),
1542 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
1543 ifname);
1544 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1545 if (system(buf) != 0) {
1546 sigma_dut_print(dut, DUT_MSG_DEBUG,
1547 "Failed to disable IPv6 address before association");
1548 }
1549 } else {
Veerendranath Jakkam176181c2020-05-16 00:19:21 +05301550 if (set_ipv6_addr(dut, ip, mask, ifname) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001551 send_resp(dut, conn, SIGMA_ERROR,
1552 "ErrorCode,Failed to set IPv6 address");
1553 return 0;
1554 }
1555 }
1556
1557 dut->last_set_ip_config_ipv6 = 1;
1558 static_ip_file(6, ip, mask, NULL);
1559 return 1;
1560 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301561 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001562 return -1;
1563 }
1564
1565 kill_dhcp_client(dut, ifname);
1566
1567 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301568 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001569 send_resp(dut, conn, SIGMA_ERROR,
1570 "ErrorCode,Failed to set IP address");
1571 return 0;
1572 }
1573 }
1574
1575 gw = get_param(cmd, "defaultGateway");
1576 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301577 if (set_ipv4_gw(dut, gw) < 1) {
1578 send_resp(dut, conn, SIGMA_ERROR,
1579 "ErrorCode,Failed to set default gateway");
1580 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001581 }
1582 }
1583
1584 val = get_param(cmd, "primary-dns");
1585 if (val) {
1586 /* TODO */
1587 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1588 "setting", val);
1589 }
1590
1591 val = get_param(cmd, "secondary-dns");
1592 if (val) {
1593 /* TODO */
1594 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1595 "setting", val);
1596 }
1597
1598 static_ip_file(4, ip, mask, gw);
1599
1600 return 1;
1601}
1602
1603
Jouni Malinenf7222712019-06-13 01:50:21 +03001604static enum sigma_cmd_result cmd_sta_get_info(struct sigma_dut *dut,
1605 struct sigma_conn *conn,
1606 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001607{
1608 /* const char *intf = get_param(cmd, "Interface"); */
1609 /* TODO: could report more details here */
1610 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1611 return 0;
1612}
1613
1614
Jouni Malinenf7222712019-06-13 01:50:21 +03001615static enum sigma_cmd_result cmd_sta_get_mac_address(struct sigma_dut *dut,
1616 struct sigma_conn *conn,
1617 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001618{
1619 /* const char *intf = get_param(cmd, "Interface"); */
1620 char addr[20], resp[50];
1621
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301622 if (dut->dev_role == DEVROLE_STA_CFON)
1623 return sta_cfon_get_mac_address(dut, conn, cmd);
1624
Jouni Malinen9540e012019-11-05 17:08:42 +02001625 start_sta_mode(dut);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001626 if (get_wpa_status(get_station_ifname(dut), "address",
1627 addr, sizeof(addr)) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001628 return -2;
1629
1630 snprintf(resp, sizeof(resp), "mac,%s", addr);
1631 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1632 return 0;
1633}
1634
1635
Jouni Malinenf7222712019-06-13 01:50:21 +03001636static enum sigma_cmd_result cmd_sta_is_connected(struct sigma_dut *dut,
1637 struct sigma_conn *conn,
1638 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001639{
1640 /* const char *intf = get_param(cmd, "Interface"); */
1641 int connected = 0;
1642 char result[32];
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001643 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001644 sizeof(result)) < 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001645 sigma_dut_print(dut, DUT_MSG_INFO,
1646 "Could not get interface %s status",
1647 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001648 return -2;
1649 }
1650
1651 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1652 if (strncmp(result, "COMPLETED", 9) == 0)
1653 connected = 1;
1654
1655 if (connected)
1656 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1657 else
1658 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1659
1660 return 0;
1661}
1662
1663
Jouni Malinenf7222712019-06-13 01:50:21 +03001664static enum sigma_cmd_result
1665cmd_sta_verify_ip_connection(struct sigma_dut *dut, struct sigma_conn *conn,
1666 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001667{
1668 /* const char *intf = get_param(cmd, "Interface"); */
1669 const char *dst, *timeout;
1670 int wait_time = 90;
1671 char buf[100];
1672 int res;
1673
1674 dst = get_param(cmd, "destination");
1675 if (dst == NULL || !is_ip_addr(dst))
1676 return -1;
1677
1678 timeout = get_param(cmd, "timeout");
1679 if (timeout) {
1680 wait_time = atoi(timeout);
1681 if (wait_time < 1)
1682 wait_time = 1;
1683 }
1684
1685 /* TODO: force renewal of IP lease if DHCP is enabled */
1686
1687 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1688 res = system(buf);
1689 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1690 if (res == 0)
1691 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1692 else if (res == 256)
1693 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1694 else
1695 return -2;
1696
1697 return 0;
1698}
1699
1700
Jouni Malinenf7222712019-06-13 01:50:21 +03001701static enum sigma_cmd_result cmd_sta_get_bssid(struct sigma_dut *dut,
1702 struct sigma_conn *conn,
1703 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001704{
1705 /* const char *intf = get_param(cmd, "Interface"); */
1706 char bssid[20], resp[50];
1707
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001708 if (get_wpa_status(get_station_ifname(dut), "bssid",
1709 bssid, sizeof(bssid)) < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001710 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001711
1712 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1713 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1714 return 0;
1715}
1716
1717
1718#ifdef __SAMSUNG__
1719static int add_use_network(const char *ifname)
1720{
1721 char buf[100];
1722
1723 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1724 wpa_command(ifname, buf);
1725 return 0;
1726}
1727#endif /* __SAMSUNG__ */
1728
1729
1730static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1731 const char *ifname, struct sigma_cmd *cmd)
1732{
1733 const char *ssid = get_param(cmd, "ssid");
1734 int id;
1735 const char *val;
1736
1737 if (ssid == NULL)
1738 return -1;
1739
1740 start_sta_mode(dut);
1741
1742#ifdef __SAMSUNG__
1743 add_use_network(ifname);
1744#endif /* __SAMSUNG__ */
1745
1746 id = add_network(ifname);
1747 if (id < 0)
1748 return -2;
1749 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1750
1751 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1752 return -2;
1753
1754 dut->infra_network_id = id;
1755 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1756
1757 val = get_param(cmd, "program");
1758 if (!val)
1759 val = get_param(cmd, "prog");
1760 if (val && strcasecmp(val, "hs2") == 0) {
1761 char buf[100];
1762 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1763 wpa_command(ifname, buf);
1764
1765 val = get_param(cmd, "prefer");
1766 if (val && atoi(val) > 0)
1767 set_network(ifname, id, "priority", "1");
1768 }
1769
1770 return id;
1771}
1772
1773
Jouni Malinenf7222712019-06-13 01:50:21 +03001774static enum sigma_cmd_result cmd_sta_set_encryption(struct sigma_dut *dut,
1775 struct sigma_conn *conn,
1776 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001777{
1778 const char *intf = get_param(cmd, "Interface");
1779 const char *ssid = get_param(cmd, "ssid");
1780 const char *type = get_param(cmd, "encpType");
1781 const char *ifname;
1782 char buf[200];
1783 int id;
1784
1785 if (intf == NULL || ssid == NULL)
1786 return -1;
1787
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001788 if (strcmp(intf, get_main_ifname(dut)) == 0)
1789 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001790 else
1791 ifname = intf;
1792
1793 id = add_network_common(dut, conn, ifname, cmd);
1794 if (id < 0)
1795 return id;
1796
1797 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1798 return -2;
1799
1800 if (type && strcasecmp(type, "wep") == 0) {
1801 const char *val;
1802 int i;
1803
1804 val = get_param(cmd, "activeKey");
1805 if (val) {
1806 int keyid;
1807 keyid = atoi(val);
1808 if (keyid < 1 || keyid > 4)
1809 return -1;
1810 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1811 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1812 return -2;
1813 }
1814
1815 for (i = 0; i < 4; i++) {
1816 snprintf(buf, sizeof(buf), "key%d", i + 1);
1817 val = get_param(cmd, buf);
1818 if (val == NULL)
1819 continue;
1820 snprintf(buf, sizeof(buf), "wep_key%d", i);
1821 if (set_network(ifname, id, buf, val) < 0)
1822 return -2;
1823 }
1824 }
1825
1826 return 1;
1827}
1828
1829
Jouni Malinene4fde732019-03-25 22:29:37 +02001830static int set_akm_suites(struct sigma_dut *dut, const char *ifname,
1831 int id, const char *val)
1832{
1833 char key_mgmt[200], *end, *pos;
1834 const char *in_pos = val;
1835
Jouni Malinen8179fee2019-03-28 03:19:47 +02001836 dut->akm_values = 0;
Jouni Malinene4fde732019-03-25 22:29:37 +02001837 pos = key_mgmt;
1838 end = pos + sizeof(key_mgmt);
1839 while (*in_pos) {
1840 int res, akm = atoi(in_pos);
1841 const char *str;
1842
Jouni Malinen8179fee2019-03-28 03:19:47 +02001843 if (akm >= 0 && akm < 32)
1844 dut->akm_values |= 1 << akm;
1845
Jouni Malinene4fde732019-03-25 22:29:37 +02001846 switch (akm) {
1847 case AKM_WPA_EAP:
1848 str = "WPA-EAP";
1849 break;
1850 case AKM_WPA_PSK:
1851 str = "WPA-PSK";
1852 break;
1853 case AKM_FT_EAP:
1854 str = "FT-EAP";
1855 break;
1856 case AKM_FT_PSK:
1857 str = "FT-PSK";
1858 break;
1859 case AKM_EAP_SHA256:
1860 str = "WPA-EAP-SHA256";
1861 break;
1862 case AKM_PSK_SHA256:
1863 str = "WPA-PSK-SHA256";
1864 break;
1865 case AKM_SAE:
1866 str = "SAE";
1867 break;
1868 case AKM_FT_SAE:
1869 str = "FT-SAE";
1870 break;
1871 case AKM_SUITE_B:
1872 str = "WPA-EAP-SUITE-B-192";
1873 break;
1874 case AKM_FT_SUITE_B:
1875 str = "FT-EAP-SHA384";
1876 break;
1877 case AKM_FILS_SHA256:
1878 str = "FILS-SHA256";
1879 break;
1880 case AKM_FILS_SHA384:
1881 str = "FILS-SHA384";
1882 break;
1883 case AKM_FT_FILS_SHA256:
1884 str = "FT-FILS-SHA256";
1885 break;
1886 case AKM_FT_FILS_SHA384:
1887 str = "FT-FILS-SHA384";
1888 break;
1889 default:
1890 sigma_dut_print(dut, DUT_MSG_ERROR,
1891 "Unsupported AKMSuitetype %d", akm);
1892 return -1;
1893 }
1894
1895 res = snprintf(pos, end - pos, "%s%s",
1896 pos == key_mgmt ? "" : " ", str);
1897 if (res < 0 || res >= end - pos)
1898 return -1;
1899 pos += res;
1900
1901 in_pos = strchr(in_pos, ';');
1902 if (!in_pos)
1903 break;
1904 while (*in_pos == ';')
1905 in_pos++;
1906 }
1907 sigma_dut_print(dut, DUT_MSG_DEBUG, "AKMSuiteType %s --> %s",
1908 val, key_mgmt);
1909 return set_network(ifname, id, "key_mgmt", key_mgmt);
1910}
1911
1912
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001913static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1914 const char *ifname, struct sigma_cmd *cmd)
1915{
1916 const char *val;
1917 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001918 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001919 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301920 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001921
1922 id = add_network_common(dut, conn, ifname, cmd);
1923 if (id < 0)
1924 return id;
1925
Jouni Malinen47dcc952017-10-09 16:43:24 +03001926 val = get_param(cmd, "Type");
1927 owe = val && strcasecmp(val, "OWE") == 0;
1928
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001929 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001930 if (!val && owe)
1931 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001932 if (val == NULL) {
Jouni Malinene4fde732019-03-25 22:29:37 +02001933 /* keyMgmtType is being replaced with AKMSuiteType, so ignore
1934 * this missing parameter and assume proto=WPA2. */
1935 if (set_network(ifname, id, "proto", "WPA2") < 0)
1936 return ERROR_SEND_STATUS;
1937 } else if (strcasecmp(val, "wpa") == 0 ||
1938 strcasecmp(val, "wpa-psk") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001939 if (set_network(ifname, id, "proto", "WPA") < 0)
1940 return -2;
1941 } else if (strcasecmp(val, "wpa2") == 0 ||
1942 strcasecmp(val, "wpa2-psk") == 0 ||
1943 strcasecmp(val, "wpa2-ft") == 0 ||
1944 strcasecmp(val, "wpa2-sha256") == 0) {
1945 if (set_network(ifname, id, "proto", "WPA2") < 0)
1946 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301947 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1948 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001949 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1950 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001951 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301952 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001953 if (set_network(ifname, id, "proto", "WPA2") < 0)
1954 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001955 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001956 } else {
1957 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1958 return 0;
1959 }
1960
1961 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001962 if (val) {
1963 cipher_set = 1;
1964 if (strcasecmp(val, "tkip") == 0) {
1965 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1966 return -2;
1967 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1968 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1969 return -2;
1970 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1971 if (set_network(ifname, id, "pairwise",
1972 "CCMP TKIP") < 0)
1973 return -2;
1974 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1975 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1976 return -2;
1977 if (set_network(ifname, id, "group", "GCMP") < 0)
1978 return -2;
1979 } else {
1980 send_resp(dut, conn, SIGMA_ERROR,
1981 "errorCode,Unrecognized encpType value");
1982 return 0;
1983 }
1984 }
1985
1986 val = get_param(cmd, "PairwiseCipher");
1987 if (val) {
1988 cipher_set = 1;
1989 /* TODO: Support space separated list */
1990 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1991 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
1992 return -2;
1993 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1994 if (set_network(ifname, id, "pairwise",
1995 "CCMP-256") < 0)
1996 return -2;
1997 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1998 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1999 return -2;
2000 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2001 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
2002 return -2;
2003 } else {
2004 send_resp(dut, conn, SIGMA_ERROR,
2005 "errorCode,Unrecognized PairwiseCipher value");
2006 return 0;
2007 }
2008 }
2009
Jouni Malinen47dcc952017-10-09 16:43:24 +03002010 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03002011 send_resp(dut, conn, SIGMA_ERROR,
2012 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002013 return 0;
2014 }
Jouni Malinenad395a22017-09-01 21:13:46 +03002015
2016 val = get_param(cmd, "GroupCipher");
2017 if (val) {
2018 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2019 if (set_network(ifname, id, "group", "GCMP-256") < 0)
2020 return -2;
2021 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2022 if (set_network(ifname, id, "group", "CCMP-256") < 0)
2023 return -2;
2024 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2025 if (set_network(ifname, id, "group", "GCMP") < 0)
2026 return -2;
2027 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2028 if (set_network(ifname, id, "group", "CCMP") < 0)
2029 return -2;
2030 } else {
2031 send_resp(dut, conn, SIGMA_ERROR,
2032 "errorCode,Unrecognized GroupCipher value");
2033 return 0;
2034 }
2035 }
2036
Jouni Malinen7b239522017-09-14 21:37:18 +03002037 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03002038 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03002039 const char *cipher;
2040
2041 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
2042 cipher = "BIP-GMAC-256";
2043 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
2044 cipher = "BIP-CMAC-256";
2045 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
2046 cipher = "BIP-GMAC-128";
2047 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
2048 cipher = "AES-128-CMAC";
2049 } else {
2050 send_resp(dut, conn, SIGMA_INVALID,
2051 "errorCode,Unsupported GroupMgntCipher");
2052 return 0;
2053 }
2054 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
2055 send_resp(dut, conn, SIGMA_INVALID,
2056 "errorCode,Failed to set GroupMgntCipher");
2057 return 0;
2058 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002059 }
2060
Jouni Malinene4fde732019-03-25 22:29:37 +02002061 val = get_param(cmd, "AKMSuiteType");
2062 if (val && set_akm_suites(dut, ifname, id, val) < 0)
2063 return ERROR_SEND_STATUS;
2064
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002065 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302066
2067 if (dut->program == PROGRAM_OCE) {
2068 dut->sta_pmf = STA_PMF_OPTIONAL;
2069 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2070 return -2;
2071 }
2072
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002073 val = get_param(cmd, "PMF");
2074 if (val) {
2075 if (strcasecmp(val, "Required") == 0 ||
2076 strcasecmp(val, "Forced_Required") == 0) {
2077 dut->sta_pmf = STA_PMF_REQUIRED;
2078 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2079 return -2;
2080 } else if (strcasecmp(val, "Optional") == 0) {
2081 dut->sta_pmf = STA_PMF_OPTIONAL;
2082 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2083 return -2;
2084 } else if (strcasecmp(val, "Disabled") == 0 ||
Kiran Kumar Lokere07da3b22018-12-16 22:42:49 -08002085 strcasecmp(val, "Disable") == 0 ||
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002086 strcasecmp(val, "Forced_Disabled") == 0) {
2087 dut->sta_pmf = STA_PMF_DISABLED;
2088 } else {
2089 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
2090 return 0;
2091 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05302092 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02002093 dut->sta_pmf = STA_PMF_REQUIRED;
2094 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2095 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002096 }
2097
Jouni Malinen0165c7f2020-03-26 11:51:58 +02002098 val = get_param(cmd, "BeaconProtection");
2099 if (val && atoi(val) == 1 &&
2100 set_network(ifname, id, "beacon_prot", "1") < 0)
2101 return ERROR_SEND_STATUS;
2102
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002103 return id;
2104}
2105
2106
Jouni Malinenf7222712019-06-13 01:50:21 +03002107static enum sigma_cmd_result cmd_sta_set_psk(struct sigma_dut *dut,
2108 struct sigma_conn *conn,
2109 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002110{
2111 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002112 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002113 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002114 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002115 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002116 const char *ifname, *val, *alg;
2117 int id;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002118 char buf[50];
Jouni Malinen11e55212019-11-22 21:46:59 +02002119 int sae_pwe = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002120
2121 if (intf == NULL)
2122 return -1;
2123
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002124 if (strcmp(intf, get_main_ifname(dut)) == 0)
2125 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002126 else
2127 ifname = intf;
2128
2129 id = set_wpa_common(dut, conn, ifname, cmd);
2130 if (id < 0)
2131 return id;
2132
2133 val = get_param(cmd, "keyMgmtType");
2134 alg = get_param(cmd, "micAlg");
2135
Jouni Malinen992a81e2017-08-22 13:57:47 +03002136 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002137 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002138 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2139 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002140 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002141 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2142 return -2;
2143 }
2144 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2145 sigma_dut_print(dut, DUT_MSG_ERROR,
2146 "Failed to clear sae_groups to default");
2147 return -2;
2148 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002149 if (!pmf) {
2150 dut->sta_pmf = STA_PMF_REQUIRED;
2151 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2152 return -2;
2153 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002154 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2155 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2156 if (set_network(ifname, id, "key_mgmt",
2157 "FT-SAE FT-PSK") < 0)
2158 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002159 } else if (!akm) {
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002160 if (set_network(ifname, id, "key_mgmt",
2161 "SAE WPA-PSK") < 0)
2162 return -2;
2163 }
2164 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2165 sigma_dut_print(dut, DUT_MSG_ERROR,
2166 "Failed to clear sae_groups to default");
2167 return -2;
2168 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002169 if (!pmf) {
2170 dut->sta_pmf = STA_PMF_OPTIONAL;
2171 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2172 return -2;
2173 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002174 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002175 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2176 return -2;
2177 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2178 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2179 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302180 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2181 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2182 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002183 } else if (!akm &&
2184 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2185 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002186 if (set_network(ifname, id, "key_mgmt",
2187 "WPA-PSK WPA-PSK-SHA256") < 0)
2188 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002189 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002190 if (set_network(ifname, id, "key_mgmt",
2191 "WPA-PSK WPA-PSK-SHA256") < 0)
2192 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002193 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002194 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2195 return -2;
2196 }
2197
2198 val = get_param(cmd, "passPhrase");
2199 if (val == NULL)
2200 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002201 if (type && strcasecmp(type, "SAE") == 0) {
2202 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2203 return -2;
2204 } else {
2205 if (set_network_quoted(ifname, id, "psk", val) < 0)
2206 return -2;
2207 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002208
Jouni Malinen78d10c42019-03-25 22:34:32 +02002209 val = get_param(cmd, "PasswordId");
2210 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2211 return ERROR_SEND_STATUS;
2212
Jouni Malinen992a81e2017-08-22 13:57:47 +03002213 val = get_param(cmd, "ECGroupID");
2214 if (val) {
Jouni Malinenb54f0df2019-12-12 01:57:29 +02002215 snprintf(buf, sizeof(buf), "SET sae_groups %s", val);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002216 if (wpa_command(ifname, buf) != 0) {
2217 sigma_dut_print(dut, DUT_MSG_ERROR,
2218 "Failed to clear sae_groups");
2219 return -2;
2220 }
2221 }
2222
Jouni Malinen68143132017-09-02 02:34:08 +03002223 val = get_param(cmd, "InvalidSAEElement");
2224 if (val) {
2225 free(dut->sae_commit_override);
2226 dut->sae_commit_override = strdup(val);
2227 }
2228
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002229 val = get_param(cmd, "PMKID_Include");
2230 if (val) {
2231 snprintf(buf, sizeof(buf), "SET sae_pmkid_in_assoc %d",
2232 get_enable_disable(val));
2233 wpa_command(intf, buf);
2234 }
2235
Jouni Malineneeb43d32019-12-06 17:40:07 +02002236 val = get_param(cmd, "IgnoreH2E_RSNXE_BSSMemSel");
2237 if (val) {
2238 snprintf(buf, sizeof(buf), "SET ignore_sae_h2e_only %d",
2239 get_enable_disable(val));
2240 wpa_command(intf, buf);
2241 }
2242
Jouni Malinenf2348d22019-12-07 11:52:55 +02002243 val = get_param(cmd, "ECGroupID_RGE");
2244 if (val) {
2245 snprintf(buf, sizeof(buf), "SET extra_sae_rejected_groups %s",
2246 val);
2247 wpa_command(intf, buf);
2248 }
2249
Jouni Malinen99e55022019-12-07 13:59:41 +02002250 val = get_param(cmd, "RSNXE_Content");
2251 if (val) {
2252 const char *param;
2253
2254 if (strncasecmp(val, "AssocReq:", 9) == 0) {
2255 val += 9;
2256 param = "rsnxe_override_assoc";
2257 } else if (strncasecmp(val, "EapolM2:", 8) == 0) {
2258 val += 8;
2259 param = "rsnxe_override_eapol";
2260 } else {
2261 send_resp(dut, conn, SIGMA_ERROR,
2262 "errorCode,Unsupported RSNXE_Content value");
2263 return STATUS_SENT_ERROR;
2264 }
2265 snprintf(buf, sizeof(buf), "SET %s %s", param, val);
2266 wpa_command(intf, buf);
2267 }
2268
Jouni Malinen11e55212019-11-22 21:46:59 +02002269 val = get_param(cmd, "sae_pwe");
2270 if (val) {
2271 if (strcasecmp(val, "h2e") == 0) {
2272 dut->sae_pwe = SAE_PWE_H2E;
Jouni Malinen7244a412019-12-07 11:54:10 +02002273 } else if (strcasecmp(val, "loop") == 0 ||
2274 strcasecmp(val, "looping") == 0) {
Jouni Malinen11e55212019-11-22 21:46:59 +02002275 dut->sae_pwe = SAE_PWE_LOOP;
2276 } else {
2277 send_resp(dut, conn, SIGMA_ERROR,
2278 "errorCode,Unsupported sae_pwe value");
2279 return STATUS_SENT_ERROR;
2280 }
2281 }
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302282
2283 val = get_param(cmd, "Clear_RSNXE");
2284 if (val && strcmp(val, "1") == 0 &&
2285 (wpa_command(intf, "SET rsnxe_override_assoc ") ||
2286 wpa_command(intf, "SET rsnxe_override_eapol "))) {
2287 send_resp(dut, conn, SIGMA_ERROR,
2288 "errorCode,Failed to clear RSNXE");
Jouni Malinenb11498c2020-08-03 11:05:53 +03002289 return STATUS_SENT_ERROR;
Vinita S. Maloo6d7454f2020-04-02 15:03:26 +05302290 }
2291
Jouni Malinenc0078772020-03-04 21:23:16 +02002292 if (dut->sae_pwe == SAE_PWE_LOOP && get_param(cmd, "PasswordId"))
2293 sae_pwe = 3;
2294 else if (dut->sae_pwe == SAE_PWE_LOOP)
Jouni Malinen11e55212019-11-22 21:46:59 +02002295 sae_pwe = 0;
2296 else if (dut->sae_pwe == SAE_PWE_H2E)
2297 sae_pwe = 1;
2298 else if (dut->sae_h2e_default)
2299 sae_pwe = 2;
2300 snprintf(buf, sizeof(buf), "SET sae_pwe %d", sae_pwe);
2301 if (sae_pwe >= 0 && wpa_command(ifname, buf) != 0)
2302 return ERROR_SEND_STATUS;
2303
Veerendranath Jakkam0316be12020-06-23 20:11:41 +05302304 val = get_param(cmd, "sae_pk");
2305 if (val && strcmp(val, "0") == 0 &&
2306 set_network(ifname, id, "sae_pk", "2") < 0)
2307 return ERROR_SEND_STATUS;
2308
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002309 if (dut->program == PROGRAM_60GHZ && network_mode &&
2310 strcasecmp(network_mode, "PBSS") == 0 &&
2311 set_network(ifname, id, "pbss", "1") < 0)
2312 return -2;
2313
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002314 return 1;
2315}
2316
2317
Jouni Malinen8ac93452019-08-14 15:19:13 +03002318static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2319 struct sigma_conn *conn,
2320 const char *ifname, int id)
2321{
2322 char buf[200];
2323
2324 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2325 if (!file_exists(buf))
2326 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2327 if (!file_exists(buf))
2328 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2329 if (!file_exists(buf)) {
2330 char msg[300];
2331
2332 snprintf(msg, sizeof(msg),
2333 "ErrorCode,trustedRootCA system store (%s) not found",
2334 buf);
2335 send_resp(dut, conn, SIGMA_ERROR, msg);
2336 return STATUS_SENT_ERROR;
2337 }
2338
2339 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2340 return ERROR_SEND_STATUS;
2341
2342 return SUCCESS_SEND_STATUS;
2343}
2344
2345
2346static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2347 struct sigma_conn *conn,
2348 const char *ifname, int id,
2349 const char *val)
2350{
2351 char buf[200];
2352#ifdef ANDROID
2353 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2354 int length;
2355#endif /* ANDROID */
2356
2357 if (strcmp(val, "DEFAULT") == 0)
2358 return set_trust_root_system(dut, conn, ifname, id);
2359
2360#ifdef ANDROID
2361 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2362 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2363 if (length > 0) {
2364 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2365 buf);
2366 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2367 goto ca_cert_selected;
2368 }
2369#endif /* ANDROID */
2370
2371 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2372#ifdef __linux__
2373 if (!file_exists(buf)) {
2374 char msg[300];
2375
2376 snprintf(msg, sizeof(msg),
2377 "ErrorCode,trustedRootCA file (%s) not found", buf);
2378 send_resp(dut, conn, SIGMA_ERROR, msg);
2379 return STATUS_SENT_ERROR;
2380 }
2381#endif /* __linux__ */
2382#ifdef ANDROID
2383ca_cert_selected:
2384#endif /* ANDROID */
2385 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2386 return ERROR_SEND_STATUS;
2387
2388 return SUCCESS_SEND_STATUS;
2389}
2390
2391
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002392static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302393 const char *ifname, int username_identity,
2394 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002395{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002396 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002397 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002398 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002399 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002400 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002401
2402 id = set_wpa_common(dut, conn, ifname, cmd);
2403 if (id < 0)
2404 return id;
2405
2406 val = get_param(cmd, "keyMgmtType");
2407 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302408 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002409 trust_root = get_param(cmd, "trustedRootCA");
2410 domain = get_param(cmd, "Domain");
2411 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002412
Jouni Malinenad395a22017-09-01 21:13:46 +03002413 if (val && strcasecmp(val, "SuiteB") == 0) {
2414 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2415 0)
2416 return -2;
2417 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002418 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2419 return -2;
2420 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2421 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2422 return -2;
2423 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2424 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2425 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002426 } else if (!akm &&
2427 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2428 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002429 if (set_network(ifname, id, "key_mgmt",
2430 "WPA-EAP WPA-EAP-SHA256") < 0)
2431 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302432 } else if (akm && atoi(akm) == 14) {
2433 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2434 dut->sta_pmf == STA_PMF_REQUIRED) {
2435 if (set_network(ifname, id, "key_mgmt",
2436 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2437 return -2;
2438 } else {
2439 if (set_network(ifname, id, "key_mgmt",
2440 "WPA-EAP FILS-SHA256") < 0)
2441 return -2;
2442 }
2443
Jouni Malinen8179fee2019-03-28 03:19:47 +02002444 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302445 } else if (akm && atoi(akm) == 15) {
2446 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2447 dut->sta_pmf == STA_PMF_REQUIRED) {
2448 if (set_network(ifname, id, "key_mgmt",
2449 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2450 return -2;
2451 } else {
2452 if (set_network(ifname, id, "key_mgmt",
2453 "WPA-EAP FILS-SHA384") < 0)
2454 return -2;
2455 }
2456
Jouni Malinen8179fee2019-03-28 03:19:47 +02002457 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002458 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002459 if (set_network(ifname, id, "key_mgmt",
2460 "WPA-EAP WPA-EAP-SHA256") < 0)
2461 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002462 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002463 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2464 return -2;
2465 }
2466
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002467 if (trust_root) {
2468 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2469 !domain_suffix) {
2470 send_resp(dut, conn, SIGMA_ERROR,
2471 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2472 return STATUS_SENT_ERROR;
2473 }
2474 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002475 if (res != SUCCESS_SEND_STATUS)
2476 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002477 }
2478
Jouni Malinen53264f62019-05-03 13:04:40 +03002479 val = get_param(cmd, "ServerCert");
2480 if (val) {
2481 FILE *f;
2482 char *result = NULL, *pos;
2483
2484 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2485 val);
2486 f = fopen(buf, "r");
2487 if (f) {
2488 result = fgets(buf, sizeof(buf), f);
2489 fclose(f);
2490 }
2491 if (!result) {
2492 snprintf(buf2, sizeof(buf2),
2493 "ErrorCode,ServerCert hash could not be read from %s",
2494 buf);
2495 send_resp(dut, conn, SIGMA_ERROR, buf2);
2496 return STATUS_SENT_ERROR;
2497 }
2498 pos = strchr(buf, '\n');
2499 if (pos)
2500 *pos = '\0';
2501 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2502 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2503 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002504
2505 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2506 if (file_exists(buf)) {
2507 sigma_dut_print(dut, DUT_MSG_DEBUG,
2508 "TOD policy enabled for the configured ServerCert hash");
2509 dut->sta_tod_policy = 1;
2510 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002511 }
2512
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002513 if (domain &&
2514 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002515 return ERROR_SEND_STATUS;
2516
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002517 if (domain_suffix &&
2518 set_network_quoted(ifname, id, "domain_suffix_match",
2519 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002520 return ERROR_SEND_STATUS;
2521
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302522 if (username_identity) {
2523 val = get_param(cmd, "username");
2524 if (val) {
2525 if (set_network_quoted(ifname, id, "identity", val) < 0)
2526 return -2;
2527 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002528
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302529 val = get_param(cmd, "password");
2530 if (val) {
2531 if (set_network_quoted(ifname, id, "password", val) < 0)
2532 return -2;
2533 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002534 }
2535
Jouni Malinen8179fee2019-03-28 03:19:47 +02002536 if (dut->akm_values &
2537 ((1 << AKM_FILS_SHA256) |
2538 (1 << AKM_FILS_SHA384) |
2539 (1 << AKM_FT_FILS_SHA256) |
2540 (1 << AKM_FT_FILS_SHA384)))
2541 erp = 1;
2542 if (erp && set_network(ifname, id, "erp", "1") < 0)
2543 return ERROR_SEND_STATUS;
2544
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002545 dut->sta_associate_wait_connect = 1;
2546
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002547 return id;
2548}
2549
2550
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002551static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2552{
2553 const char *val;
2554
2555 if (!cipher)
2556 return 0;
2557
2558 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2559 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2560 else if (strcasecmp(cipher,
2561 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2562 val = "ECDHE-RSA-AES256-GCM-SHA384";
2563 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2564 val = "DHE-RSA-AES256-GCM-SHA384";
2565 else if (strcasecmp(cipher,
2566 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2567 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2568 else
2569 return -1;
2570
2571 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2572 set_network_quoted(ifname, id, "phase1", "");
2573
2574 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2575}
2576
2577
Jouni Malinenf7222712019-06-13 01:50:21 +03002578static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2579 struct sigma_conn *conn,
2580 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002581{
2582 const char *intf = get_param(cmd, "Interface");
2583 const char *ifname, *val;
2584 int id;
2585 char buf[200];
2586#ifdef ANDROID
2587 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2588 int length;
2589 int jb_or_newer = 0;
2590 char prop[PROPERTY_VALUE_MAX];
2591#endif /* ANDROID */
2592
2593 if (intf == NULL)
2594 return -1;
2595
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002596 if (strcmp(intf, get_main_ifname(dut)) == 0)
2597 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002598 else
2599 ifname = intf;
2600
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302601 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002602 if (id < 0)
2603 return id;
2604
2605 if (set_network(ifname, id, "eap", "TLS") < 0)
2606 return -2;
2607
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302608 if (!get_param(cmd, "username") &&
2609 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002610 "wifi-user@wifilabs.local") < 0)
2611 return -2;
2612
2613 val = get_param(cmd, "clientCertificate");
2614 if (val == NULL)
2615 return -1;
2616#ifdef ANDROID
2617 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2618 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2619 if (length < 0) {
2620 /*
2621 * JB started reporting keystore type mismatches, so retry with
2622 * the GET_PUBKEY command if the generic GET fails.
2623 */
2624 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2625 buf, kvalue);
2626 }
2627
2628 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2629 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2630 if (strncmp(prop, "4.0", 3) != 0)
2631 jb_or_newer = 1;
2632 } else
2633 jb_or_newer = 1; /* assume newer */
2634
2635 if (jb_or_newer && length > 0) {
2636 sigma_dut_print(dut, DUT_MSG_INFO,
2637 "Use Android keystore [%s]", buf);
2638 if (set_network(ifname, id, "engine", "1") < 0)
2639 return -2;
2640 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2641 return -2;
2642 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2643 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2644 return -2;
2645 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2646 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2647 return -2;
2648 return 1;
2649 } else if (length > 0) {
2650 sigma_dut_print(dut, DUT_MSG_INFO,
2651 "Use Android keystore [%s]", buf);
2652 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2653 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2654 return -2;
2655 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2656 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2657 return -2;
2658 return 1;
2659 }
2660#endif /* ANDROID */
2661
2662 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2663#ifdef __linux__
2664 if (!file_exists(buf)) {
2665 char msg[300];
2666 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2667 "(%s) not found", buf);
2668 send_resp(dut, conn, SIGMA_ERROR, msg);
2669 return -3;
2670 }
2671#endif /* __linux__ */
2672 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2673 return -2;
2674 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2675 return -2;
2676
2677 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2678 return -2;
2679
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002680 val = get_param(cmd, "keyMgmtType");
2681 if (val && strcasecmp(val, "SuiteB") == 0) {
2682 val = get_param(cmd, "CertType");
2683 if (val && strcasecmp(val, "RSA") == 0) {
2684 if (set_network_quoted(ifname, id, "phase1",
2685 "tls_suiteb=1") < 0)
2686 return -2;
2687 } else {
2688 if (set_network_quoted(ifname, id, "openssl_ciphers",
2689 "SUITEB192") < 0)
2690 return -2;
2691 }
2692
2693 val = get_param(cmd, "TLSCipher");
2694 if (set_tls_cipher(ifname, id, val) < 0) {
2695 send_resp(dut, conn, SIGMA_ERROR,
2696 "ErrorCode,Unsupported TLSCipher value");
2697 return -3;
2698 }
2699 }
2700
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002701 return 1;
2702}
2703
2704
Jouni Malinenf7222712019-06-13 01:50:21 +03002705static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2706 struct sigma_conn *conn,
2707 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002708{
2709 const char *intf = get_param(cmd, "Interface");
2710 const char *ifname;
2711 int id;
2712
2713 if (intf == NULL)
2714 return -1;
2715
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002716 if (strcmp(intf, get_main_ifname(dut)) == 0)
2717 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002718 else
2719 ifname = intf;
2720
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302721 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002722 if (id < 0)
2723 return id;
2724
2725 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2726 send_resp(dut, conn, SIGMA_ERROR,
2727 "errorCode,Failed to set TTLS method");
2728 return 0;
2729 }
2730
2731 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2732 send_resp(dut, conn, SIGMA_ERROR,
2733 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2734 return 0;
2735 }
2736
2737 return 1;
2738}
2739
2740
Jouni Malinenf7222712019-06-13 01:50:21 +03002741static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2742 struct sigma_conn *conn,
2743 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002744{
2745 const char *intf = get_param(cmd, "Interface");
2746 const char *ifname;
2747 int id;
2748
2749 if (intf == NULL)
2750 return -1;
2751
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002752 if (strcmp(intf, get_main_ifname(dut)) == 0)
2753 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002754 else
2755 ifname = intf;
2756
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302757 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002758 if (id < 0)
2759 return id;
2760
2761 if (set_network(ifname, id, "eap", "SIM") < 0)
2762 return -2;
2763
2764 return 1;
2765}
2766
2767
Jouni Malinenf7222712019-06-13 01:50:21 +03002768static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2769 struct sigma_conn *conn,
2770 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002771{
2772 const char *intf = get_param(cmd, "Interface");
2773 const char *ifname, *val;
2774 int id;
2775 char buf[100];
2776
2777 if (intf == NULL)
2778 return -1;
2779
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002780 if (strcmp(intf, get_main_ifname(dut)) == 0)
2781 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002782 else
2783 ifname = intf;
2784
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302785 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002786 if (id < 0)
2787 return id;
2788
2789 if (set_network(ifname, id, "eap", "PEAP") < 0)
2790 return -2;
2791
2792 val = get_param(cmd, "innerEAP");
2793 if (val) {
2794 if (strcasecmp(val, "MSCHAPv2") == 0) {
2795 if (set_network_quoted(ifname, id, "phase2",
2796 "auth=MSCHAPV2") < 0)
2797 return -2;
2798 } else if (strcasecmp(val, "GTC") == 0) {
2799 if (set_network_quoted(ifname, id, "phase2",
2800 "auth=GTC") < 0)
2801 return -2;
2802 } else
2803 return -1;
2804 }
2805
2806 val = get_param(cmd, "peapVersion");
2807 if (val) {
2808 int ver = atoi(val);
2809 if (ver < 0 || ver > 1)
2810 return -1;
2811 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2812 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2813 return -2;
2814 }
2815
2816 return 1;
2817}
2818
2819
Jouni Malinenf7222712019-06-13 01:50:21 +03002820static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2821 struct sigma_conn *conn,
2822 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002823{
2824 const char *intf = get_param(cmd, "Interface");
2825 const char *ifname, *val;
2826 int id;
2827 char buf[100];
2828
2829 if (intf == NULL)
2830 return -1;
2831
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002832 if (strcmp(intf, get_main_ifname(dut)) == 0)
2833 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002834 else
2835 ifname = intf;
2836
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302837 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002838 if (id < 0)
2839 return id;
2840
2841 if (set_network(ifname, id, "eap", "FAST") < 0)
2842 return -2;
2843
2844 val = get_param(cmd, "innerEAP");
2845 if (val) {
2846 if (strcasecmp(val, "MSCHAPV2") == 0) {
2847 if (set_network_quoted(ifname, id, "phase2",
2848 "auth=MSCHAPV2") < 0)
2849 return -2;
2850 } else if (strcasecmp(val, "GTC") == 0) {
2851 if (set_network_quoted(ifname, id, "phase2",
2852 "auth=GTC") < 0)
2853 return -2;
2854 } else
2855 return -1;
2856 }
2857
2858 val = get_param(cmd, "validateServer");
2859 if (val) {
2860 /* TODO */
2861 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2862 "validateServer=%s", val);
2863 }
2864
2865 val = get_param(cmd, "pacFile");
2866 if (val) {
2867 snprintf(buf, sizeof(buf), "blob://%s", val);
2868 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2869 return -2;
2870 }
2871
2872 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2873 0)
2874 return -2;
2875
2876 return 1;
2877}
2878
2879
Jouni Malinenf7222712019-06-13 01:50:21 +03002880static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2881 struct sigma_conn *conn,
2882 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002883{
2884 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302885 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002886 const char *ifname;
2887 int id;
2888
2889 if (intf == NULL)
2890 return -1;
2891
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002892 if (strcmp(intf, get_main_ifname(dut)) == 0)
2893 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002894 else
2895 ifname = intf;
2896
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302897 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002898 if (id < 0)
2899 return id;
2900
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302901 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2902 * hexadecimal).
2903 */
2904 if (username && username[0] == '6') {
2905 if (set_network(ifname, id, "eap", "AKA'") < 0)
2906 return -2;
2907 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002908 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302909 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002910
2911 return 1;
2912}
2913
2914
Jouni Malinenf7222712019-06-13 01:50:21 +03002915static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2916 struct sigma_conn *conn,
2917 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002918{
2919 const char *intf = get_param(cmd, "Interface");
2920 const char *ifname;
2921 int id;
2922
2923 if (intf == NULL)
2924 return -1;
2925
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002926 if (strcmp(intf, get_main_ifname(dut)) == 0)
2927 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002928 else
2929 ifname = intf;
2930
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302931 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002932 if (id < 0)
2933 return id;
2934
2935 if (set_network(ifname, id, "eap", "AKA'") < 0)
2936 return -2;
2937
2938 return 1;
2939}
2940
2941
2942static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2943 struct sigma_cmd *cmd)
2944{
2945 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002946 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002947 const char *ifname;
2948 int id;
2949
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002950 if (strcmp(intf, get_main_ifname(dut)) == 0)
2951 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002952 else
2953 ifname = intf;
2954
2955 id = add_network_common(dut, conn, ifname, cmd);
2956 if (id < 0)
2957 return id;
2958
2959 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2960 return -2;
2961
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002962 if (dut->program == PROGRAM_60GHZ && network_mode &&
2963 strcasecmp(network_mode, "PBSS") == 0 &&
2964 set_network(ifname, id, "pbss", "1") < 0)
2965 return -2;
2966
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002967 return 1;
2968}
2969
2970
Jouni Malinen47dcc952017-10-09 16:43:24 +03002971static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2972 struct sigma_cmd *cmd)
2973{
2974 const char *intf = get_param(cmd, "Interface");
2975 const char *ifname, *val;
2976 int id;
2977
2978 if (intf == NULL)
2979 return -1;
2980
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002981 if (strcmp(intf, get_main_ifname(dut)) == 0)
2982 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002983 else
2984 ifname = intf;
2985
2986 id = set_wpa_common(dut, conn, ifname, cmd);
2987 if (id < 0)
2988 return id;
2989
2990 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
2991 return -2;
2992
Hu Wangdd5eed22020-07-16 12:18:03 +08002993 if (dut->owe_ptk_workaround &&
2994 set_network(ifname, id, "owe_ptk_workaround", "1") < 0) {
2995 sigma_dut_print(dut, DUT_MSG_ERROR,
2996 "Failed to set owe_ptk_workaround to 1");
2997 return -2;
2998 }
2999
Jouni Malinen47dcc952017-10-09 16:43:24 +03003000 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003001 if (val && strcmp(val, "0") == 0) {
3002 if (wpa_command(ifname,
3003 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
3004 sigma_dut_print(dut, DUT_MSG_ERROR,
3005 "Failed to set OWE DH Param element override");
3006 return -2;
3007 }
Hu Wangdd5eed22020-07-16 12:18:03 +08003008 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003009 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003010 "Failed to set owe_group");
Jouni Malinen47dcc952017-10-09 16:43:24 +03003011 return -2;
3012 }
3013
3014 return 1;
3015}
3016
3017
Jouni Malinenf7222712019-06-13 01:50:21 +03003018static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3019 struct sigma_conn *conn,
3020 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003021{
3022 const char *type = get_param(cmd, "Type");
3023
3024 if (type == NULL) {
3025 send_resp(dut, conn, SIGMA_ERROR,
3026 "ErrorCode,Missing Type argument");
3027 return 0;
3028 }
3029
3030 if (strcasecmp(type, "OPEN") == 0)
3031 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003032 if (strcasecmp(type, "OWE") == 0)
3033 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003034 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003035 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003036 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003037 return cmd_sta_set_psk(dut, conn, cmd);
3038 if (strcasecmp(type, "EAPTLS") == 0)
3039 return cmd_sta_set_eaptls(dut, conn, cmd);
3040 if (strcasecmp(type, "EAPTTLS") == 0)
3041 return cmd_sta_set_eapttls(dut, conn, cmd);
3042 if (strcasecmp(type, "EAPPEAP") == 0)
3043 return cmd_sta_set_peap(dut, conn, cmd);
3044 if (strcasecmp(type, "EAPSIM") == 0)
3045 return cmd_sta_set_eapsim(dut, conn, cmd);
3046 if (strcasecmp(type, "EAPFAST") == 0)
3047 return cmd_sta_set_eapfast(dut, conn, cmd);
3048 if (strcasecmp(type, "EAPAKA") == 0)
3049 return cmd_sta_set_eapaka(dut, conn, cmd);
3050 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3051 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003052 if (strcasecmp(type, "wep") == 0)
3053 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003054
3055 send_resp(dut, conn, SIGMA_ERROR,
3056 "ErrorCode,Unsupported Type value");
3057 return 0;
3058}
3059
3060
3061int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3062{
3063#ifdef __linux__
3064 /* special handling for ath6kl */
3065 char path[128], fname[128], *pos;
3066 ssize_t res;
3067 FILE *f;
3068
Jouni Malinene39cd562019-05-29 23:39:56 +03003069 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3070 intf);
3071 if (res < 0 || res >= sizeof(fname))
3072 return 0;
3073 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003074 if (res < 0)
3075 return 0; /* not ath6kl */
3076
3077 if (res >= (int) sizeof(path))
3078 res = sizeof(path) - 1;
3079 path[res] = '\0';
3080 pos = strrchr(path, '/');
3081 if (pos == NULL)
3082 pos = path;
3083 else
3084 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003085 res = snprintf(fname, sizeof(fname),
3086 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3087 "create_qos", pos);
3088 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003089 return 0; /* not ath6kl */
3090
3091 if (uapsd) {
3092 f = fopen(fname, "w");
3093 if (f == NULL)
3094 return -1;
3095
3096 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3097 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3098 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3099 "20000 0\n");
3100 fclose(f);
3101 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003102 res = snprintf(fname, sizeof(fname),
3103 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3104 "delete_qos", pos);
3105 if (res < 0 || res >= sizeof(fname))
3106 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003107
3108 f = fopen(fname, "w");
3109 if (f == NULL)
3110 return -1;
3111
3112 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3113 fprintf(f, "2 4\n");
3114 fclose(f);
3115 }
3116#endif /* __linux__ */
3117
3118 return 0;
3119}
3120
3121
Jouni Malinenf7222712019-06-13 01:50:21 +03003122static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3123 struct sigma_conn *conn,
3124 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003125{
3126 const char *intf = get_param(cmd, "Interface");
3127 /* const char *ssid = get_param(cmd, "ssid"); */
3128 const char *val;
3129 int max_sp_len = 4;
3130 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3131 char buf[100];
3132 int ret1, ret2;
3133
3134 val = get_param(cmd, "maxSPLength");
3135 if (val) {
3136 max_sp_len = atoi(val);
3137 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3138 max_sp_len != 4)
3139 return -1;
3140 }
3141
3142 val = get_param(cmd, "acBE");
3143 if (val)
3144 ac_be = atoi(val);
3145
3146 val = get_param(cmd, "acBK");
3147 if (val)
3148 ac_bk = atoi(val);
3149
3150 val = get_param(cmd, "acVI");
3151 if (val)
3152 ac_vi = atoi(val);
3153
3154 val = get_param(cmd, "acVO");
3155 if (val)
3156 ac_vo = atoi(val);
3157
3158 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3159
3160 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3161 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3162 ret1 = wpa_command(intf, buf);
3163
3164 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3165 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3166 ret2 = wpa_command(intf, buf);
3167
3168 if (ret1 && ret2) {
3169 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3170 "UAPSD parameters.");
3171 return -2;
3172 }
3173
3174 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3175 send_resp(dut, conn, SIGMA_ERROR,
3176 "ErrorCode,Failed to set ath6kl QoS parameters");
3177 return 0;
3178 }
3179
3180 return 1;
3181}
3182
3183
Jouni Malinenf7222712019-06-13 01:50:21 +03003184static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3185 struct sigma_conn *conn,
3186 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003187{
3188 char buf[1000];
3189 const char *intf = get_param(cmd, "Interface");
3190 const char *grp = get_param(cmd, "Group");
3191 const char *act = get_param(cmd, "Action");
3192 const char *tid = get_param(cmd, "Tid");
3193 const char *dir = get_param(cmd, "Direction");
3194 const char *psb = get_param(cmd, "Psb");
3195 const char *up = get_param(cmd, "Up");
3196 const char *fixed = get_param(cmd, "Fixed");
3197 const char *size = get_param(cmd, "Size");
3198 const char *msize = get_param(cmd, "Maxsize");
3199 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3200 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3201 const char *inact = get_param(cmd, "Inactivity");
3202 const char *sus = get_param(cmd, "Suspension");
3203 const char *mindr = get_param(cmd, "Mindatarate");
3204 const char *meandr = get_param(cmd, "Meandatarate");
3205 const char *peakdr = get_param(cmd, "Peakdatarate");
3206 const char *phyrate = get_param(cmd, "Phyrate");
3207 const char *burstsize = get_param(cmd, "Burstsize");
3208 const char *sba = get_param(cmd, "Sba");
3209 int direction;
3210 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003211 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003212 int fixed_int;
3213 int psb_ts;
3214
3215 if (intf == NULL || grp == NULL || act == NULL )
3216 return -1;
3217
3218 if (strcasecmp(act, "addts") == 0) {
3219 if (tid == NULL || dir == NULL || psb == NULL ||
3220 up == NULL || fixed == NULL || size == NULL)
3221 return -1;
3222
3223 /*
3224 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3225 * possible values, but WMM-AC and V-E test scripts use "UP,
3226 * "DOWN", and "BIDI".
3227 */
3228 if (strcasecmp(dir, "uplink") == 0 ||
3229 strcasecmp(dir, "up") == 0) {
3230 direction = 0;
3231 } else if (strcasecmp(dir, "downlink") == 0 ||
3232 strcasecmp(dir, "down") == 0) {
3233 direction = 1;
3234 } else if (strcasecmp(dir, "bidi") == 0) {
3235 direction = 2;
3236 } else {
3237 sigma_dut_print(dut, DUT_MSG_ERROR,
3238 "Direction %s not supported", dir);
3239 return -1;
3240 }
3241
3242 if (strcasecmp(psb, "legacy") == 0) {
3243 psb_ts = 0;
3244 } else if (strcasecmp(psb, "uapsd") == 0) {
3245 psb_ts = 1;
3246 } else {
3247 sigma_dut_print(dut, DUT_MSG_ERROR,
3248 "PSB %s not supported", psb);
3249 return -1;
3250 }
3251
3252 if (atoi(tid) < 0 || atoi(tid) > 7) {
3253 sigma_dut_print(dut, DUT_MSG_ERROR,
3254 "TID %s not supported", tid);
3255 return -1;
3256 }
3257
3258 if (strcasecmp(fixed, "true") == 0) {
3259 fixed_int = 1;
3260 } else {
3261 fixed_int = 0;
3262 }
3263
Peng Xu93319622017-10-04 17:58:16 -07003264 if (sba)
3265 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003266
3267 dut->dialog_token++;
3268 handle = 7000 + dut->dialog_token;
3269
3270 /*
3271 * size: convert to hex
3272 * maxsi: convert to hex
3273 * mindr: convert to hex
3274 * meandr: convert to hex
3275 * peakdr: convert to hex
3276 * burstsize: convert to hex
3277 * phyrate: convert to hex
3278 * sba: convert to hex with modification
3279 * minsi: convert to integer
3280 * sus: convert to integer
3281 * inact: convert to integer
3282 * maxsi: convert to integer
3283 */
3284
3285 /*
3286 * The Nominal MSDU Size field is 2 octets long and contains an
3287 * unsigned integer that specifies the nominal size, in octets,
3288 * of MSDUs belonging to the traffic under this traffic
3289 * specification and is defined in Figure 16. If the Fixed
3290 * subfield is set to 1, then the size of the MSDU is fixed and
3291 * is indicated by the Size Subfield. If the Fixed subfield is
3292 * set to 0, then the size of the MSDU might not be fixed and
3293 * the Size indicates the nominal MSDU size.
3294 *
3295 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3296 * and specifies the excess allocation of time (and bandwidth)
3297 * over and above the stated rates required to transport an MSDU
3298 * belonging to the traffic in this TSPEC. This field is
3299 * represented as an unsigned binary number with an implicit
3300 * binary point after the leftmost 3 bits. For example, an SBA
3301 * of 1.75 is represented as 0x3800. This field is included to
3302 * account for retransmissions. As such, the value of this field
3303 * must be greater than unity.
3304 */
3305
3306 snprintf(buf, sizeof(buf),
3307 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3308 " 0x%X 0x%X 0x%X"
3309 " 0x%X 0x%X 0x%X"
3310 " 0x%X %d %d %d %d"
3311 " %d %d",
3312 intf, handle, tid, direction, psb_ts, up,
3313 (unsigned int) ((fixed_int << 15) | atoi(size)),
3314 msize ? atoi(msize) : 0,
3315 mindr ? atoi(mindr) : 0,
3316 meandr ? atoi(meandr) : 0,
3317 peakdr ? atoi(peakdr) : 0,
3318 burstsize ? atoi(burstsize) : 0,
3319 phyrate ? atoi(phyrate) : 0,
3320 sba ? ((unsigned int) (((int) sba_fv << 13) |
3321 (int)((sba_fv - (int) sba_fv) *
3322 8192))) : 0,
3323 minsi ? atoi(minsi) : 0,
3324 sus ? atoi(sus) : 0,
3325 0, 0,
3326 inact ? atoi(inact) : 0,
3327 maxsi ? atoi(maxsi) : 0);
3328
3329 if (system(buf) != 0) {
3330 sigma_dut_print(dut, DUT_MSG_ERROR,
3331 "iwpriv addtspec request failed");
3332 send_resp(dut, conn, SIGMA_ERROR,
3333 "errorCode,Failed to execute addTspec command");
3334 return 0;
3335 }
3336
3337 sigma_dut_print(dut, DUT_MSG_INFO,
3338 "iwpriv addtspec request send");
3339
3340 /* Mapping handle to a TID */
3341 dut->tid_to_handle[atoi(tid)] = handle;
3342 } else if (strcasecmp(act, "delts") == 0) {
3343 if (tid == NULL)
3344 return -1;
3345
3346 if (atoi(tid) < 0 || atoi(tid) > 7) {
3347 sigma_dut_print(dut, DUT_MSG_ERROR,
3348 "TID %s not supported", tid);
3349 send_resp(dut, conn, SIGMA_ERROR,
3350 "errorCode,Unsupported TID");
3351 return 0;
3352 }
3353
3354 handle = dut->tid_to_handle[atoi(tid)];
3355
3356 if (handle < 7000 || handle > 7255) {
3357 /* Invalid handle ie no mapping for that TID */
3358 sigma_dut_print(dut, DUT_MSG_ERROR,
3359 "handle-> %d not found", handle);
3360 }
3361
3362 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3363 intf, handle);
3364
3365 if (system(buf) != 0) {
3366 sigma_dut_print(dut, DUT_MSG_ERROR,
3367 "iwpriv deltspec request failed");
3368 send_resp(dut, conn, SIGMA_ERROR,
3369 "errorCode,Failed to execute delTspec command");
3370 return 0;
3371 }
3372
3373 sigma_dut_print(dut, DUT_MSG_INFO,
3374 "iwpriv deltspec request send");
3375
3376 dut->tid_to_handle[atoi(tid)] = 0;
3377 } else {
3378 sigma_dut_print(dut, DUT_MSG_ERROR,
3379 "Action type %s not supported", act);
3380 send_resp(dut, conn, SIGMA_ERROR,
3381 "errorCode,Unsupported Action");
3382 return 0;
3383 }
3384
3385 return 1;
3386}
3387
3388
vamsi krishna52e16f92017-08-29 12:37:34 +05303389static int find_network(struct sigma_dut *dut, const char *ssid)
3390{
3391 char list[4096];
3392 char *pos;
3393
3394 sigma_dut_print(dut, DUT_MSG_DEBUG,
3395 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003396 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303397 list, sizeof(list)) < 0)
3398 return -1;
3399 pos = strstr(list, ssid);
3400 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3401 return -1;
3402
3403 while (pos > list && pos[-1] != '\n')
3404 pos--;
3405 dut->infra_network_id = atoi(pos);
3406 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3407 return 0;
3408}
3409
3410
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303411/**
3412 * enum qca_sta_helper_config_params - This helper enum defines the config
3413 * parameters which can be delivered to sta.
3414 */
3415enum qca_sta_helper_config_params {
3416 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE */
3417 STA_SET_RSNIE,
3418
3419 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC */
3420 STA_SET_LDPC,
3421
3422 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC */
3423 STA_SET_TX_STBC,
3424
3425 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC */
3426 STA_SET_RX_STBC,
3427
3428 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION */
3429 STA_SET_TX_MSDU,
3430
3431 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION */
3432 STA_SET_RX_MSDU,
3433};
3434
3435
3436static int sta_config_params(struct sigma_dut *dut, const char *intf,
3437 enum qca_sta_helper_config_params config_cmd,
3438 int value)
Sunil Dutt44595082018-02-12 19:41:45 +05303439{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303440#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05303441 struct nl_msg *msg;
3442 int ret;
3443 struct nlattr *params;
3444 int ifindex;
3445
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303446 ifindex = if_nametoindex(intf);
3447 if (ifindex == 0) {
3448 sigma_dut_print(dut, DUT_MSG_ERROR,
3449 "%s: Interface %s does not exist",
3450 __func__, intf);
3451 return -1;
3452 }
3453
Sunil Dutt44595082018-02-12 19:41:45 +05303454 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3455 NL80211_CMD_VENDOR)) ||
3456 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3457 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3458 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3459 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303460 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)))
3461 goto fail;
3462
3463 switch (config_cmd) {
3464 case STA_SET_RSNIE:
3465 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, value))
3466 goto fail;
3467 break;
3468 case STA_SET_LDPC:
3469 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC, value))
3470 goto fail;
3471 break;
3472 case STA_SET_TX_STBC:
3473 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC, value))
3474 goto fail;
3475 break;
3476 case STA_SET_RX_STBC:
3477 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC, value))
3478 goto fail;
3479 break;
3480 case STA_SET_TX_MSDU:
3481 if (nla_put_u8(msg,
3482 QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION,
3483 value))
3484 goto fail;
3485 break;
3486 case STA_SET_RX_MSDU:
3487 if (nla_put_u8(msg,
3488 QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION,
3489 value))
3490 goto fail;
3491 break;
Sunil Dutt44595082018-02-12 19:41:45 +05303492 }
3493 nla_nest_end(msg, params);
3494
3495 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3496 if (ret) {
3497 sigma_dut_print(dut, DUT_MSG_ERROR,
3498 "%s: err in send_and_recv_msgs, ret=%d",
3499 __func__, ret);
3500 return ret;
3501 }
3502
3503 return 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303504
3505fail:
3506 sigma_dut_print(dut, DUT_MSG_ERROR,
3507 "%s: err in adding vendor_cmd and vendor_data",
3508 __func__);
3509 nlmsg_free(msg);
Sunil Dutt44595082018-02-12 19:41:45 +05303510#endif /* NL80211_SUPPORT */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303511 return -1;
3512}
Sunil Dutt44595082018-02-12 19:41:45 +05303513
3514
Jouni Malinenf7222712019-06-13 01:50:21 +03003515static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3516 struct sigma_conn *conn,
3517 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003518{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303519#ifdef NL80211_SUPPORT
3520 const char *intf = get_param(cmd, "Interface");
3521#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003522 const char *ssid = get_param(cmd, "ssid");
3523 const char *wps_param = get_param(cmd, "WPS");
3524 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003525 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003526 const char *network_mode = get_param(cmd, "network_mode");
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303527 const char *ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003528 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003529 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003530 int e;
3531 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3532 struct wpa_ctrl *ctrl = NULL;
3533 int num_network_not_found = 0;
3534 int num_disconnected = 0;
3535 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003536
3537 if (ssid == NULL)
3538 return -1;
3539
Jouni Malinen37d5c692019-08-19 16:56:55 +03003540 dut->server_cert_tod = 0;
3541
Jouni Malinen3c367e82017-06-23 17:01:47 +03003542 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303543#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003544 if (get_driver_type(dut) == DRIVER_WCN) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303545 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Sunil Dutt44595082018-02-12 19:41:45 +05303546 dut->config_rsnie = 1;
3547 }
3548#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003549 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3550 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003551 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03003552 send_resp(dut, conn, SIGMA_ERROR,
3553 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3554 return 0;
3555 }
3556 }
3557
Jouni Malinen68143132017-09-02 02:34:08 +03003558 if (dut->sae_commit_override) {
3559 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3560 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003561 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03003562 send_resp(dut, conn, SIGMA_ERROR,
3563 "ErrorCode,Failed to set SAE commit override");
3564 return 0;
3565 }
3566 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303567#ifdef ANDROID
3568 if (dut->fils_hlp)
3569 process_fils_hlp(dut);
3570#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003571
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003572 if (wps_param &&
3573 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3574 wps = 1;
3575
Vamsi Krishnac1633d22020-05-06 18:31:21 +05303576 if (dut->ocvc &&
3577 set_network(get_station_ifname(dut), dut->infra_network_id,
3578 "ocv", "1") < 0)
3579 return ERROR_SEND_STATUS;
3580
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003581 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003582 if (dut->program == PROGRAM_60GHZ && network_mode &&
3583 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003584 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003585 "pbss", "1") < 0)
3586 return -2;
3587
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003588 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3589 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3590 "parameters not yet set");
3591 return 0;
3592 }
3593 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003594 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003595 return -2;
3596 } else {
3597 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3598 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003599 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003600 return -2;
3601 }
3602 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303603 if (strcmp(ssid, dut->infra_ssid) == 0) {
3604 sigma_dut_print(dut, DUT_MSG_DEBUG,
3605 "sta_associate for the most recently added network");
3606 } else if (find_network(dut, ssid) < 0) {
3607 sigma_dut_print(dut, DUT_MSG_DEBUG,
3608 "sta_associate for a previously stored network profile");
3609 send_resp(dut, conn, SIGMA_ERROR,
3610 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003611 return 0;
3612 }
3613
3614 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003615 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003616 "bssid", bssid) < 0) {
3617 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3618 "Invalid bssid argument");
3619 return 0;
3620 }
3621
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303622 if ((dut->program == PROGRAM_WPA3 &&
3623 dut->sta_associate_wait_connect) ||
3624 dut->program == PROGRAM_QM) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003625 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003626 if (!ctrl)
3627 return ERROR_SEND_STATUS;
3628 }
3629
Jouni Malinen46a19b62017-06-23 14:31:27 +03003630 extra[0] = '\0';
3631 if (chan)
3632 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003633 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003634 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3635 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003636 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003637 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3638 "network id %d on %s",
3639 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003640 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003641 ret = ERROR_SEND_STATUS;
3642 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003643 }
3644 }
3645
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003646 if (!ctrl)
3647 return SUCCESS_SEND_STATUS;
3648
3649 /* Wait for connection result to be able to store server certificate
3650 * hash for trust root override testing
3651 * (dev_exec_action,ServerCertTrust). */
3652
3653 for (e = 0; e < 20; e++) {
3654 const char *events[] = {
3655 "CTRL-EVENT-EAP-PEER-CERT",
3656 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3657 "CTRL-EVENT-DISCONNECTED",
3658 "CTRL-EVENT-CONNECTED",
3659 "CTRL-EVENT-NETWORK-NOT-FOUND",
3660 NULL
3661 };
3662 char buf[1024];
3663 int res;
3664
3665 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3666 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02003667 send_resp(dut, conn, SIGMA_COMPLETE,
3668 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003669 ret = STATUS_SENT_ERROR;
3670 break;
3671 }
3672 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3673 buf);
3674
3675 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3676 strstr(buf, " depth=0")) {
3677 char *pos = strstr(buf, " hash=");
3678
3679 if (pos) {
3680 char *end;
3681
Jouni Malinen34b19cb2019-08-16 16:37:17 +03003682 if (strstr(buf, " tod=1"))
3683 tod = 1;
3684 else if (strstr(buf, " tod=2"))
3685 tod = 2;
3686 else
3687 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003688 sigma_dut_print(dut, DUT_MSG_DEBUG,
3689 "Server certificate TOD policy: %d",
3690 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03003691 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003692
3693 pos += 6;
3694 end = strchr(pos, ' ');
3695 if (end)
3696 *end = '\0';
3697 strlcpy(dut->server_cert_hash, pos,
3698 sizeof(dut->server_cert_hash));
3699 sigma_dut_print(dut, DUT_MSG_DEBUG,
3700 "Server certificate hash: %s",
3701 dut->server_cert_hash);
3702 }
3703 }
3704
3705 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3706 send_resp(dut, conn, SIGMA_COMPLETE,
3707 "Result,TLS server certificate validation failed");
3708 ret = STATUS_SENT_ERROR;
3709 break;
3710 }
3711
3712 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3713 num_network_not_found++;
3714
3715 if (num_network_not_found > 2) {
3716 send_resp(dut, conn, SIGMA_COMPLETE,
3717 "Result,Network not found");
3718 ret = STATUS_SENT_ERROR;
3719 break;
3720 }
3721 }
3722
3723 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3724 num_disconnected++;
3725
3726 if (num_disconnected > 2) {
3727 send_resp(dut, conn, SIGMA_COMPLETE,
3728 "Result,Connection failed");
3729 ret = STATUS_SENT_ERROR;
3730 break;
3731 }
3732 }
3733
3734 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3735 if (tod >= 0) {
3736 sigma_dut_print(dut, DUT_MSG_DEBUG,
3737 "Network profile TOD policy update: %d -> %d",
3738 dut->sta_tod_policy, tod);
3739 dut->sta_tod_policy = tod;
3740 }
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303741 if (dut->program == PROGRAM_QM) {
3742 unsigned char iface_mac_addr[ETH_ALEN];
3743 char ipv6[100];
3744
3745 if (get_hwaddr(ifname, iface_mac_addr) < 0) {
3746 sigma_dut_print(dut, DUT_MSG_ERROR,
3747 "%s: get_hwaddr %s failed",
3748 __func__, ifname);
3749 ret = ERROR_SEND_STATUS;
3750 break;
3751 }
3752
3753 convert_mac_addr_to_ipv6_lladdr(iface_mac_addr,
3754 ipv6,
3755 sizeof(ipv6));
3756
3757 if (set_ipv6_addr(dut, ipv6, "64", ifname) !=
3758 0) {
3759 ret = ERROR_SEND_STATUS;
3760 break;
3761 }
3762 }
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003763 break;
3764 }
3765 }
3766done:
3767 if (ctrl) {
3768 wpa_ctrl_detach(ctrl);
3769 wpa_ctrl_close(ctrl);
3770 }
3771 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003772}
3773
3774
3775static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3776{
3777 char buf[500], cmd[200];
3778 int res;
3779
3780 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3781 * default path */
3782 res = snprintf(cmd, sizeof(cmd),
3783 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3784 file_exists("./hs20-osu-client") ?
3785 "./hs20-osu-client" : "hs20-osu-client",
3786 sigma_wpas_ctrl,
3787 dut->summary_log ? "-s " : "",
3788 dut->summary_log ? dut->summary_log : "");
3789 if (res < 0 || res >= (int) sizeof(cmd))
3790 return -1;
3791
3792 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3793 if (res < 0 || res >= (int) sizeof(buf))
3794 return -1;
3795 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3796
3797 if (system(buf) != 0) {
3798 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3799 return -1;
3800 }
3801 sigma_dut_print(dut, DUT_MSG_DEBUG,
3802 "Completed hs20-osu-client operation");
3803
3804 return 0;
3805}
3806
3807
3808static int download_ppsmo(struct sigma_dut *dut,
3809 struct sigma_conn *conn,
3810 const char *intf,
3811 struct sigma_cmd *cmd)
3812{
3813 const char *name, *path, *val;
3814 char url[500], buf[600], fbuf[100];
3815 char *fqdn = NULL;
3816
3817 name = get_param(cmd, "FileName");
3818 path = get_param(cmd, "FilePath");
3819 if (name == NULL || path == NULL)
3820 return -1;
3821
3822 if (strcasecmp(path, "VendorSpecific") == 0) {
3823 snprintf(url, sizeof(url), "PPS/%s", name);
3824 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3825 "from the device (%s)", url);
3826 if (!file_exists(url)) {
3827 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3828 "PPS MO file does not exist");
3829 return 0;
3830 }
3831 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3832 if (system(buf) != 0) {
3833 send_resp(dut, conn, SIGMA_ERROR,
3834 "errorCode,Failed to copy PPS MO");
3835 return 0;
3836 }
3837 } else if (strncasecmp(path, "http:", 5) != 0 &&
3838 strncasecmp(path, "https:", 6) != 0) {
3839 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3840 "Unsupported FilePath value");
3841 return 0;
3842 } else {
3843 snprintf(url, sizeof(url), "%s/%s", path, name);
3844 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3845 url);
3846 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3847 remove("pps-tnds.xml");
3848 if (system(buf) != 0) {
3849 send_resp(dut, conn, SIGMA_ERROR,
3850 "errorCode,Failed to download PPS MO");
3851 return 0;
3852 }
3853 }
3854
3855 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3856 send_resp(dut, conn, SIGMA_ERROR,
3857 "errorCode,Failed to parse downloaded PPSMO");
3858 return 0;
3859 }
3860 unlink("pps-tnds.xml");
3861
3862 val = get_param(cmd, "managementTreeURI");
3863 if (val) {
3864 const char *pos, *end;
3865 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3866 val);
3867 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3868 send_resp(dut, conn, SIGMA_ERROR,
3869 "errorCode,Invalid managementTreeURI prefix");
3870 return 0;
3871 }
3872 pos = val + 8;
3873 end = strchr(pos, '/');
3874 if (end == NULL ||
3875 strcmp(end, "/PerProviderSubscription") != 0) {
3876 send_resp(dut, conn, SIGMA_ERROR,
3877 "errorCode,Invalid managementTreeURI postfix");
3878 return 0;
3879 }
3880 if (end - pos >= (int) sizeof(fbuf)) {
3881 send_resp(dut, conn, SIGMA_ERROR,
3882 "errorCode,Too long FQDN in managementTreeURI");
3883 return 0;
3884 }
3885 memcpy(fbuf, pos, end - pos);
3886 fbuf[end - pos] = '\0';
3887 fqdn = fbuf;
3888 sigma_dut_print(dut, DUT_MSG_INFO,
3889 "FQDN from managementTreeURI: %s", fqdn);
3890 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3891 FILE *f = fopen("pps-fqdn", "r");
3892 if (f) {
3893 if (fgets(fbuf, sizeof(fbuf), f)) {
3894 fbuf[sizeof(fbuf) - 1] = '\0';
3895 fqdn = fbuf;
3896 sigma_dut_print(dut, DUT_MSG_DEBUG,
3897 "Use FQDN %s", fqdn);
3898 }
3899 fclose(f);
3900 }
3901 }
3902
3903 if (fqdn == NULL) {
3904 send_resp(dut, conn, SIGMA_ERROR,
3905 "errorCode,No FQDN specified");
3906 return 0;
3907 }
3908
3909 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3910 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3911 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3912
3913 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3914 if (rename("pps.xml", buf) < 0) {
3915 send_resp(dut, conn, SIGMA_ERROR,
3916 "errorCode,Could not move PPS MO");
3917 return 0;
3918 }
3919
3920 if (strcasecmp(path, "VendorSpecific") == 0) {
3921 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3922 fqdn);
3923 if (system(buf)) {
3924 send_resp(dut, conn, SIGMA_ERROR,
3925 "errorCode,Failed to copy OSU CA cert");
3926 return 0;
3927 }
3928
3929 snprintf(buf, sizeof(buf),
3930 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3931 fqdn);
3932 if (system(buf)) {
3933 send_resp(dut, conn, SIGMA_ERROR,
3934 "errorCode,Failed to copy AAA CA cert");
3935 return 0;
3936 }
3937 } else {
3938 snprintf(buf, sizeof(buf),
3939 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3940 fqdn, fqdn);
3941 if (run_hs20_osu(dut, buf) < 0) {
3942 send_resp(dut, conn, SIGMA_ERROR,
3943 "errorCode,Failed to download OSU CA cert");
3944 return 0;
3945 }
3946
3947 snprintf(buf, sizeof(buf),
3948 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3949 fqdn, fqdn);
3950 if (run_hs20_osu(dut, buf) < 0) {
3951 sigma_dut_print(dut, DUT_MSG_INFO,
3952 "Failed to download AAA CA cert");
3953 }
3954 }
3955
3956 if (file_exists("next-client-cert.pem")) {
3957 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3958 if (rename("next-client-cert.pem", buf) < 0) {
3959 send_resp(dut, conn, SIGMA_ERROR,
3960 "errorCode,Could not move client certificate");
3961 return 0;
3962 }
3963 }
3964
3965 if (file_exists("next-client-key.pem")) {
3966 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3967 if (rename("next-client-key.pem", buf) < 0) {
3968 send_resp(dut, conn, SIGMA_ERROR,
3969 "errorCode,Could not move client key");
3970 return 0;
3971 }
3972 }
3973
3974 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3975 if (run_hs20_osu(dut, buf) < 0) {
3976 send_resp(dut, conn, SIGMA_ERROR,
3977 "errorCode,Failed to configure credential from "
3978 "PPSMO");
3979 return 0;
3980 }
3981
3982 return 1;
3983}
3984
3985
3986static int download_cert(struct sigma_dut *dut,
3987 struct sigma_conn *conn,
3988 const char *intf,
3989 struct sigma_cmd *cmd)
3990{
3991 const char *name, *path;
3992 char url[500], buf[600];
3993
3994 name = get_param(cmd, "FileName");
3995 path = get_param(cmd, "FilePath");
3996 if (name == NULL || path == NULL)
3997 return -1;
3998
3999 if (strcasecmp(path, "VendorSpecific") == 0) {
4000 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
4001 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4002 "certificate from the device (%s)", url);
4003 if (!file_exists(url)) {
4004 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4005 "certificate file does not exist");
4006 return 0;
4007 }
4008 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
4009 if (system(buf) != 0) {
4010 send_resp(dut, conn, SIGMA_ERROR,
4011 "errorCode,Failed to copy client "
4012 "certificate");
4013 return 0;
4014 }
4015
4016 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
4017 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4018 "private key from the device (%s)", url);
4019 if (!file_exists(url)) {
4020 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4021 "private key file does not exist");
4022 return 0;
4023 }
4024 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
4025 if (system(buf) != 0) {
4026 send_resp(dut, conn, SIGMA_ERROR,
4027 "errorCode,Failed to copy client key");
4028 return 0;
4029 }
4030 } else if (strncasecmp(path, "http:", 5) != 0 &&
4031 strncasecmp(path, "https:", 6) != 0) {
4032 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4033 "Unsupported FilePath value");
4034 return 0;
4035 } else {
4036 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
4037 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
4038 "certificate/key from %s", url);
4039 snprintf(buf, sizeof(buf),
4040 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
4041 if (system(buf) != 0) {
4042 send_resp(dut, conn, SIGMA_ERROR,
4043 "errorCode,Failed to download client "
4044 "certificate");
4045 return 0;
4046 }
4047
4048 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
4049 {
4050 send_resp(dut, conn, SIGMA_ERROR,
4051 "errorCode,Failed to copy client key");
4052 return 0;
4053 }
4054 }
4055
4056 return 1;
4057}
4058
4059
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004060static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
4061 struct sigma_conn *conn,
4062 struct sigma_cmd *cmd)
4063{
4064 const char *val;
4065 const char *intf = get_param(cmd, "interface");
4066
4067 if (!intf)
4068 return -1;
4069
4070 val = get_param(cmd, "WscIEFragment");
4071 if (val && strcasecmp(val, "enable") == 0) {
4072 sigma_dut_print(dut, DUT_MSG_DEBUG,
4073 "Enable WSC IE fragmentation");
4074
4075 dut->wsc_fragment = 1;
4076 /* set long attributes to force fragmentation */
4077 if (wpa_command(intf, "SET device_name "
4078 WPS_LONG_DEVICE_NAME) < 0)
4079 return -2;
4080 if (wpa_command(intf, "SET manufacturer "
4081 WPS_LONG_MANUFACTURER) < 0)
4082 return -2;
4083 if (wpa_command(intf, "SET model_name "
4084 WPS_LONG_MODEL_NAME) < 0)
4085 return -2;
4086 if (wpa_command(intf, "SET model_number "
4087 WPS_LONG_MODEL_NUMBER) < 0)
4088 return -2;
4089 if (wpa_command(intf, "SET serial_number "
4090 WPS_LONG_SERIAL_NUMBER) < 0)
4091 return -2;
4092 }
4093
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02004094 val = get_param(cmd, "RSN_IE");
4095 if (val) {
4096 if (strcasecmp(val, "disable") == 0)
4097 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
4098 else if (strcasecmp(val, "enable") == 0)
4099 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
4100 }
4101
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004102 val = get_param(cmd, "WpsVersion");
4103 if (val)
4104 dut->wps_forced_version = get_wps_forced_version(dut, val);
4105
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004106 val = get_param(cmd, "WscEAPFragment");
4107 if (val && strcasecmp(val, "enable") == 0)
4108 dut->eap_fragment = 1;
4109
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004110 return 1;
4111}
4112
4113
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004114static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4115 struct sigma_conn *conn,
4116 const char *intf,
4117 struct sigma_cmd *cmd)
4118{
4119 const char *val;
4120
4121 val = get_param(cmd, "FileType");
4122 if (val && strcasecmp(val, "PPSMO") == 0)
4123 return download_ppsmo(dut, conn, intf, cmd);
4124 if (val && strcasecmp(val, "CERT") == 0)
4125 return download_cert(dut, conn, intf, cmd);
4126 if (val) {
4127 send_resp(dut, conn, SIGMA_ERROR,
4128 "ErrorCode,Unsupported FileType");
4129 return 0;
4130 }
4131
4132 return 1;
4133}
4134
4135
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304136static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4137 struct sigma_conn *conn,
4138 const char *intf,
4139 struct sigma_cmd *cmd)
4140{
4141 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304142 char buf[1000];
4143 char text[20];
4144 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304145
4146 val = get_param(cmd, "OCESupport");
4147 if (val && strcasecmp(val, "Disable") == 0) {
4148 if (wpa_command(intf, "SET oce 0") < 0) {
4149 send_resp(dut, conn, SIGMA_ERROR,
4150 "ErrorCode,Failed to disable OCE");
4151 return 0;
4152 }
4153 } else if (val && strcasecmp(val, "Enable") == 0) {
4154 if (wpa_command(intf, "SET oce 1") < 0) {
4155 send_resp(dut, conn, SIGMA_ERROR,
4156 "ErrorCode,Failed to enable OCE");
4157 return 0;
4158 }
4159 }
4160
vamsi krishnaa2799492017-12-05 14:28:01 +05304161 val = get_param(cmd, "FILScap");
4162 if (val && (atoi(val) == 1)) {
4163 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4164 send_resp(dut, conn, SIGMA_ERROR,
4165 "ErrorCode,Failed to enable FILS");
4166 return 0;
4167 }
4168 } else if (val && (atoi(val) == 0)) {
4169 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4170 send_resp(dut, conn, SIGMA_ERROR,
4171 "ErrorCode,Failed to disable FILS");
4172 return 0;
4173 }
4174 }
4175
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304176 val = get_param(cmd, "FILSHLP");
4177 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004178 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304179 sizeof(text)) < 0)
4180 return -2;
4181 hwaddr_aton(text, addr);
4182 snprintf(buf, sizeof(buf),
4183 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4184 "080045100140000040004011399e00000000ffffffff00440043"
4185 "012cb30001010600fd4f46410000000000000000000000000000"
4186 "000000000000"
4187 "%02x%02x%02x%02x%02x%02x"
4188 "0000000000000000000000000000000000000000000000000000"
4189 "0000000000000000000000000000000000000000000000000000"
4190 "0000000000000000000000000000000000000000000000000000"
4191 "0000000000000000000000000000000000000000000000000000"
4192 "0000000000000000000000000000000000000000000000000000"
4193 "0000000000000000000000000000000000000000000000000000"
4194 "0000000000000000000000000000000000000000000000000000"
4195 "0000000000000000000000000000000000000000638253633501"
4196 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4197 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4198 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4199 if (wpa_command(intf, buf)) {
4200 send_resp(dut, conn, SIGMA_ERROR,
4201 "ErrorCode,Failed to add HLP");
4202 return 0;
4203 }
4204 dut->fils_hlp = 1;
4205 }
4206
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304207 return 1;
4208}
4209
4210
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004211static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4212 const char *val)
4213{
4214 int counter = 0;
4215 char token[50];
4216 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304217 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004218
Peng Xub8fc5cc2017-05-10 17:27:28 -07004219 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004220 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304221 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004222 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004223 if (strcmp(result, "disable") == 0)
4224 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4225 else
4226 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304227 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004228 counter++;
4229 }
4230}
4231
4232
4233static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4234 const char *val)
4235{
4236 char buf[100];
4237
4238 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4239 if (system(buf) != 0) {
4240 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4241 }
4242}
4243
4244
4245static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4246 const char *val)
4247{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004248 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004249 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004250 }
4251}
4252
4253
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004254static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4255 const char *val)
4256{
4257#ifdef NL80211_SUPPORT
4258 struct nl_msg *msg;
4259 int ret = 0;
4260 struct nlattr *params;
4261 int ifindex;
4262 int wmmenable = 1;
4263
4264 if (val &&
4265 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4266 wmmenable = 0;
4267
4268 ifindex = if_nametoindex(intf);
4269 if (ifindex == 0) {
4270 sigma_dut_print(dut, DUT_MSG_ERROR,
4271 "%s: Index for interface %s failed",
4272 __func__, intf);
4273 return -1;
4274 }
4275
4276 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4277 NL80211_CMD_VENDOR)) ||
4278 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4279 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4280 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4281 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4282 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4283 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4284 wmmenable)) {
4285 sigma_dut_print(dut, DUT_MSG_ERROR,
4286 "%s: err in adding vendor_cmd and vendor_data",
4287 __func__);
4288 nlmsg_free(msg);
4289 return -1;
4290 }
4291 nla_nest_end(msg, params);
4292
4293 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4294 if (ret) {
4295 sigma_dut_print(dut, DUT_MSG_ERROR,
4296 "%s: err in send_and_recv_msgs, ret=%d",
4297 __func__, ret);
4298 }
4299 return ret;
4300#else /* NL80211_SUPPORT */
4301 sigma_dut_print(dut, DUT_MSG_ERROR,
4302 "WMM cannot be changed without NL80211_SUPPORT defined");
4303 return -1;
4304#endif /* NL80211_SUPPORT */
4305}
4306
4307
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004308static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4309 const char *val)
4310{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004311 int sgi20;
4312
4313 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4314
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004315 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004316}
4317
4318
4319static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4320 const char *val)
4321{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304322 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004323
4324 /* Disable Tx Beam forming when using a fixed rate */
4325 ath_disable_txbf(dut, intf);
4326
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304327 v = atoi(val);
4328 if (v < 0 || v > 32) {
4329 sigma_dut_print(dut, DUT_MSG_ERROR,
4330 "Invalid Fixed MCS rate: %d", v);
4331 return;
4332 }
4333 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004334
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004335 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004336
4337 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004338 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004339}
4340
4341
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004342static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4343 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004344{
4345 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304346 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004347
4348 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4349 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4350 else
4351 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4352
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304353 ret = system(buf);
4354#ifdef NL80211_SUPPORT
4355 if (ret) {
4356 int value = (strcasecmp(val, "Enable") == 0) ? 2 : 1;
4357
4358 ret = sta_config_params(dut, intf, STA_SET_TX_MSDU, value);
4359 ret |= sta_config_params(dut, intf, STA_SET_RX_MSDU, value);
4360 }
4361#endif /* NL80211_SUPPORT */
4362 if (ret)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004363 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4364}
4365
4366
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004367static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4368 int ampdu)
4369{
4370 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004371 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004372
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004373 if (ampdu)
4374 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004375 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4376 if (system(buf) != 0) {
4377 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4378 return -1;
4379 }
4380
4381 return 0;
4382}
4383
4384
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004385static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4386 const char *val)
4387{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004388 run_iwpriv(dut, intf, "tx_stbc %s", val);
4389 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004390}
4391
4392
4393static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4394 const char *val)
4395{
4396 char buf[60];
4397
Peng Xucc317ed2017-05-18 16:44:37 -07004398 if (strcmp(val, "160") == 0) {
4399 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4400 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004401 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4402 } else if (strcmp(val, "40") == 0) {
4403 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4404 } else if (strcmp(val, "20") == 0) {
4405 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4406 } else if (strcasecmp(val, "Auto") == 0) {
4407 buf[0] = '\0';
4408 } else {
4409 sigma_dut_print(dut, DUT_MSG_ERROR,
4410 "WIDTH/CTS_WIDTH value not supported");
4411 return -1;
4412 }
4413
4414 if (buf[0] != '\0' && system(buf) != 0) {
4415 sigma_dut_print(dut, DUT_MSG_ERROR,
4416 "Failed to set WIDTH/CTS_WIDTH");
4417 return -1;
4418 }
4419
4420 return 0;
4421}
4422
4423
4424int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4425 const char *intf, const char *val)
4426{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004427 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004428 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004429 dut->chwidth = 0;
4430 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004431 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004432 dut->chwidth = 0;
4433 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004434 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004435 dut->chwidth = 1;
4436 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004437 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004438 dut->chwidth = 2;
4439 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004440 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004441 dut->chwidth = 3;
4442 } else {
4443 send_resp(dut, conn, SIGMA_ERROR,
4444 "ErrorCode,WIDTH not supported");
4445 return -1;
4446 }
4447
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004448 return 0;
4449}
4450
4451
4452static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4453 const char *val)
4454{
4455 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004456 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004457
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004458 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004459 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004460 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004461 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004462 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004463 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004464 } else {
4465 sigma_dut_print(dut, DUT_MSG_ERROR,
4466 "SP_STREAM value not supported");
4467 return -1;
4468 }
4469
4470 if (system(buf) != 0) {
4471 sigma_dut_print(dut, DUT_MSG_ERROR,
4472 "Failed to set SP_STREAM");
4473 return -1;
4474 }
4475
Arif Hussainac6c5112018-05-25 17:34:00 -07004476 dut->sta_nss = sta_nss;
4477
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004478 return 0;
4479}
4480
4481
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304482static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4483 const char *val)
4484{
4485 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304486 int ret;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304487
4488 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304489 ret = system(buf);
4490#ifdef NL80211_SUPPORT
4491 if (ret)
4492 ret = sta_config_params(dut, intf, STA_SET_TX_STBC,
4493 strcmp(val, "0") == 0 ? 0 : 1);
4494#endif /* NL80211_SUPPORT */
4495 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304496 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4497
4498 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304499 ret = system(buf);
4500#ifdef NL80211_SUPPORT
4501 if (ret)
4502 ret = sta_config_params(dut, intf, STA_SET_RX_STBC,
4503 strcmp(val, "0") == 0 ? 0 : 1);
4504#endif /* NL80211_SUPPORT */
4505 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304506 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4507}
4508
4509
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304510static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4511 struct sigma_conn *conn,
4512 const char *intf, int capa)
4513{
4514 char buf[32];
4515
4516 if (capa > 0 && capa < 4) {
4517 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4518 if (wpa_command(intf, buf) < 0) {
4519 send_resp(dut, conn, SIGMA_ERROR,
4520 "ErrorCode, Failed to set cellular data capability");
4521 return 0;
4522 }
4523 return 1;
4524 }
4525
4526 sigma_dut_print(dut, DUT_MSG_ERROR,
4527 "Invalid Cellular data capability: %d", capa);
4528 send_resp(dut, conn, SIGMA_INVALID,
4529 "ErrorCode,Invalid cellular data capability");
4530 return 0;
4531}
4532
4533
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304534static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4535 const char *intf, const char *val)
4536{
4537 if (strcasecmp(val, "Disable") == 0) {
4538 if (wpa_command(intf, "SET roaming 0") < 0) {
4539 send_resp(dut, conn, SIGMA_ERROR,
4540 "ErrorCode,Failed to disable roaming");
4541 return 0;
4542 }
4543 return 1;
4544 }
4545
4546 if (strcasecmp(val, "Enable") == 0) {
4547 if (wpa_command(intf, "SET roaming 1") < 0) {
4548 send_resp(dut, conn, SIGMA_ERROR,
4549 "ErrorCode,Failed to enable roaming");
4550 return 0;
4551 }
4552 return 1;
4553 }
4554
4555 sigma_dut_print(dut, DUT_MSG_ERROR,
4556 "Invalid value provided for roaming: %s", val);
4557 send_resp(dut, conn, SIGMA_INVALID,
4558 "ErrorCode,Unknown value provided for Roaming");
4559 return 0;
4560}
4561
4562
Ashwini Patila75de5a2017-04-13 16:35:05 +05304563static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4564 struct sigma_conn *conn,
4565 const char *intf, const char *val)
4566{
4567 if (strcasecmp(val, "Disable") == 0) {
4568 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4569 send_resp(dut, conn, SIGMA_ERROR,
4570 "ErrorCode,Failed to disable Assoc_disallow");
4571 return 0;
4572 }
4573 return 1;
4574 }
4575
4576 if (strcasecmp(val, "Enable") == 0) {
4577 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4578 send_resp(dut, conn, SIGMA_ERROR,
4579 "ErrorCode,Failed to enable Assoc_disallow");
4580 return 0;
4581 }
4582 return 1;
4583 }
4584
4585 sigma_dut_print(dut, DUT_MSG_ERROR,
4586 "Invalid value provided for Assoc_disallow: %s", val);
4587 send_resp(dut, conn, SIGMA_INVALID,
4588 "ErrorCode,Unknown value provided for Assoc_disallow");
4589 return 0;
4590}
4591
4592
Ashwini Patilc63161e2017-04-13 16:30:23 +05304593static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4594 const char *intf, const char *val)
4595{
4596 if (strcasecmp(val, "Reject") == 0) {
4597 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4598 send_resp(dut, conn, SIGMA_ERROR,
4599 "ErrorCode,Failed to Reject BTM Request");
4600 return 0;
4601 }
4602 return 1;
4603 }
4604
4605 if (strcasecmp(val, "Accept") == 0) {
4606 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4607 send_resp(dut, conn, SIGMA_ERROR,
4608 "ErrorCode,Failed to Accept BTM Request");
4609 return 0;
4610 }
4611 return 1;
4612 }
4613
4614 sigma_dut_print(dut, DUT_MSG_ERROR,
4615 "Invalid value provided for BSS_Transition: %s", val);
4616 send_resp(dut, conn, SIGMA_INVALID,
4617 "ErrorCode,Unknown value provided for BSS_Transition");
4618 return 0;
4619}
4620
4621
Ashwini Patil00402582017-04-13 12:29:39 +05304622static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4623 struct sigma_conn *conn,
4624 const char *intf,
4625 struct sigma_cmd *cmd)
4626{
4627 const char *ch, *pref, *op_class, *reason;
4628 char buf[120];
4629 int len, ret;
4630
4631 pref = get_param(cmd, "Ch_Pref");
4632 if (!pref)
4633 return 1;
4634
4635 if (strcasecmp(pref, "clear") == 0) {
4636 free(dut->non_pref_ch_list);
4637 dut->non_pref_ch_list = NULL;
4638 } else {
4639 op_class = get_param(cmd, "Ch_Op_Class");
4640 if (!op_class) {
4641 send_resp(dut, conn, SIGMA_INVALID,
4642 "ErrorCode,Ch_Op_Class not provided");
4643 return 0;
4644 }
4645
4646 ch = get_param(cmd, "Ch_Pref_Num");
4647 if (!ch) {
4648 send_resp(dut, conn, SIGMA_INVALID,
4649 "ErrorCode,Ch_Pref_Num not provided");
4650 return 0;
4651 }
4652
4653 reason = get_param(cmd, "Ch_Reason_Code");
4654 if (!reason) {
4655 send_resp(dut, conn, SIGMA_INVALID,
4656 "ErrorCode,Ch_Reason_Code not provided");
4657 return 0;
4658 }
4659
4660 if (!dut->non_pref_ch_list) {
4661 dut->non_pref_ch_list =
4662 calloc(1, NON_PREF_CH_LIST_SIZE);
4663 if (!dut->non_pref_ch_list) {
4664 send_resp(dut, conn, SIGMA_ERROR,
4665 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4666 return 0;
4667 }
4668 }
4669 len = strlen(dut->non_pref_ch_list);
4670 ret = snprintf(dut->non_pref_ch_list + len,
4671 NON_PREF_CH_LIST_SIZE - len,
4672 " %s:%s:%s:%s", op_class, ch, pref, reason);
4673 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4674 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4675 dut->non_pref_ch_list);
4676 } else {
4677 sigma_dut_print(dut, DUT_MSG_ERROR,
4678 "snprintf failed for non_pref_list, ret = %d",
4679 ret);
4680 send_resp(dut, conn, SIGMA_ERROR,
4681 "ErrorCode,snprintf failed");
4682 free(dut->non_pref_ch_list);
4683 dut->non_pref_ch_list = NULL;
4684 return 0;
4685 }
4686 }
4687
4688 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4689 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4690 if (ret < 0 || ret >= (int) sizeof(buf)) {
4691 sigma_dut_print(dut, DUT_MSG_DEBUG,
4692 "snprintf failed for set non_pref_chan, ret: %d",
4693 ret);
4694 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4695 return 0;
4696 }
4697
4698 if (wpa_command(intf, buf) < 0) {
4699 send_resp(dut, conn, SIGMA_ERROR,
4700 "ErrorCode,Failed to set non-preferred channel list");
4701 return 0;
4702 }
4703
4704 return 1;
4705}
4706
4707
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004708#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004709
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004710static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4711 uint8_t cfg)
4712{
4713 struct nl_msg *msg;
4714 int ret = 0;
4715 struct nlattr *params;
4716 int ifindex;
4717
4718 ifindex = if_nametoindex(intf);
4719 if (ifindex == 0) {
4720 sigma_dut_print(dut, DUT_MSG_ERROR,
4721 "%s: Index for interface %s failed",
4722 __func__, intf);
4723 return -1;
4724 }
4725
4726 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4727 NL80211_CMD_VENDOR)) ||
4728 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4729 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4730 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4731 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4732 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4733 nla_put_u8(msg,
4734 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4735 cfg)) {
4736 sigma_dut_print(dut, DUT_MSG_ERROR,
4737 "%s: err in adding vendor_cmd and vendor_data",
4738 __func__);
4739 nlmsg_free(msg);
4740 return -1;
4741 }
4742 nla_nest_end(msg, params);
4743
4744 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4745 if (ret) {
4746 sigma_dut_print(dut, DUT_MSG_ERROR,
4747 "%s: err in send_and_recv_msgs, ret=%d",
4748 __func__, ret);
4749 }
4750 return ret;
4751}
4752
4753
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004754static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4755 enum he_fragmentation_val frag)
4756{
4757 struct nl_msg *msg;
4758 int ret = 0;
4759 struct nlattr *params;
4760 int ifindex;
4761
4762 ifindex = if_nametoindex(intf);
4763 if (ifindex == 0) {
4764 sigma_dut_print(dut, DUT_MSG_ERROR,
4765 "%s: Index for interface %s failed",
4766 __func__, intf);
4767 return -1;
4768 }
4769
4770 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4771 NL80211_CMD_VENDOR)) ||
4772 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4773 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4774 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4775 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4776 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4777 nla_put_u8(msg,
4778 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
4779 frag)) {
4780 sigma_dut_print(dut, DUT_MSG_ERROR,
4781 "%s: err in adding vendor_cmd and vendor_data",
4782 __func__);
4783 nlmsg_free(msg);
4784 return -1;
4785 }
4786 nla_nest_end(msg, params);
4787
4788 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4789 if (ret) {
4790 sigma_dut_print(dut, DUT_MSG_ERROR,
4791 "%s: err in send_and_recv_msgs, ret=%d",
4792 __func__, ret);
4793 }
4794 return ret;
4795}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004796
4797
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08004798int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
4799 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004800{
4801 struct nl_msg *msg;
4802 int ret = 0;
4803 struct nlattr *params;
4804 int ifindex;
4805
4806 ifindex = if_nametoindex(intf);
4807 if (ifindex == 0) {
4808 sigma_dut_print(dut, DUT_MSG_ERROR,
4809 "%s: Index for interface %s failed",
4810 __func__, intf);
4811 return -1;
4812 }
4813
4814 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4815 NL80211_CMD_VENDOR)) ||
4816 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4817 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4818 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4819 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4820 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4821 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
4822 ltf)) {
4823 sigma_dut_print(dut, DUT_MSG_ERROR,
4824 "%s: err in adding vendor_cmd and vendor_data",
4825 __func__);
4826 nlmsg_free(msg);
4827 return -1;
4828 }
4829 nla_nest_end(msg, params);
4830
4831 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4832 if (ret) {
4833 sigma_dut_print(dut, DUT_MSG_ERROR,
4834 "%s: err in send_and_recv_msgs, ret=%d",
4835 __func__, ret);
4836 }
4837 return ret;
4838}
4839
4840
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004841static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4842 int noack, enum qca_wlan_ac_type ac)
4843{
4844 struct nl_msg *msg;
4845 int ret = 0;
4846 struct nlattr *params;
4847 int ifindex;
4848
4849 ifindex = if_nametoindex(intf);
4850 if (ifindex == 0) {
4851 sigma_dut_print(dut, DUT_MSG_ERROR,
4852 "%s: Index for interface %s failed",
4853 __func__, intf);
4854 return -1;
4855 }
4856
4857 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4858 NL80211_CMD_VENDOR)) ||
4859 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4860 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4861 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4862 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4863 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4864 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4865 noack) ||
4866 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4867 ac)) {
4868 sigma_dut_print(dut, DUT_MSG_ERROR,
4869 "%s: err in adding vendor_cmd and vendor_data",
4870 __func__);
4871 nlmsg_free(msg);
4872 return -1;
4873 }
4874 nla_nest_end(msg, params);
4875
4876 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4877 if (ret) {
4878 sigma_dut_print(dut, DUT_MSG_ERROR,
4879 "%s: err in send_and_recv_msgs, ret=%d",
4880 __func__, ret);
4881 }
4882 return ret;
4883}
4884
4885
4886static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4887 const char *val)
4888{
4889 int noack, ret;
4890 char token[100];
4891 char *result;
4892 char *saveptr;
4893 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4894
4895 strlcpy(token, val, sizeof(token));
4896 token[sizeof(token) - 1] = '\0';
4897 result = strtok_r(token, ":", &saveptr);
4898 while (result) {
4899 noack = strcasecmp(result, "Disable") != 0;
4900 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4901 if (ret) {
4902 sigma_dut_print(dut, DUT_MSG_ERROR,
4903 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4904 ac, ret);
4905 }
4906 result = strtok_r(NULL, ":", &saveptr);
4907 ac++;
4908 }
4909}
4910
Vinita S. Maloo7462e812020-05-22 15:16:04 +05304911
4912static int nlvendor_sta_set_phymode(struct sigma_dut *dut, const char *intf,
4913 enum qca_wlan_vendor_phy_mode val)
4914{
4915 struct nl_msg *msg;
4916 struct nlattr *params;
4917 int ifindex, ret;
4918
4919 ifindex = if_nametoindex(intf);
4920 if (ifindex == 0) {
4921 sigma_dut_print(dut, DUT_MSG_ERROR,
4922 "%s: Index for interface %s not found",
4923 __func__, intf);
4924 return -1;
4925 }
4926
4927 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4928 NL80211_CMD_VENDOR);
4929 if (!msg) {
4930 sigma_dut_print(dut, DUT_MSG_ERROR,
4931 "%s: err in adding vendor_cmd", __func__);
4932 return -1;
4933 }
4934
4935 if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4936 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4937 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) {
4938 sigma_dut_print(dut, DUT_MSG_ERROR,
4939 "%s: err in adding vendor_attr", __func__);
4940 nlmsg_free(msg);
4941 return -1;
4942 }
4943
4944 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
4945 if (!params || nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_PHY_MODE,
4946 val)) {
4947 sigma_dut_print(dut, DUT_MSG_ERROR,
4948 "%s: err in adding vendor_data", __func__);
4949 nlmsg_free(msg);
4950 return -1;
4951 }
4952
4953 nla_nest_end(msg, params);
4954 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4955 if (ret) {
4956 sigma_dut_print(dut, DUT_MSG_ERROR,
4957 "%s: err in send_and_recv_msgs, ret=%d (%s)",
4958 __func__, ret, strerror(-ret));
4959 return ret;
4960 }
4961
4962 return 0;
4963}
4964
4965
4966static enum qca_wlan_vendor_phy_mode get_qca_vendor_phymode(const char *val)
4967{
4968 if (strcmp(val, "11a") == 0) {
4969 /* IEEE80211_MODE_11A */
4970 return QCA_WLAN_VENDOR_PHY_MODE_11A;
4971 }
4972
4973 if (strcmp(val, "11g") == 0) {
4974 /* IEEE80211_MODE_11G */
4975 return QCA_WLAN_VENDOR_PHY_MODE_11G;
4976 }
4977
4978 if (strcmp(val, "11b") == 0) {
4979 /* IEEE80211_MODE_11B */
4980 return QCA_WLAN_VENDOR_PHY_MODE_11B;
4981 }
4982
4983 if (strcmp(val, "11n") == 0 ||
4984 strcmp(val, "11nl") == 0 ||
4985 strcmp(val, "11nl(nabg)") == 0) {
4986 /* IEEE80211_MODE_11AGN */
4987 return QCA_WLAN_VENDOR_PHY_MODE_11AGN;
4988 }
4989
4990 if (strcmp(val, "11ng") == 0) {
4991 /* IEEE80211_MODE_11NG_HT40 */
4992 return QCA_WLAN_VENDOR_PHY_MODE_11NG_HT40;
4993 }
4994
4995 if (strcmp(val, "AC") == 0 ||
4996 strcasecmp(val, "11AC") == 0) {
4997 /* IEEE80211_MODE_11AC_VHT80 */
4998 return QCA_WLAN_VENDOR_PHY_MODE_11AC_VHT80;
4999 }
5000
5001 if (strcmp(val, "11na") == 0 ||
5002 strcasecmp(val, "11an") == 0) {
5003 /* IEEE80211_MODE_11NA_HT40 */
5004 return QCA_WLAN_VENDOR_PHY_MODE_11NA_HT40;
5005 }
5006
5007 if (strcmp(val, "11ax") == 0 ||
5008 strcmp(val, "auto") == 0) {
5009 /* IEEE80211_MODE_AUTO */
5010 return QCA_WLAN_VENDOR_PHY_MODE_AUTO;
5011 }
5012
5013 return -1;
5014}
5015
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005016#endif /* NL80211_SUPPORT */
5017
5018
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305019static int get_phymode(const char *val)
5020{
5021 if (strcmp(val, "11a") == 0)
5022 return 1; /* IEEE80211_MODE_11A */
5023 if (strcmp(val, "11g") == 0)
5024 return 3; /* IEEE80211_MODE_11G */
5025 if (strcmp(val, "11b") == 0)
5026 return 2; /* IEEE80211_MODE_11B */
5027 if (strcmp(val, "11n") == 0 ||
5028 strcmp(val, "11nl") == 0 ||
5029 strcmp(val, "11nl(nabg)") == 0)
5030 return 22; /* IEEE80211_MODE_11AGN */
5031 if (strcmp(val, "11ng") == 0)
5032 return 13; /* IEEE80211_MODE_11NG_HT40 */
5033 if (strcmp(val, "AC") == 0 ||
5034 strcasecmp(val, "11AC") == 0)
5035 return 19; /* IEEE80211_MODE_11AC_VHT80 */
5036 if (strcmp(val, "11na") == 0 ||
5037 strcasecmp(val, "11an") == 0)
5038 return 14; /* IEEE80211_MODE_11NA_HT40 */
5039 if (strcmp(val, "11ax") == 0 ||
5040 strcmp(val, "auto") == 0)
5041 return 0; /* IEEE80211_MODE_AUTO */
5042 return -1;
5043}
5044
5045
5046static void sta_set_phymode(struct sigma_dut *dut, const char *intf,
5047 const char *val)
5048{
5049 char buf[100];
5050 int len, phymode;
Vinita S. Maloo7462e812020-05-22 15:16:04 +05305051#ifdef NL80211_SUPPORT
5052 enum qca_wlan_vendor_phy_mode qca_phymode;
5053
5054 qca_phymode = get_qca_vendor_phymode(val);
5055 if (qca_phymode == -1) {
5056 sigma_dut_print(dut, DUT_MSG_DEBUG,
5057 "Ignoring mode change for mode: %s",
5058 val);
5059 return;
5060 }
5061
5062 if (nlvendor_sta_set_phymode(dut, intf, qca_phymode) == 0)
5063 return;
5064#endif /* NL80211_SUPPORT */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305065
5066 phymode = get_phymode(val);
5067 if (phymode == -1) {
5068 sigma_dut_print(dut, DUT_MSG_DEBUG,
5069 "Ignoring mode change for mode: %s",
5070 val);
5071 return;
5072 }
5073
5074 len = snprintf(buf, sizeof(buf), "iwpriv %s setphymode %d", intf,
5075 phymode);
5076 if (len < 0 || len >= sizeof(buf)) {
5077 sigma_dut_print(dut, DUT_MSG_ERROR,
5078 "Failed to set phymode");
5079 return;
5080 }
5081
5082 if (system(buf) != 0)
5083 sigma_dut_print(dut, DUT_MSG_ERROR,
5084 "iwpriv setting of phymode failed");
5085}
5086
5087
Jouni Malinenf7222712019-06-13 01:50:21 +03005088static enum sigma_cmd_result
5089cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
5090 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005091{
5092 const char *intf = get_param(cmd, "Interface");
5093 const char *val;
5094
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03005095 val = get_param(cmd, "FT_DS");
5096 if (val) {
5097 if (strcasecmp(val, "Enable") == 0) {
5098 dut->sta_ft_ds = 1;
5099 } else if (strcasecmp(val, "Disable") == 0) {
5100 dut->sta_ft_ds = 0;
5101 } else {
5102 send_resp(dut, conn, SIGMA_ERROR,
5103 "errorCode,Unsupported value for FT_DS");
5104 return STATUS_SENT_ERROR;
5105 }
5106 }
5107
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005108 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03005109 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
5110 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005111 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
5112 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005113
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005114 if (val && strcasecmp(val, "LOC") == 0)
5115 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02005116 if (val && strcasecmp(val, "60GHZ") == 0) {
5117 val = get_param(cmd, "WPS");
5118 if (val && strcasecmp(val, "disable") == 0) {
5119 dut->wps_disable = 1;
5120 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
5121 } else {
5122 /* wps_disable can have other value from the previous
5123 * test, so make sure it has the correct value.
5124 */
5125 dut->wps_disable = 0;
5126 }
5127
5128 val = get_param(cmd, "P2P");
5129 if (val && strcasecmp(val, "disable") == 0)
5130 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
5131 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005132
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02005133 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
5134 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
5135
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005136#ifdef ANDROID_NAN
5137 if (val && strcasecmp(val, "NAN") == 0)
5138 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
5139#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005140#ifdef MIRACAST
5141 if (val && (strcasecmp(val, "WFD") == 0 ||
5142 strcasecmp(val, "DisplayR2") == 0))
5143 return miracast_preset_testparameters(dut, conn, cmd);
5144#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005145
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07005146 if (val &&
5147 (strcasecmp(val, "MBO") == 0 || strcasecmp(val, "HE") == 0)) {
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305148 val = get_param(cmd, "Cellular_Data_Cap");
5149 if (val &&
5150 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
5151 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05305152
5153 val = get_param(cmd, "Ch_Pref");
5154 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
5155 return 0;
5156
Ashwini Patilc63161e2017-04-13 16:30:23 +05305157 val = get_param(cmd, "BSS_Transition");
5158 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
5159 return 0;
5160
Ashwini Patila75de5a2017-04-13 16:35:05 +05305161 val = get_param(cmd, "Assoc_Disallow");
5162 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
5163 return 0;
5164
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305165 val = get_param(cmd, "Roaming");
5166 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
5167 return 0;
5168
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305169 return 1;
5170 }
5171
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305172 if (val && strcasecmp(val, "OCE") == 0)
5173 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
5174
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005175#if 0
5176 val = get_param(cmd, "Supplicant");
5177 if (val && strcasecmp(val, "Default") != 0) {
5178 send_resp(dut, conn, SIGMA_ERROR,
5179 "ErrorCode,Only default(Vendor) supplicant "
5180 "supported");
5181 return 0;
5182 }
5183#endif
5184
5185 val = get_param(cmd, "RTS");
5186 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005187 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005188 case DRIVER_ATHEROS:
5189 ath_sta_set_rts(dut, intf, val);
5190 break;
5191 default:
5192#if 0
5193 send_resp(dut, conn, SIGMA_ERROR,
5194 "ErrorCode,Setting RTS not supported");
5195 return 0;
5196#else
5197 sigma_dut_print(dut, DUT_MSG_DEBUG,
5198 "Setting RTS not supported");
5199 break;
5200#endif
5201 }
5202 }
5203
5204#if 0
5205 val = get_param(cmd, "FRGMNT");
5206 if (val) {
5207 /* TODO */
5208 send_resp(dut, conn, SIGMA_ERROR,
5209 "ErrorCode,Setting FRGMNT not supported");
5210 return 0;
5211 }
5212#endif
5213
5214#if 0
5215 val = get_param(cmd, "Preamble");
5216 if (val) {
5217 /* TODO: Long/Short */
5218 send_resp(dut, conn, SIGMA_ERROR,
5219 "ErrorCode,Setting Preamble not supported");
5220 return 0;
5221 }
5222#endif
5223
5224 val = get_param(cmd, "Mode");
5225 if (val) {
5226 if (strcmp(val, "11b") == 0 ||
5227 strcmp(val, "11g") == 0 ||
5228 strcmp(val, "11a") == 0 ||
5229 strcmp(val, "11n") == 0 ||
5230 strcmp(val, "11ng") == 0 ||
5231 strcmp(val, "11nl") == 0 ||
5232 strcmp(val, "11nl(nabg)") == 0 ||
5233 strcmp(val, "AC") == 0 ||
5234 strcmp(val, "11AC") == 0 ||
5235 strcmp(val, "11ac") == 0 ||
5236 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08005237 strcmp(val, "11an") == 0 ||
5238 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005239 /* STA supports all modes by default */
5240 } else {
5241 send_resp(dut, conn, SIGMA_ERROR,
5242 "ErrorCode,Setting Mode not supported");
5243 return 0;
5244 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005245
5246 /* Change the mode only in case of testbed for HE program
5247 * and for 11a and 11g modes only. */
5248 if (dut->program == PROGRAM_HE &&
5249 dut->device_type == STA_testbed) {
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305250 sta_set_phymode(dut, intf, val);
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005251 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005252 }
5253
5254 val = get_param(cmd, "wmm");
5255 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005256 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005257 case DRIVER_ATHEROS:
5258 ath_sta_set_wmm(dut, intf, val);
5259 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005260 case DRIVER_WCN:
5261 wcn_sta_set_wmm(dut, intf, val);
5262 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005263 default:
5264 sigma_dut_print(dut, DUT_MSG_DEBUG,
5265 "Setting wmm not supported");
5266 break;
5267 }
5268 }
5269
5270 val = get_param(cmd, "Powersave");
5271 if (val) {
5272 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005273 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305274 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005275 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005276 }
5277
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005278 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005279 "P2P_SET ps 0") < 0)
5280 return -2;
5281 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005282 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5283 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005284 } else if (strcmp(val, "1") == 0 ||
5285 strcasecmp(val, "PSPoll") == 0 ||
5286 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005287 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305288 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005289 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005290 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005291 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005292 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005293 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005294 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005295 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005296 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005297 "P2P_SET ps 99") < 0)
5298 return -2;
5299 } else if (strcmp(val, "2") == 0 ||
5300 strcasecmp(val, "Fast") == 0) {
5301 /* TODO */
5302 send_resp(dut, conn, SIGMA_ERROR,
5303 "ErrorCode,Powersave=Fast not supported");
5304 return 0;
5305 } else if (strcmp(val, "3") == 0 ||
5306 strcasecmp(val, "PSNonPoll") == 0) {
5307 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005308 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5309 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005310
5311 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005312 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005313 "P2P_SET ps 1") < 0)
5314 return -2;
5315 } else
5316 return -1;
5317 }
5318
5319 val = get_param(cmd, "NoAck");
5320 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005321 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005322 case DRIVER_ATHEROS:
5323 ath_sta_set_noack(dut, intf, val);
5324 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005325#ifdef NL80211_SUPPORT
5326 case DRIVER_WCN:
5327 wcn_sta_set_noack(dut, intf, val);
5328 break;
5329#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005330 default:
5331 send_resp(dut, conn, SIGMA_ERROR,
5332 "ErrorCode,Setting NoAck not supported");
5333 return 0;
5334 }
5335 }
5336
5337 val = get_param(cmd, "IgnoreChswitchProhibit");
5338 if (val) {
5339 /* TODO: Enabled/disabled */
5340 if (strcasecmp(val, "Enabled") == 0) {
5341 send_resp(dut, conn, SIGMA_ERROR,
5342 "ErrorCode,Enabling IgnoreChswitchProhibit "
5343 "not supported");
5344 return 0;
5345 }
5346 }
5347
5348 val = get_param(cmd, "TDLS");
5349 if (val) {
5350 if (strcasecmp(val, "Disabled") == 0) {
5351 if (wpa_command(intf, "SET tdls_disabled 1")) {
5352 send_resp(dut, conn, SIGMA_ERROR,
5353 "ErrorCode,Failed to disable TDLS");
5354 return 0;
5355 }
5356 } else if (strcasecmp(val, "Enabled") == 0) {
5357 if (wpa_command(intf, "SET tdls_disabled 0")) {
5358 send_resp(dut, conn, SIGMA_ERROR,
5359 "ErrorCode,Failed to enable TDLS");
5360 return 0;
5361 }
5362 } else {
5363 send_resp(dut, conn, SIGMA_ERROR,
5364 "ErrorCode,Unsupported TDLS value");
5365 return 0;
5366 }
5367 }
5368
5369 val = get_param(cmd, "TDLSmode");
5370 if (val) {
5371 if (strcasecmp(val, "Default") == 0) {
5372 wpa_command(intf, "SET tdls_testing 0");
5373 } else if (strcasecmp(val, "APProhibit") == 0) {
5374 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5375 send_resp(dut, conn, SIGMA_ERROR,
5376 "ErrorCode,Failed to enable ignore "
5377 "APProhibit TDLS mode");
5378 return 0;
5379 }
5380 } else if (strcasecmp(val, "HiLoMac") == 0) {
5381 /* STA should respond with TDLS setup req for a TDLS
5382 * setup req */
5383 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5384 send_resp(dut, conn, SIGMA_ERROR,
5385 "ErrorCode,Failed to enable HiLoMac "
5386 "TDLS mode");
5387 return 0;
5388 }
5389 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5390 /*
5391 * Since all security modes are enabled by default when
5392 * Sigma control is used, there is no need to do
5393 * anything here.
5394 */
5395 } else if (strcasecmp(val, "ExistLink") == 0) {
5396 /*
5397 * Since we allow new TDLS Setup Request even if there
5398 * is an existing link, nothing needs to be done for
5399 * this.
5400 */
5401 } else {
5402 /* TODO:
5403 * ExistLink: STA should send TDLS setup req even if
5404 * direct link already exists
5405 */
5406 send_resp(dut, conn, SIGMA_ERROR,
5407 "ErrorCode,Unsupported TDLSmode value");
5408 return 0;
5409 }
5410 }
5411
5412 val = get_param(cmd, "FakePubKey");
5413 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5414 send_resp(dut, conn, SIGMA_ERROR,
5415 "ErrorCode,Failed to enable FakePubKey");
5416 return 0;
5417 }
5418
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005419#ifdef NL80211_SUPPORT
5420 val = get_param(cmd, "FrgmntSupport");
5421 if (val) {
5422 if (strcasecmp(val, "Enable") == 0) {
5423 if (sta_set_he_fragmentation(dut, intf,
5424 HE_FRAG_LEVEL1)) {
5425 send_resp(dut, conn, SIGMA_ERROR,
5426 "ErrorCode,Failed to enable HE Fragmentation");
5427 return 0;
5428 }
5429 } else if (strcasecmp(val, "Disable") == 0) {
5430 if (sta_set_he_fragmentation(dut, intf,
5431 HE_FRAG_DISABLE)) {
5432 send_resp(dut, conn, SIGMA_ERROR,
5433 "ErrorCode,Failed to disable HE Fragmentation");
5434 return 0;
5435 }
5436 }
5437 }
5438#endif /* NL80211_SUPPORT */
5439
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305440 val = get_param(cmd, "IncludeMSCSDescriptor");
5441 if (val && strcasecmp(val, "1") == 0) {
5442 char buf[128];
5443 int len;
5444
5445 len = snprintf(buf, sizeof(buf),
Veerendranath Jakkam62cde372020-08-19 18:03:06 +05305446 "MSCS add up_bitmap=F0 up_limit=7 stream_timeout=60000 frame_classifier=045F%032x",
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305447 0);
5448
5449 if (len < 0 || len >= sizeof(buf)) {
5450 sigma_dut_print(dut, DUT_MSG_ERROR,
5451 "Failed to build MSCS Descriptor IE");
5452 return ERROR_SEND_STATUS;
5453 }
5454
5455 if (wpa_command(intf, buf) != 0) {
5456 send_resp(dut, conn, SIGMA_ERROR,
5457 "ErrorCode,Failed to include MSCS descriptor");
5458 return STATUS_SENT_ERROR;
5459 }
5460 }
5461
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005462 return 1;
5463}
5464
5465
5466static const char * ath_get_radio_name(const char *radio_name)
5467{
5468 if (radio_name == NULL)
5469 return "wifi0";
5470 if (strcmp(radio_name, "wifi1") == 0)
5471 return "wifi1";
5472 if (strcmp(radio_name, "wifi2") == 0)
5473 return "wifi2";
5474 return "wifi0";
5475}
5476
5477
5478static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5479 const char *val)
5480{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005481 unsigned int vht_mcsmap = 0;
5482 int txchainmask = 0;
5483 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5484
5485 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5486 if (dut->testbed_flag_txsp == 1) {
5487 vht_mcsmap = 0xfffc;
5488 dut->testbed_flag_txsp = 0;
5489 } else {
5490 vht_mcsmap = 0xfffe;
5491 }
5492 txchainmask = 1;
5493 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5494 if (dut->testbed_flag_txsp == 1) {
5495 vht_mcsmap = 0xfff0;
5496 dut->testbed_flag_txsp = 0;
5497 } else {
5498 vht_mcsmap = 0xfffa;
5499 }
5500 txchainmask = 3;
5501 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5502 if (dut->testbed_flag_txsp == 1) {
5503 vht_mcsmap = 0xffc0;
5504 dut->testbed_flag_txsp = 0;
5505 } else {
5506 vht_mcsmap = 0xffea;
5507 }
5508 txchainmask = 7;
5509 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5510 if (dut->testbed_flag_txsp == 1) {
5511 vht_mcsmap = 0xff00;
5512 dut->testbed_flag_txsp = 0;
5513 } else {
5514 vht_mcsmap = 0xffaa;
5515 }
5516 txchainmask = 15;
5517 } else {
5518 if (dut->testbed_flag_txsp == 1) {
5519 vht_mcsmap = 0xffc0;
5520 dut->testbed_flag_txsp = 0;
5521 } else {
5522 vht_mcsmap = 0xffea;
5523 }
5524 }
5525
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005526 if (txchainmask)
5527 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005528
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005529 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005530}
5531
5532
5533static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5534 const char *val)
5535{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005536 unsigned int vht_mcsmap = 0;
5537 int rxchainmask = 0;
5538 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5539
5540 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5541 if (dut->testbed_flag_rxsp == 1) {
5542 vht_mcsmap = 0xfffc;
5543 dut->testbed_flag_rxsp = 0;
5544 } else {
5545 vht_mcsmap = 0xfffe;
5546 }
5547 rxchainmask = 1;
5548 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5549 if (dut->testbed_flag_rxsp == 1) {
5550 vht_mcsmap = 0xfff0;
5551 dut->testbed_flag_rxsp = 0;
5552 } else {
5553 vht_mcsmap = 0xfffa;
5554 }
5555 rxchainmask = 3;
5556 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5557 if (dut->testbed_flag_rxsp == 1) {
5558 vht_mcsmap = 0xffc0;
5559 dut->testbed_flag_rxsp = 0;
5560 } else {
5561 vht_mcsmap = 0xffea;
5562 }
5563 rxchainmask = 7;
5564 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5565 if (dut->testbed_flag_rxsp == 1) {
5566 vht_mcsmap = 0xff00;
5567 dut->testbed_flag_rxsp = 0;
5568 } else {
5569 vht_mcsmap = 0xffaa;
5570 }
5571 rxchainmask = 15;
5572 } else {
5573 if (dut->testbed_flag_rxsp == 1) {
5574 vht_mcsmap = 0xffc0;
5575 dut->testbed_flag_rxsp = 0;
5576 } else {
5577 vht_mcsmap = 0xffea;
5578 }
5579 }
5580
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005581 if (rxchainmask)
5582 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005583
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005584 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005585}
5586
5587
5588void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5589{
5590 if (strcasecmp(val, "enable") == 0) {
5591 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5592 != 0) {
5593 sigma_dut_print(dut, DUT_MSG_ERROR,
5594 "Disable BB_VHTSIGB_CRC_CALC failed");
5595 }
5596
5597 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5598 != 0) {
5599 sigma_dut_print(dut, DUT_MSG_ERROR,
5600 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5601 }
5602 } else {
5603 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5604 != 0) {
5605 sigma_dut_print(dut, DUT_MSG_ERROR,
5606 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5607 }
5608
5609 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5610 != 0) {
5611 sigma_dut_print(dut, DUT_MSG_ERROR,
5612 "Enable BB_VHTSIGB_CRC_CALC failed");
5613 }
5614 }
5615}
5616
5617
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005618static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5619 const char *val)
5620{
5621 char buf[60];
5622
5623 if (strcmp(val, "20") == 0) {
5624 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5625 dut->chwidth = 0;
5626 } else if (strcmp(val, "40") == 0) {
5627 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5628 dut->chwidth = 1;
5629 } else if (strcmp(val, "80") == 0) {
5630 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5631 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305632 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005633 buf[0] = '\0';
5634 } else {
5635 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5636 val);
5637 return -1;
5638 }
5639
5640 if (buf[0] != '\0' && system(buf) != 0) {
5641 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5642 return -1;
5643 }
5644
5645 return 0;
5646}
5647
5648
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005649static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5650 const char *intf, int addbareject)
5651{
5652#ifdef NL80211_SUPPORT
5653 struct nl_msg *msg;
5654 int ret = 0;
5655 struct nlattr *params;
5656 int ifindex;
5657
5658 ifindex = if_nametoindex(intf);
5659 if (ifindex == 0) {
5660 sigma_dut_print(dut, DUT_MSG_ERROR,
5661 "%s: Index for interface %s failed",
5662 __func__, intf);
5663 return -1;
5664 }
5665
5666 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5667 NL80211_CMD_VENDOR)) ||
5668 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5669 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5670 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5671 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5672 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5673 nla_put_u8(msg,
5674 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5675 !addbareject)) {
5676 sigma_dut_print(dut, DUT_MSG_ERROR,
5677 "%s: err in adding vendor_cmd and vendor_data",
5678 __func__);
5679 nlmsg_free(msg);
5680 return -1;
5681 }
5682 nla_nest_end(msg, params);
5683
5684 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5685 if (ret) {
5686 sigma_dut_print(dut, DUT_MSG_ERROR,
5687 "%s: err in send_and_recv_msgs, ret=%d",
5688 __func__, ret);
5689 }
5690 return ret;
5691#else /* NL80211_SUPPORT */
5692 sigma_dut_print(dut, DUT_MSG_ERROR,
5693 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5694 return -1;
5695#endif /* NL80211_SUPPORT */
5696}
5697
5698
5699static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5700 int addbareject)
5701{
5702 int ret;
5703
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005704 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005705 case DRIVER_WCN:
5706 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5707 if (ret) {
5708 sigma_dut_print(dut, DUT_MSG_ERROR,
5709 "nlvendor_sta_set_addba_reject failed, ret:%d",
5710 ret);
5711 return ret;
5712 }
5713 break;
5714 default:
5715 sigma_dut_print(dut, DUT_MSG_ERROR,
5716 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5717 ret = -1;
5718 break;
5719 }
5720
5721 return ret;
5722}
5723
5724
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005725static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5726 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005727{
5728#ifdef NL80211_SUPPORT
5729 struct nl_msg *msg;
5730 int ret = 0;
5731 struct nlattr *params;
5732 int ifindex;
5733
5734 ifindex = if_nametoindex(intf);
5735 if (ifindex == 0) {
5736 sigma_dut_print(dut, DUT_MSG_ERROR,
5737 "%s: Index for interface %s failed",
5738 __func__, intf);
5739 return -1;
5740 }
5741
5742 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5743 NL80211_CMD_VENDOR)) ||
5744 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5745 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5746 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5747 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5748 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5749 nla_put_u8(msg,
5750 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005751 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005752 sigma_dut_print(dut, DUT_MSG_ERROR,
5753 "%s: err in adding vendor_cmd and vendor_data",
5754 __func__);
5755 nlmsg_free(msg);
5756 return -1;
5757 }
5758 nla_nest_end(msg, params);
5759
5760 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5761 if (ret) {
5762 sigma_dut_print(dut, DUT_MSG_ERROR,
5763 "%s: err in send_and_recv_msgs, ret=%d",
5764 __func__, ret);
5765 }
5766 return ret;
5767#else /* NL80211_SUPPORT */
5768 sigma_dut_print(dut, DUT_MSG_ERROR,
5769 "Disable addba not possible without NL80211_SUPPORT defined");
5770 return -1;
5771#endif /* NL80211_SUPPORT */
5772}
5773
5774
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305775#ifdef NL80211_SUPPORT
5776static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5777{
5778 struct nl_msg *msg;
5779 int ret = 0;
5780 int ifindex;
5781
5782 ifindex = if_nametoindex(intf);
5783 if (ifindex == 0) {
5784 sigma_dut_print(dut, DUT_MSG_ERROR,
5785 "%s: Index for interface %s failed",
5786 __func__, intf);
5787 return -1;
5788 }
5789
5790 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5791 NL80211_CMD_SET_WIPHY)) ||
5792 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5793 sigma_dut_print(dut, DUT_MSG_ERROR,
5794 "%s: err in adding RTS threshold",
5795 __func__);
5796 nlmsg_free(msg);
5797 return -1;
5798 }
5799
5800 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5801 if (ret) {
5802 sigma_dut_print(dut, DUT_MSG_ERROR,
5803 "%s: err in send_and_recv_msgs, ret=%d",
5804 __func__, ret);
5805 }
5806 return ret;
5807}
5808#endif /* NL80211_SUPPORT */
5809
5810
5811static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5812{
5813 char buf[100];
5814
5815#ifdef NL80211_SUPPORT
5816 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5817 return 0;
5818 sigma_dut_print(dut, DUT_MSG_DEBUG,
5819 "Fall back to using iwconfig for setting RTS threshold");
5820#endif /* NL80211_SUPPORT */
5821
5822 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5823 if (system(buf) != 0) {
5824 sigma_dut_print(dut, DUT_MSG_ERROR,
5825 "Failed to set RTS threshold %d", val);
5826 return -1;
5827 }
5828 return 0;
5829}
5830
5831
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005832static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5833 struct sigma_conn *conn,
5834 struct sigma_cmd *cmd)
5835{
5836 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005837 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005838 char buf[128];
5839 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005840
5841 val = get_param(cmd, "40_INTOLERANT");
5842 if (val) {
5843 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5844 /* TODO: iwpriv ht40intol through wpa_supplicant */
5845 send_resp(dut, conn, SIGMA_ERROR,
5846 "ErrorCode,40_INTOLERANT not supported");
5847 return 0;
5848 }
5849 }
5850
5851 val = get_param(cmd, "ADDBA_REJECT");
5852 if (val) {
5853 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5854 /* reject any ADDBA with status "decline" */
5855 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005856 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005857 } else {
5858 /* accept ADDBA */
5859 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005860 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005861 }
5862 }
5863
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005864 if (addbareject >= 0 &&
5865 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5866 send_resp(dut, conn, SIGMA_ERROR,
5867 "ErrorCode,set addba_reject failed");
5868 return 0;
5869 }
5870
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005871 val = get_param(cmd, "AMPDU");
5872 if (val) {
5873 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5874 /* enable AMPDU Aggregation */
5875 if (ampdu == 0) {
5876 send_resp(dut, conn, SIGMA_ERROR,
5877 "ErrorCode,Mismatch in "
5878 "addba_reject/ampdu - "
5879 "not supported");
5880 return 0;
5881 }
5882 ampdu = 1;
5883 } else {
5884 /* disable AMPDU Aggregation */
5885 if (ampdu == 1) {
5886 send_resp(dut, conn, SIGMA_ERROR,
5887 "ErrorCode,Mismatch in "
5888 "addba_reject/ampdu - "
5889 "not supported");
5890 return 0;
5891 }
5892 ampdu = 0;
5893 }
5894 }
5895
5896 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005897 int ret;
5898
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005899 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5900 ampdu ? "Enabling" : "Disabling");
5901 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005902 if (wpa_command(intf, buf) < 0 &&
5903 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005904 send_resp(dut, conn, SIGMA_ERROR,
5905 "ErrorCode,set aggr failed");
5906 return 0;
5907 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005908
5909 if (ampdu == 0) {
5910 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005911 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005912 if (ret) {
5913 sigma_dut_print(dut, DUT_MSG_ERROR,
5914 "Failed to disable addba, ret:%d",
5915 ret);
5916 }
5917 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005918 }
5919
5920 val = get_param(cmd, "AMSDU");
5921 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005922 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005923 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005924 case DRIVER_WCN:
5925 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005926 break;
5927 default:
5928 if (strcmp(val, "1") == 0 ||
5929 strcasecmp(val, "Enable") == 0) {
5930 /* Enable AMSDU Aggregation */
5931 send_resp(dut, conn, SIGMA_ERROR,
5932 "ErrorCode,AMSDU aggregation not supported");
5933 return 0;
5934 }
5935 break;
5936 }
5937 }
5938
5939 val = get_param(cmd, "STBC_RX");
5940 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005941 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005942 case DRIVER_ATHEROS:
5943 ath_sta_set_stbc(dut, intf, val);
5944 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305945 case DRIVER_WCN:
5946 wcn_sta_set_stbc(dut, intf, val);
5947 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005948 default:
5949 send_resp(dut, conn, SIGMA_ERROR,
5950 "ErrorCode,STBC_RX not supported");
5951 return 0;
5952 }
5953 }
5954
5955 val = get_param(cmd, "WIDTH");
5956 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005957 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005958 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005959 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005960 send_resp(dut, conn, SIGMA_ERROR,
5961 "ErrorCode,Failed to set WIDTH");
5962 return 0;
5963 }
5964 break;
5965 case DRIVER_ATHEROS:
5966 if (ath_set_width(dut, conn, intf, val) < 0)
5967 return 0;
5968 break;
5969 default:
5970 sigma_dut_print(dut, DUT_MSG_ERROR,
5971 "Setting WIDTH not supported");
5972 break;
5973 }
5974 }
5975
5976 val = get_param(cmd, "SMPS");
5977 if (val) {
5978 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5979 send_resp(dut, conn, SIGMA_ERROR,
5980 "ErrorCode,SMPS not supported");
5981 return 0;
5982 }
5983
5984 val = get_param(cmd, "TXSP_STREAM");
5985 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005986 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005987 case DRIVER_WCN:
5988 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5989 send_resp(dut, conn, SIGMA_ERROR,
5990 "ErrorCode,Failed to set TXSP_STREAM");
5991 return 0;
5992 }
5993 break;
5994 case DRIVER_ATHEROS:
5995 ath_sta_set_txsp_stream(dut, intf, val);
5996 break;
5997 default:
5998 sigma_dut_print(dut, DUT_MSG_ERROR,
5999 "Setting TXSP_STREAM not supported");
6000 break;
6001 }
6002 }
6003
6004 val = get_param(cmd, "RXSP_STREAM");
6005 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006006 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006007 case DRIVER_WCN:
6008 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
6009 send_resp(dut, conn, SIGMA_ERROR,
6010 "ErrorCode,Failed to set RXSP_STREAM");
6011 return 0;
6012 }
6013 break;
6014 case DRIVER_ATHEROS:
6015 ath_sta_set_rxsp_stream(dut, intf, val);
6016 break;
6017 default:
6018 sigma_dut_print(dut, DUT_MSG_ERROR,
6019 "Setting RXSP_STREAM not supported");
6020 break;
6021 }
6022 }
6023
6024 val = get_param(cmd, "DYN_BW_SGNL");
6025 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006026 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006027 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08006028 if (strcasecmp(val, "enable") == 0) {
6029 snprintf(buf, sizeof(buf),
6030 "iwpriv %s cwmenable 1", intf);
6031 if (system(buf) != 0) {
6032 sigma_dut_print(dut, DUT_MSG_ERROR,
6033 "iwpriv cwmenable 1 failed");
6034 return 0;
6035 }
6036 } else if (strcasecmp(val, "disable") == 0) {
6037 snprintf(buf, sizeof(buf),
6038 "iwpriv %s cwmenable 0", intf);
6039 if (system(buf) != 0) {
6040 sigma_dut_print(dut, DUT_MSG_ERROR,
6041 "iwpriv cwmenable 0 failed");
6042 return 0;
6043 }
6044 } else {
6045 sigma_dut_print(dut, DUT_MSG_ERROR,
6046 "Unsupported DYN_BW_SGL");
6047 }
6048
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006049 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
6050 if (system(buf) != 0) {
6051 sigma_dut_print(dut, DUT_MSG_ERROR,
6052 "Failed to set cts_cbw in DYN_BW_SGNL");
6053 return 0;
6054 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006055 break;
6056 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006057 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006058 ath_config_dyn_bw_sig(dut, intf, val);
6059 break;
6060 default:
6061 sigma_dut_print(dut, DUT_MSG_ERROR,
6062 "Failed to set DYN_BW_SGNL");
6063 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006064 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006065 }
6066
6067 val = get_param(cmd, "RTS_FORCE");
6068 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006069 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006070 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306071 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006072 sigma_dut_print(dut, DUT_MSG_ERROR,
6073 "Failed to set RTS_FORCE 64");
6074 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03006075 res = snprintf(buf, sizeof(buf),
6076 "wifitool %s beeliner_fw_test 100 1",
6077 intf);
6078 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08006079 sigma_dut_print(dut, DUT_MSG_ERROR,
6080 "wifitool beeliner_fw_test 100 1 failed");
6081 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006082 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306083 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006084 sigma_dut_print(dut, DUT_MSG_ERROR,
6085 "Failed to set RTS_FORCE 2347");
6086 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006087 } else {
6088 send_resp(dut, conn, SIGMA_ERROR,
6089 "ErrorCode,RTS_FORCE value not supported");
6090 return 0;
6091 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006092 }
6093
6094 val = get_param(cmd, "CTS_WIDTH");
6095 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006096 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006097 case DRIVER_WCN:
6098 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
6099 send_resp(dut, conn, SIGMA_ERROR,
6100 "ErrorCode,Failed to set CTS_WIDTH");
6101 return 0;
6102 }
6103 break;
6104 case DRIVER_ATHEROS:
6105 ath_set_cts_width(dut, intf, val);
6106 break;
6107 default:
6108 sigma_dut_print(dut, DUT_MSG_ERROR,
6109 "Setting CTS_WIDTH not supported");
6110 break;
6111 }
6112 }
6113
6114 val = get_param(cmd, "BW_SGNL");
6115 if (val) {
6116 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006117 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006118 } else if (strcasecmp(val, "Disable") == 0) {
6119 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006120 } else {
6121 send_resp(dut, conn, SIGMA_ERROR,
6122 "ErrorCode,BW_SGNL value not supported");
6123 return 0;
6124 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006125 }
6126
6127 val = get_param(cmd, "Band");
6128 if (val) {
6129 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
6130 /* STA supports all bands by default */
6131 } else {
6132 send_resp(dut, conn, SIGMA_ERROR,
6133 "ErrorCode,Unsupported Band");
6134 return 0;
6135 }
6136 }
6137
6138 val = get_param(cmd, "zero_crc");
6139 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006140 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006141 case DRIVER_ATHEROS:
6142 ath_set_zero_crc(dut, val);
6143 break;
6144 default:
6145 break;
6146 }
6147 }
6148
6149 return 1;
6150}
6151
6152
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006153static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
6154{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006155 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006156#ifdef __linux__
6157 case DRIVER_WIL6210:
6158 return wil6210_set_force_mcs(dut, force, mcs);
6159#endif /* __linux__ */
6160 default:
6161 sigma_dut_print(dut, DUT_MSG_ERROR,
6162 "Unsupported sta_set_force_mcs with the current driver");
6163 return -1;
6164 }
6165}
6166
6167
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006168static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
6169{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006170 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006171#ifdef __linux__
6172 case DRIVER_WIL6210:
6173 return wil6210_force_rsn_ie(dut, state);
6174#endif /* __linux__ */
6175 default:
6176 sigma_dut_print(dut, DUT_MSG_ERROR,
6177 "Unsupported sta_60g_force_rsn_ie with the current driver");
6178 return -1;
6179 }
6180}
6181
6182
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006183static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
6184 struct sigma_cmd *cmd)
6185{
6186 const char *val;
6187 char buf[100];
6188
6189 val = get_param(cmd, "MSDUSize");
6190 if (val) {
6191 int mtu;
6192
6193 dut->amsdu_size = atoi(val);
6194 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
6195 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
6196 sigma_dut_print(dut, DUT_MSG_ERROR,
6197 "MSDUSize %d is above max %d or below min %d",
6198 dut->amsdu_size,
6199 IEEE80211_MAX_DATA_LEN_DMG,
6200 IEEE80211_SNAP_LEN_DMG);
6201 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006202 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006203 }
6204
6205 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
6206 sigma_dut_print(dut, DUT_MSG_DEBUG,
6207 "Setting amsdu_size to %d", mtu);
6208 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006209 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006210
6211 if (system(buf) != 0) {
6212 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
6213 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006214 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006215 }
6216 }
6217
6218 val = get_param(cmd, "BAckRcvBuf");
6219 if (val) {
6220 dut->back_rcv_buf = atoi(val);
6221 if (dut->back_rcv_buf == 0) {
6222 sigma_dut_print(dut, DUT_MSG_ERROR,
6223 "Failed to convert %s or value is 0",
6224 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006225 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006226 }
6227
6228 sigma_dut_print(dut, DUT_MSG_DEBUG,
6229 "Setting BAckRcvBuf to %s", val);
6230 }
6231
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006232 val = get_param(cmd, "MCS_FixedRate");
6233 if (val) {
6234 if (sta_set_force_mcs(dut, 1, atoi(val))) {
6235 sigma_dut_print(dut, DUT_MSG_ERROR,
6236 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006237 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006238 }
6239 }
6240
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006241 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006242}
6243
6244
6245static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
6246 struct sigma_cmd *cmd)
6247{
6248 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006249 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006250 const char *val;
6251 char buf[100];
6252
6253 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006254 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006255 if (wpa_command(ifname, "PING") != 0) {
6256 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006257 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006258 }
6259
6260 wpa_command(ifname, "FLUSH");
6261 net_id = add_network_common(dut, conn, ifname, cmd);
6262 if (net_id < 0) {
6263 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
6264 return net_id;
6265 }
6266
6267 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
6268 if (set_network(ifname, net_id, "mode", "2") < 0) {
6269 sigma_dut_print(dut, DUT_MSG_ERROR,
6270 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006271 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006272 }
6273
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006274 if (set_network(ifname, net_id, "pbss", "1") < 0)
6275 return -2;
6276
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006277 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006278 "Supplicant set network with mode 2. network_id %d",
6279 net_id);
6280
6281 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6282 sigma_dut_print(dut, DUT_MSG_INFO,
6283 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006284 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006285 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006286
6287 val = get_param(cmd, "Security");
6288 if (val && strcasecmp(val, "OPEN") == 0) {
6289 dut->ap_key_mgmt = AP_OPEN;
6290 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6291 sigma_dut_print(dut, DUT_MSG_ERROR,
6292 "Failed to set supplicant to %s security",
6293 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006294 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006295 }
6296 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6297 dut->ap_key_mgmt = AP_WPA2_PSK;
6298 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6299 sigma_dut_print(dut, DUT_MSG_ERROR,
6300 "Failed to set supplicant to %s security",
6301 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006302 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006303 }
6304
6305 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6306 sigma_dut_print(dut, DUT_MSG_ERROR,
6307 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006308 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006309 }
6310 } else if (val) {
6311 sigma_dut_print(dut, DUT_MSG_ERROR,
6312 "Requested Security %s is not supported on 60GHz",
6313 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006314 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006315 }
6316
6317 val = get_param(cmd, "Encrypt");
6318 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6319 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6320 sigma_dut_print(dut, DUT_MSG_ERROR,
6321 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006322 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006323 }
6324 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6325 sigma_dut_print(dut, DUT_MSG_ERROR,
6326 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006327 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006328 }
6329 } else if (val) {
6330 sigma_dut_print(dut, DUT_MSG_ERROR,
6331 "Requested Encrypt %s is not supported on 60 GHz",
6332 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006333 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006334 }
6335
6336 val = get_param(cmd, "PSK");
6337 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6338 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6339 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006340 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006341 }
6342
6343 /* Convert 60G channel to freq */
6344 switch (dut->ap_channel) {
6345 case 1:
6346 val = "58320";
6347 break;
6348 case 2:
6349 val = "60480";
6350 break;
6351 case 3:
6352 val = "62640";
6353 break;
6354 default:
6355 sigma_dut_print(dut, DUT_MSG_ERROR,
6356 "Failed to configure channel %d. Not supported",
6357 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006358 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006359 }
6360
6361 if (set_network(ifname, net_id, "frequency", val) < 0) {
6362 sigma_dut_print(dut, DUT_MSG_ERROR,
6363 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006364 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006365 }
6366
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006367 if (dut->eap_fragment) {
6368 sigma_dut_print(dut, DUT_MSG_DEBUG,
6369 "Set EAP fragment size to 128 bytes.");
6370 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6371 return ERROR_SEND_STATUS;
6372 }
6373
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006374 sigma_dut_print(dut, DUT_MSG_DEBUG,
6375 "Supplicant set network with frequency");
6376
6377 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6378 if (wpa_command(ifname, buf) < 0) {
6379 sigma_dut_print(dut, DUT_MSG_INFO,
6380 "Failed to select network id %d on %s",
6381 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006382 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006383 }
6384
6385 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6386
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006387 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006388}
6389
6390
Lior David67543f52017-01-03 19:04:22 +02006391static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6392{
6393 char buf[128], fname[128];
6394 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006395 int res;
Lior David67543f52017-01-03 19:04:22 +02006396
6397 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6398 sigma_dut_print(dut, DUT_MSG_ERROR,
6399 "failed to get wil6210 debugfs dir");
6400 return -1;
6401 }
6402
Jouni Malinen3aa72862019-05-29 23:14:51 +03006403 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6404 if (res < 0 || res >= sizeof(fname))
6405 return -1;
Lior David67543f52017-01-03 19:04:22 +02006406 f = fopen(fname, "w");
6407 if (!f) {
6408 sigma_dut_print(dut, DUT_MSG_ERROR,
6409 "failed to open: %s", fname);
6410 return -1;
6411 }
6412
6413 fprintf(f, "%d\n", abft_len);
6414 fclose(f);
6415
6416 return 0;
6417}
6418
6419
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006420int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6421 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006422{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006423 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006424 case DRIVER_WIL6210:
6425 return wil6210_set_abft_len(dut, abft_len);
6426 default:
6427 sigma_dut_print(dut, DUT_MSG_ERROR,
6428 "set abft_len not supported");
6429 return -1;
6430 }
6431}
6432
6433
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006434static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6435 struct sigma_cmd *cmd)
6436{
6437 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006438 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006439
6440 if (dut->dev_role != DEVROLE_PCP) {
6441 send_resp(dut, conn, SIGMA_INVALID,
6442 "ErrorCode,Invalid DevRole");
6443 return 0;
6444 }
6445
6446 val = get_param(cmd, "SSID");
6447 if (val) {
6448 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6449 send_resp(dut, conn, SIGMA_INVALID,
6450 "ErrorCode,Invalid SSID");
6451 return -1;
6452 }
6453
Peng Xub8fc5cc2017-05-10 17:27:28 -07006454 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006455 }
6456
6457 val = get_param(cmd, "CHANNEL");
6458 if (val) {
6459 const char *pos;
6460
6461 dut->ap_channel = atoi(val);
6462 pos = strchr(val, ';');
6463 if (pos) {
6464 pos++;
6465 dut->ap_channel_1 = atoi(pos);
6466 }
6467 }
6468
6469 switch (dut->ap_channel) {
6470 case 1:
6471 case 2:
6472 case 3:
6473 break;
6474 default:
6475 sigma_dut_print(dut, DUT_MSG_ERROR,
6476 "Channel %d is not supported", dut->ap_channel);
6477 send_resp(dut, conn, SIGMA_ERROR,
6478 "Requested channel is not supported");
6479 return -1;
6480 }
6481
6482 val = get_param(cmd, "BCNINT");
6483 if (val)
6484 dut->ap_bcnint = atoi(val);
6485
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006486 val = get_param(cmd, "AllocType");
6487 if (val) {
6488 send_resp(dut, conn, SIGMA_ERROR,
6489 "ErrorCode,AllocType is not supported yet");
6490 return -1;
6491 }
6492
6493 val = get_param(cmd, "PercentBI");
6494 if (val) {
6495 send_resp(dut, conn, SIGMA_ERROR,
6496 "ErrorCode,PercentBI is not supported yet");
6497 return -1;
6498 }
6499
6500 val = get_param(cmd, "CBAPOnly");
6501 if (val) {
6502 send_resp(dut, conn, SIGMA_ERROR,
6503 "ErrorCode,CBAPOnly is not supported yet");
6504 return -1;
6505 }
6506
6507 val = get_param(cmd, "AMPDU");
6508 if (val) {
6509 if (strcasecmp(val, "Enable") == 0)
6510 dut->ap_ampdu = 1;
6511 else if (strcasecmp(val, "Disable") == 0)
6512 dut->ap_ampdu = 2;
6513 else {
6514 send_resp(dut, conn, SIGMA_ERROR,
6515 "ErrorCode,AMPDU value is not Enable nor Disabled");
6516 return -1;
6517 }
6518 }
6519
6520 val = get_param(cmd, "AMSDU");
6521 if (val) {
6522 if (strcasecmp(val, "Enable") == 0)
6523 dut->ap_amsdu = 1;
6524 else if (strcasecmp(val, "Disable") == 0)
6525 dut->ap_amsdu = 2;
6526 }
6527
6528 val = get_param(cmd, "NumMSDU");
6529 if (val) {
6530 send_resp(dut, conn, SIGMA_ERROR,
6531 "ErrorCode, NumMSDU is not supported yet");
6532 return -1;
6533 }
6534
6535 val = get_param(cmd, "ABFTLRang");
6536 if (val) {
6537 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006538 "ABFTLRang parameter %s", val);
6539 if (strcmp(val, "Gt1") == 0)
6540 abft_len = 2; /* 2 slots in this case */
6541 }
6542
6543 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6544 send_resp(dut, conn, SIGMA_ERROR,
6545 "ErrorCode, Can't set ABFT length");
6546 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006547 }
6548
6549 if (sta_pcp_start(dut, conn, cmd) < 0) {
6550 send_resp(dut, conn, SIGMA_ERROR,
6551 "ErrorCode, Can't start PCP role");
6552 return -1;
6553 }
6554
6555 return sta_set_60g_common(dut, conn, cmd);
6556}
6557
6558
6559static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6560 struct sigma_cmd *cmd)
6561{
6562 const char *val = get_param(cmd, "DiscoveryMode");
6563
6564 if (dut->dev_role != DEVROLE_STA) {
6565 send_resp(dut, conn, SIGMA_INVALID,
6566 "ErrorCode,Invalid DevRole");
6567 return 0;
6568 }
6569
6570 if (val) {
6571 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6572 /* Ignore Discovery mode till Driver expose API. */
6573#if 0
6574 if (strcasecmp(val, "1") == 0) {
6575 send_resp(dut, conn, SIGMA_INVALID,
6576 "ErrorCode,DiscoveryMode 1 not supported");
6577 return 0;
6578 }
6579
6580 if (strcasecmp(val, "0") == 0) {
6581 /* OK */
6582 } else {
6583 send_resp(dut, conn, SIGMA_INVALID,
6584 "ErrorCode,DiscoveryMode not supported");
6585 return 0;
6586 }
6587#endif
6588 }
6589
6590 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006591 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006592 return sta_set_60g_common(dut, conn, cmd);
6593}
6594
6595
Jouni Malinenf7222712019-06-13 01:50:21 +03006596static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6597 struct sigma_conn *conn,
6598 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006599{
6600 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006601 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306602
Jouni Malinened77e672018-01-10 16:45:13 +02006603 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006604 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006605 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306606 wpa_command(intf, "DISCONNECT");
6607 return 1;
6608 }
6609
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006610 disconnect_station(dut);
6611 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6612 * due to cached results. */
6613 wpa_command(intf, "SET ignore_old_scan_res 1");
6614 wpa_command(intf, "BSS_FLUSH");
6615 return 1;
6616}
6617
6618
Jouni Malinenf7222712019-06-13 01:50:21 +03006619static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6620 struct sigma_conn *conn,
6621 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006622{
6623 const char *intf = get_param(cmd, "Interface");
6624 const char *bssid = get_param(cmd, "bssid");
6625 const char *val = get_param(cmd, "CHANNEL");
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006626 const char *freq_val = get_param(cmd, "ChnlFreq");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006627 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306628 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306629 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006630 int res;
6631 int chan = 0;
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006632 int freq = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006633 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306634 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006635 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006636
6637 if (bssid == NULL) {
6638 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6639 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006640 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006641 }
6642
6643 if (val)
6644 chan = atoi(val);
6645
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006646 if (freq_val)
6647 freq = atoi(freq_val);
6648
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006649 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6650 /* The current network may be from sta_associate or
6651 * sta_hs2_associate
6652 */
6653 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6654 0 ||
6655 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006656 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006657 }
6658
6659 ctrl = open_wpa_mon(intf);
6660 if (ctrl == NULL) {
6661 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6662 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006663 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006664 }
6665
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006666 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05306667 sizeof(result)) < 0 ||
6668 strncmp(result, "COMPLETED", 9) != 0) {
6669 sigma_dut_print(dut, DUT_MSG_DEBUG,
6670 "sta_reassoc: Not connected");
6671 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006672 } else if (dut->sta_ft_ds) {
6673 sigma_dut_print(dut, DUT_MSG_DEBUG,
6674 "sta_reassoc: Use FT-over-DS");
6675 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306676 }
6677
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306678 if (dut->rsne_override) {
6679#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006680 if (get_driver_type(dut) == DRIVER_WCN &&
6681 dut->config_rsnie == 0) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05306682 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306683 dut->config_rsnie = 1;
6684 }
6685#endif /* NL80211_SUPPORT */
6686 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6687 dut->rsne_override);
6688 if (wpa_command(intf, buf) < 0) {
6689 send_resp(dut, conn, SIGMA_ERROR,
6690 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6691 return 0;
6692 }
6693 }
6694
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006695 if (ft_ds) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006696 if (chan || freq) {
6697 if (!freq)
6698 freq = channel_to_freq(dut, chan);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006699 if (!freq) {
6700 sigma_dut_print(dut, DUT_MSG_ERROR,
6701 "Invalid channel number provided: %d",
6702 chan);
6703 send_resp(dut, conn, SIGMA_INVALID,
6704 "ErrorCode,Invalid channel number");
6705 goto close_mon_conn;
6706 }
6707 res = snprintf(buf, sizeof(buf),
6708 "SCAN TYPE=ONLY freq=%d", freq);
6709 } else {
6710 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6711 }
6712 if (res < 0 || res >= (int) sizeof(buf)) {
6713 send_resp(dut, conn, SIGMA_ERROR,
6714 "ErrorCode,snprintf failed");
6715 goto close_mon_conn;
6716 }
6717 if (wpa_command(intf, buf) < 0) {
6718 sigma_dut_print(dut, DUT_MSG_INFO,
6719 "Failed to start scan");
6720 send_resp(dut, conn, SIGMA_ERROR,
6721 "ErrorCode,scan failed");
6722 goto close_mon_conn;
6723 }
6724
6725 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6726 buf, sizeof(buf));
6727 if (res < 0) {
6728 sigma_dut_print(dut, DUT_MSG_INFO,
6729 "Scan did not complete");
6730 send_resp(dut, conn, SIGMA_ERROR,
6731 "ErrorCode,scan did not complete");
6732 goto close_mon_conn;
6733 }
6734
6735 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6736 if (res > 0 && res < (int) sizeof(buf))
6737 res = wpa_command(intf, buf);
6738
6739 if (res < 0 || res >= (int) sizeof(buf)) {
6740 send_resp(dut, conn, SIGMA_ERROR,
6741 "errorCode,FT_DS command failed");
6742 status = STATUS_SENT_ERROR;
6743 goto close_mon_conn;
6744 }
6745 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006746 if (chan || freq) {
6747 if (!freq)
6748 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306749 if (!freq) {
6750 sigma_dut_print(dut, DUT_MSG_ERROR,
6751 "Invalid channel number provided: %d",
6752 chan);
6753 send_resp(dut, conn, SIGMA_INVALID,
6754 "ErrorCode,Invalid channel number");
6755 goto close_mon_conn;
6756 }
6757 res = snprintf(buf, sizeof(buf),
6758 "SCAN TYPE=ONLY freq=%d", freq);
6759 } else {
6760 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6761 }
6762 if (res < 0 || res >= (int) sizeof(buf)) {
6763 send_resp(dut, conn, SIGMA_ERROR,
6764 "ErrorCode,snprintf failed");
6765 goto close_mon_conn;
6766 }
6767 if (wpa_command(intf, buf) < 0) {
6768 sigma_dut_print(dut, DUT_MSG_INFO,
6769 "Failed to start scan");
6770 send_resp(dut, conn, SIGMA_ERROR,
6771 "ErrorCode,scan failed");
6772 goto close_mon_conn;
6773 }
6774
6775 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6776 buf, sizeof(buf));
6777 if (res < 0) {
6778 sigma_dut_print(dut, DUT_MSG_INFO,
6779 "Scan did not complete");
6780 send_resp(dut, conn, SIGMA_ERROR,
6781 "ErrorCode,scan did not complete");
6782 goto close_mon_conn;
6783 }
6784
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006785 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6786 < 0) {
6787 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6788 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006789 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306790 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006791 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306792 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006793 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306794 if (res < 0 || res >= (int) sizeof(buf) ||
6795 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006796 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306797 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306798 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006799 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006800 sigma_dut_print(dut, DUT_MSG_INFO,
6801 "sta_reassoc: Run %s successful", buf);
6802 } else if (wpa_command(intf, "REASSOCIATE")) {
6803 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6804 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306805 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006806 }
6807
6808 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6809 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306810 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006811 send_resp(dut, conn, SIGMA_ERROR,
6812 "errorCode,Connection did not complete");
6813 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306814 goto close_mon_conn;
6815 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006816 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006817
Ashwini Patil467efef2017-05-25 12:18:27 +05306818close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006819 wpa_ctrl_detach(ctrl);
6820 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306821 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006822}
6823
6824
6825static void hs2_clear_credentials(const char *intf)
6826{
6827 wpa_command(intf, "REMOVE_CRED all");
6828}
6829
6830
Lior Davidcc88b562017-01-03 18:52:09 +02006831#ifdef __linux__
6832static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6833 unsigned int *aid)
6834{
Lior David0fe101e2017-03-09 16:09:50 +02006835 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006836
Lior David0fe101e2017-03-09 16:09:50 +02006837 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006838}
6839#endif /* __linux__ */
6840
6841
6842static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6843 unsigned int *aid)
6844{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006845 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02006846#ifdef __linux__
6847 case DRIVER_WIL6210:
6848 return wil6210_get_aid(dut, bssid, aid);
6849#endif /* __linux__ */
6850 default:
6851 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6852 return -1;
6853 }
6854}
6855
6856
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006857static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6858 struct sigma_cmd *cmd)
6859{
6860 char buf[MAX_CMD_LEN];
6861 char bss_list[MAX_CMD_LEN];
6862 const char *parameter = get_param(cmd, "Parameter");
6863
6864 if (parameter == NULL)
6865 return -1;
6866
Lior Davidcc88b562017-01-03 18:52:09 +02006867 if (strcasecmp(parameter, "AID") == 0) {
6868 unsigned int aid = 0;
6869 char bssid[20];
6870
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006871 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02006872 bssid, sizeof(bssid)) < 0) {
6873 sigma_dut_print(dut, DUT_MSG_ERROR,
6874 "could not get bssid");
6875 return -2;
6876 }
6877
6878 if (sta_get_aid_60g(dut, bssid, &aid))
6879 return -2;
6880
6881 snprintf(buf, sizeof(buf), "aid,%d", aid);
6882 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6883 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6884 return 0;
6885 }
6886
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006887 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6888 char *bss_line;
6889 char *bss_id = NULL;
6890 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306891 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006892
6893 if (ifname == NULL) {
6894 sigma_dut_print(dut, DUT_MSG_INFO,
6895 "For get DiscoveredDevList need Interface name.");
6896 return -1;
6897 }
6898
6899 /*
6900 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6901 * of BSSIDs in "bssid=<BSSID>\n"
6902 */
6903 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6904 bss_list,
6905 sizeof(bss_list)) < 0) {
6906 sigma_dut_print(dut, DUT_MSG_ERROR,
6907 "Failed to get bss list");
6908 return -1;
6909 }
6910
6911 sigma_dut_print(dut, DUT_MSG_DEBUG,
6912 "bss list for ifname:%s is:%s",
6913 ifname, bss_list);
6914
6915 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306916 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006917 while (bss_line) {
6918 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6919 bss_id) {
6920 int len;
6921
6922 len = snprintf(buf + strlen(buf),
6923 sizeof(buf) - strlen(buf),
6924 ",%s", bss_id);
6925 free(bss_id);
6926 bss_id = NULL;
6927 if (len < 0) {
6928 sigma_dut_print(dut,
6929 DUT_MSG_ERROR,
6930 "Failed to read BSSID");
6931 send_resp(dut, conn, SIGMA_ERROR,
6932 "ErrorCode,Failed to read BSS ID");
6933 return 0;
6934 }
6935
6936 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6937 sigma_dut_print(dut,
6938 DUT_MSG_ERROR,
6939 "Response buf too small for list");
6940 send_resp(dut, conn,
6941 SIGMA_ERROR,
6942 "ErrorCode,Response buf too small for list");
6943 return 0;
6944 }
6945 }
6946
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306947 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006948 }
6949
6950 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6951 buf);
6952 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6953 return 0;
6954 }
6955
6956 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6957 return 0;
6958}
6959
6960
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006961static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6962 struct sigma_cmd *cmd)
6963{
6964 char buf[MAX_CMD_LEN];
6965 const char *parameter = get_param(cmd, "Parameter");
6966
6967 if (!parameter)
6968 return -1;
6969
6970 if (strcasecmp(parameter, "RSSI") == 0) {
6971 char rssi[10];
6972
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006973 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006974 rssi, sizeof(rssi)) < 0) {
6975 sigma_dut_print(dut, DUT_MSG_ERROR,
6976 "Could not get RSSI");
6977 return -2;
6978 }
6979
6980 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6981 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6982 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6983 return 0;
6984 }
6985
6986 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6987 return 0;
6988}
6989
6990
Jouni Malinenca0abd32020-02-09 20:18:10 +02006991static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
6992 struct sigma_conn *conn,
6993 struct sigma_cmd *cmd)
6994{
6995 const char *intf = get_param(cmd, "Interface");
6996 char buf[4096], bssid[20], resp[200], *pos, *tmp;
6997
6998 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
6999 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
7000 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
7001 send_resp(dut, conn, SIGMA_ERROR,
7002 "ErrorCode,PMKSA_GET not supported");
7003 return STATUS_SENT_ERROR;
7004 }
7005
7006 if (strncmp(buf, "FAIL", 4) == 0 ||
7007 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
7008 send_resp(dut, conn, SIGMA_ERROR,
7009 "ErrorCode,Could not find current network");
7010 return STATUS_SENT_ERROR;
7011 }
7012
7013 pos = buf;
7014 while (pos) {
7015 if (strncmp(pos, bssid, 17) == 0) {
7016 pos = strchr(pos, ' ');
7017 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307018 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007019 pos++;
7020 pos = strchr(pos, ' ');
7021 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307022 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007023 pos++;
7024 tmp = strchr(pos, ' ');
7025 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307026 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007027 *tmp = '\0';
7028 break;
7029 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02007030 pos = strchr(pos, '\n');
7031 if (pos)
7032 pos++;
7033 }
7034
7035 if (!pos) {
7036 send_resp(dut, conn, SIGMA_ERROR,
7037 "ErrorCode,PMK not available");
7038 return STATUS_SENT_ERROR;
7039 }
7040
7041 snprintf(resp, sizeof(resp), "PMK,%s", pos);
7042 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7043 return STATUS_SENT;
7044}
7045
7046
Jouni Malinenf7222712019-06-13 01:50:21 +03007047static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
7048 struct sigma_conn *conn,
7049 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007050{
7051 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02007052 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007053
Jouni Malinenca0abd32020-02-09 20:18:10 +02007054 if (!parameter)
7055 return INVALID_SEND_STATUS;
7056
7057 if (strcasecmp(parameter, "PMK") == 0)
7058 return sta_get_pmk(dut, conn, cmd);
7059
7060 if (!program)
7061 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007062
7063 if (strcasecmp(program, "P2PNFC") == 0)
7064 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
7065
7066 if (strcasecmp(program, "60ghz") == 0)
7067 return sta_get_parameter_60g(dut, conn, cmd);
7068
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007069 if (strcasecmp(program, "he") == 0)
7070 return sta_get_parameter_he(dut, conn, cmd);
7071
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007072#ifdef ANDROID_NAN
7073 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07007074 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007075#endif /* ANDROID_NAN */
7076
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007077#ifdef MIRACAST
7078 if (strcasecmp(program, "WFD") == 0 ||
7079 strcasecmp(program, "DisplayR2") == 0)
7080 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
7081#endif /* MIRACAST */
7082
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007083 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7084 return 0;
7085}
7086
7087
7088static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
7089 const char *type)
7090{
7091 char buf[100];
7092
7093 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007094 run_iwpriv(dut, intf, "chwidth 2");
7095 run_iwpriv(dut, intf, "mode 11ACVHT80");
7096 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007097 }
7098
7099 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007100 run_iwpriv(dut, intf, "chwidth 0");
7101 run_iwpriv(dut, intf, "mode 11naht40");
7102 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007103 }
7104
7105 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007106 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007107
7108 /* Reset CTS width */
7109 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
7110 intf);
7111 if (system(buf) != 0) {
7112 sigma_dut_print(dut, DUT_MSG_ERROR,
7113 "wifitool %s beeliner_fw_test 54 0 failed",
7114 intf);
7115 }
7116
7117 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007118 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007119
7120 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
7121 if (system(buf) != 0) {
7122 sigma_dut_print(dut, DUT_MSG_ERROR,
7123 "iwpriv rts failed");
7124 }
7125 }
7126
7127 if (type && strcasecmp(type, "Testbed") == 0) {
7128 dut->testbed_flag_txsp = 1;
7129 dut->testbed_flag_rxsp = 1;
7130 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007131 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007132
7133 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007134 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007135
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007136 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007137
7138 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007139 run_iwpriv(dut, intf, "tx_stbc 0");
7140 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007141
7142 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007143 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007144 }
7145
7146 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007147 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07007148 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007149
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007150 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007151 }
7152}
7153
7154
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007155#ifdef NL80211_SUPPORT
7156static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
7157 enum he_mcs_config mcs)
7158{
7159 struct nl_msg *msg;
7160 int ret = 0;
7161 struct nlattr *params;
7162 int ifindex;
7163
7164 ifindex = if_nametoindex(intf);
7165 if (ifindex == 0) {
7166 sigma_dut_print(dut, DUT_MSG_ERROR,
7167 "%s: Index for interface %s failed",
7168 __func__, intf);
7169 return -1;
7170 }
7171
7172 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7173 NL80211_CMD_VENDOR)) ||
7174 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7175 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7176 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7177 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7178 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7179 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
7180 mcs)) {
7181 sigma_dut_print(dut, DUT_MSG_ERROR,
7182 "%s: err in adding vendor_cmd and vendor_data",
7183 __func__);
7184 nlmsg_free(msg);
7185 return -1;
7186 }
7187 nla_nest_end(msg, params);
7188
7189 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7190 if (ret) {
7191 sigma_dut_print(dut, DUT_MSG_ERROR,
7192 "%s: err in send_and_recv_msgs, ret=%d",
7193 __func__, ret);
7194 }
7195 return ret;
7196}
7197#endif /* NL80211_SUPPORT */
7198
7199
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007200static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
7201 const char *intf, int enable)
7202{
7203#ifdef NL80211_SUPPORT
7204 struct nl_msg *msg;
7205 int ret = 0;
7206 struct nlattr *params;
7207 int ifindex;
7208
7209 ifindex = if_nametoindex(intf);
7210 if (ifindex == 0) {
7211 sigma_dut_print(dut, DUT_MSG_ERROR,
7212 "%s: Index for interface %s failed",
7213 __func__, intf);
7214 return -1;
7215 }
7216
7217 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7218 NL80211_CMD_VENDOR)) ||
7219 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7220 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7221 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7222 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7223 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7224 nla_put_u8(msg,
7225 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
7226 enable)) {
7227 sigma_dut_print(dut, DUT_MSG_ERROR,
7228 "%s: err in adding vendor_cmd and vendor_data",
7229 __func__);
7230 nlmsg_free(msg);
7231 return -1;
7232 }
7233 nla_nest_end(msg, params);
7234
7235 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7236 if (ret) {
7237 sigma_dut_print(dut, DUT_MSG_ERROR,
7238 "%s: err in send_and_recv_msgs, ret=%d",
7239 __func__, ret);
7240 }
7241 return ret;
7242#else /* NL80211_SUPPORT */
7243 sigma_dut_print(dut, DUT_MSG_ERROR,
7244 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
7245 return -1;
7246#endif /* NL80211_SUPPORT */
7247}
7248
7249
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007250static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
7251 const char *intf, int enable)
7252{
7253#ifdef NL80211_SUPPORT
7254 struct nl_msg *msg;
7255 int ret = 0;
7256 struct nlattr *params;
7257 int ifindex;
7258
7259 ifindex = if_nametoindex(intf);
7260 if (ifindex == 0) {
7261 sigma_dut_print(dut, DUT_MSG_ERROR,
7262 "%s: Index for interface %s failed",
7263 __func__, intf);
7264 return -1;
7265 }
7266
7267 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7268 NL80211_CMD_VENDOR)) ||
7269 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7270 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7271 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7272 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7273 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7274 nla_put_u8(msg,
7275 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7276 enable)) {
7277 sigma_dut_print(dut, DUT_MSG_ERROR,
7278 "%s: err in adding vendor_cmd and vendor_data",
7279 __func__);
7280 nlmsg_free(msg);
7281 return -1;
7282 }
7283 nla_nest_end(msg, params);
7284
7285 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7286 if (ret) {
7287 sigma_dut_print(dut, DUT_MSG_ERROR,
7288 "%s: err in send_and_recv_msgs, ret=%d",
7289 __func__, ret);
7290 }
7291 return ret;
7292#else /* NL80211_SUPPORT */
7293 sigma_dut_print(dut, DUT_MSG_ERROR,
7294 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7295 return -1;
7296#endif /* NL80211_SUPPORT */
7297}
7298
7299
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007300#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007301
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007302static int sta_set_he_testbed_def(struct sigma_dut *dut,
7303 const char *intf, int cfg)
7304{
7305 struct nl_msg *msg;
7306 int ret = 0;
7307 struct nlattr *params;
7308 int ifindex;
7309
7310 ifindex = if_nametoindex(intf);
7311 if (ifindex == 0) {
7312 sigma_dut_print(dut, DUT_MSG_ERROR,
7313 "%s: Index for interface %s failed",
7314 __func__, intf);
7315 return -1;
7316 }
7317
7318 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7319 NL80211_CMD_VENDOR)) ||
7320 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7321 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7322 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7323 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7324 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7325 nla_put_u8(msg,
7326 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7327 cfg)) {
7328 sigma_dut_print(dut, DUT_MSG_ERROR,
7329 "%s: err in adding vendor_cmd and vendor_data",
7330 __func__);
7331 nlmsg_free(msg);
7332 return -1;
7333 }
7334 nla_nest_end(msg, params);
7335
7336 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7337 if (ret) {
7338 sigma_dut_print(dut, DUT_MSG_ERROR,
7339 "%s: err in send_and_recv_msgs, ret=%d",
7340 __func__, ret);
7341 }
7342 return ret;
7343}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007344
7345
7346static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7347{
7348 struct nl_msg *msg;
7349 int ret = 0;
7350 struct nlattr *params;
7351 int ifindex;
7352
7353 ifindex = if_nametoindex(intf);
7354 if (ifindex == 0) {
7355 sigma_dut_print(dut, DUT_MSG_ERROR,
7356 "%s: Index for interface %s failed",
7357 __func__, intf);
7358 return -1;
7359 }
7360
7361 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7362 NL80211_CMD_VENDOR)) ||
7363 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7364 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7365 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7366 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7367 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7368 nla_put_u8(msg,
7369 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7370 cfg)) {
7371 sigma_dut_print(dut, DUT_MSG_ERROR,
7372 "%s: err in adding vendor_cmd and vendor_data",
7373 __func__);
7374 nlmsg_free(msg);
7375 return -1;
7376 }
7377 nla_nest_end(msg, params);
7378
7379 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7380 if (ret) {
7381 sigma_dut_print(dut, DUT_MSG_ERROR,
7382 "%s: err in send_and_recv_msgs, ret=%d",
7383 __func__, ret);
7384 }
7385 return ret;
7386}
7387
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007388#endif /* NL80211_SUPPORT */
7389
7390
Qiwei Caib6806972020-01-15 13:52:11 +08007391int sta_set_addba_buf_size(struct sigma_dut *dut,
7392 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007393{
7394#ifdef NL80211_SUPPORT
7395 struct nl_msg *msg;
7396 int ret = 0;
7397 struct nlattr *params;
7398 int ifindex;
7399
7400 ifindex = if_nametoindex(intf);
7401 if (ifindex == 0) {
7402 sigma_dut_print(dut, DUT_MSG_ERROR,
7403 "%s: Index for interface %s failed",
7404 __func__, intf);
7405 return -1;
7406 }
7407
7408 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7409 NL80211_CMD_VENDOR)) ||
7410 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7411 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7412 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7413 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7414 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07007415 nla_put_u16(msg,
7416 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
7417 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007418 sigma_dut_print(dut, DUT_MSG_ERROR,
7419 "%s: err in adding vendor_cmd and vendor_data",
7420 __func__);
7421 nlmsg_free(msg);
7422 return -1;
7423 }
7424 nla_nest_end(msg, params);
7425
7426 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7427 if (ret) {
7428 sigma_dut_print(dut, DUT_MSG_ERROR,
7429 "%s: err in send_and_recv_msgs, ret=%d",
7430 __func__, ret);
7431 }
7432 return ret;
7433#else /* NL80211_SUPPORT */
7434 sigma_dut_print(dut, DUT_MSG_ERROR,
7435 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7436 return -1;
7437#endif /* NL80211_SUPPORT */
7438}
7439
7440
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007441static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
7442 int enable)
7443{
7444#ifdef NL80211_SUPPORT
7445 struct nl_msg *msg;
7446 int ret = 0;
7447 struct nlattr *params;
7448 int ifindex;
7449
7450 ifindex = if_nametoindex(intf);
7451 if (ifindex == 0) {
7452 sigma_dut_print(dut, DUT_MSG_ERROR,
7453 "%s: Index for interface %s failed",
7454 __func__, intf);
7455 return -1;
7456 }
7457
7458 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7459 NL80211_CMD_VENDOR)) ||
7460 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7461 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7462 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7463 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7464 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7465 nla_put_u8(msg,
7466 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7467 enable)) {
7468 sigma_dut_print(dut, DUT_MSG_ERROR,
7469 "%s: err in adding vendor_cmd and vendor_data",
7470 __func__);
7471 nlmsg_free(msg);
7472 return -1;
7473 }
7474 nla_nest_end(msg, params);
7475
7476 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7477 if (ret) {
7478 sigma_dut_print(dut, DUT_MSG_ERROR,
7479 "%s: err in send_and_recv_msgs, ret=%d",
7480 __func__, ret);
7481 }
7482 return ret;
7483#else /* NL80211_SUPPORT */
7484 sigma_dut_print(dut, DUT_MSG_ERROR,
7485 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7486 return -1;
7487#endif /* NL80211_SUPPORT */
7488}
7489
7490
Arif Hussain9765f7d2018-07-03 08:28:26 -07007491static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7492 int val)
7493{
7494#ifdef NL80211_SUPPORT
7495 struct nl_msg *msg;
7496 int ret = 0;
7497 struct nlattr *params;
7498 int ifindex;
7499
7500 ifindex = if_nametoindex(intf);
7501 if (ifindex == 0) {
7502 sigma_dut_print(dut, DUT_MSG_ERROR,
7503 "%s: Index for interface %s failed, val:%d",
7504 __func__, intf, val);
7505 return -1;
7506 }
7507
7508 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7509 NL80211_CMD_VENDOR)) ||
7510 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7511 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7512 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7513 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7514 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7515 nla_put_u8(msg,
7516 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7517 val)) {
7518 sigma_dut_print(dut, DUT_MSG_ERROR,
7519 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7520 __func__, val);
7521 nlmsg_free(msg);
7522 return -1;
7523 }
7524 nla_nest_end(msg, params);
7525
7526 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7527 if (ret) {
7528 sigma_dut_print(dut, DUT_MSG_ERROR,
7529 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7530 __func__, ret, val);
7531 }
7532 return ret;
7533#else /* NL80211_SUPPORT */
7534 sigma_dut_print(dut, DUT_MSG_ERROR,
7535 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7536 return -1;
7537#endif /* NL80211_SUPPORT */
7538}
7539
7540
Arif Hussain68d23f52018-07-11 13:39:08 -07007541#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007542static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7543 enum qca_wlan_he_mac_padding_dur val)
7544{
Arif Hussain68d23f52018-07-11 13:39:08 -07007545 struct nl_msg *msg;
7546 int ret = 0;
7547 struct nlattr *params;
7548 int ifindex;
7549
7550 ifindex = if_nametoindex(intf);
7551 if (ifindex == 0) {
7552 sigma_dut_print(dut, DUT_MSG_ERROR,
7553 "%s: Index for interface %s failed, val:%d",
7554 __func__, intf, val);
7555 return -1;
7556 }
7557
7558 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7559 NL80211_CMD_VENDOR)) ||
7560 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7561 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7562 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7563 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7564 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7565 nla_put_u8(msg,
7566 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
7567 val)) {
7568 sigma_dut_print(dut, DUT_MSG_ERROR,
7569 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7570 __func__, val);
7571 nlmsg_free(msg);
7572 return -1;
7573 }
7574 nla_nest_end(msg, params);
7575
7576 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7577 if (ret) {
7578 sigma_dut_print(dut, DUT_MSG_ERROR,
7579 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7580 __func__, ret, val);
7581 }
7582 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07007583}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007584#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007585
7586
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007587static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7588 int val)
7589{
7590#ifdef NL80211_SUPPORT
7591 struct nl_msg *msg;
7592 int ret = 0;
7593 struct nlattr *params;
7594 int ifindex;
7595
7596 ifindex = if_nametoindex(intf);
7597 if (ifindex == 0) {
7598 sigma_dut_print(dut, DUT_MSG_ERROR,
7599 "%s: Index for interface %s failed, val:%d",
7600 __func__, intf, val);
7601 return -1;
7602 }
7603
7604 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7605 NL80211_CMD_VENDOR)) ||
7606 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7607 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7608 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7609 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7610 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7611 nla_put_u8(msg,
7612 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7613 val)) {
7614 sigma_dut_print(dut, DUT_MSG_ERROR,
7615 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7616 __func__, val);
7617 nlmsg_free(msg);
7618 return -1;
7619 }
7620 nla_nest_end(msg, params);
7621
7622 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7623 if (ret) {
7624 sigma_dut_print(dut, DUT_MSG_ERROR,
7625 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7626 __func__, ret, val);
7627 }
7628 return ret;
7629#else /* NL80211_SUPPORT */
7630 sigma_dut_print(dut, DUT_MSG_ERROR,
7631 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7632 return -1;
7633#endif /* NL80211_SUPPORT */
7634}
7635
7636
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007637#ifdef NL80211_SUPPORT
7638static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7639{
7640 struct nl_msg *msg;
7641 int ret = 0;
7642 struct nlattr *params;
7643 int ifindex;
7644
7645 ifindex = if_nametoindex(intf);
7646 if (ifindex == 0) {
7647 sigma_dut_print(dut, DUT_MSG_ERROR,
7648 "%s: Index for interface %s failed",
7649 __func__, intf);
7650 return -1;
7651 }
7652
7653 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7654 NL80211_CMD_VENDOR)) ||
7655 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7656 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7657 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7658 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7659 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7660 nla_put_flag(msg,
7661 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
7662 sigma_dut_print(dut, DUT_MSG_ERROR,
7663 "%s: err in adding vendor_cmd and vendor_data",
7664 __func__);
7665 nlmsg_free(msg);
7666 return -1;
7667 }
7668 nla_nest_end(msg, params);
7669
7670 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7671 if (ret) {
7672 sigma_dut_print(dut, DUT_MSG_ERROR,
7673 "%s: err in send_and_recv_msgs, ret=%d",
7674 __func__, ret);
7675 }
7676 return ret;
7677}
7678#endif /* NL80211_SUPPORT */
7679
7680
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007681static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7682 int val)
7683{
7684#ifdef NL80211_SUPPORT
7685 struct nl_msg *msg;
7686 int ret = 0;
7687 struct nlattr *params;
7688 int ifindex;
7689
7690 ifindex = if_nametoindex(intf);
7691 if (ifindex == 0) {
7692 sigma_dut_print(dut, DUT_MSG_ERROR,
7693 "%s: Index for interface %s failed, val:%d",
7694 __func__, intf, val);
7695 return -1;
7696 }
7697
7698 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7699 NL80211_CMD_VENDOR)) ||
7700 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7701 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7702 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7703 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7704 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7705 nla_put_u8(msg,
7706 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
7707 val)) {
7708 sigma_dut_print(dut, DUT_MSG_ERROR,
7709 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7710 __func__, val);
7711 nlmsg_free(msg);
7712 return -1;
7713 }
7714 nla_nest_end(msg, params);
7715
7716 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7717 if (ret) {
7718 sigma_dut_print(dut, DUT_MSG_ERROR,
7719 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7720 __func__, ret, val);
7721 }
7722 return ret;
7723#else /* NL80211_SUPPORT */
7724 sigma_dut_print(dut, DUT_MSG_ERROR,
7725 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7726 return -1;
7727#endif /* NL80211_SUPPORT */
7728}
7729
7730
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007731static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7732 int val)
7733{
7734#ifdef NL80211_SUPPORT
7735 struct nl_msg *msg;
7736 int ret = 0;
7737 struct nlattr *params;
7738 int ifindex;
7739
7740 ifindex = if_nametoindex(intf);
7741 if (ifindex == 0) {
7742 sigma_dut_print(dut, DUT_MSG_ERROR,
7743 "%s: Index for interface %s failed, val:%d",
7744 __func__, intf, val);
7745 return -1;
7746 }
7747
7748 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7749 NL80211_CMD_VENDOR)) ||
7750 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7751 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7752 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7753 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7754 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7755 nla_put_u8(msg,
7756 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
7757 val)) {
7758 sigma_dut_print(dut, DUT_MSG_ERROR,
7759 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7760 __func__, val);
7761 nlmsg_free(msg);
7762 return -1;
7763 }
7764 nla_nest_end(msg, params);
7765
7766 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7767 if (ret) {
7768 sigma_dut_print(dut, DUT_MSG_ERROR,
7769 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7770 __func__, ret, val);
7771 }
7772 return ret;
7773#else /* NL80211_SUPPORT */
7774 sigma_dut_print(dut, DUT_MSG_ERROR,
7775 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7776 return -1;
7777#endif /* NL80211_SUPPORT */
7778}
7779
7780
Arif Hussain480d5f42019-03-12 14:40:42 -07007781static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7782 int val)
7783{
7784#ifdef NL80211_SUPPORT
7785 struct nl_msg *msg;
7786 int ret;
7787 struct nlattr *params;
7788 int ifindex;
7789
7790 ifindex = if_nametoindex(intf);
7791 if (ifindex == 0) {
7792 sigma_dut_print(dut, DUT_MSG_ERROR,
7793 "%s: Index for interface %s failed, val:%d",
7794 __func__, intf, val);
7795 return -1;
7796 }
7797
7798 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7799 NL80211_CMD_VENDOR)) ||
7800 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7801 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7802 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7803 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7804 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7805 nla_put_u8(msg,
7806 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT,
7807 val)) {
7808 sigma_dut_print(dut, DUT_MSG_ERROR,
7809 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7810 __func__, val);
7811 nlmsg_free(msg);
7812 return -1;
7813 }
7814 nla_nest_end(msg, params);
7815
7816 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7817 if (ret) {
7818 sigma_dut_print(dut, DUT_MSG_ERROR,
7819 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7820 __func__, ret, val);
7821 }
7822 return ret;
7823#else /* NL80211_SUPPORT */
7824 sigma_dut_print(dut, DUT_MSG_ERROR,
7825 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7826 return -1;
7827#endif /* NL80211_SUPPORT */
7828}
7829
7830
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007831static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7832 const char *type)
7833{
7834 char buf[60];
7835
7836 if (dut->program == PROGRAM_HE) {
7837 /* resetting phymode to auto in case of HE program */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05307838 sta_set_phymode(dut, intf, "auto");
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007839
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007840 /* reset the rate to Auto rate */
7841 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7842 intf);
7843 if (system(buf) != 0) {
7844 sigma_dut_print(dut, DUT_MSG_ERROR,
7845 "iwpriv %s set_11ax_rate 0xff failed",
7846 intf);
7847 }
7848
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007849 /* reset the LDPC setting */
7850 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7851 if (system(buf) != 0) {
7852 sigma_dut_print(dut, DUT_MSG_ERROR,
7853 "iwpriv %s ldpc 1 failed", intf);
7854 }
7855
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007856 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05307857 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007858
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007859 /* remove all network profiles */
7860 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007861
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007862 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7863 sta_set_addba_buf_size(dut, intf, 64);
7864
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007865#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007866 /* Reset the device HE capabilities to its default supported
7867 * configuration. */
7868 sta_set_he_testbed_def(dut, intf, 0);
7869
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007870 /* Disable noackpolicy for all AC */
7871 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7872 sigma_dut_print(dut, DUT_MSG_ERROR,
7873 "Disable of noackpolicy for all AC failed");
7874 }
7875#endif /* NL80211_SUPPORT */
7876
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007877 /* Enable WMM by default */
7878 if (wcn_sta_set_wmm(dut, intf, "on")) {
7879 sigma_dut_print(dut, DUT_MSG_ERROR,
7880 "Enable of WMM in sta_reset_default_wcn failed");
7881 }
7882
7883 /* Disable ADDBA_REJECT by default */
7884 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7885 sigma_dut_print(dut, DUT_MSG_ERROR,
7886 "Disable of addba_reject in sta_reset_default_wcn failed");
7887 }
7888
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007889 /* Enable sending of ADDBA by default */
7890 if (nlvendor_config_send_addba(dut, intf, 1)) {
7891 sigma_dut_print(dut, DUT_MSG_ERROR,
7892 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7893 }
7894
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007895 /* Enable AMPDU by default */
7896 iwpriv_sta_set_ampdu(dut, intf, 1);
7897
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007898#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08007899 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007900 sigma_dut_print(dut, DUT_MSG_ERROR,
7901 "Set LTF config to default in sta_reset_default_wcn failed");
7902 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007903
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007904 /* set the beamformee NSTS(maximum number of
7905 * space-time streams) to default DUT config
7906 */
7907 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007908 sigma_dut_print(dut, DUT_MSG_ERROR,
7909 "Failed to set BeamformeeSTS");
7910 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007911
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007912 if (sta_set_mac_padding_duration(
7913 dut, intf,
7914 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007915 sigma_dut_print(dut, DUT_MSG_ERROR,
7916 "Failed to set MAC padding duration");
7917 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007918
7919 if (sta_set_mu_edca_override(dut, intf, 0)) {
7920 sigma_dut_print(dut, DUT_MSG_ERROR,
7921 "ErrorCode,Failed to set MU EDCA override disable");
7922 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007923
7924 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7925 sigma_dut_print(dut, DUT_MSG_ERROR,
7926 "Failed to set OM ctrl supp");
7927 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007928
7929 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7930 sigma_dut_print(dut, DUT_MSG_ERROR,
7931 "Failed to set Tx SU PPDU enable");
7932 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007933
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007934 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7935 sigma_dut_print(dut, DUT_MSG_ERROR,
7936 "failed to send TB PPDU Tx cfg");
7937 }
7938
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007939 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7940 sigma_dut_print(dut, DUT_MSG_ERROR,
7941 "Failed to set OM ctrl reset");
7942 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007943
7944 /* +HTC-HE support default on */
7945 if (sta_set_he_htc_supp(dut, intf, 1)) {
7946 sigma_dut_print(dut, DUT_MSG_ERROR,
7947 "Setting of +HTC-HE support failed");
7948 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007949#endif /* NL80211_SUPPORT */
7950
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007951 if (sta_set_tx_beamformee(dut, intf, 1)) {
7952 sigma_dut_print(dut, DUT_MSG_ERROR,
7953 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7954 }
7955
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007956 wpa_command(intf, "SET oce 1");
7957
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007958 /* Set nss to 1 and MCS 0-7 in case of testbed */
7959 if (type && strcasecmp(type, "Testbed") == 0) {
7960#ifdef NL80211_SUPPORT
7961 int ret;
7962#endif /* NL80211_SUPPORT */
7963
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007964 wpa_command(intf, "SET oce 0");
7965
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007966 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7967 if (system(buf) != 0) {
7968 sigma_dut_print(dut, DUT_MSG_ERROR,
7969 "iwpriv %s nss failed", intf);
7970 }
7971
7972#ifdef NL80211_SUPPORT
7973 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7974 if (ret) {
7975 sigma_dut_print(dut, DUT_MSG_ERROR,
7976 "Setting of MCS failed, ret:%d",
7977 ret);
7978 }
7979#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007980
7981 /* Disable STBC as default */
7982 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007983
7984 /* Disable AMSDU as default */
7985 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007986
7987#ifdef NL80211_SUPPORT
7988 /* HE fragmentation default off */
7989 if (sta_set_he_fragmentation(dut, intf,
7990 HE_FRAG_DISABLE)) {
7991 sigma_dut_print(dut, DUT_MSG_ERROR,
7992 "Setting of HE fragmentation failed");
7993 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007994
7995 /* set the beamformee NSTS(maximum number of
7996 * space-time streams) to default testbed config
7997 */
7998 if (sta_set_beamformee_sts(dut, intf, 3)) {
7999 sigma_dut_print(dut, DUT_MSG_ERROR,
8000 "Failed to set BeamformeeSTS");
8001 }
8002
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08008003 /* +HTC-HE support default off */
8004 if (sta_set_he_htc_supp(dut, intf, 0)) {
8005 sigma_dut_print(dut, DUT_MSG_ERROR,
8006 "Setting of +HTC-HE support failed");
8007 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008008
8009 /* Set device HE capabilities to testbed default
8010 * configuration. */
8011 if (sta_set_he_testbed_def(dut, intf, 1)) {
8012 sigma_dut_print(dut, DUT_MSG_DEBUG,
8013 "Failed to set HE defaults");
8014 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08008015
8016 /* Disable VHT support in 2.4 GHz for testbed */
8017 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08008018#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08008019
8020 /* Enable WEP/TKIP with HE capability in testbed */
8021 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
8022 sigma_dut_print(dut, DUT_MSG_ERROR,
8023 "Enabling HE config with WEP/TKIP failed");
8024 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008025 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008026
8027 /* Defaults in case of DUT */
8028 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07008029 /* Enable STBC by default */
8030 wcn_sta_set_stbc(dut, intf, "1");
8031
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008032 /* set nss to 2 */
8033 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
8034 if (system(buf) != 0) {
8035 sigma_dut_print(dut, DUT_MSG_ERROR,
8036 "iwpriv %s nss 2 failed", intf);
8037 }
Arif Hussainac6c5112018-05-25 17:34:00 -07008038 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008039
8040#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07008041 /* Set HE_MCS to 0-11 */
8042 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008043 sigma_dut_print(dut, DUT_MSG_ERROR,
8044 "Setting of MCS failed");
8045 }
8046#endif /* NL80211_SUPPORT */
8047
8048 /* Disable WEP/TKIP with HE capability in DUT */
8049 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
8050 sigma_dut_print(dut, DUT_MSG_ERROR,
8051 "Enabling HE config with WEP/TKIP failed");
8052 }
8053 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008054 }
8055}
8056
8057
Jouni Malinenf7222712019-06-13 01:50:21 +03008058static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
8059 struct sigma_conn *conn,
8060 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008061{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008062 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008063 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008064 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008065 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308066 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008067
Jouni Malinenb21f0542019-11-04 17:53:38 +02008068 if (dut->station_ifname_2g &&
8069 strcmp(dut->station_ifname_2g, intf) == 0)
8070 dut->use_5g = 0;
8071 else if (dut->station_ifname_5g &&
8072 strcmp(dut->station_ifname_5g, intf) == 0)
8073 dut->use_5g = 1;
8074
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008075 if (!program)
8076 program = get_param(cmd, "prog");
8077 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008078 dut->device_type = STA_unknown;
8079 type = get_param(cmd, "type");
8080 if (type && strcasecmp(type, "Testbed") == 0)
8081 dut->device_type = STA_testbed;
8082 if (type && strcasecmp(type, "DUT") == 0)
8083 dut->device_type = STA_dut;
8084
8085 if (dut->program == PROGRAM_TDLS) {
8086 /* Clear TDLS testing mode */
8087 wpa_command(intf, "SET tdls_disabled 0");
8088 wpa_command(intf, "SET tdls_testing 0");
8089 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008090 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05308091 /* Enable the WCN driver in TDLS Explicit trigger mode
8092 */
8093 wpa_command(intf, "SET tdls_external_control 0");
8094 wpa_command(intf, "SET tdls_trigger_control 0");
8095 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008096 }
8097
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008098#ifdef MIRACAST
8099 if (dut->program == PROGRAM_WFD ||
8100 dut->program == PROGRAM_DISPLAYR2)
8101 miracast_sta_reset_default(dut, conn, cmd);
8102#endif /* MIRACAST */
8103
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008104 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008105 case DRIVER_ATHEROS:
8106 sta_reset_default_ath(dut, intf, type);
8107 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008108 case DRIVER_WCN:
8109 sta_reset_default_wcn(dut, intf, type);
8110 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008111 default:
8112 break;
8113 }
8114
8115#ifdef ANDROID_NAN
8116 if (dut->program == PROGRAM_NAN)
8117 nan_cmd_sta_reset_default(dut, conn, cmd);
8118#endif /* ANDROID_NAN */
8119
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05308120 if (dut->program == PROGRAM_LOC &&
8121 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
8122 return ERROR_SEND_STATUS;
8123
Jouni Malinenba630452018-06-22 11:49:59 +03008124 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008125 unlink("SP/wi-fi.org/pps.xml");
8126 if (system("rm -r SP/*") != 0) {
8127 }
8128 unlink("next-client-cert.pem");
8129 unlink("next-client-key.pem");
8130 }
8131
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008132 /* For WPS program of the 60 GHz band the band type needs to be saved */
8133 if (dut->program == PROGRAM_WPS) {
8134 if (band && strcasecmp(band, "60GHz") == 0) {
8135 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008136 /* For 60 GHz enable WPS for WPS TCs */
8137 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008138 } else {
8139 dut->band = WPS_BAND_NON_60G;
8140 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008141 } else if (dut->program == PROGRAM_60GHZ) {
8142 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
8143 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008144 }
8145
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02008146 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008147 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008148 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008149
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008150 sigma_dut_print(dut, DUT_MSG_INFO,
8151 "WPS 60 GHz program, wps_disable = %d",
8152 dut->wps_disable);
8153
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008154 if (!dev_role) {
8155 send_resp(dut, conn, SIGMA_ERROR,
8156 "errorCode,Missing DevRole argument");
8157 return 0;
8158 }
8159
8160 if (strcasecmp(dev_role, "STA") == 0)
8161 dut->dev_role = DEVROLE_STA;
8162 else if (strcasecmp(dev_role, "PCP") == 0)
8163 dut->dev_role = DEVROLE_PCP;
8164 else {
8165 send_resp(dut, conn, SIGMA_ERROR,
8166 "errorCode,Unknown DevRole");
8167 return 0;
8168 }
8169
8170 if (dut->device_type == STA_unknown) {
8171 sigma_dut_print(dut, DUT_MSG_ERROR,
8172 "Device type is not STA testbed or DUT");
8173 send_resp(dut, conn, SIGMA_ERROR,
8174 "errorCode,Unknown device type");
8175 return 0;
8176 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008177
8178 sigma_dut_print(dut, DUT_MSG_DEBUG,
8179 "Setting msdu_size to MAX: 7912");
8180 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008181 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008182
8183 if (system(buf) != 0) {
8184 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
8185 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008186 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008187 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008188
8189 if (sta_set_force_mcs(dut, 0, 1)) {
8190 sigma_dut_print(dut, DUT_MSG_ERROR,
8191 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008192 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008193 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008194 }
8195
8196 wpa_command(intf, "WPS_ER_STOP");
8197 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05308198 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008199 wpa_command(intf, "SET radio_disabled 0");
8200
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02008201 dut->wps_forced_version = 0;
8202
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008203 if (dut->wsc_fragment) {
8204 dut->wsc_fragment = 0;
8205 wpa_command(intf, "SET device_name Test client");
8206 wpa_command(intf, "SET manufacturer ");
8207 wpa_command(intf, "SET model_name ");
8208 wpa_command(intf, "SET model_number ");
8209 wpa_command(intf, "SET serial_number ");
8210 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02008211 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
8212 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
8213 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
8214 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008215
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008216 if (dut->tmp_mac_addr && dut->set_macaddr) {
8217 dut->tmp_mac_addr = 0;
8218 if (system(dut->set_macaddr) != 0) {
8219 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
8220 "temporary MAC address");
8221 }
8222 }
8223
8224 set_ps(intf, dut, 0);
8225
Jouni Malinenba630452018-06-22 11:49:59 +03008226 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
8227 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008228 wpa_command(intf, "SET interworking 1");
8229 wpa_command(intf, "SET hs20 1");
8230 }
8231
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008232 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03008233 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008234 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008235 wpa_command(intf, "SET pmf 1");
8236 } else {
8237 wpa_command(intf, "SET pmf 0");
8238 }
8239
8240 hs2_clear_credentials(intf);
8241 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
8242 wpa_command(intf, "SET access_network_type 15");
8243
8244 static_ip_file(0, NULL, NULL, NULL);
8245 kill_dhcp_client(dut, intf);
8246 clear_ip_addr(dut, intf);
8247
8248 dut->er_oper_performed = 0;
8249 dut->er_oper_bssid[0] = '\0';
8250
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008251 if (dut->program == PROGRAM_LOC) {
8252 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008253 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008254 }
8255
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07008256 if (dut->program == PROGRAM_MBO || dut->program == PROGRAM_HE) {
Ashwini Patil00402582017-04-13 12:29:39 +05308257 free(dut->non_pref_ch_list);
8258 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05308259 free(dut->btm_query_cand_list);
8260 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05308261 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05308262 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05308263 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05308264 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05308265 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05308266 }
8267
Jouni Malinen3c367e82017-06-23 17:01:47 +03008268 free(dut->rsne_override);
8269 dut->rsne_override = NULL;
8270
Jouni Malinen68143132017-09-02 02:34:08 +03008271 free(dut->sae_commit_override);
8272 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03008273 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02008274 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03008275
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008276 dut->sta_associate_wait_connect = 0;
8277 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03008278 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008279 dut->sta_tod_policy = 0;
8280
Jouni Malinend86e5822017-08-29 03:55:32 +03008281 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02008282 free(dut->dpp_peer_uri);
8283 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02008284 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02008285 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03008286 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03008287
Jouni Malinenfac9cad2017-10-10 18:35:55 +03008288 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
8289
vamsi krishnaa2799492017-12-05 14:28:01 +05308290 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308291 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05308292 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05308293 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
8294 dut->fils_hlp = 0;
8295#ifdef ANDROID
8296 hlp_thread_cleanup(dut);
8297#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05308298 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308299
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308300 if (dut->program == PROGRAM_QM)
8301 wpa_command(intf, "SET interworking 1");
8302
Jouni Malinen8179fee2019-03-28 03:19:47 +02008303 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03008304 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02008305
Sunil Dutt076081f2018-02-05 19:45:50 +05308306#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008307 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05308308 dut->config_rsnie == 1) {
8309 dut->config_rsnie = 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308310 sta_config_params(dut, intf, STA_SET_RSNIE, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05308311 }
8312#endif /* NL80211_SUPPORT */
8313
Sunil Duttfebf8a82018-02-09 18:50:13 +05308314 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
8315 dut->dev_role = DEVROLE_STA_CFON;
8316 return sta_cfon_reset_default(dut, conn, cmd);
8317 }
8318
Jouni Malinen439352d2018-09-13 03:42:23 +03008319 wpa_command(intf, "SET setband AUTO");
8320
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308321 dut->ocvc = 0;
Jouni Malinen67433fc2020-06-26 22:50:33 +03008322 dut->client_privacy = 0;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05308323 dut->saquery_oci_freq = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308324
Sunil Duttfebf8a82018-02-09 18:50:13 +05308325 if (dut->program != PROGRAM_VHT)
8326 return cmd_sta_p2p_reset(dut, conn, cmd);
8327
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08008328 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008329}
8330
8331
Jouni Malinenf7222712019-06-13 01:50:21 +03008332static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
8333 struct sigma_conn *conn,
8334 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008335{
8336 const char *program = get_param(cmd, "Program");
8337
8338 if (program == NULL)
8339 return -1;
8340#ifdef ANDROID_NAN
8341 if (strcasecmp(program, "NAN") == 0)
8342 return nan_cmd_sta_get_events(dut, conn, cmd);
8343#endif /* ANDROID_NAN */
8344 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8345 return 0;
8346}
8347
8348
Jouni Malinen82905202018-04-29 17:20:10 +03008349static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
8350 struct sigma_cmd *cmd)
8351{
8352 const char *url = get_param(cmd, "url");
8353 const char *method = get_param(cmd, "method");
8354 pid_t pid;
8355 int status;
8356
8357 if (!url || !method)
8358 return -1;
8359
8360 /* TODO: Add support for method,post */
8361 if (strcasecmp(method, "get") != 0) {
8362 send_resp(dut, conn, SIGMA_ERROR,
8363 "ErrorCode,Unsupported method");
8364 return 0;
8365 }
8366
8367 pid = fork();
8368 if (pid < 0) {
8369 perror("fork");
8370 return -1;
8371 }
8372
8373 if (pid == 0) {
8374 char * argv[5] = { "wget", "-O", "/dev/null",
8375 (char *) url, NULL };
8376
8377 execv("/usr/bin/wget", argv);
8378 perror("execv");
8379 exit(0);
8380 return -1;
8381 }
8382
8383 if (waitpid(pid, &status, 0) < 0) {
8384 perror("waitpid");
8385 return -1;
8386 }
8387
8388 if (WIFEXITED(status)) {
8389 const char *errmsg;
8390
8391 if (WEXITSTATUS(status) == 0)
8392 return 1;
8393 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
8394 WEXITSTATUS(status));
8395 switch (WEXITSTATUS(status)) {
8396 case 4:
8397 errmsg = "errmsg,Network failure";
8398 break;
8399 case 8:
8400 errmsg = "errmsg,Server issued an error response";
8401 break;
8402 default:
8403 errmsg = "errmsg,Unknown failure from wget";
8404 break;
8405 }
8406 send_resp(dut, conn, SIGMA_ERROR, errmsg);
8407 return 0;
8408 }
8409
8410 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
8411 return 0;
8412}
8413
8414
Jouni Malinenf7222712019-06-13 01:50:21 +03008415static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
8416 struct sigma_conn *conn,
8417 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008418{
8419 const char *program = get_param(cmd, "Prog");
8420
Jouni Malinen82905202018-04-29 17:20:10 +03008421 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008422 return -1;
8423#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03008424 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008425 return nan_cmd_sta_exec_action(dut, conn, cmd);
8426#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03008427
8428 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07008429 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03008430
8431 if (get_param(cmd, "url"))
8432 return sta_exec_action_url(dut, conn, cmd);
8433
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008434 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8435 return 0;
8436}
8437
8438
Jouni Malinenf7222712019-06-13 01:50:21 +03008439static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
8440 struct sigma_conn *conn,
8441 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008442{
8443 const char *intf = get_param(cmd, "Interface");
8444 const char *val, *mcs32, *rate;
8445
8446 val = get_param(cmd, "GREENFIELD");
8447 if (val) {
8448 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
8449 /* Enable GD */
8450 send_resp(dut, conn, SIGMA_ERROR,
8451 "ErrorCode,GF not supported");
8452 return 0;
8453 }
8454 }
8455
8456 val = get_param(cmd, "SGI20");
8457 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008458 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008459 case DRIVER_ATHEROS:
8460 ath_sta_set_sgi(dut, intf, val);
8461 break;
8462 default:
8463 send_resp(dut, conn, SIGMA_ERROR,
8464 "ErrorCode,SGI20 not supported");
8465 return 0;
8466 }
8467 }
8468
8469 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
8470 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
8471 if (mcs32 && rate) {
8472 /* TODO */
8473 send_resp(dut, conn, SIGMA_ERROR,
8474 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
8475 return 0;
8476 } else if (mcs32 && !rate) {
8477 /* TODO */
8478 send_resp(dut, conn, SIGMA_ERROR,
8479 "ErrorCode,MCS32 not supported");
8480 return 0;
8481 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008482 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008483 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008484 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008485 ath_sta_set_11nrates(dut, intf, rate);
8486 break;
8487 default:
8488 send_resp(dut, conn, SIGMA_ERROR,
8489 "ErrorCode,MCS32_FIXEDRATE not supported");
8490 return 0;
8491 }
8492 }
8493
8494 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8495}
8496
8497
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008498static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8499 int mcs_config)
8500{
8501#ifdef NL80211_SUPPORT
8502 int ret;
8503
8504 switch (mcs_config) {
8505 case HE_80_MCS0_7:
8506 case HE_80_MCS0_9:
8507 case HE_80_MCS0_11:
8508 ret = sta_set_he_mcs(dut, intf, mcs_config);
8509 if (ret) {
8510 sigma_dut_print(dut, DUT_MSG_ERROR,
8511 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8512 mcs_config, ret);
8513 }
8514 break;
8515 default:
8516 sigma_dut_print(dut, DUT_MSG_ERROR,
8517 "cmd_set_max_he_mcs: Invalid mcs %d",
8518 mcs_config);
8519 break;
8520 }
8521#else /* NL80211_SUPPORT */
8522 sigma_dut_print(dut, DUT_MSG_ERROR,
8523 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8524#endif /* NL80211_SUPPORT */
8525}
8526
8527
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008528#define TWT_REQUEST_CMD 0
8529#define TWT_SUGGEST_CMD 1
8530#define TWT_DEMAND_CMD 2
8531
Arif Hussain480d5f42019-03-12 14:40:42 -07008532static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8533 struct sigma_cmd *cmd)
8534{
8535#ifdef NL80211_SUPPORT
8536 struct nlattr *params;
8537 struct nlattr *attr;
8538 struct nlattr *attr1;
8539 struct nl_msg *msg;
8540 int ifindex, ret;
8541 const char *val;
8542 const char *intf = get_param(cmd, "Interface");
8543 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8544 wake_interval_mantissa = 512;
8545 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008546 protection = 0, cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
Arif Hussain480d5f42019-03-12 14:40:42 -07008547
8548 ifindex = if_nametoindex(intf);
8549 if (ifindex == 0) {
8550 sigma_dut_print(dut, DUT_MSG_ERROR,
8551 "%s: Index for interface %s failed",
8552 __func__, intf);
8553 return -1;
8554 }
8555
8556 val = get_param(cmd, "FlowType");
8557 if (val) {
8558 flow_type = atoi(val);
8559 if (flow_type != 0 && flow_type != 1) {
8560 sigma_dut_print(dut, DUT_MSG_ERROR,
8561 "TWT: Invalid FlowType %d", flow_type);
8562 return -1;
8563 }
8564 }
8565
8566 val = get_param(cmd, "TWT_Trigger");
8567 if (val) {
8568 twt_trigger = atoi(val);
8569 if (twt_trigger != 0 && twt_trigger != 1) {
8570 sigma_dut_print(dut, DUT_MSG_ERROR,
8571 "TWT: Invalid TWT_Trigger %d",
8572 twt_trigger);
8573 return -1;
8574 }
8575 }
8576
8577 val = get_param(cmd, "Protection");
8578 if (val) {
8579 protection = atoi(val);
8580 if (protection != 0 && protection != 1) {
8581 sigma_dut_print(dut, DUT_MSG_ERROR,
8582 "TWT: Invalid Protection %d",
8583 protection);
8584 return -1;
8585 }
8586 }
8587
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008588 val = get_param(cmd, "SetupCommand");
8589 if (val) {
8590 cmd_type = atoi(val);
8591 if (cmd_type == TWT_REQUEST_CMD)
8592 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_REQUEST;
8593 else if (cmd_type == TWT_SUGGEST_CMD)
8594 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
8595 else if (cmd_type == TWT_DEMAND_CMD)
8596 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_DEMAND;
8597 else
8598 sigma_dut_print(dut, DUT_MSG_ERROR,
8599 "Default suggest is used for cmd %d",
8600 cmd_type);
8601 }
8602
Arif Hussain480d5f42019-03-12 14:40:42 -07008603 val = get_param(cmd, "TargetWakeTime");
8604 if (val)
8605 target_wake_time = atoi(val);
8606
8607 val = get_param(cmd, "WakeIntervalMantissa");
8608 if (val)
8609 wake_interval_mantissa = atoi(val);
8610
8611 val = get_param(cmd, "WakeIntervalExp");
8612 if (val)
8613 wake_interval_exp = atoi(val);
8614
8615 val = get_param(cmd, "NominalMinWakeDur");
8616 if (val)
8617 nominal_min_wake_dur = atoi(val);
8618
8619 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8620 NL80211_CMD_VENDOR)) ||
8621 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8622 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8623 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8624 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8625 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8626 !(params = nla_nest_start(
8627 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
8628 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8629 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8630 wake_interval_exp) ||
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008631 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, cmd_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008632 (twt_trigger &&
8633 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008634 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8635 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008636 (protection &&
8637 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008638 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8639 target_wake_time) ||
8640 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8641 nominal_min_wake_dur) ||
8642 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8643 wake_interval_mantissa)) {
8644 sigma_dut_print(dut, DUT_MSG_ERROR,
8645 "%s: err in adding vendor_cmd and vendor_data",
8646 __func__);
8647 nlmsg_free(msg);
8648 return -1;
8649 }
8650 nla_nest_end(msg, attr1);
8651 nla_nest_end(msg, params);
8652 nla_nest_end(msg, attr);
8653
8654 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8655 if (ret) {
8656 sigma_dut_print(dut, DUT_MSG_ERROR,
8657 "%s: err in send_and_recv_msgs, ret=%d",
8658 __func__, ret);
8659 }
8660
8661 return ret;
8662#else /* NL80211_SUPPORT */
8663 sigma_dut_print(dut, DUT_MSG_ERROR,
8664 "TWT request cannot be done without NL80211_SUPPORT defined");
8665 return -1;
8666#endif /* NL80211_SUPPORT */
8667}
8668
8669
8670static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8671 struct sigma_cmd *cmd)
8672{
8673 #ifdef NL80211_SUPPORT
8674 struct nlattr *params;
8675 struct nlattr *attr;
8676 struct nlattr *attr1;
8677 int ifindex, ret;
8678 struct nl_msg *msg;
8679 const char *intf = get_param(cmd, "Interface");
8680
8681 ifindex = if_nametoindex(intf);
8682 if (ifindex == 0) {
8683 sigma_dut_print(dut, DUT_MSG_ERROR,
8684 "%s: Index for interface %s failed",
8685 __func__, intf);
8686 return -1;
8687 }
8688
8689 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8690 NL80211_CMD_VENDOR)) ||
8691 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8692 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8693 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8694 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8695 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8696 !(params = nla_nest_start(
8697 msg,
8698 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8699 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8700 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8701 sigma_dut_print(dut, DUT_MSG_ERROR,
8702 "%s: err in adding vendor_cmd and vendor_data",
8703 __func__);
8704 nlmsg_free(msg);
8705 return -1;
8706 }
8707 nla_nest_end(msg, attr1);
8708 nla_nest_end(msg, params);
8709 nla_nest_end(msg, attr);
8710
8711 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8712 if (ret) {
8713 sigma_dut_print(dut, DUT_MSG_ERROR,
8714 "%s: err in send_and_recv_msgs, ret=%d",
8715 __func__, ret);
8716 }
8717
8718 return ret;
8719#else /* NL80211_SUPPORT */
8720 sigma_dut_print(dut, DUT_MSG_ERROR,
8721 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8722 return -1;
8723#endif /* NL80211_SUPPORT */
8724}
8725
8726
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008727static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8728 struct sigma_cmd *cmd)
8729{
8730#ifdef NL80211_SUPPORT
8731 struct nlattr *params;
8732 struct nlattr *attr;
8733 struct nlattr *attr1;
8734 struct nl_msg *msg;
8735 int ifindex, ret;
8736 const char *val;
8737 const char *intf = get_param(cmd, "Interface");
8738 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8739 ulmu_data_dis = 0;
8740
8741 ifindex = if_nametoindex(intf);
8742 if (ifindex == 0) {
8743 sigma_dut_print(dut, DUT_MSG_ERROR,
8744 "%s: Index for interface %s failed",
8745 __func__, intf);
8746 return -1;
8747 }
8748 val = get_param(cmd, "OMCtrl_RxNSS");
8749 if (val)
8750 rx_nss = atoi(val);
8751
8752 val = get_param(cmd, "OMCtrl_ChnlWidth");
8753 if (val)
8754 ch_bw = atoi(val);
8755
8756 val = get_param(cmd, "OMCtrl_ULMUDisable");
8757 if (val)
8758 ulmu_dis = atoi(val);
8759
8760 val = get_param(cmd, "OMCtrl_TxNSTS");
8761 if (val)
8762 tx_nsts = atoi(val);
8763
8764 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8765 if (val)
8766 ulmu_data_dis = atoi(val);
8767
8768 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8769 NL80211_CMD_VENDOR)) ||
8770 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8771 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8772 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8773 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8774 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8775 !(params = nla_nest_start(
8776 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8777 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8778 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8779 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8780 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8781 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8782 ulmu_data_dis) ||
8783 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8784 ulmu_dis)) {
8785 sigma_dut_print(dut, DUT_MSG_ERROR,
8786 "%s: err in adding vendor_cmd and vendor_data",
8787 __func__);
8788 nlmsg_free(msg);
8789 return -1;
8790 }
8791 nla_nest_end(msg, attr1);
8792 nla_nest_end(msg, params);
8793 nla_nest_end(msg, attr);
8794
8795 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8796 if (ret) {
8797 sigma_dut_print(dut, DUT_MSG_ERROR,
8798 "%s: err in send_and_recv_msgs, ret=%d",
8799 __func__, ret);
8800 }
8801
8802 return ret;
8803#else /* NL80211_SUPPORT */
8804 sigma_dut_print(dut, DUT_MSG_ERROR,
8805 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8806 return -1;
8807#endif /* NL80211_SUPPORT */
8808}
8809
8810
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008811static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8812 struct sigma_conn *conn,
8813 struct sigma_cmd *cmd)
8814{
8815 const char *intf = get_param(cmd, "Interface");
8816 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008817 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008818 int tkip = -1;
8819 int wep = -1;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308820 int iwpriv_status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008821
Arif Hussaina37e9552018-06-20 17:05:59 -07008822 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008823 val = get_param(cmd, "SGI80");
8824 if (val) {
8825 int sgi80;
8826
8827 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008828 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008829 }
8830
8831 val = get_param(cmd, "TxBF");
8832 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008833 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008834 case DRIVER_WCN:
8835 if (sta_set_tx_beamformee(dut, intf, 1)) {
8836 send_resp(dut, conn, SIGMA_ERROR,
8837 "ErrorCode,Failed to set TX beamformee enable");
8838 return 0;
8839 }
8840 break;
8841 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008842 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008843 send_resp(dut, conn, SIGMA_ERROR,
8844 "ErrorCode,Setting vhtsubfee failed");
8845 return 0;
8846 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008847 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008848 send_resp(dut, conn, SIGMA_ERROR,
8849 "ErrorCode,Setting vhtsubfer failed");
8850 return 0;
8851 }
8852 break;
8853 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008854 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008855 "Unsupported driver type");
8856 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008857 }
8858 }
8859
8860 val = get_param(cmd, "MU_TxBF");
8861 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008862 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008863 case DRIVER_ATHEROS:
8864 ath_sta_set_txsp_stream(dut, intf, "1SS");
8865 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008866 run_iwpriv(dut, intf, "vhtmubfee 1");
8867 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308868 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008869 case DRIVER_WCN:
8870 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8871 send_resp(dut, conn, SIGMA_ERROR,
8872 "ErrorCode,Failed to set RX/TXSP_STREAM");
8873 return 0;
8874 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308875 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008876 default:
8877 sigma_dut_print(dut, DUT_MSG_ERROR,
8878 "Setting SP_STREAM not supported");
8879 break;
8880 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008881 }
8882
8883 val = get_param(cmd, "LDPC");
8884 if (val) {
8885 int ldpc;
8886
8887 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308888 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", ldpc);
8889 if (iwpriv_status)
8890 sta_config_params(dut, intf, STA_SET_LDPC, ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008891 }
8892
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008893 val = get_param(cmd, "BCC");
8894 if (val) {
8895 int bcc;
8896
8897 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8898 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8899 * is mutually exclusive to bcc */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308900 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", !bcc);
8901 if (iwpriv_status)
8902 sta_config_params(dut, intf, STA_SET_LDPC, !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008903 }
8904
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008905 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8906 if (val && dut->sta_nss == 1)
8907 cmd_set_max_he_mcs(dut, intf, atoi(val));
8908
8909 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8910 if (val && dut->sta_nss == 2)
8911 cmd_set_max_he_mcs(dut, intf, atoi(val));
8912
Arif Hussainac6c5112018-05-25 17:34:00 -07008913 val = get_param(cmd, "MCS_FixedRate");
8914 if (val) {
8915#ifdef NL80211_SUPPORT
8916 int mcs, ratecode = 0;
8917 enum he_mcs_config mcs_config;
8918 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008919 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008920
8921 ratecode = (0x07 & dut->sta_nss) << 5;
8922 mcs = atoi(val);
8923 /* Add the MCS to the ratecode */
8924 if (mcs >= 0 && mcs <= 11) {
8925 ratecode += mcs;
8926 if (dut->device_type == STA_testbed &&
8927 mcs > 7 && mcs <= 11) {
8928 if (mcs <= 9)
8929 mcs_config = HE_80_MCS0_9;
8930 else
8931 mcs_config = HE_80_MCS0_11;
8932 ret = sta_set_he_mcs(dut, intf, mcs_config);
8933 if (ret) {
8934 sigma_dut_print(dut, DUT_MSG_ERROR,
8935 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8936 mcs, mcs_config, ret);
8937 }
8938 }
8939 snprintf(buf, sizeof(buf),
8940 "iwpriv %s set_11ax_rate 0x%03x",
8941 intf, ratecode);
8942 if (system(buf) != 0) {
8943 sigma_dut_print(dut, DUT_MSG_ERROR,
8944 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8945 ratecode);
8946 }
8947 } else {
8948 sigma_dut_print(dut, DUT_MSG_ERROR,
8949 "MCS_FixedRate: HE MCS %d not supported",
8950 mcs);
8951 }
8952#else /* NL80211_SUPPORT */
8953 sigma_dut_print(dut, DUT_MSG_ERROR,
8954 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8955#endif /* NL80211_SUPPORT */
8956 }
8957
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008958 val = get_param(cmd, "opt_md_notif_ie");
8959 if (val) {
8960 char *result = NULL;
8961 char delim[] = ";";
8962 char token[30];
8963 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308964 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008965
Peng Xub8fc5cc2017-05-10 17:27:28 -07008966 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308967 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008968
8969 /* Extract the NSS information */
8970 if (result) {
8971 value = atoi(result);
8972 switch (value) {
8973 case 1:
8974 config_val = 1;
8975 break;
8976 case 2:
8977 config_val = 3;
8978 break;
8979 case 3:
8980 config_val = 7;
8981 break;
8982 case 4:
8983 config_val = 15;
8984 break;
8985 default:
8986 config_val = 3;
8987 break;
8988 }
8989
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008990 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8991 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008992
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008993 }
8994
8995 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308996 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008997 if (result) {
8998 value = atoi(result);
8999 switch (value) {
9000 case 20:
9001 config_val = 0;
9002 break;
9003 case 40:
9004 config_val = 1;
9005 break;
9006 case 80:
9007 config_val = 2;
9008 break;
9009 case 160:
9010 config_val = 3;
9011 break;
9012 default:
9013 config_val = 2;
9014 break;
9015 }
9016
9017 dut->chwidth = config_val;
9018
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009019 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009020 }
9021
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009022 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009023 }
9024
9025 val = get_param(cmd, "nss_mcs_cap");
9026 if (val) {
9027 int nss, mcs;
9028 char token[20];
9029 char *result = NULL;
9030 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309031 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009032
Peng Xub8fc5cc2017-05-10 17:27:28 -07009033 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309034 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309035 if (!result) {
9036 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009037 "NSS not specified");
9038 send_resp(dut, conn, SIGMA_ERROR,
9039 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309040 return 0;
9041 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009042 nss = atoi(result);
9043
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009044 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07009045 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009046
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309047 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009048 if (result == NULL) {
9049 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009050 "MCS not specified");
9051 send_resp(dut, conn, SIGMA_ERROR,
9052 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009053 return 0;
9054 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309055 result = strtok_r(result, "-", &saveptr);
9056 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309057 if (!result) {
9058 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009059 "MCS not specified");
9060 send_resp(dut, conn, SIGMA_ERROR,
9061 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309062 return 0;
9063 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009064 mcs = atoi(result);
9065
Arif Hussaina37e9552018-06-20 17:05:59 -07009066 if (program && strcasecmp(program, "HE") == 0) {
9067#ifdef NL80211_SUPPORT
9068 enum he_mcs_config mcs_config;
9069 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009070
Arif Hussaina37e9552018-06-20 17:05:59 -07009071 if (mcs >= 0 && mcs <= 7) {
9072 mcs_config = HE_80_MCS0_7;
9073 } else if (mcs > 7 && mcs <= 9) {
9074 mcs_config = HE_80_MCS0_9;
9075 } else if (mcs > 9 && mcs <= 11) {
9076 mcs_config = HE_80_MCS0_11;
9077 } else {
9078 sigma_dut_print(dut, DUT_MSG_ERROR,
9079 "nss_mcs_cap: HE: Invalid mcs: %d",
9080 mcs);
9081 send_resp(dut, conn, SIGMA_ERROR,
9082 "errorCode,Invalid MCS");
9083 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009084 }
Arif Hussaina37e9552018-06-20 17:05:59 -07009085
9086 ret = sta_set_he_mcs(dut, intf, mcs_config);
9087 if (ret) {
9088 sigma_dut_print(dut, DUT_MSG_ERROR,
9089 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
9090 mcs_config, ret);
9091 send_resp(dut, conn, SIGMA_ERROR,
9092 "errorCode,Failed to set MCS");
9093 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009094 }
Arif Hussaina37e9552018-06-20 17:05:59 -07009095#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009096 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009097 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
9098#endif /* NL80211_SUPPORT */
9099 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009100 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07009101
9102 switch (nss) {
9103 case 1:
9104 switch (mcs) {
9105 case 7:
9106 vht_mcsmap = 0xfffc;
9107 break;
9108 case 8:
9109 vht_mcsmap = 0xfffd;
9110 break;
9111 case 9:
9112 vht_mcsmap = 0xfffe;
9113 break;
9114 default:
9115 vht_mcsmap = 0xfffe;
9116 break;
9117 }
9118 break;
9119 case 2:
9120 switch (mcs) {
9121 case 7:
9122 vht_mcsmap = 0xfff0;
9123 break;
9124 case 8:
9125 vht_mcsmap = 0xfff5;
9126 break;
9127 case 9:
9128 vht_mcsmap = 0xfffa;
9129 break;
9130 default:
9131 vht_mcsmap = 0xfffa;
9132 break;
9133 }
9134 break;
9135 case 3:
9136 switch (mcs) {
9137 case 7:
9138 vht_mcsmap = 0xffc0;
9139 break;
9140 case 8:
9141 vht_mcsmap = 0xffd5;
9142 break;
9143 case 9:
9144 vht_mcsmap = 0xffea;
9145 break;
9146 default:
9147 vht_mcsmap = 0xffea;
9148 break;
9149 }
9150 break;
9151 default:
9152 vht_mcsmap = 0xffea;
9153 break;
9154 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009155 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009156 }
9157 }
9158
9159 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
9160
9161 val = get_param(cmd, "Vht_tkip");
9162 if (val)
9163 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9164
9165 val = get_param(cmd, "Vht_wep");
9166 if (val)
9167 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9168
9169 if (tkip != -1 || wep != -1) {
9170 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009171 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009172 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009173 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009174 } else {
9175 sigma_dut_print(dut, DUT_MSG_ERROR,
9176 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
9177 return 0;
9178 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009179 }
9180
Arif Hussain55f00da2018-07-03 08:28:26 -07009181 val = get_param(cmd, "txBandwidth");
9182 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009183 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07009184 case DRIVER_WCN:
9185 if (wcn_sta_set_width(dut, intf, val) < 0) {
9186 send_resp(dut, conn, SIGMA_ERROR,
9187 "ErrorCode,Failed to set txBandwidth");
9188 return 0;
9189 }
9190 break;
9191 case DRIVER_ATHEROS:
9192 if (ath_set_width(dut, conn, intf, val) < 0) {
9193 send_resp(dut, conn, SIGMA_ERROR,
9194 "ErrorCode,Failed to set txBandwidth");
9195 return 0;
9196 }
9197 break;
9198 default:
9199 sigma_dut_print(dut, DUT_MSG_ERROR,
9200 "Setting txBandwidth not supported");
9201 break;
9202 }
9203 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009204
Arif Hussain9765f7d2018-07-03 08:28:26 -07009205 val = get_param(cmd, "BeamformeeSTS");
9206 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07009207 if (sta_set_tx_beamformee(dut, intf, 1)) {
9208 send_resp(dut, conn, SIGMA_ERROR,
9209 "ErrorCode,Failed to set TX beamformee enable");
9210 return 0;
9211 }
9212
Arif Hussain9765f7d2018-07-03 08:28:26 -07009213 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
9214 send_resp(dut, conn, SIGMA_ERROR,
9215 "ErrorCode,Failed to set BeamformeeSTS");
9216 return 0;
9217 }
9218 }
9219
Arif Hussain68d23f52018-07-11 13:39:08 -07009220 val = get_param(cmd, "Trig_MAC_Padding_Dur");
9221 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07009222#ifdef NL80211_SUPPORT
9223 enum qca_wlan_he_mac_padding_dur set_val;
9224
9225 switch (atoi(val)) {
9226 case 16:
9227 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
9228 break;
9229 case 8:
9230 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
9231 break;
9232 default:
9233 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
9234 break;
9235 }
9236 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07009237 send_resp(dut, conn, SIGMA_ERROR,
9238 "ErrorCode,Failed to set MAC padding duration");
9239 return 0;
9240 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07009241#else /* NL80211_SUPPORT */
9242 sigma_dut_print(dut, DUT_MSG_ERROR,
9243 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
9244#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07009245 }
9246
Arif Hussain480d5f42019-03-12 14:40:42 -07009247 val = get_param(cmd, "TWT_ReqSupport");
9248 if (val) {
9249 int set_val;
9250
9251 if (strcasecmp(val, "Enable") == 0) {
9252 set_val = 1;
9253 } else if (strcasecmp(val, "Disable") == 0) {
9254 set_val = 0;
9255 } else {
9256 send_resp(dut, conn, SIGMA_ERROR,
9257 "ErrorCode,Invalid TWT_ReqSupport");
9258 return STATUS_SENT;
9259 }
9260
9261 if (sta_set_twt_req_support(dut, intf, set_val)) {
9262 sigma_dut_print(dut, DUT_MSG_ERROR,
9263 "Failed to set TWT req support %d",
9264 set_val);
9265 send_resp(dut, conn, SIGMA_ERROR,
9266 "ErrorCode,Failed to set TWT_ReqSupport");
9267 return STATUS_SENT;
9268 }
9269 }
9270
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07009271 val = get_param(cmd, "MU_EDCA");
9272 if (val && (strcasecmp(val, "Override") == 0)) {
9273 if (sta_set_mu_edca_override(dut, intf, 1)) {
9274 send_resp(dut, conn, SIGMA_ERROR,
9275 "ErrorCode,Failed to set MU EDCA override");
9276 return 0;
9277 }
9278 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009279
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07009280 val = get_param(cmd, "OMControl");
9281 if (val) {
9282 int set_val = 1;
9283
9284 if (strcasecmp(val, "Enable") == 0)
9285 set_val = 1;
9286 else if (strcasecmp(val, "Disable") == 0)
9287 set_val = 0;
9288
9289 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
9290 send_resp(dut, conn, SIGMA_ERROR,
9291 "ErrorCode,Failed to set OM ctrl supp");
9292 return 0;
9293 }
9294 }
9295
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009296 val = get_param(cmd, "ADDBAResp_BufSize");
9297 if (val) {
9298 int buf_size;
9299
9300 if (strcasecmp(val, "gt64") == 0)
9301 buf_size = 256;
9302 else
9303 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009304 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009305 sta_set_addba_buf_size(dut, intf, buf_size)) {
9306 send_resp(dut, conn, SIGMA_ERROR,
9307 "ErrorCode,set addbaresp_buff_size failed");
9308 return 0;
9309 }
9310 }
9311
9312 val = get_param(cmd, "ADDBAReq_BufSize");
9313 if (val) {
9314 int buf_size;
9315
9316 if (strcasecmp(val, "gt64") == 0)
9317 buf_size = 256;
9318 else
9319 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009320 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009321 sta_set_addba_buf_size(dut, intf, buf_size)) {
9322 send_resp(dut, conn, SIGMA_ERROR,
9323 "ErrorCode,set addbareq_buff_size failed");
9324 return 0;
9325 }
9326 }
9327
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009328 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9329}
9330
9331
9332static int sta_set_wireless_60g(struct sigma_dut *dut,
9333 struct sigma_conn *conn,
9334 struct sigma_cmd *cmd)
9335{
9336 const char *dev_role = get_param(cmd, "DevRole");
9337
9338 if (!dev_role) {
9339 send_resp(dut, conn, SIGMA_INVALID,
9340 "ErrorCode,DevRole not specified");
9341 return 0;
9342 }
9343
9344 if (strcasecmp(dev_role, "PCP") == 0)
9345 return sta_set_60g_pcp(dut, conn, cmd);
9346 if (strcasecmp(dev_role, "STA") == 0)
9347 return sta_set_60g_sta(dut, conn, cmd);
9348 send_resp(dut, conn, SIGMA_INVALID,
9349 "ErrorCode,DevRole not supported");
9350 return 0;
9351}
9352
9353
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309354static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
9355 struct sigma_cmd *cmd)
9356{
9357 int status;
9358 const char *intf = get_param(cmd, "Interface");
9359 const char *val = get_param(cmd, "DevRole");
9360
9361 if (val && strcasecmp(val, "STA-CFON") == 0) {
9362 status = sta_cfon_set_wireless(dut, conn, cmd);
9363 if (status)
9364 return status;
9365 }
9366 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9367}
9368
9369
Jouni Malinen67433fc2020-06-26 22:50:33 +03009370static enum sigma_cmd_result
9371sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
9372 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309373{
9374 const char *intf = get_param(cmd, "Interface");
9375 const char *val;
9376
9377 val = get_param(cmd, "ocvc");
9378 if (val)
9379 dut->ocvc = atoi(val);
9380
Jouni Malinen67433fc2020-06-26 22:50:33 +03009381 val = get_param(cmd, "ClientPrivacy");
9382 if (val) {
9383 dut->client_privacy = atoi(val);
9384 if (dut->client_privacy &&
9385 (wpa_command(intf, "SET mac_addr 1") < 0 ||
9386 wpa_command(intf, "SET rand_addr_lifetime 1") < 0 ||
9387 wpa_command(intf, "SET preassoc_mac_addr 1") < 0 ||
9388 wpa_command(intf, "SET gas_rand_mac_addr 1") < 0 ||
9389 wpa_command(intf, "SET gas_rand_addr_lifetime 1") < 0)) {
9390 send_resp(dut, conn, SIGMA_ERROR,
9391 "errorCode,Failed to enable random MAC address use");
9392 return STATUS_SENT_ERROR;
9393 }
9394 }
9395
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309396 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9397}
9398
9399
Jouni Malinenf7222712019-06-13 01:50:21 +03009400static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
9401 struct sigma_conn *conn,
9402 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009403{
9404 const char *val;
9405
9406 val = get_param(cmd, "Program");
9407 if (val) {
9408 if (strcasecmp(val, "11n") == 0)
9409 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08009410 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009411 return cmd_sta_set_wireless_vht(dut, conn, cmd);
9412 if (strcasecmp(val, "60ghz") == 0)
9413 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309414 if (strcasecmp(val, "OCE") == 0)
9415 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02009416 /* sta_set_wireless in WPS program is only used for 60G */
9417 if (is_60g_sigma_dut(dut))
9418 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309419 if (strcasecmp(val, "WPA3") == 0)
9420 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009421 send_resp(dut, conn, SIGMA_ERROR,
9422 "ErrorCode,Program value not supported");
9423 } else {
9424 send_resp(dut, conn, SIGMA_ERROR,
9425 "ErrorCode,Program argument not available");
9426 }
9427
9428 return 0;
9429}
9430
9431
9432static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
9433 int tid)
9434{
9435 char buf[100];
9436 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
9437
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05309438 if (tid < 0 ||
9439 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
9440 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
9441 return;
9442 }
9443
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009444 /*
9445 * Two ways to ensure that addba request with a
9446 * non zero TID could be sent out. EV 117296
9447 */
9448 snprintf(buf, sizeof(buf),
9449 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
9450 tid);
9451 if (system(buf) != 0) {
9452 sigma_dut_print(dut, DUT_MSG_ERROR,
9453 "Ping did not send out");
9454 }
9455
9456 snprintf(buf, sizeof(buf),
9457 "iwconfig %s | grep Access | awk '{print $6}' > %s",
9458 intf, VI_QOS_TMP_FILE);
9459 if (system(buf) != 0)
9460 return;
9461
9462 snprintf(buf, sizeof(buf),
9463 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
9464 intf, VI_QOS_TMP_FILE);
9465 if (system(buf) != 0)
9466 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
9467
9468 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
9469 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
9470 if (system(buf) != 0) {
9471 sigma_dut_print(dut, DUT_MSG_ERROR,
9472 "VI_QOS_TEMP_FILE generation error failed");
9473 }
9474 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9475 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9476 if (system(buf) != 0) {
9477 sigma_dut_print(dut, DUT_MSG_ERROR,
9478 "VI_QOS_FILE generation failed");
9479 }
9480
9481 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9482 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9483 if (system(buf) != 0) {
9484 sigma_dut_print(dut, DUT_MSG_ERROR,
9485 "VI_QOS_FILE generation failed");
9486 }
9487
9488 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
9489 if (system(buf) != 0) {
9490 }
9491}
9492
9493
9494static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9495 struct sigma_cmd *cmd)
9496{
9497 const char *intf = get_param(cmd, "Interface");
9498 const char *val;
9499 int tid = 0;
9500 char buf[100];
9501
9502 val = get_param(cmd, "TID");
9503 if (val) {
9504 tid = atoi(val);
9505 if (tid)
9506 ath_sta_inject_frame(dut, intf, tid);
9507 }
9508
9509 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009510 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009511
9512 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
9513 if (system(buf) != 0) {
9514 sigma_dut_print(dut, DUT_MSG_ERROR,
9515 "wifitool senddelba failed");
9516 }
9517
9518 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
9519 if (system(buf) != 0) {
9520 sigma_dut_print(dut, DUT_MSG_ERROR,
9521 "wifitool sendaddba failed");
9522 }
9523
9524 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9525
9526 return 1;
9527}
9528
9529
Lior David9981b512017-01-20 13:16:40 +02009530#ifdef __linux__
9531
9532static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
9533 int agg_size)
9534{
9535 char dir[128], buf[128];
9536 FILE *f;
9537 regex_t re;
9538 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03009539 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02009540
9541 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
9542 sigma_dut_print(dut, DUT_MSG_ERROR,
9543 "failed to get wil6210 debugfs dir");
9544 return -1;
9545 }
9546
Jouni Malinen3aa72862019-05-29 23:14:51 +03009547 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
9548 if (res < 0 || res >= sizeof(buf))
9549 return -1;
Lior David9981b512017-01-20 13:16:40 +02009550 f = fopen(buf, "r");
9551 if (!f) {
9552 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009553 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009554 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9555 if (res < 0 || res >= sizeof(buf))
9556 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009557 f = fopen(buf, "r");
9558 if (!f) {
9559 sigma_dut_print(dut, DUT_MSG_ERROR,
9560 "failed to open: %s", buf);
9561 return -1;
9562 }
Lior David9981b512017-01-20 13:16:40 +02009563 }
9564
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009565 /* can be either VRING tx... or RING... */
9566 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009567 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9568 goto out;
9569 }
9570
9571 /* find TX VRING for the mac address */
9572 found = 0;
9573 while (fgets(buf, sizeof(buf), f)) {
9574 if (strcasestr(buf, dest_mac)) {
9575 found = 1;
9576 break;
9577 }
9578 }
9579
9580 if (!found) {
9581 sigma_dut_print(dut, DUT_MSG_ERROR,
9582 "no TX VRING for %s", dest_mac);
9583 goto out;
9584 }
9585
9586 /* extract VRING ID, "VRING tx_<id> = {" */
9587 if (!fgets(buf, sizeof(buf), f)) {
9588 sigma_dut_print(dut, DUT_MSG_ERROR,
9589 "no VRING start line for %s", dest_mac);
9590 goto out;
9591 }
9592
9593 rc = regexec(&re, buf, 2, m, 0);
9594 regfree(&re);
9595 if (rc || m[1].rm_so < 0) {
9596 sigma_dut_print(dut, DUT_MSG_ERROR,
9597 "no VRING TX ID for %s", dest_mac);
9598 goto out;
9599 }
9600 buf[m[1].rm_eo] = 0;
9601 vring_id = atoi(&buf[m[1].rm_so]);
9602
9603 /* send the addba command */
9604 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009605 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9606 if (res < 0 || res >= sizeof(buf))
9607 return -1;
Lior David9981b512017-01-20 13:16:40 +02009608 f = fopen(buf, "w");
9609 if (!f) {
9610 sigma_dut_print(dut, DUT_MSG_ERROR,
9611 "failed to open: %s", buf);
9612 return -1;
9613 }
9614
9615 fprintf(f, "add %d %d\n", vring_id, agg_size);
9616
9617 ret = 0;
9618
9619out:
9620 fclose(f);
9621
9622 return ret;
9623}
9624
9625
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009626int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9627 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009628{
9629 const char *val;
9630 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009631
9632 val = get_param(cmd, "TID");
9633 if (val) {
9634 tid = atoi(val);
9635 if (tid != 0) {
9636 sigma_dut_print(dut, DUT_MSG_ERROR,
9637 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9638 tid);
9639 }
9640 }
9641
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009642 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009643 if (!val) {
9644 sigma_dut_print(dut, DUT_MSG_ERROR,
9645 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009646 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009647 }
9648
Lior David9981b512017-01-20 13:16:40 +02009649 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009650 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009651
9652 return 1;
9653}
9654
Lior David9981b512017-01-20 13:16:40 +02009655#endif /* __linux__ */
9656
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009657
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009658static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9659 struct sigma_cmd *cmd)
9660{
9661#ifdef NL80211_SUPPORT
9662 const char *intf = get_param(cmd, "Interface");
9663 const char *val;
9664 int tid = -1;
9665 int bufsize = 64;
9666 struct nl_msg *msg;
9667 int ret = 0;
9668 struct nlattr *params;
9669 int ifindex;
9670
9671 val = get_param(cmd, "TID");
9672 if (val)
9673 tid = atoi(val);
9674
9675 if (tid == -1) {
9676 send_resp(dut, conn, SIGMA_ERROR,
9677 "ErrorCode,sta_send_addba tid invalid");
9678 return 0;
9679 }
9680
9681 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9682
9683 ifindex = if_nametoindex(intf);
9684 if (ifindex == 0) {
9685 sigma_dut_print(dut, DUT_MSG_ERROR,
9686 "%s: Index for interface %s failed",
9687 __func__, intf);
9688 send_resp(dut, conn, SIGMA_ERROR,
9689 "ErrorCode,sta_send_addba interface invalid");
9690 return 0;
9691 }
9692
9693 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9694 NL80211_CMD_VENDOR)) ||
9695 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9696 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9697 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9698 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9699 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9700 nla_put_u8(msg,
9701 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9702 QCA_WLAN_ADD_BA) ||
9703 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9704 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009705 nla_put_u16(msg,
9706 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9707 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009708 sigma_dut_print(dut, DUT_MSG_ERROR,
9709 "%s: err in adding vendor_cmd and vendor_data",
9710 __func__);
9711 nlmsg_free(msg);
9712 send_resp(dut, conn, SIGMA_ERROR,
9713 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9714 return 0;
9715 }
9716 nla_nest_end(msg, params);
9717
9718 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9719 if (ret) {
9720 sigma_dut_print(dut, DUT_MSG_ERROR,
9721 "%s: err in send_and_recv_msgs, ret=%d",
9722 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309723 if (ret == -EOPNOTSUPP)
9724 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009725 send_resp(dut, conn, SIGMA_ERROR,
9726 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9727 return 0;
9728 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009729#else /* NL80211_SUPPORT */
9730 sigma_dut_print(dut, DUT_MSG_ERROR,
9731 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009732#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309733
9734 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009735}
9736
9737
Jouni Malinenf7222712019-06-13 01:50:21 +03009738static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9739 struct sigma_conn *conn,
9740 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009741{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009742 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009743 case DRIVER_ATHEROS:
9744 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009745 case DRIVER_WCN:
9746 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009747#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009748 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009749 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009750#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009751 default:
9752 /*
9753 * There is no driver specific implementation for other drivers.
9754 * Ignore the command and report COMPLETE since the following
9755 * throughput test operation will end up sending ADDBA anyway.
9756 */
9757 return 1;
9758 }
9759}
9760
9761
9762int inject_eth_frame(int s, const void *data, size_t len,
9763 unsigned short ethtype, char *dst, char *src)
9764{
9765 struct iovec iov[4] = {
9766 {
9767 .iov_base = dst,
9768 .iov_len = ETH_ALEN,
9769 },
9770 {
9771 .iov_base = src,
9772 .iov_len = ETH_ALEN,
9773 },
9774 {
9775 .iov_base = &ethtype,
9776 .iov_len = sizeof(unsigned short),
9777 },
9778 {
9779 .iov_base = (void *) data,
9780 .iov_len = len,
9781 }
9782 };
9783 struct msghdr msg = {
9784 .msg_name = NULL,
9785 .msg_namelen = 0,
9786 .msg_iov = iov,
9787 .msg_iovlen = 4,
9788 .msg_control = NULL,
9789 .msg_controllen = 0,
9790 .msg_flags = 0,
9791 };
9792
9793 return sendmsg(s, &msg, 0);
9794}
9795
9796#if defined(__linux__) || defined(__QNXNTO__)
9797
9798int inject_frame(int s, const void *data, size_t len, int encrypt)
9799{
9800#define IEEE80211_RADIOTAP_F_WEP 0x04
9801#define IEEE80211_RADIOTAP_F_FRAG 0x08
9802 unsigned char rtap_hdr[] = {
9803 0x00, 0x00, /* radiotap version */
9804 0x0e, 0x00, /* radiotap length */
9805 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9806 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9807 0x00, /* padding */
9808 0x00, 0x00, /* RX and TX flags to indicate that */
9809 0x00, 0x00, /* this is the injected frame directly */
9810 };
9811 struct iovec iov[2] = {
9812 {
9813 .iov_base = &rtap_hdr,
9814 .iov_len = sizeof(rtap_hdr),
9815 },
9816 {
9817 .iov_base = (void *) data,
9818 .iov_len = len,
9819 }
9820 };
9821 struct msghdr msg = {
9822 .msg_name = NULL,
9823 .msg_namelen = 0,
9824 .msg_iov = iov,
9825 .msg_iovlen = 2,
9826 .msg_control = NULL,
9827 .msg_controllen = 0,
9828 .msg_flags = 0,
9829 };
9830
9831 if (encrypt)
9832 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9833
9834 return sendmsg(s, &msg, 0);
9835}
9836
9837
9838int open_monitor(const char *ifname)
9839{
9840#ifdef __QNXNTO__
9841 struct sockaddr_dl ll;
9842 int s;
9843
9844 memset(&ll, 0, sizeof(ll));
9845 ll.sdl_family = AF_LINK;
9846 ll.sdl_index = if_nametoindex(ifname);
9847 if (ll.sdl_index == 0) {
9848 perror("if_nametoindex");
9849 return -1;
9850 }
9851 s = socket(PF_INET, SOCK_RAW, 0);
9852#else /* __QNXNTO__ */
9853 struct sockaddr_ll ll;
9854 int s;
9855
9856 memset(&ll, 0, sizeof(ll));
9857 ll.sll_family = AF_PACKET;
9858 ll.sll_ifindex = if_nametoindex(ifname);
9859 if (ll.sll_ifindex == 0) {
9860 perror("if_nametoindex");
9861 return -1;
9862 }
9863 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9864#endif /* __QNXNTO__ */
9865 if (s < 0) {
9866 perror("socket[PF_PACKET,SOCK_RAW]");
9867 return -1;
9868 }
9869
9870 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9871 perror("monitor socket bind");
9872 close(s);
9873 return -1;
9874 }
9875
9876 return s;
9877}
9878
9879
9880static int hex2num(char c)
9881{
9882 if (c >= '0' && c <= '9')
9883 return c - '0';
9884 if (c >= 'a' && c <= 'f')
9885 return c - 'a' + 10;
9886 if (c >= 'A' && c <= 'F')
9887 return c - 'A' + 10;
9888 return -1;
9889}
9890
9891
9892int hwaddr_aton(const char *txt, unsigned char *addr)
9893{
9894 int i;
9895
9896 for (i = 0; i < 6; i++) {
9897 int a, b;
9898
9899 a = hex2num(*txt++);
9900 if (a < 0)
9901 return -1;
9902 b = hex2num(*txt++);
9903 if (b < 0)
9904 return -1;
9905 *addr++ = (a << 4) | b;
9906 if (i < 5 && *txt++ != ':')
9907 return -1;
9908 }
9909
9910 return 0;
9911}
9912
9913#endif /* defined(__linux__) || defined(__QNXNTO__) */
9914
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309915
9916#ifdef NL80211_SUPPORT
9917static int nl80211_send_frame_cmd(struct sigma_dut *dut, const char *intf,
9918 const u8 *data, size_t data_len, int freq)
9919{
9920 struct nl_msg *msg;
9921 int ret = 0;
9922 int ifindex;
9923
9924 ifindex = if_nametoindex(intf);
9925 if (ifindex == 0) {
9926 sigma_dut_print(dut, DUT_MSG_ERROR,
9927 "%s: Index for interface %s failed",
9928 __func__, intf);
9929 return -1;
9930 }
9931
9932 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9933 NL80211_CMD_FRAME)) ||
9934 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
9935 nla_put(msg, NL80211_ATTR_FRAME, data_len, data)) {
9936 sigma_dut_print(dut, DUT_MSG_ERROR,
9937 "%s: Error in adding NL80211_CMD_FRAME",
9938 __func__);
9939 nlmsg_free(msg);
9940 return -1;
9941 }
9942
9943 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9944 if (ret) {
9945 sigma_dut_print(dut, DUT_MSG_ERROR,
9946 "nl80211: Frame command failed: ret=%d (%s) req=%u",
9947 ret, strerror(-ret), freq);
9948 return -1;
9949 }
9950
9951 return 0;
9952}
9953#endif /* NL80211_SUPPORT */
9954
9955
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009956enum send_frame_type {
9957 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9958};
9959enum send_frame_protection {
9960 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9961};
9962
9963
9964static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309965 const char *intf, enum send_frame_type frame,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009966 enum send_frame_protection protected,
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309967 const char *dest, int use_monitor)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009968{
9969#ifdef __linux__
9970 unsigned char buf[1000], *pos;
9971 int s, res;
9972 char bssid[20], addr[20];
9973 char result[32], ssid[100];
9974 size_t ssid_len;
9975
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009976 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009977 sizeof(result)) < 0 ||
9978 strncmp(result, "COMPLETED", 9) != 0) {
9979 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9980 return 0;
9981 }
9982
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009983 if (get_wpa_status(get_station_ifname(dut), "bssid",
9984 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009985 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9986 "current BSSID");
9987 return 0;
9988 }
9989
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009990 if (get_wpa_status(get_station_ifname(dut), "address",
9991 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009992 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9993 "own MAC address");
9994 return 0;
9995 }
9996
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009997 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009998 < 0) {
9999 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
10000 "current SSID");
10001 return 0;
10002 }
10003 ssid_len = strlen(ssid);
10004
10005 pos = buf;
10006
10007 /* Frame Control */
10008 switch (frame) {
10009 case DISASSOC:
10010 *pos++ = 0xa0;
10011 break;
10012 case DEAUTH:
10013 *pos++ = 0xc0;
10014 break;
10015 case SAQUERY:
10016 *pos++ = 0xd0;
10017 break;
10018 case AUTH:
10019 *pos++ = 0xb0;
10020 break;
10021 case ASSOCREQ:
10022 *pos++ = 0x00;
10023 break;
10024 case REASSOCREQ:
10025 *pos++ = 0x20;
10026 break;
10027 case DLS_REQ:
10028 *pos++ = 0xd0;
10029 break;
10030 }
10031
10032 if (protected == INCORRECT_KEY)
10033 *pos++ = 0x40; /* Set Protected field to 1 */
10034 else
10035 *pos++ = 0x00;
10036
10037 /* Duration */
10038 *pos++ = 0x00;
10039 *pos++ = 0x00;
10040
10041 /* addr1 = DA (current AP) */
10042 hwaddr_aton(bssid, pos);
10043 pos += 6;
10044 /* addr2 = SA (own address) */
10045 hwaddr_aton(addr, pos);
10046 pos += 6;
10047 /* addr3 = BSSID (current AP) */
10048 hwaddr_aton(bssid, pos);
10049 pos += 6;
10050
10051 /* Seq# (to be filled by driver/mac80211) */
10052 *pos++ = 0x00;
10053 *pos++ = 0x00;
10054
10055 if (protected == INCORRECT_KEY) {
10056 /* CCMP parameters */
10057 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
10058 pos += 8;
10059 }
10060
10061 if (protected == INCORRECT_KEY) {
10062 switch (frame) {
10063 case DEAUTH:
10064 /* Reason code (encrypted) */
10065 memcpy(pos, "\xa7\x39", 2);
10066 pos += 2;
10067 break;
10068 case DISASSOC:
10069 /* Reason code (encrypted) */
10070 memcpy(pos, "\xa7\x39", 2);
10071 pos += 2;
10072 break;
10073 case SAQUERY:
10074 /* Category|Action|TransID (encrypted) */
10075 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
10076 pos += 4;
10077 break;
10078 default:
10079 return -1;
10080 }
10081
10082 /* CCMP MIC */
10083 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
10084 pos += 8;
10085 } else {
10086 switch (frame) {
10087 case DEAUTH:
10088 /* reason code = 8 */
10089 *pos++ = 0x08;
10090 *pos++ = 0x00;
10091 break;
10092 case DISASSOC:
10093 /* reason code = 8 */
10094 *pos++ = 0x08;
10095 *pos++ = 0x00;
10096 break;
10097 case SAQUERY:
10098 /* Category - SA Query */
10099 *pos++ = 0x08;
10100 /* SA query Action - Request */
10101 *pos++ = 0x00;
10102 /* Transaction ID */
10103 *pos++ = 0x12;
10104 *pos++ = 0x34;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053010105 if (dut->saquery_oci_freq) {
10106 /* OCI IE - Extended ID */
10107 *pos++ = 0xFF;
10108 *pos++ = 0x04;
10109 *pos++ = 0x36;
10110 /* Operating Class */
10111 *pos++ = 0x74;
10112 /* Primary Channel */
10113 *pos++ = freq_to_channel(dut->saquery_oci_freq);
10114 /* Frequency Segment 1 Channel Number */
10115 *pos++ = 0x00;
10116 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010117 break;
10118 case AUTH:
10119 /* Auth Alg (Open) */
10120 *pos++ = 0x00;
10121 *pos++ = 0x00;
10122 /* Seq# */
10123 *pos++ = 0x01;
10124 *pos++ = 0x00;
10125 /* Status code */
10126 *pos++ = 0x00;
10127 *pos++ = 0x00;
10128 break;
10129 case ASSOCREQ:
10130 /* Capability Information */
10131 *pos++ = 0x31;
10132 *pos++ = 0x04;
10133 /* Listen Interval */
10134 *pos++ = 0x0a;
10135 *pos++ = 0x00;
10136 /* SSID */
10137 *pos++ = 0x00;
10138 *pos++ = ssid_len;
10139 memcpy(pos, ssid, ssid_len);
10140 pos += ssid_len;
10141 /* Supported Rates */
10142 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
10143 10);
10144 pos += 10;
10145 /* Extended Supported Rates */
10146 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
10147 pos += 6;
10148 /* RSN */
10149 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
10150 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
10151 "\x00\x00\x00\x00\x0f\xac\x06", 28);
10152 pos += 28;
10153 break;
10154 case REASSOCREQ:
10155 /* Capability Information */
10156 *pos++ = 0x31;
10157 *pos++ = 0x04;
10158 /* Listen Interval */
10159 *pos++ = 0x0a;
10160 *pos++ = 0x00;
10161 /* Current AP */
10162 hwaddr_aton(bssid, pos);
10163 pos += 6;
10164 /* SSID */
10165 *pos++ = 0x00;
10166 *pos++ = ssid_len;
10167 memcpy(pos, ssid, ssid_len);
10168 pos += ssid_len;
10169 /* Supported Rates */
10170 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
10171 10);
10172 pos += 10;
10173 /* Extended Supported Rates */
10174 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
10175 pos += 6;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053010176 /* RSNE - Group and Pairwise ciphers */
10177 memcpy(pos,
10178 "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04",
10179 14);
10180 pos += 14;
10181 /* RSNE - AKM Suite count */
10182 *pos++ = 0x01;
10183 *pos++ = 0x00;
10184 /* RSNE - AKM Suites */
10185 if (dut->program == PROGRAM_WPA3)
10186 memcpy(pos, "\x00\x0f\xac\x08", 4);
10187 else
10188 memcpy(pos, "\x00\x0f\xac\x02", 4);
10189 pos += 4;
10190 /* RSNE - Capabilities */
10191 *pos++ = 0xc0;
10192 if (dut->ocvc)
10193 *pos++ = 0x40;
10194 else
10195 *pos++ = 0x00;
10196 /* RSNE - PMKID list and Group Management Ciphers */
10197 memcpy(pos, "\x00\x00\x00\x0f\xac\x06", 6);
10198 pos += 6;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010199 break;
10200 case DLS_REQ:
10201 /* Category - DLS */
10202 *pos++ = 0x02;
10203 /* DLS Action - Request */
10204 *pos++ = 0x00;
10205 /* Destination MACAddress */
10206 if (dest)
10207 hwaddr_aton(dest, pos);
10208 else
10209 memset(pos, 0, 6);
10210 pos += 6;
10211 /* Source MACAddress */
10212 hwaddr_aton(addr, pos);
10213 pos += 6;
10214 /* Capability Information */
10215 *pos++ = 0x10; /* Privacy */
10216 *pos++ = 0x06; /* QoS */
10217 /* DLS Timeout Value */
10218 *pos++ = 0x00;
10219 *pos++ = 0x01;
10220 /* Supported rates */
10221 *pos++ = 0x01;
10222 *pos++ = 0x08;
10223 *pos++ = 0x0c; /* 6 Mbps */
10224 *pos++ = 0x12; /* 9 Mbps */
10225 *pos++ = 0x18; /* 12 Mbps */
10226 *pos++ = 0x24; /* 18 Mbps */
10227 *pos++ = 0x30; /* 24 Mbps */
10228 *pos++ = 0x48; /* 36 Mbps */
10229 *pos++ = 0x60; /* 48 Mbps */
10230 *pos++ = 0x6c; /* 54 Mbps */
10231 /* TODO: Extended Supported Rates */
10232 /* TODO: HT Capabilities */
10233 break;
10234 }
10235 }
10236
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010237 if (use_monitor) {
10238 s = open_monitor("sigmadut");
10239 if (s < 0) {
10240 send_resp(dut, conn, SIGMA_ERROR,
10241 "errorCode,Failed to open monitor socket");
10242 return 0;
10243 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010244
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010245 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
10246 if (res < 0) {
10247 send_resp(dut, conn, SIGMA_ERROR,
10248 "errorCode,Failed to inject frame");
10249 close(s);
10250 return 0;
10251 }
10252 if (res < pos - buf) {
10253 send_resp(dut, conn, SIGMA_ERROR,
10254 "errorCode,Only partial frame sent");
10255 close(s);
10256 return 0;
10257 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010258
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010259 close(s);
10260 } else {
10261#ifdef NL80211_SUPPORT
10262 int freq;
10263 char freq_str[10];
10264
10265 if (get_wpa_status(get_station_ifname(dut), "freq",
10266 freq_str, sizeof(freq_str)) < 0) {
10267 send_resp(dut, conn, SIGMA_ERROR,
10268 "errorCode,Could not get current operating frequency");
10269 return 0;
10270 }
10271 freq = atoi(freq_str);
10272
10273 if (nl80211_send_frame_cmd(dut, intf, buf, pos - buf, freq)) {
10274 send_resp(dut, conn, SIGMA_ERROR,
10275 "errorCode,Failed to inject frame");
10276 return 0;
10277 }
10278#else /* NL80211_SUPPORT */
10279 send_resp(dut, conn, SIGMA_ERROR,
10280 "errorCode,Failed to inject frame (no NL80211_SUPPORT)");
10281 return 0;
10282#endif /* NL80211_SUPPORT */
10283 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010284
10285 return 1;
10286#else /* __linux__ */
10287 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
10288 "yet supported");
10289 return 0;
10290#endif /* __linux__ */
10291}
10292
10293
10294static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
10295 struct sigma_conn *conn,
10296 struct sigma_cmd *cmd)
10297{
10298 const char *intf = get_param(cmd, "Interface");
10299 const char *sta, *val;
10300 unsigned char addr[ETH_ALEN];
10301 char buf[100];
10302
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010303 if (!intf)
10304 return -1;
10305
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010306 sta = get_param(cmd, "peer");
10307 if (sta == NULL)
10308 sta = get_param(cmd, "station");
10309 if (sta == NULL) {
10310 send_resp(dut, conn, SIGMA_ERROR,
10311 "ErrorCode,Missing peer address");
10312 return 0;
10313 }
10314 if (hwaddr_aton(sta, addr) < 0) {
10315 send_resp(dut, conn, SIGMA_ERROR,
10316 "ErrorCode,Invalid peer address");
10317 return 0;
10318 }
10319
10320 val = get_param(cmd, "type");
10321 if (val == NULL)
10322 return -1;
10323
10324 if (strcasecmp(val, "DISCOVERY") == 0) {
10325 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
10326 if (wpa_command(intf, buf) < 0) {
10327 send_resp(dut, conn, SIGMA_ERROR,
10328 "ErrorCode,Failed to send TDLS discovery");
10329 return 0;
10330 }
10331 return 1;
10332 }
10333
10334 if (strcasecmp(val, "SETUP") == 0) {
10335 int status = 0, timeout = 0;
10336
10337 val = get_param(cmd, "Status");
10338 if (val)
10339 status = atoi(val);
10340
10341 val = get_param(cmd, "Timeout");
10342 if (val)
10343 timeout = atoi(val);
10344
10345 if (status != 0 && status != 37) {
10346 send_resp(dut, conn, SIGMA_ERROR,
10347 "ErrorCode,Unsupported status value");
10348 return 0;
10349 }
10350
10351 if (timeout != 0 && timeout != 301) {
10352 send_resp(dut, conn, SIGMA_ERROR,
10353 "ErrorCode,Unsupported timeout value");
10354 return 0;
10355 }
10356
10357 if (status && timeout) {
10358 send_resp(dut, conn, SIGMA_ERROR,
10359 "ErrorCode,Unsupported timeout+status "
10360 "combination");
10361 return 0;
10362 }
10363
10364 if (status == 37 &&
10365 wpa_command(intf, "SET tdls_testing 0x200")) {
10366 send_resp(dut, conn, SIGMA_ERROR,
10367 "ErrorCode,Failed to enable "
10368 "decline setup response test mode");
10369 return 0;
10370 }
10371
10372 if (timeout == 301) {
10373 int res;
10374 if (dut->no_tpk_expiration)
10375 res = wpa_command(intf,
10376 "SET tdls_testing 0x108");
10377 else
10378 res = wpa_command(intf,
10379 "SET tdls_testing 0x8");
10380 if (res) {
10381 send_resp(dut, conn, SIGMA_ERROR,
10382 "ErrorCode,Failed to set short TPK "
10383 "lifetime");
10384 return 0;
10385 }
10386 }
10387
10388 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
10389 if (wpa_command(intf, buf) < 0) {
10390 send_resp(dut, conn, SIGMA_ERROR,
10391 "ErrorCode,Failed to send TDLS setup");
10392 return 0;
10393 }
10394 return 1;
10395 }
10396
10397 if (strcasecmp(val, "TEARDOWN") == 0) {
10398 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
10399 if (wpa_command(intf, buf) < 0) {
10400 send_resp(dut, conn, SIGMA_ERROR,
10401 "ErrorCode,Failed to send TDLS teardown");
10402 return 0;
10403 }
10404 return 1;
10405 }
10406
10407 send_resp(dut, conn, SIGMA_ERROR,
10408 "ErrorCode,Unsupported TDLS frame");
10409 return 0;
10410}
10411
10412
10413static int sta_ap_known(const char *ifname, const char *bssid)
10414{
10415 char buf[4096];
10416
Jouni Malinendd32f192018-09-15 02:55:19 +030010417 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010418 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
10419 return 0;
10420 if (strncmp(buf, "id=", 3) != 0)
10421 return 0;
10422 return 1;
10423}
10424
10425
10426static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
10427 const char *bssid)
10428{
10429 int res;
10430 struct wpa_ctrl *ctrl;
10431 char buf[256];
10432
10433 if (sta_ap_known(ifname, bssid))
10434 return 0;
10435 sigma_dut_print(dut, DUT_MSG_DEBUG,
10436 "AP not in BSS table - start scan");
10437
10438 ctrl = open_wpa_mon(ifname);
10439 if (ctrl == NULL) {
10440 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10441 "wpa_supplicant monitor connection");
10442 return -1;
10443 }
10444
10445 if (wpa_command(ifname, "SCAN") < 0) {
10446 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
10447 wpa_ctrl_detach(ctrl);
10448 wpa_ctrl_close(ctrl);
10449 return -1;
10450 }
10451
10452 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
10453 buf, sizeof(buf));
10454
10455 wpa_ctrl_detach(ctrl);
10456 wpa_ctrl_close(ctrl);
10457
10458 if (res < 0) {
10459 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
10460 return -1;
10461 }
10462
10463 if (sta_ap_known(ifname, bssid))
10464 return 0;
10465 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
10466 return -1;
10467}
10468
10469
10470static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
10471 struct sigma_conn *conn,
10472 struct sigma_cmd *cmd,
10473 const char *intf)
10474{
10475 char buf[200];
10476
10477 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
10478 if (system(buf) != 0) {
10479 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
10480 "ndsend");
10481 return 0;
10482 }
10483
10484 return 1;
10485}
10486
10487
10488static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
10489 struct sigma_conn *conn,
10490 struct sigma_cmd *cmd,
10491 const char *intf)
10492{
10493 char buf[200];
10494 const char *ip = get_param(cmd, "SenderIP");
10495
Peng Xu26b356d2017-10-04 17:58:16 -070010496 if (!ip)
10497 return 0;
10498
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010499 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
10500 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10501 if (system(buf) == 0) {
10502 sigma_dut_print(dut, DUT_MSG_INFO,
10503 "Neighbor Solicitation got a response "
10504 "for %s@%s", ip, intf);
10505 }
10506
10507 return 1;
10508}
10509
10510
10511static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
10512 struct sigma_conn *conn,
10513 struct sigma_cmd *cmd,
10514 const char *ifname)
10515{
10516 char buf[200];
10517 const char *ip = get_param(cmd, "SenderIP");
10518
10519 if (ip == NULL) {
10520 send_resp(dut, conn, SIGMA_ERROR,
10521 "ErrorCode,Missing SenderIP parameter");
10522 return 0;
10523 }
10524 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
10525 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10526 if (system(buf) != 0) {
10527 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
10528 "for %s@%s", ip, ifname);
10529 }
10530
10531 return 1;
10532}
10533
10534
10535static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
10536 struct sigma_conn *conn,
10537 struct sigma_cmd *cmd,
10538 const char *ifname)
10539{
10540 char buf[200];
10541 char ip[16];
10542 int s;
Peng Xub3756882017-10-04 14:39:09 -070010543 struct ifreq ifr;
10544 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010545
10546 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070010547 if (s < 0) {
10548 perror("socket");
10549 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010550 }
10551
Peng Xub3756882017-10-04 14:39:09 -070010552 memset(&ifr, 0, sizeof(ifr));
10553 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
10554 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
10555 sigma_dut_print(dut, DUT_MSG_INFO,
10556 "Failed to get %s IP address: %s",
10557 ifname, strerror(errno));
10558 close(s);
10559 return -1;
10560 }
10561 close(s);
10562
10563 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
10564 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
10565
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010566 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
10567 ip);
10568 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10569 if (system(buf) != 0) {
10570 }
10571
10572 return 1;
10573}
10574
10575
10576static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
10577 struct sigma_conn *conn,
10578 struct sigma_cmd *cmd,
10579 const char *ifname)
10580{
10581 char buf[200], addr[20];
10582 char dst[ETH_ALEN], src[ETH_ALEN];
10583 short ethtype = htons(ETH_P_ARP);
10584 char *pos;
10585 int s, res;
10586 const char *val;
10587 struct sockaddr_in taddr;
10588
10589 val = get_param(cmd, "dest");
10590 if (val)
10591 hwaddr_aton(val, (unsigned char *) dst);
10592
10593 val = get_param(cmd, "DestIP");
10594 if (val)
10595 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070010596 else
10597 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010598
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010599 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010600 sizeof(addr)) < 0)
10601 return -2;
10602 hwaddr_aton(addr, (unsigned char *) src);
10603
10604 pos = buf;
10605 *pos++ = 0x00;
10606 *pos++ = 0x01;
10607 *pos++ = 0x08;
10608 *pos++ = 0x00;
10609 *pos++ = 0x06;
10610 *pos++ = 0x04;
10611 *pos++ = 0x00;
10612 *pos++ = 0x02;
10613 memcpy(pos, src, ETH_ALEN);
10614 pos += ETH_ALEN;
10615 memcpy(pos, &taddr.sin_addr, 4);
10616 pos += 4;
10617 memcpy(pos, dst, ETH_ALEN);
10618 pos += ETH_ALEN;
10619 memcpy(pos, &taddr.sin_addr, 4);
10620 pos += 4;
10621
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010622 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010623 if (s < 0) {
10624 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
10625 "monitor socket");
10626 return 0;
10627 }
10628
10629 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
10630 if (res < 0) {
10631 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
10632 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053010633 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010634 return 0;
10635 }
10636
10637 close(s);
10638
10639 return 1;
10640}
10641
10642
10643static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
10644 struct sigma_conn *conn,
10645 struct sigma_cmd *cmd,
10646 const char *intf, const char *dest)
10647{
10648 char buf[100];
10649
10650 if (if_nametoindex("sigmadut") == 0) {
10651 snprintf(buf, sizeof(buf),
10652 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010653 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010654 if (system(buf) != 0 ||
10655 if_nametoindex("sigmadut") == 0) {
10656 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10657 "monitor interface with '%s'", buf);
10658 return -2;
10659 }
10660 }
10661
10662 if (system("ifconfig sigmadut up") != 0) {
10663 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10664 "monitor interface up");
10665 return -2;
10666 }
10667
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010668 return sta_inject_frame(dut, conn, intf, DLS_REQ, UNPROTECTED, dest, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010669}
10670
10671
10672static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10673 struct sigma_conn *conn,
10674 struct sigma_cmd *cmd)
10675{
10676 const char *intf = get_param(cmd, "Interface");
10677 const char *dest = get_param(cmd, "Dest");
10678 const char *type = get_param(cmd, "FrameName");
10679 const char *val;
10680 char buf[200], *pos, *end;
10681 int count, count2;
10682
10683 if (type == NULL)
10684 type = get_param(cmd, "Type");
10685
10686 if (intf == NULL || dest == NULL || type == NULL)
10687 return -1;
10688
10689 if (strcasecmp(type, "NeighAdv") == 0)
10690 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10691
10692 if (strcasecmp(type, "NeighSolicitReq") == 0)
10693 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10694
10695 if (strcasecmp(type, "ARPProbe") == 0)
10696 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10697
10698 if (strcasecmp(type, "ARPAnnounce") == 0)
10699 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10700
10701 if (strcasecmp(type, "ARPReply") == 0)
10702 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10703
10704 if (strcasecmp(type, "DLS-request") == 0 ||
10705 strcasecmp(type, "DLSrequest") == 0)
10706 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10707 dest);
10708
10709 if (strcasecmp(type, "ANQPQuery") != 0 &&
10710 strcasecmp(type, "Query") != 0) {
10711 send_resp(dut, conn, SIGMA_ERROR,
10712 "ErrorCode,Unsupported HS 2.0 send frame type");
10713 return 0;
10714 }
10715
10716 if (sta_scan_ap(dut, intf, dest) < 0) {
10717 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10718 "the requested AP");
10719 return 0;
10720 }
10721
10722 pos = buf;
10723 end = buf + sizeof(buf);
10724 count = 0;
10725 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10726
10727 val = get_param(cmd, "ANQP_CAP_LIST");
10728 if (val && atoi(val)) {
10729 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10730 count++;
10731 }
10732
10733 val = get_param(cmd, "VENUE_NAME");
10734 if (val && atoi(val)) {
10735 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10736 count++;
10737 }
10738
10739 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10740 if (val && atoi(val)) {
10741 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10742 count++;
10743 }
10744
10745 val = get_param(cmd, "ROAMING_CONS");
10746 if (val && atoi(val)) {
10747 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10748 count++;
10749 }
10750
10751 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10752 if (val && atoi(val)) {
10753 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10754 count++;
10755 }
10756
10757 val = get_param(cmd, "NAI_REALM_LIST");
10758 if (val && atoi(val)) {
10759 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10760 count++;
10761 }
10762
10763 val = get_param(cmd, "3GPP_INFO");
10764 if (val && atoi(val)) {
10765 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10766 count++;
10767 }
10768
10769 val = get_param(cmd, "DOMAIN_LIST");
10770 if (val && atoi(val)) {
10771 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10772 count++;
10773 }
10774
Jouni Malinen34cf9532018-04-29 19:26:33 +030010775 val = get_param(cmd, "Venue_URL");
10776 if (val && atoi(val)) {
10777 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10778 count++;
10779 }
10780
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010781 val = get_param(cmd, "Advice_Of_Charge");
10782 if (val && atoi(val)) {
10783 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10784 count++;
10785 }
10786
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010787 if (count && wpa_command(intf, buf)) {
10788 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10789 return 0;
10790 }
10791
10792 pos = buf;
10793 end = buf + sizeof(buf);
10794 count2 = 0;
10795 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
10796
10797 val = get_param(cmd, "HS_CAP_LIST");
10798 if (val && atoi(val)) {
10799 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
10800 count2++;
10801 }
10802
10803 val = get_param(cmd, "OPER_NAME");
10804 if (val && atoi(val)) {
10805 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
10806 count2++;
10807 }
10808
10809 val = get_param(cmd, "WAN_METRICS");
10810 if (!val)
10811 val = get_param(cmd, "WAN_MAT");
10812 if (!val)
10813 val = get_param(cmd, "WAN_MET");
10814 if (val && atoi(val)) {
10815 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10816 count2++;
10817 }
10818
10819 val = get_param(cmd, "CONNECTION_CAPABILITY");
10820 if (val && atoi(val)) {
10821 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10822 count2++;
10823 }
10824
10825 val = get_param(cmd, "OP_CLASS");
10826 if (val && atoi(val)) {
10827 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10828 count2++;
10829 }
10830
10831 val = get_param(cmd, "OSU_PROVIDER_LIST");
10832 if (val && atoi(val)) {
10833 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10834 count2++;
10835 }
10836
Jouni Malinenf67afec2018-04-29 19:24:58 +030010837 val = get_param(cmd, "OPER_ICON_METADATA");
10838 if (!val)
10839 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10840 if (val && atoi(val)) {
10841 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10842 count2++;
10843 }
10844
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010845 if (count && count2) {
10846 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10847 "second query");
10848 sleep(1);
10849 }
10850
10851 if (count2 && wpa_command(intf, buf)) {
10852 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10853 "failed");
10854 return 0;
10855 }
10856
10857 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10858 if (val) {
10859 if (count || count2) {
10860 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10861 "sending out second query");
10862 sleep(1);
10863 }
10864
10865 if (strcmp(val, "1") == 0)
10866 val = "mail.example.com";
10867 snprintf(buf, end - pos,
10868 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10869 dest, val);
10870 if (wpa_command(intf, buf)) {
10871 send_resp(dut, conn, SIGMA_ERROR,
10872 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10873 "failed");
10874 return 0;
10875 }
10876 }
10877
10878 val = get_param(cmd, "ICON_REQUEST");
10879 if (val) {
10880 if (count || count2) {
10881 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10882 "sending out second query");
10883 sleep(1);
10884 }
10885
10886 snprintf(buf, end - pos,
10887 "HS20_ICON_REQUEST %s %s", dest, val);
10888 if (wpa_command(intf, buf)) {
10889 send_resp(dut, conn, SIGMA_ERROR,
10890 "ErrorCode,HS20_ICON_REQUEST failed");
10891 return 0;
10892 }
10893 }
10894
10895 return 1;
10896}
10897
10898
10899static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10900 struct sigma_conn *conn,
10901 struct sigma_cmd *cmd)
10902{
10903 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010904 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010905 int chwidth, nss;
10906
10907 val = get_param(cmd, "framename");
10908 if (!val)
10909 return -1;
10910 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10911
10912 /* Command sequence to generate Op mode notification */
10913 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010914 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010915
10916 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010917 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010918
10919 /* Extract Channel width */
10920 val = get_param(cmd, "Channel_width");
10921 if (val) {
10922 switch (atoi(val)) {
10923 case 20:
10924 chwidth = 0;
10925 break;
10926 case 40:
10927 chwidth = 1;
10928 break;
10929 case 80:
10930 chwidth = 2;
10931 break;
10932 case 160:
10933 chwidth = 3;
10934 break;
10935 default:
10936 chwidth = 2;
10937 break;
10938 }
10939
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010940 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010941 }
10942
10943 /* Extract NSS */
10944 val = get_param(cmd, "NSS");
10945 if (val) {
10946 switch (atoi(val)) {
10947 case 1:
10948 nss = 1;
10949 break;
10950 case 2:
10951 nss = 3;
10952 break;
10953 case 3:
10954 nss = 7;
10955 break;
10956 default:
10957 /* We do not support NSS > 3 */
10958 nss = 3;
10959 break;
10960 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010961 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010962 }
10963
10964 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010965 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010966 }
10967
10968 return 1;
10969}
10970
10971
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010972static int wcn_sta_set_pmf_config(struct sigma_dut *dut, const char *intf,
10973 enum send_frame_protection protected)
10974{
10975#ifdef NL80211_SUPPORT
10976 struct nl_msg *msg;
10977 int ret = 0;
10978 struct nlattr *params;
10979 int ifindex;
10980
10981 ifindex = if_nametoindex(intf);
10982 if (ifindex == 0) {
10983 sigma_dut_print(dut, DUT_MSG_ERROR,
10984 "%s: Index for interface %s failed",
10985 __func__, intf);
10986 return -1;
10987 }
10988
10989 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10990 NL80211_CMD_VENDOR)) ||
10991 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
10992 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10993 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10994 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
10995 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10996 nla_put_u8(msg,
10997 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PMF_PROTECTION,
10998 protected)) {
10999 sigma_dut_print(dut, DUT_MSG_ERROR,
11000 "%s: err in adding vendor_cmd and vendor_data",
11001 __func__);
11002 nlmsg_free(msg);
11003 return -1;
11004 }
11005 nla_nest_end(msg, params);
11006
11007 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
11008 if (ret) {
11009 sigma_dut_print(dut, DUT_MSG_ERROR,
11010 "%s: err in send_and_recv_msgs, ret=%d",
11011 __func__, ret);
11012 }
11013 return ret;
11014#else /* NL80211_SUPPORT */
11015 sigma_dut_print(dut, DUT_MSG_ERROR,
11016 "PMF config cannot be set without NL80211_SUPPORT defined");
11017 return -1;
11018#endif /* NL80211_SUPPORT */
11019}
11020
11021
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011022static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
11023 struct sigma_conn *conn,
11024 struct sigma_cmd *cmd)
11025{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011026 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011027 case DRIVER_ATHEROS:
11028 return ath_sta_send_frame_vht(dut, conn, cmd);
11029 default:
11030 send_resp(dut, conn, SIGMA_ERROR,
11031 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
11032 return 0;
11033 }
11034}
11035
11036
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011037static int wcn_sta_send_disassoc(struct sigma_dut *dut, const char *intf)
11038{
11039#ifdef NL80211_SUPPORT
11040 struct nl_msg *msg;
11041 int ret = 0;
11042 struct nlattr *params;
11043 int ifindex;
11044
11045 ifindex = if_nametoindex(intf);
11046 if (ifindex == 0) {
11047 sigma_dut_print(dut, DUT_MSG_ERROR,
11048 "%s: Index for interface %s failed",
11049 __func__, intf);
11050 return -1;
11051 }
11052
11053 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
11054 NL80211_CMD_VENDOR)) ||
11055 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
11056 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
11057 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
11058 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
11059 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
11060 nla_put_flag(msg,
11061 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISASSOC_TX)) {
11062 sigma_dut_print(dut, DUT_MSG_ERROR,
11063 "%s: err in adding vendor_cmd and vendor_data",
11064 __func__);
11065 nlmsg_free(msg);
11066 return -1;
11067 }
11068 nla_nest_end(msg, params);
11069
11070 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
11071 if (ret) {
11072 sigma_dut_print(dut, DUT_MSG_ERROR,
11073 "%s: err in send_and_recv_msgs, ret=%d",
11074 __func__, ret);
11075 }
11076 return ret;
11077#else /* NL80211_SUPPORT */
11078 sigma_dut_print(dut, DUT_MSG_ERROR,
11079 "Disassoc Tx cannot be done without NL80211_SUPPORT defined");
11080 return -1;
11081#endif /* NL80211_SUPPORT */
11082}
11083
11084
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011085static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
11086 struct sigma_cmd *cmd)
11087{
11088 const char *val;
11089 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011090 enum send_frame_protection protected;
11091 const char *pmf;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011092
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011093 if (!intf)
11094 return -1;
11095
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011096 val = get_param(cmd, "framename");
11097 if (!val)
11098 return -1;
11099 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
11100
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011101 pmf = get_param(cmd, "PMFProtected");
11102 if (!pmf)
11103 pmf = get_param(cmd, "Protected");
11104 if (pmf) {
11105 if (strcasecmp(pmf, "Correct-key") == 0 ||
11106 strcasecmp(pmf, "CorrectKey") == 0) {
11107 protected = CORRECT_KEY;
11108 } else if (strcasecmp(pmf, "IncorrectKey") == 0) {
11109 protected = INCORRECT_KEY;
11110 } else if (strcasecmp(pmf, "Unprotected") == 0) {
11111 protected = UNPROTECTED;
11112 } else {
11113 send_resp(dut, conn, SIGMA_ERROR,
11114 "errorCode,Unsupported PMFProtected");
11115 return STATUS_SENT_ERROR;
11116 }
11117 sigma_dut_print(dut, DUT_MSG_DEBUG, "Config PMF protection %d",
11118 protected);
11119 wcn_sta_set_pmf_config(dut, intf, protected);
11120 }
11121
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011122 /* Command sequence to generate Op mode notification */
11123 if (val && strcasecmp(val, "action") == 0) {
11124 val = get_param(cmd, "PPDUTxType");
11125 if (val && strcasecmp(val, "TB") == 0) {
11126 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
11127 sigma_dut_print(dut, DUT_MSG_ERROR,
11128 "failed to send TB PPDU Tx cfg");
11129 send_resp(dut, conn, SIGMA_ERROR,
11130 "ErrorCode,set TB PPDU Tx cfg failed");
11131 return 0;
11132 }
11133 return 1;
11134 }
11135
11136 sigma_dut_print(dut, DUT_MSG_ERROR,
11137 "Action Tx type is not defined");
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011138
11139 return SUCCESS_SEND_STATUS;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011140 }
11141
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011142 if (strcasecmp(val, "disassoc") == 0)
11143 wcn_sta_send_disassoc(dut, intf);
11144
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011145 return 1;
11146}
11147
11148
11149static int cmd_sta_send_frame_he(struct sigma_dut *dut,
11150 struct sigma_conn *conn,
11151 struct sigma_cmd *cmd)
11152{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011153 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011154 case DRIVER_WCN:
11155 return wcn_sta_send_frame_he(dut, conn, cmd);
11156 default:
11157 send_resp(dut, conn, SIGMA_ERROR,
11158 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
11159 return 0;
11160 }
11161}
11162
11163
Lior David0fe101e2017-03-09 16:09:50 +020011164#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011165
11166static int
11167wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
11168 const char *frame_name, const char *dest_mac)
11169{
11170 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
11171 const char *ssid = get_param(cmd, "ssid");
11172 const char *countstr = get_param(cmd, "count");
11173 const char *channelstr = get_param(cmd, "channel");
11174 const char *group_id = get_param(cmd, "groupid");
11175 const char *client_id = get_param(cmd, "clientmac");
11176 int count, channel, freq, i;
11177 const char *fname;
11178 char frame[1024], src_mac[20], group_id_attr[25],
11179 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
11180 const char *group_ssid;
11181 const int group_ssid_prefix_len = 9;
11182 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
11183 size_t framelen = sizeof(frame);
11184 struct template_frame_tag tags[2];
11185 size_t tags_total = ARRAY_SIZE(tags);
11186 int tag_index, len, dst_len;
11187
11188 if (!countstr || !channelstr) {
11189 sigma_dut_print(dut, DUT_MSG_ERROR,
11190 "Missing argument: count, channel");
11191 return -1;
11192 }
11193 if (isprobereq && !ssid) {
11194 sigma_dut_print(dut, DUT_MSG_ERROR,
11195 "Missing argument: ssid");
11196 return -1;
11197 }
11198 if (!isprobereq && (!group_id || !client_id)) {
11199 sigma_dut_print(dut, DUT_MSG_ERROR,
11200 "Missing argument: group_id, client_id");
11201 return -1;
11202 }
11203
11204 count = atoi(countstr);
11205 channel = atoi(channelstr);
11206 freq = channel_to_freq(dut, channel);
11207
11208 if (!freq) {
11209 sigma_dut_print(dut, DUT_MSG_ERROR,
11210 "invalid channel: %s", channelstr);
11211 return -1;
11212 }
11213
11214 if (isprobereq) {
11215 if (strcasecmp(ssid, "wildcard") == 0) {
11216 fname = "probe_req_wildcard.txt";
11217 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
11218 fname = "probe_req_P2P_Wildcard.txt";
11219 } else {
11220 sigma_dut_print(dut, DUT_MSG_ERROR,
11221 "invalid probe request type");
11222 return -1;
11223 }
11224 } else {
11225 fname = "P2P_device_discovery_req.txt";
11226 }
11227
11228 if (parse_template_frame_file(dut, fname, frame, &framelen,
11229 tags, &tags_total)) {
11230 sigma_dut_print(dut, DUT_MSG_ERROR,
11231 "invalid frame template: %s", fname);
11232 return -1;
11233 }
11234
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011235 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011236 src_mac, sizeof(src_mac)) < 0 ||
11237 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
11238 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
11239 return -1;
11240 /* Use wildcard BSSID, since we are in PBSS */
11241 memset(&hdr->addr3, 0xFF, ETH_ALEN);
11242
11243 if (!isprobereq) {
11244 tag_index = find_template_frame_tag(tags, tags_total, 1);
11245 if (tag_index < 0) {
11246 sigma_dut_print(dut, DUT_MSG_ERROR,
11247 "can't find device id attribute");
11248 return -1;
11249 }
11250 if (parse_mac_address(dut, client_id,
11251 (unsigned char *) client_mac)) {
11252 sigma_dut_print(dut, DUT_MSG_ERROR,
11253 "invalid client_id: %s", client_id);
11254 return -1;
11255 }
11256 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11257 framelen - tags[tag_index].offset,
11258 IEEE80211_P2P_ATTR_DEVICE_ID,
11259 client_mac, ETH_ALEN)) {
11260 sigma_dut_print(dut, DUT_MSG_ERROR,
11261 "fail to replace device id attribute");
11262 return -1;
11263 }
11264
11265 /*
11266 * group_id arg contains device MAC address followed by
11267 * space and SSID (DIRECT-somessid).
11268 * group id attribute contains device address (6 bytes)
11269 * followed by SSID prefix DIRECT-XX (9 bytes)
11270 */
11271 if (strlen(group_id) < sizeof(device_macstr)) {
11272 sigma_dut_print(dut, DUT_MSG_ERROR,
11273 "group_id arg too short");
11274 return -1;
11275 }
11276 memcpy(device_macstr, group_id, sizeof(device_macstr));
11277 device_macstr[sizeof(device_macstr) - 1] = '\0';
11278 if (parse_mac_address(dut, device_macstr,
11279 (unsigned char *) group_id_attr)) {
11280 sigma_dut_print(dut, DUT_MSG_ERROR,
11281 "fail to parse device address from group_id");
11282 return -1;
11283 }
11284 group_ssid = strchr(group_id, ' ');
11285 if (!group_ssid) {
11286 sigma_dut_print(dut, DUT_MSG_ERROR,
11287 "invalid group_id arg, no ssid");
11288 return -1;
11289 }
11290 group_ssid++;
11291 len = strlen(group_ssid);
11292 if (len < group_ssid_prefix_len) {
11293 sigma_dut_print(dut, DUT_MSG_ERROR,
11294 "group_id SSID too short");
11295 return -1;
11296 }
11297 dst_len = sizeof(group_id_attr) - ETH_ALEN;
11298 if (len > dst_len) {
11299 sigma_dut_print(dut, DUT_MSG_ERROR,
11300 "group_id SSID (%s) too long",
11301 group_ssid);
11302 return -1;
11303 }
11304
11305 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
11306 tag_index = find_template_frame_tag(tags, tags_total, 2);
11307 if (tag_index < 0) {
11308 sigma_dut_print(dut, DUT_MSG_ERROR,
11309 "can't find group id attribute");
11310 return -1;
11311 }
11312 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11313 framelen - tags[tag_index].offset,
11314 IEEE80211_P2P_ATTR_GROUP_ID,
11315 group_id_attr,
11316 sizeof(group_id_attr))) {
11317 sigma_dut_print(dut, DUT_MSG_ERROR,
11318 "fail to replace group id attribute");
11319 return -1;
11320 }
11321 }
11322
11323 for (i = 0; i < count; i++) {
11324 if (wil6210_transmit_frame(dut, freq,
11325 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
11326 frame, framelen)) {
11327 sigma_dut_print(dut, DUT_MSG_ERROR,
11328 "fail to transmit probe request frame");
11329 return -1;
11330 }
11331 }
11332
11333 return 0;
11334}
11335
11336
Lior David0fe101e2017-03-09 16:09:50 +020011337int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
11338 struct sigma_cmd *cmd)
11339{
11340 const char *frame_name = get_param(cmd, "framename");
11341 const char *mac = get_param(cmd, "dest_mac");
11342
11343 if (!frame_name || !mac) {
11344 sigma_dut_print(dut, DUT_MSG_ERROR,
11345 "framename and dest_mac must be provided");
11346 return -1;
11347 }
11348
11349 if (strcasecmp(frame_name, "brp") == 0) {
11350 const char *l_rx = get_param(cmd, "L-RX");
11351 int l_rx_i;
11352
11353 if (!l_rx) {
11354 sigma_dut_print(dut, DUT_MSG_ERROR,
11355 "L-RX must be provided");
11356 return -1;
11357 }
11358 l_rx_i = atoi(l_rx);
11359
11360 sigma_dut_print(dut, DUT_MSG_INFO,
11361 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
11362 mac, l_rx);
11363 if (l_rx_i != 16) {
11364 sigma_dut_print(dut, DUT_MSG_ERROR,
11365 "unsupported L-RX: %s", l_rx);
11366 return -1;
11367 }
11368
11369 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
11370 return -1;
11371 } else if (strcasecmp(frame_name, "ssw") == 0) {
11372 sigma_dut_print(dut, DUT_MSG_INFO,
11373 "dev_send_frame: SLS, dest_mac %s", mac);
11374 if (wil6210_send_sls(dut, mac))
11375 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011376 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
11377 (strcasecmp(frame_name, "devdiscreq") == 0)) {
11378 sigma_dut_print(dut, DUT_MSG_INFO,
11379 "dev_send_frame: %s, dest_mac %s", frame_name,
11380 mac);
11381 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
11382 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020011383 } else {
11384 sigma_dut_print(dut, DUT_MSG_ERROR,
11385 "unsupported frame type: %s", frame_name);
11386 return -1;
11387 }
11388
11389 return 1;
11390}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011391
Lior David0fe101e2017-03-09 16:09:50 +020011392#endif /* __linux__ */
11393
11394
11395static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
11396 struct sigma_conn *conn,
11397 struct sigma_cmd *cmd)
11398{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011399 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020011400#ifdef __linux__
11401 case DRIVER_WIL6210:
11402 return wil6210_send_frame_60g(dut, conn, cmd);
11403#endif /* __linux__ */
11404 default:
11405 send_resp(dut, conn, SIGMA_ERROR,
11406 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
11407 return 0;
11408 }
11409}
11410
11411
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011412static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
11413 const char *intf, struct sigma_cmd *cmd)
11414{
11415 const char *val, *addr;
11416 char buf[100];
11417
11418 addr = get_param(cmd, "DestMac");
11419 if (!addr) {
11420 send_resp(dut, conn, SIGMA_INVALID,
11421 "ErrorCode,AP MAC address is missing");
11422 return 0;
11423 }
11424
11425 val = get_param(cmd, "ANQPQuery_ID");
11426 if (!val) {
11427 send_resp(dut, conn, SIGMA_INVALID,
11428 "ErrorCode,Missing ANQPQuery_ID");
11429 return 0;
11430 }
11431
11432 if (strcasecmp(val, "NeighborReportReq") == 0) {
11433 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
11434 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
11435 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
11436 } else {
11437 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
11438 val);
11439 send_resp(dut, conn, SIGMA_INVALID,
11440 "ErrorCode,Invalid ANQPQuery_ID");
11441 return 0;
11442 }
11443
Ashwini Patild174f2c2017-04-13 16:49:46 +053011444 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
11445 * (Address3 = Wildcard BSSID when sent to not-associated AP;
11446 * if associated, AP BSSID).
11447 */
11448 if (wpa_command(intf, "SET gas_address3 1") < 0) {
11449 send_resp(dut, conn, SIGMA_ERROR,
11450 "ErrorCode,Failed to set gas_address3");
11451 return 0;
11452 }
11453
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011454 if (wpa_command(intf, buf) < 0) {
11455 send_resp(dut, conn, SIGMA_ERROR,
11456 "ErrorCode,Failed to send ANQP query");
11457 return 0;
11458 }
11459
11460 return 1;
11461}
11462
11463
11464static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
11465 struct sigma_conn *conn,
11466 const char *intf,
11467 struct sigma_cmd *cmd)
11468{
11469 const char *val = get_param(cmd, "FrameName");
11470
11471 if (val && strcasecmp(val, "ANQPQuery") == 0)
11472 return mbo_send_anqp_query(dut, conn, intf, cmd);
11473
11474 return 2;
11475}
11476
11477
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011478static enum sigma_cmd_result cmd_sta_send_frame_wpa3(struct sigma_dut *dut,
11479 struct sigma_conn *conn,
11480 const char *intf,
11481 struct sigma_cmd *cmd)
11482{
11483 const char *val = get_param(cmd, "framename");
11484
11485 if (!val)
11486 return INVALID_SEND_STATUS;
11487
11488 if (strcasecmp(val, "SAQueryReq") == 0) {
11489 val = get_param(cmd, "OCIChannel");
11490
11491 if (!val) {
11492 send_resp(dut, conn, SIGMA_ERROR,
11493 "errorCode,OCIChannel not present");
11494 return STATUS_SENT_ERROR;
11495 }
11496
11497 dut->saquery_oci_freq = channel_to_freq(dut, atoi(val));
11498 if (!dut->saquery_oci_freq) {
11499 send_resp(dut, conn, SIGMA_ERROR,
11500 "errorCode,Invalid OCIChannel number");
11501 return STATUS_SENT_ERROR;
11502 }
11503
11504 return sta_inject_frame(dut, conn, intf, SAQUERY, CORRECT_KEY,
11505 NULL, 0);
11506 }
11507
11508 if (strcasecmp(val, "reassocreq") == 0)
11509 return sta_inject_frame(dut, conn, intf, REASSOCREQ,
11510 CORRECT_KEY, NULL, 0);
11511
11512 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported framename");
11513 return STATUS_SENT_ERROR;
11514}
11515
11516
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011517static enum sigma_cmd_result
11518cmd_sta_send_frame_mscs(struct sigma_dut *dut, struct sigma_conn *conn,
11519 const char *intf, struct sigma_cmd *cmd)
11520{
11521 char buf[128], *pos;
11522 const char *val, *classifier_type = "04", *type;
11523 int len, rem_len;
11524 u8 up_bitmap;
11525
11526 val = get_param(cmd, "FrameName");
11527 type = get_param(cmd, "Request_Type");
11528 if (!val || !type || strcasecmp(val, "MSCSReq") != 0) {
11529 sigma_dut_print(dut, DUT_MSG_ERROR,
11530 "%s: frame name or type not valid", __func__);
11531 return INVALID_SEND_STATUS;
11532 }
11533
11534 rem_len = sizeof(buf);
11535 pos = buf;
11536 if (strcasecmp(type, "add") == 0) {
11537 len = snprintf(pos, rem_len, "MSCS add");
11538 } else if (strcasecmp(type, "update") == 0) {
11539 len = snprintf(pos, rem_len, "MSCS change");
11540 } else if (strcasecmp(type, "remove") == 0) {
11541 if (wpa_command(intf, "MSCS remove") != 0) {
11542 send_resp(dut, conn, SIGMA_ERROR,
11543 "ErrorCode,Failed to send MSCS frame req");
11544 return STATUS_SENT_ERROR;
11545 }
11546 return SUCCESS_SEND_STATUS;
11547 } else {
11548 sigma_dut_print(dut, DUT_MSG_ERROR,
11549 "%s: request type invalid", __func__);
11550 return INVALID_SEND_STATUS;
11551 }
11552
11553 if (len < 0 || len >= rem_len)
11554 goto fail;
11555
11556 pos += len;
11557 rem_len -= len;
11558
11559 val = get_param(cmd, "User_Priority_Bitmap");
11560 if (!val) {
11561 sigma_dut_print(dut, DUT_MSG_ERROR,
11562 "%s: user priority bitmap empty", __func__);
11563 return INVALID_SEND_STATUS;
11564 }
11565
11566 switch (atoi(val)) {
11567 case 0:
11568 up_bitmap = 0x00;
11569 break;
11570 case 1:
11571 up_bitmap = 0xF0;
11572 break;
11573 case 2:
11574 up_bitmap = 0xF6;
11575 break;
11576 default:
11577 sigma_dut_print(dut, DUT_MSG_ERROR,
11578 "%s: Unknown User_Priority_Bitmap value %d",
11579 __func__, atoi(val));
11580 return INVALID_SEND_STATUS;
11581 }
11582
11583 len = snprintf(pos, rem_len, " up_bitmap=%02x", up_bitmap);
11584 if (len < 0 || len >= rem_len)
11585 goto fail;
11586
11587 pos += len;
11588 rem_len -= len;
11589
11590 val = get_param(cmd, "User_Priority_Limit");
11591 if (!val) {
11592 sigma_dut_print(dut, DUT_MSG_ERROR,
11593 "%s: invalid user priority limit", __func__);
11594 return INVALID_SEND_STATUS;
11595 }
11596
11597 len = snprintf(pos, rem_len, " up_limit=%s", val);
11598 if (len < 0 || len >= rem_len)
11599 goto fail;
11600
11601 pos += len;
11602 rem_len -= len;
11603
11604 val = get_param(cmd, "Stream_Timeout");
11605 if (!val)
11606 val = get_param(cmd, "Stream_Timtout");
11607 if (!val) {
11608 sigma_dut_print(dut, DUT_MSG_ERROR,
11609 "%s: invalid stream timeout", __func__);
11610 return INVALID_SEND_STATUS;
11611 }
11612
11613 len = snprintf(pos, rem_len, " stream_timeout=%s", val);
11614 if (len < 0 || len >= rem_len)
11615 goto fail;
11616
11617 pos += len;
11618 rem_len -= len;
11619
11620 val = get_param(cmd, "TCLAS_Mask");
11621 if (!val) {
11622 sigma_dut_print(dut, DUT_MSG_ERROR,
11623 "%s: invalid tclas mask", __func__);
11624 return INVALID_SEND_STATUS;
11625 }
11626
11627 len = snprintf(pos, rem_len, " frame_classifier=%s%lx%032x",
11628 classifier_type, strtol(val, NULL, 2), 0);
11629 if (len < 0 || len >= rem_len)
11630 goto fail;
11631
11632 if (wpa_command(intf, buf) != 0) {
11633 send_resp(dut, conn, SIGMA_ERROR,
11634 "ErrorCode,Failed to send MSCS frame req");
11635 return STATUS_SENT_ERROR;
11636 }
11637
11638 sigma_dut_print(dut, DUT_MSG_DEBUG,
11639 "MSCS frame request sent: %s", buf);
11640
11641 return SUCCESS_SEND_STATUS;
11642fail:
11643 sigma_dut_print(dut, DUT_MSG_ERROR,
11644 "Failed to create MSCS frame req");
11645 return ERROR_SEND_STATUS;
11646}
11647
11648
Jouni Malinenf7222712019-06-13 01:50:21 +030011649enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
11650 struct sigma_conn *conn,
11651 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011652{
11653 const char *intf = get_param(cmd, "Interface");
11654 const char *val;
11655 enum send_frame_type frame;
11656 enum send_frame_protection protected;
11657 char buf[100];
11658 unsigned char addr[ETH_ALEN];
11659 int res;
11660
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011661 if (!intf)
11662 return -1;
11663
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011664 val = get_param(cmd, "program");
11665 if (val == NULL)
11666 val = get_param(cmd, "frame");
11667 if (val && strcasecmp(val, "TDLS") == 0)
11668 return cmd_sta_send_frame_tdls(dut, conn, cmd);
11669 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011670 strcasecmp(val, "HS2-R2") == 0 ||
11671 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011672 return cmd_sta_send_frame_hs2(dut, conn, cmd);
11673 if (val && strcasecmp(val, "VHT") == 0)
11674 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011675 if (val && strcasecmp(val, "HE") == 0)
11676 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070011677 if (val && strcasecmp(val, "LOC") == 0)
11678 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020011679 if (val && strcasecmp(val, "60GHz") == 0)
11680 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011681 if (val && strcasecmp(val, "MBO") == 0) {
11682 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
11683 if (res != 2)
11684 return res;
11685 }
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011686 if (val && strcasecmp(val, "WPA3") == 0)
11687 return cmd_sta_send_frame_wpa3(dut, conn, intf, cmd);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011688 if (val && strcasecmp(val, "QM") == 0)
11689 return cmd_sta_send_frame_mscs(dut, conn, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011690
11691 val = get_param(cmd, "TD_DISC");
11692 if (val) {
11693 if (hwaddr_aton(val, addr) < 0)
11694 return -1;
11695 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
11696 if (wpa_command(intf, buf) < 0) {
11697 send_resp(dut, conn, SIGMA_ERROR,
11698 "ErrorCode,Failed to send TDLS discovery");
11699 return 0;
11700 }
11701 return 1;
11702 }
11703
11704 val = get_param(cmd, "TD_Setup");
11705 if (val) {
11706 if (hwaddr_aton(val, addr) < 0)
11707 return -1;
11708 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
11709 if (wpa_command(intf, buf) < 0) {
11710 send_resp(dut, conn, SIGMA_ERROR,
11711 "ErrorCode,Failed to start TDLS setup");
11712 return 0;
11713 }
11714 return 1;
11715 }
11716
11717 val = get_param(cmd, "TD_TearDown");
11718 if (val) {
11719 if (hwaddr_aton(val, addr) < 0)
11720 return -1;
11721 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
11722 if (wpa_command(intf, buf) < 0) {
11723 send_resp(dut, conn, SIGMA_ERROR,
11724 "ErrorCode,Failed to tear down TDLS link");
11725 return 0;
11726 }
11727 return 1;
11728 }
11729
11730 val = get_param(cmd, "TD_ChannelSwitch");
11731 if (val) {
11732 /* TODO */
11733 send_resp(dut, conn, SIGMA_ERROR,
11734 "ErrorCode,TD_ChannelSwitch not yet supported");
11735 return 0;
11736 }
11737
11738 val = get_param(cmd, "TD_NF");
11739 if (val) {
11740 /* TODO */
11741 send_resp(dut, conn, SIGMA_ERROR,
11742 "ErrorCode,TD_NF not yet supported");
11743 return 0;
11744 }
11745
11746 val = get_param(cmd, "PMFFrameType");
11747 if (val == NULL)
11748 val = get_param(cmd, "FrameName");
11749 if (val == NULL)
11750 val = get_param(cmd, "Type");
11751 if (val == NULL)
11752 return -1;
11753 if (strcasecmp(val, "disassoc") == 0)
11754 frame = DISASSOC;
11755 else if (strcasecmp(val, "deauth") == 0)
11756 frame = DEAUTH;
11757 else if (strcasecmp(val, "saquery") == 0)
11758 frame = SAQUERY;
11759 else if (strcasecmp(val, "auth") == 0)
11760 frame = AUTH;
11761 else if (strcasecmp(val, "assocreq") == 0)
11762 frame = ASSOCREQ;
11763 else if (strcasecmp(val, "reassocreq") == 0)
11764 frame = REASSOCREQ;
11765 else if (strcasecmp(val, "neigreq") == 0) {
11766 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
11767
11768 val = get_param(cmd, "ssid");
11769 if (val == NULL)
11770 return -1;
11771
11772 res = send_neighbor_request(dut, intf, val);
11773 if (res) {
11774 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11775 "Failed to send neighbor report request");
11776 return 0;
11777 }
11778
11779 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053011780 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
11781 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011782 sigma_dut_print(dut, DUT_MSG_DEBUG,
11783 "Got Transition Management Query");
11784
Ashwini Patil5acd7382017-04-13 15:55:04 +053011785 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011786 if (res) {
11787 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11788 "Failed to send Transition Management Query");
11789 return 0;
11790 }
11791
11792 return 1;
11793 } else {
11794 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11795 "PMFFrameType");
11796 return 0;
11797 }
11798
11799 val = get_param(cmd, "PMFProtected");
11800 if (val == NULL)
11801 val = get_param(cmd, "Protected");
11802 if (val == NULL)
11803 return -1;
11804 if (strcasecmp(val, "Correct-key") == 0 ||
11805 strcasecmp(val, "CorrectKey") == 0)
11806 protected = CORRECT_KEY;
11807 else if (strcasecmp(val, "IncorrectKey") == 0)
11808 protected = INCORRECT_KEY;
11809 else if (strcasecmp(val, "Unprotected") == 0)
11810 protected = UNPROTECTED;
11811 else {
11812 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11813 "PMFProtected");
11814 return 0;
11815 }
11816
11817 if (protected != UNPROTECTED &&
11818 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
11819 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
11820 "PMFProtected for auth/assocreq/reassocreq");
11821 return 0;
11822 }
11823
11824 if (if_nametoindex("sigmadut") == 0) {
11825 snprintf(buf, sizeof(buf),
11826 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011827 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011828 if (system(buf) != 0 ||
11829 if_nametoindex("sigmadut") == 0) {
11830 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11831 "monitor interface with '%s'", buf);
11832 return -2;
11833 }
11834 }
11835
11836 if (system("ifconfig sigmadut up") != 0) {
11837 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11838 "monitor interface up");
11839 return -2;
11840 }
11841
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011842 return sta_inject_frame(dut, conn, intf, frame, protected, NULL, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011843}
11844
11845
11846static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
11847 struct sigma_conn *conn,
11848 struct sigma_cmd *cmd,
11849 const char *ifname)
11850{
11851 char buf[200];
11852 const char *val;
11853
11854 val = get_param(cmd, "ClearARP");
11855 if (val && atoi(val) == 1) {
11856 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
11857 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11858 if (system(buf) != 0) {
11859 send_resp(dut, conn, SIGMA_ERROR,
11860 "errorCode,Failed to clear ARP cache");
11861 return 0;
11862 }
11863 }
11864
11865 return 1;
11866}
11867
11868
11869int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
11870 struct sigma_cmd *cmd)
11871{
11872 const char *intf = get_param(cmd, "Interface");
11873 const char *val;
11874
11875 if (intf == NULL)
11876 return -1;
11877
11878 val = get_param(cmd, "program");
11879 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011880 strcasecmp(val, "HS2-R2") == 0 ||
11881 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011882 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
11883
11884 return -1;
11885}
11886
11887
Jouni Malinenf7222712019-06-13 01:50:21 +030011888static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
11889 struct sigma_conn *conn,
11890 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011891{
11892 const char *intf = get_param(cmd, "Interface");
11893 const char *mac = get_param(cmd, "MAC");
11894
11895 if (intf == NULL || mac == NULL)
11896 return -1;
11897
11898 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
11899 "interface %s to %s", intf, mac);
11900
11901 if (dut->set_macaddr) {
11902 char buf[128];
11903 int res;
11904 if (strcasecmp(mac, "default") == 0) {
11905 res = snprintf(buf, sizeof(buf), "%s",
11906 dut->set_macaddr);
11907 dut->tmp_mac_addr = 0;
11908 } else {
11909 res = snprintf(buf, sizeof(buf), "%s %s",
11910 dut->set_macaddr, mac);
11911 dut->tmp_mac_addr = 1;
11912 }
11913 if (res < 0 || res >= (int) sizeof(buf))
11914 return -1;
11915 if (system(buf) != 0) {
11916 send_resp(dut, conn, SIGMA_ERROR,
11917 "errorCode,Failed to set MAC "
11918 "address");
11919 return 0;
11920 }
11921 return 1;
11922 }
11923
11924 if (strcasecmp(mac, "default") == 0)
11925 return 1;
11926
11927 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11928 "command");
11929 return 0;
11930}
11931
11932
11933static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
11934 struct sigma_conn *conn, const char *intf,
11935 int val)
11936{
11937 char buf[200];
11938 int res;
11939
11940 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
11941 intf, val);
11942 if (res < 0 || res >= (int) sizeof(buf))
11943 return -1;
11944 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11945 if (system(buf) != 0) {
11946 send_resp(dut, conn, SIGMA_ERROR,
11947 "errorCode,Failed to configure offchannel mode");
11948 return 0;
11949 }
11950
11951 return 1;
11952}
11953
11954
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011955static int off_chan_val(enum sec_ch_offset off)
11956{
11957 switch (off) {
11958 case SEC_CH_NO:
11959 return 0;
11960 case SEC_CH_40ABOVE:
11961 return 40;
11962 case SEC_CH_40BELOW:
11963 return -40;
11964 }
11965
11966 return 0;
11967}
11968
11969
11970static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
11971 const char *intf, int off_ch_num,
11972 enum sec_ch_offset sec)
11973{
11974 char buf[200];
11975 int res;
11976
11977 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
11978 intf, off_ch_num);
11979 if (res < 0 || res >= (int) sizeof(buf))
11980 return -1;
11981 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11982 if (system(buf) != 0) {
11983 send_resp(dut, conn, SIGMA_ERROR,
11984 "errorCode,Failed to set offchan");
11985 return 0;
11986 }
11987
11988 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
11989 intf, off_chan_val(sec));
11990 if (res < 0 || res >= (int) sizeof(buf))
11991 return -1;
11992 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11993 if (system(buf) != 0) {
11994 send_resp(dut, conn, SIGMA_ERROR,
11995 "errorCode,Failed to set sec chan offset");
11996 return 0;
11997 }
11998
11999 return 1;
12000}
12001
12002
12003static int tdls_set_offchannel_offset(struct sigma_dut *dut,
12004 struct sigma_conn *conn,
12005 const char *intf, int off_ch_num,
12006 enum sec_ch_offset sec)
12007{
12008 char buf[200];
12009 int res;
12010
12011 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
12012 off_ch_num);
12013 if (res < 0 || res >= (int) sizeof(buf))
12014 return -1;
12015 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12016
12017 if (wpa_command(intf, buf) < 0) {
12018 send_resp(dut, conn, SIGMA_ERROR,
12019 "ErrorCode,Failed to set offchan");
12020 return 0;
12021 }
12022 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
12023 off_chan_val(sec));
12024 if (res < 0 || res >= (int) sizeof(buf))
12025 return -1;
12026
12027 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12028
12029 if (wpa_command(intf, buf) < 0) {
12030 send_resp(dut, conn, SIGMA_ERROR,
12031 "ErrorCode,Failed to set sec chan offset");
12032 return 0;
12033 }
12034
12035 return 1;
12036}
12037
12038
12039static int tdls_set_offchannel_mode(struct sigma_dut *dut,
12040 struct sigma_conn *conn,
12041 const char *intf, int val)
12042{
12043 char buf[200];
12044 int res;
12045
12046 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
12047 val);
12048 if (res < 0 || res >= (int) sizeof(buf))
12049 return -1;
12050 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12051
12052 if (wpa_command(intf, buf) < 0) {
12053 send_resp(dut, conn, SIGMA_ERROR,
12054 "ErrorCode,Failed to configure offchannel mode");
12055 return 0;
12056 }
12057
12058 return 1;
12059}
12060
12061
12062static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
12063 struct sigma_conn *conn,
12064 struct sigma_cmd *cmd)
12065{
12066 const char *val;
12067 enum {
12068 CHSM_NOT_SET,
12069 CHSM_ENABLE,
12070 CHSM_DISABLE,
12071 CHSM_REJREQ,
12072 CHSM_UNSOLRESP
12073 } chsm = CHSM_NOT_SET;
12074 int off_ch_num = -1;
12075 enum sec_ch_offset sec_ch = SEC_CH_NO;
12076 int res;
12077
12078 val = get_param(cmd, "Uapsd");
12079 if (val) {
12080 char buf[100];
12081 if (strcasecmp(val, "Enable") == 0)
12082 snprintf(buf, sizeof(buf), "SET ps 99");
12083 else if (strcasecmp(val, "Disable") == 0)
12084 snprintf(buf, sizeof(buf), "SET ps 98");
12085 else {
12086 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
12087 "Unsupported uapsd parameter value");
12088 return 0;
12089 }
12090 if (wpa_command(intf, buf)) {
12091 send_resp(dut, conn, SIGMA_ERROR,
12092 "ErrorCode,Failed to change U-APSD "
12093 "powersave mode");
12094 return 0;
12095 }
12096 }
12097
12098 val = get_param(cmd, "TPKTIMER");
12099 if (val && strcasecmp(val, "DISABLE") == 0) {
12100 if (wpa_command(intf, "SET tdls_testing 0x100")) {
12101 send_resp(dut, conn, SIGMA_ERROR,
12102 "ErrorCode,Failed to enable no TPK "
12103 "expiration test mode");
12104 return 0;
12105 }
12106 dut->no_tpk_expiration = 1;
12107 }
12108
12109 val = get_param(cmd, "ChSwitchMode");
12110 if (val) {
12111 if (strcasecmp(val, "Enable") == 0 ||
12112 strcasecmp(val, "Initiate") == 0)
12113 chsm = CHSM_ENABLE;
12114 else if (strcasecmp(val, "Disable") == 0 ||
12115 strcasecmp(val, "passive") == 0)
12116 chsm = CHSM_DISABLE;
12117 else if (strcasecmp(val, "RejReq") == 0)
12118 chsm = CHSM_REJREQ;
12119 else if (strcasecmp(val, "UnSolResp") == 0)
12120 chsm = CHSM_UNSOLRESP;
12121 else {
12122 send_resp(dut, conn, SIGMA_ERROR,
12123 "ErrorCode,Unknown ChSwitchMode value");
12124 return 0;
12125 }
12126 }
12127
12128 val = get_param(cmd, "OffChNum");
12129 if (val) {
12130 off_ch_num = atoi(val);
12131 if (off_ch_num == 0) {
12132 send_resp(dut, conn, SIGMA_ERROR,
12133 "ErrorCode,Invalid OffChNum");
12134 return 0;
12135 }
12136 }
12137
12138 val = get_param(cmd, "SecChOffset");
12139 if (val) {
12140 if (strcmp(val, "20") == 0)
12141 sec_ch = SEC_CH_NO;
12142 else if (strcasecmp(val, "40above") == 0)
12143 sec_ch = SEC_CH_40ABOVE;
12144 else if (strcasecmp(val, "40below") == 0)
12145 sec_ch = SEC_CH_40BELOW;
12146 else {
12147 send_resp(dut, conn, SIGMA_ERROR,
12148 "ErrorCode,Unknown SecChOffset value");
12149 return 0;
12150 }
12151 }
12152
12153 if (chsm == CHSM_NOT_SET) {
12154 /* no offchannel changes requested */
12155 return 1;
12156 }
12157
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012158 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
12159 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012160 send_resp(dut, conn, SIGMA_ERROR,
12161 "ErrorCode,Unknown interface");
12162 return 0;
12163 }
12164
12165 switch (chsm) {
12166 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030012167 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012168 break;
12169 case CHSM_ENABLE:
12170 if (off_ch_num < 0) {
12171 send_resp(dut, conn, SIGMA_ERROR,
12172 "ErrorCode,Missing OffChNum argument");
12173 return 0;
12174 }
12175 if (wifi_chip_type == DRIVER_WCN) {
12176 res = tdls_set_offchannel_offset(dut, conn, intf,
12177 off_ch_num, sec_ch);
12178 } else {
12179 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
12180 sec_ch);
12181 }
12182 if (res != 1)
12183 return res;
12184 if (wifi_chip_type == DRIVER_WCN)
12185 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
12186 else
12187 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
12188 break;
12189 case CHSM_DISABLE:
12190 if (wifi_chip_type == DRIVER_WCN)
12191 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
12192 else
12193 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
12194 break;
12195 case CHSM_REJREQ:
12196 if (wifi_chip_type == DRIVER_WCN)
12197 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
12198 else
12199 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
12200 break;
12201 case CHSM_UNSOLRESP:
12202 if (off_ch_num < 0) {
12203 send_resp(dut, conn, SIGMA_ERROR,
12204 "ErrorCode,Missing OffChNum argument");
12205 return 0;
12206 }
12207 if (wifi_chip_type == DRIVER_WCN) {
12208 res = tdls_set_offchannel_offset(dut, conn, intf,
12209 off_ch_num, sec_ch);
12210 } else {
12211 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
12212 sec_ch);
12213 }
12214 if (res != 1)
12215 return res;
12216 if (wifi_chip_type == DRIVER_WCN)
12217 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
12218 else
12219 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
12220 break;
12221 }
12222
12223 return res;
12224}
12225
12226
12227static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
12228 struct sigma_conn *conn,
12229 struct sigma_cmd *cmd)
12230{
12231 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053012232 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012233
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070012234 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080012235
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012236 val = get_param(cmd, "nss_mcs_opt");
12237 if (val) {
12238 /* String (nss_operating_mode; mcs_operating_mode) */
12239 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012240 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012241
12242 token = strdup(val);
12243 if (!token)
12244 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012245 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053012246 if (!result) {
12247 sigma_dut_print(dut, DUT_MSG_ERROR,
12248 "VHT NSS not specified");
12249 goto failed;
12250 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012251 if (strcasecmp(result, "def") != 0) {
12252 nss = atoi(result);
12253 if (nss == 4)
12254 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012255 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012256 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012257
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012258 }
12259
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012260 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053012261 if (!result) {
12262 sigma_dut_print(dut, DUT_MSG_ERROR,
12263 "VHT MCS not specified");
12264 goto failed;
12265 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012266 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012267 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012268 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012269 } else {
12270 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012271 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012272 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012273 }
12274 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012275 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012276 }
12277
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053012278 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012279 return 1;
12280failed:
12281 free(token);
12282 return 0;
12283}
12284
12285
12286static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
12287 struct sigma_conn *conn,
12288 struct sigma_cmd *cmd)
12289{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012290 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012291 case DRIVER_ATHEROS:
12292 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
12293 default:
12294 send_resp(dut, conn, SIGMA_ERROR,
12295 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
12296 return 0;
12297 }
12298}
12299
12300
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012301static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12302 struct sigma_conn *conn,
12303 struct sigma_cmd *cmd)
12304{
12305 const char *val;
12306 char *token = NULL, *result;
12307 char buf[60];
12308
12309 val = get_param(cmd, "nss_mcs_opt");
12310 if (val) {
12311 /* String (nss_operating_mode; mcs_operating_mode) */
12312 int nss, mcs, ratecode;
12313 char *saveptr;
12314
12315 token = strdup(val);
12316 if (!token)
12317 return -2;
12318
12319 result = strtok_r(token, ";", &saveptr);
12320 if (!result) {
12321 sigma_dut_print(dut, DUT_MSG_ERROR,
12322 "HE NSS not specified");
12323 goto failed;
12324 }
12325 nss = 1;
12326 if (strcasecmp(result, "def") != 0)
12327 nss = atoi(result);
12328
12329 result = strtok_r(NULL, ";", &saveptr);
12330 if (!result) {
12331 sigma_dut_print(dut, DUT_MSG_ERROR,
12332 "HE MCS not specified");
12333 goto failed;
12334 }
12335 mcs = 7;
12336 if (strcasecmp(result, "def") != 0)
12337 mcs = atoi(result);
12338
Arif Hussain557bf412018-05-25 17:29:36 -070012339 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012340 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070012341 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012342 } else if (nss > 2) {
12343 sigma_dut_print(dut, DUT_MSG_ERROR,
12344 "HE NSS %d not supported", nss);
12345 goto failed;
12346 }
12347
Arif Hussain557bf412018-05-25 17:29:36 -070012348 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
12349 if (system(buf) != 0) {
12350 sigma_dut_print(dut, DUT_MSG_ERROR,
12351 "nss_mcs_opt: iwpriv %s nss %d failed",
12352 intf, nss);
12353 goto failed;
12354 }
Arif Hussainac6c5112018-05-25 17:34:00 -070012355 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070012356
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012357 /* Add the MCS to the ratecode */
12358 if (mcs >= 0 && mcs <= 11) {
12359 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070012360#ifdef NL80211_SUPPORT
12361 if (dut->device_type == STA_testbed) {
12362 enum he_mcs_config mcs_config;
12363 int ret;
12364
12365 if (mcs <= 7)
12366 mcs_config = HE_80_MCS0_7;
12367 else if (mcs <= 9)
12368 mcs_config = HE_80_MCS0_9;
12369 else
12370 mcs_config = HE_80_MCS0_11;
12371 ret = sta_set_he_mcs(dut, intf, mcs_config);
12372 if (ret) {
12373 sigma_dut_print(dut, DUT_MSG_ERROR,
12374 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
12375 mcs, mcs_config, ret);
12376 goto failed;
12377 }
12378 }
12379#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012380 } else {
12381 sigma_dut_print(dut, DUT_MSG_ERROR,
12382 "HE MCS %d not supported", mcs);
12383 goto failed;
12384 }
12385 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
12386 intf, ratecode);
12387 if (system(buf) != 0) {
12388 sigma_dut_print(dut, DUT_MSG_ERROR,
12389 "iwpriv setting of 11ax rates failed");
12390 goto failed;
12391 }
12392 free(token);
12393 }
12394
12395 val = get_param(cmd, "GI");
12396 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012397 int fix_rate_sgi;
12398
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012399 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012400 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012401 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012402 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012403 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
12404 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012405 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012406 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012407 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
12408 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012409 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012410 } else {
12411 send_resp(dut, conn, SIGMA_ERROR,
12412 "errorCode,GI value not supported");
12413 return 0;
12414 }
12415 if (system(buf) != 0) {
12416 send_resp(dut, conn, SIGMA_ERROR,
12417 "errorCode,Failed to set shortgi");
12418 return 0;
12419 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012420 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
12421 intf, fix_rate_sgi);
12422 if (system(buf) != 0) {
12423 send_resp(dut, conn, SIGMA_ERROR,
12424 "errorCode,Failed to set fix rate shortgi");
12425 return STATUS_SENT;
12426 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012427 }
12428
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012429 val = get_param(cmd, "LTF");
12430 if (val) {
12431#ifdef NL80211_SUPPORT
12432 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012433 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012434 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012435 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012436 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012437 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012438 } else {
12439 send_resp(dut, conn, SIGMA_ERROR,
12440 "errorCode, LTF value not supported");
12441 return 0;
12442 }
12443#else /* NL80211_SUPPORT */
12444 sigma_dut_print(dut, DUT_MSG_ERROR,
12445 "LTF cannot be set without NL80211_SUPPORT defined");
12446 return -2;
12447#endif /* NL80211_SUPPORT */
12448 }
12449
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070012450 val = get_param(cmd, "TxSUPPDU");
12451 if (val) {
12452 int set_val = 1;
12453
12454 if (strcasecmp(val, "Enable") == 0)
12455 set_val = 1;
12456 else if (strcasecmp(val, "Disable") == 0)
12457 set_val = 0;
12458
12459 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
12460 send_resp(dut, conn, SIGMA_ERROR,
12461 "ErrorCode,Failed to set Tx SU PPDU config");
12462 return 0;
12463 }
12464 }
12465
Arif Hussain480d5f42019-03-12 14:40:42 -070012466 val = get_param(cmd, "TWT_Setup");
12467 if (val) {
12468 if (strcasecmp(val, "Request") == 0) {
12469 if (sta_twt_request(dut, conn, cmd)) {
12470 send_resp(dut, conn, SIGMA_ERROR,
12471 "ErrorCode,sta_twt_request failed");
12472 return STATUS_SENT;
12473 }
12474 } else if (strcasecmp(val, "Teardown") == 0) {
12475 if (sta_twt_teardown(dut, conn, cmd)) {
12476 send_resp(dut, conn, SIGMA_ERROR,
12477 "ErrorCode,sta_twt_teardown failed");
12478 return STATUS_SENT;
12479 }
12480 }
12481 }
12482
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080012483 val = get_param(cmd, "transmitOMI");
12484 if (val && sta_transmit_omi(dut, conn, cmd)) {
12485 send_resp(dut, conn, SIGMA_ERROR,
12486 "ErrorCode,sta_transmit_omi failed");
12487 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070012488 }
12489
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012490 val = get_param(cmd, "Powersave");
12491 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012492 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012493
12494 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012495 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012496 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012497 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012498 } else {
12499 sigma_dut_print(dut, DUT_MSG_ERROR,
12500 "Unsupported Powersave value '%s'",
12501 val);
12502 return -1;
12503 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012504 if (set_power_save_wcn(dut, intf, ps) < 0)
12505 return 0;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012506 }
12507
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080012508 val = get_param(cmd, "MU_EDCA");
12509 if (val) {
12510 if (strcasecmp(val, "Override") == 0) {
12511 if (sta_set_mu_edca_override(dut, intf, 1)) {
12512 send_resp(dut, conn, SIGMA_ERROR,
12513 "errorCode,MU EDCA override set failed");
12514 return STATUS_SENT;
12515 }
12516 } else if (strcasecmp(val, "Disable") == 0) {
12517 if (sta_set_mu_edca_override(dut, intf, 0)) {
12518 send_resp(dut, conn, SIGMA_ERROR,
12519 "errorCode,MU EDCA override disable failed");
12520 return STATUS_SENT;
12521 }
12522 }
12523 }
12524
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -070012525 val = get_param(cmd, "Ch_Pref");
12526 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12527 return STATUS_SENT;
12528
12529 val = get_param(cmd, "Cellular_Data_Cap");
12530 if (val && mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12531 return STATUS_SENT;
12532
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012533 return 1;
12534
12535failed:
12536 free(token);
12537 return -2;
12538}
12539
12540
12541static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12542 struct sigma_conn *conn,
12543 struct sigma_cmd *cmd)
12544{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012545 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012546 case DRIVER_WCN:
12547 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
12548 default:
12549 send_resp(dut, conn, SIGMA_ERROR,
12550 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
12551 return 0;
12552 }
12553}
12554
12555
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012556static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
12557 struct sigma_conn *conn,
12558 struct sigma_cmd *cmd)
12559{
12560 const char *val;
12561
12562 val = get_param(cmd, "powersave");
12563 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012564 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012565
12566 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012567 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012568 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012569 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012570 } else {
12571 sigma_dut_print(dut, DUT_MSG_ERROR,
12572 "Unsupported power save config");
12573 return -1;
12574 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012575 if (set_power_save_wcn(dut, intf, ps) < 0)
12576 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012577 return 1;
12578 }
12579
12580 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
12581
12582 return 0;
12583}
12584
12585
Ashwini Patil5acd7382017-04-13 15:55:04 +053012586static int btm_query_candidate_list(struct sigma_dut *dut,
12587 struct sigma_conn *conn,
12588 struct sigma_cmd *cmd)
12589{
12590 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
12591 int len, ret;
12592 char buf[10];
12593
12594 /*
12595 * Neighbor Report elements format:
12596 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
12597 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
12598 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
12599 */
12600
12601 bssid = get_param(cmd, "Nebor_BSSID");
12602 if (!bssid) {
12603 send_resp(dut, conn, SIGMA_INVALID,
12604 "errorCode,Nebor_BSSID is missing");
12605 return 0;
12606 }
12607
12608 info = get_param(cmd, "Nebor_Bssid_Info");
12609 if (!info) {
12610 sigma_dut_print(dut, DUT_MSG_INFO,
12611 "Using default value for Nebor_Bssid_Info: %s",
12612 DEFAULT_NEIGHBOR_BSSID_INFO);
12613 info = DEFAULT_NEIGHBOR_BSSID_INFO;
12614 }
12615
12616 op_class = get_param(cmd, "Nebor_Op_Class");
12617 if (!op_class) {
12618 send_resp(dut, conn, SIGMA_INVALID,
12619 "errorCode,Nebor_Op_Class is missing");
12620 return 0;
12621 }
12622
12623 ch = get_param(cmd, "Nebor_Op_Ch");
12624 if (!ch) {
12625 send_resp(dut, conn, SIGMA_INVALID,
12626 "errorCode,Nebor_Op_Ch is missing");
12627 return 0;
12628 }
12629
12630 phy_type = get_param(cmd, "Nebor_Phy_Type");
12631 if (!phy_type) {
12632 sigma_dut_print(dut, DUT_MSG_INFO,
12633 "Using default value for Nebor_Phy_Type: %s",
12634 DEFAULT_NEIGHBOR_PHY_TYPE);
12635 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
12636 }
12637
12638 /* Parse optional subelements */
12639 buf[0] = '\0';
12640 pref = get_param(cmd, "Nebor_Pref");
12641 if (pref) {
12642 /* hexdump for preferrence subelement */
12643 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
12644 if (ret < 0 || ret >= (int) sizeof(buf)) {
12645 sigma_dut_print(dut, DUT_MSG_ERROR,
12646 "snprintf failed for optional subelement ret: %d",
12647 ret);
12648 send_resp(dut, conn, SIGMA_ERROR,
12649 "errorCode,snprintf failed for subelement");
12650 return 0;
12651 }
12652 }
12653
12654 if (!dut->btm_query_cand_list) {
12655 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
12656 if (!dut->btm_query_cand_list) {
12657 send_resp(dut, conn, SIGMA_ERROR,
12658 "errorCode,Failed to allocate memory for btm_query_cand_list");
12659 return 0;
12660 }
12661 }
12662
12663 len = strlen(dut->btm_query_cand_list);
12664 ret = snprintf(dut->btm_query_cand_list + len,
12665 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
12666 bssid, info, op_class, ch, phy_type, buf);
12667 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
12668 sigma_dut_print(dut, DUT_MSG_ERROR,
12669 "snprintf failed for neighbor report list ret: %d",
12670 ret);
12671 send_resp(dut, conn, SIGMA_ERROR,
12672 "errorCode,snprintf failed for neighbor report");
12673 free(dut->btm_query_cand_list);
12674 dut->btm_query_cand_list = NULL;
12675 return 0;
12676 }
12677
12678 return 1;
12679}
12680
12681
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012682int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
12683 struct sigma_ese_alloc *allocs, int *allocs_size)
12684{
12685 int max_count = *allocs_size;
12686 int count = 0, i;
12687 const char *val;
12688
12689 do {
12690 val = get_param_indexed(cmd, "AllocID", count);
12691 if (val)
12692 count++;
12693 } while (val);
12694
12695 if (count == 0 || count > max_count) {
12696 sigma_dut_print(dut, DUT_MSG_ERROR,
12697 "Invalid number of allocations(%d)", count);
12698 return -1;
12699 }
12700
12701 for (i = 0; i < count; i++) {
12702 val = get_param_indexed(cmd, "PercentBI", i);
12703 if (!val) {
12704 sigma_dut_print(dut, DUT_MSG_ERROR,
12705 "Missing PercentBI parameter at index %d",
12706 i);
12707 return -1;
12708 }
12709 allocs[i].percent_bi = atoi(val);
12710
12711 val = get_param_indexed(cmd, "SrcAID", i);
12712 if (val)
12713 allocs[i].src_aid = strtol(val, NULL, 0);
12714 else
12715 allocs[i].src_aid = ESE_BCAST_AID;
12716
12717 val = get_param_indexed(cmd, "DestAID", i);
12718 if (val)
12719 allocs[i].dst_aid = strtol(val, NULL, 0);
12720 else
12721 allocs[i].dst_aid = ESE_BCAST_AID;
12722
12723 allocs[i].type = ESE_CBAP;
12724 sigma_dut_print(dut, DUT_MSG_INFO,
12725 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
12726 i, allocs[i].percent_bi, allocs[i].src_aid,
12727 allocs[i].dst_aid);
12728 }
12729
12730 *allocs_size = count;
12731 return 0;
12732}
12733
12734
12735static int sta_set_60g_ese(struct sigma_dut *dut, int count,
12736 struct sigma_ese_alloc *allocs)
12737{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012738 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012739#ifdef __linux__
12740 case DRIVER_WIL6210:
12741 if (wil6210_set_ese(dut, count, allocs))
12742 return -1;
12743 return 1;
12744#endif /* __linux__ */
12745 default:
12746 sigma_dut_print(dut, DUT_MSG_ERROR,
12747 "Unsupported sta_set_60g_ese with the current driver");
12748 return -1;
12749 }
12750}
12751
12752
12753static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
12754 struct sigma_conn *conn,
12755 struct sigma_cmd *cmd)
12756{
12757 const char *val;
12758
12759 val = get_param(cmd, "ExtSchIE");
12760 if (val && !strcasecmp(val, "Enable")) {
12761 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
12762 int count = MAX_ESE_ALLOCS;
12763
12764 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
12765 return -1;
12766 return sta_set_60g_ese(dut, count, allocs);
12767 }
12768
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012769 val = get_param(cmd, "MCS_FixedRate");
12770 if (val) {
12771 int sta_mcs = atoi(val);
12772
12773 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
12774 sta_mcs);
12775 wil6210_set_force_mcs(dut, 1, sta_mcs);
12776
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012777 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012778 }
12779
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012780 send_resp(dut, conn, SIGMA_ERROR,
12781 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012782 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012783}
12784
12785
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012786static int wcn_sta_override_oci(struct sigma_dut *dut, const char *intf,
12787 const char *oci_frametype, uint32_t oci_freq)
12788{
12789#ifdef NL80211_SUPPORT
12790 struct nl_msg *msg;
12791 int ret = 0;
12792 struct nlattr *params;
12793 struct nlattr *attr;
12794 int ifindex;
12795 u8 frame_type;
12796
12797 ifindex = if_nametoindex(intf);
12798 if (ifindex == 0) {
12799 sigma_dut_print(dut, DUT_MSG_ERROR,
12800 "%s: Index for interface %s failed",
12801 __func__, intf);
12802 return -1;
12803 }
12804
12805 if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12806 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_REQ;
12807 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12808 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_RESP;
12809 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
12810 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_FT_REASSOC_REQ;
12811 } else {
12812 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: Unknown frametype %s",
12813 __func__, oci_frametype);
12814 return -1;
12815 }
12816
12817
12818 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
12819 NL80211_CMD_VENDOR)) ||
12820 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
12821 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
12822 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
12823 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
12824 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
12825 !(params = nla_nest_start(
12826 msg,
12827 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OCI_OVERRIDE)) ||
12828 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FRAME_TYPE,
12829 frame_type) ||
12830 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FREQUENCY,
12831 oci_freq)) {
12832 sigma_dut_print(dut, DUT_MSG_ERROR,
12833 "%s: err in adding vendor_cmd and vendor_data",
12834 __func__);
12835 nlmsg_free(msg);
12836 return -1;
12837 }
12838 nla_nest_end(msg, params);
12839 nla_nest_end(msg, attr);
12840
12841 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
12842 if (ret) {
12843 sigma_dut_print(dut, DUT_MSG_ERROR,
12844 "%s: err in send_and_recv_msgs, ret=%d",
12845 __func__, ret);
12846 }
12847 return ret;
12848#else /* NL80211_SUPPORT */
12849 sigma_dut_print(dut, DUT_MSG_ERROR,
12850 "OCI override not possible without NL80211_SUPPORT defined");
12851 return -1;
12852#endif /* NL80211_SUPPORT */
12853}
12854
12855
Jouni Malinen6250cb02020-04-15 13:54:45 +030012856static enum sigma_cmd_result
12857cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
12858 struct sigma_conn *conn,
12859 struct sigma_cmd *cmd)
12860{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012861 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030012862
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053012863 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030012864 if (val && atoi(val) == 1) {
12865 if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
12866 send_resp(dut, conn, SIGMA_ERROR,
12867 "errorCode,Failed to set ft_rsnxe_used");
12868 return STATUS_SENT_ERROR;
12869 }
12870 return SUCCESS_SEND_STATUS;
12871 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012872
12873 oci_chan = get_param(cmd, "OCIChannel");
12874 oci_frametype = get_param(cmd, "OCIFrameType");
12875 if (oci_chan && oci_frametype) {
12876 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
12877 char buf[100];
12878
12879 if (!oci_freq) {
12880 send_resp(dut, conn, SIGMA_ERROR,
12881 "errorCode,Invalid OCIChannel number");
12882 return STATUS_SENT_ERROR;
12883 }
12884
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012885 if (wifi_chip_type == DRIVER_WCN &&
12886 (strcasecmp(oci_frametype, "SAQueryReq") == 0 ||
12887 strcasecmp(oci_frametype, "SAQueryResp") == 0 ||
12888 strcasecmp(oci_frametype, "Reassocreq") == 0)) {
12889 if (wcn_sta_override_oci(dut, intf, oci_frametype,
12890 oci_freq)) {
12891 send_resp(dut, conn, SIGMA_ERROR,
12892 "errorCode,Failed to override OCI");
12893 return STATUS_SENT_ERROR;
12894 }
12895 return SUCCESS_SEND_STATUS;
12896 }
12897
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012898 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
12899 snprintf(buf, sizeof(buf),
12900 "SET oci_freq_override_eapol %d", oci_freq);
12901 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12902 snprintf(buf, sizeof(buf),
12903 "SET oci_freq_override_saquery_req %d",
12904 oci_freq);
12905 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12906 snprintf(buf, sizeof(buf),
12907 "SET oci_freq_override_saquery_resp %d",
12908 oci_freq);
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012909 } else if (strcasecmp(oci_frametype, "GrpKeyM2") == 0) {
12910 snprintf(buf, sizeof(buf),
12911 "SET oci_freq_override_eapol_g2 %d",
12912 oci_freq);
12913 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
12914 snprintf(buf, sizeof(buf),
12915 "SET oci_freq_override_ft_assoc %d",
12916 oci_freq);
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012917 } else {
12918 send_resp(dut, conn, SIGMA_ERROR,
12919 "errorCode,Unsupported OCIFrameType");
12920 return STATUS_SENT_ERROR;
12921 }
12922 if (wpa_command(intf, buf) < 0) {
12923 send_resp(dut, conn, SIGMA_ERROR,
12924 "errorCode,Failed to set oci_freq_override");
12925 return STATUS_SENT_ERROR;
12926 }
12927 return SUCCESS_SEND_STATUS;
12928 }
12929
Jouni Malinen6250cb02020-04-15 13:54:45 +030012930 send_resp(dut, conn, SIGMA_ERROR,
12931 "errorCode,Unsupported WPA3 rfeature");
12932 return STATUS_SENT_ERROR;
12933}
12934
12935
Jouni Malinenf7222712019-06-13 01:50:21 +030012936static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
12937 struct sigma_conn *conn,
12938 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012939{
12940 const char *intf = get_param(cmd, "Interface");
12941 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012942 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012943
12944 if (intf == NULL || prog == NULL)
12945 return -1;
12946
Ashwini Patil5acd7382017-04-13 15:55:04 +053012947 /* BSS Transition candidate list for BTM query */
12948 val = get_param(cmd, "Nebor_BSSID");
12949 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
12950 return 0;
12951
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012952 if (strcasecmp(prog, "TDLS") == 0)
12953 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
12954
12955 if (strcasecmp(prog, "VHT") == 0)
12956 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
12957
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012958 if (strcasecmp(prog, "HE") == 0)
12959 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
12960
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012961 if (strcasecmp(prog, "MBO") == 0) {
12962 val = get_param(cmd, "Cellular_Data_Cap");
12963 if (val &&
12964 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12965 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053012966
12967 val = get_param(cmd, "Ch_Pref");
12968 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12969 return 0;
12970
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012971 return 1;
12972 }
12973
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012974 if (strcasecmp(prog, "60GHz") == 0)
12975 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
12976
Jouni Malinen6250cb02020-04-15 13:54:45 +030012977 if (strcasecmp(prog, "WPA3") == 0)
12978 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
12979
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012980 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
12981 return 0;
12982}
12983
12984
Jouni Malinenf7222712019-06-13 01:50:21 +030012985static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
12986 struct sigma_conn *conn,
12987 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012988{
12989 const char *intf = get_param(cmd, "Interface");
12990 const char *mode = get_param(cmd, "Mode");
12991 int res;
12992
12993 if (intf == NULL || mode == NULL)
12994 return -1;
12995
12996 if (strcasecmp(mode, "On") == 0)
12997 res = wpa_command(intf, "SET radio_disabled 0");
12998 else if (strcasecmp(mode, "Off") == 0)
12999 res = wpa_command(intf, "SET radio_disabled 1");
13000 else
13001 return -1;
13002
13003 if (res) {
13004 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
13005 "radio mode");
13006 return 0;
13007 }
13008
13009 return 1;
13010}
13011
13012
Jouni Malinenf7222712019-06-13 01:50:21 +030013013static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
13014 struct sigma_conn *conn,
13015 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013016{
13017 const char *intf = get_param(cmd, "Interface");
13018 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013019 const char *prog = get_param(cmd, "program");
13020 const char *powersave = get_param(cmd, "powersave");
13021 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013022
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013023 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013024 return -1;
13025
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013026 if (prog && strcasecmp(prog, "60GHz") == 0) {
13027 /*
13028 * The CAPI mode parameter does not exist in 60G
13029 * unscheduled PS.
13030 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080013031 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013032 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013033 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020013034 strcasecmp(prog, "HE") == 0) {
13035 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013036 } else {
13037 if (mode == NULL)
13038 return -1;
13039
13040 if (strcasecmp(mode, "On") == 0)
13041 res = set_ps(intf, dut, 1);
13042 else if (strcasecmp(mode, "Off") == 0)
13043 res = set_ps(intf, dut, 0);
13044 else
13045 return -1;
13046 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013047
13048 if (res) {
13049 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
13050 "power save mode");
13051 return 0;
13052 }
13053
13054 return 1;
13055}
13056
13057
Jouni Malinenf7222712019-06-13 01:50:21 +030013058static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
13059 struct sigma_conn *conn,
13060 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013061{
13062 const char *intf = get_param(cmd, "Interface");
13063 const char *val, *bssid;
13064 int res;
13065 char *buf;
13066 size_t buf_len;
13067
13068 val = get_param(cmd, "BSSID_FILTER");
13069 if (val == NULL)
13070 return -1;
13071
13072 bssid = get_param(cmd, "BSSID_List");
13073 if (atoi(val) == 0 || bssid == NULL) {
13074 /* Disable BSSID filter */
13075 if (wpa_command(intf, "SET bssid_filter ")) {
13076 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
13077 "to disable BSSID filter");
13078 return 0;
13079 }
13080
13081 return 1;
13082 }
13083
13084 buf_len = 100 + strlen(bssid);
13085 buf = malloc(buf_len);
13086 if (buf == NULL)
13087 return -1;
13088
13089 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
13090 res = wpa_command(intf, buf);
13091 free(buf);
13092 if (res) {
13093 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
13094 "BSSID filter");
13095 return 0;
13096 }
13097
13098 return 1;
13099}
13100
13101
Jouni Malinenf7222712019-06-13 01:50:21 +030013102static enum sigma_cmd_result cmd_sta_reset_parm(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");
13107 const char *val;
13108
13109 /* TODO: ARP */
13110
13111 val = get_param(cmd, "HS2_CACHE_PROFILE");
13112 if (val && strcasecmp(val, "All") == 0)
13113 hs2_clear_credentials(intf);
13114
13115 return 1;
13116}
13117
13118
Jouni Malinenf7222712019-06-13 01:50:21 +030013119static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
13120 struct sigma_conn *conn,
13121 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013122{
13123 const char *intf = get_param(cmd, "Interface");
13124 const char *key_type = get_param(cmd, "KeyType");
13125 char buf[100], resp[200];
13126
13127 if (key_type == NULL)
13128 return -1;
13129
13130 if (strcasecmp(key_type, "GTK") == 0) {
13131 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
13132 strncmp(buf, "FAIL", 4) == 0) {
13133 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13134 "not fetch current GTK");
13135 return 0;
13136 }
13137 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
13138 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13139 return 0;
13140 } else {
13141 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13142 "KeyType");
13143 return 0;
13144 }
13145
13146 return 1;
13147}
13148
13149
13150static int hs2_set_policy(struct sigma_dut *dut)
13151{
13152#ifdef ANDROID
13153 system("ip rule del prio 23000");
13154 if (system("ip rule add from all lookup main prio 23000") != 0) {
13155 sigma_dut_print(dut, DUT_MSG_ERROR,
13156 "Failed to run:ip rule add from all lookup main prio");
13157 return -1;
13158 }
13159 if (system("ip route flush cache") != 0) {
13160 sigma_dut_print(dut, DUT_MSG_ERROR,
13161 "Failed to run ip route flush cache");
13162 return -1;
13163 }
13164 return 1;
13165#else /* ANDROID */
13166 return 0;
13167#endif /* ANDROID */
13168}
13169
13170
Jouni Malinenf7222712019-06-13 01:50:21 +030013171static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
13172 struct sigma_conn *conn,
13173 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013174{
13175 const char *intf = get_param(cmd, "Interface");
13176 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030013177 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013178 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030013179 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013180 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
13181 int tries = 0;
13182 int ignore_blacklist = 0;
13183 const char *events[] = {
13184 "CTRL-EVENT-CONNECTED",
13185 "INTERWORKING-BLACKLISTED",
13186 "INTERWORKING-NO-MATCH",
13187 NULL
13188 };
13189
13190 start_sta_mode(dut);
13191
Jouni Malinen439352d2018-09-13 03:42:23 +030013192 if (band) {
13193 if (strcmp(band, "2.4") == 0) {
13194 wpa_command(intf, "SET setband 2G");
13195 } else if (strcmp(band, "5") == 0) {
13196 wpa_command(intf, "SET setband 5G");
13197 } else {
13198 send_resp(dut, conn, SIGMA_ERROR,
13199 "errorCode,Unsupported band");
13200 return 0;
13201 }
13202 }
13203
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013204 blacklisted[0] = '\0';
13205 if (val && atoi(val))
13206 ignore_blacklist = 1;
13207
13208try_again:
13209 ctrl = open_wpa_mon(intf);
13210 if (ctrl == NULL) {
13211 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13212 "wpa_supplicant monitor connection");
13213 return -2;
13214 }
13215
13216 tries++;
13217 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
13218 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
13219 "Interworking connection");
13220 wpa_ctrl_detach(ctrl);
13221 wpa_ctrl_close(ctrl);
13222 return 0;
13223 }
13224
13225 buf[0] = '\0';
13226 while (1) {
13227 char *pos;
13228 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13229 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
13230 if (!pos)
13231 break;
13232 pos += 25;
13233 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
13234 pos);
13235 if (!blacklisted[0])
13236 memcpy(blacklisted, pos, strlen(pos) + 1);
13237 }
13238
13239 if (ignore_blacklist && blacklisted[0]) {
13240 char *end;
13241 end = strchr(blacklisted, ' ');
13242 if (end)
13243 *end = '\0';
13244 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
13245 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030013246 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
13247 blacklisted);
13248 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013249 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
13250 wpa_ctrl_detach(ctrl);
13251 wpa_ctrl_close(ctrl);
13252 return 0;
13253 }
13254 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13255 buf, sizeof(buf));
13256 }
13257
13258 wpa_ctrl_detach(ctrl);
13259 wpa_ctrl_close(ctrl);
13260
13261 if (res < 0) {
13262 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
13263 "connect");
13264 return 0;
13265 }
13266
13267 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
13268 strstr(buf, "INTERWORKING-BLACKLISTED")) {
13269 if (tries < 2) {
13270 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
13271 goto try_again;
13272 }
13273 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
13274 "matching credentials found");
13275 return 0;
13276 }
13277
13278 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13279 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13280 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
13281 "get current BSSID/SSID");
13282 return 0;
13283 }
13284
13285 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
13286 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13287 hs2_set_policy(dut);
13288 return 0;
13289}
13290
13291
Jouni Malinenf7222712019-06-13 01:50:21 +030013292static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
13293 struct sigma_conn *conn,
13294 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013295{
13296 const char *intf = get_param(cmd, "Interface");
13297 const char *display = get_param(cmd, "Display");
13298 struct wpa_ctrl *ctrl;
13299 char buf[300], params[400], *pos;
13300 char bssid[20];
13301 int info_avail = 0;
13302 unsigned int old_timeout;
13303 int res;
13304
13305 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
13306 send_resp(dut, conn, SIGMA_ERROR,
13307 "ErrorCode,Could not get current BSSID");
13308 return 0;
13309 }
13310 ctrl = open_wpa_mon(intf);
13311 if (!ctrl) {
13312 sigma_dut_print(dut, DUT_MSG_ERROR,
13313 "Failed to open wpa_supplicant monitor connection");
13314 return -2;
13315 }
13316
13317 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
13318 wpa_command(intf, buf);
13319
13320 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
13321 if (res < 0) {
13322 send_resp(dut, conn, SIGMA_ERROR,
13323 "ErrorCode,Could not complete GAS query");
13324 goto fail;
13325 }
13326
13327 old_timeout = dut->default_timeout;
13328 dut->default_timeout = 2;
13329 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
13330 dut->default_timeout = old_timeout;
13331 if (res < 0)
13332 goto done;
13333 pos = strchr(buf, ' ');
13334 if (!pos)
13335 goto done;
13336 pos++;
13337 pos = strchr(pos, ' ');
13338 if (!pos)
13339 goto done;
13340 pos++;
13341 info_avail = 1;
13342 snprintf(params, sizeof(params), "browser %s", pos);
13343
13344 if (display && strcasecmp(display, "Yes") == 0) {
13345 pid_t pid;
13346
13347 pid = fork();
13348 if (pid < 0) {
13349 perror("fork");
13350 return -1;
13351 }
13352
13353 if (pid == 0) {
13354 run_hs20_osu(dut, params);
13355 exit(0);
13356 }
13357 }
13358
13359done:
13360 snprintf(buf, sizeof(buf), "Info_available,%s",
13361 info_avail ? "Yes" : "No");
13362 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13363fail:
13364 wpa_ctrl_detach(ctrl);
13365 wpa_ctrl_close(ctrl);
13366 return 0;
13367}
13368
13369
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013370static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
13371 struct sigma_conn *conn,
13372 const char *ifname,
13373 struct sigma_cmd *cmd)
13374{
13375 const char *val;
13376 int id;
13377
13378 id = add_cred(ifname);
13379 if (id < 0)
13380 return -2;
13381 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13382
13383 val = get_param(cmd, "prefer");
13384 if (val && atoi(val) > 0)
13385 set_cred(ifname, id, "priority", "1");
13386
13387 val = get_param(cmd, "REALM");
13388 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13389 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13390 "realm");
13391 return 0;
13392 }
13393
13394 val = get_param(cmd, "HOME_FQDN");
13395 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13396 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13397 "home_fqdn");
13398 return 0;
13399 }
13400
13401 val = get_param(cmd, "Username");
13402 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13403 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13404 "username");
13405 return 0;
13406 }
13407
13408 val = get_param(cmd, "Password");
13409 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
13410 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13411 "password");
13412 return 0;
13413 }
13414
13415 val = get_param(cmd, "ROOT_CA");
13416 if (val) {
13417 char fname[200];
13418 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13419#ifdef __linux__
13420 if (!file_exists(fname)) {
13421 char msg[300];
13422 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13423 "file (%s) not found", fname);
13424 send_resp(dut, conn, SIGMA_ERROR, msg);
13425 return 0;
13426 }
13427#endif /* __linux__ */
13428 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13429 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13430 "not set root CA");
13431 return 0;
13432 }
13433 }
13434
13435 return 1;
13436}
13437
13438
13439static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
13440{
13441 FILE *in, *out;
13442 char buf[500];
13443 int found = 0;
13444
13445 in = fopen("devdetail.xml", "r");
13446 if (in == NULL)
13447 return -1;
13448 out = fopen("devdetail.xml.tmp", "w");
13449 if (out == NULL) {
13450 fclose(in);
13451 return -1;
13452 }
13453
13454 while (fgets(buf, sizeof(buf), in)) {
13455 char *pos = strstr(buf, "<IMSI>");
13456 if (pos) {
13457 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
13458 imsi);
13459 pos += 6;
13460 *pos = '\0';
13461 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
13462 found++;
13463 } else {
13464 fprintf(out, "%s", buf);
13465 }
13466 }
13467
13468 fclose(out);
13469 fclose(in);
13470 if (found)
13471 rename("devdetail.xml.tmp", "devdetail.xml");
13472 else
13473 unlink("devdetail.xml.tmp");
13474
13475 return 0;
13476}
13477
13478
13479static int sta_add_credential_sim(struct sigma_dut *dut,
13480 struct sigma_conn *conn,
13481 const char *ifname, struct sigma_cmd *cmd)
13482{
13483 const char *val, *imsi = NULL;
13484 int id;
13485 char buf[200];
13486 int res;
13487 const char *pos;
13488 size_t mnc_len;
13489 char plmn_mcc[4];
13490 char plmn_mnc[4];
13491
13492 id = add_cred(ifname);
13493 if (id < 0)
13494 return -2;
13495 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13496
13497 val = get_param(cmd, "prefer");
13498 if (val && atoi(val) > 0)
13499 set_cred(ifname, id, "priority", "1");
13500
13501 val = get_param(cmd, "PLMN_MCC");
13502 if (val == NULL) {
13503 send_resp(dut, conn, SIGMA_ERROR,
13504 "errorCode,Missing PLMN_MCC");
13505 return 0;
13506 }
13507 if (strlen(val) != 3) {
13508 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
13509 return 0;
13510 }
13511 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
13512
13513 val = get_param(cmd, "PLMN_MNC");
13514 if (val == NULL) {
13515 send_resp(dut, conn, SIGMA_ERROR,
13516 "errorCode,Missing PLMN_MNC");
13517 return 0;
13518 }
13519 if (strlen(val) != 2 && strlen(val) != 3) {
13520 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
13521 return 0;
13522 }
13523 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
13524
13525 val = get_param(cmd, "IMSI");
13526 if (val == NULL) {
13527 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
13528 "IMSI");
13529 return 0;
13530 }
13531
13532 imsi = pos = val;
13533
13534 if (strncmp(plmn_mcc, pos, 3) != 0) {
13535 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
13536 return 0;
13537 }
13538 pos += 3;
13539
13540 mnc_len = strlen(plmn_mnc);
13541 if (mnc_len < 2) {
13542 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
13543 return 0;
13544 }
13545
13546 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
13547 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
13548 return 0;
13549 }
13550 pos += mnc_len;
13551
13552 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
13553 if (res < 0 || res >= (int) sizeof(buf))
13554 return -1;
13555 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
13556 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13557 "not set IMSI");
13558 return 0;
13559 }
13560
13561 val = get_param(cmd, "Password");
13562 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
13563 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13564 "not set password");
13565 return 0;
13566 }
13567
Jouni Malinenba630452018-06-22 11:49:59 +030013568 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013569 /*
13570 * Set provisioning_sp for the test cases where SIM/USIM
13571 * provisioning is used.
13572 */
13573 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
13574 "wi-fi.org") < 0) {
13575 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13576 "not set provisioning_sp");
13577 return 0;
13578 }
13579
13580 update_devdetail_imsi(dut, imsi);
13581 }
13582
13583 return 1;
13584}
13585
13586
13587static int sta_add_credential_cert(struct sigma_dut *dut,
13588 struct sigma_conn *conn,
13589 const char *ifname,
13590 struct sigma_cmd *cmd)
13591{
13592 const char *val;
13593 int id;
13594
13595 id = add_cred(ifname);
13596 if (id < 0)
13597 return -2;
13598 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13599
13600 val = get_param(cmd, "prefer");
13601 if (val && atoi(val) > 0)
13602 set_cred(ifname, id, "priority", "1");
13603
13604 val = get_param(cmd, "REALM");
13605 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13606 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13607 "realm");
13608 return 0;
13609 }
13610
13611 val = get_param(cmd, "HOME_FQDN");
13612 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13613 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13614 "home_fqdn");
13615 return 0;
13616 }
13617
13618 val = get_param(cmd, "Username");
13619 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13620 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13621 "username");
13622 return 0;
13623 }
13624
13625 val = get_param(cmd, "clientCertificate");
13626 if (val) {
13627 char fname[200];
13628 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13629#ifdef __linux__
13630 if (!file_exists(fname)) {
13631 char msg[300];
13632 snprintf(msg, sizeof(msg),
13633 "ErrorCode,clientCertificate "
13634 "file (%s) not found", fname);
13635 send_resp(dut, conn, SIGMA_ERROR, msg);
13636 return 0;
13637 }
13638#endif /* __linux__ */
13639 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
13640 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13641 "not set client_cert");
13642 return 0;
13643 }
13644 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
13645 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13646 "not set private_key");
13647 return 0;
13648 }
13649 }
13650
13651 val = get_param(cmd, "ROOT_CA");
13652 if (val) {
13653 char fname[200];
13654 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13655#ifdef __linux__
13656 if (!file_exists(fname)) {
13657 char msg[300];
13658 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13659 "file (%s) not found", fname);
13660 send_resp(dut, conn, SIGMA_ERROR, msg);
13661 return 0;
13662 }
13663#endif /* __linux__ */
13664 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13665 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13666 "not set root CA");
13667 return 0;
13668 }
13669 }
13670
13671 return 1;
13672}
13673
13674
Jouni Malinenf7222712019-06-13 01:50:21 +030013675static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
13676 struct sigma_conn *conn,
13677 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013678{
13679 const char *intf = get_param(cmd, "Interface");
13680 const char *type;
13681
13682 start_sta_mode(dut);
13683
13684 type = get_param(cmd, "Type");
13685 if (!type)
13686 return -1;
13687
13688 if (strcasecmp(type, "uname_pwd") == 0)
13689 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
13690
13691 if (strcasecmp(type, "sim") == 0)
13692 return sta_add_credential_sim(dut, conn, intf, cmd);
13693
13694 if (strcasecmp(type, "cert") == 0)
13695 return sta_add_credential_cert(dut, conn, intf, cmd);
13696
13697 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
13698 "type");
13699 return 0;
13700}
13701
13702
Jouni Malinenf7222712019-06-13 01:50:21 +030013703static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
13704 struct sigma_conn *conn,
13705 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013706{
13707 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013708 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Arif Hussain66a4af02019-02-07 15:04:51 -080013709 char buf[4096];
vamsi krishna89ad8c62017-09-19 12:51:18 +053013710 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013711 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013712 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013713 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013714 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013715
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020013716 start_sta_mode(dut);
13717
Arif Hussain66a4af02019-02-07 15:04:51 -080013718 val = get_param(cmd, "GetParameter");
13719 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013720 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080013721 buf, sizeof(buf)) < 0) {
13722 sigma_dut_print(dut, DUT_MSG_ERROR,
13723 "Could not get ssid bssid");
13724 return ERROR_SEND_STATUS;
13725 }
13726
13727 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
13728 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13729 return STATUS_SENT;
13730 }
13731
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013732 val = get_param(cmd, "HESSID");
13733 if (val) {
13734 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
13735 if (res < 0 || res >= (int) sizeof(buf))
13736 return -1;
13737 wpa_command(intf, buf);
13738 }
13739
13740 val = get_param(cmd, "ACCS_NET_TYPE");
13741 if (val) {
13742 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
13743 val);
13744 if (res < 0 || res >= (int) sizeof(buf))
13745 return -1;
13746 wpa_command(intf, buf);
13747 }
13748
vamsi krishna89ad8c62017-09-19 12:51:18 +053013749 bssid = get_param(cmd, "Bssid");
13750 ssid = get_param(cmd, "Ssid");
13751
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013752 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
13753 dut->device_type == STA_testbed) {
13754 ssid = NULL;
13755 wildcard_ssid = 1;
13756 }
13757
vamsi krishna89ad8c62017-09-19 12:51:18 +053013758 if (ssid) {
13759 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
13760 send_resp(dut, conn, SIGMA_ERROR,
13761 "ErrorCode,Too long SSID");
13762 return 0;
13763 }
13764 ascii2hexstr(ssid, ssid_hex);
13765 }
13766
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013767 short_ssid = get_param(cmd, "ShortSSID");
13768 if (short_ssid) {
13769 uint32_t short_ssid_hex;
13770
13771 short_ssid_hex = strtoul(short_ssid, NULL, 16);
13772 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
13773 (((short_ssid_hex >> 8) & 0xFF) << 16) |
13774 (((short_ssid_hex >> 16) & 0xFF) << 8) |
13775 ((short_ssid_hex >> 24) & 0xFF);
13776
13777 res = snprintf(buf, sizeof(buf),
13778 "VENDOR_ELEM_ADD 14 ff053a%08x",
13779 short_ssid_hex);
13780 if (res < 0 || res >= (int) sizeof(buf) ||
13781 wpa_command(intf, buf)) {
13782 send_resp(dut, conn, SIGMA_ERROR,
13783 "errorCode,Failed to add short SSID");
13784 return STATUS_SENT_ERROR;
13785 }
13786 }
13787
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013788 scan_freq = get_param(cmd, "ChnlFreq");
13789
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013790 val = get_param(cmd, "WaitCompletion");
13791 if (val && atoi(val) == 1) {
13792 ctrl = open_wpa_mon(intf);
13793 if (!ctrl) {
13794 send_resp(dut, conn, SIGMA_ERROR,
13795 "errorCode,Failed to open monitor socket");
13796 return STATUS_SENT_ERROR;
13797 }
13798 }
13799
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013800 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053013801 bssid ? " bssid=": "",
13802 bssid ? bssid : "",
13803 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013804 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013805 wildcard_ssid ? " wildcard_ssid=1" : "",
13806 scan_freq ? " freq=" : "",
13807 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013808 if (res < 0 || res >= (int) sizeof(buf)) {
13809 send_resp(dut, conn, SIGMA_ERROR,
13810 "errorCode,Could not build scan command");
13811 status = STATUS_SENT_ERROR;
13812 goto remove_s_ssid;
13813 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053013814
13815 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013816 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
13817 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013818 status = STATUS_SENT_ERROR;
13819 } else {
13820 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013821 }
13822
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013823remove_s_ssid:
13824 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
13825 sigma_dut_print(dut, DUT_MSG_ERROR,
13826 "Failed to delete vendor element");
13827
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013828 if (ctrl) {
13829 if (status == SUCCESS_SEND_STATUS) {
13830 res = get_wpa_cli_event(dut, ctrl,
13831 "CTRL-EVENT-SCAN-RESULTS",
13832 buf, sizeof(buf));
13833 if (res < 0) {
13834 send_resp(dut, conn, SIGMA_ERROR,
13835 "ErrorCode,scan did not complete");
13836 status = STATUS_SENT_ERROR;
13837 }
13838 }
13839
13840 wpa_ctrl_detach(ctrl);
13841 wpa_ctrl_close(ctrl);
13842 }
13843
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013844 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013845}
13846
13847
Jouni Malinenf7222712019-06-13 01:50:21 +030013848static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
13849 struct sigma_conn *conn,
13850 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013851{
13852 const char *intf = get_param(cmd, "Interface");
13853 const char *bssid;
13854 char buf[4096], *pos;
13855 int freq, chan;
13856 char *ssid;
13857 char resp[100];
13858 int res;
13859 struct wpa_ctrl *ctrl;
13860
13861 bssid = get_param(cmd, "BSSID");
13862 if (!bssid) {
13863 send_resp(dut, conn, SIGMA_INVALID,
13864 "errorCode,BSSID argument is missing");
13865 return 0;
13866 }
13867
13868 ctrl = open_wpa_mon(intf);
13869 if (!ctrl) {
13870 sigma_dut_print(dut, DUT_MSG_ERROR,
13871 "Failed to open wpa_supplicant monitor connection");
13872 return -1;
13873 }
13874
13875 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
13876 send_resp(dut, conn, SIGMA_ERROR,
13877 "errorCode,Could not start scan");
13878 wpa_ctrl_detach(ctrl);
13879 wpa_ctrl_close(ctrl);
13880 return 0;
13881 }
13882
13883 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
13884 buf, sizeof(buf));
13885
13886 wpa_ctrl_detach(ctrl);
13887 wpa_ctrl_close(ctrl);
13888
13889 if (res < 0) {
13890 send_resp(dut, conn, SIGMA_ERROR,
13891 "errorCode,Scan did not complete");
13892 return 0;
13893 }
13894
13895 snprintf(buf, sizeof(buf), "BSS %s", bssid);
13896 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
13897 strncmp(buf, "id=", 3) != 0) {
13898 send_resp(dut, conn, SIGMA_ERROR,
13899 "errorCode,Specified BSSID not found");
13900 return 0;
13901 }
13902
13903 pos = strstr(buf, "\nfreq=");
13904 if (!pos) {
13905 send_resp(dut, conn, SIGMA_ERROR,
13906 "errorCode,Channel not found");
13907 return 0;
13908 }
13909 freq = atoi(pos + 6);
13910 chan = freq_to_channel(freq);
13911
13912 pos = strstr(buf, "\nssid=");
13913 if (!pos) {
13914 send_resp(dut, conn, SIGMA_ERROR,
13915 "errorCode,SSID not found");
13916 return 0;
13917 }
13918 ssid = pos + 6;
13919 pos = strchr(ssid, '\n');
13920 if (pos)
13921 *pos = '\0';
13922 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
13923 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13924 return 0;
13925}
13926
13927
Jouni Malinenf7222712019-06-13 01:50:21 +030013928static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
13929 struct sigma_conn *conn,
13930 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013931{
13932#ifdef __linux__
13933 struct timeval tv;
13934 struct tm tm;
13935 time_t t;
13936 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013937 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013938
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013939 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013940
13941 memset(&tm, 0, sizeof(tm));
13942 val = get_param(cmd, "seconds");
13943 if (val)
13944 tm.tm_sec = atoi(val);
13945 val = get_param(cmd, "minutes");
13946 if (val)
13947 tm.tm_min = atoi(val);
13948 val = get_param(cmd, "hours");
13949 if (val)
13950 tm.tm_hour = atoi(val);
13951 val = get_param(cmd, "date");
13952 if (val)
13953 tm.tm_mday = atoi(val);
13954 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013955 if (val) {
13956 v = atoi(val);
13957 if (v < 1 || v > 12) {
13958 send_resp(dut, conn, SIGMA_INVALID,
13959 "errorCode,Invalid month");
13960 return 0;
13961 }
13962 tm.tm_mon = v - 1;
13963 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013964 val = get_param(cmd, "year");
13965 if (val) {
13966 int year = atoi(val);
13967#ifdef ANDROID
13968 if (year > 2035)
13969 year = 2035; /* years beyond 2035 not supported */
13970#endif /* ANDROID */
13971 tm.tm_year = year - 1900;
13972 }
13973 t = mktime(&tm);
13974 if (t == (time_t) -1) {
13975 send_resp(dut, conn, SIGMA_ERROR,
13976 "errorCode,Invalid date or time");
13977 return 0;
13978 }
13979
13980 memset(&tv, 0, sizeof(tv));
13981 tv.tv_sec = t;
13982
13983 if (settimeofday(&tv, NULL) < 0) {
13984 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
13985 strerror(errno));
13986 send_resp(dut, conn, SIGMA_ERROR,
13987 "errorCode,Failed to set time");
13988 return 0;
13989 }
13990
13991 return 1;
13992#endif /* __linux__ */
13993
13994 return -1;
13995}
13996
13997
Jouni Malinenf7222712019-06-13 01:50:21 +030013998static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
13999 struct sigma_conn *conn,
14000 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014001{
14002 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014003 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014004 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014005 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014006 int res;
14007 struct wpa_ctrl *ctrl;
14008
14009 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014010 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014011
14012 val = get_param(cmd, "ProdESSAssoc");
14013 if (val)
14014 prod_ess_assoc = atoi(val);
14015
14016 kill_dhcp_client(dut, intf);
14017 if (start_dhcp_client(dut, intf) < 0)
14018 return -2;
14019
14020 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
14021 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
14022 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014023 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014024 prod_ess_assoc ? "" : "-N",
14025 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014026 name ? "'" : "",
14027 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
14028 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014029
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053014030 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014031 if (run_hs20_osu(dut, buf) < 0) {
14032 FILE *f;
14033
14034 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
14035
14036 f = fopen("hs20-osu-client.res", "r");
14037 if (f) {
14038 char resp[400], res[300], *pos;
14039 if (!fgets(res, sizeof(res), f))
14040 res[0] = '\0';
14041 pos = strchr(res, '\n');
14042 if (pos)
14043 *pos = '\0';
14044 fclose(f);
14045 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
14046 res);
14047 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
14048 if (system(resp) != 0) {
14049 }
14050 snprintf(resp, sizeof(resp),
14051 "SSID,,BSSID,,failureReason,%s", res);
14052 send_resp(dut, conn, SIGMA_COMPLETE, resp);
14053 return 0;
14054 }
14055
14056 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
14057 return 0;
14058 }
14059
14060 if (!prod_ess_assoc)
14061 goto report;
14062
14063 ctrl = open_wpa_mon(intf);
14064 if (ctrl == NULL) {
14065 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14066 "wpa_supplicant monitor connection");
14067 return -1;
14068 }
14069
14070 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
14071 buf, sizeof(buf));
14072
14073 wpa_ctrl_detach(ctrl);
14074 wpa_ctrl_close(ctrl);
14075
14076 if (res < 0) {
14077 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
14078 "network after OSU");
14079 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
14080 return 0;
14081 }
14082
14083report:
14084 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
14085 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
14086 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
14087 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
14088 return 0;
14089 }
14090
14091 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
14092 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014093 return 0;
14094}
14095
14096
Jouni Malinenf7222712019-06-13 01:50:21 +030014097static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
14098 struct sigma_conn *conn,
14099 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014100{
14101 const char *val;
14102 int timeout = 120;
14103
14104 val = get_param(cmd, "PolicyUpdate");
14105 if (val == NULL || atoi(val) == 0)
14106 return 1; /* No operation requested */
14107
14108 val = get_param(cmd, "Timeout");
14109 if (val)
14110 timeout = atoi(val);
14111
14112 if (timeout) {
14113 /* TODO: time out the command and return
14114 * PolicyUpdateStatus,TIMEOUT if needed. */
14115 }
14116
14117 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
14118 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
14119 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
14120 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
14121 return 0;
14122 }
14123
14124 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
14125 return 0;
14126}
14127
14128
Jouni Malinenf7222712019-06-13 01:50:21 +030014129static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
14130 struct sigma_conn *conn,
14131 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014132{
14133 struct wpa_ctrl *ctrl;
14134 const char *intf = get_param(cmd, "Interface");
14135 const char *bssid = get_param(cmd, "Bssid");
14136 const char *ssid = get_param(cmd, "SSID");
14137 const char *security = get_param(cmd, "Security");
14138 const char *passphrase = get_param(cmd, "Passphrase");
14139 const char *pin = get_param(cmd, "PIN");
14140 char buf[1000];
14141 char ssid_hex[200], passphrase_hex[200];
14142 const char *keymgmt, *cipher;
14143
14144 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014145 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014146
14147 if (!bssid) {
14148 send_resp(dut, conn, SIGMA_ERROR,
14149 "ErrorCode,Missing Bssid argument");
14150 return 0;
14151 }
14152
14153 if (!ssid) {
14154 send_resp(dut, conn, SIGMA_ERROR,
14155 "ErrorCode,Missing SSID argument");
14156 return 0;
14157 }
14158
14159 if (!security) {
14160 send_resp(dut, conn, SIGMA_ERROR,
14161 "ErrorCode,Missing Security argument");
14162 return 0;
14163 }
14164
14165 if (!passphrase) {
14166 send_resp(dut, conn, SIGMA_ERROR,
14167 "ErrorCode,Missing Passphrase argument");
14168 return 0;
14169 }
14170
14171 if (!pin) {
14172 send_resp(dut, conn, SIGMA_ERROR,
14173 "ErrorCode,Missing PIN argument");
14174 return 0;
14175 }
14176
vamsi krishna8c9c1562017-05-12 15:51:46 +053014177 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
14178 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014179 send_resp(dut, conn, SIGMA_ERROR,
14180 "ErrorCode,Too long SSID/passphrase");
14181 return 0;
14182 }
14183
14184 ctrl = open_wpa_mon(intf);
14185 if (ctrl == NULL) {
14186 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14187 "wpa_supplicant monitor connection");
14188 return -2;
14189 }
14190
14191 if (strcasecmp(security, "wpa2-psk") == 0) {
14192 keymgmt = "WPA2PSK";
14193 cipher = "CCMP";
14194 } else {
14195 wpa_ctrl_detach(ctrl);
14196 wpa_ctrl_close(ctrl);
14197 send_resp(dut, conn, SIGMA_ERROR,
14198 "ErrorCode,Unsupported Security value");
14199 return 0;
14200 }
14201
14202 ascii2hexstr(ssid, ssid_hex);
14203 ascii2hexstr(passphrase, passphrase_hex);
14204 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
14205 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
14206
14207 if (wpa_command(intf, buf) < 0) {
14208 wpa_ctrl_detach(ctrl);
14209 wpa_ctrl_close(ctrl);
14210 send_resp(dut, conn, SIGMA_ERROR,
14211 "ErrorCode,Failed to start registrar");
14212 return 0;
14213 }
14214
14215 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
14216 dut->er_oper_performed = 1;
14217
14218 return wps_connection_event(dut, conn, ctrl, intf, 0);
14219}
14220
14221
Jouni Malinenf7222712019-06-13 01:50:21 +030014222static enum sigma_cmd_result
14223cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
14224 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014225{
14226 struct wpa_ctrl *ctrl;
14227 const char *intf = get_param(cmd, "Interface");
14228 const char *bssid = get_param(cmd, "Bssid");
14229 char buf[100];
14230
14231 if (!bssid) {
14232 send_resp(dut, conn, SIGMA_ERROR,
14233 "ErrorCode,Missing Bssid argument");
14234 return 0;
14235 }
14236
14237 ctrl = open_wpa_mon(intf);
14238 if (ctrl == NULL) {
14239 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14240 "wpa_supplicant monitor connection");
14241 return -2;
14242 }
14243
14244 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
14245
14246 if (wpa_command(intf, buf) < 0) {
14247 wpa_ctrl_detach(ctrl);
14248 wpa_ctrl_close(ctrl);
14249 send_resp(dut, conn, SIGMA_ERROR,
14250 "ErrorCode,Failed to start registrar");
14251 return 0;
14252 }
14253
14254 return wps_connection_event(dut, conn, ctrl, intf, 0);
14255}
14256
14257
Jouni Malinenf7222712019-06-13 01:50:21 +030014258static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
14259 struct sigma_conn *conn,
14260 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053014261{
14262 struct wpa_ctrl *ctrl;
14263 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014264 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014265 const char *config_method = get_param(cmd, "WPSConfigMethod");
14266 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053014267 int res;
14268 char buf[256];
14269 const char *events[] = {
14270 "CTRL-EVENT-CONNECTED",
14271 "WPS-OVERLAP-DETECTED",
14272 "WPS-TIMEOUT",
14273 "WPS-FAIL",
14274 NULL
14275 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014276 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053014277
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014278 /* 60G WPS tests do not pass Interface parameter */
14279 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014280 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014281
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014282 if (dut->mode == SIGMA_MODE_AP)
14283 return ap_wps_registration(dut, conn, cmd);
14284
14285 if (config_method) {
14286 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
14287 * sta_wps_enter_pin before calling start_wps_registration. */
14288 if (strcasecmp(config_method, "PBC") == 0)
14289 dut->wps_method = WFA_CS_WPS_PBC;
14290 }
14291 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
14292 send_resp(dut, conn, SIGMA_ERROR,
14293 "ErrorCode,WPS parameters not yet set");
14294 return STATUS_SENT;
14295 }
14296
14297 /* Make sure WPS is enabled (also for STA mode) */
14298 dut->wps_disable = 0;
14299
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014300 if (dut->band == WPS_BAND_60G && network_mode &&
14301 strcasecmp(network_mode, "PBSS") == 0) {
14302 sigma_dut_print(dut, DUT_MSG_DEBUG,
14303 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014304 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014305 return -2;
14306 }
14307
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020014308 if (dut->force_rsn_ie) {
14309 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
14310 dut->force_rsn_ie);
14311 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
14312 sigma_dut_print(dut, DUT_MSG_INFO,
14313 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014314 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020014315 }
14316 }
14317
vamsi krishna9b144002017-09-20 13:28:13 +053014318 ctrl = open_wpa_mon(intf);
14319 if (!ctrl) {
14320 sigma_dut_print(dut, DUT_MSG_ERROR,
14321 "Failed to open wpa_supplicant monitor connection");
14322 return -2;
14323 }
14324
14325 role = get_param(cmd, "WpsRole");
14326 if (!role) {
14327 send_resp(dut, conn, SIGMA_INVALID,
14328 "ErrorCode,WpsRole not provided");
14329 goto fail;
14330 }
14331
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014332 if (strcasecmp(role, "Enrollee") != 0) {
14333 /* Registrar role for STA not supported */
14334 send_resp(dut, conn, SIGMA_ERROR,
14335 "ErrorCode,Unsupported WpsRole value");
14336 goto fail;
14337 }
14338
14339 if (is_60g_sigma_dut(dut)) {
14340 if (dut->wps_method == WFA_CS_WPS_PBC)
14341 snprintf(buf, sizeof(buf), "WPS_PBC");
14342 else /* WFA_CS_WPS_PIN_KEYPAD */
14343 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
14344 dut->wps_pin);
14345 if (wpa_command(intf, buf) < 0) {
14346 send_resp(dut, conn, SIGMA_ERROR,
14347 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053014348 goto fail;
14349 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014350 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
14351 if (res < 0) {
14352 send_resp(dut, conn, SIGMA_ERROR,
14353 "ErrorCode,WPS connection did not complete");
14354 goto fail;
14355 }
14356 if (strstr(buf, "WPS-TIMEOUT")) {
14357 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
14358 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
14359 send_resp(dut, conn, SIGMA_COMPLETE,
14360 "WpsState,OverlapSession");
14361 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
14362 send_resp(dut, conn, SIGMA_COMPLETE,
14363 "WpsState,Successful");
14364 } else {
14365 send_resp(dut, conn, SIGMA_COMPLETE,
14366 "WpsState,Failure");
14367 }
14368 } else {
14369 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053014370 if (wpa_command(intf, "WPS_PBC") < 0) {
14371 send_resp(dut, conn, SIGMA_ERROR,
14372 "ErrorCode,Failed to enable PBC");
14373 goto fail;
14374 }
14375 } else {
14376 /* TODO: PIN method */
14377 send_resp(dut, conn, SIGMA_ERROR,
14378 "ErrorCode,Unsupported WpsConfigMethod value");
14379 goto fail;
14380 }
14381 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
14382 if (res < 0) {
14383 send_resp(dut, conn, SIGMA_ERROR,
14384 "ErrorCode,WPS connection did not complete");
14385 goto fail;
14386 }
14387 if (strstr(buf, "WPS-TIMEOUT")) {
14388 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
14389 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
14390 send_resp(dut, conn, SIGMA_ERROR,
14391 "ErrorCode,OverlapSession");
14392 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
14393 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
14394 } else {
14395 send_resp(dut, conn, SIGMA_ERROR,
14396 "ErrorCode,WPS operation failed");
14397 }
vamsi krishna9b144002017-09-20 13:28:13 +053014398 }
14399
14400fail:
14401 wpa_ctrl_detach(ctrl);
14402 wpa_ctrl_close(ctrl);
14403 return 0;
14404}
14405
14406
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014407static int req_intf(struct sigma_cmd *cmd)
14408{
14409 return get_param(cmd, "interface") == NULL ? -1 : 0;
14410}
14411
14412
14413void sta_register_cmds(void)
14414{
14415 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
14416 cmd_sta_get_ip_config);
14417 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
14418 cmd_sta_set_ip_config);
14419 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
14420 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
14421 cmd_sta_get_mac_address);
14422 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
14423 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
14424 cmd_sta_verify_ip_connection);
14425 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
14426 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
14427 cmd_sta_set_encryption);
14428 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
14429 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
14430 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
14431 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
14432 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
14433 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
14434 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
14435 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
14436 cmd_sta_set_eapakaprime);
14437 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
14438 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
14439 /* TODO: sta_set_ibss */
14440 /* TODO: sta_set_mode */
14441 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
14442 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
14443 /* TODO: sta_up_load */
14444 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
14445 cmd_sta_preset_testparameters);
14446 /* TODO: sta_set_system */
14447 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
14448 /* TODO: sta_set_rifs_test */
14449 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
14450 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
14451 /* TODO: sta_send_coexist_mgmt */
14452 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
14453 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
14454 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
14455 sigma_dut_reg_cmd("sta_reset_default", req_intf,
14456 cmd_sta_reset_default);
14457 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
14458 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
14459 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
14460 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
14461 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014462 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014463 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
14464 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
14465 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
14466 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
14467 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030014468 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
14469 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014470 sigma_dut_reg_cmd("sta_add_credential", req_intf,
14471 cmd_sta_add_credential);
14472 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020014473 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014474 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
14475 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
14476 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
14477 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
14478 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
14479 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030014480 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014481 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
14482 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014483 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053014484 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014485}