blob: bb03e0279fdf3542f8eeff0fac87380eed73a0ca [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
Veerendranath Jakkama9177042020-08-10 00:14:03 +05302309 val = get_param(cmd, "sae_pk_only");
2310 if (val && strcmp(val, "1") == 0 &&
2311 set_network(ifname, id, "sae_pk", "1") < 0)
2312 return ERROR_SEND_STATUS;
2313
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002314 if (dut->program == PROGRAM_60GHZ && network_mode &&
2315 strcasecmp(network_mode, "PBSS") == 0 &&
2316 set_network(ifname, id, "pbss", "1") < 0)
2317 return -2;
2318
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002319 return 1;
2320}
2321
2322
Jouni Malinen8ac93452019-08-14 15:19:13 +03002323static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2324 struct sigma_conn *conn,
2325 const char *ifname, int id)
2326{
2327 char buf[200];
2328
2329 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2330 if (!file_exists(buf))
2331 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2332 if (!file_exists(buf))
2333 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2334 if (!file_exists(buf)) {
2335 char msg[300];
2336
2337 snprintf(msg, sizeof(msg),
2338 "ErrorCode,trustedRootCA system store (%s) not found",
2339 buf);
2340 send_resp(dut, conn, SIGMA_ERROR, msg);
2341 return STATUS_SENT_ERROR;
2342 }
2343
2344 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2345 return ERROR_SEND_STATUS;
2346
2347 return SUCCESS_SEND_STATUS;
2348}
2349
2350
2351static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2352 struct sigma_conn *conn,
2353 const char *ifname, int id,
2354 const char *val)
2355{
2356 char buf[200];
2357#ifdef ANDROID
2358 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2359 int length;
2360#endif /* ANDROID */
2361
2362 if (strcmp(val, "DEFAULT") == 0)
2363 return set_trust_root_system(dut, conn, ifname, id);
2364
2365#ifdef ANDROID
2366 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2367 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2368 if (length > 0) {
2369 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2370 buf);
2371 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2372 goto ca_cert_selected;
2373 }
2374#endif /* ANDROID */
2375
2376 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2377#ifdef __linux__
2378 if (!file_exists(buf)) {
2379 char msg[300];
2380
2381 snprintf(msg, sizeof(msg),
2382 "ErrorCode,trustedRootCA file (%s) not found", buf);
2383 send_resp(dut, conn, SIGMA_ERROR, msg);
2384 return STATUS_SENT_ERROR;
2385 }
2386#endif /* __linux__ */
2387#ifdef ANDROID
2388ca_cert_selected:
2389#endif /* ANDROID */
2390 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2391 return ERROR_SEND_STATUS;
2392
2393 return SUCCESS_SEND_STATUS;
2394}
2395
2396
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002397static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302398 const char *ifname, int username_identity,
2399 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002400{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002401 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002402 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002403 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002404 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002405 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002406
2407 id = set_wpa_common(dut, conn, ifname, cmd);
2408 if (id < 0)
2409 return id;
2410
2411 val = get_param(cmd, "keyMgmtType");
2412 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302413 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002414 trust_root = get_param(cmd, "trustedRootCA");
2415 domain = get_param(cmd, "Domain");
2416 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002417
Jouni Malinenad395a22017-09-01 21:13:46 +03002418 if (val && strcasecmp(val, "SuiteB") == 0) {
2419 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2420 0)
2421 return -2;
2422 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002423 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2424 return -2;
2425 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2426 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2427 return -2;
2428 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2429 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2430 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002431 } else if (!akm &&
2432 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2433 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002434 if (set_network(ifname, id, "key_mgmt",
2435 "WPA-EAP WPA-EAP-SHA256") < 0)
2436 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302437 } else if (akm && atoi(akm) == 14) {
2438 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2439 dut->sta_pmf == STA_PMF_REQUIRED) {
2440 if (set_network(ifname, id, "key_mgmt",
2441 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2442 return -2;
2443 } else {
2444 if (set_network(ifname, id, "key_mgmt",
2445 "WPA-EAP FILS-SHA256") < 0)
2446 return -2;
2447 }
2448
Jouni Malinen8179fee2019-03-28 03:19:47 +02002449 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302450 } else if (akm && atoi(akm) == 15) {
2451 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2452 dut->sta_pmf == STA_PMF_REQUIRED) {
2453 if (set_network(ifname, id, "key_mgmt",
2454 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2455 return -2;
2456 } else {
2457 if (set_network(ifname, id, "key_mgmt",
2458 "WPA-EAP FILS-SHA384") < 0)
2459 return -2;
2460 }
2461
Jouni Malinen8179fee2019-03-28 03:19:47 +02002462 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002463 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002464 if (set_network(ifname, id, "key_mgmt",
2465 "WPA-EAP WPA-EAP-SHA256") < 0)
2466 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002467 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002468 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2469 return -2;
2470 }
2471
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002472 if (trust_root) {
2473 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2474 !domain_suffix) {
2475 send_resp(dut, conn, SIGMA_ERROR,
2476 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2477 return STATUS_SENT_ERROR;
2478 }
2479 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002480 if (res != SUCCESS_SEND_STATUS)
2481 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002482 }
2483
Jouni Malinen53264f62019-05-03 13:04:40 +03002484 val = get_param(cmd, "ServerCert");
2485 if (val) {
2486 FILE *f;
2487 char *result = NULL, *pos;
2488
2489 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2490 val);
2491 f = fopen(buf, "r");
2492 if (f) {
2493 result = fgets(buf, sizeof(buf), f);
2494 fclose(f);
2495 }
2496 if (!result) {
2497 snprintf(buf2, sizeof(buf2),
2498 "ErrorCode,ServerCert hash could not be read from %s",
2499 buf);
2500 send_resp(dut, conn, SIGMA_ERROR, buf2);
2501 return STATUS_SENT_ERROR;
2502 }
2503 pos = strchr(buf, '\n');
2504 if (pos)
2505 *pos = '\0';
2506 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2507 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2508 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002509
2510 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2511 if (file_exists(buf)) {
2512 sigma_dut_print(dut, DUT_MSG_DEBUG,
2513 "TOD policy enabled for the configured ServerCert hash");
2514 dut->sta_tod_policy = 1;
2515 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002516 }
2517
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002518 if (domain &&
2519 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002520 return ERROR_SEND_STATUS;
2521
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002522 if (domain_suffix &&
2523 set_network_quoted(ifname, id, "domain_suffix_match",
2524 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002525 return ERROR_SEND_STATUS;
2526
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302527 if (username_identity) {
2528 val = get_param(cmd, "username");
2529 if (val) {
2530 if (set_network_quoted(ifname, id, "identity", val) < 0)
2531 return -2;
2532 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002533
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302534 val = get_param(cmd, "password");
2535 if (val) {
2536 if (set_network_quoted(ifname, id, "password", val) < 0)
2537 return -2;
2538 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002539 }
2540
Jouni Malinen8179fee2019-03-28 03:19:47 +02002541 if (dut->akm_values &
2542 ((1 << AKM_FILS_SHA256) |
2543 (1 << AKM_FILS_SHA384) |
2544 (1 << AKM_FT_FILS_SHA256) |
2545 (1 << AKM_FT_FILS_SHA384)))
2546 erp = 1;
2547 if (erp && set_network(ifname, id, "erp", "1") < 0)
2548 return ERROR_SEND_STATUS;
2549
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002550 dut->sta_associate_wait_connect = 1;
2551
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002552 return id;
2553}
2554
2555
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002556static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2557{
2558 const char *val;
2559
2560 if (!cipher)
2561 return 0;
2562
2563 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2564 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2565 else if (strcasecmp(cipher,
2566 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2567 val = "ECDHE-RSA-AES256-GCM-SHA384";
2568 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2569 val = "DHE-RSA-AES256-GCM-SHA384";
2570 else if (strcasecmp(cipher,
2571 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2572 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2573 else
2574 return -1;
2575
2576 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2577 set_network_quoted(ifname, id, "phase1", "");
2578
2579 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2580}
2581
2582
Jouni Malinenf7222712019-06-13 01:50:21 +03002583static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2584 struct sigma_conn *conn,
2585 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002586{
2587 const char *intf = get_param(cmd, "Interface");
2588 const char *ifname, *val;
2589 int id;
2590 char buf[200];
2591#ifdef ANDROID
2592 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2593 int length;
2594 int jb_or_newer = 0;
2595 char prop[PROPERTY_VALUE_MAX];
2596#endif /* ANDROID */
2597
2598 if (intf == NULL)
2599 return -1;
2600
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002601 if (strcmp(intf, get_main_ifname(dut)) == 0)
2602 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002603 else
2604 ifname = intf;
2605
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302606 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002607 if (id < 0)
2608 return id;
2609
2610 if (set_network(ifname, id, "eap", "TLS") < 0)
2611 return -2;
2612
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302613 if (!get_param(cmd, "username") &&
2614 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002615 "wifi-user@wifilabs.local") < 0)
2616 return -2;
2617
2618 val = get_param(cmd, "clientCertificate");
2619 if (val == NULL)
2620 return -1;
2621#ifdef ANDROID
2622 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2623 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2624 if (length < 0) {
2625 /*
2626 * JB started reporting keystore type mismatches, so retry with
2627 * the GET_PUBKEY command if the generic GET fails.
2628 */
2629 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2630 buf, kvalue);
2631 }
2632
2633 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2634 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2635 if (strncmp(prop, "4.0", 3) != 0)
2636 jb_or_newer = 1;
2637 } else
2638 jb_or_newer = 1; /* assume newer */
2639
2640 if (jb_or_newer && length > 0) {
2641 sigma_dut_print(dut, DUT_MSG_INFO,
2642 "Use Android keystore [%s]", buf);
2643 if (set_network(ifname, id, "engine", "1") < 0)
2644 return -2;
2645 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2646 return -2;
2647 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2648 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2649 return -2;
2650 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2651 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2652 return -2;
2653 return 1;
2654 } else if (length > 0) {
2655 sigma_dut_print(dut, DUT_MSG_INFO,
2656 "Use Android keystore [%s]", buf);
2657 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2658 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2659 return -2;
2660 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2661 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2662 return -2;
2663 return 1;
2664 }
2665#endif /* ANDROID */
2666
2667 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2668#ifdef __linux__
2669 if (!file_exists(buf)) {
2670 char msg[300];
2671 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2672 "(%s) not found", buf);
2673 send_resp(dut, conn, SIGMA_ERROR, msg);
2674 return -3;
2675 }
2676#endif /* __linux__ */
2677 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2678 return -2;
2679 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2680 return -2;
2681
2682 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2683 return -2;
2684
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002685 val = get_param(cmd, "keyMgmtType");
2686 if (val && strcasecmp(val, "SuiteB") == 0) {
2687 val = get_param(cmd, "CertType");
2688 if (val && strcasecmp(val, "RSA") == 0) {
2689 if (set_network_quoted(ifname, id, "phase1",
2690 "tls_suiteb=1") < 0)
2691 return -2;
2692 } else {
2693 if (set_network_quoted(ifname, id, "openssl_ciphers",
2694 "SUITEB192") < 0)
2695 return -2;
2696 }
2697
2698 val = get_param(cmd, "TLSCipher");
2699 if (set_tls_cipher(ifname, id, val) < 0) {
2700 send_resp(dut, conn, SIGMA_ERROR,
2701 "ErrorCode,Unsupported TLSCipher value");
2702 return -3;
2703 }
2704 }
2705
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002706 return 1;
2707}
2708
2709
Jouni Malinenf7222712019-06-13 01:50:21 +03002710static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2711 struct sigma_conn *conn,
2712 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002713{
2714 const char *intf = get_param(cmd, "Interface");
2715 const char *ifname;
2716 int id;
2717
2718 if (intf == NULL)
2719 return -1;
2720
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002721 if (strcmp(intf, get_main_ifname(dut)) == 0)
2722 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002723 else
2724 ifname = intf;
2725
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302726 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002727 if (id < 0)
2728 return id;
2729
2730 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2731 send_resp(dut, conn, SIGMA_ERROR,
2732 "errorCode,Failed to set TTLS method");
2733 return 0;
2734 }
2735
2736 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2737 send_resp(dut, conn, SIGMA_ERROR,
2738 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2739 return 0;
2740 }
2741
2742 return 1;
2743}
2744
2745
Jouni Malinenf7222712019-06-13 01:50:21 +03002746static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2747 struct sigma_conn *conn,
2748 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002749{
2750 const char *intf = get_param(cmd, "Interface");
2751 const char *ifname;
2752 int id;
2753
2754 if (intf == NULL)
2755 return -1;
2756
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002757 if (strcmp(intf, get_main_ifname(dut)) == 0)
2758 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002759 else
2760 ifname = intf;
2761
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302762 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002763 if (id < 0)
2764 return id;
2765
2766 if (set_network(ifname, id, "eap", "SIM") < 0)
2767 return -2;
2768
2769 return 1;
2770}
2771
2772
Jouni Malinenf7222712019-06-13 01:50:21 +03002773static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2774 struct sigma_conn *conn,
2775 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002776{
2777 const char *intf = get_param(cmd, "Interface");
2778 const char *ifname, *val;
2779 int id;
2780 char buf[100];
2781
2782 if (intf == NULL)
2783 return -1;
2784
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002785 if (strcmp(intf, get_main_ifname(dut)) == 0)
2786 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002787 else
2788 ifname = intf;
2789
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302790 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002791 if (id < 0)
2792 return id;
2793
2794 if (set_network(ifname, id, "eap", "PEAP") < 0)
2795 return -2;
2796
2797 val = get_param(cmd, "innerEAP");
2798 if (val) {
2799 if (strcasecmp(val, "MSCHAPv2") == 0) {
2800 if (set_network_quoted(ifname, id, "phase2",
2801 "auth=MSCHAPV2") < 0)
2802 return -2;
2803 } else if (strcasecmp(val, "GTC") == 0) {
2804 if (set_network_quoted(ifname, id, "phase2",
2805 "auth=GTC") < 0)
2806 return -2;
2807 } else
2808 return -1;
2809 }
2810
2811 val = get_param(cmd, "peapVersion");
2812 if (val) {
2813 int ver = atoi(val);
2814 if (ver < 0 || ver > 1)
2815 return -1;
2816 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2817 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2818 return -2;
2819 }
2820
2821 return 1;
2822}
2823
2824
Jouni Malinenf7222712019-06-13 01:50:21 +03002825static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2826 struct sigma_conn *conn,
2827 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002828{
2829 const char *intf = get_param(cmd, "Interface");
2830 const char *ifname, *val;
2831 int id;
2832 char buf[100];
2833
2834 if (intf == NULL)
2835 return -1;
2836
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002837 if (strcmp(intf, get_main_ifname(dut)) == 0)
2838 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002839 else
2840 ifname = intf;
2841
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302842 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002843 if (id < 0)
2844 return id;
2845
2846 if (set_network(ifname, id, "eap", "FAST") < 0)
2847 return -2;
2848
2849 val = get_param(cmd, "innerEAP");
2850 if (val) {
2851 if (strcasecmp(val, "MSCHAPV2") == 0) {
2852 if (set_network_quoted(ifname, id, "phase2",
2853 "auth=MSCHAPV2") < 0)
2854 return -2;
2855 } else if (strcasecmp(val, "GTC") == 0) {
2856 if (set_network_quoted(ifname, id, "phase2",
2857 "auth=GTC") < 0)
2858 return -2;
2859 } else
2860 return -1;
2861 }
2862
2863 val = get_param(cmd, "validateServer");
2864 if (val) {
2865 /* TODO */
2866 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2867 "validateServer=%s", val);
2868 }
2869
2870 val = get_param(cmd, "pacFile");
2871 if (val) {
2872 snprintf(buf, sizeof(buf), "blob://%s", val);
2873 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2874 return -2;
2875 }
2876
2877 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2878 0)
2879 return -2;
2880
2881 return 1;
2882}
2883
2884
Jouni Malinenf7222712019-06-13 01:50:21 +03002885static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2886 struct sigma_conn *conn,
2887 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002888{
2889 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302890 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002891 const char *ifname;
2892 int id;
2893
2894 if (intf == NULL)
2895 return -1;
2896
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002897 if (strcmp(intf, get_main_ifname(dut)) == 0)
2898 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002899 else
2900 ifname = intf;
2901
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302902 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002903 if (id < 0)
2904 return id;
2905
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302906 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2907 * hexadecimal).
2908 */
2909 if (username && username[0] == '6') {
2910 if (set_network(ifname, id, "eap", "AKA'") < 0)
2911 return -2;
2912 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002913 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302914 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002915
2916 return 1;
2917}
2918
2919
Jouni Malinenf7222712019-06-13 01:50:21 +03002920static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2921 struct sigma_conn *conn,
2922 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002923{
2924 const char *intf = get_param(cmd, "Interface");
2925 const char *ifname;
2926 int id;
2927
2928 if (intf == NULL)
2929 return -1;
2930
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002931 if (strcmp(intf, get_main_ifname(dut)) == 0)
2932 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002933 else
2934 ifname = intf;
2935
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302936 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002937 if (id < 0)
2938 return id;
2939
2940 if (set_network(ifname, id, "eap", "AKA'") < 0)
2941 return -2;
2942
2943 return 1;
2944}
2945
2946
2947static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2948 struct sigma_cmd *cmd)
2949{
2950 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002951 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002952 const char *ifname;
2953 int id;
2954
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002955 if (strcmp(intf, get_main_ifname(dut)) == 0)
2956 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002957 else
2958 ifname = intf;
2959
2960 id = add_network_common(dut, conn, ifname, cmd);
2961 if (id < 0)
2962 return id;
2963
2964 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2965 return -2;
2966
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002967 if (dut->program == PROGRAM_60GHZ && network_mode &&
2968 strcasecmp(network_mode, "PBSS") == 0 &&
2969 set_network(ifname, id, "pbss", "1") < 0)
2970 return -2;
2971
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002972 return 1;
2973}
2974
2975
Jouni Malinen8e3f8812020-10-05 10:02:03 +03002976static enum sigma_cmd_result sta_set_owe(struct sigma_dut *dut,
2977 struct sigma_conn *conn,
2978 struct sigma_cmd *cmd)
Jouni Malinen47dcc952017-10-09 16:43:24 +03002979{
2980 const char *intf = get_param(cmd, "Interface");
2981 const char *ifname, *val;
2982 int id;
2983
2984 if (intf == NULL)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03002985 return INVALID_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03002986
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002987 if (strcmp(intf, get_main_ifname(dut)) == 0)
2988 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002989 else
2990 ifname = intf;
2991
2992 id = set_wpa_common(dut, conn, ifname, cmd);
2993 if (id < 0)
2994 return id;
2995
2996 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03002997 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03002998
Hu Wangdd5eed22020-07-16 12:18:03 +08002999 if (dut->owe_ptk_workaround &&
3000 set_network(ifname, id, "owe_ptk_workaround", "1") < 0) {
3001 sigma_dut_print(dut, DUT_MSG_ERROR,
3002 "Failed to set owe_ptk_workaround to 1");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003003 return ERROR_SEND_STATUS;
Hu Wangdd5eed22020-07-16 12:18:03 +08003004 }
3005
Jouni Malinen47dcc952017-10-09 16:43:24 +03003006 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003007 if (val && strcmp(val, "0") == 0) {
3008 if (wpa_command(ifname,
3009 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
3010 sigma_dut_print(dut, DUT_MSG_ERROR,
3011 "Failed to set OWE DH Param element override");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003012 return ERROR_SEND_STATUS;
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003013 }
Hu Wangdd5eed22020-07-16 12:18:03 +08003014 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003015 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003016 "Failed to set owe_group");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003017 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003018 }
3019
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003020 return SUCCESS_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003021}
3022
3023
Jouni Malinenf7222712019-06-13 01:50:21 +03003024static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3025 struct sigma_conn *conn,
3026 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003027{
3028 const char *type = get_param(cmd, "Type");
3029
3030 if (type == NULL) {
3031 send_resp(dut, conn, SIGMA_ERROR,
3032 "ErrorCode,Missing Type argument");
3033 return 0;
3034 }
3035
3036 if (strcasecmp(type, "OPEN") == 0)
3037 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003038 if (strcasecmp(type, "OWE") == 0)
3039 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003040 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003041 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003042 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003043 return cmd_sta_set_psk(dut, conn, cmd);
3044 if (strcasecmp(type, "EAPTLS") == 0)
3045 return cmd_sta_set_eaptls(dut, conn, cmd);
3046 if (strcasecmp(type, "EAPTTLS") == 0)
3047 return cmd_sta_set_eapttls(dut, conn, cmd);
3048 if (strcasecmp(type, "EAPPEAP") == 0)
3049 return cmd_sta_set_peap(dut, conn, cmd);
3050 if (strcasecmp(type, "EAPSIM") == 0)
3051 return cmd_sta_set_eapsim(dut, conn, cmd);
3052 if (strcasecmp(type, "EAPFAST") == 0)
3053 return cmd_sta_set_eapfast(dut, conn, cmd);
3054 if (strcasecmp(type, "EAPAKA") == 0)
3055 return cmd_sta_set_eapaka(dut, conn, cmd);
3056 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3057 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003058 if (strcasecmp(type, "wep") == 0)
3059 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003060
3061 send_resp(dut, conn, SIGMA_ERROR,
3062 "ErrorCode,Unsupported Type value");
3063 return 0;
3064}
3065
3066
3067int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3068{
3069#ifdef __linux__
3070 /* special handling for ath6kl */
3071 char path[128], fname[128], *pos;
3072 ssize_t res;
3073 FILE *f;
3074
Jouni Malinene39cd562019-05-29 23:39:56 +03003075 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3076 intf);
3077 if (res < 0 || res >= sizeof(fname))
3078 return 0;
3079 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003080 if (res < 0)
3081 return 0; /* not ath6kl */
3082
3083 if (res >= (int) sizeof(path))
3084 res = sizeof(path) - 1;
3085 path[res] = '\0';
3086 pos = strrchr(path, '/');
3087 if (pos == NULL)
3088 pos = path;
3089 else
3090 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003091 res = snprintf(fname, sizeof(fname),
3092 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3093 "create_qos", pos);
3094 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003095 return 0; /* not ath6kl */
3096
3097 if (uapsd) {
3098 f = fopen(fname, "w");
3099 if (f == NULL)
3100 return -1;
3101
3102 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3103 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3104 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3105 "20000 0\n");
3106 fclose(f);
3107 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003108 res = snprintf(fname, sizeof(fname),
3109 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3110 "delete_qos", pos);
3111 if (res < 0 || res >= sizeof(fname))
3112 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003113
3114 f = fopen(fname, "w");
3115 if (f == NULL)
3116 return -1;
3117
3118 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3119 fprintf(f, "2 4\n");
3120 fclose(f);
3121 }
3122#endif /* __linux__ */
3123
3124 return 0;
3125}
3126
3127
Jouni Malinenf7222712019-06-13 01:50:21 +03003128static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3129 struct sigma_conn *conn,
3130 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003131{
3132 const char *intf = get_param(cmd, "Interface");
3133 /* const char *ssid = get_param(cmd, "ssid"); */
3134 const char *val;
3135 int max_sp_len = 4;
3136 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3137 char buf[100];
3138 int ret1, ret2;
3139
3140 val = get_param(cmd, "maxSPLength");
3141 if (val) {
3142 max_sp_len = atoi(val);
3143 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3144 max_sp_len != 4)
3145 return -1;
3146 }
3147
3148 val = get_param(cmd, "acBE");
3149 if (val)
3150 ac_be = atoi(val);
3151
3152 val = get_param(cmd, "acBK");
3153 if (val)
3154 ac_bk = atoi(val);
3155
3156 val = get_param(cmd, "acVI");
3157 if (val)
3158 ac_vi = atoi(val);
3159
3160 val = get_param(cmd, "acVO");
3161 if (val)
3162 ac_vo = atoi(val);
3163
3164 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3165
3166 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3167 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3168 ret1 = wpa_command(intf, buf);
3169
3170 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3171 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3172 ret2 = wpa_command(intf, buf);
3173
3174 if (ret1 && ret2) {
3175 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3176 "UAPSD parameters.");
3177 return -2;
3178 }
3179
3180 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3181 send_resp(dut, conn, SIGMA_ERROR,
3182 "ErrorCode,Failed to set ath6kl QoS parameters");
3183 return 0;
3184 }
3185
3186 return 1;
3187}
3188
3189
Jouni Malinenf7222712019-06-13 01:50:21 +03003190static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3191 struct sigma_conn *conn,
3192 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003193{
3194 char buf[1000];
3195 const char *intf = get_param(cmd, "Interface");
3196 const char *grp = get_param(cmd, "Group");
3197 const char *act = get_param(cmd, "Action");
3198 const char *tid = get_param(cmd, "Tid");
3199 const char *dir = get_param(cmd, "Direction");
3200 const char *psb = get_param(cmd, "Psb");
3201 const char *up = get_param(cmd, "Up");
3202 const char *fixed = get_param(cmd, "Fixed");
3203 const char *size = get_param(cmd, "Size");
3204 const char *msize = get_param(cmd, "Maxsize");
3205 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3206 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3207 const char *inact = get_param(cmd, "Inactivity");
3208 const char *sus = get_param(cmd, "Suspension");
3209 const char *mindr = get_param(cmd, "Mindatarate");
3210 const char *meandr = get_param(cmd, "Meandatarate");
3211 const char *peakdr = get_param(cmd, "Peakdatarate");
3212 const char *phyrate = get_param(cmd, "Phyrate");
3213 const char *burstsize = get_param(cmd, "Burstsize");
3214 const char *sba = get_param(cmd, "Sba");
3215 int direction;
3216 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003217 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003218 int fixed_int;
3219 int psb_ts;
3220
3221 if (intf == NULL || grp == NULL || act == NULL )
3222 return -1;
3223
3224 if (strcasecmp(act, "addts") == 0) {
3225 if (tid == NULL || dir == NULL || psb == NULL ||
3226 up == NULL || fixed == NULL || size == NULL)
3227 return -1;
3228
3229 /*
3230 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3231 * possible values, but WMM-AC and V-E test scripts use "UP,
3232 * "DOWN", and "BIDI".
3233 */
3234 if (strcasecmp(dir, "uplink") == 0 ||
3235 strcasecmp(dir, "up") == 0) {
3236 direction = 0;
3237 } else if (strcasecmp(dir, "downlink") == 0 ||
3238 strcasecmp(dir, "down") == 0) {
3239 direction = 1;
3240 } else if (strcasecmp(dir, "bidi") == 0) {
3241 direction = 2;
3242 } else {
3243 sigma_dut_print(dut, DUT_MSG_ERROR,
3244 "Direction %s not supported", dir);
3245 return -1;
3246 }
3247
3248 if (strcasecmp(psb, "legacy") == 0) {
3249 psb_ts = 0;
3250 } else if (strcasecmp(psb, "uapsd") == 0) {
3251 psb_ts = 1;
3252 } else {
3253 sigma_dut_print(dut, DUT_MSG_ERROR,
3254 "PSB %s not supported", psb);
3255 return -1;
3256 }
3257
3258 if (atoi(tid) < 0 || atoi(tid) > 7) {
3259 sigma_dut_print(dut, DUT_MSG_ERROR,
3260 "TID %s not supported", tid);
3261 return -1;
3262 }
3263
3264 if (strcasecmp(fixed, "true") == 0) {
3265 fixed_int = 1;
3266 } else {
3267 fixed_int = 0;
3268 }
3269
Peng Xu93319622017-10-04 17:58:16 -07003270 if (sba)
3271 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003272
3273 dut->dialog_token++;
3274 handle = 7000 + dut->dialog_token;
3275
3276 /*
3277 * size: convert to hex
3278 * maxsi: convert to hex
3279 * mindr: convert to hex
3280 * meandr: convert to hex
3281 * peakdr: convert to hex
3282 * burstsize: convert to hex
3283 * phyrate: convert to hex
3284 * sba: convert to hex with modification
3285 * minsi: convert to integer
3286 * sus: convert to integer
3287 * inact: convert to integer
3288 * maxsi: convert to integer
3289 */
3290
3291 /*
3292 * The Nominal MSDU Size field is 2 octets long and contains an
3293 * unsigned integer that specifies the nominal size, in octets,
3294 * of MSDUs belonging to the traffic under this traffic
3295 * specification and is defined in Figure 16. If the Fixed
3296 * subfield is set to 1, then the size of the MSDU is fixed and
3297 * is indicated by the Size Subfield. If the Fixed subfield is
3298 * set to 0, then the size of the MSDU might not be fixed and
3299 * the Size indicates the nominal MSDU size.
3300 *
3301 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3302 * and specifies the excess allocation of time (and bandwidth)
3303 * over and above the stated rates required to transport an MSDU
3304 * belonging to the traffic in this TSPEC. This field is
3305 * represented as an unsigned binary number with an implicit
3306 * binary point after the leftmost 3 bits. For example, an SBA
3307 * of 1.75 is represented as 0x3800. This field is included to
3308 * account for retransmissions. As such, the value of this field
3309 * must be greater than unity.
3310 */
3311
3312 snprintf(buf, sizeof(buf),
3313 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3314 " 0x%X 0x%X 0x%X"
3315 " 0x%X 0x%X 0x%X"
3316 " 0x%X %d %d %d %d"
3317 " %d %d",
3318 intf, handle, tid, direction, psb_ts, up,
3319 (unsigned int) ((fixed_int << 15) | atoi(size)),
3320 msize ? atoi(msize) : 0,
3321 mindr ? atoi(mindr) : 0,
3322 meandr ? atoi(meandr) : 0,
3323 peakdr ? atoi(peakdr) : 0,
3324 burstsize ? atoi(burstsize) : 0,
3325 phyrate ? atoi(phyrate) : 0,
3326 sba ? ((unsigned int) (((int) sba_fv << 13) |
3327 (int)((sba_fv - (int) sba_fv) *
3328 8192))) : 0,
3329 minsi ? atoi(minsi) : 0,
3330 sus ? atoi(sus) : 0,
3331 0, 0,
3332 inact ? atoi(inact) : 0,
3333 maxsi ? atoi(maxsi) : 0);
3334
3335 if (system(buf) != 0) {
3336 sigma_dut_print(dut, DUT_MSG_ERROR,
3337 "iwpriv addtspec request failed");
3338 send_resp(dut, conn, SIGMA_ERROR,
3339 "errorCode,Failed to execute addTspec command");
3340 return 0;
3341 }
3342
3343 sigma_dut_print(dut, DUT_MSG_INFO,
3344 "iwpriv addtspec request send");
3345
3346 /* Mapping handle to a TID */
3347 dut->tid_to_handle[atoi(tid)] = handle;
3348 } else if (strcasecmp(act, "delts") == 0) {
3349 if (tid == NULL)
3350 return -1;
3351
3352 if (atoi(tid) < 0 || atoi(tid) > 7) {
3353 sigma_dut_print(dut, DUT_MSG_ERROR,
3354 "TID %s not supported", tid);
3355 send_resp(dut, conn, SIGMA_ERROR,
3356 "errorCode,Unsupported TID");
3357 return 0;
3358 }
3359
3360 handle = dut->tid_to_handle[atoi(tid)];
3361
3362 if (handle < 7000 || handle > 7255) {
3363 /* Invalid handle ie no mapping for that TID */
3364 sigma_dut_print(dut, DUT_MSG_ERROR,
3365 "handle-> %d not found", handle);
3366 }
3367
3368 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3369 intf, handle);
3370
3371 if (system(buf) != 0) {
3372 sigma_dut_print(dut, DUT_MSG_ERROR,
3373 "iwpriv deltspec request failed");
3374 send_resp(dut, conn, SIGMA_ERROR,
3375 "errorCode,Failed to execute delTspec command");
3376 return 0;
3377 }
3378
3379 sigma_dut_print(dut, DUT_MSG_INFO,
3380 "iwpriv deltspec request send");
3381
3382 dut->tid_to_handle[atoi(tid)] = 0;
3383 } else {
3384 sigma_dut_print(dut, DUT_MSG_ERROR,
3385 "Action type %s not supported", act);
3386 send_resp(dut, conn, SIGMA_ERROR,
3387 "errorCode,Unsupported Action");
3388 return 0;
3389 }
3390
3391 return 1;
3392}
3393
3394
vamsi krishna52e16f92017-08-29 12:37:34 +05303395static int find_network(struct sigma_dut *dut, const char *ssid)
3396{
3397 char list[4096];
3398 char *pos;
3399
3400 sigma_dut_print(dut, DUT_MSG_DEBUG,
3401 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003402 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303403 list, sizeof(list)) < 0)
3404 return -1;
3405 pos = strstr(list, ssid);
3406 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3407 return -1;
3408
3409 while (pos > list && pos[-1] != '\n')
3410 pos--;
3411 dut->infra_network_id = atoi(pos);
3412 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3413 return 0;
3414}
3415
3416
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303417/**
3418 * enum qca_sta_helper_config_params - This helper enum defines the config
3419 * parameters which can be delivered to sta.
3420 */
3421enum qca_sta_helper_config_params {
3422 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE */
3423 STA_SET_RSNIE,
3424
3425 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC */
3426 STA_SET_LDPC,
3427
3428 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC */
3429 STA_SET_TX_STBC,
3430
3431 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC */
3432 STA_SET_RX_STBC,
3433
3434 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION */
3435 STA_SET_TX_MSDU,
3436
3437 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION */
3438 STA_SET_RX_MSDU,
3439};
3440
3441
3442static int sta_config_params(struct sigma_dut *dut, const char *intf,
3443 enum qca_sta_helper_config_params config_cmd,
3444 int value)
Sunil Dutt44595082018-02-12 19:41:45 +05303445{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303446#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05303447 struct nl_msg *msg;
3448 int ret;
3449 struct nlattr *params;
3450 int ifindex;
3451
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303452 ifindex = if_nametoindex(intf);
3453 if (ifindex == 0) {
3454 sigma_dut_print(dut, DUT_MSG_ERROR,
3455 "%s: Interface %s does not exist",
3456 __func__, intf);
3457 return -1;
3458 }
3459
Sunil Dutt44595082018-02-12 19:41:45 +05303460 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3461 NL80211_CMD_VENDOR)) ||
3462 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3463 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3464 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3465 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303466 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)))
3467 goto fail;
3468
3469 switch (config_cmd) {
3470 case STA_SET_RSNIE:
3471 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, value))
3472 goto fail;
3473 break;
3474 case STA_SET_LDPC:
3475 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC, value))
3476 goto fail;
3477 break;
3478 case STA_SET_TX_STBC:
3479 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC, value))
3480 goto fail;
3481 break;
3482 case STA_SET_RX_STBC:
3483 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC, value))
3484 goto fail;
3485 break;
3486 case STA_SET_TX_MSDU:
3487 if (nla_put_u8(msg,
3488 QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION,
3489 value))
3490 goto fail;
3491 break;
3492 case STA_SET_RX_MSDU:
3493 if (nla_put_u8(msg,
3494 QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION,
3495 value))
3496 goto fail;
3497 break;
Sunil Dutt44595082018-02-12 19:41:45 +05303498 }
3499 nla_nest_end(msg, params);
3500
3501 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3502 if (ret) {
3503 sigma_dut_print(dut, DUT_MSG_ERROR,
3504 "%s: err in send_and_recv_msgs, ret=%d",
3505 __func__, ret);
3506 return ret;
3507 }
3508
3509 return 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303510
3511fail:
3512 sigma_dut_print(dut, DUT_MSG_ERROR,
3513 "%s: err in adding vendor_cmd and vendor_data",
3514 __func__);
3515 nlmsg_free(msg);
Sunil Dutt44595082018-02-12 19:41:45 +05303516#endif /* NL80211_SUPPORT */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303517 return -1;
3518}
Sunil Dutt44595082018-02-12 19:41:45 +05303519
3520
Jouni Malinenf7222712019-06-13 01:50:21 +03003521static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3522 struct sigma_conn *conn,
3523 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003524{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303525#ifdef NL80211_SUPPORT
3526 const char *intf = get_param(cmd, "Interface");
3527#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003528 const char *ssid = get_param(cmd, "ssid");
3529 const char *wps_param = get_param(cmd, "WPS");
3530 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003531 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003532 const char *network_mode = get_param(cmd, "network_mode");
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303533 const char *ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003534 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003535 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003536 int e;
3537 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3538 struct wpa_ctrl *ctrl = NULL;
3539 int num_network_not_found = 0;
3540 int num_disconnected = 0;
3541 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003542
3543 if (ssid == NULL)
3544 return -1;
3545
Jouni Malinen37d5c692019-08-19 16:56:55 +03003546 dut->server_cert_tod = 0;
3547
Jouni Malinen3c367e82017-06-23 17:01:47 +03003548 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303549#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003550 if (get_driver_type(dut) == DRIVER_WCN) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303551 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Sunil Dutt44595082018-02-12 19:41:45 +05303552 dut->config_rsnie = 1;
3553 }
3554#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003555 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3556 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003557 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03003558 send_resp(dut, conn, SIGMA_ERROR,
3559 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3560 return 0;
3561 }
3562 }
3563
Jouni Malinen68143132017-09-02 02:34:08 +03003564 if (dut->sae_commit_override) {
3565 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3566 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003567 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03003568 send_resp(dut, conn, SIGMA_ERROR,
3569 "ErrorCode,Failed to set SAE commit override");
3570 return 0;
3571 }
3572 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303573#ifdef ANDROID
3574 if (dut->fils_hlp)
3575 process_fils_hlp(dut);
3576#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003577
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003578 if (wps_param &&
3579 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3580 wps = 1;
3581
Vamsi Krishnac1633d22020-05-06 18:31:21 +05303582 if (dut->ocvc &&
3583 set_network(get_station_ifname(dut), dut->infra_network_id,
3584 "ocv", "1") < 0)
3585 return ERROR_SEND_STATUS;
3586
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003587 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003588 if (dut->program == PROGRAM_60GHZ && network_mode &&
3589 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003590 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003591 "pbss", "1") < 0)
3592 return -2;
3593
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003594 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3595 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3596 "parameters not yet set");
3597 return 0;
3598 }
3599 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003600 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003601 return -2;
3602 } else {
3603 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3604 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003605 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003606 return -2;
3607 }
3608 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303609 if (strcmp(ssid, dut->infra_ssid) == 0) {
3610 sigma_dut_print(dut, DUT_MSG_DEBUG,
3611 "sta_associate for the most recently added network");
3612 } else if (find_network(dut, ssid) < 0) {
3613 sigma_dut_print(dut, DUT_MSG_DEBUG,
3614 "sta_associate for a previously stored network profile");
3615 send_resp(dut, conn, SIGMA_ERROR,
3616 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003617 return 0;
3618 }
3619
3620 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003621 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003622 "bssid", bssid) < 0) {
3623 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3624 "Invalid bssid argument");
3625 return 0;
3626 }
3627
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303628 if ((dut->program == PROGRAM_WPA3 &&
3629 dut->sta_associate_wait_connect) ||
3630 dut->program == PROGRAM_QM) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003631 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003632 if (!ctrl)
3633 return ERROR_SEND_STATUS;
3634 }
3635
Jouni Malinen46a19b62017-06-23 14:31:27 +03003636 extra[0] = '\0';
3637 if (chan)
3638 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003639 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003640 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3641 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003642 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003643 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3644 "network id %d on %s",
3645 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003646 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003647 ret = ERROR_SEND_STATUS;
3648 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003649 }
3650 }
3651
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003652 if (!ctrl)
3653 return SUCCESS_SEND_STATUS;
3654
3655 /* Wait for connection result to be able to store server certificate
3656 * hash for trust root override testing
3657 * (dev_exec_action,ServerCertTrust). */
3658
3659 for (e = 0; e < 20; e++) {
3660 const char *events[] = {
3661 "CTRL-EVENT-EAP-PEER-CERT",
3662 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3663 "CTRL-EVENT-DISCONNECTED",
3664 "CTRL-EVENT-CONNECTED",
3665 "CTRL-EVENT-NETWORK-NOT-FOUND",
3666 NULL
3667 };
3668 char buf[1024];
3669 int res;
3670
3671 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3672 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02003673 send_resp(dut, conn, SIGMA_COMPLETE,
3674 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003675 ret = STATUS_SENT_ERROR;
3676 break;
3677 }
3678 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3679 buf);
3680
3681 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3682 strstr(buf, " depth=0")) {
3683 char *pos = strstr(buf, " hash=");
3684
3685 if (pos) {
3686 char *end;
3687
Jouni Malinen34b19cb2019-08-16 16:37:17 +03003688 if (strstr(buf, " tod=1"))
3689 tod = 1;
3690 else if (strstr(buf, " tod=2"))
3691 tod = 2;
3692 else
3693 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003694 sigma_dut_print(dut, DUT_MSG_DEBUG,
3695 "Server certificate TOD policy: %d",
3696 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03003697 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003698
3699 pos += 6;
3700 end = strchr(pos, ' ');
3701 if (end)
3702 *end = '\0';
3703 strlcpy(dut->server_cert_hash, pos,
3704 sizeof(dut->server_cert_hash));
3705 sigma_dut_print(dut, DUT_MSG_DEBUG,
3706 "Server certificate hash: %s",
3707 dut->server_cert_hash);
3708 }
3709 }
3710
3711 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3712 send_resp(dut, conn, SIGMA_COMPLETE,
3713 "Result,TLS server certificate validation failed");
3714 ret = STATUS_SENT_ERROR;
3715 break;
3716 }
3717
3718 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3719 num_network_not_found++;
3720
3721 if (num_network_not_found > 2) {
3722 send_resp(dut, conn, SIGMA_COMPLETE,
3723 "Result,Network not found");
3724 ret = STATUS_SENT_ERROR;
3725 break;
3726 }
3727 }
3728
3729 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3730 num_disconnected++;
3731
3732 if (num_disconnected > 2) {
3733 send_resp(dut, conn, SIGMA_COMPLETE,
3734 "Result,Connection failed");
3735 ret = STATUS_SENT_ERROR;
3736 break;
3737 }
3738 }
3739
3740 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3741 if (tod >= 0) {
3742 sigma_dut_print(dut, DUT_MSG_DEBUG,
3743 "Network profile TOD policy update: %d -> %d",
3744 dut->sta_tod_policy, tod);
3745 dut->sta_tod_policy = tod;
3746 }
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303747 if (dut->program == PROGRAM_QM) {
3748 unsigned char iface_mac_addr[ETH_ALEN];
3749 char ipv6[100];
3750
3751 if (get_hwaddr(ifname, iface_mac_addr) < 0) {
3752 sigma_dut_print(dut, DUT_MSG_ERROR,
3753 "%s: get_hwaddr %s failed",
3754 __func__, ifname);
3755 ret = ERROR_SEND_STATUS;
3756 break;
3757 }
3758
3759 convert_mac_addr_to_ipv6_lladdr(iface_mac_addr,
3760 ipv6,
3761 sizeof(ipv6));
3762
3763 if (set_ipv6_addr(dut, ipv6, "64", ifname) !=
3764 0) {
3765 ret = ERROR_SEND_STATUS;
3766 break;
3767 }
3768 }
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003769 break;
3770 }
3771 }
3772done:
3773 if (ctrl) {
3774 wpa_ctrl_detach(ctrl);
3775 wpa_ctrl_close(ctrl);
3776 }
3777 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003778}
3779
3780
3781static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3782{
3783 char buf[500], cmd[200];
3784 int res;
3785
3786 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3787 * default path */
3788 res = snprintf(cmd, sizeof(cmd),
3789 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3790 file_exists("./hs20-osu-client") ?
3791 "./hs20-osu-client" : "hs20-osu-client",
3792 sigma_wpas_ctrl,
3793 dut->summary_log ? "-s " : "",
3794 dut->summary_log ? dut->summary_log : "");
3795 if (res < 0 || res >= (int) sizeof(cmd))
3796 return -1;
3797
3798 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3799 if (res < 0 || res >= (int) sizeof(buf))
3800 return -1;
3801 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3802
3803 if (system(buf) != 0) {
3804 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3805 return -1;
3806 }
3807 sigma_dut_print(dut, DUT_MSG_DEBUG,
3808 "Completed hs20-osu-client operation");
3809
3810 return 0;
3811}
3812
3813
3814static int download_ppsmo(struct sigma_dut *dut,
3815 struct sigma_conn *conn,
3816 const char *intf,
3817 struct sigma_cmd *cmd)
3818{
3819 const char *name, *path, *val;
3820 char url[500], buf[600], fbuf[100];
3821 char *fqdn = NULL;
3822
3823 name = get_param(cmd, "FileName");
3824 path = get_param(cmd, "FilePath");
3825 if (name == NULL || path == NULL)
3826 return -1;
3827
3828 if (strcasecmp(path, "VendorSpecific") == 0) {
3829 snprintf(url, sizeof(url), "PPS/%s", name);
3830 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3831 "from the device (%s)", url);
3832 if (!file_exists(url)) {
3833 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3834 "PPS MO file does not exist");
3835 return 0;
3836 }
3837 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3838 if (system(buf) != 0) {
3839 send_resp(dut, conn, SIGMA_ERROR,
3840 "errorCode,Failed to copy PPS MO");
3841 return 0;
3842 }
3843 } else if (strncasecmp(path, "http:", 5) != 0 &&
3844 strncasecmp(path, "https:", 6) != 0) {
3845 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3846 "Unsupported FilePath value");
3847 return 0;
3848 } else {
3849 snprintf(url, sizeof(url), "%s/%s", path, name);
3850 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3851 url);
3852 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3853 remove("pps-tnds.xml");
3854 if (system(buf) != 0) {
3855 send_resp(dut, conn, SIGMA_ERROR,
3856 "errorCode,Failed to download PPS MO");
3857 return 0;
3858 }
3859 }
3860
3861 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3862 send_resp(dut, conn, SIGMA_ERROR,
3863 "errorCode,Failed to parse downloaded PPSMO");
3864 return 0;
3865 }
3866 unlink("pps-tnds.xml");
3867
3868 val = get_param(cmd, "managementTreeURI");
3869 if (val) {
3870 const char *pos, *end;
3871 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3872 val);
3873 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3874 send_resp(dut, conn, SIGMA_ERROR,
3875 "errorCode,Invalid managementTreeURI prefix");
3876 return 0;
3877 }
3878 pos = val + 8;
3879 end = strchr(pos, '/');
3880 if (end == NULL ||
3881 strcmp(end, "/PerProviderSubscription") != 0) {
3882 send_resp(dut, conn, SIGMA_ERROR,
3883 "errorCode,Invalid managementTreeURI postfix");
3884 return 0;
3885 }
3886 if (end - pos >= (int) sizeof(fbuf)) {
3887 send_resp(dut, conn, SIGMA_ERROR,
3888 "errorCode,Too long FQDN in managementTreeURI");
3889 return 0;
3890 }
3891 memcpy(fbuf, pos, end - pos);
3892 fbuf[end - pos] = '\0';
3893 fqdn = fbuf;
3894 sigma_dut_print(dut, DUT_MSG_INFO,
3895 "FQDN from managementTreeURI: %s", fqdn);
3896 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3897 FILE *f = fopen("pps-fqdn", "r");
3898 if (f) {
3899 if (fgets(fbuf, sizeof(fbuf), f)) {
3900 fbuf[sizeof(fbuf) - 1] = '\0';
3901 fqdn = fbuf;
3902 sigma_dut_print(dut, DUT_MSG_DEBUG,
3903 "Use FQDN %s", fqdn);
3904 }
3905 fclose(f);
3906 }
3907 }
3908
3909 if (fqdn == NULL) {
3910 send_resp(dut, conn, SIGMA_ERROR,
3911 "errorCode,No FQDN specified");
3912 return 0;
3913 }
3914
3915 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3916 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3917 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3918
3919 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3920 if (rename("pps.xml", buf) < 0) {
3921 send_resp(dut, conn, SIGMA_ERROR,
3922 "errorCode,Could not move PPS MO");
3923 return 0;
3924 }
3925
3926 if (strcasecmp(path, "VendorSpecific") == 0) {
3927 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3928 fqdn);
3929 if (system(buf)) {
3930 send_resp(dut, conn, SIGMA_ERROR,
3931 "errorCode,Failed to copy OSU CA cert");
3932 return 0;
3933 }
3934
3935 snprintf(buf, sizeof(buf),
3936 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3937 fqdn);
3938 if (system(buf)) {
3939 send_resp(dut, conn, SIGMA_ERROR,
3940 "errorCode,Failed to copy AAA CA cert");
3941 return 0;
3942 }
3943 } else {
3944 snprintf(buf, sizeof(buf),
3945 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3946 fqdn, fqdn);
3947 if (run_hs20_osu(dut, buf) < 0) {
3948 send_resp(dut, conn, SIGMA_ERROR,
3949 "errorCode,Failed to download OSU CA cert");
3950 return 0;
3951 }
3952
3953 snprintf(buf, sizeof(buf),
3954 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3955 fqdn, fqdn);
3956 if (run_hs20_osu(dut, buf) < 0) {
3957 sigma_dut_print(dut, DUT_MSG_INFO,
3958 "Failed to download AAA CA cert");
3959 }
3960 }
3961
3962 if (file_exists("next-client-cert.pem")) {
3963 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3964 if (rename("next-client-cert.pem", buf) < 0) {
3965 send_resp(dut, conn, SIGMA_ERROR,
3966 "errorCode,Could not move client certificate");
3967 return 0;
3968 }
3969 }
3970
3971 if (file_exists("next-client-key.pem")) {
3972 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3973 if (rename("next-client-key.pem", buf) < 0) {
3974 send_resp(dut, conn, SIGMA_ERROR,
3975 "errorCode,Could not move client key");
3976 return 0;
3977 }
3978 }
3979
3980 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3981 if (run_hs20_osu(dut, buf) < 0) {
3982 send_resp(dut, conn, SIGMA_ERROR,
3983 "errorCode,Failed to configure credential from "
3984 "PPSMO");
3985 return 0;
3986 }
3987
3988 return 1;
3989}
3990
3991
3992static int download_cert(struct sigma_dut *dut,
3993 struct sigma_conn *conn,
3994 const char *intf,
3995 struct sigma_cmd *cmd)
3996{
3997 const char *name, *path;
3998 char url[500], buf[600];
3999
4000 name = get_param(cmd, "FileName");
4001 path = get_param(cmd, "FilePath");
4002 if (name == NULL || path == NULL)
4003 return -1;
4004
4005 if (strcasecmp(path, "VendorSpecific") == 0) {
4006 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
4007 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4008 "certificate from the device (%s)", url);
4009 if (!file_exists(url)) {
4010 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4011 "certificate file does not exist");
4012 return 0;
4013 }
4014 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
4015 if (system(buf) != 0) {
4016 send_resp(dut, conn, SIGMA_ERROR,
4017 "errorCode,Failed to copy client "
4018 "certificate");
4019 return 0;
4020 }
4021
4022 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
4023 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4024 "private key from the device (%s)", url);
4025 if (!file_exists(url)) {
4026 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4027 "private key file does not exist");
4028 return 0;
4029 }
4030 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
4031 if (system(buf) != 0) {
4032 send_resp(dut, conn, SIGMA_ERROR,
4033 "errorCode,Failed to copy client key");
4034 return 0;
4035 }
4036 } else if (strncasecmp(path, "http:", 5) != 0 &&
4037 strncasecmp(path, "https:", 6) != 0) {
4038 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4039 "Unsupported FilePath value");
4040 return 0;
4041 } else {
4042 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
4043 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
4044 "certificate/key from %s", url);
4045 snprintf(buf, sizeof(buf),
4046 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
4047 if (system(buf) != 0) {
4048 send_resp(dut, conn, SIGMA_ERROR,
4049 "errorCode,Failed to download client "
4050 "certificate");
4051 return 0;
4052 }
4053
4054 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
4055 {
4056 send_resp(dut, conn, SIGMA_ERROR,
4057 "errorCode,Failed to copy client key");
4058 return 0;
4059 }
4060 }
4061
4062 return 1;
4063}
4064
4065
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004066static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
4067 struct sigma_conn *conn,
4068 struct sigma_cmd *cmd)
4069{
4070 const char *val;
4071 const char *intf = get_param(cmd, "interface");
4072
4073 if (!intf)
4074 return -1;
4075
4076 val = get_param(cmd, "WscIEFragment");
4077 if (val && strcasecmp(val, "enable") == 0) {
4078 sigma_dut_print(dut, DUT_MSG_DEBUG,
4079 "Enable WSC IE fragmentation");
4080
4081 dut->wsc_fragment = 1;
4082 /* set long attributes to force fragmentation */
4083 if (wpa_command(intf, "SET device_name "
4084 WPS_LONG_DEVICE_NAME) < 0)
4085 return -2;
4086 if (wpa_command(intf, "SET manufacturer "
4087 WPS_LONG_MANUFACTURER) < 0)
4088 return -2;
4089 if (wpa_command(intf, "SET model_name "
4090 WPS_LONG_MODEL_NAME) < 0)
4091 return -2;
4092 if (wpa_command(intf, "SET model_number "
4093 WPS_LONG_MODEL_NUMBER) < 0)
4094 return -2;
4095 if (wpa_command(intf, "SET serial_number "
4096 WPS_LONG_SERIAL_NUMBER) < 0)
4097 return -2;
4098 }
4099
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02004100 val = get_param(cmd, "RSN_IE");
4101 if (val) {
4102 if (strcasecmp(val, "disable") == 0)
4103 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
4104 else if (strcasecmp(val, "enable") == 0)
4105 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
4106 }
4107
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004108 val = get_param(cmd, "WpsVersion");
4109 if (val)
4110 dut->wps_forced_version = get_wps_forced_version(dut, val);
4111
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004112 val = get_param(cmd, "WscEAPFragment");
4113 if (val && strcasecmp(val, "enable") == 0)
4114 dut->eap_fragment = 1;
4115
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004116 return 1;
4117}
4118
4119
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004120static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4121 struct sigma_conn *conn,
4122 const char *intf,
4123 struct sigma_cmd *cmd)
4124{
4125 const char *val;
4126
4127 val = get_param(cmd, "FileType");
4128 if (val && strcasecmp(val, "PPSMO") == 0)
4129 return download_ppsmo(dut, conn, intf, cmd);
4130 if (val && strcasecmp(val, "CERT") == 0)
4131 return download_cert(dut, conn, intf, cmd);
4132 if (val) {
4133 send_resp(dut, conn, SIGMA_ERROR,
4134 "ErrorCode,Unsupported FileType");
4135 return 0;
4136 }
4137
4138 return 1;
4139}
4140
4141
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304142static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4143 struct sigma_conn *conn,
4144 const char *intf,
4145 struct sigma_cmd *cmd)
4146{
4147 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304148 char buf[1000];
4149 char text[20];
4150 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304151
4152 val = get_param(cmd, "OCESupport");
4153 if (val && strcasecmp(val, "Disable") == 0) {
4154 if (wpa_command(intf, "SET oce 0") < 0) {
4155 send_resp(dut, conn, SIGMA_ERROR,
4156 "ErrorCode,Failed to disable OCE");
4157 return 0;
4158 }
4159 } else if (val && strcasecmp(val, "Enable") == 0) {
4160 if (wpa_command(intf, "SET oce 1") < 0) {
4161 send_resp(dut, conn, SIGMA_ERROR,
4162 "ErrorCode,Failed to enable OCE");
4163 return 0;
4164 }
4165 }
4166
vamsi krishnaa2799492017-12-05 14:28:01 +05304167 val = get_param(cmd, "FILScap");
4168 if (val && (atoi(val) == 1)) {
4169 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4170 send_resp(dut, conn, SIGMA_ERROR,
4171 "ErrorCode,Failed to enable FILS");
4172 return 0;
4173 }
4174 } else if (val && (atoi(val) == 0)) {
4175 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4176 send_resp(dut, conn, SIGMA_ERROR,
4177 "ErrorCode,Failed to disable FILS");
4178 return 0;
4179 }
4180 }
4181
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304182 val = get_param(cmd, "FILSHLP");
4183 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004184 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304185 sizeof(text)) < 0)
4186 return -2;
4187 hwaddr_aton(text, addr);
4188 snprintf(buf, sizeof(buf),
4189 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4190 "080045100140000040004011399e00000000ffffffff00440043"
4191 "012cb30001010600fd4f46410000000000000000000000000000"
4192 "000000000000"
4193 "%02x%02x%02x%02x%02x%02x"
4194 "0000000000000000000000000000000000000000000000000000"
4195 "0000000000000000000000000000000000000000000000000000"
4196 "0000000000000000000000000000000000000000000000000000"
4197 "0000000000000000000000000000000000000000000000000000"
4198 "0000000000000000000000000000000000000000000000000000"
4199 "0000000000000000000000000000000000000000000000000000"
4200 "0000000000000000000000000000000000000000000000000000"
4201 "0000000000000000000000000000000000000000638253633501"
4202 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4203 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4204 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4205 if (wpa_command(intf, buf)) {
4206 send_resp(dut, conn, SIGMA_ERROR,
4207 "ErrorCode,Failed to add HLP");
4208 return 0;
4209 }
4210 dut->fils_hlp = 1;
4211 }
4212
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304213 return 1;
4214}
4215
4216
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004217static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4218 const char *val)
4219{
4220 int counter = 0;
4221 char token[50];
4222 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304223 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004224
Peng Xub8fc5cc2017-05-10 17:27:28 -07004225 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004226 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304227 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004228 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004229 if (strcmp(result, "disable") == 0)
4230 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4231 else
4232 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304233 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004234 counter++;
4235 }
4236}
4237
4238
4239static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4240 const char *val)
4241{
4242 char buf[100];
4243
4244 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4245 if (system(buf) != 0) {
4246 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4247 }
4248}
4249
4250
4251static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4252 const char *val)
4253{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004254 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004255 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004256 }
4257}
4258
4259
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004260static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4261 const char *val)
4262{
4263#ifdef NL80211_SUPPORT
4264 struct nl_msg *msg;
4265 int ret = 0;
4266 struct nlattr *params;
4267 int ifindex;
4268 int wmmenable = 1;
4269
4270 if (val &&
4271 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4272 wmmenable = 0;
4273
4274 ifindex = if_nametoindex(intf);
4275 if (ifindex == 0) {
4276 sigma_dut_print(dut, DUT_MSG_ERROR,
4277 "%s: Index for interface %s failed",
4278 __func__, intf);
4279 return -1;
4280 }
4281
4282 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4283 NL80211_CMD_VENDOR)) ||
4284 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4285 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4286 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4287 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4288 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4289 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4290 wmmenable)) {
4291 sigma_dut_print(dut, DUT_MSG_ERROR,
4292 "%s: err in adding vendor_cmd and vendor_data",
4293 __func__);
4294 nlmsg_free(msg);
4295 return -1;
4296 }
4297 nla_nest_end(msg, params);
4298
4299 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4300 if (ret) {
4301 sigma_dut_print(dut, DUT_MSG_ERROR,
4302 "%s: err in send_and_recv_msgs, ret=%d",
4303 __func__, ret);
4304 }
4305 return ret;
4306#else /* NL80211_SUPPORT */
4307 sigma_dut_print(dut, DUT_MSG_ERROR,
4308 "WMM cannot be changed without NL80211_SUPPORT defined");
4309 return -1;
4310#endif /* NL80211_SUPPORT */
4311}
4312
4313
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004314static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4315 const char *val)
4316{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004317 int sgi20;
4318
4319 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4320
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004321 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004322}
4323
4324
4325static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4326 const char *val)
4327{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304328 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004329
4330 /* Disable Tx Beam forming when using a fixed rate */
4331 ath_disable_txbf(dut, intf);
4332
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304333 v = atoi(val);
4334 if (v < 0 || v > 32) {
4335 sigma_dut_print(dut, DUT_MSG_ERROR,
4336 "Invalid Fixed MCS rate: %d", v);
4337 return;
4338 }
4339 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004340
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004341 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004342
4343 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004344 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004345}
4346
4347
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004348static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4349 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004350{
4351 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304352 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004353
4354 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4355 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4356 else
4357 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4358
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304359 ret = system(buf);
4360#ifdef NL80211_SUPPORT
4361 if (ret) {
4362 int value = (strcasecmp(val, "Enable") == 0) ? 2 : 1;
4363
4364 ret = sta_config_params(dut, intf, STA_SET_TX_MSDU, value);
4365 ret |= sta_config_params(dut, intf, STA_SET_RX_MSDU, value);
4366 }
4367#endif /* NL80211_SUPPORT */
4368 if (ret)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004369 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4370}
4371
4372
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004373static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4374 int ampdu)
4375{
4376 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004377 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004378
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004379 if (ampdu)
4380 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004381 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4382 if (system(buf) != 0) {
4383 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4384 return -1;
4385 }
4386
4387 return 0;
4388}
4389
4390
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004391static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4392 const char *val)
4393{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004394 run_iwpriv(dut, intf, "tx_stbc %s", val);
4395 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004396}
4397
4398
4399static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4400 const char *val)
4401{
4402 char buf[60];
4403
Peng Xucc317ed2017-05-18 16:44:37 -07004404 if (strcmp(val, "160") == 0) {
4405 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4406 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004407 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4408 } else if (strcmp(val, "40") == 0) {
4409 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4410 } else if (strcmp(val, "20") == 0) {
4411 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4412 } else if (strcasecmp(val, "Auto") == 0) {
4413 buf[0] = '\0';
4414 } else {
4415 sigma_dut_print(dut, DUT_MSG_ERROR,
4416 "WIDTH/CTS_WIDTH value not supported");
4417 return -1;
4418 }
4419
4420 if (buf[0] != '\0' && system(buf) != 0) {
4421 sigma_dut_print(dut, DUT_MSG_ERROR,
4422 "Failed to set WIDTH/CTS_WIDTH");
4423 return -1;
4424 }
4425
4426 return 0;
4427}
4428
4429
4430int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4431 const char *intf, const char *val)
4432{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004433 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004434 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004435 dut->chwidth = 0;
4436 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004437 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004438 dut->chwidth = 0;
4439 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004440 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004441 dut->chwidth = 1;
4442 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004443 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004444 dut->chwidth = 2;
4445 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004446 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004447 dut->chwidth = 3;
4448 } else {
4449 send_resp(dut, conn, SIGMA_ERROR,
4450 "ErrorCode,WIDTH not supported");
4451 return -1;
4452 }
4453
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004454 return 0;
4455}
4456
4457
4458static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4459 const char *val)
4460{
4461 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004462 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004463
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004464 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004465 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004466 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004467 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004468 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004469 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004470 } else {
4471 sigma_dut_print(dut, DUT_MSG_ERROR,
4472 "SP_STREAM value not supported");
4473 return -1;
4474 }
4475
4476 if (system(buf) != 0) {
4477 sigma_dut_print(dut, DUT_MSG_ERROR,
4478 "Failed to set SP_STREAM");
4479 return -1;
4480 }
4481
Arif Hussainac6c5112018-05-25 17:34:00 -07004482 dut->sta_nss = sta_nss;
4483
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004484 return 0;
4485}
4486
4487
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304488static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4489 const char *val)
4490{
4491 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304492 int ret;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304493
4494 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304495 ret = system(buf);
4496#ifdef NL80211_SUPPORT
4497 if (ret)
4498 ret = sta_config_params(dut, intf, STA_SET_TX_STBC,
4499 strcmp(val, "0") == 0 ? 0 : 1);
4500#endif /* NL80211_SUPPORT */
4501 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304502 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4503
4504 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304505 ret = system(buf);
4506#ifdef NL80211_SUPPORT
4507 if (ret)
4508 ret = sta_config_params(dut, intf, STA_SET_RX_STBC,
4509 strcmp(val, "0") == 0 ? 0 : 1);
4510#endif /* NL80211_SUPPORT */
4511 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304512 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4513}
4514
4515
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304516static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4517 struct sigma_conn *conn,
4518 const char *intf, int capa)
4519{
4520 char buf[32];
4521
4522 if (capa > 0 && capa < 4) {
4523 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4524 if (wpa_command(intf, buf) < 0) {
4525 send_resp(dut, conn, SIGMA_ERROR,
4526 "ErrorCode, Failed to set cellular data capability");
4527 return 0;
4528 }
4529 return 1;
4530 }
4531
4532 sigma_dut_print(dut, DUT_MSG_ERROR,
4533 "Invalid Cellular data capability: %d", capa);
4534 send_resp(dut, conn, SIGMA_INVALID,
4535 "ErrorCode,Invalid cellular data capability");
4536 return 0;
4537}
4538
4539
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304540static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4541 const char *intf, const char *val)
4542{
4543 if (strcasecmp(val, "Disable") == 0) {
4544 if (wpa_command(intf, "SET roaming 0") < 0) {
4545 send_resp(dut, conn, SIGMA_ERROR,
4546 "ErrorCode,Failed to disable roaming");
4547 return 0;
4548 }
4549 return 1;
4550 }
4551
4552 if (strcasecmp(val, "Enable") == 0) {
4553 if (wpa_command(intf, "SET roaming 1") < 0) {
4554 send_resp(dut, conn, SIGMA_ERROR,
4555 "ErrorCode,Failed to enable roaming");
4556 return 0;
4557 }
4558 return 1;
4559 }
4560
4561 sigma_dut_print(dut, DUT_MSG_ERROR,
4562 "Invalid value provided for roaming: %s", val);
4563 send_resp(dut, conn, SIGMA_INVALID,
4564 "ErrorCode,Unknown value provided for Roaming");
4565 return 0;
4566}
4567
4568
Ashwini Patila75de5a2017-04-13 16:35:05 +05304569static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4570 struct sigma_conn *conn,
4571 const char *intf, const char *val)
4572{
4573 if (strcasecmp(val, "Disable") == 0) {
4574 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4575 send_resp(dut, conn, SIGMA_ERROR,
4576 "ErrorCode,Failed to disable Assoc_disallow");
4577 return 0;
4578 }
4579 return 1;
4580 }
4581
4582 if (strcasecmp(val, "Enable") == 0) {
4583 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4584 send_resp(dut, conn, SIGMA_ERROR,
4585 "ErrorCode,Failed to enable Assoc_disallow");
4586 return 0;
4587 }
4588 return 1;
4589 }
4590
4591 sigma_dut_print(dut, DUT_MSG_ERROR,
4592 "Invalid value provided for Assoc_disallow: %s", val);
4593 send_resp(dut, conn, SIGMA_INVALID,
4594 "ErrorCode,Unknown value provided for Assoc_disallow");
4595 return 0;
4596}
4597
4598
Ashwini Patilc63161e2017-04-13 16:30:23 +05304599static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4600 const char *intf, const char *val)
4601{
4602 if (strcasecmp(val, "Reject") == 0) {
4603 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4604 send_resp(dut, conn, SIGMA_ERROR,
4605 "ErrorCode,Failed to Reject BTM Request");
4606 return 0;
4607 }
4608 return 1;
4609 }
4610
4611 if (strcasecmp(val, "Accept") == 0) {
4612 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4613 send_resp(dut, conn, SIGMA_ERROR,
4614 "ErrorCode,Failed to Accept BTM Request");
4615 return 0;
4616 }
4617 return 1;
4618 }
4619
4620 sigma_dut_print(dut, DUT_MSG_ERROR,
4621 "Invalid value provided for BSS_Transition: %s", val);
4622 send_resp(dut, conn, SIGMA_INVALID,
4623 "ErrorCode,Unknown value provided for BSS_Transition");
4624 return 0;
4625}
4626
4627
Ashwini Patil00402582017-04-13 12:29:39 +05304628static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4629 struct sigma_conn *conn,
4630 const char *intf,
4631 struct sigma_cmd *cmd)
4632{
4633 const char *ch, *pref, *op_class, *reason;
4634 char buf[120];
4635 int len, ret;
4636
4637 pref = get_param(cmd, "Ch_Pref");
4638 if (!pref)
4639 return 1;
4640
4641 if (strcasecmp(pref, "clear") == 0) {
4642 free(dut->non_pref_ch_list);
4643 dut->non_pref_ch_list = NULL;
4644 } else {
4645 op_class = get_param(cmd, "Ch_Op_Class");
4646 if (!op_class) {
4647 send_resp(dut, conn, SIGMA_INVALID,
4648 "ErrorCode,Ch_Op_Class not provided");
4649 return 0;
4650 }
4651
4652 ch = get_param(cmd, "Ch_Pref_Num");
4653 if (!ch) {
4654 send_resp(dut, conn, SIGMA_INVALID,
4655 "ErrorCode,Ch_Pref_Num not provided");
4656 return 0;
4657 }
4658
4659 reason = get_param(cmd, "Ch_Reason_Code");
4660 if (!reason) {
4661 send_resp(dut, conn, SIGMA_INVALID,
4662 "ErrorCode,Ch_Reason_Code not provided");
4663 return 0;
4664 }
4665
4666 if (!dut->non_pref_ch_list) {
4667 dut->non_pref_ch_list =
4668 calloc(1, NON_PREF_CH_LIST_SIZE);
4669 if (!dut->non_pref_ch_list) {
4670 send_resp(dut, conn, SIGMA_ERROR,
4671 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4672 return 0;
4673 }
4674 }
4675 len = strlen(dut->non_pref_ch_list);
4676 ret = snprintf(dut->non_pref_ch_list + len,
4677 NON_PREF_CH_LIST_SIZE - len,
4678 " %s:%s:%s:%s", op_class, ch, pref, reason);
4679 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4680 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4681 dut->non_pref_ch_list);
4682 } else {
4683 sigma_dut_print(dut, DUT_MSG_ERROR,
4684 "snprintf failed for non_pref_list, ret = %d",
4685 ret);
4686 send_resp(dut, conn, SIGMA_ERROR,
4687 "ErrorCode,snprintf failed");
4688 free(dut->non_pref_ch_list);
4689 dut->non_pref_ch_list = NULL;
4690 return 0;
4691 }
4692 }
4693
4694 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4695 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4696 if (ret < 0 || ret >= (int) sizeof(buf)) {
4697 sigma_dut_print(dut, DUT_MSG_DEBUG,
4698 "snprintf failed for set non_pref_chan, ret: %d",
4699 ret);
4700 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4701 return 0;
4702 }
4703
4704 if (wpa_command(intf, buf) < 0) {
4705 send_resp(dut, conn, SIGMA_ERROR,
4706 "ErrorCode,Failed to set non-preferred channel list");
4707 return 0;
4708 }
4709
4710 return 1;
4711}
4712
4713
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004714#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004715
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004716static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4717 uint8_t cfg)
4718{
4719 struct nl_msg *msg;
4720 int ret = 0;
4721 struct nlattr *params;
4722 int ifindex;
4723
4724 ifindex = if_nametoindex(intf);
4725 if (ifindex == 0) {
4726 sigma_dut_print(dut, DUT_MSG_ERROR,
4727 "%s: Index for interface %s failed",
4728 __func__, intf);
4729 return -1;
4730 }
4731
4732 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4733 NL80211_CMD_VENDOR)) ||
4734 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4735 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4736 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4737 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4738 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4739 nla_put_u8(msg,
4740 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4741 cfg)) {
4742 sigma_dut_print(dut, DUT_MSG_ERROR,
4743 "%s: err in adding vendor_cmd and vendor_data",
4744 __func__);
4745 nlmsg_free(msg);
4746 return -1;
4747 }
4748 nla_nest_end(msg, params);
4749
4750 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4751 if (ret) {
4752 sigma_dut_print(dut, DUT_MSG_ERROR,
4753 "%s: err in send_and_recv_msgs, ret=%d",
4754 __func__, ret);
4755 }
4756 return ret;
4757}
4758
4759
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004760static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4761 enum he_fragmentation_val frag)
4762{
4763 struct nl_msg *msg;
4764 int ret = 0;
4765 struct nlattr *params;
4766 int ifindex;
4767
4768 ifindex = if_nametoindex(intf);
4769 if (ifindex == 0) {
4770 sigma_dut_print(dut, DUT_MSG_ERROR,
4771 "%s: Index for interface %s failed",
4772 __func__, intf);
4773 return -1;
4774 }
4775
4776 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4777 NL80211_CMD_VENDOR)) ||
4778 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4779 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4780 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4781 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4782 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4783 nla_put_u8(msg,
4784 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
4785 frag)) {
4786 sigma_dut_print(dut, DUT_MSG_ERROR,
4787 "%s: err in adding vendor_cmd and vendor_data",
4788 __func__);
4789 nlmsg_free(msg);
4790 return -1;
4791 }
4792 nla_nest_end(msg, params);
4793
4794 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4795 if (ret) {
4796 sigma_dut_print(dut, DUT_MSG_ERROR,
4797 "%s: err in send_and_recv_msgs, ret=%d",
4798 __func__, ret);
4799 }
4800 return ret;
4801}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004802
4803
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08004804int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
4805 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004806{
4807 struct nl_msg *msg;
4808 int ret = 0;
4809 struct nlattr *params;
4810 int ifindex;
4811
4812 ifindex = if_nametoindex(intf);
4813 if (ifindex == 0) {
4814 sigma_dut_print(dut, DUT_MSG_ERROR,
4815 "%s: Index for interface %s failed",
4816 __func__, intf);
4817 return -1;
4818 }
4819
4820 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4821 NL80211_CMD_VENDOR)) ||
4822 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4823 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4824 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4825 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4826 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4827 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
4828 ltf)) {
4829 sigma_dut_print(dut, DUT_MSG_ERROR,
4830 "%s: err in adding vendor_cmd and vendor_data",
4831 __func__);
4832 nlmsg_free(msg);
4833 return -1;
4834 }
4835 nla_nest_end(msg, params);
4836
4837 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4838 if (ret) {
4839 sigma_dut_print(dut, DUT_MSG_ERROR,
4840 "%s: err in send_and_recv_msgs, ret=%d",
4841 __func__, ret);
4842 }
4843 return ret;
4844}
4845
4846
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004847static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4848 int noack, enum qca_wlan_ac_type ac)
4849{
4850 struct nl_msg *msg;
4851 int ret = 0;
4852 struct nlattr *params;
4853 int ifindex;
4854
4855 ifindex = if_nametoindex(intf);
4856 if (ifindex == 0) {
4857 sigma_dut_print(dut, DUT_MSG_ERROR,
4858 "%s: Index for interface %s failed",
4859 __func__, intf);
4860 return -1;
4861 }
4862
4863 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4864 NL80211_CMD_VENDOR)) ||
4865 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4866 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4867 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4868 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4869 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4870 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4871 noack) ||
4872 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4873 ac)) {
4874 sigma_dut_print(dut, DUT_MSG_ERROR,
4875 "%s: err in adding vendor_cmd and vendor_data",
4876 __func__);
4877 nlmsg_free(msg);
4878 return -1;
4879 }
4880 nla_nest_end(msg, params);
4881
4882 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4883 if (ret) {
4884 sigma_dut_print(dut, DUT_MSG_ERROR,
4885 "%s: err in send_and_recv_msgs, ret=%d",
4886 __func__, ret);
4887 }
4888 return ret;
4889}
4890
4891
4892static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4893 const char *val)
4894{
4895 int noack, ret;
4896 char token[100];
4897 char *result;
4898 char *saveptr;
4899 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4900
4901 strlcpy(token, val, sizeof(token));
4902 token[sizeof(token) - 1] = '\0';
4903 result = strtok_r(token, ":", &saveptr);
4904 while (result) {
4905 noack = strcasecmp(result, "Disable") != 0;
4906 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4907 if (ret) {
4908 sigma_dut_print(dut, DUT_MSG_ERROR,
4909 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4910 ac, ret);
4911 }
4912 result = strtok_r(NULL, ":", &saveptr);
4913 ac++;
4914 }
4915}
4916
Vinita S. Maloo7462e812020-05-22 15:16:04 +05304917
4918static int nlvendor_sta_set_phymode(struct sigma_dut *dut, const char *intf,
4919 enum qca_wlan_vendor_phy_mode val)
4920{
4921 struct nl_msg *msg;
4922 struct nlattr *params;
4923 int ifindex, ret;
4924
4925 ifindex = if_nametoindex(intf);
4926 if (ifindex == 0) {
4927 sigma_dut_print(dut, DUT_MSG_ERROR,
4928 "%s: Index for interface %s not found",
4929 __func__, intf);
4930 return -1;
4931 }
4932
4933 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4934 NL80211_CMD_VENDOR);
4935 if (!msg) {
4936 sigma_dut_print(dut, DUT_MSG_ERROR,
4937 "%s: err in adding vendor_cmd", __func__);
4938 return -1;
4939 }
4940
4941 if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4942 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4943 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) {
4944 sigma_dut_print(dut, DUT_MSG_ERROR,
4945 "%s: err in adding vendor_attr", __func__);
4946 nlmsg_free(msg);
4947 return -1;
4948 }
4949
4950 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
4951 if (!params || nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_PHY_MODE,
4952 val)) {
4953 sigma_dut_print(dut, DUT_MSG_ERROR,
4954 "%s: err in adding vendor_data", __func__);
4955 nlmsg_free(msg);
4956 return -1;
4957 }
4958
4959 nla_nest_end(msg, params);
4960 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4961 if (ret) {
4962 sigma_dut_print(dut, DUT_MSG_ERROR,
4963 "%s: err in send_and_recv_msgs, ret=%d (%s)",
4964 __func__, ret, strerror(-ret));
4965 return ret;
4966 }
4967
4968 return 0;
4969}
4970
4971
4972static enum qca_wlan_vendor_phy_mode get_qca_vendor_phymode(const char *val)
4973{
4974 if (strcmp(val, "11a") == 0) {
4975 /* IEEE80211_MODE_11A */
4976 return QCA_WLAN_VENDOR_PHY_MODE_11A;
4977 }
4978
4979 if (strcmp(val, "11g") == 0) {
4980 /* IEEE80211_MODE_11G */
4981 return QCA_WLAN_VENDOR_PHY_MODE_11G;
4982 }
4983
4984 if (strcmp(val, "11b") == 0) {
4985 /* IEEE80211_MODE_11B */
4986 return QCA_WLAN_VENDOR_PHY_MODE_11B;
4987 }
4988
4989 if (strcmp(val, "11n") == 0 ||
4990 strcmp(val, "11nl") == 0 ||
4991 strcmp(val, "11nl(nabg)") == 0) {
4992 /* IEEE80211_MODE_11AGN */
4993 return QCA_WLAN_VENDOR_PHY_MODE_11AGN;
4994 }
4995
4996 if (strcmp(val, "11ng") == 0) {
4997 /* IEEE80211_MODE_11NG_HT40 */
4998 return QCA_WLAN_VENDOR_PHY_MODE_11NG_HT40;
4999 }
5000
5001 if (strcmp(val, "AC") == 0 ||
5002 strcasecmp(val, "11AC") == 0) {
5003 /* IEEE80211_MODE_11AC_VHT80 */
5004 return QCA_WLAN_VENDOR_PHY_MODE_11AC_VHT80;
5005 }
5006
5007 if (strcmp(val, "11na") == 0 ||
5008 strcasecmp(val, "11an") == 0) {
5009 /* IEEE80211_MODE_11NA_HT40 */
5010 return QCA_WLAN_VENDOR_PHY_MODE_11NA_HT40;
5011 }
5012
5013 if (strcmp(val, "11ax") == 0 ||
5014 strcmp(val, "auto") == 0) {
5015 /* IEEE80211_MODE_AUTO */
5016 return QCA_WLAN_VENDOR_PHY_MODE_AUTO;
5017 }
5018
5019 return -1;
5020}
5021
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005022#endif /* NL80211_SUPPORT */
5023
5024
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305025static int get_phymode(const char *val)
5026{
5027 if (strcmp(val, "11a") == 0)
5028 return 1; /* IEEE80211_MODE_11A */
5029 if (strcmp(val, "11g") == 0)
5030 return 3; /* IEEE80211_MODE_11G */
5031 if (strcmp(val, "11b") == 0)
5032 return 2; /* IEEE80211_MODE_11B */
5033 if (strcmp(val, "11n") == 0 ||
5034 strcmp(val, "11nl") == 0 ||
5035 strcmp(val, "11nl(nabg)") == 0)
5036 return 22; /* IEEE80211_MODE_11AGN */
5037 if (strcmp(val, "11ng") == 0)
5038 return 13; /* IEEE80211_MODE_11NG_HT40 */
5039 if (strcmp(val, "AC") == 0 ||
5040 strcasecmp(val, "11AC") == 0)
5041 return 19; /* IEEE80211_MODE_11AC_VHT80 */
5042 if (strcmp(val, "11na") == 0 ||
5043 strcasecmp(val, "11an") == 0)
5044 return 14; /* IEEE80211_MODE_11NA_HT40 */
5045 if (strcmp(val, "11ax") == 0 ||
5046 strcmp(val, "auto") == 0)
5047 return 0; /* IEEE80211_MODE_AUTO */
5048 return -1;
5049}
5050
5051
5052static void sta_set_phymode(struct sigma_dut *dut, const char *intf,
5053 const char *val)
5054{
5055 char buf[100];
5056 int len, phymode;
Vinita S. Maloo7462e812020-05-22 15:16:04 +05305057#ifdef NL80211_SUPPORT
5058 enum qca_wlan_vendor_phy_mode qca_phymode;
5059
5060 qca_phymode = get_qca_vendor_phymode(val);
5061 if (qca_phymode == -1) {
5062 sigma_dut_print(dut, DUT_MSG_DEBUG,
5063 "Ignoring mode change for mode: %s",
5064 val);
5065 return;
5066 }
5067
5068 if (nlvendor_sta_set_phymode(dut, intf, qca_phymode) == 0)
5069 return;
5070#endif /* NL80211_SUPPORT */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305071
5072 phymode = get_phymode(val);
5073 if (phymode == -1) {
5074 sigma_dut_print(dut, DUT_MSG_DEBUG,
5075 "Ignoring mode change for mode: %s",
5076 val);
5077 return;
5078 }
5079
5080 len = snprintf(buf, sizeof(buf), "iwpriv %s setphymode %d", intf,
5081 phymode);
5082 if (len < 0 || len >= sizeof(buf)) {
5083 sigma_dut_print(dut, DUT_MSG_ERROR,
5084 "Failed to set phymode");
5085 return;
5086 }
5087
5088 if (system(buf) != 0)
5089 sigma_dut_print(dut, DUT_MSG_ERROR,
5090 "iwpriv setting of phymode failed");
5091}
5092
5093
Jouni Malinenf7222712019-06-13 01:50:21 +03005094static enum sigma_cmd_result
5095cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
5096 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005097{
5098 const char *intf = get_param(cmd, "Interface");
5099 const char *val;
5100
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03005101 val = get_param(cmd, "FT_DS");
5102 if (val) {
5103 if (strcasecmp(val, "Enable") == 0) {
5104 dut->sta_ft_ds = 1;
5105 } else if (strcasecmp(val, "Disable") == 0) {
5106 dut->sta_ft_ds = 0;
5107 } else {
5108 send_resp(dut, conn, SIGMA_ERROR,
5109 "errorCode,Unsupported value for FT_DS");
5110 return STATUS_SENT_ERROR;
5111 }
5112 }
5113
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005114 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03005115 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
5116 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005117 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
5118 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005119
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005120 if (val && strcasecmp(val, "LOC") == 0)
5121 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02005122 if (val && strcasecmp(val, "60GHZ") == 0) {
5123 val = get_param(cmd, "WPS");
5124 if (val && strcasecmp(val, "disable") == 0) {
5125 dut->wps_disable = 1;
5126 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
5127 } else {
5128 /* wps_disable can have other value from the previous
5129 * test, so make sure it has the correct value.
5130 */
5131 dut->wps_disable = 0;
5132 }
5133
5134 val = get_param(cmd, "P2P");
5135 if (val && strcasecmp(val, "disable") == 0)
5136 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
5137 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005138
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02005139 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
5140 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
5141
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005142#ifdef ANDROID_NAN
5143 if (val && strcasecmp(val, "NAN") == 0)
5144 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
5145#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005146#ifdef MIRACAST
5147 if (val && (strcasecmp(val, "WFD") == 0 ||
5148 strcasecmp(val, "DisplayR2") == 0))
5149 return miracast_preset_testparameters(dut, conn, cmd);
5150#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005151
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07005152 if (val &&
5153 (strcasecmp(val, "MBO") == 0 || strcasecmp(val, "HE") == 0)) {
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305154 val = get_param(cmd, "Cellular_Data_Cap");
5155 if (val &&
5156 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
5157 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05305158
5159 val = get_param(cmd, "Ch_Pref");
5160 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
5161 return 0;
5162
Ashwini Patilc63161e2017-04-13 16:30:23 +05305163 val = get_param(cmd, "BSS_Transition");
5164 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
5165 return 0;
5166
Ashwini Patila75de5a2017-04-13 16:35:05 +05305167 val = get_param(cmd, "Assoc_Disallow");
5168 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
5169 return 0;
5170
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305171 val = get_param(cmd, "Roaming");
5172 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
5173 return 0;
5174
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305175 return 1;
5176 }
5177
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305178 if (val && strcasecmp(val, "OCE") == 0)
5179 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
5180
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005181#if 0
5182 val = get_param(cmd, "Supplicant");
5183 if (val && strcasecmp(val, "Default") != 0) {
5184 send_resp(dut, conn, SIGMA_ERROR,
5185 "ErrorCode,Only default(Vendor) supplicant "
5186 "supported");
5187 return 0;
5188 }
5189#endif
5190
5191 val = get_param(cmd, "RTS");
5192 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005193 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005194 case DRIVER_ATHEROS:
5195 ath_sta_set_rts(dut, intf, val);
5196 break;
5197 default:
5198#if 0
5199 send_resp(dut, conn, SIGMA_ERROR,
5200 "ErrorCode,Setting RTS not supported");
5201 return 0;
5202#else
5203 sigma_dut_print(dut, DUT_MSG_DEBUG,
5204 "Setting RTS not supported");
5205 break;
5206#endif
5207 }
5208 }
5209
5210#if 0
5211 val = get_param(cmd, "FRGMNT");
5212 if (val) {
5213 /* TODO */
5214 send_resp(dut, conn, SIGMA_ERROR,
5215 "ErrorCode,Setting FRGMNT not supported");
5216 return 0;
5217 }
5218#endif
5219
5220#if 0
5221 val = get_param(cmd, "Preamble");
5222 if (val) {
5223 /* TODO: Long/Short */
5224 send_resp(dut, conn, SIGMA_ERROR,
5225 "ErrorCode,Setting Preamble not supported");
5226 return 0;
5227 }
5228#endif
5229
5230 val = get_param(cmd, "Mode");
5231 if (val) {
5232 if (strcmp(val, "11b") == 0 ||
5233 strcmp(val, "11g") == 0 ||
5234 strcmp(val, "11a") == 0 ||
5235 strcmp(val, "11n") == 0 ||
5236 strcmp(val, "11ng") == 0 ||
5237 strcmp(val, "11nl") == 0 ||
5238 strcmp(val, "11nl(nabg)") == 0 ||
5239 strcmp(val, "AC") == 0 ||
5240 strcmp(val, "11AC") == 0 ||
5241 strcmp(val, "11ac") == 0 ||
5242 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08005243 strcmp(val, "11an") == 0 ||
5244 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005245 /* STA supports all modes by default */
5246 } else {
5247 send_resp(dut, conn, SIGMA_ERROR,
5248 "ErrorCode,Setting Mode not supported");
5249 return 0;
5250 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005251
5252 /* Change the mode only in case of testbed for HE program
5253 * and for 11a and 11g modes only. */
5254 if (dut->program == PROGRAM_HE &&
5255 dut->device_type == STA_testbed) {
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305256 sta_set_phymode(dut, intf, val);
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005257 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005258 }
5259
5260 val = get_param(cmd, "wmm");
5261 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005262 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005263 case DRIVER_ATHEROS:
5264 ath_sta_set_wmm(dut, intf, val);
5265 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005266 case DRIVER_WCN:
5267 wcn_sta_set_wmm(dut, intf, val);
5268 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005269 default:
5270 sigma_dut_print(dut, DUT_MSG_DEBUG,
5271 "Setting wmm not supported");
5272 break;
5273 }
5274 }
5275
5276 val = get_param(cmd, "Powersave");
5277 if (val) {
5278 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005279 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305280 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005281 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005282 }
5283
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005284 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005285 "P2P_SET ps 0") < 0)
5286 return -2;
5287 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005288 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5289 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005290 } else if (strcmp(val, "1") == 0 ||
5291 strcasecmp(val, "PSPoll") == 0 ||
5292 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005293 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305294 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005295 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005296 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005297 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005298 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005299 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005300 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005301 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005302 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005303 "P2P_SET ps 99") < 0)
5304 return -2;
5305 } else if (strcmp(val, "2") == 0 ||
5306 strcasecmp(val, "Fast") == 0) {
5307 /* TODO */
5308 send_resp(dut, conn, SIGMA_ERROR,
5309 "ErrorCode,Powersave=Fast not supported");
5310 return 0;
5311 } else if (strcmp(val, "3") == 0 ||
5312 strcasecmp(val, "PSNonPoll") == 0) {
5313 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005314 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5315 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005316
5317 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005318 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005319 "P2P_SET ps 1") < 0)
5320 return -2;
5321 } else
5322 return -1;
5323 }
5324
5325 val = get_param(cmd, "NoAck");
5326 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005327 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005328 case DRIVER_ATHEROS:
5329 ath_sta_set_noack(dut, intf, val);
5330 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005331#ifdef NL80211_SUPPORT
5332 case DRIVER_WCN:
5333 wcn_sta_set_noack(dut, intf, val);
5334 break;
5335#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005336 default:
5337 send_resp(dut, conn, SIGMA_ERROR,
5338 "ErrorCode,Setting NoAck not supported");
5339 return 0;
5340 }
5341 }
5342
5343 val = get_param(cmd, "IgnoreChswitchProhibit");
5344 if (val) {
5345 /* TODO: Enabled/disabled */
5346 if (strcasecmp(val, "Enabled") == 0) {
5347 send_resp(dut, conn, SIGMA_ERROR,
5348 "ErrorCode,Enabling IgnoreChswitchProhibit "
5349 "not supported");
5350 return 0;
5351 }
5352 }
5353
5354 val = get_param(cmd, "TDLS");
5355 if (val) {
5356 if (strcasecmp(val, "Disabled") == 0) {
5357 if (wpa_command(intf, "SET tdls_disabled 1")) {
5358 send_resp(dut, conn, SIGMA_ERROR,
5359 "ErrorCode,Failed to disable TDLS");
5360 return 0;
5361 }
5362 } else if (strcasecmp(val, "Enabled") == 0) {
5363 if (wpa_command(intf, "SET tdls_disabled 0")) {
5364 send_resp(dut, conn, SIGMA_ERROR,
5365 "ErrorCode,Failed to enable TDLS");
5366 return 0;
5367 }
5368 } else {
5369 send_resp(dut, conn, SIGMA_ERROR,
5370 "ErrorCode,Unsupported TDLS value");
5371 return 0;
5372 }
5373 }
5374
5375 val = get_param(cmd, "TDLSmode");
5376 if (val) {
5377 if (strcasecmp(val, "Default") == 0) {
5378 wpa_command(intf, "SET tdls_testing 0");
5379 } else if (strcasecmp(val, "APProhibit") == 0) {
5380 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5381 send_resp(dut, conn, SIGMA_ERROR,
5382 "ErrorCode,Failed to enable ignore "
5383 "APProhibit TDLS mode");
5384 return 0;
5385 }
5386 } else if (strcasecmp(val, "HiLoMac") == 0) {
5387 /* STA should respond with TDLS setup req for a TDLS
5388 * setup req */
5389 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5390 send_resp(dut, conn, SIGMA_ERROR,
5391 "ErrorCode,Failed to enable HiLoMac "
5392 "TDLS mode");
5393 return 0;
5394 }
5395 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5396 /*
5397 * Since all security modes are enabled by default when
5398 * Sigma control is used, there is no need to do
5399 * anything here.
5400 */
5401 } else if (strcasecmp(val, "ExistLink") == 0) {
5402 /*
5403 * Since we allow new TDLS Setup Request even if there
5404 * is an existing link, nothing needs to be done for
5405 * this.
5406 */
5407 } else {
5408 /* TODO:
5409 * ExistLink: STA should send TDLS setup req even if
5410 * direct link already exists
5411 */
5412 send_resp(dut, conn, SIGMA_ERROR,
5413 "ErrorCode,Unsupported TDLSmode value");
5414 return 0;
5415 }
5416 }
5417
5418 val = get_param(cmd, "FakePubKey");
5419 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5420 send_resp(dut, conn, SIGMA_ERROR,
5421 "ErrorCode,Failed to enable FakePubKey");
5422 return 0;
5423 }
5424
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005425#ifdef NL80211_SUPPORT
5426 val = get_param(cmd, "FrgmntSupport");
5427 if (val) {
5428 if (strcasecmp(val, "Enable") == 0) {
5429 if (sta_set_he_fragmentation(dut, intf,
5430 HE_FRAG_LEVEL1)) {
5431 send_resp(dut, conn, SIGMA_ERROR,
5432 "ErrorCode,Failed to enable HE Fragmentation");
5433 return 0;
5434 }
5435 } else if (strcasecmp(val, "Disable") == 0) {
5436 if (sta_set_he_fragmentation(dut, intf,
5437 HE_FRAG_DISABLE)) {
5438 send_resp(dut, conn, SIGMA_ERROR,
5439 "ErrorCode,Failed to disable HE Fragmentation");
5440 return 0;
5441 }
5442 }
5443 }
5444#endif /* NL80211_SUPPORT */
5445
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305446 val = get_param(cmd, "IncludeMSCSDescriptor");
5447 if (val && strcasecmp(val, "1") == 0) {
5448 char buf[128];
5449 int len;
5450
5451 len = snprintf(buf, sizeof(buf),
Veerendranath Jakkam62cde372020-08-19 18:03:06 +05305452 "MSCS add up_bitmap=F0 up_limit=7 stream_timeout=60000 frame_classifier=045F%032x",
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305453 0);
5454
5455 if (len < 0 || len >= sizeof(buf)) {
5456 sigma_dut_print(dut, DUT_MSG_ERROR,
5457 "Failed to build MSCS Descriptor IE");
5458 return ERROR_SEND_STATUS;
5459 }
5460
5461 if (wpa_command(intf, buf) != 0) {
5462 send_resp(dut, conn, SIGMA_ERROR,
5463 "ErrorCode,Failed to include MSCS descriptor");
5464 return STATUS_SENT_ERROR;
5465 }
5466 }
5467
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005468 return 1;
5469}
5470
5471
5472static const char * ath_get_radio_name(const char *radio_name)
5473{
5474 if (radio_name == NULL)
5475 return "wifi0";
5476 if (strcmp(radio_name, "wifi1") == 0)
5477 return "wifi1";
5478 if (strcmp(radio_name, "wifi2") == 0)
5479 return "wifi2";
5480 return "wifi0";
5481}
5482
5483
5484static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5485 const char *val)
5486{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005487 unsigned int vht_mcsmap = 0;
5488 int txchainmask = 0;
5489 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5490
5491 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5492 if (dut->testbed_flag_txsp == 1) {
5493 vht_mcsmap = 0xfffc;
5494 dut->testbed_flag_txsp = 0;
5495 } else {
5496 vht_mcsmap = 0xfffe;
5497 }
5498 txchainmask = 1;
5499 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5500 if (dut->testbed_flag_txsp == 1) {
5501 vht_mcsmap = 0xfff0;
5502 dut->testbed_flag_txsp = 0;
5503 } else {
5504 vht_mcsmap = 0xfffa;
5505 }
5506 txchainmask = 3;
5507 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5508 if (dut->testbed_flag_txsp == 1) {
5509 vht_mcsmap = 0xffc0;
5510 dut->testbed_flag_txsp = 0;
5511 } else {
5512 vht_mcsmap = 0xffea;
5513 }
5514 txchainmask = 7;
5515 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5516 if (dut->testbed_flag_txsp == 1) {
5517 vht_mcsmap = 0xff00;
5518 dut->testbed_flag_txsp = 0;
5519 } else {
5520 vht_mcsmap = 0xffaa;
5521 }
5522 txchainmask = 15;
5523 } else {
5524 if (dut->testbed_flag_txsp == 1) {
5525 vht_mcsmap = 0xffc0;
5526 dut->testbed_flag_txsp = 0;
5527 } else {
5528 vht_mcsmap = 0xffea;
5529 }
5530 }
5531
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005532 if (txchainmask)
5533 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005534
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005535 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005536}
5537
5538
5539static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5540 const char *val)
5541{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005542 unsigned int vht_mcsmap = 0;
5543 int rxchainmask = 0;
5544 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5545
5546 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5547 if (dut->testbed_flag_rxsp == 1) {
5548 vht_mcsmap = 0xfffc;
5549 dut->testbed_flag_rxsp = 0;
5550 } else {
5551 vht_mcsmap = 0xfffe;
5552 }
5553 rxchainmask = 1;
5554 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5555 if (dut->testbed_flag_rxsp == 1) {
5556 vht_mcsmap = 0xfff0;
5557 dut->testbed_flag_rxsp = 0;
5558 } else {
5559 vht_mcsmap = 0xfffa;
5560 }
5561 rxchainmask = 3;
5562 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5563 if (dut->testbed_flag_rxsp == 1) {
5564 vht_mcsmap = 0xffc0;
5565 dut->testbed_flag_rxsp = 0;
5566 } else {
5567 vht_mcsmap = 0xffea;
5568 }
5569 rxchainmask = 7;
5570 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5571 if (dut->testbed_flag_rxsp == 1) {
5572 vht_mcsmap = 0xff00;
5573 dut->testbed_flag_rxsp = 0;
5574 } else {
5575 vht_mcsmap = 0xffaa;
5576 }
5577 rxchainmask = 15;
5578 } else {
5579 if (dut->testbed_flag_rxsp == 1) {
5580 vht_mcsmap = 0xffc0;
5581 dut->testbed_flag_rxsp = 0;
5582 } else {
5583 vht_mcsmap = 0xffea;
5584 }
5585 }
5586
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005587 if (rxchainmask)
5588 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005589
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005590 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005591}
5592
5593
5594void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5595{
5596 if (strcasecmp(val, "enable") == 0) {
5597 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5598 != 0) {
5599 sigma_dut_print(dut, DUT_MSG_ERROR,
5600 "Disable BB_VHTSIGB_CRC_CALC failed");
5601 }
5602
5603 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5604 != 0) {
5605 sigma_dut_print(dut, DUT_MSG_ERROR,
5606 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5607 }
5608 } else {
5609 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5610 != 0) {
5611 sigma_dut_print(dut, DUT_MSG_ERROR,
5612 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5613 }
5614
5615 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5616 != 0) {
5617 sigma_dut_print(dut, DUT_MSG_ERROR,
5618 "Enable BB_VHTSIGB_CRC_CALC failed");
5619 }
5620 }
5621}
5622
5623
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005624static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5625 const char *val)
5626{
5627 char buf[60];
5628
5629 if (strcmp(val, "20") == 0) {
5630 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5631 dut->chwidth = 0;
5632 } else if (strcmp(val, "40") == 0) {
5633 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5634 dut->chwidth = 1;
5635 } else if (strcmp(val, "80") == 0) {
5636 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5637 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305638 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005639 buf[0] = '\0';
5640 } else {
5641 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5642 val);
5643 return -1;
5644 }
5645
5646 if (buf[0] != '\0' && system(buf) != 0) {
5647 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5648 return -1;
5649 }
5650
5651 return 0;
5652}
5653
5654
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005655static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5656 const char *intf, int addbareject)
5657{
5658#ifdef NL80211_SUPPORT
5659 struct nl_msg *msg;
5660 int ret = 0;
5661 struct nlattr *params;
5662 int ifindex;
5663
5664 ifindex = if_nametoindex(intf);
5665 if (ifindex == 0) {
5666 sigma_dut_print(dut, DUT_MSG_ERROR,
5667 "%s: Index for interface %s failed",
5668 __func__, intf);
5669 return -1;
5670 }
5671
5672 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5673 NL80211_CMD_VENDOR)) ||
5674 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5675 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5676 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5677 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5678 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5679 nla_put_u8(msg,
5680 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5681 !addbareject)) {
5682 sigma_dut_print(dut, DUT_MSG_ERROR,
5683 "%s: err in adding vendor_cmd and vendor_data",
5684 __func__);
5685 nlmsg_free(msg);
5686 return -1;
5687 }
5688 nla_nest_end(msg, params);
5689
5690 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5691 if (ret) {
5692 sigma_dut_print(dut, DUT_MSG_ERROR,
5693 "%s: err in send_and_recv_msgs, ret=%d",
5694 __func__, ret);
5695 }
5696 return ret;
5697#else /* NL80211_SUPPORT */
5698 sigma_dut_print(dut, DUT_MSG_ERROR,
5699 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5700 return -1;
5701#endif /* NL80211_SUPPORT */
5702}
5703
5704
5705static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5706 int addbareject)
5707{
5708 int ret;
5709
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005710 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005711 case DRIVER_WCN:
5712 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5713 if (ret) {
5714 sigma_dut_print(dut, DUT_MSG_ERROR,
5715 "nlvendor_sta_set_addba_reject failed, ret:%d",
5716 ret);
5717 return ret;
5718 }
5719 break;
5720 default:
5721 sigma_dut_print(dut, DUT_MSG_ERROR,
5722 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5723 ret = -1;
5724 break;
5725 }
5726
5727 return ret;
5728}
5729
5730
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005731static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5732 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005733{
5734#ifdef NL80211_SUPPORT
5735 struct nl_msg *msg;
5736 int ret = 0;
5737 struct nlattr *params;
5738 int ifindex;
5739
5740 ifindex = if_nametoindex(intf);
5741 if (ifindex == 0) {
5742 sigma_dut_print(dut, DUT_MSG_ERROR,
5743 "%s: Index for interface %s failed",
5744 __func__, intf);
5745 return -1;
5746 }
5747
5748 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5749 NL80211_CMD_VENDOR)) ||
5750 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5751 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5752 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5753 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5754 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5755 nla_put_u8(msg,
5756 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005757 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005758 sigma_dut_print(dut, DUT_MSG_ERROR,
5759 "%s: err in adding vendor_cmd and vendor_data",
5760 __func__);
5761 nlmsg_free(msg);
5762 return -1;
5763 }
5764 nla_nest_end(msg, params);
5765
5766 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5767 if (ret) {
5768 sigma_dut_print(dut, DUT_MSG_ERROR,
5769 "%s: err in send_and_recv_msgs, ret=%d",
5770 __func__, ret);
5771 }
5772 return ret;
5773#else /* NL80211_SUPPORT */
5774 sigma_dut_print(dut, DUT_MSG_ERROR,
5775 "Disable addba not possible without NL80211_SUPPORT defined");
5776 return -1;
5777#endif /* NL80211_SUPPORT */
5778}
5779
5780
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305781#ifdef NL80211_SUPPORT
5782static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5783{
5784 struct nl_msg *msg;
5785 int ret = 0;
5786 int ifindex;
5787
5788 ifindex = if_nametoindex(intf);
5789 if (ifindex == 0) {
5790 sigma_dut_print(dut, DUT_MSG_ERROR,
5791 "%s: Index for interface %s failed",
5792 __func__, intf);
5793 return -1;
5794 }
5795
5796 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5797 NL80211_CMD_SET_WIPHY)) ||
5798 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5799 sigma_dut_print(dut, DUT_MSG_ERROR,
5800 "%s: err in adding RTS threshold",
5801 __func__);
5802 nlmsg_free(msg);
5803 return -1;
5804 }
5805
5806 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5807 if (ret) {
5808 sigma_dut_print(dut, DUT_MSG_ERROR,
5809 "%s: err in send_and_recv_msgs, ret=%d",
5810 __func__, ret);
5811 }
5812 return ret;
5813}
5814#endif /* NL80211_SUPPORT */
5815
5816
5817static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5818{
5819 char buf[100];
5820
5821#ifdef NL80211_SUPPORT
5822 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5823 return 0;
5824 sigma_dut_print(dut, DUT_MSG_DEBUG,
5825 "Fall back to using iwconfig for setting RTS threshold");
5826#endif /* NL80211_SUPPORT */
5827
5828 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5829 if (system(buf) != 0) {
5830 sigma_dut_print(dut, DUT_MSG_ERROR,
5831 "Failed to set RTS threshold %d", val);
5832 return -1;
5833 }
5834 return 0;
5835}
5836
5837
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005838static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5839 struct sigma_conn *conn,
5840 struct sigma_cmd *cmd)
5841{
5842 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005843 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005844 char buf[128];
5845 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005846
5847 val = get_param(cmd, "40_INTOLERANT");
5848 if (val) {
5849 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5850 /* TODO: iwpriv ht40intol through wpa_supplicant */
5851 send_resp(dut, conn, SIGMA_ERROR,
5852 "ErrorCode,40_INTOLERANT not supported");
5853 return 0;
5854 }
5855 }
5856
5857 val = get_param(cmd, "ADDBA_REJECT");
5858 if (val) {
5859 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5860 /* reject any ADDBA with status "decline" */
5861 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005862 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005863 } else {
5864 /* accept ADDBA */
5865 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005866 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005867 }
5868 }
5869
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005870 if (addbareject >= 0 &&
5871 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5872 send_resp(dut, conn, SIGMA_ERROR,
5873 "ErrorCode,set addba_reject failed");
5874 return 0;
5875 }
5876
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005877 val = get_param(cmd, "AMPDU");
5878 if (val) {
5879 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5880 /* enable AMPDU Aggregation */
5881 if (ampdu == 0) {
5882 send_resp(dut, conn, SIGMA_ERROR,
5883 "ErrorCode,Mismatch in "
5884 "addba_reject/ampdu - "
5885 "not supported");
5886 return 0;
5887 }
5888 ampdu = 1;
5889 } else {
5890 /* disable AMPDU Aggregation */
5891 if (ampdu == 1) {
5892 send_resp(dut, conn, SIGMA_ERROR,
5893 "ErrorCode,Mismatch in "
5894 "addba_reject/ampdu - "
5895 "not supported");
5896 return 0;
5897 }
5898 ampdu = 0;
5899 }
5900 }
5901
5902 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005903 int ret;
5904
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005905 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5906 ampdu ? "Enabling" : "Disabling");
5907 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005908 if (wpa_command(intf, buf) < 0 &&
5909 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005910 send_resp(dut, conn, SIGMA_ERROR,
5911 "ErrorCode,set aggr failed");
5912 return 0;
5913 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005914
5915 if (ampdu == 0) {
5916 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005917 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005918 if (ret) {
5919 sigma_dut_print(dut, DUT_MSG_ERROR,
5920 "Failed to disable addba, ret:%d",
5921 ret);
5922 }
5923 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005924 }
5925
5926 val = get_param(cmd, "AMSDU");
5927 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005928 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005929 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005930 case DRIVER_WCN:
5931 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005932 break;
5933 default:
5934 if (strcmp(val, "1") == 0 ||
5935 strcasecmp(val, "Enable") == 0) {
5936 /* Enable AMSDU Aggregation */
5937 send_resp(dut, conn, SIGMA_ERROR,
5938 "ErrorCode,AMSDU aggregation not supported");
5939 return 0;
5940 }
5941 break;
5942 }
5943 }
5944
5945 val = get_param(cmd, "STBC_RX");
5946 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005947 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005948 case DRIVER_ATHEROS:
5949 ath_sta_set_stbc(dut, intf, val);
5950 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305951 case DRIVER_WCN:
5952 wcn_sta_set_stbc(dut, intf, val);
5953 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005954 default:
5955 send_resp(dut, conn, SIGMA_ERROR,
5956 "ErrorCode,STBC_RX not supported");
5957 return 0;
5958 }
5959 }
5960
5961 val = get_param(cmd, "WIDTH");
5962 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005963 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005964 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005965 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005966 send_resp(dut, conn, SIGMA_ERROR,
5967 "ErrorCode,Failed to set WIDTH");
5968 return 0;
5969 }
5970 break;
5971 case DRIVER_ATHEROS:
5972 if (ath_set_width(dut, conn, intf, val) < 0)
5973 return 0;
5974 break;
5975 default:
5976 sigma_dut_print(dut, DUT_MSG_ERROR,
5977 "Setting WIDTH not supported");
5978 break;
5979 }
5980 }
5981
5982 val = get_param(cmd, "SMPS");
5983 if (val) {
5984 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5985 send_resp(dut, conn, SIGMA_ERROR,
5986 "ErrorCode,SMPS not supported");
5987 return 0;
5988 }
5989
5990 val = get_param(cmd, "TXSP_STREAM");
5991 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005992 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005993 case DRIVER_WCN:
5994 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5995 send_resp(dut, conn, SIGMA_ERROR,
5996 "ErrorCode,Failed to set TXSP_STREAM");
5997 return 0;
5998 }
5999 break;
6000 case DRIVER_ATHEROS:
6001 ath_sta_set_txsp_stream(dut, intf, val);
6002 break;
6003 default:
6004 sigma_dut_print(dut, DUT_MSG_ERROR,
6005 "Setting TXSP_STREAM not supported");
6006 break;
6007 }
6008 }
6009
6010 val = get_param(cmd, "RXSP_STREAM");
6011 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006012 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006013 case DRIVER_WCN:
6014 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
6015 send_resp(dut, conn, SIGMA_ERROR,
6016 "ErrorCode,Failed to set RXSP_STREAM");
6017 return 0;
6018 }
6019 break;
6020 case DRIVER_ATHEROS:
6021 ath_sta_set_rxsp_stream(dut, intf, val);
6022 break;
6023 default:
6024 sigma_dut_print(dut, DUT_MSG_ERROR,
6025 "Setting RXSP_STREAM not supported");
6026 break;
6027 }
6028 }
6029
6030 val = get_param(cmd, "DYN_BW_SGNL");
6031 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006032 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006033 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08006034 if (strcasecmp(val, "enable") == 0) {
6035 snprintf(buf, sizeof(buf),
6036 "iwpriv %s cwmenable 1", intf);
6037 if (system(buf) != 0) {
6038 sigma_dut_print(dut, DUT_MSG_ERROR,
6039 "iwpriv cwmenable 1 failed");
6040 return 0;
6041 }
6042 } else if (strcasecmp(val, "disable") == 0) {
6043 snprintf(buf, sizeof(buf),
6044 "iwpriv %s cwmenable 0", intf);
6045 if (system(buf) != 0) {
6046 sigma_dut_print(dut, DUT_MSG_ERROR,
6047 "iwpriv cwmenable 0 failed");
6048 return 0;
6049 }
6050 } else {
6051 sigma_dut_print(dut, DUT_MSG_ERROR,
6052 "Unsupported DYN_BW_SGL");
6053 }
6054
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006055 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
6056 if (system(buf) != 0) {
6057 sigma_dut_print(dut, DUT_MSG_ERROR,
6058 "Failed to set cts_cbw in DYN_BW_SGNL");
6059 return 0;
6060 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006061 break;
6062 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006063 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08006064 ath_config_dyn_bw_sig(dut, intf, val);
6065 break;
6066 default:
6067 sigma_dut_print(dut, DUT_MSG_ERROR,
6068 "Failed to set DYN_BW_SGNL");
6069 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006070 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006071 }
6072
6073 val = get_param(cmd, "RTS_FORCE");
6074 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07006075 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006076 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306077 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006078 sigma_dut_print(dut, DUT_MSG_ERROR,
6079 "Failed to set RTS_FORCE 64");
6080 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03006081 res = snprintf(buf, sizeof(buf),
6082 "wifitool %s beeliner_fw_test 100 1",
6083 intf);
6084 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08006085 sigma_dut_print(dut, DUT_MSG_ERROR,
6086 "wifitool beeliner_fw_test 100 1 failed");
6087 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006088 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05306089 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02006090 sigma_dut_print(dut, DUT_MSG_ERROR,
6091 "Failed to set RTS_FORCE 2347");
6092 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006093 } else {
6094 send_resp(dut, conn, SIGMA_ERROR,
6095 "ErrorCode,RTS_FORCE value not supported");
6096 return 0;
6097 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006098 }
6099
6100 val = get_param(cmd, "CTS_WIDTH");
6101 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006102 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006103 case DRIVER_WCN:
6104 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
6105 send_resp(dut, conn, SIGMA_ERROR,
6106 "ErrorCode,Failed to set CTS_WIDTH");
6107 return 0;
6108 }
6109 break;
6110 case DRIVER_ATHEROS:
6111 ath_set_cts_width(dut, intf, val);
6112 break;
6113 default:
6114 sigma_dut_print(dut, DUT_MSG_ERROR,
6115 "Setting CTS_WIDTH not supported");
6116 break;
6117 }
6118 }
6119
6120 val = get_param(cmd, "BW_SGNL");
6121 if (val) {
6122 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006123 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006124 } else if (strcasecmp(val, "Disable") == 0) {
6125 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006126 } else {
6127 send_resp(dut, conn, SIGMA_ERROR,
6128 "ErrorCode,BW_SGNL value not supported");
6129 return 0;
6130 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006131 }
6132
6133 val = get_param(cmd, "Band");
6134 if (val) {
6135 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
6136 /* STA supports all bands by default */
6137 } else {
6138 send_resp(dut, conn, SIGMA_ERROR,
6139 "ErrorCode,Unsupported Band");
6140 return 0;
6141 }
6142 }
6143
6144 val = get_param(cmd, "zero_crc");
6145 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006146 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006147 case DRIVER_ATHEROS:
6148 ath_set_zero_crc(dut, val);
6149 break;
6150 default:
6151 break;
6152 }
6153 }
6154
6155 return 1;
6156}
6157
6158
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006159static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
6160{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006161 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006162#ifdef __linux__
6163 case DRIVER_WIL6210:
6164 return wil6210_set_force_mcs(dut, force, mcs);
6165#endif /* __linux__ */
6166 default:
6167 sigma_dut_print(dut, DUT_MSG_ERROR,
6168 "Unsupported sta_set_force_mcs with the current driver");
6169 return -1;
6170 }
6171}
6172
6173
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006174static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
6175{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006176 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02006177#ifdef __linux__
6178 case DRIVER_WIL6210:
6179 return wil6210_force_rsn_ie(dut, state);
6180#endif /* __linux__ */
6181 default:
6182 sigma_dut_print(dut, DUT_MSG_ERROR,
6183 "Unsupported sta_60g_force_rsn_ie with the current driver");
6184 return -1;
6185 }
6186}
6187
6188
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006189static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
6190 struct sigma_cmd *cmd)
6191{
6192 const char *val;
6193 char buf[100];
6194
6195 val = get_param(cmd, "MSDUSize");
6196 if (val) {
6197 int mtu;
6198
6199 dut->amsdu_size = atoi(val);
6200 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
6201 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
6202 sigma_dut_print(dut, DUT_MSG_ERROR,
6203 "MSDUSize %d is above max %d or below min %d",
6204 dut->amsdu_size,
6205 IEEE80211_MAX_DATA_LEN_DMG,
6206 IEEE80211_SNAP_LEN_DMG);
6207 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006208 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006209 }
6210
6211 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
6212 sigma_dut_print(dut, DUT_MSG_DEBUG,
6213 "Setting amsdu_size to %d", mtu);
6214 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006215 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006216
6217 if (system(buf) != 0) {
6218 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
6219 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006220 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006221 }
6222 }
6223
6224 val = get_param(cmd, "BAckRcvBuf");
6225 if (val) {
6226 dut->back_rcv_buf = atoi(val);
6227 if (dut->back_rcv_buf == 0) {
6228 sigma_dut_print(dut, DUT_MSG_ERROR,
6229 "Failed to convert %s or value is 0",
6230 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006231 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006232 }
6233
6234 sigma_dut_print(dut, DUT_MSG_DEBUG,
6235 "Setting BAckRcvBuf to %s", val);
6236 }
6237
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006238 val = get_param(cmd, "MCS_FixedRate");
6239 if (val) {
6240 if (sta_set_force_mcs(dut, 1, atoi(val))) {
6241 sigma_dut_print(dut, DUT_MSG_ERROR,
6242 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006243 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006244 }
6245 }
6246
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006247 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006248}
6249
6250
6251static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
6252 struct sigma_cmd *cmd)
6253{
6254 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006255 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006256 const char *val;
6257 char buf[100];
6258
6259 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006260 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006261 if (wpa_command(ifname, "PING") != 0) {
6262 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006263 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006264 }
6265
6266 wpa_command(ifname, "FLUSH");
6267 net_id = add_network_common(dut, conn, ifname, cmd);
6268 if (net_id < 0) {
6269 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
6270 return net_id;
6271 }
6272
6273 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
6274 if (set_network(ifname, net_id, "mode", "2") < 0) {
6275 sigma_dut_print(dut, DUT_MSG_ERROR,
6276 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006277 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006278 }
6279
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006280 if (set_network(ifname, net_id, "pbss", "1") < 0)
6281 return -2;
6282
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006283 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006284 "Supplicant set network with mode 2. network_id %d",
6285 net_id);
6286
6287 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6288 sigma_dut_print(dut, DUT_MSG_INFO,
6289 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006290 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006291 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006292
6293 val = get_param(cmd, "Security");
6294 if (val && strcasecmp(val, "OPEN") == 0) {
6295 dut->ap_key_mgmt = AP_OPEN;
6296 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6297 sigma_dut_print(dut, DUT_MSG_ERROR,
6298 "Failed to set supplicant to %s security",
6299 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006300 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006301 }
6302 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6303 dut->ap_key_mgmt = AP_WPA2_PSK;
6304 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6305 sigma_dut_print(dut, DUT_MSG_ERROR,
6306 "Failed to set supplicant to %s security",
6307 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006308 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006309 }
6310
6311 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6312 sigma_dut_print(dut, DUT_MSG_ERROR,
6313 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006314 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006315 }
6316 } else if (val) {
6317 sigma_dut_print(dut, DUT_MSG_ERROR,
6318 "Requested Security %s is not supported on 60GHz",
6319 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006320 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006321 }
6322
6323 val = get_param(cmd, "Encrypt");
6324 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6325 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6326 sigma_dut_print(dut, DUT_MSG_ERROR,
6327 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006328 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006329 }
6330 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6331 sigma_dut_print(dut, DUT_MSG_ERROR,
6332 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006333 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006334 }
6335 } else if (val) {
6336 sigma_dut_print(dut, DUT_MSG_ERROR,
6337 "Requested Encrypt %s is not supported on 60 GHz",
6338 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006339 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006340 }
6341
6342 val = get_param(cmd, "PSK");
6343 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6344 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6345 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006346 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006347 }
6348
6349 /* Convert 60G channel to freq */
6350 switch (dut->ap_channel) {
6351 case 1:
6352 val = "58320";
6353 break;
6354 case 2:
6355 val = "60480";
6356 break;
6357 case 3:
6358 val = "62640";
6359 break;
6360 default:
6361 sigma_dut_print(dut, DUT_MSG_ERROR,
6362 "Failed to configure channel %d. Not supported",
6363 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006364 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006365 }
6366
6367 if (set_network(ifname, net_id, "frequency", val) < 0) {
6368 sigma_dut_print(dut, DUT_MSG_ERROR,
6369 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006370 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006371 }
6372
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006373 if (dut->eap_fragment) {
6374 sigma_dut_print(dut, DUT_MSG_DEBUG,
6375 "Set EAP fragment size to 128 bytes.");
6376 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6377 return ERROR_SEND_STATUS;
6378 }
6379
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006380 sigma_dut_print(dut, DUT_MSG_DEBUG,
6381 "Supplicant set network with frequency");
6382
6383 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6384 if (wpa_command(ifname, buf) < 0) {
6385 sigma_dut_print(dut, DUT_MSG_INFO,
6386 "Failed to select network id %d on %s",
6387 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006388 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006389 }
6390
6391 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6392
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006393 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006394}
6395
6396
Lior David67543f52017-01-03 19:04:22 +02006397static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6398{
6399 char buf[128], fname[128];
6400 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006401 int res;
Lior David67543f52017-01-03 19:04:22 +02006402
6403 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6404 sigma_dut_print(dut, DUT_MSG_ERROR,
6405 "failed to get wil6210 debugfs dir");
6406 return -1;
6407 }
6408
Jouni Malinen3aa72862019-05-29 23:14:51 +03006409 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6410 if (res < 0 || res >= sizeof(fname))
6411 return -1;
Lior David67543f52017-01-03 19:04:22 +02006412 f = fopen(fname, "w");
6413 if (!f) {
6414 sigma_dut_print(dut, DUT_MSG_ERROR,
6415 "failed to open: %s", fname);
6416 return -1;
6417 }
6418
6419 fprintf(f, "%d\n", abft_len);
6420 fclose(f);
6421
6422 return 0;
6423}
6424
6425
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006426int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6427 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006428{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006429 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006430 case DRIVER_WIL6210:
6431 return wil6210_set_abft_len(dut, abft_len);
6432 default:
6433 sigma_dut_print(dut, DUT_MSG_ERROR,
6434 "set abft_len not supported");
6435 return -1;
6436 }
6437}
6438
6439
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006440static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6441 struct sigma_cmd *cmd)
6442{
6443 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006444 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006445
6446 if (dut->dev_role != DEVROLE_PCP) {
6447 send_resp(dut, conn, SIGMA_INVALID,
6448 "ErrorCode,Invalid DevRole");
6449 return 0;
6450 }
6451
6452 val = get_param(cmd, "SSID");
6453 if (val) {
6454 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6455 send_resp(dut, conn, SIGMA_INVALID,
6456 "ErrorCode,Invalid SSID");
6457 return -1;
6458 }
6459
Peng Xub8fc5cc2017-05-10 17:27:28 -07006460 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006461 }
6462
6463 val = get_param(cmd, "CHANNEL");
6464 if (val) {
6465 const char *pos;
6466
6467 dut->ap_channel = atoi(val);
6468 pos = strchr(val, ';');
6469 if (pos) {
6470 pos++;
6471 dut->ap_channel_1 = atoi(pos);
6472 }
6473 }
6474
6475 switch (dut->ap_channel) {
6476 case 1:
6477 case 2:
6478 case 3:
6479 break;
6480 default:
6481 sigma_dut_print(dut, DUT_MSG_ERROR,
6482 "Channel %d is not supported", dut->ap_channel);
6483 send_resp(dut, conn, SIGMA_ERROR,
6484 "Requested channel is not supported");
6485 return -1;
6486 }
6487
6488 val = get_param(cmd, "BCNINT");
6489 if (val)
6490 dut->ap_bcnint = atoi(val);
6491
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006492 val = get_param(cmd, "AllocType");
6493 if (val) {
6494 send_resp(dut, conn, SIGMA_ERROR,
6495 "ErrorCode,AllocType is not supported yet");
6496 return -1;
6497 }
6498
6499 val = get_param(cmd, "PercentBI");
6500 if (val) {
6501 send_resp(dut, conn, SIGMA_ERROR,
6502 "ErrorCode,PercentBI is not supported yet");
6503 return -1;
6504 }
6505
6506 val = get_param(cmd, "CBAPOnly");
6507 if (val) {
6508 send_resp(dut, conn, SIGMA_ERROR,
6509 "ErrorCode,CBAPOnly is not supported yet");
6510 return -1;
6511 }
6512
6513 val = get_param(cmd, "AMPDU");
6514 if (val) {
6515 if (strcasecmp(val, "Enable") == 0)
6516 dut->ap_ampdu = 1;
6517 else if (strcasecmp(val, "Disable") == 0)
6518 dut->ap_ampdu = 2;
6519 else {
6520 send_resp(dut, conn, SIGMA_ERROR,
6521 "ErrorCode,AMPDU value is not Enable nor Disabled");
6522 return -1;
6523 }
6524 }
6525
6526 val = get_param(cmd, "AMSDU");
6527 if (val) {
6528 if (strcasecmp(val, "Enable") == 0)
6529 dut->ap_amsdu = 1;
6530 else if (strcasecmp(val, "Disable") == 0)
6531 dut->ap_amsdu = 2;
6532 }
6533
6534 val = get_param(cmd, "NumMSDU");
6535 if (val) {
6536 send_resp(dut, conn, SIGMA_ERROR,
6537 "ErrorCode, NumMSDU is not supported yet");
6538 return -1;
6539 }
6540
6541 val = get_param(cmd, "ABFTLRang");
6542 if (val) {
6543 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006544 "ABFTLRang parameter %s", val);
6545 if (strcmp(val, "Gt1") == 0)
6546 abft_len = 2; /* 2 slots in this case */
6547 }
6548
6549 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6550 send_resp(dut, conn, SIGMA_ERROR,
6551 "ErrorCode, Can't set ABFT length");
6552 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006553 }
6554
6555 if (sta_pcp_start(dut, conn, cmd) < 0) {
6556 send_resp(dut, conn, SIGMA_ERROR,
6557 "ErrorCode, Can't start PCP role");
6558 return -1;
6559 }
6560
6561 return sta_set_60g_common(dut, conn, cmd);
6562}
6563
6564
6565static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6566 struct sigma_cmd *cmd)
6567{
6568 const char *val = get_param(cmd, "DiscoveryMode");
6569
6570 if (dut->dev_role != DEVROLE_STA) {
6571 send_resp(dut, conn, SIGMA_INVALID,
6572 "ErrorCode,Invalid DevRole");
6573 return 0;
6574 }
6575
6576 if (val) {
6577 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6578 /* Ignore Discovery mode till Driver expose API. */
6579#if 0
6580 if (strcasecmp(val, "1") == 0) {
6581 send_resp(dut, conn, SIGMA_INVALID,
6582 "ErrorCode,DiscoveryMode 1 not supported");
6583 return 0;
6584 }
6585
6586 if (strcasecmp(val, "0") == 0) {
6587 /* OK */
6588 } else {
6589 send_resp(dut, conn, SIGMA_INVALID,
6590 "ErrorCode,DiscoveryMode not supported");
6591 return 0;
6592 }
6593#endif
6594 }
6595
6596 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006597 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006598 return sta_set_60g_common(dut, conn, cmd);
6599}
6600
6601
Jouni Malinenf7222712019-06-13 01:50:21 +03006602static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6603 struct sigma_conn *conn,
6604 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006605{
6606 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006607 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306608
Jouni Malinened77e672018-01-10 16:45:13 +02006609 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006610 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006611 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306612 wpa_command(intf, "DISCONNECT");
6613 return 1;
6614 }
6615
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006616 disconnect_station(dut);
6617 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6618 * due to cached results. */
6619 wpa_command(intf, "SET ignore_old_scan_res 1");
6620 wpa_command(intf, "BSS_FLUSH");
6621 return 1;
6622}
6623
6624
Jouni Malinenf7222712019-06-13 01:50:21 +03006625static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6626 struct sigma_conn *conn,
6627 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006628{
6629 const char *intf = get_param(cmd, "Interface");
6630 const char *bssid = get_param(cmd, "bssid");
6631 const char *val = get_param(cmd, "CHANNEL");
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006632 const char *freq_val = get_param(cmd, "ChnlFreq");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006633 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306634 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306635 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006636 int res;
6637 int chan = 0;
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006638 int freq = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006639 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306640 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006641 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006642
6643 if (bssid == NULL) {
6644 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6645 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006646 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006647 }
6648
6649 if (val)
6650 chan = atoi(val);
6651
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006652 if (freq_val)
6653 freq = atoi(freq_val);
6654
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006655 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6656 /* The current network may be from sta_associate or
6657 * sta_hs2_associate
6658 */
6659 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6660 0 ||
6661 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006662 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006663 }
6664
6665 ctrl = open_wpa_mon(intf);
6666 if (ctrl == NULL) {
6667 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6668 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006669 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006670 }
6671
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006672 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05306673 sizeof(result)) < 0 ||
6674 strncmp(result, "COMPLETED", 9) != 0) {
6675 sigma_dut_print(dut, DUT_MSG_DEBUG,
6676 "sta_reassoc: Not connected");
6677 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006678 } else if (dut->sta_ft_ds) {
6679 sigma_dut_print(dut, DUT_MSG_DEBUG,
6680 "sta_reassoc: Use FT-over-DS");
6681 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306682 }
6683
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306684 if (dut->rsne_override) {
6685#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006686 if (get_driver_type(dut) == DRIVER_WCN &&
6687 dut->config_rsnie == 0) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05306688 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306689 dut->config_rsnie = 1;
6690 }
6691#endif /* NL80211_SUPPORT */
6692 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6693 dut->rsne_override);
6694 if (wpa_command(intf, buf) < 0) {
6695 send_resp(dut, conn, SIGMA_ERROR,
6696 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6697 return 0;
6698 }
6699 }
6700
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006701 if (ft_ds) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006702 if (chan || freq) {
6703 if (!freq)
6704 freq = channel_to_freq(dut, chan);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006705 if (!freq) {
6706 sigma_dut_print(dut, DUT_MSG_ERROR,
6707 "Invalid channel number provided: %d",
6708 chan);
6709 send_resp(dut, conn, SIGMA_INVALID,
6710 "ErrorCode,Invalid channel number");
6711 goto close_mon_conn;
6712 }
6713 res = snprintf(buf, sizeof(buf),
6714 "SCAN TYPE=ONLY freq=%d", freq);
6715 } else {
6716 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6717 }
6718 if (res < 0 || res >= (int) sizeof(buf)) {
6719 send_resp(dut, conn, SIGMA_ERROR,
6720 "ErrorCode,snprintf failed");
6721 goto close_mon_conn;
6722 }
6723 if (wpa_command(intf, buf) < 0) {
6724 sigma_dut_print(dut, DUT_MSG_INFO,
6725 "Failed to start scan");
6726 send_resp(dut, conn, SIGMA_ERROR,
6727 "ErrorCode,scan failed");
6728 goto close_mon_conn;
6729 }
6730
6731 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6732 buf, sizeof(buf));
6733 if (res < 0) {
6734 sigma_dut_print(dut, DUT_MSG_INFO,
6735 "Scan did not complete");
6736 send_resp(dut, conn, SIGMA_ERROR,
6737 "ErrorCode,scan did not complete");
6738 goto close_mon_conn;
6739 }
6740
6741 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6742 if (res > 0 && res < (int) sizeof(buf))
6743 res = wpa_command(intf, buf);
6744
6745 if (res < 0 || res >= (int) sizeof(buf)) {
6746 send_resp(dut, conn, SIGMA_ERROR,
6747 "errorCode,FT_DS command failed");
6748 status = STATUS_SENT_ERROR;
6749 goto close_mon_conn;
6750 }
6751 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006752 if (chan || freq) {
6753 if (!freq)
6754 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306755 if (!freq) {
6756 sigma_dut_print(dut, DUT_MSG_ERROR,
6757 "Invalid channel number provided: %d",
6758 chan);
6759 send_resp(dut, conn, SIGMA_INVALID,
6760 "ErrorCode,Invalid channel number");
6761 goto close_mon_conn;
6762 }
6763 res = snprintf(buf, sizeof(buf),
6764 "SCAN TYPE=ONLY freq=%d", freq);
6765 } else {
6766 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6767 }
6768 if (res < 0 || res >= (int) sizeof(buf)) {
6769 send_resp(dut, conn, SIGMA_ERROR,
6770 "ErrorCode,snprintf failed");
6771 goto close_mon_conn;
6772 }
6773 if (wpa_command(intf, buf) < 0) {
6774 sigma_dut_print(dut, DUT_MSG_INFO,
6775 "Failed to start scan");
6776 send_resp(dut, conn, SIGMA_ERROR,
6777 "ErrorCode,scan failed");
6778 goto close_mon_conn;
6779 }
6780
6781 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6782 buf, sizeof(buf));
6783 if (res < 0) {
6784 sigma_dut_print(dut, DUT_MSG_INFO,
6785 "Scan did not complete");
6786 send_resp(dut, conn, SIGMA_ERROR,
6787 "ErrorCode,scan did not complete");
6788 goto close_mon_conn;
6789 }
6790
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006791 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6792 < 0) {
6793 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6794 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006795 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306796 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006797 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306798 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006799 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306800 if (res < 0 || res >= (int) sizeof(buf) ||
6801 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006802 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306803 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306804 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006805 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006806 sigma_dut_print(dut, DUT_MSG_INFO,
6807 "sta_reassoc: Run %s successful", buf);
6808 } else if (wpa_command(intf, "REASSOCIATE")) {
6809 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6810 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306811 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006812 }
6813
6814 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6815 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306816 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006817 send_resp(dut, conn, SIGMA_ERROR,
6818 "errorCode,Connection did not complete");
6819 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306820 goto close_mon_conn;
6821 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006822 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006823
Ashwini Patil467efef2017-05-25 12:18:27 +05306824close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006825 wpa_ctrl_detach(ctrl);
6826 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306827 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006828}
6829
6830
6831static void hs2_clear_credentials(const char *intf)
6832{
6833 wpa_command(intf, "REMOVE_CRED all");
6834}
6835
6836
Lior Davidcc88b562017-01-03 18:52:09 +02006837#ifdef __linux__
6838static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6839 unsigned int *aid)
6840{
Lior David0fe101e2017-03-09 16:09:50 +02006841 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006842
Lior David0fe101e2017-03-09 16:09:50 +02006843 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006844}
6845#endif /* __linux__ */
6846
6847
6848static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6849 unsigned int *aid)
6850{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006851 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02006852#ifdef __linux__
6853 case DRIVER_WIL6210:
6854 return wil6210_get_aid(dut, bssid, aid);
6855#endif /* __linux__ */
6856 default:
6857 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6858 return -1;
6859 }
6860}
6861
6862
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006863static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6864 struct sigma_cmd *cmd)
6865{
6866 char buf[MAX_CMD_LEN];
6867 char bss_list[MAX_CMD_LEN];
6868 const char *parameter = get_param(cmd, "Parameter");
6869
6870 if (parameter == NULL)
6871 return -1;
6872
Lior Davidcc88b562017-01-03 18:52:09 +02006873 if (strcasecmp(parameter, "AID") == 0) {
6874 unsigned int aid = 0;
6875 char bssid[20];
6876
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006877 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02006878 bssid, sizeof(bssid)) < 0) {
6879 sigma_dut_print(dut, DUT_MSG_ERROR,
6880 "could not get bssid");
6881 return -2;
6882 }
6883
6884 if (sta_get_aid_60g(dut, bssid, &aid))
6885 return -2;
6886
6887 snprintf(buf, sizeof(buf), "aid,%d", aid);
6888 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6889 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6890 return 0;
6891 }
6892
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006893 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6894 char *bss_line;
6895 char *bss_id = NULL;
6896 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306897 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006898
6899 if (ifname == NULL) {
6900 sigma_dut_print(dut, DUT_MSG_INFO,
6901 "For get DiscoveredDevList need Interface name.");
6902 return -1;
6903 }
6904
6905 /*
6906 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6907 * of BSSIDs in "bssid=<BSSID>\n"
6908 */
6909 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6910 bss_list,
6911 sizeof(bss_list)) < 0) {
6912 sigma_dut_print(dut, DUT_MSG_ERROR,
6913 "Failed to get bss list");
6914 return -1;
6915 }
6916
6917 sigma_dut_print(dut, DUT_MSG_DEBUG,
6918 "bss list for ifname:%s is:%s",
6919 ifname, bss_list);
6920
6921 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306922 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006923 while (bss_line) {
6924 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6925 bss_id) {
6926 int len;
6927
6928 len = snprintf(buf + strlen(buf),
6929 sizeof(buf) - strlen(buf),
6930 ",%s", bss_id);
6931 free(bss_id);
6932 bss_id = NULL;
6933 if (len < 0) {
6934 sigma_dut_print(dut,
6935 DUT_MSG_ERROR,
6936 "Failed to read BSSID");
6937 send_resp(dut, conn, SIGMA_ERROR,
6938 "ErrorCode,Failed to read BSS ID");
6939 return 0;
6940 }
6941
6942 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6943 sigma_dut_print(dut,
6944 DUT_MSG_ERROR,
6945 "Response buf too small for list");
6946 send_resp(dut, conn,
6947 SIGMA_ERROR,
6948 "ErrorCode,Response buf too small for list");
6949 return 0;
6950 }
6951 }
6952
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306953 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006954 }
6955
6956 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6957 buf);
6958 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6959 return 0;
6960 }
6961
6962 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6963 return 0;
6964}
6965
6966
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006967static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6968 struct sigma_cmd *cmd)
6969{
6970 char buf[MAX_CMD_LEN];
6971 const char *parameter = get_param(cmd, "Parameter");
6972
6973 if (!parameter)
6974 return -1;
6975
6976 if (strcasecmp(parameter, "RSSI") == 0) {
6977 char rssi[10];
6978
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006979 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006980 rssi, sizeof(rssi)) < 0) {
6981 sigma_dut_print(dut, DUT_MSG_ERROR,
6982 "Could not get RSSI");
6983 return -2;
6984 }
6985
6986 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6987 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6988 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6989 return 0;
6990 }
6991
6992 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6993 return 0;
6994}
6995
6996
Jouni Malinenca0abd32020-02-09 20:18:10 +02006997static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
6998 struct sigma_conn *conn,
6999 struct sigma_cmd *cmd)
7000{
7001 const char *intf = get_param(cmd, "Interface");
7002 char buf[4096], bssid[20], resp[200], *pos, *tmp;
7003
7004 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
7005 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
7006 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
7007 send_resp(dut, conn, SIGMA_ERROR,
7008 "ErrorCode,PMKSA_GET not supported");
7009 return STATUS_SENT_ERROR;
7010 }
7011
7012 if (strncmp(buf, "FAIL", 4) == 0 ||
7013 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
7014 send_resp(dut, conn, SIGMA_ERROR,
7015 "ErrorCode,Could not find current network");
7016 return STATUS_SENT_ERROR;
7017 }
7018
7019 pos = buf;
7020 while (pos) {
7021 if (strncmp(pos, bssid, 17) == 0) {
7022 pos = strchr(pos, ' ');
7023 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307024 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007025 pos++;
7026 pos = strchr(pos, ' ');
7027 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307028 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007029 pos++;
7030 tmp = strchr(pos, ' ');
7031 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307032 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007033 *tmp = '\0';
7034 break;
7035 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02007036 pos = strchr(pos, '\n');
7037 if (pos)
7038 pos++;
7039 }
7040
7041 if (!pos) {
7042 send_resp(dut, conn, SIGMA_ERROR,
7043 "ErrorCode,PMK not available");
7044 return STATUS_SENT_ERROR;
7045 }
7046
7047 snprintf(resp, sizeof(resp), "PMK,%s", pos);
7048 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7049 return STATUS_SENT;
7050}
7051
7052
Jouni Malinenf7222712019-06-13 01:50:21 +03007053static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
7054 struct sigma_conn *conn,
7055 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007056{
7057 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02007058 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007059
Jouni Malinenca0abd32020-02-09 20:18:10 +02007060 if (!parameter)
7061 return INVALID_SEND_STATUS;
7062
7063 if (strcasecmp(parameter, "PMK") == 0)
7064 return sta_get_pmk(dut, conn, cmd);
7065
7066 if (!program)
7067 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007068
7069 if (strcasecmp(program, "P2PNFC") == 0)
7070 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
7071
7072 if (strcasecmp(program, "60ghz") == 0)
7073 return sta_get_parameter_60g(dut, conn, cmd);
7074
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007075 if (strcasecmp(program, "he") == 0)
7076 return sta_get_parameter_he(dut, conn, cmd);
7077
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007078#ifdef ANDROID_NAN
7079 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07007080 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007081#endif /* ANDROID_NAN */
7082
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007083#ifdef MIRACAST
7084 if (strcasecmp(program, "WFD") == 0 ||
7085 strcasecmp(program, "DisplayR2") == 0)
7086 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
7087#endif /* MIRACAST */
7088
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007089 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7090 return 0;
7091}
7092
7093
7094static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
7095 const char *type)
7096{
7097 char buf[100];
7098
7099 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007100 run_iwpriv(dut, intf, "chwidth 2");
7101 run_iwpriv(dut, intf, "mode 11ACVHT80");
7102 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007103 }
7104
7105 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007106 run_iwpriv(dut, intf, "chwidth 0");
7107 run_iwpriv(dut, intf, "mode 11naht40");
7108 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007109 }
7110
7111 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007112 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007113
7114 /* Reset CTS width */
7115 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
7116 intf);
7117 if (system(buf) != 0) {
7118 sigma_dut_print(dut, DUT_MSG_ERROR,
7119 "wifitool %s beeliner_fw_test 54 0 failed",
7120 intf);
7121 }
7122
7123 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007124 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007125
7126 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
7127 if (system(buf) != 0) {
7128 sigma_dut_print(dut, DUT_MSG_ERROR,
7129 "iwpriv rts failed");
7130 }
7131 }
7132
7133 if (type && strcasecmp(type, "Testbed") == 0) {
7134 dut->testbed_flag_txsp = 1;
7135 dut->testbed_flag_rxsp = 1;
7136 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007137 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007138
7139 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007140 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007141
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007142 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007143
7144 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007145 run_iwpriv(dut, intf, "tx_stbc 0");
7146 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007147
7148 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007149 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007150 }
7151
7152 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007153 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07007154 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007155
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007156 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007157 }
7158}
7159
7160
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007161#ifdef NL80211_SUPPORT
7162static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
7163 enum he_mcs_config mcs)
7164{
7165 struct nl_msg *msg;
7166 int ret = 0;
7167 struct nlattr *params;
7168 int ifindex;
7169
7170 ifindex = if_nametoindex(intf);
7171 if (ifindex == 0) {
7172 sigma_dut_print(dut, DUT_MSG_ERROR,
7173 "%s: Index for interface %s failed",
7174 __func__, intf);
7175 return -1;
7176 }
7177
7178 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7179 NL80211_CMD_VENDOR)) ||
7180 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7181 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7182 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7183 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7184 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7185 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
7186 mcs)) {
7187 sigma_dut_print(dut, DUT_MSG_ERROR,
7188 "%s: err in adding vendor_cmd and vendor_data",
7189 __func__);
7190 nlmsg_free(msg);
7191 return -1;
7192 }
7193 nla_nest_end(msg, params);
7194
7195 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7196 if (ret) {
7197 sigma_dut_print(dut, DUT_MSG_ERROR,
7198 "%s: err in send_and_recv_msgs, ret=%d",
7199 __func__, ret);
7200 }
7201 return ret;
7202}
7203#endif /* NL80211_SUPPORT */
7204
7205
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007206static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
7207 const char *intf, int enable)
7208{
7209#ifdef NL80211_SUPPORT
7210 struct nl_msg *msg;
7211 int ret = 0;
7212 struct nlattr *params;
7213 int ifindex;
7214
7215 ifindex = if_nametoindex(intf);
7216 if (ifindex == 0) {
7217 sigma_dut_print(dut, DUT_MSG_ERROR,
7218 "%s: Index for interface %s failed",
7219 __func__, intf);
7220 return -1;
7221 }
7222
7223 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7224 NL80211_CMD_VENDOR)) ||
7225 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7226 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7227 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7228 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7229 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7230 nla_put_u8(msg,
7231 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
7232 enable)) {
7233 sigma_dut_print(dut, DUT_MSG_ERROR,
7234 "%s: err in adding vendor_cmd and vendor_data",
7235 __func__);
7236 nlmsg_free(msg);
7237 return -1;
7238 }
7239 nla_nest_end(msg, params);
7240
7241 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7242 if (ret) {
7243 sigma_dut_print(dut, DUT_MSG_ERROR,
7244 "%s: err in send_and_recv_msgs, ret=%d",
7245 __func__, ret);
7246 }
7247 return ret;
7248#else /* NL80211_SUPPORT */
7249 sigma_dut_print(dut, DUT_MSG_ERROR,
7250 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
7251 return -1;
7252#endif /* NL80211_SUPPORT */
7253}
7254
7255
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007256static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
7257 const char *intf, int enable)
7258{
7259#ifdef NL80211_SUPPORT
7260 struct nl_msg *msg;
7261 int ret = 0;
7262 struct nlattr *params;
7263 int ifindex;
7264
7265 ifindex = if_nametoindex(intf);
7266 if (ifindex == 0) {
7267 sigma_dut_print(dut, DUT_MSG_ERROR,
7268 "%s: Index for interface %s failed",
7269 __func__, intf);
7270 return -1;
7271 }
7272
7273 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7274 NL80211_CMD_VENDOR)) ||
7275 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7276 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7277 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7278 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7279 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7280 nla_put_u8(msg,
7281 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7282 enable)) {
7283 sigma_dut_print(dut, DUT_MSG_ERROR,
7284 "%s: err in adding vendor_cmd and vendor_data",
7285 __func__);
7286 nlmsg_free(msg);
7287 return -1;
7288 }
7289 nla_nest_end(msg, params);
7290
7291 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7292 if (ret) {
7293 sigma_dut_print(dut, DUT_MSG_ERROR,
7294 "%s: err in send_and_recv_msgs, ret=%d",
7295 __func__, ret);
7296 }
7297 return ret;
7298#else /* NL80211_SUPPORT */
7299 sigma_dut_print(dut, DUT_MSG_ERROR,
7300 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7301 return -1;
7302#endif /* NL80211_SUPPORT */
7303}
7304
7305
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007306#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007307
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007308static int sta_set_he_testbed_def(struct sigma_dut *dut,
7309 const char *intf, int cfg)
7310{
7311 struct nl_msg *msg;
7312 int ret = 0;
7313 struct nlattr *params;
7314 int ifindex;
7315
7316 ifindex = if_nametoindex(intf);
7317 if (ifindex == 0) {
7318 sigma_dut_print(dut, DUT_MSG_ERROR,
7319 "%s: Index for interface %s failed",
7320 __func__, intf);
7321 return -1;
7322 }
7323
7324 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7325 NL80211_CMD_VENDOR)) ||
7326 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7327 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7328 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7329 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7330 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7331 nla_put_u8(msg,
7332 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7333 cfg)) {
7334 sigma_dut_print(dut, DUT_MSG_ERROR,
7335 "%s: err in adding vendor_cmd and vendor_data",
7336 __func__);
7337 nlmsg_free(msg);
7338 return -1;
7339 }
7340 nla_nest_end(msg, params);
7341
7342 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7343 if (ret) {
7344 sigma_dut_print(dut, DUT_MSG_ERROR,
7345 "%s: err in send_and_recv_msgs, ret=%d",
7346 __func__, ret);
7347 }
7348 return ret;
7349}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007350
7351
7352static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7353{
7354 struct nl_msg *msg;
7355 int ret = 0;
7356 struct nlattr *params;
7357 int ifindex;
7358
7359 ifindex = if_nametoindex(intf);
7360 if (ifindex == 0) {
7361 sigma_dut_print(dut, DUT_MSG_ERROR,
7362 "%s: Index for interface %s failed",
7363 __func__, intf);
7364 return -1;
7365 }
7366
7367 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7368 NL80211_CMD_VENDOR)) ||
7369 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7370 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7371 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7372 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7373 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7374 nla_put_u8(msg,
7375 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7376 cfg)) {
7377 sigma_dut_print(dut, DUT_MSG_ERROR,
7378 "%s: err in adding vendor_cmd and vendor_data",
7379 __func__);
7380 nlmsg_free(msg);
7381 return -1;
7382 }
7383 nla_nest_end(msg, params);
7384
7385 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7386 if (ret) {
7387 sigma_dut_print(dut, DUT_MSG_ERROR,
7388 "%s: err in send_and_recv_msgs, ret=%d",
7389 __func__, ret);
7390 }
7391 return ret;
7392}
7393
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007394#endif /* NL80211_SUPPORT */
7395
7396
Qiwei Caib6806972020-01-15 13:52:11 +08007397int sta_set_addba_buf_size(struct sigma_dut *dut,
7398 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007399{
7400#ifdef NL80211_SUPPORT
7401 struct nl_msg *msg;
7402 int ret = 0;
7403 struct nlattr *params;
7404 int ifindex;
7405
7406 ifindex = if_nametoindex(intf);
7407 if (ifindex == 0) {
7408 sigma_dut_print(dut, DUT_MSG_ERROR,
7409 "%s: Index for interface %s failed",
7410 __func__, intf);
7411 return -1;
7412 }
7413
7414 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7415 NL80211_CMD_VENDOR)) ||
7416 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7417 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7418 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7419 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7420 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07007421 nla_put_u16(msg,
7422 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
7423 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007424 sigma_dut_print(dut, DUT_MSG_ERROR,
7425 "%s: err in adding vendor_cmd and vendor_data",
7426 __func__);
7427 nlmsg_free(msg);
7428 return -1;
7429 }
7430 nla_nest_end(msg, params);
7431
7432 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7433 if (ret) {
7434 sigma_dut_print(dut, DUT_MSG_ERROR,
7435 "%s: err in send_and_recv_msgs, ret=%d",
7436 __func__, ret);
7437 }
7438 return ret;
7439#else /* NL80211_SUPPORT */
7440 sigma_dut_print(dut, DUT_MSG_ERROR,
7441 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7442 return -1;
7443#endif /* NL80211_SUPPORT */
7444}
7445
7446
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007447static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
7448 int enable)
7449{
7450#ifdef NL80211_SUPPORT
7451 struct nl_msg *msg;
7452 int ret = 0;
7453 struct nlattr *params;
7454 int ifindex;
7455
7456 ifindex = if_nametoindex(intf);
7457 if (ifindex == 0) {
7458 sigma_dut_print(dut, DUT_MSG_ERROR,
7459 "%s: Index for interface %s failed",
7460 __func__, intf);
7461 return -1;
7462 }
7463
7464 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7465 NL80211_CMD_VENDOR)) ||
7466 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7467 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7468 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7469 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7470 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7471 nla_put_u8(msg,
7472 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7473 enable)) {
7474 sigma_dut_print(dut, DUT_MSG_ERROR,
7475 "%s: err in adding vendor_cmd and vendor_data",
7476 __func__);
7477 nlmsg_free(msg);
7478 return -1;
7479 }
7480 nla_nest_end(msg, params);
7481
7482 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7483 if (ret) {
7484 sigma_dut_print(dut, DUT_MSG_ERROR,
7485 "%s: err in send_and_recv_msgs, ret=%d",
7486 __func__, ret);
7487 }
7488 return ret;
7489#else /* NL80211_SUPPORT */
7490 sigma_dut_print(dut, DUT_MSG_ERROR,
7491 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7492 return -1;
7493#endif /* NL80211_SUPPORT */
7494}
7495
7496
Arif Hussain9765f7d2018-07-03 08:28:26 -07007497static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7498 int val)
7499{
7500#ifdef NL80211_SUPPORT
7501 struct nl_msg *msg;
7502 int ret = 0;
7503 struct nlattr *params;
7504 int ifindex;
7505
7506 ifindex = if_nametoindex(intf);
7507 if (ifindex == 0) {
7508 sigma_dut_print(dut, DUT_MSG_ERROR,
7509 "%s: Index for interface %s failed, val:%d",
7510 __func__, intf, val);
7511 return -1;
7512 }
7513
7514 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7515 NL80211_CMD_VENDOR)) ||
7516 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7517 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7518 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7519 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7520 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7521 nla_put_u8(msg,
7522 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7523 val)) {
7524 sigma_dut_print(dut, DUT_MSG_ERROR,
7525 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7526 __func__, val);
7527 nlmsg_free(msg);
7528 return -1;
7529 }
7530 nla_nest_end(msg, params);
7531
7532 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7533 if (ret) {
7534 sigma_dut_print(dut, DUT_MSG_ERROR,
7535 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7536 __func__, ret, val);
7537 }
7538 return ret;
7539#else /* NL80211_SUPPORT */
7540 sigma_dut_print(dut, DUT_MSG_ERROR,
7541 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7542 return -1;
7543#endif /* NL80211_SUPPORT */
7544}
7545
7546
Arif Hussain68d23f52018-07-11 13:39:08 -07007547#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007548static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7549 enum qca_wlan_he_mac_padding_dur val)
7550{
Arif Hussain68d23f52018-07-11 13:39:08 -07007551 struct nl_msg *msg;
7552 int ret = 0;
7553 struct nlattr *params;
7554 int ifindex;
7555
7556 ifindex = if_nametoindex(intf);
7557 if (ifindex == 0) {
7558 sigma_dut_print(dut, DUT_MSG_ERROR,
7559 "%s: Index for interface %s failed, val:%d",
7560 __func__, intf, val);
7561 return -1;
7562 }
7563
7564 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7565 NL80211_CMD_VENDOR)) ||
7566 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7567 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7568 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7569 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7570 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7571 nla_put_u8(msg,
7572 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
7573 val)) {
7574 sigma_dut_print(dut, DUT_MSG_ERROR,
7575 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7576 __func__, val);
7577 nlmsg_free(msg);
7578 return -1;
7579 }
7580 nla_nest_end(msg, params);
7581
7582 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7583 if (ret) {
7584 sigma_dut_print(dut, DUT_MSG_ERROR,
7585 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7586 __func__, ret, val);
7587 }
7588 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07007589}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007590#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007591
7592
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007593static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7594 int val)
7595{
7596#ifdef NL80211_SUPPORT
7597 struct nl_msg *msg;
7598 int ret = 0;
7599 struct nlattr *params;
7600 int ifindex;
7601
7602 ifindex = if_nametoindex(intf);
7603 if (ifindex == 0) {
7604 sigma_dut_print(dut, DUT_MSG_ERROR,
7605 "%s: Index for interface %s failed, val:%d",
7606 __func__, intf, val);
7607 return -1;
7608 }
7609
7610 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7611 NL80211_CMD_VENDOR)) ||
7612 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7613 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7614 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7615 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7616 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7617 nla_put_u8(msg,
7618 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7619 val)) {
7620 sigma_dut_print(dut, DUT_MSG_ERROR,
7621 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7622 __func__, val);
7623 nlmsg_free(msg);
7624 return -1;
7625 }
7626 nla_nest_end(msg, params);
7627
7628 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7629 if (ret) {
7630 sigma_dut_print(dut, DUT_MSG_ERROR,
7631 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7632 __func__, ret, val);
7633 }
7634 return ret;
7635#else /* NL80211_SUPPORT */
7636 sigma_dut_print(dut, DUT_MSG_ERROR,
7637 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7638 return -1;
7639#endif /* NL80211_SUPPORT */
7640}
7641
7642
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007643#ifdef NL80211_SUPPORT
7644static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7645{
7646 struct nl_msg *msg;
7647 int ret = 0;
7648 struct nlattr *params;
7649 int ifindex;
7650
7651 ifindex = if_nametoindex(intf);
7652 if (ifindex == 0) {
7653 sigma_dut_print(dut, DUT_MSG_ERROR,
7654 "%s: Index for interface %s failed",
7655 __func__, intf);
7656 return -1;
7657 }
7658
7659 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7660 NL80211_CMD_VENDOR)) ||
7661 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7662 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7663 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7664 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7665 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7666 nla_put_flag(msg,
7667 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
7668 sigma_dut_print(dut, DUT_MSG_ERROR,
7669 "%s: err in adding vendor_cmd and vendor_data",
7670 __func__);
7671 nlmsg_free(msg);
7672 return -1;
7673 }
7674 nla_nest_end(msg, params);
7675
7676 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7677 if (ret) {
7678 sigma_dut_print(dut, DUT_MSG_ERROR,
7679 "%s: err in send_and_recv_msgs, ret=%d",
7680 __func__, ret);
7681 }
7682 return ret;
7683}
7684#endif /* NL80211_SUPPORT */
7685
7686
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007687static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7688 int val)
7689{
7690#ifdef NL80211_SUPPORT
7691 struct nl_msg *msg;
7692 int ret = 0;
7693 struct nlattr *params;
7694 int ifindex;
7695
7696 ifindex = if_nametoindex(intf);
7697 if (ifindex == 0) {
7698 sigma_dut_print(dut, DUT_MSG_ERROR,
7699 "%s: Index for interface %s failed, val:%d",
7700 __func__, intf, val);
7701 return -1;
7702 }
7703
7704 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7705 NL80211_CMD_VENDOR)) ||
7706 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7707 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7708 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7709 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7710 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7711 nla_put_u8(msg,
7712 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
7713 val)) {
7714 sigma_dut_print(dut, DUT_MSG_ERROR,
7715 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7716 __func__, val);
7717 nlmsg_free(msg);
7718 return -1;
7719 }
7720 nla_nest_end(msg, params);
7721
7722 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7723 if (ret) {
7724 sigma_dut_print(dut, DUT_MSG_ERROR,
7725 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7726 __func__, ret, val);
7727 }
7728 return ret;
7729#else /* NL80211_SUPPORT */
7730 sigma_dut_print(dut, DUT_MSG_ERROR,
7731 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7732 return -1;
7733#endif /* NL80211_SUPPORT */
7734}
7735
7736
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007737static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7738 int val)
7739{
7740#ifdef NL80211_SUPPORT
7741 struct nl_msg *msg;
7742 int ret = 0;
7743 struct nlattr *params;
7744 int ifindex;
7745
7746 ifindex = if_nametoindex(intf);
7747 if (ifindex == 0) {
7748 sigma_dut_print(dut, DUT_MSG_ERROR,
7749 "%s: Index for interface %s failed, val:%d",
7750 __func__, intf, val);
7751 return -1;
7752 }
7753
7754 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7755 NL80211_CMD_VENDOR)) ||
7756 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7757 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7758 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7759 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7760 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7761 nla_put_u8(msg,
7762 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
7763 val)) {
7764 sigma_dut_print(dut, DUT_MSG_ERROR,
7765 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7766 __func__, val);
7767 nlmsg_free(msg);
7768 return -1;
7769 }
7770 nla_nest_end(msg, params);
7771
7772 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7773 if (ret) {
7774 sigma_dut_print(dut, DUT_MSG_ERROR,
7775 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7776 __func__, ret, val);
7777 }
7778 return ret;
7779#else /* NL80211_SUPPORT */
7780 sigma_dut_print(dut, DUT_MSG_ERROR,
7781 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7782 return -1;
7783#endif /* NL80211_SUPPORT */
7784}
7785
7786
Arif Hussain480d5f42019-03-12 14:40:42 -07007787static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7788 int val)
7789{
7790#ifdef NL80211_SUPPORT
7791 struct nl_msg *msg;
7792 int ret;
7793 struct nlattr *params;
7794 int ifindex;
7795
7796 ifindex = if_nametoindex(intf);
7797 if (ifindex == 0) {
7798 sigma_dut_print(dut, DUT_MSG_ERROR,
7799 "%s: Index for interface %s failed, val:%d",
7800 __func__, intf, val);
7801 return -1;
7802 }
7803
7804 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7805 NL80211_CMD_VENDOR)) ||
7806 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7807 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7808 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7809 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7810 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7811 nla_put_u8(msg,
7812 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT,
7813 val)) {
7814 sigma_dut_print(dut, DUT_MSG_ERROR,
7815 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7816 __func__, val);
7817 nlmsg_free(msg);
7818 return -1;
7819 }
7820 nla_nest_end(msg, params);
7821
7822 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7823 if (ret) {
7824 sigma_dut_print(dut, DUT_MSG_ERROR,
7825 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7826 __func__, ret, val);
7827 }
7828 return ret;
7829#else /* NL80211_SUPPORT */
7830 sigma_dut_print(dut, DUT_MSG_ERROR,
7831 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7832 return -1;
7833#endif /* NL80211_SUPPORT */
7834}
7835
7836
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007837static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7838 const char *type)
7839{
7840 char buf[60];
7841
7842 if (dut->program == PROGRAM_HE) {
7843 /* resetting phymode to auto in case of HE program */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05307844 sta_set_phymode(dut, intf, "auto");
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007845
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007846 /* reset the rate to Auto rate */
7847 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7848 intf);
7849 if (system(buf) != 0) {
7850 sigma_dut_print(dut, DUT_MSG_ERROR,
7851 "iwpriv %s set_11ax_rate 0xff failed",
7852 intf);
7853 }
7854
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007855 /* reset the LDPC setting */
7856 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7857 if (system(buf) != 0) {
7858 sigma_dut_print(dut, DUT_MSG_ERROR,
7859 "iwpriv %s ldpc 1 failed", intf);
7860 }
7861
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007862 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05307863 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007864
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007865 /* remove all network profiles */
7866 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007867
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007868 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7869 sta_set_addba_buf_size(dut, intf, 64);
7870
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007871#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007872 /* Reset the device HE capabilities to its default supported
7873 * configuration. */
7874 sta_set_he_testbed_def(dut, intf, 0);
7875
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007876 /* Disable noackpolicy for all AC */
7877 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7878 sigma_dut_print(dut, DUT_MSG_ERROR,
7879 "Disable of noackpolicy for all AC failed");
7880 }
7881#endif /* NL80211_SUPPORT */
7882
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007883 /* Enable WMM by default */
7884 if (wcn_sta_set_wmm(dut, intf, "on")) {
7885 sigma_dut_print(dut, DUT_MSG_ERROR,
7886 "Enable of WMM in sta_reset_default_wcn failed");
7887 }
7888
7889 /* Disable ADDBA_REJECT by default */
7890 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7891 sigma_dut_print(dut, DUT_MSG_ERROR,
7892 "Disable of addba_reject in sta_reset_default_wcn failed");
7893 }
7894
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007895 /* Enable sending of ADDBA by default */
7896 if (nlvendor_config_send_addba(dut, intf, 1)) {
7897 sigma_dut_print(dut, DUT_MSG_ERROR,
7898 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7899 }
7900
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007901 /* Enable AMPDU by default */
7902 iwpriv_sta_set_ampdu(dut, intf, 1);
7903
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007904#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08007905 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007906 sigma_dut_print(dut, DUT_MSG_ERROR,
7907 "Set LTF config to default in sta_reset_default_wcn failed");
7908 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007909
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007910 /* set the beamformee NSTS(maximum number of
7911 * space-time streams) to default DUT config
7912 */
7913 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007914 sigma_dut_print(dut, DUT_MSG_ERROR,
7915 "Failed to set BeamformeeSTS");
7916 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007917
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007918 if (sta_set_mac_padding_duration(
7919 dut, intf,
7920 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007921 sigma_dut_print(dut, DUT_MSG_ERROR,
7922 "Failed to set MAC padding duration");
7923 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007924
7925 if (sta_set_mu_edca_override(dut, intf, 0)) {
7926 sigma_dut_print(dut, DUT_MSG_ERROR,
7927 "ErrorCode,Failed to set MU EDCA override disable");
7928 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007929
7930 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7931 sigma_dut_print(dut, DUT_MSG_ERROR,
7932 "Failed to set OM ctrl supp");
7933 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007934
7935 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7936 sigma_dut_print(dut, DUT_MSG_ERROR,
7937 "Failed to set Tx SU PPDU enable");
7938 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007939
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007940 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7941 sigma_dut_print(dut, DUT_MSG_ERROR,
7942 "failed to send TB PPDU Tx cfg");
7943 }
7944
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007945 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7946 sigma_dut_print(dut, DUT_MSG_ERROR,
7947 "Failed to set OM ctrl reset");
7948 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007949
7950 /* +HTC-HE support default on */
7951 if (sta_set_he_htc_supp(dut, intf, 1)) {
7952 sigma_dut_print(dut, DUT_MSG_ERROR,
7953 "Setting of +HTC-HE support failed");
7954 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007955#endif /* NL80211_SUPPORT */
7956
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007957 if (sta_set_tx_beamformee(dut, intf, 1)) {
7958 sigma_dut_print(dut, DUT_MSG_ERROR,
7959 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7960 }
7961
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007962 wpa_command(intf, "SET oce 1");
7963
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007964 /* Set nss to 1 and MCS 0-7 in case of testbed */
7965 if (type && strcasecmp(type, "Testbed") == 0) {
7966#ifdef NL80211_SUPPORT
7967 int ret;
7968#endif /* NL80211_SUPPORT */
7969
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007970 wpa_command(intf, "SET oce 0");
7971
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007972 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7973 if (system(buf) != 0) {
7974 sigma_dut_print(dut, DUT_MSG_ERROR,
7975 "iwpriv %s nss failed", intf);
7976 }
7977
7978#ifdef NL80211_SUPPORT
7979 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7980 if (ret) {
7981 sigma_dut_print(dut, DUT_MSG_ERROR,
7982 "Setting of MCS failed, ret:%d",
7983 ret);
7984 }
7985#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007986
7987 /* Disable STBC as default */
7988 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007989
7990 /* Disable AMSDU as default */
7991 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007992
7993#ifdef NL80211_SUPPORT
7994 /* HE fragmentation default off */
7995 if (sta_set_he_fragmentation(dut, intf,
7996 HE_FRAG_DISABLE)) {
7997 sigma_dut_print(dut, DUT_MSG_ERROR,
7998 "Setting of HE fragmentation failed");
7999 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08008000
8001 /* set the beamformee NSTS(maximum number of
8002 * space-time streams) to default testbed config
8003 */
8004 if (sta_set_beamformee_sts(dut, intf, 3)) {
8005 sigma_dut_print(dut, DUT_MSG_ERROR,
8006 "Failed to set BeamformeeSTS");
8007 }
8008
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08008009 /* +HTC-HE support default off */
8010 if (sta_set_he_htc_supp(dut, intf, 0)) {
8011 sigma_dut_print(dut, DUT_MSG_ERROR,
8012 "Setting of +HTC-HE support failed");
8013 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08008014
8015 /* Set device HE capabilities to testbed default
8016 * configuration. */
8017 if (sta_set_he_testbed_def(dut, intf, 1)) {
8018 sigma_dut_print(dut, DUT_MSG_DEBUG,
8019 "Failed to set HE defaults");
8020 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08008021
8022 /* Disable VHT support in 2.4 GHz for testbed */
8023 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08008024#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08008025
8026 /* Enable WEP/TKIP with HE capability in testbed */
8027 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
8028 sigma_dut_print(dut, DUT_MSG_ERROR,
8029 "Enabling HE config with WEP/TKIP failed");
8030 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08008031 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008032
8033 /* Defaults in case of DUT */
8034 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07008035 /* Enable STBC by default */
8036 wcn_sta_set_stbc(dut, intf, "1");
8037
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008038 /* set nss to 2 */
8039 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
8040 if (system(buf) != 0) {
8041 sigma_dut_print(dut, DUT_MSG_ERROR,
8042 "iwpriv %s nss 2 failed", intf);
8043 }
Arif Hussainac6c5112018-05-25 17:34:00 -07008044 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008045
8046#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07008047 /* Set HE_MCS to 0-11 */
8048 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08008049 sigma_dut_print(dut, DUT_MSG_ERROR,
8050 "Setting of MCS failed");
8051 }
8052#endif /* NL80211_SUPPORT */
8053
8054 /* Disable WEP/TKIP with HE capability in DUT */
8055 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
8056 sigma_dut_print(dut, DUT_MSG_ERROR,
8057 "Enabling HE config with WEP/TKIP failed");
8058 }
8059 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008060 }
8061}
8062
8063
Jouni Malinenf7222712019-06-13 01:50:21 +03008064static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
8065 struct sigma_conn *conn,
8066 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008067{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008068 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008069 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008070 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008071 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308072 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008073
Jouni Malinenb21f0542019-11-04 17:53:38 +02008074 if (dut->station_ifname_2g &&
8075 strcmp(dut->station_ifname_2g, intf) == 0)
8076 dut->use_5g = 0;
8077 else if (dut->station_ifname_5g &&
8078 strcmp(dut->station_ifname_5g, intf) == 0)
8079 dut->use_5g = 1;
8080
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008081 if (!program)
8082 program = get_param(cmd, "prog");
8083 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008084 dut->device_type = STA_unknown;
8085 type = get_param(cmd, "type");
8086 if (type && strcasecmp(type, "Testbed") == 0)
8087 dut->device_type = STA_testbed;
8088 if (type && strcasecmp(type, "DUT") == 0)
8089 dut->device_type = STA_dut;
8090
8091 if (dut->program == PROGRAM_TDLS) {
8092 /* Clear TDLS testing mode */
8093 wpa_command(intf, "SET tdls_disabled 0");
8094 wpa_command(intf, "SET tdls_testing 0");
8095 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008096 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05308097 /* Enable the WCN driver in TDLS Explicit trigger mode
8098 */
8099 wpa_command(intf, "SET tdls_external_control 0");
8100 wpa_command(intf, "SET tdls_trigger_control 0");
8101 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008102 }
8103
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07008104#ifdef MIRACAST
8105 if (dut->program == PROGRAM_WFD ||
8106 dut->program == PROGRAM_DISPLAYR2)
8107 miracast_sta_reset_default(dut, conn, cmd);
8108#endif /* MIRACAST */
8109
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008110 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008111 case DRIVER_ATHEROS:
8112 sta_reset_default_ath(dut, intf, type);
8113 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08008114 case DRIVER_WCN:
8115 sta_reset_default_wcn(dut, intf, type);
8116 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008117 default:
8118 break;
8119 }
8120
8121#ifdef ANDROID_NAN
8122 if (dut->program == PROGRAM_NAN)
8123 nan_cmd_sta_reset_default(dut, conn, cmd);
8124#endif /* ANDROID_NAN */
8125
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05308126 if (dut->program == PROGRAM_LOC &&
8127 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
8128 return ERROR_SEND_STATUS;
8129
Jouni Malinenba630452018-06-22 11:49:59 +03008130 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008131 unlink("SP/wi-fi.org/pps.xml");
8132 if (system("rm -r SP/*") != 0) {
8133 }
8134 unlink("next-client-cert.pem");
8135 unlink("next-client-key.pem");
8136 }
8137
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008138 /* For WPS program of the 60 GHz band the band type needs to be saved */
8139 if (dut->program == PROGRAM_WPS) {
8140 if (band && strcasecmp(band, "60GHz") == 0) {
8141 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008142 /* For 60 GHz enable WPS for WPS TCs */
8143 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008144 } else {
8145 dut->band = WPS_BAND_NON_60G;
8146 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008147 } else if (dut->program == PROGRAM_60GHZ) {
8148 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
8149 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008150 }
8151
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02008152 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008153 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008154 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008155
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008156 sigma_dut_print(dut, DUT_MSG_INFO,
8157 "WPS 60 GHz program, wps_disable = %d",
8158 dut->wps_disable);
8159
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008160 if (!dev_role) {
8161 send_resp(dut, conn, SIGMA_ERROR,
8162 "errorCode,Missing DevRole argument");
8163 return 0;
8164 }
8165
8166 if (strcasecmp(dev_role, "STA") == 0)
8167 dut->dev_role = DEVROLE_STA;
8168 else if (strcasecmp(dev_role, "PCP") == 0)
8169 dut->dev_role = DEVROLE_PCP;
8170 else {
8171 send_resp(dut, conn, SIGMA_ERROR,
8172 "errorCode,Unknown DevRole");
8173 return 0;
8174 }
8175
8176 if (dut->device_type == STA_unknown) {
8177 sigma_dut_print(dut, DUT_MSG_ERROR,
8178 "Device type is not STA testbed or DUT");
8179 send_resp(dut, conn, SIGMA_ERROR,
8180 "errorCode,Unknown device type");
8181 return 0;
8182 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008183
8184 sigma_dut_print(dut, DUT_MSG_DEBUG,
8185 "Setting msdu_size to MAX: 7912");
8186 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008187 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008188
8189 if (system(buf) != 0) {
8190 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
8191 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008192 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02008193 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008194
8195 if (sta_set_force_mcs(dut, 0, 1)) {
8196 sigma_dut_print(dut, DUT_MSG_ERROR,
8197 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008198 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008199 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008200 }
8201
8202 wpa_command(intf, "WPS_ER_STOP");
8203 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05308204 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008205 wpa_command(intf, "SET radio_disabled 0");
8206
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02008207 dut->wps_forced_version = 0;
8208
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008209 if (dut->wsc_fragment) {
8210 dut->wsc_fragment = 0;
8211 wpa_command(intf, "SET device_name Test client");
8212 wpa_command(intf, "SET manufacturer ");
8213 wpa_command(intf, "SET model_name ");
8214 wpa_command(intf, "SET model_number ");
8215 wpa_command(intf, "SET serial_number ");
8216 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02008217 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
8218 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
8219 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
8220 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008221
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008222 if (dut->tmp_mac_addr && dut->set_macaddr) {
8223 dut->tmp_mac_addr = 0;
8224 if (system(dut->set_macaddr) != 0) {
8225 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
8226 "temporary MAC address");
8227 }
8228 }
8229
8230 set_ps(intf, dut, 0);
8231
Jouni Malinenba630452018-06-22 11:49:59 +03008232 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
8233 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008234 wpa_command(intf, "SET interworking 1");
8235 wpa_command(intf, "SET hs20 1");
8236 }
8237
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008238 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03008239 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08008240 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008241 wpa_command(intf, "SET pmf 1");
8242 } else {
8243 wpa_command(intf, "SET pmf 0");
8244 }
8245
8246 hs2_clear_credentials(intf);
8247 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
8248 wpa_command(intf, "SET access_network_type 15");
8249
8250 static_ip_file(0, NULL, NULL, NULL);
8251 kill_dhcp_client(dut, intf);
8252 clear_ip_addr(dut, intf);
8253
8254 dut->er_oper_performed = 0;
8255 dut->er_oper_bssid[0] = '\0';
8256
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008257 if (dut->program == PROGRAM_LOC) {
8258 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008259 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07008260 }
8261
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07008262 if (dut->program == PROGRAM_MBO || dut->program == PROGRAM_HE) {
Ashwini Patil00402582017-04-13 12:29:39 +05308263 free(dut->non_pref_ch_list);
8264 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05308265 free(dut->btm_query_cand_list);
8266 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05308267 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05308268 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05308269 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05308270 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05308271 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05308272 }
8273
Jouni Malinen3c367e82017-06-23 17:01:47 +03008274 free(dut->rsne_override);
8275 dut->rsne_override = NULL;
8276
Jouni Malinen68143132017-09-02 02:34:08 +03008277 free(dut->sae_commit_override);
8278 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03008279 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02008280 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03008281
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008282 dut->sta_associate_wait_connect = 0;
8283 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03008284 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03008285 dut->sta_tod_policy = 0;
8286
Jouni Malinend86e5822017-08-29 03:55:32 +03008287 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02008288 free(dut->dpp_peer_uri);
8289 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02008290 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02008291 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03008292 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03008293
Jouni Malinenfac9cad2017-10-10 18:35:55 +03008294 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
8295
vamsi krishnaa2799492017-12-05 14:28:01 +05308296 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308297 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05308298 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05308299 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
8300 dut->fils_hlp = 0;
8301#ifdef ANDROID
8302 hlp_thread_cleanup(dut);
8303#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05308304 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05308305
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05308306 if (dut->program == PROGRAM_QM)
8307 wpa_command(intf, "SET interworking 1");
8308
Jouni Malinen8179fee2019-03-28 03:19:47 +02008309 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03008310 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02008311
Sunil Dutt076081f2018-02-05 19:45:50 +05308312#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008313 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05308314 dut->config_rsnie == 1) {
8315 dut->config_rsnie = 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308316 sta_config_params(dut, intf, STA_SET_RSNIE, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05308317 }
8318#endif /* NL80211_SUPPORT */
8319
Sunil Duttfebf8a82018-02-09 18:50:13 +05308320 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
8321 dut->dev_role = DEVROLE_STA_CFON;
8322 return sta_cfon_reset_default(dut, conn, cmd);
8323 }
8324
Jouni Malinen439352d2018-09-13 03:42:23 +03008325 wpa_command(intf, "SET setband AUTO");
8326
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308327 dut->ocvc = 0;
Jouni Malinen67433fc2020-06-26 22:50:33 +03008328 dut->client_privacy = 0;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05308329 dut->saquery_oci_freq = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05308330
Sunil Duttfebf8a82018-02-09 18:50:13 +05308331 if (dut->program != PROGRAM_VHT)
8332 return cmd_sta_p2p_reset(dut, conn, cmd);
8333
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08008334 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008335}
8336
8337
Jouni Malinenf7222712019-06-13 01:50:21 +03008338static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
8339 struct sigma_conn *conn,
8340 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008341{
8342 const char *program = get_param(cmd, "Program");
8343
8344 if (program == NULL)
8345 return -1;
8346#ifdef ANDROID_NAN
8347 if (strcasecmp(program, "NAN") == 0)
8348 return nan_cmd_sta_get_events(dut, conn, cmd);
8349#endif /* ANDROID_NAN */
8350 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8351 return 0;
8352}
8353
8354
Jouni Malinen82905202018-04-29 17:20:10 +03008355static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
8356 struct sigma_cmd *cmd)
8357{
8358 const char *url = get_param(cmd, "url");
8359 const char *method = get_param(cmd, "method");
8360 pid_t pid;
8361 int status;
8362
8363 if (!url || !method)
8364 return -1;
8365
8366 /* TODO: Add support for method,post */
8367 if (strcasecmp(method, "get") != 0) {
8368 send_resp(dut, conn, SIGMA_ERROR,
8369 "ErrorCode,Unsupported method");
8370 return 0;
8371 }
8372
8373 pid = fork();
8374 if (pid < 0) {
8375 perror("fork");
8376 return -1;
8377 }
8378
8379 if (pid == 0) {
8380 char * argv[5] = { "wget", "-O", "/dev/null",
8381 (char *) url, NULL };
8382
8383 execv("/usr/bin/wget", argv);
8384 perror("execv");
8385 exit(0);
8386 return -1;
8387 }
8388
8389 if (waitpid(pid, &status, 0) < 0) {
8390 perror("waitpid");
8391 return -1;
8392 }
8393
8394 if (WIFEXITED(status)) {
8395 const char *errmsg;
8396
8397 if (WEXITSTATUS(status) == 0)
8398 return 1;
8399 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
8400 WEXITSTATUS(status));
8401 switch (WEXITSTATUS(status)) {
8402 case 4:
8403 errmsg = "errmsg,Network failure";
8404 break;
8405 case 8:
8406 errmsg = "errmsg,Server issued an error response";
8407 break;
8408 default:
8409 errmsg = "errmsg,Unknown failure from wget";
8410 break;
8411 }
8412 send_resp(dut, conn, SIGMA_ERROR, errmsg);
8413 return 0;
8414 }
8415
8416 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
8417 return 0;
8418}
8419
8420
Jouni Malinenf7222712019-06-13 01:50:21 +03008421static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
8422 struct sigma_conn *conn,
8423 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008424{
8425 const char *program = get_param(cmd, "Prog");
8426
Jouni Malinen82905202018-04-29 17:20:10 +03008427 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008428 return -1;
8429#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03008430 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008431 return nan_cmd_sta_exec_action(dut, conn, cmd);
8432#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03008433
8434 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07008435 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03008436
8437 if (get_param(cmd, "url"))
8438 return sta_exec_action_url(dut, conn, cmd);
8439
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008440 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8441 return 0;
8442}
8443
8444
Jouni Malinenf7222712019-06-13 01:50:21 +03008445static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
8446 struct sigma_conn *conn,
8447 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008448{
8449 const char *intf = get_param(cmd, "Interface");
8450 const char *val, *mcs32, *rate;
8451
8452 val = get_param(cmd, "GREENFIELD");
8453 if (val) {
8454 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
8455 /* Enable GD */
8456 send_resp(dut, conn, SIGMA_ERROR,
8457 "ErrorCode,GF not supported");
8458 return 0;
8459 }
8460 }
8461
8462 val = get_param(cmd, "SGI20");
8463 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008464 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008465 case DRIVER_ATHEROS:
8466 ath_sta_set_sgi(dut, intf, val);
8467 break;
8468 default:
8469 send_resp(dut, conn, SIGMA_ERROR,
8470 "ErrorCode,SGI20 not supported");
8471 return 0;
8472 }
8473 }
8474
8475 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
8476 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
8477 if (mcs32 && rate) {
8478 /* TODO */
8479 send_resp(dut, conn, SIGMA_ERROR,
8480 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
8481 return 0;
8482 } else if (mcs32 && !rate) {
8483 /* TODO */
8484 send_resp(dut, conn, SIGMA_ERROR,
8485 "ErrorCode,MCS32 not supported");
8486 return 0;
8487 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008488 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008489 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008490 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008491 ath_sta_set_11nrates(dut, intf, rate);
8492 break;
8493 default:
8494 send_resp(dut, conn, SIGMA_ERROR,
8495 "ErrorCode,MCS32_FIXEDRATE not supported");
8496 return 0;
8497 }
8498 }
8499
8500 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8501}
8502
8503
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008504static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8505 int mcs_config)
8506{
8507#ifdef NL80211_SUPPORT
8508 int ret;
8509
8510 switch (mcs_config) {
8511 case HE_80_MCS0_7:
8512 case HE_80_MCS0_9:
8513 case HE_80_MCS0_11:
8514 ret = sta_set_he_mcs(dut, intf, mcs_config);
8515 if (ret) {
8516 sigma_dut_print(dut, DUT_MSG_ERROR,
8517 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8518 mcs_config, ret);
8519 }
8520 break;
8521 default:
8522 sigma_dut_print(dut, DUT_MSG_ERROR,
8523 "cmd_set_max_he_mcs: Invalid mcs %d",
8524 mcs_config);
8525 break;
8526 }
8527#else /* NL80211_SUPPORT */
8528 sigma_dut_print(dut, DUT_MSG_ERROR,
8529 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8530#endif /* NL80211_SUPPORT */
8531}
8532
8533
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008534#define TWT_REQUEST_CMD 0
8535#define TWT_SUGGEST_CMD 1
8536#define TWT_DEMAND_CMD 2
8537
Arif Hussain480d5f42019-03-12 14:40:42 -07008538static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8539 struct sigma_cmd *cmd)
8540{
8541#ifdef NL80211_SUPPORT
8542 struct nlattr *params;
8543 struct nlattr *attr;
8544 struct nlattr *attr1;
8545 struct nl_msg *msg;
8546 int ifindex, ret;
8547 const char *val;
8548 const char *intf = get_param(cmd, "Interface");
8549 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8550 wake_interval_mantissa = 512;
8551 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008552 protection = 0, cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
Arif Hussain480d5f42019-03-12 14:40:42 -07008553
8554 ifindex = if_nametoindex(intf);
8555 if (ifindex == 0) {
8556 sigma_dut_print(dut, DUT_MSG_ERROR,
8557 "%s: Index for interface %s failed",
8558 __func__, intf);
8559 return -1;
8560 }
8561
8562 val = get_param(cmd, "FlowType");
8563 if (val) {
8564 flow_type = atoi(val);
8565 if (flow_type != 0 && flow_type != 1) {
8566 sigma_dut_print(dut, DUT_MSG_ERROR,
8567 "TWT: Invalid FlowType %d", flow_type);
8568 return -1;
8569 }
8570 }
8571
8572 val = get_param(cmd, "TWT_Trigger");
8573 if (val) {
8574 twt_trigger = atoi(val);
8575 if (twt_trigger != 0 && twt_trigger != 1) {
8576 sigma_dut_print(dut, DUT_MSG_ERROR,
8577 "TWT: Invalid TWT_Trigger %d",
8578 twt_trigger);
8579 return -1;
8580 }
8581 }
8582
8583 val = get_param(cmd, "Protection");
8584 if (val) {
8585 protection = atoi(val);
8586 if (protection != 0 && protection != 1) {
8587 sigma_dut_print(dut, DUT_MSG_ERROR,
8588 "TWT: Invalid Protection %d",
8589 protection);
8590 return -1;
8591 }
8592 }
8593
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008594 val = get_param(cmd, "SetupCommand");
8595 if (val) {
8596 cmd_type = atoi(val);
8597 if (cmd_type == TWT_REQUEST_CMD)
8598 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_REQUEST;
8599 else if (cmd_type == TWT_SUGGEST_CMD)
8600 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
8601 else if (cmd_type == TWT_DEMAND_CMD)
8602 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_DEMAND;
8603 else
8604 sigma_dut_print(dut, DUT_MSG_ERROR,
8605 "Default suggest is used for cmd %d",
8606 cmd_type);
8607 }
8608
Arif Hussain480d5f42019-03-12 14:40:42 -07008609 val = get_param(cmd, "TargetWakeTime");
8610 if (val)
8611 target_wake_time = atoi(val);
8612
8613 val = get_param(cmd, "WakeIntervalMantissa");
8614 if (val)
8615 wake_interval_mantissa = atoi(val);
8616
8617 val = get_param(cmd, "WakeIntervalExp");
8618 if (val)
8619 wake_interval_exp = atoi(val);
8620
8621 val = get_param(cmd, "NominalMinWakeDur");
8622 if (val)
8623 nominal_min_wake_dur = atoi(val);
8624
8625 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8626 NL80211_CMD_VENDOR)) ||
8627 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8628 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8629 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8630 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8631 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8632 !(params = nla_nest_start(
8633 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
8634 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8635 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8636 wake_interval_exp) ||
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008637 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, cmd_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008638 (twt_trigger &&
8639 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008640 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8641 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008642 (protection &&
8643 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008644 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8645 target_wake_time) ||
8646 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8647 nominal_min_wake_dur) ||
8648 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8649 wake_interval_mantissa)) {
8650 sigma_dut_print(dut, DUT_MSG_ERROR,
8651 "%s: err in adding vendor_cmd and vendor_data",
8652 __func__);
8653 nlmsg_free(msg);
8654 return -1;
8655 }
8656 nla_nest_end(msg, attr1);
8657 nla_nest_end(msg, params);
8658 nla_nest_end(msg, attr);
8659
8660 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8661 if (ret) {
8662 sigma_dut_print(dut, DUT_MSG_ERROR,
8663 "%s: err in send_and_recv_msgs, ret=%d",
8664 __func__, ret);
8665 }
8666
8667 return ret;
8668#else /* NL80211_SUPPORT */
8669 sigma_dut_print(dut, DUT_MSG_ERROR,
8670 "TWT request cannot be done without NL80211_SUPPORT defined");
8671 return -1;
8672#endif /* NL80211_SUPPORT */
8673}
8674
8675
8676static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8677 struct sigma_cmd *cmd)
8678{
8679 #ifdef NL80211_SUPPORT
8680 struct nlattr *params;
8681 struct nlattr *attr;
8682 struct nlattr *attr1;
8683 int ifindex, ret;
8684 struct nl_msg *msg;
8685 const char *intf = get_param(cmd, "Interface");
8686
8687 ifindex = if_nametoindex(intf);
8688 if (ifindex == 0) {
8689 sigma_dut_print(dut, DUT_MSG_ERROR,
8690 "%s: Index for interface %s failed",
8691 __func__, intf);
8692 return -1;
8693 }
8694
8695 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8696 NL80211_CMD_VENDOR)) ||
8697 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8698 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8699 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8700 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8701 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8702 !(params = nla_nest_start(
8703 msg,
8704 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8705 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8706 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8707 sigma_dut_print(dut, DUT_MSG_ERROR,
8708 "%s: err in adding vendor_cmd and vendor_data",
8709 __func__);
8710 nlmsg_free(msg);
8711 return -1;
8712 }
8713 nla_nest_end(msg, attr1);
8714 nla_nest_end(msg, params);
8715 nla_nest_end(msg, attr);
8716
8717 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8718 if (ret) {
8719 sigma_dut_print(dut, DUT_MSG_ERROR,
8720 "%s: err in send_and_recv_msgs, ret=%d",
8721 __func__, ret);
8722 }
8723
8724 return ret;
8725#else /* NL80211_SUPPORT */
8726 sigma_dut_print(dut, DUT_MSG_ERROR,
8727 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8728 return -1;
8729#endif /* NL80211_SUPPORT */
8730}
8731
8732
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008733static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8734 struct sigma_cmd *cmd)
8735{
8736#ifdef NL80211_SUPPORT
8737 struct nlattr *params;
8738 struct nlattr *attr;
8739 struct nlattr *attr1;
8740 struct nl_msg *msg;
8741 int ifindex, ret;
8742 const char *val;
8743 const char *intf = get_param(cmd, "Interface");
8744 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8745 ulmu_data_dis = 0;
8746
8747 ifindex = if_nametoindex(intf);
8748 if (ifindex == 0) {
8749 sigma_dut_print(dut, DUT_MSG_ERROR,
8750 "%s: Index for interface %s failed",
8751 __func__, intf);
8752 return -1;
8753 }
8754 val = get_param(cmd, "OMCtrl_RxNSS");
8755 if (val)
8756 rx_nss = atoi(val);
8757
8758 val = get_param(cmd, "OMCtrl_ChnlWidth");
8759 if (val)
8760 ch_bw = atoi(val);
8761
8762 val = get_param(cmd, "OMCtrl_ULMUDisable");
8763 if (val)
8764 ulmu_dis = atoi(val);
8765
8766 val = get_param(cmd, "OMCtrl_TxNSTS");
8767 if (val)
8768 tx_nsts = atoi(val);
8769
8770 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8771 if (val)
8772 ulmu_data_dis = atoi(val);
8773
8774 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8775 NL80211_CMD_VENDOR)) ||
8776 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8777 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8778 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8779 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8780 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8781 !(params = nla_nest_start(
8782 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8783 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8784 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8785 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8786 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8787 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8788 ulmu_data_dis) ||
8789 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8790 ulmu_dis)) {
8791 sigma_dut_print(dut, DUT_MSG_ERROR,
8792 "%s: err in adding vendor_cmd and vendor_data",
8793 __func__);
8794 nlmsg_free(msg);
8795 return -1;
8796 }
8797 nla_nest_end(msg, attr1);
8798 nla_nest_end(msg, params);
8799 nla_nest_end(msg, attr);
8800
8801 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8802 if (ret) {
8803 sigma_dut_print(dut, DUT_MSG_ERROR,
8804 "%s: err in send_and_recv_msgs, ret=%d",
8805 __func__, ret);
8806 }
8807
8808 return ret;
8809#else /* NL80211_SUPPORT */
8810 sigma_dut_print(dut, DUT_MSG_ERROR,
8811 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8812 return -1;
8813#endif /* NL80211_SUPPORT */
8814}
8815
8816
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008817static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8818 struct sigma_conn *conn,
8819 struct sigma_cmd *cmd)
8820{
8821 const char *intf = get_param(cmd, "Interface");
8822 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008823 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008824 int tkip = -1;
8825 int wep = -1;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308826 int iwpriv_status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008827
Arif Hussaina37e9552018-06-20 17:05:59 -07008828 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008829 val = get_param(cmd, "SGI80");
8830 if (val) {
8831 int sgi80;
8832
8833 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008834 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008835 }
8836
8837 val = get_param(cmd, "TxBF");
8838 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008839 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008840 case DRIVER_WCN:
8841 if (sta_set_tx_beamformee(dut, intf, 1)) {
8842 send_resp(dut, conn, SIGMA_ERROR,
8843 "ErrorCode,Failed to set TX beamformee enable");
8844 return 0;
8845 }
8846 break;
8847 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008848 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008849 send_resp(dut, conn, SIGMA_ERROR,
8850 "ErrorCode,Setting vhtsubfee failed");
8851 return 0;
8852 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008853 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008854 send_resp(dut, conn, SIGMA_ERROR,
8855 "ErrorCode,Setting vhtsubfer failed");
8856 return 0;
8857 }
8858 break;
8859 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008860 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008861 "Unsupported driver type");
8862 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008863 }
8864 }
8865
8866 val = get_param(cmd, "MU_TxBF");
8867 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008868 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008869 case DRIVER_ATHEROS:
8870 ath_sta_set_txsp_stream(dut, intf, "1SS");
8871 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008872 run_iwpriv(dut, intf, "vhtmubfee 1");
8873 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308874 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008875 case DRIVER_WCN:
8876 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8877 send_resp(dut, conn, SIGMA_ERROR,
8878 "ErrorCode,Failed to set RX/TXSP_STREAM");
8879 return 0;
8880 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308881 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008882 default:
8883 sigma_dut_print(dut, DUT_MSG_ERROR,
8884 "Setting SP_STREAM not supported");
8885 break;
8886 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008887 }
8888
8889 val = get_param(cmd, "LDPC");
8890 if (val) {
8891 int ldpc;
8892
8893 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308894 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", ldpc);
8895 if (iwpriv_status)
8896 sta_config_params(dut, intf, STA_SET_LDPC, ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008897 }
8898
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008899 val = get_param(cmd, "BCC");
8900 if (val) {
8901 int bcc;
8902
8903 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8904 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8905 * is mutually exclusive to bcc */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308906 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", !bcc);
8907 if (iwpriv_status)
8908 sta_config_params(dut, intf, STA_SET_LDPC, !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008909 }
8910
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008911 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8912 if (val && dut->sta_nss == 1)
8913 cmd_set_max_he_mcs(dut, intf, atoi(val));
8914
8915 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8916 if (val && dut->sta_nss == 2)
8917 cmd_set_max_he_mcs(dut, intf, atoi(val));
8918
Arif Hussainac6c5112018-05-25 17:34:00 -07008919 val = get_param(cmd, "MCS_FixedRate");
8920 if (val) {
8921#ifdef NL80211_SUPPORT
8922 int mcs, ratecode = 0;
8923 enum he_mcs_config mcs_config;
8924 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008925 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008926
8927 ratecode = (0x07 & dut->sta_nss) << 5;
8928 mcs = atoi(val);
8929 /* Add the MCS to the ratecode */
8930 if (mcs >= 0 && mcs <= 11) {
8931 ratecode += mcs;
8932 if (dut->device_type == STA_testbed &&
8933 mcs > 7 && mcs <= 11) {
8934 if (mcs <= 9)
8935 mcs_config = HE_80_MCS0_9;
8936 else
8937 mcs_config = HE_80_MCS0_11;
8938 ret = sta_set_he_mcs(dut, intf, mcs_config);
8939 if (ret) {
8940 sigma_dut_print(dut, DUT_MSG_ERROR,
8941 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8942 mcs, mcs_config, ret);
8943 }
8944 }
8945 snprintf(buf, sizeof(buf),
8946 "iwpriv %s set_11ax_rate 0x%03x",
8947 intf, ratecode);
8948 if (system(buf) != 0) {
8949 sigma_dut_print(dut, DUT_MSG_ERROR,
8950 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8951 ratecode);
8952 }
8953 } else {
8954 sigma_dut_print(dut, DUT_MSG_ERROR,
8955 "MCS_FixedRate: HE MCS %d not supported",
8956 mcs);
8957 }
8958#else /* NL80211_SUPPORT */
8959 sigma_dut_print(dut, DUT_MSG_ERROR,
8960 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8961#endif /* NL80211_SUPPORT */
8962 }
8963
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008964 val = get_param(cmd, "opt_md_notif_ie");
8965 if (val) {
8966 char *result = NULL;
8967 char delim[] = ";";
8968 char token[30];
8969 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308970 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008971
Peng Xub8fc5cc2017-05-10 17:27:28 -07008972 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308973 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008974
8975 /* Extract the NSS information */
8976 if (result) {
8977 value = atoi(result);
8978 switch (value) {
8979 case 1:
8980 config_val = 1;
8981 break;
8982 case 2:
8983 config_val = 3;
8984 break;
8985 case 3:
8986 config_val = 7;
8987 break;
8988 case 4:
8989 config_val = 15;
8990 break;
8991 default:
8992 config_val = 3;
8993 break;
8994 }
8995
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008996 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8997 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008998
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008999 }
9000
9001 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309002 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009003 if (result) {
9004 value = atoi(result);
9005 switch (value) {
9006 case 20:
9007 config_val = 0;
9008 break;
9009 case 40:
9010 config_val = 1;
9011 break;
9012 case 80:
9013 config_val = 2;
9014 break;
9015 case 160:
9016 config_val = 3;
9017 break;
9018 default:
9019 config_val = 2;
9020 break;
9021 }
9022
9023 dut->chwidth = config_val;
9024
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009025 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009026 }
9027
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009028 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009029 }
9030
9031 val = get_param(cmd, "nss_mcs_cap");
9032 if (val) {
9033 int nss, mcs;
9034 char token[20];
9035 char *result = NULL;
9036 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309037 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009038
Peng Xub8fc5cc2017-05-10 17:27:28 -07009039 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309040 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309041 if (!result) {
9042 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009043 "NSS not specified");
9044 send_resp(dut, conn, SIGMA_ERROR,
9045 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309046 return 0;
9047 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009048 nss = atoi(result);
9049
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009050 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07009051 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009052
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309053 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009054 if (result == NULL) {
9055 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009056 "MCS not specified");
9057 send_resp(dut, conn, SIGMA_ERROR,
9058 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009059 return 0;
9060 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309061 result = strtok_r(result, "-", &saveptr);
9062 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309063 if (!result) {
9064 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009065 "MCS not specified");
9066 send_resp(dut, conn, SIGMA_ERROR,
9067 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05309068 return 0;
9069 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009070 mcs = atoi(result);
9071
Arif Hussaina37e9552018-06-20 17:05:59 -07009072 if (program && strcasecmp(program, "HE") == 0) {
9073#ifdef NL80211_SUPPORT
9074 enum he_mcs_config mcs_config;
9075 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009076
Arif Hussaina37e9552018-06-20 17:05:59 -07009077 if (mcs >= 0 && mcs <= 7) {
9078 mcs_config = HE_80_MCS0_7;
9079 } else if (mcs > 7 && mcs <= 9) {
9080 mcs_config = HE_80_MCS0_9;
9081 } else if (mcs > 9 && mcs <= 11) {
9082 mcs_config = HE_80_MCS0_11;
9083 } else {
9084 sigma_dut_print(dut, DUT_MSG_ERROR,
9085 "nss_mcs_cap: HE: Invalid mcs: %d",
9086 mcs);
9087 send_resp(dut, conn, SIGMA_ERROR,
9088 "errorCode,Invalid MCS");
9089 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009090 }
Arif Hussaina37e9552018-06-20 17:05:59 -07009091
9092 ret = sta_set_he_mcs(dut, intf, mcs_config);
9093 if (ret) {
9094 sigma_dut_print(dut, DUT_MSG_ERROR,
9095 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
9096 mcs_config, ret);
9097 send_resp(dut, conn, SIGMA_ERROR,
9098 "errorCode,Failed to set MCS");
9099 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009100 }
Arif Hussaina37e9552018-06-20 17:05:59 -07009101#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009102 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07009103 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
9104#endif /* NL80211_SUPPORT */
9105 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009106 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07009107
9108 switch (nss) {
9109 case 1:
9110 switch (mcs) {
9111 case 7:
9112 vht_mcsmap = 0xfffc;
9113 break;
9114 case 8:
9115 vht_mcsmap = 0xfffd;
9116 break;
9117 case 9:
9118 vht_mcsmap = 0xfffe;
9119 break;
9120 default:
9121 vht_mcsmap = 0xfffe;
9122 break;
9123 }
9124 break;
9125 case 2:
9126 switch (mcs) {
9127 case 7:
9128 vht_mcsmap = 0xfff0;
9129 break;
9130 case 8:
9131 vht_mcsmap = 0xfff5;
9132 break;
9133 case 9:
9134 vht_mcsmap = 0xfffa;
9135 break;
9136 default:
9137 vht_mcsmap = 0xfffa;
9138 break;
9139 }
9140 break;
9141 case 3:
9142 switch (mcs) {
9143 case 7:
9144 vht_mcsmap = 0xffc0;
9145 break;
9146 case 8:
9147 vht_mcsmap = 0xffd5;
9148 break;
9149 case 9:
9150 vht_mcsmap = 0xffea;
9151 break;
9152 default:
9153 vht_mcsmap = 0xffea;
9154 break;
9155 }
9156 break;
9157 default:
9158 vht_mcsmap = 0xffea;
9159 break;
9160 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009161 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009162 }
9163 }
9164
9165 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
9166
9167 val = get_param(cmd, "Vht_tkip");
9168 if (val)
9169 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9170
9171 val = get_param(cmd, "Vht_wep");
9172 if (val)
9173 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
9174
9175 if (tkip != -1 || wep != -1) {
9176 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009177 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009178 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009179 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009180 } else {
9181 sigma_dut_print(dut, DUT_MSG_ERROR,
9182 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
9183 return 0;
9184 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009185 }
9186
Arif Hussain55f00da2018-07-03 08:28:26 -07009187 val = get_param(cmd, "txBandwidth");
9188 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009189 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07009190 case DRIVER_WCN:
9191 if (wcn_sta_set_width(dut, intf, val) < 0) {
9192 send_resp(dut, conn, SIGMA_ERROR,
9193 "ErrorCode,Failed to set txBandwidth");
9194 return 0;
9195 }
9196 break;
9197 case DRIVER_ATHEROS:
9198 if (ath_set_width(dut, conn, intf, val) < 0) {
9199 send_resp(dut, conn, SIGMA_ERROR,
9200 "ErrorCode,Failed to set txBandwidth");
9201 return 0;
9202 }
9203 break;
9204 default:
9205 sigma_dut_print(dut, DUT_MSG_ERROR,
9206 "Setting txBandwidth not supported");
9207 break;
9208 }
9209 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009210
Arif Hussain9765f7d2018-07-03 08:28:26 -07009211 val = get_param(cmd, "BeamformeeSTS");
9212 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07009213 if (sta_set_tx_beamformee(dut, intf, 1)) {
9214 send_resp(dut, conn, SIGMA_ERROR,
9215 "ErrorCode,Failed to set TX beamformee enable");
9216 return 0;
9217 }
9218
Arif Hussain9765f7d2018-07-03 08:28:26 -07009219 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
9220 send_resp(dut, conn, SIGMA_ERROR,
9221 "ErrorCode,Failed to set BeamformeeSTS");
9222 return 0;
9223 }
9224 }
9225
Arif Hussain68d23f52018-07-11 13:39:08 -07009226 val = get_param(cmd, "Trig_MAC_Padding_Dur");
9227 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07009228#ifdef NL80211_SUPPORT
9229 enum qca_wlan_he_mac_padding_dur set_val;
9230
9231 switch (atoi(val)) {
9232 case 16:
9233 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
9234 break;
9235 case 8:
9236 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
9237 break;
9238 default:
9239 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
9240 break;
9241 }
9242 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07009243 send_resp(dut, conn, SIGMA_ERROR,
9244 "ErrorCode,Failed to set MAC padding duration");
9245 return 0;
9246 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07009247#else /* NL80211_SUPPORT */
9248 sigma_dut_print(dut, DUT_MSG_ERROR,
9249 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
9250#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07009251 }
9252
Arif Hussain480d5f42019-03-12 14:40:42 -07009253 val = get_param(cmd, "TWT_ReqSupport");
9254 if (val) {
9255 int set_val;
9256
9257 if (strcasecmp(val, "Enable") == 0) {
9258 set_val = 1;
9259 } else if (strcasecmp(val, "Disable") == 0) {
9260 set_val = 0;
9261 } else {
9262 send_resp(dut, conn, SIGMA_ERROR,
9263 "ErrorCode,Invalid TWT_ReqSupport");
9264 return STATUS_SENT;
9265 }
9266
9267 if (sta_set_twt_req_support(dut, intf, set_val)) {
9268 sigma_dut_print(dut, DUT_MSG_ERROR,
9269 "Failed to set TWT req support %d",
9270 set_val);
9271 send_resp(dut, conn, SIGMA_ERROR,
9272 "ErrorCode,Failed to set TWT_ReqSupport");
9273 return STATUS_SENT;
9274 }
9275 }
9276
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07009277 val = get_param(cmd, "MU_EDCA");
9278 if (val && (strcasecmp(val, "Override") == 0)) {
9279 if (sta_set_mu_edca_override(dut, intf, 1)) {
9280 send_resp(dut, conn, SIGMA_ERROR,
9281 "ErrorCode,Failed to set MU EDCA override");
9282 return 0;
9283 }
9284 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009285
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07009286 val = get_param(cmd, "OMControl");
9287 if (val) {
9288 int set_val = 1;
9289
9290 if (strcasecmp(val, "Enable") == 0)
9291 set_val = 1;
9292 else if (strcasecmp(val, "Disable") == 0)
9293 set_val = 0;
9294
9295 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
9296 send_resp(dut, conn, SIGMA_ERROR,
9297 "ErrorCode,Failed to set OM ctrl supp");
9298 return 0;
9299 }
9300 }
9301
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009302 val = get_param(cmd, "ADDBAResp_BufSize");
9303 if (val) {
9304 int buf_size;
9305
9306 if (strcasecmp(val, "gt64") == 0)
9307 buf_size = 256;
9308 else
9309 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009310 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009311 sta_set_addba_buf_size(dut, intf, buf_size)) {
9312 send_resp(dut, conn, SIGMA_ERROR,
9313 "ErrorCode,set addbaresp_buff_size failed");
9314 return 0;
9315 }
9316 }
9317
9318 val = get_param(cmd, "ADDBAReq_BufSize");
9319 if (val) {
9320 int buf_size;
9321
9322 if (strcasecmp(val, "gt64") == 0)
9323 buf_size = 256;
9324 else
9325 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009326 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009327 sta_set_addba_buf_size(dut, intf, buf_size)) {
9328 send_resp(dut, conn, SIGMA_ERROR,
9329 "ErrorCode,set addbareq_buff_size failed");
9330 return 0;
9331 }
9332 }
9333
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009334 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9335}
9336
9337
9338static int sta_set_wireless_60g(struct sigma_dut *dut,
9339 struct sigma_conn *conn,
9340 struct sigma_cmd *cmd)
9341{
9342 const char *dev_role = get_param(cmd, "DevRole");
9343
9344 if (!dev_role) {
9345 send_resp(dut, conn, SIGMA_INVALID,
9346 "ErrorCode,DevRole not specified");
9347 return 0;
9348 }
9349
9350 if (strcasecmp(dev_role, "PCP") == 0)
9351 return sta_set_60g_pcp(dut, conn, cmd);
9352 if (strcasecmp(dev_role, "STA") == 0)
9353 return sta_set_60g_sta(dut, conn, cmd);
9354 send_resp(dut, conn, SIGMA_INVALID,
9355 "ErrorCode,DevRole not supported");
9356 return 0;
9357}
9358
9359
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309360static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
9361 struct sigma_cmd *cmd)
9362{
9363 int status;
9364 const char *intf = get_param(cmd, "Interface");
9365 const char *val = get_param(cmd, "DevRole");
9366
9367 if (val && strcasecmp(val, "STA-CFON") == 0) {
9368 status = sta_cfon_set_wireless(dut, conn, cmd);
9369 if (status)
9370 return status;
9371 }
9372 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9373}
9374
9375
Jouni Malinen67433fc2020-06-26 22:50:33 +03009376static enum sigma_cmd_result
9377sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
9378 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309379{
9380 const char *intf = get_param(cmd, "Interface");
9381 const char *val;
9382
9383 val = get_param(cmd, "ocvc");
9384 if (val)
9385 dut->ocvc = atoi(val);
9386
Jouni Malinen67433fc2020-06-26 22:50:33 +03009387 val = get_param(cmd, "ClientPrivacy");
9388 if (val) {
9389 dut->client_privacy = atoi(val);
9390 if (dut->client_privacy &&
9391 (wpa_command(intf, "SET mac_addr 1") < 0 ||
9392 wpa_command(intf, "SET rand_addr_lifetime 1") < 0 ||
9393 wpa_command(intf, "SET preassoc_mac_addr 1") < 0 ||
9394 wpa_command(intf, "SET gas_rand_mac_addr 1") < 0 ||
9395 wpa_command(intf, "SET gas_rand_addr_lifetime 1") < 0)) {
9396 send_resp(dut, conn, SIGMA_ERROR,
9397 "errorCode,Failed to enable random MAC address use");
9398 return STATUS_SENT_ERROR;
9399 }
9400 }
9401
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309402 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9403}
9404
9405
Jouni Malinenf7222712019-06-13 01:50:21 +03009406static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
9407 struct sigma_conn *conn,
9408 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009409{
9410 const char *val;
9411
9412 val = get_param(cmd, "Program");
9413 if (val) {
9414 if (strcasecmp(val, "11n") == 0)
9415 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08009416 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009417 return cmd_sta_set_wireless_vht(dut, conn, cmd);
9418 if (strcasecmp(val, "60ghz") == 0)
9419 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309420 if (strcasecmp(val, "OCE") == 0)
9421 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02009422 /* sta_set_wireless in WPS program is only used for 60G */
9423 if (is_60g_sigma_dut(dut))
9424 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309425 if (strcasecmp(val, "WPA3") == 0)
9426 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009427 send_resp(dut, conn, SIGMA_ERROR,
9428 "ErrorCode,Program value not supported");
9429 } else {
9430 send_resp(dut, conn, SIGMA_ERROR,
9431 "ErrorCode,Program argument not available");
9432 }
9433
9434 return 0;
9435}
9436
9437
9438static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
9439 int tid)
9440{
9441 char buf[100];
9442 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
9443
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05309444 if (tid < 0 ||
9445 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
9446 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
9447 return;
9448 }
9449
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009450 /*
9451 * Two ways to ensure that addba request with a
9452 * non zero TID could be sent out. EV 117296
9453 */
9454 snprintf(buf, sizeof(buf),
9455 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
9456 tid);
9457 if (system(buf) != 0) {
9458 sigma_dut_print(dut, DUT_MSG_ERROR,
9459 "Ping did not send out");
9460 }
9461
9462 snprintf(buf, sizeof(buf),
9463 "iwconfig %s | grep Access | awk '{print $6}' > %s",
9464 intf, VI_QOS_TMP_FILE);
9465 if (system(buf) != 0)
9466 return;
9467
9468 snprintf(buf, sizeof(buf),
9469 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
9470 intf, VI_QOS_TMP_FILE);
9471 if (system(buf) != 0)
9472 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
9473
9474 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
9475 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
9476 if (system(buf) != 0) {
9477 sigma_dut_print(dut, DUT_MSG_ERROR,
9478 "VI_QOS_TEMP_FILE generation error failed");
9479 }
9480 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9481 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9482 if (system(buf) != 0) {
9483 sigma_dut_print(dut, DUT_MSG_ERROR,
9484 "VI_QOS_FILE generation failed");
9485 }
9486
9487 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9488 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9489 if (system(buf) != 0) {
9490 sigma_dut_print(dut, DUT_MSG_ERROR,
9491 "VI_QOS_FILE generation failed");
9492 }
9493
9494 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
9495 if (system(buf) != 0) {
9496 }
9497}
9498
9499
9500static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9501 struct sigma_cmd *cmd)
9502{
9503 const char *intf = get_param(cmd, "Interface");
9504 const char *val;
9505 int tid = 0;
9506 char buf[100];
9507
9508 val = get_param(cmd, "TID");
9509 if (val) {
9510 tid = atoi(val);
9511 if (tid)
9512 ath_sta_inject_frame(dut, intf, tid);
9513 }
9514
9515 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009516 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009517
9518 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
9519 if (system(buf) != 0) {
9520 sigma_dut_print(dut, DUT_MSG_ERROR,
9521 "wifitool senddelba failed");
9522 }
9523
9524 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
9525 if (system(buf) != 0) {
9526 sigma_dut_print(dut, DUT_MSG_ERROR,
9527 "wifitool sendaddba failed");
9528 }
9529
9530 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9531
9532 return 1;
9533}
9534
9535
Lior David9981b512017-01-20 13:16:40 +02009536#ifdef __linux__
9537
9538static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
9539 int agg_size)
9540{
9541 char dir[128], buf[128];
9542 FILE *f;
9543 regex_t re;
9544 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03009545 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02009546
9547 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
9548 sigma_dut_print(dut, DUT_MSG_ERROR,
9549 "failed to get wil6210 debugfs dir");
9550 return -1;
9551 }
9552
Jouni Malinen3aa72862019-05-29 23:14:51 +03009553 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
9554 if (res < 0 || res >= sizeof(buf))
9555 return -1;
Lior David9981b512017-01-20 13:16:40 +02009556 f = fopen(buf, "r");
9557 if (!f) {
9558 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009559 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009560 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9561 if (res < 0 || res >= sizeof(buf))
9562 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009563 f = fopen(buf, "r");
9564 if (!f) {
9565 sigma_dut_print(dut, DUT_MSG_ERROR,
9566 "failed to open: %s", buf);
9567 return -1;
9568 }
Lior David9981b512017-01-20 13:16:40 +02009569 }
9570
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009571 /* can be either VRING tx... or RING... */
9572 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009573 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9574 goto out;
9575 }
9576
9577 /* find TX VRING for the mac address */
9578 found = 0;
9579 while (fgets(buf, sizeof(buf), f)) {
9580 if (strcasestr(buf, dest_mac)) {
9581 found = 1;
9582 break;
9583 }
9584 }
9585
9586 if (!found) {
9587 sigma_dut_print(dut, DUT_MSG_ERROR,
9588 "no TX VRING for %s", dest_mac);
9589 goto out;
9590 }
9591
9592 /* extract VRING ID, "VRING tx_<id> = {" */
9593 if (!fgets(buf, sizeof(buf), f)) {
9594 sigma_dut_print(dut, DUT_MSG_ERROR,
9595 "no VRING start line for %s", dest_mac);
9596 goto out;
9597 }
9598
9599 rc = regexec(&re, buf, 2, m, 0);
9600 regfree(&re);
9601 if (rc || m[1].rm_so < 0) {
9602 sigma_dut_print(dut, DUT_MSG_ERROR,
9603 "no VRING TX ID for %s", dest_mac);
9604 goto out;
9605 }
9606 buf[m[1].rm_eo] = 0;
9607 vring_id = atoi(&buf[m[1].rm_so]);
9608
9609 /* send the addba command */
9610 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009611 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9612 if (res < 0 || res >= sizeof(buf))
9613 return -1;
Lior David9981b512017-01-20 13:16:40 +02009614 f = fopen(buf, "w");
9615 if (!f) {
9616 sigma_dut_print(dut, DUT_MSG_ERROR,
9617 "failed to open: %s", buf);
9618 return -1;
9619 }
9620
9621 fprintf(f, "add %d %d\n", vring_id, agg_size);
9622
9623 ret = 0;
9624
9625out:
9626 fclose(f);
9627
9628 return ret;
9629}
9630
9631
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009632int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9633 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009634{
9635 const char *val;
9636 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009637
9638 val = get_param(cmd, "TID");
9639 if (val) {
9640 tid = atoi(val);
9641 if (tid != 0) {
9642 sigma_dut_print(dut, DUT_MSG_ERROR,
9643 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9644 tid);
9645 }
9646 }
9647
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009648 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009649 if (!val) {
9650 sigma_dut_print(dut, DUT_MSG_ERROR,
9651 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009652 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009653 }
9654
Lior David9981b512017-01-20 13:16:40 +02009655 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009656 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009657
9658 return 1;
9659}
9660
Lior David9981b512017-01-20 13:16:40 +02009661#endif /* __linux__ */
9662
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009663
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009664static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9665 struct sigma_cmd *cmd)
9666{
9667#ifdef NL80211_SUPPORT
9668 const char *intf = get_param(cmd, "Interface");
9669 const char *val;
9670 int tid = -1;
9671 int bufsize = 64;
9672 struct nl_msg *msg;
9673 int ret = 0;
9674 struct nlattr *params;
9675 int ifindex;
9676
9677 val = get_param(cmd, "TID");
9678 if (val)
9679 tid = atoi(val);
9680
9681 if (tid == -1) {
9682 send_resp(dut, conn, SIGMA_ERROR,
9683 "ErrorCode,sta_send_addba tid invalid");
9684 return 0;
9685 }
9686
9687 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9688
9689 ifindex = if_nametoindex(intf);
9690 if (ifindex == 0) {
9691 sigma_dut_print(dut, DUT_MSG_ERROR,
9692 "%s: Index for interface %s failed",
9693 __func__, intf);
9694 send_resp(dut, conn, SIGMA_ERROR,
9695 "ErrorCode,sta_send_addba interface invalid");
9696 return 0;
9697 }
9698
9699 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9700 NL80211_CMD_VENDOR)) ||
9701 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9702 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9703 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9704 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9705 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9706 nla_put_u8(msg,
9707 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9708 QCA_WLAN_ADD_BA) ||
9709 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9710 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009711 nla_put_u16(msg,
9712 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9713 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009714 sigma_dut_print(dut, DUT_MSG_ERROR,
9715 "%s: err in adding vendor_cmd and vendor_data",
9716 __func__);
9717 nlmsg_free(msg);
9718 send_resp(dut, conn, SIGMA_ERROR,
9719 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9720 return 0;
9721 }
9722 nla_nest_end(msg, params);
9723
9724 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9725 if (ret) {
9726 sigma_dut_print(dut, DUT_MSG_ERROR,
9727 "%s: err in send_and_recv_msgs, ret=%d",
9728 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309729 if (ret == -EOPNOTSUPP)
9730 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009731 send_resp(dut, conn, SIGMA_ERROR,
9732 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9733 return 0;
9734 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009735#else /* NL80211_SUPPORT */
9736 sigma_dut_print(dut, DUT_MSG_ERROR,
9737 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009738#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309739
9740 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009741}
9742
9743
Jouni Malinenf7222712019-06-13 01:50:21 +03009744static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9745 struct sigma_conn *conn,
9746 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009747{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009748 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009749 case DRIVER_ATHEROS:
9750 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009751 case DRIVER_WCN:
9752 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009753#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009754 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009755 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009756#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009757 default:
9758 /*
9759 * There is no driver specific implementation for other drivers.
9760 * Ignore the command and report COMPLETE since the following
9761 * throughput test operation will end up sending ADDBA anyway.
9762 */
9763 return 1;
9764 }
9765}
9766
9767
9768int inject_eth_frame(int s, const void *data, size_t len,
9769 unsigned short ethtype, char *dst, char *src)
9770{
9771 struct iovec iov[4] = {
9772 {
9773 .iov_base = dst,
9774 .iov_len = ETH_ALEN,
9775 },
9776 {
9777 .iov_base = src,
9778 .iov_len = ETH_ALEN,
9779 },
9780 {
9781 .iov_base = &ethtype,
9782 .iov_len = sizeof(unsigned short),
9783 },
9784 {
9785 .iov_base = (void *) data,
9786 .iov_len = len,
9787 }
9788 };
9789 struct msghdr msg = {
9790 .msg_name = NULL,
9791 .msg_namelen = 0,
9792 .msg_iov = iov,
9793 .msg_iovlen = 4,
9794 .msg_control = NULL,
9795 .msg_controllen = 0,
9796 .msg_flags = 0,
9797 };
9798
9799 return sendmsg(s, &msg, 0);
9800}
9801
9802#if defined(__linux__) || defined(__QNXNTO__)
9803
9804int inject_frame(int s, const void *data, size_t len, int encrypt)
9805{
9806#define IEEE80211_RADIOTAP_F_WEP 0x04
9807#define IEEE80211_RADIOTAP_F_FRAG 0x08
9808 unsigned char rtap_hdr[] = {
9809 0x00, 0x00, /* radiotap version */
9810 0x0e, 0x00, /* radiotap length */
9811 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9812 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9813 0x00, /* padding */
9814 0x00, 0x00, /* RX and TX flags to indicate that */
9815 0x00, 0x00, /* this is the injected frame directly */
9816 };
9817 struct iovec iov[2] = {
9818 {
9819 .iov_base = &rtap_hdr,
9820 .iov_len = sizeof(rtap_hdr),
9821 },
9822 {
9823 .iov_base = (void *) data,
9824 .iov_len = len,
9825 }
9826 };
9827 struct msghdr msg = {
9828 .msg_name = NULL,
9829 .msg_namelen = 0,
9830 .msg_iov = iov,
9831 .msg_iovlen = 2,
9832 .msg_control = NULL,
9833 .msg_controllen = 0,
9834 .msg_flags = 0,
9835 };
9836
9837 if (encrypt)
9838 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9839
9840 return sendmsg(s, &msg, 0);
9841}
9842
9843
9844int open_monitor(const char *ifname)
9845{
9846#ifdef __QNXNTO__
9847 struct sockaddr_dl ll;
9848 int s;
9849
9850 memset(&ll, 0, sizeof(ll));
9851 ll.sdl_family = AF_LINK;
9852 ll.sdl_index = if_nametoindex(ifname);
9853 if (ll.sdl_index == 0) {
9854 perror("if_nametoindex");
9855 return -1;
9856 }
9857 s = socket(PF_INET, SOCK_RAW, 0);
9858#else /* __QNXNTO__ */
9859 struct sockaddr_ll ll;
9860 int s;
9861
9862 memset(&ll, 0, sizeof(ll));
9863 ll.sll_family = AF_PACKET;
9864 ll.sll_ifindex = if_nametoindex(ifname);
9865 if (ll.sll_ifindex == 0) {
9866 perror("if_nametoindex");
9867 return -1;
9868 }
9869 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9870#endif /* __QNXNTO__ */
9871 if (s < 0) {
9872 perror("socket[PF_PACKET,SOCK_RAW]");
9873 return -1;
9874 }
9875
9876 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9877 perror("monitor socket bind");
9878 close(s);
9879 return -1;
9880 }
9881
9882 return s;
9883}
9884
9885
9886static int hex2num(char c)
9887{
9888 if (c >= '0' && c <= '9')
9889 return c - '0';
9890 if (c >= 'a' && c <= 'f')
9891 return c - 'a' + 10;
9892 if (c >= 'A' && c <= 'F')
9893 return c - 'A' + 10;
9894 return -1;
9895}
9896
9897
9898int hwaddr_aton(const char *txt, unsigned char *addr)
9899{
9900 int i;
9901
9902 for (i = 0; i < 6; i++) {
9903 int a, b;
9904
9905 a = hex2num(*txt++);
9906 if (a < 0)
9907 return -1;
9908 b = hex2num(*txt++);
9909 if (b < 0)
9910 return -1;
9911 *addr++ = (a << 4) | b;
9912 if (i < 5 && *txt++ != ':')
9913 return -1;
9914 }
9915
9916 return 0;
9917}
9918
9919#endif /* defined(__linux__) || defined(__QNXNTO__) */
9920
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309921
9922#ifdef NL80211_SUPPORT
9923static int nl80211_send_frame_cmd(struct sigma_dut *dut, const char *intf,
9924 const u8 *data, size_t data_len, int freq)
9925{
9926 struct nl_msg *msg;
9927 int ret = 0;
9928 int ifindex;
9929
9930 ifindex = if_nametoindex(intf);
9931 if (ifindex == 0) {
9932 sigma_dut_print(dut, DUT_MSG_ERROR,
9933 "%s: Index for interface %s failed",
9934 __func__, intf);
9935 return -1;
9936 }
9937
9938 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9939 NL80211_CMD_FRAME)) ||
9940 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
9941 nla_put(msg, NL80211_ATTR_FRAME, data_len, data)) {
9942 sigma_dut_print(dut, DUT_MSG_ERROR,
9943 "%s: Error in adding NL80211_CMD_FRAME",
9944 __func__);
9945 nlmsg_free(msg);
9946 return -1;
9947 }
9948
9949 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9950 if (ret) {
9951 sigma_dut_print(dut, DUT_MSG_ERROR,
9952 "nl80211: Frame command failed: ret=%d (%s) req=%u",
9953 ret, strerror(-ret), freq);
9954 return -1;
9955 }
9956
9957 return 0;
9958}
9959#endif /* NL80211_SUPPORT */
9960
9961
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009962enum send_frame_type {
9963 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9964};
9965enum send_frame_protection {
9966 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9967};
9968
9969
9970static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309971 const char *intf, enum send_frame_type frame,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009972 enum send_frame_protection protected,
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309973 const char *dest, int use_monitor)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009974{
9975#ifdef __linux__
9976 unsigned char buf[1000], *pos;
9977 int s, res;
9978 char bssid[20], addr[20];
9979 char result[32], ssid[100];
9980 size_t ssid_len;
9981
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009982 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009983 sizeof(result)) < 0 ||
9984 strncmp(result, "COMPLETED", 9) != 0) {
9985 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9986 return 0;
9987 }
9988
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009989 if (get_wpa_status(get_station_ifname(dut), "bssid",
9990 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009991 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9992 "current BSSID");
9993 return 0;
9994 }
9995
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009996 if (get_wpa_status(get_station_ifname(dut), "address",
9997 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009998 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9999 "own MAC address");
10000 return 0;
10001 }
10002
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010003 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010004 < 0) {
10005 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
10006 "current SSID");
10007 return 0;
10008 }
10009 ssid_len = strlen(ssid);
10010
10011 pos = buf;
10012
10013 /* Frame Control */
10014 switch (frame) {
10015 case DISASSOC:
10016 *pos++ = 0xa0;
10017 break;
10018 case DEAUTH:
10019 *pos++ = 0xc0;
10020 break;
10021 case SAQUERY:
10022 *pos++ = 0xd0;
10023 break;
10024 case AUTH:
10025 *pos++ = 0xb0;
10026 break;
10027 case ASSOCREQ:
10028 *pos++ = 0x00;
10029 break;
10030 case REASSOCREQ:
10031 *pos++ = 0x20;
10032 break;
10033 case DLS_REQ:
10034 *pos++ = 0xd0;
10035 break;
10036 }
10037
10038 if (protected == INCORRECT_KEY)
10039 *pos++ = 0x40; /* Set Protected field to 1 */
10040 else
10041 *pos++ = 0x00;
10042
10043 /* Duration */
10044 *pos++ = 0x00;
10045 *pos++ = 0x00;
10046
10047 /* addr1 = DA (current AP) */
10048 hwaddr_aton(bssid, pos);
10049 pos += 6;
10050 /* addr2 = SA (own address) */
10051 hwaddr_aton(addr, pos);
10052 pos += 6;
10053 /* addr3 = BSSID (current AP) */
10054 hwaddr_aton(bssid, pos);
10055 pos += 6;
10056
10057 /* Seq# (to be filled by driver/mac80211) */
10058 *pos++ = 0x00;
10059 *pos++ = 0x00;
10060
10061 if (protected == INCORRECT_KEY) {
10062 /* CCMP parameters */
10063 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
10064 pos += 8;
10065 }
10066
10067 if (protected == INCORRECT_KEY) {
10068 switch (frame) {
10069 case DEAUTH:
10070 /* Reason code (encrypted) */
10071 memcpy(pos, "\xa7\x39", 2);
10072 pos += 2;
10073 break;
10074 case DISASSOC:
10075 /* Reason code (encrypted) */
10076 memcpy(pos, "\xa7\x39", 2);
10077 pos += 2;
10078 break;
10079 case SAQUERY:
10080 /* Category|Action|TransID (encrypted) */
10081 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
10082 pos += 4;
10083 break;
10084 default:
10085 return -1;
10086 }
10087
10088 /* CCMP MIC */
10089 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
10090 pos += 8;
10091 } else {
10092 switch (frame) {
10093 case DEAUTH:
10094 /* reason code = 8 */
10095 *pos++ = 0x08;
10096 *pos++ = 0x00;
10097 break;
10098 case DISASSOC:
10099 /* reason code = 8 */
10100 *pos++ = 0x08;
10101 *pos++ = 0x00;
10102 break;
10103 case SAQUERY:
10104 /* Category - SA Query */
10105 *pos++ = 0x08;
10106 /* SA query Action - Request */
10107 *pos++ = 0x00;
10108 /* Transaction ID */
10109 *pos++ = 0x12;
10110 *pos++ = 0x34;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053010111 if (dut->saquery_oci_freq) {
10112 /* OCI IE - Extended ID */
10113 *pos++ = 0xFF;
10114 *pos++ = 0x04;
10115 *pos++ = 0x36;
10116 /* Operating Class */
10117 *pos++ = 0x74;
10118 /* Primary Channel */
10119 *pos++ = freq_to_channel(dut->saquery_oci_freq);
10120 /* Frequency Segment 1 Channel Number */
10121 *pos++ = 0x00;
10122 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010123 break;
10124 case AUTH:
10125 /* Auth Alg (Open) */
10126 *pos++ = 0x00;
10127 *pos++ = 0x00;
10128 /* Seq# */
10129 *pos++ = 0x01;
10130 *pos++ = 0x00;
10131 /* Status code */
10132 *pos++ = 0x00;
10133 *pos++ = 0x00;
10134 break;
10135 case ASSOCREQ:
10136 /* Capability Information */
10137 *pos++ = 0x31;
10138 *pos++ = 0x04;
10139 /* Listen Interval */
10140 *pos++ = 0x0a;
10141 *pos++ = 0x00;
10142 /* SSID */
10143 *pos++ = 0x00;
10144 *pos++ = ssid_len;
10145 memcpy(pos, ssid, ssid_len);
10146 pos += ssid_len;
10147 /* Supported Rates */
10148 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
10149 10);
10150 pos += 10;
10151 /* Extended Supported Rates */
10152 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
10153 pos += 6;
10154 /* RSN */
10155 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
10156 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
10157 "\x00\x00\x00\x00\x0f\xac\x06", 28);
10158 pos += 28;
10159 break;
10160 case REASSOCREQ:
10161 /* Capability Information */
10162 *pos++ = 0x31;
10163 *pos++ = 0x04;
10164 /* Listen Interval */
10165 *pos++ = 0x0a;
10166 *pos++ = 0x00;
10167 /* Current AP */
10168 hwaddr_aton(bssid, pos);
10169 pos += 6;
10170 /* SSID */
10171 *pos++ = 0x00;
10172 *pos++ = ssid_len;
10173 memcpy(pos, ssid, ssid_len);
10174 pos += ssid_len;
10175 /* Supported Rates */
10176 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
10177 10);
10178 pos += 10;
10179 /* Extended Supported Rates */
10180 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
10181 pos += 6;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053010182 /* RSNE - Group and Pairwise ciphers */
10183 memcpy(pos,
10184 "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04",
10185 14);
10186 pos += 14;
10187 /* RSNE - AKM Suite count */
10188 *pos++ = 0x01;
10189 *pos++ = 0x00;
10190 /* RSNE - AKM Suites */
10191 if (dut->program == PROGRAM_WPA3)
10192 memcpy(pos, "\x00\x0f\xac\x08", 4);
10193 else
10194 memcpy(pos, "\x00\x0f\xac\x02", 4);
10195 pos += 4;
10196 /* RSNE - Capabilities */
10197 *pos++ = 0xc0;
10198 if (dut->ocvc)
10199 *pos++ = 0x40;
10200 else
10201 *pos++ = 0x00;
10202 /* RSNE - PMKID list and Group Management Ciphers */
10203 memcpy(pos, "\x00\x00\x00\x0f\xac\x06", 6);
10204 pos += 6;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010205 break;
10206 case DLS_REQ:
10207 /* Category - DLS */
10208 *pos++ = 0x02;
10209 /* DLS Action - Request */
10210 *pos++ = 0x00;
10211 /* Destination MACAddress */
10212 if (dest)
10213 hwaddr_aton(dest, pos);
10214 else
10215 memset(pos, 0, 6);
10216 pos += 6;
10217 /* Source MACAddress */
10218 hwaddr_aton(addr, pos);
10219 pos += 6;
10220 /* Capability Information */
10221 *pos++ = 0x10; /* Privacy */
10222 *pos++ = 0x06; /* QoS */
10223 /* DLS Timeout Value */
10224 *pos++ = 0x00;
10225 *pos++ = 0x01;
10226 /* Supported rates */
10227 *pos++ = 0x01;
10228 *pos++ = 0x08;
10229 *pos++ = 0x0c; /* 6 Mbps */
10230 *pos++ = 0x12; /* 9 Mbps */
10231 *pos++ = 0x18; /* 12 Mbps */
10232 *pos++ = 0x24; /* 18 Mbps */
10233 *pos++ = 0x30; /* 24 Mbps */
10234 *pos++ = 0x48; /* 36 Mbps */
10235 *pos++ = 0x60; /* 48 Mbps */
10236 *pos++ = 0x6c; /* 54 Mbps */
10237 /* TODO: Extended Supported Rates */
10238 /* TODO: HT Capabilities */
10239 break;
10240 }
10241 }
10242
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010243 if (use_monitor) {
10244 s = open_monitor("sigmadut");
10245 if (s < 0) {
10246 send_resp(dut, conn, SIGMA_ERROR,
10247 "errorCode,Failed to open monitor socket");
10248 return 0;
10249 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010250
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010251 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
10252 if (res < 0) {
10253 send_resp(dut, conn, SIGMA_ERROR,
10254 "errorCode,Failed to inject frame");
10255 close(s);
10256 return 0;
10257 }
10258 if (res < pos - buf) {
10259 send_resp(dut, conn, SIGMA_ERROR,
10260 "errorCode,Only partial frame sent");
10261 close(s);
10262 return 0;
10263 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010264
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010265 close(s);
10266 } else {
10267#ifdef NL80211_SUPPORT
10268 int freq;
10269 char freq_str[10];
10270
10271 if (get_wpa_status(get_station_ifname(dut), "freq",
10272 freq_str, sizeof(freq_str)) < 0) {
10273 send_resp(dut, conn, SIGMA_ERROR,
10274 "errorCode,Could not get current operating frequency");
10275 return 0;
10276 }
10277 freq = atoi(freq_str);
10278
10279 if (nl80211_send_frame_cmd(dut, intf, buf, pos - buf, freq)) {
10280 send_resp(dut, conn, SIGMA_ERROR,
10281 "errorCode,Failed to inject frame");
10282 return 0;
10283 }
10284#else /* NL80211_SUPPORT */
10285 send_resp(dut, conn, SIGMA_ERROR,
10286 "errorCode,Failed to inject frame (no NL80211_SUPPORT)");
10287 return 0;
10288#endif /* NL80211_SUPPORT */
10289 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010290
10291 return 1;
10292#else /* __linux__ */
10293 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
10294 "yet supported");
10295 return 0;
10296#endif /* __linux__ */
10297}
10298
10299
10300static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
10301 struct sigma_conn *conn,
10302 struct sigma_cmd *cmd)
10303{
10304 const char *intf = get_param(cmd, "Interface");
10305 const char *sta, *val;
10306 unsigned char addr[ETH_ALEN];
10307 char buf[100];
10308
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010309 if (!intf)
10310 return -1;
10311
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010312 sta = get_param(cmd, "peer");
10313 if (sta == NULL)
10314 sta = get_param(cmd, "station");
10315 if (sta == NULL) {
10316 send_resp(dut, conn, SIGMA_ERROR,
10317 "ErrorCode,Missing peer address");
10318 return 0;
10319 }
10320 if (hwaddr_aton(sta, addr) < 0) {
10321 send_resp(dut, conn, SIGMA_ERROR,
10322 "ErrorCode,Invalid peer address");
10323 return 0;
10324 }
10325
10326 val = get_param(cmd, "type");
10327 if (val == NULL)
10328 return -1;
10329
10330 if (strcasecmp(val, "DISCOVERY") == 0) {
10331 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
10332 if (wpa_command(intf, buf) < 0) {
10333 send_resp(dut, conn, SIGMA_ERROR,
10334 "ErrorCode,Failed to send TDLS discovery");
10335 return 0;
10336 }
10337 return 1;
10338 }
10339
10340 if (strcasecmp(val, "SETUP") == 0) {
10341 int status = 0, timeout = 0;
10342
10343 val = get_param(cmd, "Status");
10344 if (val)
10345 status = atoi(val);
10346
10347 val = get_param(cmd, "Timeout");
10348 if (val)
10349 timeout = atoi(val);
10350
10351 if (status != 0 && status != 37) {
10352 send_resp(dut, conn, SIGMA_ERROR,
10353 "ErrorCode,Unsupported status value");
10354 return 0;
10355 }
10356
10357 if (timeout != 0 && timeout != 301) {
10358 send_resp(dut, conn, SIGMA_ERROR,
10359 "ErrorCode,Unsupported timeout value");
10360 return 0;
10361 }
10362
10363 if (status && timeout) {
10364 send_resp(dut, conn, SIGMA_ERROR,
10365 "ErrorCode,Unsupported timeout+status "
10366 "combination");
10367 return 0;
10368 }
10369
10370 if (status == 37 &&
10371 wpa_command(intf, "SET tdls_testing 0x200")) {
10372 send_resp(dut, conn, SIGMA_ERROR,
10373 "ErrorCode,Failed to enable "
10374 "decline setup response test mode");
10375 return 0;
10376 }
10377
10378 if (timeout == 301) {
10379 int res;
10380 if (dut->no_tpk_expiration)
10381 res = wpa_command(intf,
10382 "SET tdls_testing 0x108");
10383 else
10384 res = wpa_command(intf,
10385 "SET tdls_testing 0x8");
10386 if (res) {
10387 send_resp(dut, conn, SIGMA_ERROR,
10388 "ErrorCode,Failed to set short TPK "
10389 "lifetime");
10390 return 0;
10391 }
10392 }
10393
10394 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
10395 if (wpa_command(intf, buf) < 0) {
10396 send_resp(dut, conn, SIGMA_ERROR,
10397 "ErrorCode,Failed to send TDLS setup");
10398 return 0;
10399 }
10400 return 1;
10401 }
10402
10403 if (strcasecmp(val, "TEARDOWN") == 0) {
10404 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
10405 if (wpa_command(intf, buf) < 0) {
10406 send_resp(dut, conn, SIGMA_ERROR,
10407 "ErrorCode,Failed to send TDLS teardown");
10408 return 0;
10409 }
10410 return 1;
10411 }
10412
10413 send_resp(dut, conn, SIGMA_ERROR,
10414 "ErrorCode,Unsupported TDLS frame");
10415 return 0;
10416}
10417
10418
10419static int sta_ap_known(const char *ifname, const char *bssid)
10420{
10421 char buf[4096];
10422
Jouni Malinendd32f192018-09-15 02:55:19 +030010423 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010424 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
10425 return 0;
10426 if (strncmp(buf, "id=", 3) != 0)
10427 return 0;
10428 return 1;
10429}
10430
10431
10432static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
10433 const char *bssid)
10434{
10435 int res;
10436 struct wpa_ctrl *ctrl;
10437 char buf[256];
10438
10439 if (sta_ap_known(ifname, bssid))
10440 return 0;
10441 sigma_dut_print(dut, DUT_MSG_DEBUG,
10442 "AP not in BSS table - start scan");
10443
10444 ctrl = open_wpa_mon(ifname);
10445 if (ctrl == NULL) {
10446 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10447 "wpa_supplicant monitor connection");
10448 return -1;
10449 }
10450
10451 if (wpa_command(ifname, "SCAN") < 0) {
10452 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
10453 wpa_ctrl_detach(ctrl);
10454 wpa_ctrl_close(ctrl);
10455 return -1;
10456 }
10457
10458 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
10459 buf, sizeof(buf));
10460
10461 wpa_ctrl_detach(ctrl);
10462 wpa_ctrl_close(ctrl);
10463
10464 if (res < 0) {
10465 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
10466 return -1;
10467 }
10468
10469 if (sta_ap_known(ifname, bssid))
10470 return 0;
10471 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
10472 return -1;
10473}
10474
10475
10476static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
10477 struct sigma_conn *conn,
10478 struct sigma_cmd *cmd,
10479 const char *intf)
10480{
10481 char buf[200];
10482
10483 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
10484 if (system(buf) != 0) {
10485 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
10486 "ndsend");
10487 return 0;
10488 }
10489
10490 return 1;
10491}
10492
10493
10494static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
10495 struct sigma_conn *conn,
10496 struct sigma_cmd *cmd,
10497 const char *intf)
10498{
10499 char buf[200];
10500 const char *ip = get_param(cmd, "SenderIP");
10501
Peng Xu26b356d2017-10-04 17:58:16 -070010502 if (!ip)
10503 return 0;
10504
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010505 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
10506 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10507 if (system(buf) == 0) {
10508 sigma_dut_print(dut, DUT_MSG_INFO,
10509 "Neighbor Solicitation got a response "
10510 "for %s@%s", ip, intf);
10511 }
10512
10513 return 1;
10514}
10515
10516
10517static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
10518 struct sigma_conn *conn,
10519 struct sigma_cmd *cmd,
10520 const char *ifname)
10521{
10522 char buf[200];
10523 const char *ip = get_param(cmd, "SenderIP");
10524
10525 if (ip == NULL) {
10526 send_resp(dut, conn, SIGMA_ERROR,
10527 "ErrorCode,Missing SenderIP parameter");
10528 return 0;
10529 }
10530 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
10531 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10532 if (system(buf) != 0) {
10533 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
10534 "for %s@%s", ip, ifname);
10535 }
10536
10537 return 1;
10538}
10539
10540
10541static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
10542 struct sigma_conn *conn,
10543 struct sigma_cmd *cmd,
10544 const char *ifname)
10545{
10546 char buf[200];
10547 char ip[16];
10548 int s;
Peng Xub3756882017-10-04 14:39:09 -070010549 struct ifreq ifr;
10550 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010551
10552 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070010553 if (s < 0) {
10554 perror("socket");
10555 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010556 }
10557
Peng Xub3756882017-10-04 14:39:09 -070010558 memset(&ifr, 0, sizeof(ifr));
10559 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
10560 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
10561 sigma_dut_print(dut, DUT_MSG_INFO,
10562 "Failed to get %s IP address: %s",
10563 ifname, strerror(errno));
10564 close(s);
10565 return -1;
10566 }
10567 close(s);
10568
10569 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
10570 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
10571
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010572 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
10573 ip);
10574 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10575 if (system(buf) != 0) {
10576 }
10577
10578 return 1;
10579}
10580
10581
10582static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
10583 struct sigma_conn *conn,
10584 struct sigma_cmd *cmd,
10585 const char *ifname)
10586{
10587 char buf[200], addr[20];
10588 char dst[ETH_ALEN], src[ETH_ALEN];
10589 short ethtype = htons(ETH_P_ARP);
10590 char *pos;
10591 int s, res;
10592 const char *val;
10593 struct sockaddr_in taddr;
10594
10595 val = get_param(cmd, "dest");
10596 if (val)
10597 hwaddr_aton(val, (unsigned char *) dst);
10598
10599 val = get_param(cmd, "DestIP");
10600 if (val)
10601 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070010602 else
10603 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010604
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010605 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010606 sizeof(addr)) < 0)
10607 return -2;
10608 hwaddr_aton(addr, (unsigned char *) src);
10609
10610 pos = buf;
10611 *pos++ = 0x00;
10612 *pos++ = 0x01;
10613 *pos++ = 0x08;
10614 *pos++ = 0x00;
10615 *pos++ = 0x06;
10616 *pos++ = 0x04;
10617 *pos++ = 0x00;
10618 *pos++ = 0x02;
10619 memcpy(pos, src, ETH_ALEN);
10620 pos += ETH_ALEN;
10621 memcpy(pos, &taddr.sin_addr, 4);
10622 pos += 4;
10623 memcpy(pos, dst, ETH_ALEN);
10624 pos += ETH_ALEN;
10625 memcpy(pos, &taddr.sin_addr, 4);
10626 pos += 4;
10627
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010628 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010629 if (s < 0) {
10630 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
10631 "monitor socket");
10632 return 0;
10633 }
10634
10635 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
10636 if (res < 0) {
10637 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
10638 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053010639 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010640 return 0;
10641 }
10642
10643 close(s);
10644
10645 return 1;
10646}
10647
10648
10649static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
10650 struct sigma_conn *conn,
10651 struct sigma_cmd *cmd,
10652 const char *intf, const char *dest)
10653{
10654 char buf[100];
10655
10656 if (if_nametoindex("sigmadut") == 0) {
10657 snprintf(buf, sizeof(buf),
10658 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010659 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010660 if (system(buf) != 0 ||
10661 if_nametoindex("sigmadut") == 0) {
10662 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10663 "monitor interface with '%s'", buf);
10664 return -2;
10665 }
10666 }
10667
10668 if (system("ifconfig sigmadut up") != 0) {
10669 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10670 "monitor interface up");
10671 return -2;
10672 }
10673
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010674 return sta_inject_frame(dut, conn, intf, DLS_REQ, UNPROTECTED, dest, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010675}
10676
10677
10678static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10679 struct sigma_conn *conn,
10680 struct sigma_cmd *cmd)
10681{
10682 const char *intf = get_param(cmd, "Interface");
10683 const char *dest = get_param(cmd, "Dest");
10684 const char *type = get_param(cmd, "FrameName");
10685 const char *val;
10686 char buf[200], *pos, *end;
10687 int count, count2;
10688
10689 if (type == NULL)
10690 type = get_param(cmd, "Type");
10691
10692 if (intf == NULL || dest == NULL || type == NULL)
10693 return -1;
10694
10695 if (strcasecmp(type, "NeighAdv") == 0)
10696 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10697
10698 if (strcasecmp(type, "NeighSolicitReq") == 0)
10699 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10700
10701 if (strcasecmp(type, "ARPProbe") == 0)
10702 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10703
10704 if (strcasecmp(type, "ARPAnnounce") == 0)
10705 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10706
10707 if (strcasecmp(type, "ARPReply") == 0)
10708 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10709
10710 if (strcasecmp(type, "DLS-request") == 0 ||
10711 strcasecmp(type, "DLSrequest") == 0)
10712 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10713 dest);
10714
10715 if (strcasecmp(type, "ANQPQuery") != 0 &&
10716 strcasecmp(type, "Query") != 0) {
10717 send_resp(dut, conn, SIGMA_ERROR,
10718 "ErrorCode,Unsupported HS 2.0 send frame type");
10719 return 0;
10720 }
10721
10722 if (sta_scan_ap(dut, intf, dest) < 0) {
10723 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10724 "the requested AP");
10725 return 0;
10726 }
10727
10728 pos = buf;
10729 end = buf + sizeof(buf);
10730 count = 0;
10731 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10732
10733 val = get_param(cmd, "ANQP_CAP_LIST");
10734 if (val && atoi(val)) {
10735 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10736 count++;
10737 }
10738
10739 val = get_param(cmd, "VENUE_NAME");
10740 if (val && atoi(val)) {
10741 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10742 count++;
10743 }
10744
10745 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10746 if (val && atoi(val)) {
10747 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10748 count++;
10749 }
10750
10751 val = get_param(cmd, "ROAMING_CONS");
10752 if (val && atoi(val)) {
10753 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10754 count++;
10755 }
10756
10757 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10758 if (val && atoi(val)) {
10759 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10760 count++;
10761 }
10762
10763 val = get_param(cmd, "NAI_REALM_LIST");
10764 if (val && atoi(val)) {
10765 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10766 count++;
10767 }
10768
10769 val = get_param(cmd, "3GPP_INFO");
10770 if (val && atoi(val)) {
10771 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10772 count++;
10773 }
10774
10775 val = get_param(cmd, "DOMAIN_LIST");
10776 if (val && atoi(val)) {
10777 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10778 count++;
10779 }
10780
Jouni Malinen34cf9532018-04-29 19:26:33 +030010781 val = get_param(cmd, "Venue_URL");
10782 if (val && atoi(val)) {
10783 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10784 count++;
10785 }
10786
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010787 val = get_param(cmd, "Advice_Of_Charge");
10788 if (val && atoi(val)) {
10789 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10790 count++;
10791 }
10792
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010793 if (count && wpa_command(intf, buf)) {
10794 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10795 return 0;
10796 }
10797
10798 pos = buf;
10799 end = buf + sizeof(buf);
10800 count2 = 0;
10801 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
10802
10803 val = get_param(cmd, "HS_CAP_LIST");
10804 if (val && atoi(val)) {
10805 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
10806 count2++;
10807 }
10808
10809 val = get_param(cmd, "OPER_NAME");
10810 if (val && atoi(val)) {
10811 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
10812 count2++;
10813 }
10814
10815 val = get_param(cmd, "WAN_METRICS");
10816 if (!val)
10817 val = get_param(cmd, "WAN_MAT");
10818 if (!val)
10819 val = get_param(cmd, "WAN_MET");
10820 if (val && atoi(val)) {
10821 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10822 count2++;
10823 }
10824
10825 val = get_param(cmd, "CONNECTION_CAPABILITY");
10826 if (val && atoi(val)) {
10827 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10828 count2++;
10829 }
10830
10831 val = get_param(cmd, "OP_CLASS");
10832 if (val && atoi(val)) {
10833 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10834 count2++;
10835 }
10836
10837 val = get_param(cmd, "OSU_PROVIDER_LIST");
10838 if (val && atoi(val)) {
10839 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10840 count2++;
10841 }
10842
Jouni Malinenf67afec2018-04-29 19:24:58 +030010843 val = get_param(cmd, "OPER_ICON_METADATA");
10844 if (!val)
10845 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10846 if (val && atoi(val)) {
10847 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10848 count2++;
10849 }
10850
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010851 if (count && count2) {
10852 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10853 "second query");
10854 sleep(1);
10855 }
10856
10857 if (count2 && wpa_command(intf, buf)) {
10858 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10859 "failed");
10860 return 0;
10861 }
10862
10863 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10864 if (val) {
10865 if (count || count2) {
10866 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10867 "sending out second query");
10868 sleep(1);
10869 }
10870
10871 if (strcmp(val, "1") == 0)
10872 val = "mail.example.com";
10873 snprintf(buf, end - pos,
10874 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10875 dest, val);
10876 if (wpa_command(intf, buf)) {
10877 send_resp(dut, conn, SIGMA_ERROR,
10878 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10879 "failed");
10880 return 0;
10881 }
10882 }
10883
10884 val = get_param(cmd, "ICON_REQUEST");
10885 if (val) {
10886 if (count || count2) {
10887 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10888 "sending out second query");
10889 sleep(1);
10890 }
10891
10892 snprintf(buf, end - pos,
10893 "HS20_ICON_REQUEST %s %s", dest, val);
10894 if (wpa_command(intf, buf)) {
10895 send_resp(dut, conn, SIGMA_ERROR,
10896 "ErrorCode,HS20_ICON_REQUEST failed");
10897 return 0;
10898 }
10899 }
10900
10901 return 1;
10902}
10903
10904
10905static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10906 struct sigma_conn *conn,
10907 struct sigma_cmd *cmd)
10908{
10909 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010910 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010911 int chwidth, nss;
10912
10913 val = get_param(cmd, "framename");
10914 if (!val)
10915 return -1;
10916 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10917
10918 /* Command sequence to generate Op mode notification */
10919 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010920 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010921
10922 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010923 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010924
10925 /* Extract Channel width */
10926 val = get_param(cmd, "Channel_width");
10927 if (val) {
10928 switch (atoi(val)) {
10929 case 20:
10930 chwidth = 0;
10931 break;
10932 case 40:
10933 chwidth = 1;
10934 break;
10935 case 80:
10936 chwidth = 2;
10937 break;
10938 case 160:
10939 chwidth = 3;
10940 break;
10941 default:
10942 chwidth = 2;
10943 break;
10944 }
10945
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010946 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010947 }
10948
10949 /* Extract NSS */
10950 val = get_param(cmd, "NSS");
10951 if (val) {
10952 switch (atoi(val)) {
10953 case 1:
10954 nss = 1;
10955 break;
10956 case 2:
10957 nss = 3;
10958 break;
10959 case 3:
10960 nss = 7;
10961 break;
10962 default:
10963 /* We do not support NSS > 3 */
10964 nss = 3;
10965 break;
10966 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010967 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010968 }
10969
10970 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010971 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010972 }
10973
10974 return 1;
10975}
10976
10977
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010978static int wcn_sta_set_pmf_config(struct sigma_dut *dut, const char *intf,
10979 enum send_frame_protection protected)
10980{
10981#ifdef NL80211_SUPPORT
10982 struct nl_msg *msg;
10983 int ret = 0;
10984 struct nlattr *params;
10985 int ifindex;
10986
10987 ifindex = if_nametoindex(intf);
10988 if (ifindex == 0) {
10989 sigma_dut_print(dut, DUT_MSG_ERROR,
10990 "%s: Index for interface %s failed",
10991 __func__, intf);
10992 return -1;
10993 }
10994
10995 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
10996 NL80211_CMD_VENDOR)) ||
10997 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
10998 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10999 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
11000 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
11001 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
11002 nla_put_u8(msg,
11003 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PMF_PROTECTION,
11004 protected)) {
11005 sigma_dut_print(dut, DUT_MSG_ERROR,
11006 "%s: err in adding vendor_cmd and vendor_data",
11007 __func__);
11008 nlmsg_free(msg);
11009 return -1;
11010 }
11011 nla_nest_end(msg, params);
11012
11013 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
11014 if (ret) {
11015 sigma_dut_print(dut, DUT_MSG_ERROR,
11016 "%s: err in send_and_recv_msgs, ret=%d",
11017 __func__, ret);
11018 }
11019 return ret;
11020#else /* NL80211_SUPPORT */
11021 sigma_dut_print(dut, DUT_MSG_ERROR,
11022 "PMF config cannot be set without NL80211_SUPPORT defined");
11023 return -1;
11024#endif /* NL80211_SUPPORT */
11025}
11026
11027
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011028static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
11029 struct sigma_conn *conn,
11030 struct sigma_cmd *cmd)
11031{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011032 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011033 case DRIVER_ATHEROS:
11034 return ath_sta_send_frame_vht(dut, conn, cmd);
11035 default:
11036 send_resp(dut, conn, SIGMA_ERROR,
11037 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
11038 return 0;
11039 }
11040}
11041
11042
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011043static int wcn_sta_send_disassoc(struct sigma_dut *dut, const char *intf)
11044{
11045#ifdef NL80211_SUPPORT
11046 struct nl_msg *msg;
11047 int ret = 0;
11048 struct nlattr *params;
11049 int ifindex;
11050
11051 ifindex = if_nametoindex(intf);
11052 if (ifindex == 0) {
11053 sigma_dut_print(dut, DUT_MSG_ERROR,
11054 "%s: Index for interface %s failed",
11055 __func__, intf);
11056 return -1;
11057 }
11058
11059 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
11060 NL80211_CMD_VENDOR)) ||
11061 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
11062 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
11063 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
11064 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
11065 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
11066 nla_put_flag(msg,
11067 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISASSOC_TX)) {
11068 sigma_dut_print(dut, DUT_MSG_ERROR,
11069 "%s: err in adding vendor_cmd and vendor_data",
11070 __func__);
11071 nlmsg_free(msg);
11072 return -1;
11073 }
11074 nla_nest_end(msg, params);
11075
11076 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
11077 if (ret) {
11078 sigma_dut_print(dut, DUT_MSG_ERROR,
11079 "%s: err in send_and_recv_msgs, ret=%d",
11080 __func__, ret);
11081 }
11082 return ret;
11083#else /* NL80211_SUPPORT */
11084 sigma_dut_print(dut, DUT_MSG_ERROR,
11085 "Disassoc Tx cannot be done without NL80211_SUPPORT defined");
11086 return -1;
11087#endif /* NL80211_SUPPORT */
11088}
11089
11090
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011091static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
11092 struct sigma_cmd *cmd)
11093{
11094 const char *val;
11095 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011096 enum send_frame_protection protected;
11097 const char *pmf;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011098
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011099 if (!intf)
11100 return -1;
11101
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011102 val = get_param(cmd, "framename");
11103 if (!val)
11104 return -1;
11105 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
11106
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070011107 pmf = get_param(cmd, "PMFProtected");
11108 if (!pmf)
11109 pmf = get_param(cmd, "Protected");
11110 if (pmf) {
11111 if (strcasecmp(pmf, "Correct-key") == 0 ||
11112 strcasecmp(pmf, "CorrectKey") == 0) {
11113 protected = CORRECT_KEY;
11114 } else if (strcasecmp(pmf, "IncorrectKey") == 0) {
11115 protected = INCORRECT_KEY;
11116 } else if (strcasecmp(pmf, "Unprotected") == 0) {
11117 protected = UNPROTECTED;
11118 } else {
11119 send_resp(dut, conn, SIGMA_ERROR,
11120 "errorCode,Unsupported PMFProtected");
11121 return STATUS_SENT_ERROR;
11122 }
11123 sigma_dut_print(dut, DUT_MSG_DEBUG, "Config PMF protection %d",
11124 protected);
11125 wcn_sta_set_pmf_config(dut, intf, protected);
11126 }
11127
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011128 /* Command sequence to generate Op mode notification */
11129 if (val && strcasecmp(val, "action") == 0) {
11130 val = get_param(cmd, "PPDUTxType");
11131 if (val && strcasecmp(val, "TB") == 0) {
11132 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
11133 sigma_dut_print(dut, DUT_MSG_ERROR,
11134 "failed to send TB PPDU Tx cfg");
11135 send_resp(dut, conn, SIGMA_ERROR,
11136 "ErrorCode,set TB PPDU Tx cfg failed");
11137 return 0;
11138 }
11139 return 1;
11140 }
11141
11142 sigma_dut_print(dut, DUT_MSG_ERROR,
11143 "Action Tx type is not defined");
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011144
11145 return SUCCESS_SEND_STATUS;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011146 }
11147
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070011148 if (strcasecmp(val, "disassoc") == 0)
11149 wcn_sta_send_disassoc(dut, intf);
11150
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011151 return 1;
11152}
11153
11154
11155static int cmd_sta_send_frame_he(struct sigma_dut *dut,
11156 struct sigma_conn *conn,
11157 struct sigma_cmd *cmd)
11158{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011159 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011160 case DRIVER_WCN:
11161 return wcn_sta_send_frame_he(dut, conn, cmd);
11162 default:
11163 send_resp(dut, conn, SIGMA_ERROR,
11164 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
11165 return 0;
11166 }
11167}
11168
11169
Lior David0fe101e2017-03-09 16:09:50 +020011170#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011171
11172static int
11173wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
11174 const char *frame_name, const char *dest_mac)
11175{
11176 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
11177 const char *ssid = get_param(cmd, "ssid");
11178 const char *countstr = get_param(cmd, "count");
11179 const char *channelstr = get_param(cmd, "channel");
11180 const char *group_id = get_param(cmd, "groupid");
11181 const char *client_id = get_param(cmd, "clientmac");
11182 int count, channel, freq, i;
11183 const char *fname;
11184 char frame[1024], src_mac[20], group_id_attr[25],
11185 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
11186 const char *group_ssid;
11187 const int group_ssid_prefix_len = 9;
11188 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
11189 size_t framelen = sizeof(frame);
11190 struct template_frame_tag tags[2];
11191 size_t tags_total = ARRAY_SIZE(tags);
11192 int tag_index, len, dst_len;
11193
11194 if (!countstr || !channelstr) {
11195 sigma_dut_print(dut, DUT_MSG_ERROR,
11196 "Missing argument: count, channel");
11197 return -1;
11198 }
11199 if (isprobereq && !ssid) {
11200 sigma_dut_print(dut, DUT_MSG_ERROR,
11201 "Missing argument: ssid");
11202 return -1;
11203 }
11204 if (!isprobereq && (!group_id || !client_id)) {
11205 sigma_dut_print(dut, DUT_MSG_ERROR,
11206 "Missing argument: group_id, client_id");
11207 return -1;
11208 }
11209
11210 count = atoi(countstr);
11211 channel = atoi(channelstr);
11212 freq = channel_to_freq(dut, channel);
11213
11214 if (!freq) {
11215 sigma_dut_print(dut, DUT_MSG_ERROR,
11216 "invalid channel: %s", channelstr);
11217 return -1;
11218 }
11219
11220 if (isprobereq) {
11221 if (strcasecmp(ssid, "wildcard") == 0) {
11222 fname = "probe_req_wildcard.txt";
11223 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
11224 fname = "probe_req_P2P_Wildcard.txt";
11225 } else {
11226 sigma_dut_print(dut, DUT_MSG_ERROR,
11227 "invalid probe request type");
11228 return -1;
11229 }
11230 } else {
11231 fname = "P2P_device_discovery_req.txt";
11232 }
11233
11234 if (parse_template_frame_file(dut, fname, frame, &framelen,
11235 tags, &tags_total)) {
11236 sigma_dut_print(dut, DUT_MSG_ERROR,
11237 "invalid frame template: %s", fname);
11238 return -1;
11239 }
11240
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011241 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011242 src_mac, sizeof(src_mac)) < 0 ||
11243 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
11244 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
11245 return -1;
11246 /* Use wildcard BSSID, since we are in PBSS */
11247 memset(&hdr->addr3, 0xFF, ETH_ALEN);
11248
11249 if (!isprobereq) {
11250 tag_index = find_template_frame_tag(tags, tags_total, 1);
11251 if (tag_index < 0) {
11252 sigma_dut_print(dut, DUT_MSG_ERROR,
11253 "can't find device id attribute");
11254 return -1;
11255 }
11256 if (parse_mac_address(dut, client_id,
11257 (unsigned char *) client_mac)) {
11258 sigma_dut_print(dut, DUT_MSG_ERROR,
11259 "invalid client_id: %s", client_id);
11260 return -1;
11261 }
11262 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11263 framelen - tags[tag_index].offset,
11264 IEEE80211_P2P_ATTR_DEVICE_ID,
11265 client_mac, ETH_ALEN)) {
11266 sigma_dut_print(dut, DUT_MSG_ERROR,
11267 "fail to replace device id attribute");
11268 return -1;
11269 }
11270
11271 /*
11272 * group_id arg contains device MAC address followed by
11273 * space and SSID (DIRECT-somessid).
11274 * group id attribute contains device address (6 bytes)
11275 * followed by SSID prefix DIRECT-XX (9 bytes)
11276 */
11277 if (strlen(group_id) < sizeof(device_macstr)) {
11278 sigma_dut_print(dut, DUT_MSG_ERROR,
11279 "group_id arg too short");
11280 return -1;
11281 }
11282 memcpy(device_macstr, group_id, sizeof(device_macstr));
11283 device_macstr[sizeof(device_macstr) - 1] = '\0';
11284 if (parse_mac_address(dut, device_macstr,
11285 (unsigned char *) group_id_attr)) {
11286 sigma_dut_print(dut, DUT_MSG_ERROR,
11287 "fail to parse device address from group_id");
11288 return -1;
11289 }
11290 group_ssid = strchr(group_id, ' ');
11291 if (!group_ssid) {
11292 sigma_dut_print(dut, DUT_MSG_ERROR,
11293 "invalid group_id arg, no ssid");
11294 return -1;
11295 }
11296 group_ssid++;
11297 len = strlen(group_ssid);
11298 if (len < group_ssid_prefix_len) {
11299 sigma_dut_print(dut, DUT_MSG_ERROR,
11300 "group_id SSID too short");
11301 return -1;
11302 }
11303 dst_len = sizeof(group_id_attr) - ETH_ALEN;
11304 if (len > dst_len) {
11305 sigma_dut_print(dut, DUT_MSG_ERROR,
11306 "group_id SSID (%s) too long",
11307 group_ssid);
11308 return -1;
11309 }
11310
11311 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
11312 tag_index = find_template_frame_tag(tags, tags_total, 2);
11313 if (tag_index < 0) {
11314 sigma_dut_print(dut, DUT_MSG_ERROR,
11315 "can't find group id attribute");
11316 return -1;
11317 }
11318 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11319 framelen - tags[tag_index].offset,
11320 IEEE80211_P2P_ATTR_GROUP_ID,
11321 group_id_attr,
11322 sizeof(group_id_attr))) {
11323 sigma_dut_print(dut, DUT_MSG_ERROR,
11324 "fail to replace group id attribute");
11325 return -1;
11326 }
11327 }
11328
11329 for (i = 0; i < count; i++) {
11330 if (wil6210_transmit_frame(dut, freq,
11331 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
11332 frame, framelen)) {
11333 sigma_dut_print(dut, DUT_MSG_ERROR,
11334 "fail to transmit probe request frame");
11335 return -1;
11336 }
11337 }
11338
11339 return 0;
11340}
11341
11342
Lior David0fe101e2017-03-09 16:09:50 +020011343int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
11344 struct sigma_cmd *cmd)
11345{
11346 const char *frame_name = get_param(cmd, "framename");
11347 const char *mac = get_param(cmd, "dest_mac");
11348
11349 if (!frame_name || !mac) {
11350 sigma_dut_print(dut, DUT_MSG_ERROR,
11351 "framename and dest_mac must be provided");
11352 return -1;
11353 }
11354
11355 if (strcasecmp(frame_name, "brp") == 0) {
11356 const char *l_rx = get_param(cmd, "L-RX");
11357 int l_rx_i;
11358
11359 if (!l_rx) {
11360 sigma_dut_print(dut, DUT_MSG_ERROR,
11361 "L-RX must be provided");
11362 return -1;
11363 }
11364 l_rx_i = atoi(l_rx);
11365
11366 sigma_dut_print(dut, DUT_MSG_INFO,
11367 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
11368 mac, l_rx);
11369 if (l_rx_i != 16) {
11370 sigma_dut_print(dut, DUT_MSG_ERROR,
11371 "unsupported L-RX: %s", l_rx);
11372 return -1;
11373 }
11374
11375 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
11376 return -1;
11377 } else if (strcasecmp(frame_name, "ssw") == 0) {
11378 sigma_dut_print(dut, DUT_MSG_INFO,
11379 "dev_send_frame: SLS, dest_mac %s", mac);
11380 if (wil6210_send_sls(dut, mac))
11381 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011382 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
11383 (strcasecmp(frame_name, "devdiscreq") == 0)) {
11384 sigma_dut_print(dut, DUT_MSG_INFO,
11385 "dev_send_frame: %s, dest_mac %s", frame_name,
11386 mac);
11387 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
11388 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020011389 } else {
11390 sigma_dut_print(dut, DUT_MSG_ERROR,
11391 "unsupported frame type: %s", frame_name);
11392 return -1;
11393 }
11394
11395 return 1;
11396}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011397
Lior David0fe101e2017-03-09 16:09:50 +020011398#endif /* __linux__ */
11399
11400
11401static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
11402 struct sigma_conn *conn,
11403 struct sigma_cmd *cmd)
11404{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011405 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020011406#ifdef __linux__
11407 case DRIVER_WIL6210:
11408 return wil6210_send_frame_60g(dut, conn, cmd);
11409#endif /* __linux__ */
11410 default:
11411 send_resp(dut, conn, SIGMA_ERROR,
11412 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
11413 return 0;
11414 }
11415}
11416
11417
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011418static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
11419 const char *intf, struct sigma_cmd *cmd)
11420{
11421 const char *val, *addr;
11422 char buf[100];
11423
11424 addr = get_param(cmd, "DestMac");
11425 if (!addr) {
11426 send_resp(dut, conn, SIGMA_INVALID,
11427 "ErrorCode,AP MAC address is missing");
11428 return 0;
11429 }
11430
11431 val = get_param(cmd, "ANQPQuery_ID");
11432 if (!val) {
11433 send_resp(dut, conn, SIGMA_INVALID,
11434 "ErrorCode,Missing ANQPQuery_ID");
11435 return 0;
11436 }
11437
11438 if (strcasecmp(val, "NeighborReportReq") == 0) {
11439 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
11440 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
11441 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
11442 } else {
11443 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
11444 val);
11445 send_resp(dut, conn, SIGMA_INVALID,
11446 "ErrorCode,Invalid ANQPQuery_ID");
11447 return 0;
11448 }
11449
Ashwini Patild174f2c2017-04-13 16:49:46 +053011450 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
11451 * (Address3 = Wildcard BSSID when sent to not-associated AP;
11452 * if associated, AP BSSID).
11453 */
11454 if (wpa_command(intf, "SET gas_address3 1") < 0) {
11455 send_resp(dut, conn, SIGMA_ERROR,
11456 "ErrorCode,Failed to set gas_address3");
11457 return 0;
11458 }
11459
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011460 if (wpa_command(intf, buf) < 0) {
11461 send_resp(dut, conn, SIGMA_ERROR,
11462 "ErrorCode,Failed to send ANQP query");
11463 return 0;
11464 }
11465
11466 return 1;
11467}
11468
11469
11470static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
11471 struct sigma_conn *conn,
11472 const char *intf,
11473 struct sigma_cmd *cmd)
11474{
11475 const char *val = get_param(cmd, "FrameName");
11476
11477 if (val && strcasecmp(val, "ANQPQuery") == 0)
11478 return mbo_send_anqp_query(dut, conn, intf, cmd);
11479
11480 return 2;
11481}
11482
11483
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011484static enum sigma_cmd_result cmd_sta_send_frame_wpa3(struct sigma_dut *dut,
11485 struct sigma_conn *conn,
11486 const char *intf,
11487 struct sigma_cmd *cmd)
11488{
11489 const char *val = get_param(cmd, "framename");
11490
11491 if (!val)
11492 return INVALID_SEND_STATUS;
11493
11494 if (strcasecmp(val, "SAQueryReq") == 0) {
11495 val = get_param(cmd, "OCIChannel");
11496
11497 if (!val) {
11498 send_resp(dut, conn, SIGMA_ERROR,
11499 "errorCode,OCIChannel not present");
11500 return STATUS_SENT_ERROR;
11501 }
11502
11503 dut->saquery_oci_freq = channel_to_freq(dut, atoi(val));
11504 if (!dut->saquery_oci_freq) {
11505 send_resp(dut, conn, SIGMA_ERROR,
11506 "errorCode,Invalid OCIChannel number");
11507 return STATUS_SENT_ERROR;
11508 }
11509
11510 return sta_inject_frame(dut, conn, intf, SAQUERY, CORRECT_KEY,
11511 NULL, 0);
11512 }
11513
11514 if (strcasecmp(val, "reassocreq") == 0)
11515 return sta_inject_frame(dut, conn, intf, REASSOCREQ,
11516 CORRECT_KEY, NULL, 0);
11517
Veerendranath9f81dfb2020-08-10 01:21:29 -070011518 if (strcasecmp(val, "ANQPQuery") == 0) {
11519 char buf[50];
11520 const char *dest = get_param(cmd, "DestMac");
11521 const char *chan = get_param(cmd, "channel");
11522 int len, freq;
11523
11524 freq = chan ? channel_to_freq(dut, atoi(chan)) : 0;
11525 if (!dest || !freq)
11526 return INVALID_SEND_STATUS;
11527
11528 len = snprintf(buf, sizeof(buf), "ANQP_GET %s freq=%d 257",
11529 dest, freq);
11530 if (len < 0 || len >= sizeof(buf)) {
11531 sigma_dut_print(dut, DUT_MSG_ERROR,
11532 "Failed to allocate buf");
11533 return ERROR_SEND_STATUS;
11534 }
11535
11536 if (wpa_command(intf, buf) != 0) {
11537 send_resp(dut, conn, SIGMA_ERROR,
11538 "ErrorCode,Failed to send ANQP Query frame");
11539 return STATUS_SENT_ERROR;
11540 }
11541
11542 sigma_dut_print(dut, DUT_MSG_DEBUG,
11543 "ANQP Query sent: %s", buf);
11544
11545 return SUCCESS_SEND_STATUS;
11546 }
11547
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011548 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported framename");
11549 return STATUS_SENT_ERROR;
11550}
11551
11552
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011553static enum sigma_cmd_result
11554cmd_sta_send_frame_mscs(struct sigma_dut *dut, struct sigma_conn *conn,
11555 const char *intf, struct sigma_cmd *cmd)
11556{
11557 char buf[128], *pos;
11558 const char *val, *classifier_type = "04", *type;
11559 int len, rem_len;
11560 u8 up_bitmap;
11561
11562 val = get_param(cmd, "FrameName");
11563 type = get_param(cmd, "Request_Type");
11564 if (!val || !type || strcasecmp(val, "MSCSReq") != 0) {
11565 sigma_dut_print(dut, DUT_MSG_ERROR,
11566 "%s: frame name or type not valid", __func__);
11567 return INVALID_SEND_STATUS;
11568 }
11569
11570 rem_len = sizeof(buf);
11571 pos = buf;
11572 if (strcasecmp(type, "add") == 0) {
11573 len = snprintf(pos, rem_len, "MSCS add");
11574 } else if (strcasecmp(type, "update") == 0) {
11575 len = snprintf(pos, rem_len, "MSCS change");
11576 } else if (strcasecmp(type, "remove") == 0) {
11577 if (wpa_command(intf, "MSCS remove") != 0) {
11578 send_resp(dut, conn, SIGMA_ERROR,
11579 "ErrorCode,Failed to send MSCS frame req");
11580 return STATUS_SENT_ERROR;
11581 }
11582 return SUCCESS_SEND_STATUS;
11583 } else {
11584 sigma_dut_print(dut, DUT_MSG_ERROR,
11585 "%s: request type invalid", __func__);
11586 return INVALID_SEND_STATUS;
11587 }
11588
11589 if (len < 0 || len >= rem_len)
11590 goto fail;
11591
11592 pos += len;
11593 rem_len -= len;
11594
11595 val = get_param(cmd, "User_Priority_Bitmap");
11596 if (!val) {
11597 sigma_dut_print(dut, DUT_MSG_ERROR,
11598 "%s: user priority bitmap empty", __func__);
11599 return INVALID_SEND_STATUS;
11600 }
11601
11602 switch (atoi(val)) {
11603 case 0:
11604 up_bitmap = 0x00;
11605 break;
11606 case 1:
11607 up_bitmap = 0xF0;
11608 break;
11609 case 2:
11610 up_bitmap = 0xF6;
11611 break;
11612 default:
11613 sigma_dut_print(dut, DUT_MSG_ERROR,
11614 "%s: Unknown User_Priority_Bitmap value %d",
11615 __func__, atoi(val));
11616 return INVALID_SEND_STATUS;
11617 }
11618
11619 len = snprintf(pos, rem_len, " up_bitmap=%02x", up_bitmap);
11620 if (len < 0 || len >= rem_len)
11621 goto fail;
11622
11623 pos += len;
11624 rem_len -= len;
11625
11626 val = get_param(cmd, "User_Priority_Limit");
11627 if (!val) {
11628 sigma_dut_print(dut, DUT_MSG_ERROR,
11629 "%s: invalid user priority limit", __func__);
11630 return INVALID_SEND_STATUS;
11631 }
11632
11633 len = snprintf(pos, rem_len, " up_limit=%s", val);
11634 if (len < 0 || len >= rem_len)
11635 goto fail;
11636
11637 pos += len;
11638 rem_len -= len;
11639
11640 val = get_param(cmd, "Stream_Timeout");
11641 if (!val)
11642 val = get_param(cmd, "Stream_Timtout");
11643 if (!val) {
11644 sigma_dut_print(dut, DUT_MSG_ERROR,
11645 "%s: invalid stream timeout", __func__);
11646 return INVALID_SEND_STATUS;
11647 }
11648
11649 len = snprintf(pos, rem_len, " stream_timeout=%s", val);
11650 if (len < 0 || len >= rem_len)
11651 goto fail;
11652
11653 pos += len;
11654 rem_len -= len;
11655
11656 val = get_param(cmd, "TCLAS_Mask");
11657 if (!val) {
11658 sigma_dut_print(dut, DUT_MSG_ERROR,
11659 "%s: invalid tclas mask", __func__);
11660 return INVALID_SEND_STATUS;
11661 }
11662
11663 len = snprintf(pos, rem_len, " frame_classifier=%s%lx%032x",
11664 classifier_type, strtol(val, NULL, 2), 0);
11665 if (len < 0 || len >= rem_len)
11666 goto fail;
11667
11668 if (wpa_command(intf, buf) != 0) {
11669 send_resp(dut, conn, SIGMA_ERROR,
11670 "ErrorCode,Failed to send MSCS frame req");
11671 return STATUS_SENT_ERROR;
11672 }
11673
11674 sigma_dut_print(dut, DUT_MSG_DEBUG,
11675 "MSCS frame request sent: %s", buf);
11676
11677 return SUCCESS_SEND_STATUS;
11678fail:
11679 sigma_dut_print(dut, DUT_MSG_ERROR,
11680 "Failed to create MSCS frame req");
11681 return ERROR_SEND_STATUS;
11682}
11683
11684
Jouni Malinenf7222712019-06-13 01:50:21 +030011685enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
11686 struct sigma_conn *conn,
11687 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011688{
11689 const char *intf = get_param(cmd, "Interface");
11690 const char *val;
11691 enum send_frame_type frame;
11692 enum send_frame_protection protected;
11693 char buf[100];
11694 unsigned char addr[ETH_ALEN];
11695 int res;
11696
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011697 if (!intf)
11698 return -1;
11699
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011700 val = get_param(cmd, "program");
11701 if (val == NULL)
11702 val = get_param(cmd, "frame");
11703 if (val && strcasecmp(val, "TDLS") == 0)
11704 return cmd_sta_send_frame_tdls(dut, conn, cmd);
11705 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011706 strcasecmp(val, "HS2-R2") == 0 ||
11707 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011708 return cmd_sta_send_frame_hs2(dut, conn, cmd);
11709 if (val && strcasecmp(val, "VHT") == 0)
11710 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011711 if (val && strcasecmp(val, "HE") == 0)
11712 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070011713 if (val && strcasecmp(val, "LOC") == 0)
11714 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020011715 if (val && strcasecmp(val, "60GHz") == 0)
11716 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011717 if (val && strcasecmp(val, "MBO") == 0) {
11718 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
11719 if (res != 2)
11720 return res;
11721 }
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011722 if (val && strcasecmp(val, "WPA3") == 0)
11723 return cmd_sta_send_frame_wpa3(dut, conn, intf, cmd);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011724 if (val && strcasecmp(val, "QM") == 0)
11725 return cmd_sta_send_frame_mscs(dut, conn, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011726
11727 val = get_param(cmd, "TD_DISC");
11728 if (val) {
11729 if (hwaddr_aton(val, addr) < 0)
11730 return -1;
11731 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
11732 if (wpa_command(intf, buf) < 0) {
11733 send_resp(dut, conn, SIGMA_ERROR,
11734 "ErrorCode,Failed to send TDLS discovery");
11735 return 0;
11736 }
11737 return 1;
11738 }
11739
11740 val = get_param(cmd, "TD_Setup");
11741 if (val) {
11742 if (hwaddr_aton(val, addr) < 0)
11743 return -1;
11744 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
11745 if (wpa_command(intf, buf) < 0) {
11746 send_resp(dut, conn, SIGMA_ERROR,
11747 "ErrorCode,Failed to start TDLS setup");
11748 return 0;
11749 }
11750 return 1;
11751 }
11752
11753 val = get_param(cmd, "TD_TearDown");
11754 if (val) {
11755 if (hwaddr_aton(val, addr) < 0)
11756 return -1;
11757 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
11758 if (wpa_command(intf, buf) < 0) {
11759 send_resp(dut, conn, SIGMA_ERROR,
11760 "ErrorCode,Failed to tear down TDLS link");
11761 return 0;
11762 }
11763 return 1;
11764 }
11765
11766 val = get_param(cmd, "TD_ChannelSwitch");
11767 if (val) {
11768 /* TODO */
11769 send_resp(dut, conn, SIGMA_ERROR,
11770 "ErrorCode,TD_ChannelSwitch not yet supported");
11771 return 0;
11772 }
11773
11774 val = get_param(cmd, "TD_NF");
11775 if (val) {
11776 /* TODO */
11777 send_resp(dut, conn, SIGMA_ERROR,
11778 "ErrorCode,TD_NF not yet supported");
11779 return 0;
11780 }
11781
11782 val = get_param(cmd, "PMFFrameType");
11783 if (val == NULL)
11784 val = get_param(cmd, "FrameName");
11785 if (val == NULL)
11786 val = get_param(cmd, "Type");
11787 if (val == NULL)
11788 return -1;
11789 if (strcasecmp(val, "disassoc") == 0)
11790 frame = DISASSOC;
11791 else if (strcasecmp(val, "deauth") == 0)
11792 frame = DEAUTH;
11793 else if (strcasecmp(val, "saquery") == 0)
11794 frame = SAQUERY;
11795 else if (strcasecmp(val, "auth") == 0)
11796 frame = AUTH;
11797 else if (strcasecmp(val, "assocreq") == 0)
11798 frame = ASSOCREQ;
11799 else if (strcasecmp(val, "reassocreq") == 0)
11800 frame = REASSOCREQ;
11801 else if (strcasecmp(val, "neigreq") == 0) {
11802 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
11803
11804 val = get_param(cmd, "ssid");
11805 if (val == NULL)
11806 return -1;
11807
11808 res = send_neighbor_request(dut, intf, val);
11809 if (res) {
11810 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11811 "Failed to send neighbor report request");
11812 return 0;
11813 }
11814
11815 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053011816 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
11817 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011818 sigma_dut_print(dut, DUT_MSG_DEBUG,
11819 "Got Transition Management Query");
11820
Ashwini Patil5acd7382017-04-13 15:55:04 +053011821 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011822 if (res) {
11823 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11824 "Failed to send Transition Management Query");
11825 return 0;
11826 }
11827
11828 return 1;
11829 } else {
11830 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11831 "PMFFrameType");
11832 return 0;
11833 }
11834
11835 val = get_param(cmd, "PMFProtected");
11836 if (val == NULL)
11837 val = get_param(cmd, "Protected");
11838 if (val == NULL)
11839 return -1;
11840 if (strcasecmp(val, "Correct-key") == 0 ||
11841 strcasecmp(val, "CorrectKey") == 0)
11842 protected = CORRECT_KEY;
11843 else if (strcasecmp(val, "IncorrectKey") == 0)
11844 protected = INCORRECT_KEY;
11845 else if (strcasecmp(val, "Unprotected") == 0)
11846 protected = UNPROTECTED;
11847 else {
11848 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11849 "PMFProtected");
11850 return 0;
11851 }
11852
11853 if (protected != UNPROTECTED &&
11854 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
11855 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
11856 "PMFProtected for auth/assocreq/reassocreq");
11857 return 0;
11858 }
11859
11860 if (if_nametoindex("sigmadut") == 0) {
11861 snprintf(buf, sizeof(buf),
11862 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011863 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011864 if (system(buf) != 0 ||
11865 if_nametoindex("sigmadut") == 0) {
11866 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11867 "monitor interface with '%s'", buf);
11868 return -2;
11869 }
11870 }
11871
11872 if (system("ifconfig sigmadut up") != 0) {
11873 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11874 "monitor interface up");
11875 return -2;
11876 }
11877
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011878 return sta_inject_frame(dut, conn, intf, frame, protected, NULL, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011879}
11880
11881
11882static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
11883 struct sigma_conn *conn,
11884 struct sigma_cmd *cmd,
11885 const char *ifname)
11886{
11887 char buf[200];
11888 const char *val;
11889
11890 val = get_param(cmd, "ClearARP");
11891 if (val && atoi(val) == 1) {
11892 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
11893 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11894 if (system(buf) != 0) {
11895 send_resp(dut, conn, SIGMA_ERROR,
11896 "errorCode,Failed to clear ARP cache");
11897 return 0;
11898 }
11899 }
11900
11901 return 1;
11902}
11903
11904
11905int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
11906 struct sigma_cmd *cmd)
11907{
11908 const char *intf = get_param(cmd, "Interface");
11909 const char *val;
11910
11911 if (intf == NULL)
11912 return -1;
11913
11914 val = get_param(cmd, "program");
11915 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011916 strcasecmp(val, "HS2-R2") == 0 ||
11917 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011918 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
11919
11920 return -1;
11921}
11922
11923
Jouni Malinenf7222712019-06-13 01:50:21 +030011924static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
11925 struct sigma_conn *conn,
11926 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011927{
11928 const char *intf = get_param(cmd, "Interface");
11929 const char *mac = get_param(cmd, "MAC");
11930
11931 if (intf == NULL || mac == NULL)
11932 return -1;
11933
11934 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
11935 "interface %s to %s", intf, mac);
11936
11937 if (dut->set_macaddr) {
11938 char buf[128];
11939 int res;
11940 if (strcasecmp(mac, "default") == 0) {
11941 res = snprintf(buf, sizeof(buf), "%s",
11942 dut->set_macaddr);
11943 dut->tmp_mac_addr = 0;
11944 } else {
11945 res = snprintf(buf, sizeof(buf), "%s %s",
11946 dut->set_macaddr, mac);
11947 dut->tmp_mac_addr = 1;
11948 }
11949 if (res < 0 || res >= (int) sizeof(buf))
11950 return -1;
11951 if (system(buf) != 0) {
11952 send_resp(dut, conn, SIGMA_ERROR,
11953 "errorCode,Failed to set MAC "
11954 "address");
11955 return 0;
11956 }
11957 return 1;
11958 }
11959
11960 if (strcasecmp(mac, "default") == 0)
11961 return 1;
11962
11963 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11964 "command");
11965 return 0;
11966}
11967
11968
11969static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
11970 struct sigma_conn *conn, const char *intf,
11971 int val)
11972{
11973 char buf[200];
11974 int res;
11975
11976 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
11977 intf, val);
11978 if (res < 0 || res >= (int) sizeof(buf))
11979 return -1;
11980 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11981 if (system(buf) != 0) {
11982 send_resp(dut, conn, SIGMA_ERROR,
11983 "errorCode,Failed to configure offchannel mode");
11984 return 0;
11985 }
11986
11987 return 1;
11988}
11989
11990
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011991static int off_chan_val(enum sec_ch_offset off)
11992{
11993 switch (off) {
11994 case SEC_CH_NO:
11995 return 0;
11996 case SEC_CH_40ABOVE:
11997 return 40;
11998 case SEC_CH_40BELOW:
11999 return -40;
12000 }
12001
12002 return 0;
12003}
12004
12005
12006static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
12007 const char *intf, int off_ch_num,
12008 enum sec_ch_offset sec)
12009{
12010 char buf[200];
12011 int res;
12012
12013 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
12014 intf, off_ch_num);
12015 if (res < 0 || res >= (int) sizeof(buf))
12016 return -1;
12017 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12018 if (system(buf) != 0) {
12019 send_resp(dut, conn, SIGMA_ERROR,
12020 "errorCode,Failed to set offchan");
12021 return 0;
12022 }
12023
12024 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
12025 intf, off_chan_val(sec));
12026 if (res < 0 || res >= (int) sizeof(buf))
12027 return -1;
12028 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12029 if (system(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_offset(struct sigma_dut *dut,
12040 struct sigma_conn *conn,
12041 const char *intf, int off_ch_num,
12042 enum sec_ch_offset sec)
12043{
12044 char buf[200];
12045 int res;
12046
12047 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
12048 off_ch_num);
12049 if (res < 0 || res >= (int) sizeof(buf))
12050 return -1;
12051 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12052
12053 if (wpa_command(intf, buf) < 0) {
12054 send_resp(dut, conn, SIGMA_ERROR,
12055 "ErrorCode,Failed to set offchan");
12056 return 0;
12057 }
12058 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
12059 off_chan_val(sec));
12060 if (res < 0 || res >= (int) sizeof(buf))
12061 return -1;
12062
12063 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12064
12065 if (wpa_command(intf, buf) < 0) {
12066 send_resp(dut, conn, SIGMA_ERROR,
12067 "ErrorCode,Failed to set sec chan offset");
12068 return 0;
12069 }
12070
12071 return 1;
12072}
12073
12074
12075static int tdls_set_offchannel_mode(struct sigma_dut *dut,
12076 struct sigma_conn *conn,
12077 const char *intf, int val)
12078{
12079 char buf[200];
12080 int res;
12081
12082 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
12083 val);
12084 if (res < 0 || res >= (int) sizeof(buf))
12085 return -1;
12086 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
12087
12088 if (wpa_command(intf, buf) < 0) {
12089 send_resp(dut, conn, SIGMA_ERROR,
12090 "ErrorCode,Failed to configure offchannel mode");
12091 return 0;
12092 }
12093
12094 return 1;
12095}
12096
12097
12098static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
12099 struct sigma_conn *conn,
12100 struct sigma_cmd *cmd)
12101{
12102 const char *val;
12103 enum {
12104 CHSM_NOT_SET,
12105 CHSM_ENABLE,
12106 CHSM_DISABLE,
12107 CHSM_REJREQ,
12108 CHSM_UNSOLRESP
12109 } chsm = CHSM_NOT_SET;
12110 int off_ch_num = -1;
12111 enum sec_ch_offset sec_ch = SEC_CH_NO;
12112 int res;
12113
12114 val = get_param(cmd, "Uapsd");
12115 if (val) {
12116 char buf[100];
12117 if (strcasecmp(val, "Enable") == 0)
12118 snprintf(buf, sizeof(buf), "SET ps 99");
12119 else if (strcasecmp(val, "Disable") == 0)
12120 snprintf(buf, sizeof(buf), "SET ps 98");
12121 else {
12122 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
12123 "Unsupported uapsd parameter value");
12124 return 0;
12125 }
12126 if (wpa_command(intf, buf)) {
12127 send_resp(dut, conn, SIGMA_ERROR,
12128 "ErrorCode,Failed to change U-APSD "
12129 "powersave mode");
12130 return 0;
12131 }
12132 }
12133
12134 val = get_param(cmd, "TPKTIMER");
12135 if (val && strcasecmp(val, "DISABLE") == 0) {
12136 if (wpa_command(intf, "SET tdls_testing 0x100")) {
12137 send_resp(dut, conn, SIGMA_ERROR,
12138 "ErrorCode,Failed to enable no TPK "
12139 "expiration test mode");
12140 return 0;
12141 }
12142 dut->no_tpk_expiration = 1;
12143 }
12144
12145 val = get_param(cmd, "ChSwitchMode");
12146 if (val) {
12147 if (strcasecmp(val, "Enable") == 0 ||
12148 strcasecmp(val, "Initiate") == 0)
12149 chsm = CHSM_ENABLE;
12150 else if (strcasecmp(val, "Disable") == 0 ||
12151 strcasecmp(val, "passive") == 0)
12152 chsm = CHSM_DISABLE;
12153 else if (strcasecmp(val, "RejReq") == 0)
12154 chsm = CHSM_REJREQ;
12155 else if (strcasecmp(val, "UnSolResp") == 0)
12156 chsm = CHSM_UNSOLRESP;
12157 else {
12158 send_resp(dut, conn, SIGMA_ERROR,
12159 "ErrorCode,Unknown ChSwitchMode value");
12160 return 0;
12161 }
12162 }
12163
12164 val = get_param(cmd, "OffChNum");
12165 if (val) {
12166 off_ch_num = atoi(val);
12167 if (off_ch_num == 0) {
12168 send_resp(dut, conn, SIGMA_ERROR,
12169 "ErrorCode,Invalid OffChNum");
12170 return 0;
12171 }
12172 }
12173
12174 val = get_param(cmd, "SecChOffset");
12175 if (val) {
12176 if (strcmp(val, "20") == 0)
12177 sec_ch = SEC_CH_NO;
12178 else if (strcasecmp(val, "40above") == 0)
12179 sec_ch = SEC_CH_40ABOVE;
12180 else if (strcasecmp(val, "40below") == 0)
12181 sec_ch = SEC_CH_40BELOW;
12182 else {
12183 send_resp(dut, conn, SIGMA_ERROR,
12184 "ErrorCode,Unknown SecChOffset value");
12185 return 0;
12186 }
12187 }
12188
12189 if (chsm == CHSM_NOT_SET) {
12190 /* no offchannel changes requested */
12191 return 1;
12192 }
12193
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012194 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
12195 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012196 send_resp(dut, conn, SIGMA_ERROR,
12197 "ErrorCode,Unknown interface");
12198 return 0;
12199 }
12200
12201 switch (chsm) {
12202 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030012203 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012204 break;
12205 case CHSM_ENABLE:
12206 if (off_ch_num < 0) {
12207 send_resp(dut, conn, SIGMA_ERROR,
12208 "ErrorCode,Missing OffChNum argument");
12209 return 0;
12210 }
12211 if (wifi_chip_type == DRIVER_WCN) {
12212 res = tdls_set_offchannel_offset(dut, conn, intf,
12213 off_ch_num, sec_ch);
12214 } else {
12215 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
12216 sec_ch);
12217 }
12218 if (res != 1)
12219 return res;
12220 if (wifi_chip_type == DRIVER_WCN)
12221 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
12222 else
12223 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
12224 break;
12225 case CHSM_DISABLE:
12226 if (wifi_chip_type == DRIVER_WCN)
12227 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
12228 else
12229 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
12230 break;
12231 case CHSM_REJREQ:
12232 if (wifi_chip_type == DRIVER_WCN)
12233 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
12234 else
12235 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
12236 break;
12237 case CHSM_UNSOLRESP:
12238 if (off_ch_num < 0) {
12239 send_resp(dut, conn, SIGMA_ERROR,
12240 "ErrorCode,Missing OffChNum argument");
12241 return 0;
12242 }
12243 if (wifi_chip_type == DRIVER_WCN) {
12244 res = tdls_set_offchannel_offset(dut, conn, intf,
12245 off_ch_num, sec_ch);
12246 } else {
12247 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
12248 sec_ch);
12249 }
12250 if (res != 1)
12251 return res;
12252 if (wifi_chip_type == DRIVER_WCN)
12253 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
12254 else
12255 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
12256 break;
12257 }
12258
12259 return res;
12260}
12261
12262
12263static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
12264 struct sigma_conn *conn,
12265 struct sigma_cmd *cmd)
12266{
12267 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053012268 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012269
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070012270 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080012271
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012272 val = get_param(cmd, "nss_mcs_opt");
12273 if (val) {
12274 /* String (nss_operating_mode; mcs_operating_mode) */
12275 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012276 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012277
12278 token = strdup(val);
12279 if (!token)
12280 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012281 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053012282 if (!result) {
12283 sigma_dut_print(dut, DUT_MSG_ERROR,
12284 "VHT NSS not specified");
12285 goto failed;
12286 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012287 if (strcasecmp(result, "def") != 0) {
12288 nss = atoi(result);
12289 if (nss == 4)
12290 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012291 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012292 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012293
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012294 }
12295
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012296 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053012297 if (!result) {
12298 sigma_dut_print(dut, DUT_MSG_ERROR,
12299 "VHT MCS not specified");
12300 goto failed;
12301 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012302 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012303 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012304 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012305 } else {
12306 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012307 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012308 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012309 }
12310 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012311 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012312 }
12313
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053012314 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012315 return 1;
12316failed:
12317 free(token);
12318 return 0;
12319}
12320
12321
12322static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
12323 struct sigma_conn *conn,
12324 struct sigma_cmd *cmd)
12325{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012326 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012327 case DRIVER_ATHEROS:
12328 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
12329 default:
12330 send_resp(dut, conn, SIGMA_ERROR,
12331 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
12332 return 0;
12333 }
12334}
12335
12336
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012337static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12338 struct sigma_conn *conn,
12339 struct sigma_cmd *cmd)
12340{
12341 const char *val;
12342 char *token = NULL, *result;
12343 char buf[60];
12344
12345 val = get_param(cmd, "nss_mcs_opt");
12346 if (val) {
12347 /* String (nss_operating_mode; mcs_operating_mode) */
12348 int nss, mcs, ratecode;
12349 char *saveptr;
12350
12351 token = strdup(val);
12352 if (!token)
12353 return -2;
12354
12355 result = strtok_r(token, ";", &saveptr);
12356 if (!result) {
12357 sigma_dut_print(dut, DUT_MSG_ERROR,
12358 "HE NSS not specified");
12359 goto failed;
12360 }
12361 nss = 1;
12362 if (strcasecmp(result, "def") != 0)
12363 nss = atoi(result);
12364
12365 result = strtok_r(NULL, ";", &saveptr);
12366 if (!result) {
12367 sigma_dut_print(dut, DUT_MSG_ERROR,
12368 "HE MCS not specified");
12369 goto failed;
12370 }
12371 mcs = 7;
12372 if (strcasecmp(result, "def") != 0)
12373 mcs = atoi(result);
12374
Arif Hussain557bf412018-05-25 17:29:36 -070012375 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012376 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070012377 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012378 } else if (nss > 2) {
12379 sigma_dut_print(dut, DUT_MSG_ERROR,
12380 "HE NSS %d not supported", nss);
12381 goto failed;
12382 }
12383
Arif Hussain557bf412018-05-25 17:29:36 -070012384 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
12385 if (system(buf) != 0) {
12386 sigma_dut_print(dut, DUT_MSG_ERROR,
12387 "nss_mcs_opt: iwpriv %s nss %d failed",
12388 intf, nss);
12389 goto failed;
12390 }
Arif Hussainac6c5112018-05-25 17:34:00 -070012391 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070012392
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012393 /* Add the MCS to the ratecode */
12394 if (mcs >= 0 && mcs <= 11) {
12395 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070012396#ifdef NL80211_SUPPORT
12397 if (dut->device_type == STA_testbed) {
12398 enum he_mcs_config mcs_config;
12399 int ret;
12400
12401 if (mcs <= 7)
12402 mcs_config = HE_80_MCS0_7;
12403 else if (mcs <= 9)
12404 mcs_config = HE_80_MCS0_9;
12405 else
12406 mcs_config = HE_80_MCS0_11;
12407 ret = sta_set_he_mcs(dut, intf, mcs_config);
12408 if (ret) {
12409 sigma_dut_print(dut, DUT_MSG_ERROR,
12410 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
12411 mcs, mcs_config, ret);
12412 goto failed;
12413 }
12414 }
12415#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012416 } else {
12417 sigma_dut_print(dut, DUT_MSG_ERROR,
12418 "HE MCS %d not supported", mcs);
12419 goto failed;
12420 }
12421 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
12422 intf, ratecode);
12423 if (system(buf) != 0) {
12424 sigma_dut_print(dut, DUT_MSG_ERROR,
12425 "iwpriv setting of 11ax rates failed");
12426 goto failed;
12427 }
12428 free(token);
12429 }
12430
12431 val = get_param(cmd, "GI");
12432 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012433 int fix_rate_sgi;
12434
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012435 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012436 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012437 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012438 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012439 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
12440 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012441 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012442 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012443 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
12444 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012445 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012446 } else {
12447 send_resp(dut, conn, SIGMA_ERROR,
12448 "errorCode,GI value not supported");
12449 return 0;
12450 }
12451 if (system(buf) != 0) {
12452 send_resp(dut, conn, SIGMA_ERROR,
12453 "errorCode,Failed to set shortgi");
12454 return 0;
12455 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012456 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
12457 intf, fix_rate_sgi);
12458 if (system(buf) != 0) {
12459 send_resp(dut, conn, SIGMA_ERROR,
12460 "errorCode,Failed to set fix rate shortgi");
12461 return STATUS_SENT;
12462 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012463 }
12464
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012465 val = get_param(cmd, "LTF");
12466 if (val) {
12467#ifdef NL80211_SUPPORT
12468 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012469 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012470 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012471 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012472 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012473 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012474 } else {
12475 send_resp(dut, conn, SIGMA_ERROR,
12476 "errorCode, LTF value not supported");
12477 return 0;
12478 }
12479#else /* NL80211_SUPPORT */
12480 sigma_dut_print(dut, DUT_MSG_ERROR,
12481 "LTF cannot be set without NL80211_SUPPORT defined");
12482 return -2;
12483#endif /* NL80211_SUPPORT */
12484 }
12485
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070012486 val = get_param(cmd, "TxSUPPDU");
12487 if (val) {
12488 int set_val = 1;
12489
12490 if (strcasecmp(val, "Enable") == 0)
12491 set_val = 1;
12492 else if (strcasecmp(val, "Disable") == 0)
12493 set_val = 0;
12494
12495 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
12496 send_resp(dut, conn, SIGMA_ERROR,
12497 "ErrorCode,Failed to set Tx SU PPDU config");
12498 return 0;
12499 }
12500 }
12501
Arif Hussain480d5f42019-03-12 14:40:42 -070012502 val = get_param(cmd, "TWT_Setup");
12503 if (val) {
12504 if (strcasecmp(val, "Request") == 0) {
12505 if (sta_twt_request(dut, conn, cmd)) {
12506 send_resp(dut, conn, SIGMA_ERROR,
12507 "ErrorCode,sta_twt_request failed");
12508 return STATUS_SENT;
12509 }
12510 } else if (strcasecmp(val, "Teardown") == 0) {
12511 if (sta_twt_teardown(dut, conn, cmd)) {
12512 send_resp(dut, conn, SIGMA_ERROR,
12513 "ErrorCode,sta_twt_teardown failed");
12514 return STATUS_SENT;
12515 }
12516 }
12517 }
12518
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080012519 val = get_param(cmd, "transmitOMI");
12520 if (val && sta_transmit_omi(dut, conn, cmd)) {
12521 send_resp(dut, conn, SIGMA_ERROR,
12522 "ErrorCode,sta_transmit_omi failed");
12523 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070012524 }
12525
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012526 val = get_param(cmd, "Powersave");
12527 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012528 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012529
12530 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012531 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012532 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012533 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012534 } else {
12535 sigma_dut_print(dut, DUT_MSG_ERROR,
12536 "Unsupported Powersave value '%s'",
12537 val);
12538 return -1;
12539 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012540 if (set_power_save_wcn(dut, intf, ps) < 0)
12541 return 0;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012542 }
12543
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080012544 val = get_param(cmd, "MU_EDCA");
12545 if (val) {
12546 if (strcasecmp(val, "Override") == 0) {
12547 if (sta_set_mu_edca_override(dut, intf, 1)) {
12548 send_resp(dut, conn, SIGMA_ERROR,
12549 "errorCode,MU EDCA override set failed");
12550 return STATUS_SENT;
12551 }
12552 } else if (strcasecmp(val, "Disable") == 0) {
12553 if (sta_set_mu_edca_override(dut, intf, 0)) {
12554 send_resp(dut, conn, SIGMA_ERROR,
12555 "errorCode,MU EDCA override disable failed");
12556 return STATUS_SENT;
12557 }
12558 }
12559 }
12560
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -070012561 val = get_param(cmd, "Ch_Pref");
12562 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12563 return STATUS_SENT;
12564
12565 val = get_param(cmd, "Cellular_Data_Cap");
12566 if (val && mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12567 return STATUS_SENT;
12568
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012569 return 1;
12570
12571failed:
12572 free(token);
12573 return -2;
12574}
12575
12576
12577static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12578 struct sigma_conn *conn,
12579 struct sigma_cmd *cmd)
12580{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012581 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012582 case DRIVER_WCN:
12583 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
12584 default:
12585 send_resp(dut, conn, SIGMA_ERROR,
12586 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
12587 return 0;
12588 }
12589}
12590
12591
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012592static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
12593 struct sigma_conn *conn,
12594 struct sigma_cmd *cmd)
12595{
12596 const char *val;
12597
12598 val = get_param(cmd, "powersave");
12599 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012600 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012601
12602 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012603 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012604 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012605 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012606 } else {
12607 sigma_dut_print(dut, DUT_MSG_ERROR,
12608 "Unsupported power save config");
12609 return -1;
12610 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012611 if (set_power_save_wcn(dut, intf, ps) < 0)
12612 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012613 return 1;
12614 }
12615
12616 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
12617
12618 return 0;
12619}
12620
12621
Ashwini Patil5acd7382017-04-13 15:55:04 +053012622static int btm_query_candidate_list(struct sigma_dut *dut,
12623 struct sigma_conn *conn,
12624 struct sigma_cmd *cmd)
12625{
12626 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
12627 int len, ret;
12628 char buf[10];
12629
12630 /*
12631 * Neighbor Report elements format:
12632 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
12633 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
12634 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
12635 */
12636
12637 bssid = get_param(cmd, "Nebor_BSSID");
12638 if (!bssid) {
12639 send_resp(dut, conn, SIGMA_INVALID,
12640 "errorCode,Nebor_BSSID is missing");
12641 return 0;
12642 }
12643
12644 info = get_param(cmd, "Nebor_Bssid_Info");
12645 if (!info) {
12646 sigma_dut_print(dut, DUT_MSG_INFO,
12647 "Using default value for Nebor_Bssid_Info: %s",
12648 DEFAULT_NEIGHBOR_BSSID_INFO);
12649 info = DEFAULT_NEIGHBOR_BSSID_INFO;
12650 }
12651
12652 op_class = get_param(cmd, "Nebor_Op_Class");
12653 if (!op_class) {
12654 send_resp(dut, conn, SIGMA_INVALID,
12655 "errorCode,Nebor_Op_Class is missing");
12656 return 0;
12657 }
12658
12659 ch = get_param(cmd, "Nebor_Op_Ch");
12660 if (!ch) {
12661 send_resp(dut, conn, SIGMA_INVALID,
12662 "errorCode,Nebor_Op_Ch is missing");
12663 return 0;
12664 }
12665
12666 phy_type = get_param(cmd, "Nebor_Phy_Type");
12667 if (!phy_type) {
12668 sigma_dut_print(dut, DUT_MSG_INFO,
12669 "Using default value for Nebor_Phy_Type: %s",
12670 DEFAULT_NEIGHBOR_PHY_TYPE);
12671 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
12672 }
12673
12674 /* Parse optional subelements */
12675 buf[0] = '\0';
12676 pref = get_param(cmd, "Nebor_Pref");
12677 if (pref) {
12678 /* hexdump for preferrence subelement */
12679 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
12680 if (ret < 0 || ret >= (int) sizeof(buf)) {
12681 sigma_dut_print(dut, DUT_MSG_ERROR,
12682 "snprintf failed for optional subelement ret: %d",
12683 ret);
12684 send_resp(dut, conn, SIGMA_ERROR,
12685 "errorCode,snprintf failed for subelement");
12686 return 0;
12687 }
12688 }
12689
12690 if (!dut->btm_query_cand_list) {
12691 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
12692 if (!dut->btm_query_cand_list) {
12693 send_resp(dut, conn, SIGMA_ERROR,
12694 "errorCode,Failed to allocate memory for btm_query_cand_list");
12695 return 0;
12696 }
12697 }
12698
12699 len = strlen(dut->btm_query_cand_list);
12700 ret = snprintf(dut->btm_query_cand_list + len,
12701 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
12702 bssid, info, op_class, ch, phy_type, buf);
12703 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
12704 sigma_dut_print(dut, DUT_MSG_ERROR,
12705 "snprintf failed for neighbor report list ret: %d",
12706 ret);
12707 send_resp(dut, conn, SIGMA_ERROR,
12708 "errorCode,snprintf failed for neighbor report");
12709 free(dut->btm_query_cand_list);
12710 dut->btm_query_cand_list = NULL;
12711 return 0;
12712 }
12713
12714 return 1;
12715}
12716
12717
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012718int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
12719 struct sigma_ese_alloc *allocs, int *allocs_size)
12720{
12721 int max_count = *allocs_size;
12722 int count = 0, i;
12723 const char *val;
12724
12725 do {
12726 val = get_param_indexed(cmd, "AllocID", count);
12727 if (val)
12728 count++;
12729 } while (val);
12730
12731 if (count == 0 || count > max_count) {
12732 sigma_dut_print(dut, DUT_MSG_ERROR,
12733 "Invalid number of allocations(%d)", count);
12734 return -1;
12735 }
12736
12737 for (i = 0; i < count; i++) {
12738 val = get_param_indexed(cmd, "PercentBI", i);
12739 if (!val) {
12740 sigma_dut_print(dut, DUT_MSG_ERROR,
12741 "Missing PercentBI parameter at index %d",
12742 i);
12743 return -1;
12744 }
12745 allocs[i].percent_bi = atoi(val);
12746
12747 val = get_param_indexed(cmd, "SrcAID", i);
12748 if (val)
12749 allocs[i].src_aid = strtol(val, NULL, 0);
12750 else
12751 allocs[i].src_aid = ESE_BCAST_AID;
12752
12753 val = get_param_indexed(cmd, "DestAID", i);
12754 if (val)
12755 allocs[i].dst_aid = strtol(val, NULL, 0);
12756 else
12757 allocs[i].dst_aid = ESE_BCAST_AID;
12758
12759 allocs[i].type = ESE_CBAP;
12760 sigma_dut_print(dut, DUT_MSG_INFO,
12761 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
12762 i, allocs[i].percent_bi, allocs[i].src_aid,
12763 allocs[i].dst_aid);
12764 }
12765
12766 *allocs_size = count;
12767 return 0;
12768}
12769
12770
12771static int sta_set_60g_ese(struct sigma_dut *dut, int count,
12772 struct sigma_ese_alloc *allocs)
12773{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012774 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012775#ifdef __linux__
12776 case DRIVER_WIL6210:
12777 if (wil6210_set_ese(dut, count, allocs))
12778 return -1;
12779 return 1;
12780#endif /* __linux__ */
12781 default:
12782 sigma_dut_print(dut, DUT_MSG_ERROR,
12783 "Unsupported sta_set_60g_ese with the current driver");
12784 return -1;
12785 }
12786}
12787
12788
12789static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
12790 struct sigma_conn *conn,
12791 struct sigma_cmd *cmd)
12792{
12793 const char *val;
12794
12795 val = get_param(cmd, "ExtSchIE");
12796 if (val && !strcasecmp(val, "Enable")) {
12797 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
12798 int count = MAX_ESE_ALLOCS;
12799
12800 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
12801 return -1;
12802 return sta_set_60g_ese(dut, count, allocs);
12803 }
12804
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012805 val = get_param(cmd, "MCS_FixedRate");
12806 if (val) {
12807 int sta_mcs = atoi(val);
12808
12809 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
12810 sta_mcs);
12811 wil6210_set_force_mcs(dut, 1, sta_mcs);
12812
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012813 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012814 }
12815
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012816 send_resp(dut, conn, SIGMA_ERROR,
12817 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012818 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012819}
12820
12821
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012822static int wcn_sta_override_oci(struct sigma_dut *dut, const char *intf,
12823 const char *oci_frametype, uint32_t oci_freq)
12824{
12825#ifdef NL80211_SUPPORT
12826 struct nl_msg *msg;
12827 int ret = 0;
12828 struct nlattr *params;
12829 struct nlattr *attr;
12830 int ifindex;
12831 u8 frame_type;
12832
12833 ifindex = if_nametoindex(intf);
12834 if (ifindex == 0) {
12835 sigma_dut_print(dut, DUT_MSG_ERROR,
12836 "%s: Index for interface %s failed",
12837 __func__, intf);
12838 return -1;
12839 }
12840
12841 if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12842 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_REQ;
12843 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12844 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_RESP;
12845 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
12846 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_FT_REASSOC_REQ;
12847 } else {
12848 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: Unknown frametype %s",
12849 __func__, oci_frametype);
12850 return -1;
12851 }
12852
12853
12854 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
12855 NL80211_CMD_VENDOR)) ||
12856 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
12857 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
12858 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
12859 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
12860 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
12861 !(params = nla_nest_start(
12862 msg,
12863 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OCI_OVERRIDE)) ||
12864 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FRAME_TYPE,
12865 frame_type) ||
12866 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FREQUENCY,
12867 oci_freq)) {
12868 sigma_dut_print(dut, DUT_MSG_ERROR,
12869 "%s: err in adding vendor_cmd and vendor_data",
12870 __func__);
12871 nlmsg_free(msg);
12872 return -1;
12873 }
12874 nla_nest_end(msg, params);
12875 nla_nest_end(msg, attr);
12876
12877 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
12878 if (ret) {
12879 sigma_dut_print(dut, DUT_MSG_ERROR,
12880 "%s: err in send_and_recv_msgs, ret=%d",
12881 __func__, ret);
12882 }
12883 return ret;
12884#else /* NL80211_SUPPORT */
12885 sigma_dut_print(dut, DUT_MSG_ERROR,
12886 "OCI override not possible without NL80211_SUPPORT defined");
12887 return -1;
12888#endif /* NL80211_SUPPORT */
12889}
12890
12891
Jouni Malinen6250cb02020-04-15 13:54:45 +030012892static enum sigma_cmd_result
12893cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
12894 struct sigma_conn *conn,
12895 struct sigma_cmd *cmd)
12896{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012897 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030012898
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053012899 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030012900 if (val && atoi(val) == 1) {
12901 if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
12902 send_resp(dut, conn, SIGMA_ERROR,
12903 "errorCode,Failed to set ft_rsnxe_used");
12904 return STATUS_SENT_ERROR;
12905 }
12906 return SUCCESS_SEND_STATUS;
12907 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012908
12909 oci_chan = get_param(cmd, "OCIChannel");
12910 oci_frametype = get_param(cmd, "OCIFrameType");
12911 if (oci_chan && oci_frametype) {
12912 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
12913 char buf[100];
12914
12915 if (!oci_freq) {
12916 send_resp(dut, conn, SIGMA_ERROR,
12917 "errorCode,Invalid OCIChannel number");
12918 return STATUS_SENT_ERROR;
12919 }
12920
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012921 if (wifi_chip_type == DRIVER_WCN &&
12922 (strcasecmp(oci_frametype, "SAQueryReq") == 0 ||
12923 strcasecmp(oci_frametype, "SAQueryResp") == 0 ||
12924 strcasecmp(oci_frametype, "Reassocreq") == 0)) {
12925 if (wcn_sta_override_oci(dut, intf, oci_frametype,
12926 oci_freq)) {
12927 send_resp(dut, conn, SIGMA_ERROR,
12928 "errorCode,Failed to override OCI");
12929 return STATUS_SENT_ERROR;
12930 }
12931 return SUCCESS_SEND_STATUS;
12932 }
12933
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012934 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
12935 snprintf(buf, sizeof(buf),
12936 "SET oci_freq_override_eapol %d", oci_freq);
12937 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12938 snprintf(buf, sizeof(buf),
12939 "SET oci_freq_override_saquery_req %d",
12940 oci_freq);
12941 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12942 snprintf(buf, sizeof(buf),
12943 "SET oci_freq_override_saquery_resp %d",
12944 oci_freq);
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012945 } else if (strcasecmp(oci_frametype, "GrpKeyM2") == 0) {
12946 snprintf(buf, sizeof(buf),
12947 "SET oci_freq_override_eapol_g2 %d",
12948 oci_freq);
12949 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
12950 snprintf(buf, sizeof(buf),
12951 "SET oci_freq_override_ft_assoc %d",
12952 oci_freq);
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012953 } else {
12954 send_resp(dut, conn, SIGMA_ERROR,
12955 "errorCode,Unsupported OCIFrameType");
12956 return STATUS_SENT_ERROR;
12957 }
12958 if (wpa_command(intf, buf) < 0) {
12959 send_resp(dut, conn, SIGMA_ERROR,
12960 "errorCode,Failed to set oci_freq_override");
12961 return STATUS_SENT_ERROR;
12962 }
12963 return SUCCESS_SEND_STATUS;
12964 }
12965
Jouni Malinen6250cb02020-04-15 13:54:45 +030012966 send_resp(dut, conn, SIGMA_ERROR,
12967 "errorCode,Unsupported WPA3 rfeature");
12968 return STATUS_SENT_ERROR;
12969}
12970
12971
Jouni Malinenf7222712019-06-13 01:50:21 +030012972static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
12973 struct sigma_conn *conn,
12974 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012975{
12976 const char *intf = get_param(cmd, "Interface");
12977 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012978 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012979
12980 if (intf == NULL || prog == NULL)
12981 return -1;
12982
Ashwini Patil5acd7382017-04-13 15:55:04 +053012983 /* BSS Transition candidate list for BTM query */
12984 val = get_param(cmd, "Nebor_BSSID");
12985 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
12986 return 0;
12987
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012988 if (strcasecmp(prog, "TDLS") == 0)
12989 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
12990
12991 if (strcasecmp(prog, "VHT") == 0)
12992 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
12993
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012994 if (strcasecmp(prog, "HE") == 0)
12995 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
12996
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012997 if (strcasecmp(prog, "MBO") == 0) {
12998 val = get_param(cmd, "Cellular_Data_Cap");
12999 if (val &&
13000 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
13001 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053013002
13003 val = get_param(cmd, "Ch_Pref");
13004 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
13005 return 0;
13006
Ashwini Patil68d02cd2017-01-10 15:39:16 +053013007 return 1;
13008 }
13009
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020013010 if (strcasecmp(prog, "60GHz") == 0)
13011 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
13012
Jouni Malinen6250cb02020-04-15 13:54:45 +030013013 if (strcasecmp(prog, "WPA3") == 0)
13014 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
13015
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013016 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
13017 return 0;
13018}
13019
13020
Jouni Malinenf7222712019-06-13 01:50:21 +030013021static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
13022 struct sigma_conn *conn,
13023 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013024{
13025 const char *intf = get_param(cmd, "Interface");
13026 const char *mode = get_param(cmd, "Mode");
13027 int res;
13028
13029 if (intf == NULL || mode == NULL)
13030 return -1;
13031
13032 if (strcasecmp(mode, "On") == 0)
13033 res = wpa_command(intf, "SET radio_disabled 0");
13034 else if (strcasecmp(mode, "Off") == 0)
13035 res = wpa_command(intf, "SET radio_disabled 1");
13036 else
13037 return -1;
13038
13039 if (res) {
13040 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
13041 "radio mode");
13042 return 0;
13043 }
13044
13045 return 1;
13046}
13047
13048
Jouni Malinenf7222712019-06-13 01:50:21 +030013049static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
13050 struct sigma_conn *conn,
13051 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013052{
13053 const char *intf = get_param(cmd, "Interface");
13054 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013055 const char *prog = get_param(cmd, "program");
13056 const char *powersave = get_param(cmd, "powersave");
13057 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013058
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013059 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013060 return -1;
13061
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013062 if (prog && strcasecmp(prog, "60GHz") == 0) {
13063 /*
13064 * The CAPI mode parameter does not exist in 60G
13065 * unscheduled PS.
13066 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080013067 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013068 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013069 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020013070 strcasecmp(prog, "HE") == 0) {
13071 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013072 } else {
13073 if (mode == NULL)
13074 return -1;
13075
13076 if (strcasecmp(mode, "On") == 0)
13077 res = set_ps(intf, dut, 1);
13078 else if (strcasecmp(mode, "Off") == 0)
13079 res = set_ps(intf, dut, 0);
13080 else
13081 return -1;
13082 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013083
13084 if (res) {
13085 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
13086 "power save mode");
13087 return 0;
13088 }
13089
13090 return 1;
13091}
13092
13093
Jouni Malinenf7222712019-06-13 01:50:21 +030013094static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
13095 struct sigma_conn *conn,
13096 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013097{
13098 const char *intf = get_param(cmd, "Interface");
13099 const char *val, *bssid;
13100 int res;
13101 char *buf;
13102 size_t buf_len;
13103
13104 val = get_param(cmd, "BSSID_FILTER");
13105 if (val == NULL)
13106 return -1;
13107
13108 bssid = get_param(cmd, "BSSID_List");
13109 if (atoi(val) == 0 || bssid == NULL) {
13110 /* Disable BSSID filter */
13111 if (wpa_command(intf, "SET bssid_filter ")) {
13112 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
13113 "to disable BSSID filter");
13114 return 0;
13115 }
13116
13117 return 1;
13118 }
13119
13120 buf_len = 100 + strlen(bssid);
13121 buf = malloc(buf_len);
13122 if (buf == NULL)
13123 return -1;
13124
13125 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
13126 res = wpa_command(intf, buf);
13127 free(buf);
13128 if (res) {
13129 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
13130 "BSSID filter");
13131 return 0;
13132 }
13133
13134 return 1;
13135}
13136
13137
Jouni Malinenf7222712019-06-13 01:50:21 +030013138static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
13139 struct sigma_conn *conn,
13140 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013141{
13142 const char *intf = get_param(cmd, "Interface");
13143 const char *val;
13144
13145 /* TODO: ARP */
13146
13147 val = get_param(cmd, "HS2_CACHE_PROFILE");
13148 if (val && strcasecmp(val, "All") == 0)
13149 hs2_clear_credentials(intf);
13150
13151 return 1;
13152}
13153
13154
Jouni Malinenf7222712019-06-13 01:50:21 +030013155static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
13156 struct sigma_conn *conn,
13157 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013158{
13159 const char *intf = get_param(cmd, "Interface");
13160 const char *key_type = get_param(cmd, "KeyType");
13161 char buf[100], resp[200];
13162
13163 if (key_type == NULL)
13164 return -1;
13165
13166 if (strcasecmp(key_type, "GTK") == 0) {
13167 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
13168 strncmp(buf, "FAIL", 4) == 0) {
13169 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13170 "not fetch current GTK");
13171 return 0;
13172 }
13173 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
13174 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13175 return 0;
13176 } else {
13177 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
13178 "KeyType");
13179 return 0;
13180 }
13181
13182 return 1;
13183}
13184
13185
13186static int hs2_set_policy(struct sigma_dut *dut)
13187{
13188#ifdef ANDROID
13189 system("ip rule del prio 23000");
13190 if (system("ip rule add from all lookup main prio 23000") != 0) {
13191 sigma_dut_print(dut, DUT_MSG_ERROR,
13192 "Failed to run:ip rule add from all lookup main prio");
13193 return -1;
13194 }
13195 if (system("ip route flush cache") != 0) {
13196 sigma_dut_print(dut, DUT_MSG_ERROR,
13197 "Failed to run ip route flush cache");
13198 return -1;
13199 }
13200 return 1;
13201#else /* ANDROID */
13202 return 0;
13203#endif /* ANDROID */
13204}
13205
13206
Jouni Malinenf7222712019-06-13 01:50:21 +030013207static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
13208 struct sigma_conn *conn,
13209 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013210{
13211 const char *intf = get_param(cmd, "Interface");
13212 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030013213 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013214 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030013215 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013216 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
13217 int tries = 0;
13218 int ignore_blacklist = 0;
13219 const char *events[] = {
13220 "CTRL-EVENT-CONNECTED",
13221 "INTERWORKING-BLACKLISTED",
13222 "INTERWORKING-NO-MATCH",
13223 NULL
13224 };
13225
13226 start_sta_mode(dut);
13227
Jouni Malinen439352d2018-09-13 03:42:23 +030013228 if (band) {
13229 if (strcmp(band, "2.4") == 0) {
13230 wpa_command(intf, "SET setband 2G");
13231 } else if (strcmp(band, "5") == 0) {
13232 wpa_command(intf, "SET setband 5G");
13233 } else {
13234 send_resp(dut, conn, SIGMA_ERROR,
13235 "errorCode,Unsupported band");
13236 return 0;
13237 }
13238 }
13239
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013240 blacklisted[0] = '\0';
13241 if (val && atoi(val))
13242 ignore_blacklist = 1;
13243
13244try_again:
13245 ctrl = open_wpa_mon(intf);
13246 if (ctrl == NULL) {
13247 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13248 "wpa_supplicant monitor connection");
13249 return -2;
13250 }
13251
13252 tries++;
13253 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
13254 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
13255 "Interworking connection");
13256 wpa_ctrl_detach(ctrl);
13257 wpa_ctrl_close(ctrl);
13258 return 0;
13259 }
13260
13261 buf[0] = '\0';
13262 while (1) {
13263 char *pos;
13264 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13265 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
13266 if (!pos)
13267 break;
13268 pos += 25;
13269 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
13270 pos);
13271 if (!blacklisted[0])
13272 memcpy(blacklisted, pos, strlen(pos) + 1);
13273 }
13274
13275 if (ignore_blacklist && blacklisted[0]) {
13276 char *end;
13277 end = strchr(blacklisted, ' ');
13278 if (end)
13279 *end = '\0';
13280 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
13281 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030013282 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
13283 blacklisted);
13284 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013285 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
13286 wpa_ctrl_detach(ctrl);
13287 wpa_ctrl_close(ctrl);
13288 return 0;
13289 }
13290 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13291 buf, sizeof(buf));
13292 }
13293
13294 wpa_ctrl_detach(ctrl);
13295 wpa_ctrl_close(ctrl);
13296
13297 if (res < 0) {
13298 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
13299 "connect");
13300 return 0;
13301 }
13302
13303 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
13304 strstr(buf, "INTERWORKING-BLACKLISTED")) {
13305 if (tries < 2) {
13306 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
13307 goto try_again;
13308 }
13309 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
13310 "matching credentials found");
13311 return 0;
13312 }
13313
13314 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13315 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13316 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
13317 "get current BSSID/SSID");
13318 return 0;
13319 }
13320
13321 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
13322 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13323 hs2_set_policy(dut);
13324 return 0;
13325}
13326
13327
Jouni Malinenf7222712019-06-13 01:50:21 +030013328static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
13329 struct sigma_conn *conn,
13330 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013331{
13332 const char *intf = get_param(cmd, "Interface");
13333 const char *display = get_param(cmd, "Display");
13334 struct wpa_ctrl *ctrl;
13335 char buf[300], params[400], *pos;
13336 char bssid[20];
13337 int info_avail = 0;
13338 unsigned int old_timeout;
13339 int res;
13340
13341 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
13342 send_resp(dut, conn, SIGMA_ERROR,
13343 "ErrorCode,Could not get current BSSID");
13344 return 0;
13345 }
13346 ctrl = open_wpa_mon(intf);
13347 if (!ctrl) {
13348 sigma_dut_print(dut, DUT_MSG_ERROR,
13349 "Failed to open wpa_supplicant monitor connection");
13350 return -2;
13351 }
13352
13353 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
13354 wpa_command(intf, buf);
13355
13356 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
13357 if (res < 0) {
13358 send_resp(dut, conn, SIGMA_ERROR,
13359 "ErrorCode,Could not complete GAS query");
13360 goto fail;
13361 }
13362
13363 old_timeout = dut->default_timeout;
13364 dut->default_timeout = 2;
13365 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
13366 dut->default_timeout = old_timeout;
13367 if (res < 0)
13368 goto done;
13369 pos = strchr(buf, ' ');
13370 if (!pos)
13371 goto done;
13372 pos++;
13373 pos = strchr(pos, ' ');
13374 if (!pos)
13375 goto done;
13376 pos++;
13377 info_avail = 1;
13378 snprintf(params, sizeof(params), "browser %s", pos);
13379
13380 if (display && strcasecmp(display, "Yes") == 0) {
13381 pid_t pid;
13382
13383 pid = fork();
13384 if (pid < 0) {
13385 perror("fork");
13386 return -1;
13387 }
13388
13389 if (pid == 0) {
13390 run_hs20_osu(dut, params);
13391 exit(0);
13392 }
13393 }
13394
13395done:
13396 snprintf(buf, sizeof(buf), "Info_available,%s",
13397 info_avail ? "Yes" : "No");
13398 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13399fail:
13400 wpa_ctrl_detach(ctrl);
13401 wpa_ctrl_close(ctrl);
13402 return 0;
13403}
13404
13405
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013406static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
13407 struct sigma_conn *conn,
13408 const char *ifname,
13409 struct sigma_cmd *cmd)
13410{
13411 const char *val;
13412 int id;
13413
13414 id = add_cred(ifname);
13415 if (id < 0)
13416 return -2;
13417 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13418
13419 val = get_param(cmd, "prefer");
13420 if (val && atoi(val) > 0)
13421 set_cred(ifname, id, "priority", "1");
13422
13423 val = get_param(cmd, "REALM");
13424 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13425 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13426 "realm");
13427 return 0;
13428 }
13429
13430 val = get_param(cmd, "HOME_FQDN");
13431 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13432 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13433 "home_fqdn");
13434 return 0;
13435 }
13436
13437 val = get_param(cmd, "Username");
13438 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13439 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13440 "username");
13441 return 0;
13442 }
13443
13444 val = get_param(cmd, "Password");
13445 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
13446 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13447 "password");
13448 return 0;
13449 }
13450
13451 val = get_param(cmd, "ROOT_CA");
13452 if (val) {
13453 char fname[200];
13454 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13455#ifdef __linux__
13456 if (!file_exists(fname)) {
13457 char msg[300];
13458 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13459 "file (%s) not found", fname);
13460 send_resp(dut, conn, SIGMA_ERROR, msg);
13461 return 0;
13462 }
13463#endif /* __linux__ */
13464 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13465 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13466 "not set root CA");
13467 return 0;
13468 }
13469 }
13470
13471 return 1;
13472}
13473
13474
13475static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
13476{
13477 FILE *in, *out;
13478 char buf[500];
13479 int found = 0;
13480
13481 in = fopen("devdetail.xml", "r");
13482 if (in == NULL)
13483 return -1;
13484 out = fopen("devdetail.xml.tmp", "w");
13485 if (out == NULL) {
13486 fclose(in);
13487 return -1;
13488 }
13489
13490 while (fgets(buf, sizeof(buf), in)) {
13491 char *pos = strstr(buf, "<IMSI>");
13492 if (pos) {
13493 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
13494 imsi);
13495 pos += 6;
13496 *pos = '\0';
13497 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
13498 found++;
13499 } else {
13500 fprintf(out, "%s", buf);
13501 }
13502 }
13503
13504 fclose(out);
13505 fclose(in);
13506 if (found)
13507 rename("devdetail.xml.tmp", "devdetail.xml");
13508 else
13509 unlink("devdetail.xml.tmp");
13510
13511 return 0;
13512}
13513
13514
13515static int sta_add_credential_sim(struct sigma_dut *dut,
13516 struct sigma_conn *conn,
13517 const char *ifname, struct sigma_cmd *cmd)
13518{
13519 const char *val, *imsi = NULL;
13520 int id;
13521 char buf[200];
13522 int res;
13523 const char *pos;
13524 size_t mnc_len;
13525 char plmn_mcc[4];
13526 char plmn_mnc[4];
13527
13528 id = add_cred(ifname);
13529 if (id < 0)
13530 return -2;
13531 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13532
13533 val = get_param(cmd, "prefer");
13534 if (val && atoi(val) > 0)
13535 set_cred(ifname, id, "priority", "1");
13536
13537 val = get_param(cmd, "PLMN_MCC");
13538 if (val == NULL) {
13539 send_resp(dut, conn, SIGMA_ERROR,
13540 "errorCode,Missing PLMN_MCC");
13541 return 0;
13542 }
13543 if (strlen(val) != 3) {
13544 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
13545 return 0;
13546 }
13547 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
13548
13549 val = get_param(cmd, "PLMN_MNC");
13550 if (val == NULL) {
13551 send_resp(dut, conn, SIGMA_ERROR,
13552 "errorCode,Missing PLMN_MNC");
13553 return 0;
13554 }
13555 if (strlen(val) != 2 && strlen(val) != 3) {
13556 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
13557 return 0;
13558 }
13559 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
13560
13561 val = get_param(cmd, "IMSI");
13562 if (val == NULL) {
13563 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
13564 "IMSI");
13565 return 0;
13566 }
13567
13568 imsi = pos = val;
13569
13570 if (strncmp(plmn_mcc, pos, 3) != 0) {
13571 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
13572 return 0;
13573 }
13574 pos += 3;
13575
13576 mnc_len = strlen(plmn_mnc);
13577 if (mnc_len < 2) {
13578 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
13579 return 0;
13580 }
13581
13582 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
13583 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
13584 return 0;
13585 }
13586 pos += mnc_len;
13587
13588 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
13589 if (res < 0 || res >= (int) sizeof(buf))
13590 return -1;
13591 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
13592 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13593 "not set IMSI");
13594 return 0;
13595 }
13596
13597 val = get_param(cmd, "Password");
13598 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
13599 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13600 "not set password");
13601 return 0;
13602 }
13603
Jouni Malinenba630452018-06-22 11:49:59 +030013604 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013605 /*
13606 * Set provisioning_sp for the test cases where SIM/USIM
13607 * provisioning is used.
13608 */
13609 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
13610 "wi-fi.org") < 0) {
13611 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13612 "not set provisioning_sp");
13613 return 0;
13614 }
13615
13616 update_devdetail_imsi(dut, imsi);
13617 }
13618
13619 return 1;
13620}
13621
13622
13623static int sta_add_credential_cert(struct sigma_dut *dut,
13624 struct sigma_conn *conn,
13625 const char *ifname,
13626 struct sigma_cmd *cmd)
13627{
13628 const char *val;
13629 int id;
13630
13631 id = add_cred(ifname);
13632 if (id < 0)
13633 return -2;
13634 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13635
13636 val = get_param(cmd, "prefer");
13637 if (val && atoi(val) > 0)
13638 set_cred(ifname, id, "priority", "1");
13639
13640 val = get_param(cmd, "REALM");
13641 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13642 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13643 "realm");
13644 return 0;
13645 }
13646
13647 val = get_param(cmd, "HOME_FQDN");
13648 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13649 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13650 "home_fqdn");
13651 return 0;
13652 }
13653
13654 val = get_param(cmd, "Username");
13655 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13656 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13657 "username");
13658 return 0;
13659 }
13660
13661 val = get_param(cmd, "clientCertificate");
13662 if (val) {
13663 char fname[200];
13664 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13665#ifdef __linux__
13666 if (!file_exists(fname)) {
13667 char msg[300];
13668 snprintf(msg, sizeof(msg),
13669 "ErrorCode,clientCertificate "
13670 "file (%s) not found", fname);
13671 send_resp(dut, conn, SIGMA_ERROR, msg);
13672 return 0;
13673 }
13674#endif /* __linux__ */
13675 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
13676 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13677 "not set client_cert");
13678 return 0;
13679 }
13680 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
13681 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13682 "not set private_key");
13683 return 0;
13684 }
13685 }
13686
13687 val = get_param(cmd, "ROOT_CA");
13688 if (val) {
13689 char fname[200];
13690 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13691#ifdef __linux__
13692 if (!file_exists(fname)) {
13693 char msg[300];
13694 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13695 "file (%s) not found", fname);
13696 send_resp(dut, conn, SIGMA_ERROR, msg);
13697 return 0;
13698 }
13699#endif /* __linux__ */
13700 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13701 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13702 "not set root CA");
13703 return 0;
13704 }
13705 }
13706
13707 return 1;
13708}
13709
13710
Jouni Malinenf7222712019-06-13 01:50:21 +030013711static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
13712 struct sigma_conn *conn,
13713 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013714{
13715 const char *intf = get_param(cmd, "Interface");
13716 const char *type;
13717
13718 start_sta_mode(dut);
13719
13720 type = get_param(cmd, "Type");
13721 if (!type)
13722 return -1;
13723
13724 if (strcasecmp(type, "uname_pwd") == 0)
13725 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
13726
13727 if (strcasecmp(type, "sim") == 0)
13728 return sta_add_credential_sim(dut, conn, intf, cmd);
13729
13730 if (strcasecmp(type, "cert") == 0)
13731 return sta_add_credential_cert(dut, conn, intf, cmd);
13732
13733 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
13734 "type");
13735 return 0;
13736}
13737
13738
Jouni Malinenf7222712019-06-13 01:50:21 +030013739static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
13740 struct sigma_conn *conn,
13741 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013742{
13743 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013744 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Veerendranathdc581b52020-08-10 03:29:08 -070013745 char buf[4096], scan_res[20];
vamsi krishna89ad8c62017-09-19 12:51:18 +053013746 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013747 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013748 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013749 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013750 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013751
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020013752 start_sta_mode(dut);
13753
Arif Hussain66a4af02019-02-07 15:04:51 -080013754 val = get_param(cmd, "GetParameter");
13755 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013756 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080013757 buf, sizeof(buf)) < 0) {
13758 sigma_dut_print(dut, DUT_MSG_ERROR,
13759 "Could not get ssid bssid");
13760 return ERROR_SEND_STATUS;
13761 }
13762
13763 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
13764 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13765 return STATUS_SENT;
13766 }
13767
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013768 val = get_param(cmd, "HESSID");
13769 if (val) {
13770 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
13771 if (res < 0 || res >= (int) sizeof(buf))
13772 return -1;
13773 wpa_command(intf, buf);
13774 }
13775
13776 val = get_param(cmd, "ACCS_NET_TYPE");
13777 if (val) {
13778 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
13779 val);
13780 if (res < 0 || res >= (int) sizeof(buf))
13781 return -1;
13782 wpa_command(intf, buf);
13783 }
13784
vamsi krishna89ad8c62017-09-19 12:51:18 +053013785 bssid = get_param(cmd, "Bssid");
13786 ssid = get_param(cmd, "Ssid");
13787
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013788 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
13789 dut->device_type == STA_testbed) {
13790 ssid = NULL;
13791 wildcard_ssid = 1;
13792 }
13793
vamsi krishna89ad8c62017-09-19 12:51:18 +053013794 if (ssid) {
13795 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
13796 send_resp(dut, conn, SIGMA_ERROR,
13797 "ErrorCode,Too long SSID");
13798 return 0;
13799 }
13800 ascii2hexstr(ssid, ssid_hex);
13801 }
13802
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013803 short_ssid = get_param(cmd, "ShortSSID");
13804 if (short_ssid) {
13805 uint32_t short_ssid_hex;
13806
13807 short_ssid_hex = strtoul(short_ssid, NULL, 16);
13808 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
13809 (((short_ssid_hex >> 8) & 0xFF) << 16) |
13810 (((short_ssid_hex >> 16) & 0xFF) << 8) |
13811 ((short_ssid_hex >> 24) & 0xFF);
13812
13813 res = snprintf(buf, sizeof(buf),
13814 "VENDOR_ELEM_ADD 14 ff053a%08x",
13815 short_ssid_hex);
13816 if (res < 0 || res >= (int) sizeof(buf) ||
13817 wpa_command(intf, buf)) {
13818 send_resp(dut, conn, SIGMA_ERROR,
13819 "errorCode,Failed to add short SSID");
13820 return STATUS_SENT_ERROR;
13821 }
13822 }
13823
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013824 scan_freq = get_param(cmd, "ChnlFreq");
Veerendranath Jakkam132c4b42020-08-10 00:29:03 +053013825 if (scan_freq) {
13826 if (strcasecmp(scan_freq, "2G") == 0)
13827 scan_freq = "2412-2462";
13828 else if (strcasecmp(scan_freq, "5G") == 0)
13829 scan_freq = "5180-5925";
13830 }
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013831
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013832 val = get_param(cmd, "WaitCompletion");
13833 if (val && atoi(val) == 1) {
13834 ctrl = open_wpa_mon(intf);
13835 if (!ctrl) {
13836 send_resp(dut, conn, SIGMA_ERROR,
13837 "errorCode,Failed to open monitor socket");
13838 return STATUS_SENT_ERROR;
13839 }
13840 }
13841
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013842 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053013843 bssid ? " bssid=": "",
13844 bssid ? bssid : "",
13845 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013846 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013847 wildcard_ssid ? " wildcard_ssid=1" : "",
13848 scan_freq ? " freq=" : "",
13849 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013850 if (res < 0 || res >= (int) sizeof(buf)) {
13851 send_resp(dut, conn, SIGMA_ERROR,
13852 "errorCode,Could not build scan command");
13853 status = STATUS_SENT_ERROR;
13854 goto remove_s_ssid;
13855 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053013856
Veerendranathdc581b52020-08-10 03:29:08 -070013857 res = wpa_command_resp(intf, buf, scan_res, sizeof(scan_res));
13858 if (strncmp(scan_res, "FAIL-BUSY", 9) == 0) {
13859 sigma_dut_print(dut, DUT_MSG_DEBUG,
13860 "Scan request rejected with busy status, abort ongoing scan and try again");
13861 wpa_command(intf, "ABORT_SCAN");
13862 res = wpa_command(intf, buf);
13863 }
13864
13865 if (res < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013866 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
13867 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013868 status = STATUS_SENT_ERROR;
13869 } else {
13870 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013871 }
13872
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013873remove_s_ssid:
13874 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
13875 sigma_dut_print(dut, DUT_MSG_ERROR,
13876 "Failed to delete vendor element");
13877
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013878 if (ctrl) {
13879 if (status == SUCCESS_SEND_STATUS) {
13880 res = get_wpa_cli_event(dut, ctrl,
13881 "CTRL-EVENT-SCAN-RESULTS",
13882 buf, sizeof(buf));
13883 if (res < 0) {
13884 send_resp(dut, conn, SIGMA_ERROR,
13885 "ErrorCode,scan did not complete");
13886 status = STATUS_SENT_ERROR;
13887 }
13888 }
13889
13890 wpa_ctrl_detach(ctrl);
13891 wpa_ctrl_close(ctrl);
13892 }
13893
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013894 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013895}
13896
13897
Jouni Malinenf7222712019-06-13 01:50:21 +030013898static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
13899 struct sigma_conn *conn,
13900 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013901{
13902 const char *intf = get_param(cmd, "Interface");
13903 const char *bssid;
13904 char buf[4096], *pos;
13905 int freq, chan;
13906 char *ssid;
13907 char resp[100];
13908 int res;
13909 struct wpa_ctrl *ctrl;
13910
13911 bssid = get_param(cmd, "BSSID");
13912 if (!bssid) {
13913 send_resp(dut, conn, SIGMA_INVALID,
13914 "errorCode,BSSID argument is missing");
13915 return 0;
13916 }
13917
13918 ctrl = open_wpa_mon(intf);
13919 if (!ctrl) {
13920 sigma_dut_print(dut, DUT_MSG_ERROR,
13921 "Failed to open wpa_supplicant monitor connection");
13922 return -1;
13923 }
13924
13925 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
13926 send_resp(dut, conn, SIGMA_ERROR,
13927 "errorCode,Could not start scan");
13928 wpa_ctrl_detach(ctrl);
13929 wpa_ctrl_close(ctrl);
13930 return 0;
13931 }
13932
13933 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
13934 buf, sizeof(buf));
13935
13936 wpa_ctrl_detach(ctrl);
13937 wpa_ctrl_close(ctrl);
13938
13939 if (res < 0) {
13940 send_resp(dut, conn, SIGMA_ERROR,
13941 "errorCode,Scan did not complete");
13942 return 0;
13943 }
13944
13945 snprintf(buf, sizeof(buf), "BSS %s", bssid);
13946 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
13947 strncmp(buf, "id=", 3) != 0) {
13948 send_resp(dut, conn, SIGMA_ERROR,
13949 "errorCode,Specified BSSID not found");
13950 return 0;
13951 }
13952
13953 pos = strstr(buf, "\nfreq=");
13954 if (!pos) {
13955 send_resp(dut, conn, SIGMA_ERROR,
13956 "errorCode,Channel not found");
13957 return 0;
13958 }
13959 freq = atoi(pos + 6);
13960 chan = freq_to_channel(freq);
13961
13962 pos = strstr(buf, "\nssid=");
13963 if (!pos) {
13964 send_resp(dut, conn, SIGMA_ERROR,
13965 "errorCode,SSID not found");
13966 return 0;
13967 }
13968 ssid = pos + 6;
13969 pos = strchr(ssid, '\n');
13970 if (pos)
13971 *pos = '\0';
13972 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
13973 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13974 return 0;
13975}
13976
13977
Jouni Malinenf7222712019-06-13 01:50:21 +030013978static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
13979 struct sigma_conn *conn,
13980 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013981{
13982#ifdef __linux__
13983 struct timeval tv;
13984 struct tm tm;
13985 time_t t;
13986 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013987 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013988
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013989 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013990
13991 memset(&tm, 0, sizeof(tm));
13992 val = get_param(cmd, "seconds");
13993 if (val)
13994 tm.tm_sec = atoi(val);
13995 val = get_param(cmd, "minutes");
13996 if (val)
13997 tm.tm_min = atoi(val);
13998 val = get_param(cmd, "hours");
13999 if (val)
14000 tm.tm_hour = atoi(val);
14001 val = get_param(cmd, "date");
14002 if (val)
14003 tm.tm_mday = atoi(val);
14004 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053014005 if (val) {
14006 v = atoi(val);
14007 if (v < 1 || v > 12) {
14008 send_resp(dut, conn, SIGMA_INVALID,
14009 "errorCode,Invalid month");
14010 return 0;
14011 }
14012 tm.tm_mon = v - 1;
14013 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014014 val = get_param(cmd, "year");
14015 if (val) {
14016 int year = atoi(val);
14017#ifdef ANDROID
14018 if (year > 2035)
14019 year = 2035; /* years beyond 2035 not supported */
14020#endif /* ANDROID */
14021 tm.tm_year = year - 1900;
14022 }
14023 t = mktime(&tm);
14024 if (t == (time_t) -1) {
14025 send_resp(dut, conn, SIGMA_ERROR,
14026 "errorCode,Invalid date or time");
14027 return 0;
14028 }
14029
14030 memset(&tv, 0, sizeof(tv));
14031 tv.tv_sec = t;
14032
14033 if (settimeofday(&tv, NULL) < 0) {
14034 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
14035 strerror(errno));
14036 send_resp(dut, conn, SIGMA_ERROR,
14037 "errorCode,Failed to set time");
14038 return 0;
14039 }
14040
14041 return 1;
14042#endif /* __linux__ */
14043
14044 return -1;
14045}
14046
14047
Jouni Malinenf7222712019-06-13 01:50:21 +030014048static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
14049 struct sigma_conn *conn,
14050 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014051{
14052 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014053 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014054 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014055 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014056 int res;
14057 struct wpa_ctrl *ctrl;
14058
14059 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014060 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014061
14062 val = get_param(cmd, "ProdESSAssoc");
14063 if (val)
14064 prod_ess_assoc = atoi(val);
14065
14066 kill_dhcp_client(dut, intf);
14067 if (start_dhcp_client(dut, intf) < 0)
14068 return -2;
14069
14070 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
14071 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
14072 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014073 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014074 prod_ess_assoc ? "" : "-N",
14075 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030014076 name ? "'" : "",
14077 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
14078 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014079
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053014080 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014081 if (run_hs20_osu(dut, buf) < 0) {
14082 FILE *f;
14083
14084 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
14085
14086 f = fopen("hs20-osu-client.res", "r");
14087 if (f) {
14088 char resp[400], res[300], *pos;
14089 if (!fgets(res, sizeof(res), f))
14090 res[0] = '\0';
14091 pos = strchr(res, '\n');
14092 if (pos)
14093 *pos = '\0';
14094 fclose(f);
14095 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
14096 res);
14097 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
14098 if (system(resp) != 0) {
14099 }
14100 snprintf(resp, sizeof(resp),
14101 "SSID,,BSSID,,failureReason,%s", res);
14102 send_resp(dut, conn, SIGMA_COMPLETE, resp);
14103 return 0;
14104 }
14105
14106 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
14107 return 0;
14108 }
14109
14110 if (!prod_ess_assoc)
14111 goto report;
14112
14113 ctrl = open_wpa_mon(intf);
14114 if (ctrl == NULL) {
14115 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14116 "wpa_supplicant monitor connection");
14117 return -1;
14118 }
14119
14120 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
14121 buf, sizeof(buf));
14122
14123 wpa_ctrl_detach(ctrl);
14124 wpa_ctrl_close(ctrl);
14125
14126 if (res < 0) {
14127 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
14128 "network after OSU");
14129 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
14130 return 0;
14131 }
14132
14133report:
14134 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
14135 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
14136 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
14137 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
14138 return 0;
14139 }
14140
14141 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
14142 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014143 return 0;
14144}
14145
14146
Jouni Malinenf7222712019-06-13 01:50:21 +030014147static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
14148 struct sigma_conn *conn,
14149 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014150{
14151 const char *val;
14152 int timeout = 120;
14153
14154 val = get_param(cmd, "PolicyUpdate");
14155 if (val == NULL || atoi(val) == 0)
14156 return 1; /* No operation requested */
14157
14158 val = get_param(cmd, "Timeout");
14159 if (val)
14160 timeout = atoi(val);
14161
14162 if (timeout) {
14163 /* TODO: time out the command and return
14164 * PolicyUpdateStatus,TIMEOUT if needed. */
14165 }
14166
14167 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
14168 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
14169 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
14170 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
14171 return 0;
14172 }
14173
14174 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
14175 return 0;
14176}
14177
14178
Jouni Malinenf7222712019-06-13 01:50:21 +030014179static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
14180 struct sigma_conn *conn,
14181 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014182{
14183 struct wpa_ctrl *ctrl;
14184 const char *intf = get_param(cmd, "Interface");
14185 const char *bssid = get_param(cmd, "Bssid");
14186 const char *ssid = get_param(cmd, "SSID");
14187 const char *security = get_param(cmd, "Security");
14188 const char *passphrase = get_param(cmd, "Passphrase");
14189 const char *pin = get_param(cmd, "PIN");
14190 char buf[1000];
14191 char ssid_hex[200], passphrase_hex[200];
14192 const char *keymgmt, *cipher;
14193
14194 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014195 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014196
14197 if (!bssid) {
14198 send_resp(dut, conn, SIGMA_ERROR,
14199 "ErrorCode,Missing Bssid argument");
14200 return 0;
14201 }
14202
14203 if (!ssid) {
14204 send_resp(dut, conn, SIGMA_ERROR,
14205 "ErrorCode,Missing SSID argument");
14206 return 0;
14207 }
14208
14209 if (!security) {
14210 send_resp(dut, conn, SIGMA_ERROR,
14211 "ErrorCode,Missing Security argument");
14212 return 0;
14213 }
14214
14215 if (!passphrase) {
14216 send_resp(dut, conn, SIGMA_ERROR,
14217 "ErrorCode,Missing Passphrase argument");
14218 return 0;
14219 }
14220
14221 if (!pin) {
14222 send_resp(dut, conn, SIGMA_ERROR,
14223 "ErrorCode,Missing PIN argument");
14224 return 0;
14225 }
14226
vamsi krishna8c9c1562017-05-12 15:51:46 +053014227 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
14228 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014229 send_resp(dut, conn, SIGMA_ERROR,
14230 "ErrorCode,Too long SSID/passphrase");
14231 return 0;
14232 }
14233
14234 ctrl = open_wpa_mon(intf);
14235 if (ctrl == NULL) {
14236 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14237 "wpa_supplicant monitor connection");
14238 return -2;
14239 }
14240
14241 if (strcasecmp(security, "wpa2-psk") == 0) {
14242 keymgmt = "WPA2PSK";
14243 cipher = "CCMP";
14244 } else {
14245 wpa_ctrl_detach(ctrl);
14246 wpa_ctrl_close(ctrl);
14247 send_resp(dut, conn, SIGMA_ERROR,
14248 "ErrorCode,Unsupported Security value");
14249 return 0;
14250 }
14251
14252 ascii2hexstr(ssid, ssid_hex);
14253 ascii2hexstr(passphrase, passphrase_hex);
14254 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
14255 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
14256
14257 if (wpa_command(intf, buf) < 0) {
14258 wpa_ctrl_detach(ctrl);
14259 wpa_ctrl_close(ctrl);
14260 send_resp(dut, conn, SIGMA_ERROR,
14261 "ErrorCode,Failed to start registrar");
14262 return 0;
14263 }
14264
14265 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
14266 dut->er_oper_performed = 1;
14267
14268 return wps_connection_event(dut, conn, ctrl, intf, 0);
14269}
14270
14271
Jouni Malinenf7222712019-06-13 01:50:21 +030014272static enum sigma_cmd_result
14273cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
14274 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014275{
14276 struct wpa_ctrl *ctrl;
14277 const char *intf = get_param(cmd, "Interface");
14278 const char *bssid = get_param(cmd, "Bssid");
14279 char buf[100];
14280
14281 if (!bssid) {
14282 send_resp(dut, conn, SIGMA_ERROR,
14283 "ErrorCode,Missing Bssid argument");
14284 return 0;
14285 }
14286
14287 ctrl = open_wpa_mon(intf);
14288 if (ctrl == NULL) {
14289 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14290 "wpa_supplicant monitor connection");
14291 return -2;
14292 }
14293
14294 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
14295
14296 if (wpa_command(intf, buf) < 0) {
14297 wpa_ctrl_detach(ctrl);
14298 wpa_ctrl_close(ctrl);
14299 send_resp(dut, conn, SIGMA_ERROR,
14300 "ErrorCode,Failed to start registrar");
14301 return 0;
14302 }
14303
14304 return wps_connection_event(dut, conn, ctrl, intf, 0);
14305}
14306
14307
Jouni Malinenf7222712019-06-13 01:50:21 +030014308static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
14309 struct sigma_conn *conn,
14310 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053014311{
14312 struct wpa_ctrl *ctrl;
14313 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014314 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014315 const char *config_method = get_param(cmd, "WPSConfigMethod");
14316 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053014317 int res;
14318 char buf[256];
14319 const char *events[] = {
14320 "CTRL-EVENT-CONNECTED",
14321 "WPS-OVERLAP-DETECTED",
14322 "WPS-TIMEOUT",
14323 "WPS-FAIL",
14324 NULL
14325 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014326 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053014327
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014328 /* 60G WPS tests do not pass Interface parameter */
14329 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014330 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014331
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014332 if (dut->mode == SIGMA_MODE_AP)
14333 return ap_wps_registration(dut, conn, cmd);
14334
14335 if (config_method) {
14336 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
14337 * sta_wps_enter_pin before calling start_wps_registration. */
14338 if (strcasecmp(config_method, "PBC") == 0)
14339 dut->wps_method = WFA_CS_WPS_PBC;
14340 }
14341 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
14342 send_resp(dut, conn, SIGMA_ERROR,
14343 "ErrorCode,WPS parameters not yet set");
14344 return STATUS_SENT;
14345 }
14346
14347 /* Make sure WPS is enabled (also for STA mode) */
14348 dut->wps_disable = 0;
14349
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014350 if (dut->band == WPS_BAND_60G && network_mode &&
14351 strcasecmp(network_mode, "PBSS") == 0) {
14352 sigma_dut_print(dut, DUT_MSG_DEBUG,
14353 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014354 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014355 return -2;
14356 }
14357
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020014358 if (dut->force_rsn_ie) {
14359 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
14360 dut->force_rsn_ie);
14361 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
14362 sigma_dut_print(dut, DUT_MSG_INFO,
14363 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014364 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020014365 }
14366 }
14367
vamsi krishna9b144002017-09-20 13:28:13 +053014368 ctrl = open_wpa_mon(intf);
14369 if (!ctrl) {
14370 sigma_dut_print(dut, DUT_MSG_ERROR,
14371 "Failed to open wpa_supplicant monitor connection");
14372 return -2;
14373 }
14374
14375 role = get_param(cmd, "WpsRole");
14376 if (!role) {
14377 send_resp(dut, conn, SIGMA_INVALID,
14378 "ErrorCode,WpsRole not provided");
14379 goto fail;
14380 }
14381
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014382 if (strcasecmp(role, "Enrollee") != 0) {
14383 /* Registrar role for STA not supported */
14384 send_resp(dut, conn, SIGMA_ERROR,
14385 "ErrorCode,Unsupported WpsRole value");
14386 goto fail;
14387 }
14388
14389 if (is_60g_sigma_dut(dut)) {
14390 if (dut->wps_method == WFA_CS_WPS_PBC)
14391 snprintf(buf, sizeof(buf), "WPS_PBC");
14392 else /* WFA_CS_WPS_PIN_KEYPAD */
14393 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
14394 dut->wps_pin);
14395 if (wpa_command(intf, buf) < 0) {
14396 send_resp(dut, conn, SIGMA_ERROR,
14397 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053014398 goto fail;
14399 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014400 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
14401 if (res < 0) {
14402 send_resp(dut, conn, SIGMA_ERROR,
14403 "ErrorCode,WPS connection did not complete");
14404 goto fail;
14405 }
14406 if (strstr(buf, "WPS-TIMEOUT")) {
14407 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
14408 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
14409 send_resp(dut, conn, SIGMA_COMPLETE,
14410 "WpsState,OverlapSession");
14411 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
14412 send_resp(dut, conn, SIGMA_COMPLETE,
14413 "WpsState,Successful");
14414 } else {
14415 send_resp(dut, conn, SIGMA_COMPLETE,
14416 "WpsState,Failure");
14417 }
14418 } else {
14419 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053014420 if (wpa_command(intf, "WPS_PBC") < 0) {
14421 send_resp(dut, conn, SIGMA_ERROR,
14422 "ErrorCode,Failed to enable PBC");
14423 goto fail;
14424 }
14425 } else {
14426 /* TODO: PIN method */
14427 send_resp(dut, conn, SIGMA_ERROR,
14428 "ErrorCode,Unsupported WpsConfigMethod value");
14429 goto fail;
14430 }
14431 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
14432 if (res < 0) {
14433 send_resp(dut, conn, SIGMA_ERROR,
14434 "ErrorCode,WPS connection did not complete");
14435 goto fail;
14436 }
14437 if (strstr(buf, "WPS-TIMEOUT")) {
14438 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
14439 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
14440 send_resp(dut, conn, SIGMA_ERROR,
14441 "ErrorCode,OverlapSession");
14442 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
14443 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
14444 } else {
14445 send_resp(dut, conn, SIGMA_ERROR,
14446 "ErrorCode,WPS operation failed");
14447 }
vamsi krishna9b144002017-09-20 13:28:13 +053014448 }
14449
14450fail:
14451 wpa_ctrl_detach(ctrl);
14452 wpa_ctrl_close(ctrl);
14453 return 0;
14454}
14455
14456
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014457static int req_intf(struct sigma_cmd *cmd)
14458{
14459 return get_param(cmd, "interface") == NULL ? -1 : 0;
14460}
14461
14462
14463void sta_register_cmds(void)
14464{
14465 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
14466 cmd_sta_get_ip_config);
14467 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
14468 cmd_sta_set_ip_config);
14469 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
14470 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
14471 cmd_sta_get_mac_address);
14472 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
14473 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
14474 cmd_sta_verify_ip_connection);
14475 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
14476 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
14477 cmd_sta_set_encryption);
14478 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
14479 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
14480 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
14481 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
14482 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
14483 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
14484 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
14485 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
14486 cmd_sta_set_eapakaprime);
14487 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
14488 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
14489 /* TODO: sta_set_ibss */
14490 /* TODO: sta_set_mode */
14491 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
14492 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
14493 /* TODO: sta_up_load */
14494 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
14495 cmd_sta_preset_testparameters);
14496 /* TODO: sta_set_system */
14497 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
14498 /* TODO: sta_set_rifs_test */
14499 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
14500 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
14501 /* TODO: sta_send_coexist_mgmt */
14502 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
14503 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
14504 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
14505 sigma_dut_reg_cmd("sta_reset_default", req_intf,
14506 cmd_sta_reset_default);
14507 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
14508 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
14509 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
14510 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
14511 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014512 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014513 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
14514 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
14515 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
14516 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
14517 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030014518 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
14519 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014520 sigma_dut_reg_cmd("sta_add_credential", req_intf,
14521 cmd_sta_add_credential);
14522 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020014523 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014524 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
14525 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
14526 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
14527 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
14528 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
14529 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030014530 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014531 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
14532 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014533 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053014534 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014535}